Back to index

lightning-sunbird  0.9+nobinonly
Defines | Typedefs | Enumerations | Functions
nsIDNKitInterface.h File Reference
#include "prtypes.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define IDN_NAMEPREP_CURRENT   "nameprep-11"
#define assert(a)
#define TRACE(a)

Typedefs

typedef struct idn_nameprepidn_nameprep_t

Enumerations

enum  idn_result_t {
  idn_success, idn_notfound, idn_invalid_encoding, idn_invalid_syntax,
  idn_invalid_name, idn_invalid_message, idn_invalid_action, idn_invalid_codepoint,
  idn_invalid_length, idn_buffer_overflow, idn_noentry, idn_nomemory,
  idn_nofile, idn_nomapping, idn_context_required, idn_prohibited,
  idn_failure
}
enum  idn_biditype_t { idn_biditype_r_al, idn_biditype_l, idn_biditype_others }

Functions

idn_result_t race_decode_decompress (const char *from, PRUint16 *buf, size_t buflen)
idn_result_t race_compress_encode (const PRUint16 *p, int compress_mode, char *to, size_t tolen)
int get_compress_mode (PRUint16 *p)
idn_result_t idn_nameprep_create (const char *version, idn_nameprep_t *handlep)
void idn_nameprep_destroy (idn_nameprep_t handle)
idn_result_t idn_nameprep_map (idn_nameprep_t handle, const PRUint32 *from, PRUint32 *to, size_t tolen)
idn_result_t idn_nameprep_isprohibited (idn_nameprep_t handle, const PRUint32 *str, const PRUint32 **found)
idn_result_t idn_nameprep_isunassigned (idn_nameprep_t handle, const PRUint32 *str, const PRUint32 **found)
idn_result_t idn_nameprep_isvalidbidi (idn_nameprep_t handle, const PRUint32 *str, const PRUint32 **found)

Define Documentation

#define assert (   a)

Definition at line 95 of file nsIDNKitInterface.h.

#define IDN_NAMEPREP_CURRENT   "nameprep-11"

Definition at line 93 of file nsIDNKitInterface.h.

#define TRACE (   a)

Definition at line 96 of file nsIDNKitInterface.h.


Typedef Documentation

typedef struct idn_nameprep* idn_nameprep_t

Definition at line 87 of file nsIDNKitInterface.h.


Enumeration Type Documentation

Enumerator:
idn_biditype_r_al 
idn_biditype_l 
idn_biditype_others 

Definition at line 78 of file nsIDNKitInterface.h.

Enumerator:
idn_success 
idn_notfound 
idn_invalid_encoding 
idn_invalid_syntax 
idn_invalid_name 
idn_invalid_message 
idn_invalid_action 
idn_invalid_codepoint 
idn_invalid_length 
idn_buffer_overflow 
idn_noentry 
idn_nomemory 
idn_nofile 
idn_nomapping 
idn_context_required 
idn_prohibited 
idn_failure 

Definition at line 55 of file nsIDNKitInterface.h.


Function Documentation

Definition at line 211 of file race.c.

                               {
       int zero = 0;
       unsigned int upper = 0;
       PRUint16 *modepos = p - 1;

       while (*p != '\0') {
              unsigned int hi = *p++ & 0xff00;

              if (hi == 0) {
                     zero++;
              } else if (hi == upper) {
                     ;
              } else if (upper == 0) {
                     upper = hi;
              } else {
                     *modepos = RACE_2OCTET_MODE;
                     return (compress_none);
              }
       }
       *modepos = upper >> 8;
       if (upper > 0 && zero > 0)
              return (compress_two);
       else
              return (compress_one);
}

Here is the caller graph for this function:

idn_result_t idn_nameprep_create ( const char *  version,
idn_nameprep_t handlep 
)

Definition at line 93 of file nameprep.c.

                                                                  {
       idn_nameprep_t handle;

       assert(handlep != NULL);

       TRACE(("idn_nameprep_create(version=%-.50s)\n",
              version == NULL ? "<NULL>" : version));

       if (version == NULL)
              version = IDN_NAMEPREP_CURRENT;

       /*
        * Lookup table for the specified version.  Since the number of
        * versions won't be large (I don't want see draft-23 or such :-),
        * simple linear search is OK.
        */
       for (handle = nameprep_versions; handle->version != NULL; handle++) {
              if (strcmp(handle->version, version) == 0) {
                     *handlep = handle;
                     return (idn_success);
              }
       }
       return (idn_notfound);
}

Here is the caller graph for this function:

Definition at line 119 of file nameprep.c.

                                            {
       assert(handle != NULL);

       TRACE(("idn_nameprep_destroy()\n"));

       /* Nothing to do. */
}

