LCOV - code coverage report
Current view: directory - netwerk/dns - nameprep_template.c (source / functions) Found Hit Coverage
Test: app.info Lines: 26 25 96.2 %
Date: 2012-06-02 Functions: 4 4 100.0 %

       1                 : /*
       2                 :  * Copyright (c) 2001 Japan Network Information Center.  All rights reserved.
       3                 :  *  
       4                 :  * By using this file, you agree to the terms and conditions set forth bellow.
       5                 :  * 
       6                 :  *                      LICENSE TERMS AND CONDITIONS 
       7                 :  * 
       8                 :  * The following License Terms and Conditions apply, unless a different
       9                 :  * license is obtained from Japan Network Information Center ("JPNIC"),
      10                 :  * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
      11                 :  * Chiyoda-ku, Tokyo 101-0047, Japan.
      12                 :  * 
      13                 :  * 1. Use, Modification and Redistribution (including distribution of any
      14                 :  *    modified or derived work) in source and/or binary forms is permitted
      15                 :  *    under this License Terms and Conditions.
      16                 :  * 
      17                 :  * 2. Redistribution of source code must retain the copyright notices as they
      18                 :  *    appear in each source code file, this License Terms and Conditions.
      19                 :  * 
      20                 :  * 3. Redistribution in binary form must reproduce the Copyright Notice,
      21                 :  *    this License Terms and Conditions, in the documentation and/or other
      22                 :  *    materials provided with the distribution.  For the purposes of binary
      23                 :  *    distribution the "Copyright Notice" refers to the following language:
      24                 :  *    "Copyright (c) 2000-2002 Japan Network Information Center.  All rights reserved."
      25                 :  * 
      26                 :  * 4. The name of JPNIC may not be used to endorse or promote products
      27                 :  *    derived from this Software without specific prior written approval of
      28                 :  *    JPNIC.
      29                 :  * 
      30                 :  * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
      31                 :  *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      32                 :  *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
      33                 :  *    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL JPNIC BE LIABLE
      34                 :  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      35                 :  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
      36                 :  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
      37                 :  *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
      38                 :  *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      39                 :  *    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
      40                 :  *    ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
      41                 :  */
      42                 : 
      43                 : /*
      44                 :  * Include this file once for each version of NAMEPREP.
      45                 :  * VERSION should be defined to appropriate value before inclusion.
      46                 :  */
      47                 : 
      48                 : #ifndef NAMEPREP_TEMPLATE_INIT
      49                 : #define NAMEPREP_TEMPLATE_INIT
      50                 : 
      51                 : #include "prtypes.h"
      52                 : 
      53                 : /* Symbol composition. */
      54                 : #define compose_sym2(a, b)              compose_sym2X(a, b)
      55                 : #define compose_sym2X(a, b)             a ## b
      56                 : #define compose_sym3(a, b, c)           compose_sym3X(a, b, c)
      57                 : #define compose_sym3X(a, b, c)          a ## b ## c
      58                 : 
      59                 : /* The table is based on "Optimized Two-Stage Table" mentioned in
      60                 :  * Unicode 3.0 page 106, extended to handle 21bit data instead of 16 bit.
      61                 :  */
      62                 : 
      63                 : /* Index calculation for multi-level index tables. */
      64                 : #define IDX0(type, v) IDX_0(v, BITS1(type), BITS2(type))
      65                 : #define IDX1(type, v) IDX_1(v, BITS1(type), BITS2(type))
      66                 : #define IDX2(type, v) IDX_2(v, BITS1(type), BITS2(type))
      67                 : 
      68                 : #define IDX_0(v, bits1, bits2)  ((v) >> ((bits1) + (bits2)))
      69                 : #define IDX_1(v, bits1, bits2)  (((v) >> (bits2)) & ((1 << (bits1)) - 1))
      70                 : #define IDX_2(v, bits1, bits2)  ((v) & ((1 << (bits2)) - 1))
      71                 : 
      72                 : #define BITS1(type)     type ## _BITS_1
      73                 : #define BITS2(type)     type ## _BITS_2
      74                 : 
      75                 : #endif /* NAMEPREP_TEMPLATE_INIT */
      76                 : 
      77                 : static const char *
      78            3464 : compose_sym2(nameprep_map_, VERSION) (PRUint32 v) {
      79            3464 :         int idx0 = IDX0(MAP, v);
      80            3464 :         int idx1 = IDX1(MAP, v);
      81            3464 :         int idx2 = IDX2(MAP, v);
      82                 :         int offset;
      83                 : 
      84                 : #define IMAP    compose_sym3(nameprep_, VERSION, _map_imap)
      85                 : #define TABLE   compose_sym3(nameprep_, VERSION, _map_table)
      86                 : #define DATA    compose_sym3(nameprep_, VERSION, _map_data)
      87            3464 :         offset = TABLE[IMAP[IMAP[idx0] + idx1]].tbl[idx2];
      88            3464 :         if (offset == 0)
      89            3464 :                 return (NULL);  /* no mapping */
      90               0 :         return (const char *)(DATA + offset);
      91                 : #undef IMAP
      92                 : #undef TABLE
      93                 : #undef DATA
      94                 : }
      95                 : 
      96                 : static int
      97            3417 : compose_sym2(nameprep_prohibited_, VERSION) (PRUint32 v) {
      98            3417 :         int idx0 = IDX0(PROH, v);
      99            3417 :         int idx1 = IDX1(PROH, v);
     100            3417 :         int idx2 = IDX2(PROH, v);
     101                 :         const unsigned char *bm;
     102                 : 
     103                 : #define IMAP    compose_sym3(nameprep_, VERSION, _prohibited_imap)
     104                 : #define BITMAP  compose_sym3(nameprep_, VERSION, _prohibited_bitmap)
     105            3417 :         bm = BITMAP[IMAP[IMAP[idx0] + idx1]].bm;
     106            3417 :         return (bm[idx2 / 8] & (1 << (idx2 % 8)));
     107                 : #undef IMAP
     108                 : #undef BITMAP
     109                 : }
     110                 : 
     111                 : static int
     112              80 : compose_sym2(nameprep_unassigned_, VERSION) (PRUint32 v) {
     113              80 :         int idx0 = IDX0(UNAS, v);
     114              80 :         int idx1 = IDX1(UNAS, v);
     115              80 :         int idx2 = IDX2(UNAS, v);
     116                 :         const unsigned char *bm;
     117                 : 
     118                 : #define IMAP    compose_sym3(nameprep_, VERSION, _unassigned_imap)
     119                 : #define BITMAP  compose_sym3(nameprep_, VERSION, _unassigned_bitmap)
     120              80 :         bm = BITMAP[IMAP[IMAP[idx0] + idx1]].bm;
     121              80 :         return (bm[idx2 / 8] & (1 << (idx2 % 8)));
     122                 : #undef IMAP
     123                 : #undef BITMAP
     124                 : }
     125                 : 
     126                 : static idn_biditype_t
     127            3354 : compose_sym2(nameprep_biditype_, VERSION) (PRUint32 v) {
     128            3354 :         int idx0 = IDX0(BIDI, v);
     129            3354 :         int idx1 = IDX1(BIDI, v);
     130            3354 :         int idx2 = IDX2(BIDI, v);
     131                 :         int offset;
     132                 : 
     133                 : #define IMAP    compose_sym3(nameprep_, VERSION, _bidi_imap)
     134                 : #define TABLE   compose_sym3(nameprep_, VERSION, _bidi_table)
     135                 : #define DATA    compose_sym3(nameprep_, VERSION, _bidi_data)
     136            3354 :         offset = TABLE[IMAP[IMAP[idx0] + idx1]].tbl[idx2];
     137            3354 :         return DATA[offset];
     138                 : #undef IMAP
     139                 : #undef TABLE
     140                 : #undef DATA
     141                 : }

Generated by: LCOV version 1.7