Here is the caller graph for this function:

Definition at line 192 of file nameprep.c.

                                               {
       assert(handle != NULL && str != NULL && found != NULL);

       TRACE(("idn_nameprep_isprohibited(ctx=%s, str=\"%s\")\n",
              handle->version, idn__debug_ucs4xstring(str, 50)));

       return (idn_nameprep_check(handle->prohibited_proc, str, found));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 203 of file nameprep.c.

                                               {
       assert(handle != NULL && str != NULL && found != NULL);

       TRACE(("idn_nameprep_isunassigned(handle->version, str=\"%s\")\n",
              handle->version, idn__debug_ucs4xstring(str, 50)));

       return (idn_nameprep_check(handle->unassigned_proc, str, found));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 239 of file nameprep.c.

                                              {
       PRUint32 v;
       idn_biditype_t first_char;
       idn_biditype_t last_char;
       int found_r_al;

       assert(handle != NULL && str != NULL && found != NULL);

       TRACE(("idn_nameprep_isvalidbidi(ctx=%s, str=\"%s\")\n",
              handle->version, idn__debug_ucs4xstring(str, 50)));

       if (*str == '\0') {
              *found = NULL;
              return (idn_success);
       }

       /*
        * check first character's type and initialize variables.
        */
       found_r_al = 0;
       if (*str > UCS_MAX) {
              /* This cannot happen, but just in case.. */
              return (idn_invalid_codepoint);
       } else if (*str > UNICODE_MAX) {
              /* It is invalid.. */
              *found = str;
              return (idn_success);
       }
       first_char = last_char = (*(handle->biditype_proc))(*str);
       if (first_char == idn_biditype_r_al) {
              found_r_al = 1;
       }
       str++;

       /*
        * see whether string is valid or not.
        */
       while (*str != '\0') {
              v = *str;

              if (v > UCS_MAX) {
                     /* This cannot happen, but just in case.. */
                     return (idn_invalid_codepoint);
              } else if (v > UNICODE_MAX) {
                     /* It is invalid.. */
                     *found = str;
                     return (idn_success);
              } else { 
                     last_char = (*(handle->biditype_proc))(v);
                     if (found_r_al && last_char == idn_biditype_l) {
                            *found = str;
                            return (idn_success);
                     }
                     if (first_char != idn_biditype_r_al && last_char == idn_biditype_r_al) {
                            *found = str;
                            return (idn_success);
                     }
                     if (last_char == idn_biditype_r_al) {
                            found_r_al = 1;
                     }
              }
              str++;
       }

       if (found_r_al) {
              if (last_char != idn_biditype_r_al) {
                     *found = str - 1;
                     return (idn_success);
              }
       }

       *found = NULL;
       return (idn_success);
}

Here is the caller graph for this function:

idn_result_t idn_nameprep_map ( idn_nameprep_t  handle,
const PRUint32 from,
PRUint32 to,
size_t  tolen 
)

Definition at line 128 of file nameprep.c.

                                           {
       assert(handle != NULL && from != NULL && to != NULL);

       TRACE(("idn_nameprep_map(ctx=%s, from=\"%s\")\n",
              handle->version, idn__debug_ucs4xstring(from, 50)));

       while (*from != '\0') {
              PRUint32 v = *from;
              const char *mapped;

              if (v > UCS_MAX) {
                     /* This cannot happen, but just in case.. */
                     return (idn_invalid_codepoint);
              } else if (v > UNICODE_MAX) {
                     /* No mapping is possible. */
                     mapped = NULL;
              } else {
                     /* Try mapping. */
                     mapped = (*handle->map_proc)(v);
              }

              if (mapped == NULL) {
                     /* No mapping. Just copy verbatim. */
                     if (tolen < 1)
                            return (idn_buffer_overflow);
                     *to++ = v;
                     tolen--;
              } else {
                     const unsigned char *mappeddata;
                     size_t mappedlen;

                     mappeddata = (const unsigned char *)mapped + 1;
                     mappedlen = *mapped;

                     if (tolen < (mappedlen + 3) / 4)
                            return (idn_buffer_overflow);
                     tolen -= (mappedlen + 3) / 4;
                     while (mappedlen >= 4) {
                            *to  = *mappeddata++;
                            *to |= *mappeddata++ <<  8;
                            *to |= *mappeddata++ << 16;
                            *to |= *mappeddata++ << 24;
                            mappedlen -= 4;
                            to++;
                     }
                     if (mappedlen > 0) {
                            *to  = *mappeddata++;
                            *to |= (mappedlen >= 2) ?
                                   *mappeddata++ <<  8: 0;
                            *to |= (mappedlen >= 3) ?
                                   *mappeddata++ << 16: 0;
                            to++;
                     }
              }
              from++;
       }
       if (tolen == 0)
              return (idn_buffer_overflow);
       *to = '\0';
       return (idn_success);
}

Here is the caller graph for this function:

idn_result_t race_compress_encode ( const PRUint16 p,
int  compress_mode,
char *  to,
size_t  tolen 
)

Definition at line 141 of file race.c.

{
       PRUint32 bitbuf = *p++;     /* bit stream buffer */
       int bitlen = 8;                    /* # of bits in 'bitbuf' */

       while (*p != '\0' || bitlen > 0) {
              unsigned int c = *p;

              if (c == '\0') {
                     /* End of data.  Flush. */
                     bitbuf <<= (5 - bitlen);
                     bitlen = 5;
              } else if (compress_mode == compress_none) {
                     /* Push 16 bit data. */
                     bitbuf = (bitbuf << 16) | c;
                     bitlen += 16;
                     p++;
              } else {/* compress_mode == compress_one/compress_two */
                     /* Push 8 or 16 bit data. */
                     if (compress_mode == compress_two &&
                         (c & 0xff00) == 0) {
                            /* Upper octet is zero (and not U1). */
                            bitbuf = (bitbuf << 16) | 0xff00 | c;
                            bitlen += 16;
                     } else if ((c & 0xff) == 0xff) {
                            /* Lower octet is 0xff. */
                            bitbuf = (bitbuf << 16) |
                                   (RACE_ESCAPE << 8) | RACE_ESCAPE_2ND;
                            bitlen += 16;
                     } else {
                            /* Just output lower octet. */
                            bitbuf = (bitbuf << 8) | (c & 0xff);
                            bitlen += 8;
                     }
                     p++;
              }

              /*
               * Output bits in 'bitbuf' in 5-bit unit.
               */
              while (bitlen >= 5) {
                     int x;

                     /* Get top 5 bits. */
                     x = (bitbuf >> (bitlen - 5)) & 0x1f;
                     bitlen -= 5;

                     /* Encode. */
                     if (x < 26)
                            x += 'a';
                     else
                            x = (x - 26) + '2';

                     if (tolen < 1)
                            return (idn_buffer_overflow);

                     *to++ = x;
                     tolen--;
              }
       }

       if (tolen <= 0)
              return (idn_buffer_overflow);

       *to = '\0';
       return (idn_success);
}

Here is the caller graph for this function:

idn_result_t race_decode_decompress ( const char *  from,
PRUint16 buf,
size_t  buflen 
)

Definition at line 67 of file race.c.

{
       PRUint16 *p = buf;
       unsigned int bitbuf = 0;
       int bitlen = 0;
       unsigned int i, j;
       size_t len;

       while (*from != '\0') {
              int c = *from++;
              int x;

              if ('a' <= c && c <= 'z')
                     x = c - 'a';
              else if ('A' <= c && c <= 'Z')
                     x = c - 'A';
              else if ('2' <= c && c <= '7')
                     x = c - '2' + 26;
              else
                     return (idn_invalid_encoding);

              bitbuf = (bitbuf << 5) + x;
              bitlen += 5;
              if (bitlen >= 8) {
                     *p++ = (bitbuf >> (bitlen - 8)) & 0xff;
                     bitlen -= 8;
              }
       }
       len = p - buf;

       /*
        * Now 'buf' holds the decoded string.
        */

       /*
        * Decompress.
        */
       if (buf[0] == RACE_2OCTET_MODE) {
              if ((len - 1) % 2 != 0)
                     return (idn_invalid_encoding);
              for (i = 1, j = 0; i < len; i += 2, j++)
                     buf[j] = (buf[i] << 8) + buf[i + 1];
              len = j;
       } else {
              PRUint16 c = buf[0] << 8;   /* higher octet */

              for (i = 1, j = 0; i < len; j++) {
                     if (buf[i] == RACE_ESCAPE) {
                            if (i + 1 >= len)
                                   return (idn_invalid_encoding);
                            else if (buf[i + 1] == RACE_ESCAPE_2ND)
                                   buf[j] = c | 0xff;
                            else
                                   buf[j] = buf[i + 1];
                            i += 2;

                     } else if (buf[i] == 0x99 && c == 0x00) {
                            /*
                             * The RACE specification says this is error.
                             */
                            return (idn_invalid_encoding);
                             
                     } else {
                            buf[j] = c | buf[i++];
                     }
              }
              len = j;
       }
       buf[len] = '\0';

       return (idn_success);
}