]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/charset.c
Provide build support for sasl.c.
[openldap] / libraries / libldap / charset.c
index 20a9db5306e8492cacd19d751261cad2e364a540..75c30ff9d96f007796ffdc5306e0cc5a323d0eb9 100644 (file)
@@ -14,7 +14,8 @@
 #ifdef STR_TRANSLATION
 
 #include <stdio.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
 
 #include <ac/socket.h>
 #include <ac/string.h>
@@ -39,7 +40,7 @@ ldap_set_string_translators( LDAP *ld, BERTranslateProc encode_proc,
 void
 ldap_enable_translation( LDAP *ld, LDAPMessage *entry, int enable )
 {
-       char    *optionsp;
+       short   *optionsp;
 
        optionsp = ( entry == NULLMSG ) ? &ld->ld_lberoptions :
            &entry->lm_ber->ber_options;
@@ -53,7 +54,7 @@ ldap_enable_translation( LDAP *ld, LDAPMessage *entry, int enable )
 
 
 int
-ldap_translate_from_t61( LDAP *ld, char **bufp, unsigned long *lenp,
+ldap_translate_from_t61( LDAP *ld, char **bufp, ber_len_t *lenp,
     int free_input )
 {
        if ( ld->ld_lber_decode_translate_proc == 0 ) {
@@ -65,7 +66,7 @@ ldap_translate_from_t61( LDAP *ld, char **bufp, unsigned long *lenp,
 
 
 int
-ldap_translate_to_t61( LDAP *ld, char **bufp, unsigned long *lenp,
+ldap_translate_to_t61( LDAP *ld, char **bufp, ber_len_t *lenp,
     int free_input )
 {
        if ( ld->ld_lber_encode_translate_proc == 0 ) {
@@ -147,7 +148,7 @@ ldap_translate_to_t61( LDAP *ld, char **bufp, unsigned long *lenp,
 
 
 #include <stdio.h>
-#include <stdlib.h>
+#include <ac/stdlib.h>
 #include <ac/string.h>
 
 /* Character set used: ISO 8859-1, ISO 8859-2, ISO 8859-3, ... */
@@ -163,9 +164,9 @@ typedef struct { Byte  a, b; } Couple;
 /* Prototypes without LDAP_P():
  * 'Byte' in definition incompatible with unprototyped declaration. */
 static Byte *c_to_hh   ( Byte *o, Byte c );
-static Byte *c_to_cc   ( Byte *o, Couple *cc, Byte c );
-static int   hh_to_c   ( Byte *h );
-static Byte *cc_to_t61 ( Byte *o, Byte *s );
+static Byte *c_to_cc   ( Byte *o, const Couple *cc, Byte c );
+static int   hh_to_c   ( const Byte *h );
+static Byte *cc_to_t61 ( Byte *o, const Byte *s );
 
 /*
    Character choosed as base in diacritics alone: NO-BREAK SPACE.
@@ -173,7 +174,7 @@ static Byte *cc_to_t61 ( Byte *o, Byte *s );
 */
 #define  ALONE  0xA0
 
-static Couple diacritic[16] = {
+static const Couple diacritic[16] = {
 #if (ISO_8859 == 1) || (ISO_8859 == 9)
        {0,0},       {'`',0},     {0xb4,0},    {'^',0},
        {'~',0},     {0xaf,0},    {'(',ALONE}, {'.',ALONE},
@@ -208,7 +209,7 @@ static Couple diacritic[16] = {
        L,   N,   O,   R,   S,   T,   U,   W,   Y,   Z.
    -----------------------------------------------------------------------
 */
-static int letter_w_diacritic[16][38] = {
+static const int letter_w_diacritic[16][38] = {
 #if (ISO_8859 == 1)
        0,   0,   0,   0,   0,   0,   0,   0,   0,
        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
@@ -670,7 +671,7 @@ static int letter_w_diacritic[16][38] = {
 /*
 --- T.61 characters [0xA0 .. 0xBF] -----------------
 */
-static Couple trans_t61a_iso8859[32] = {
+static const Couple trans_t61a_iso8859[32] = {
 #if (ISO_8859 == 1) || (ISO_8859 == 9)
        {'N','S'}, {0xa1,0},  {0xa2,0},  {0xa3,0},
        {'D','O'}, {0xa5,0},  {'C','u'}, {0xa7,0},
@@ -722,7 +723,7 @@ static Couple trans_t61a_iso8859[32] = {
 /*
 --- T.61 characters [0xE0 .. 0xFF] -----------------
 */
-static Couple trans_t61b_iso8859[48] = {
+static const Couple trans_t61b_iso8859[48] = {
 #if (ISO_8859 == 1)
        {'-','M'}, {0xb9,0},  {0xae,0},  {0xa9,0},
        {'T','M'}, {'M','8'}, {0xac,0},  {0xa6,0},
@@ -821,7 +822,7 @@ static Couple trans_t61b_iso8859[48] = {
 --- ISO 8859-n characters <0xA0 .. 0xFF> -------------------
 */
 #if (ISO_8859 == 1)
-static Couple trans_iso8859_t61[96] = {
+static const Couple trans_iso8859_t61[96] = {
        {0xa0,0},     {0xa1,0},     {0xa2,0},     {0xa3,0},
        {0xa8,0},     {0xa5,0},     {0xd7,0},     {0xa7,0},
        {0xc8,ALONE}, {0xd3,0},     {0xe3,0},     {0xab,0},
@@ -848,7 +849,7 @@ static Couple trans_iso8859_t61[96] = {
        {0xc8,'u'},   {0xc2,'y'},   {0xfc,0},     {0xc8,'y'}
 };
 #elif (ISO_8859 == 2)
-static Couple trans_iso8859_t61[96] = {
+static const Couple trans_iso8859_t61[96] = {
        {0xa0,0},     {0xce,'A'},   {0xc6,ALONE}, {0xe8,0},
        {0xa8,0},     {0xcf,'L'},   {0xc2,'S'},   {0xa7,0},
        {0xc8,ALONE}, {0xcf,'S'},   {0xcb,'S'},   {0xcf,'T'},
@@ -875,7 +876,7 @@ static Couple trans_iso8859_t61[96] = {
        {0xc8,'u'},   {0xc2,'y'},   {0xcb,'t'},   {0xc7,ALONE}
 };
 #elif (ISO_8859 == 3)
-static Couple trans_iso8859_t61[96] = {
+static const Couple trans_iso8859_t61[96] = {
        {0xa0,0},     {0xe4,0},     {0xc6,ALONE}, {0xa3,0},
        {0xa8,0},     {0,0},        {0xc3,'H'},   {0xa7,0},
        {0xc8,ALONE}, {0xc7,'I'},   {0xcb,'S'},   {0xc6,'G'},
@@ -902,7 +903,7 @@ static Couple trans_iso8859_t61[96] = {
        {0xc8,'u'},   {0xc6,'u'},   {0xc3,'s'},   {0xc7,ALONE}
 };
 #elif (ISO_8859 == 4)
-static Couple trans_iso8859_t61[96] = {
+static const Couple trans_iso8859_t61[96] = {
        {0xa0,0},     {0xce,'A'},   {0xf0,0},     {0xcb,'R'},
        {0xa8,0},     {0xc4,'I'},   {0xcb,'L'},   {0xa7,0},
        {0xc8,ALONE}, {0xcf,'S'},   {0xc5,'E'},   {0xcb,'G'},
@@ -929,7 +930,7 @@ static Couple trans_iso8859_t61[96] = {
        {0xc8,'u'},   {0xc4,'u'},   {0xc5,'u'},   {0xc7,ALONE}
 };
 #elif (ISO_8859 == 9)
-static Couple trans_iso8859_t61[96] = {
+static const Couple trans_iso8859_t61[96] = {
        {0xa0,0},     {0xa1,0},     {0xa2,0},     {0xa3,0},
        {0xa8,0},     {0xa5,0},     {0xd7,0},     {0xa7,0},
        {0xc8,ALONE}, {0xd3,0},     {0xe3,0},     {0xab,0},
@@ -956,7 +957,7 @@ static Couple trans_iso8859_t61[96] = {
        {0xc8,'u'},   {0xf5,0},     {0xcb,'s'},   {0xc8,'y'}
 };
 #elif (ISO_8859 == 10)
-static Couple trans_iso8859_t61[96] = {
+static const Couple trans_iso8859_t61[96] = {
        {0xa0,0},     {0xce,'A'},   {0xc5,'E'},   {0xcb,'G'},
        {0xc5,'I'},   {0xc4,'I'},   {0xcb,'K'},   {0xa7,0},
        {0xcb,'L'},   {0xe2,0},     {0xcf,'S'},   {0xed,0},
@@ -1001,7 +1002,7 @@ c_to_hh( Byte *o, Byte c )
 
 
 static Byte *
-c_to_cc( Byte *o, Couple *cc, Byte c )
+c_to_cc( Byte *o, const Couple *cc, Byte c )
 {
   if ( (*cc).a != 0 ) {
     if ( (*cc).b == 0 )
@@ -1021,13 +1022,12 @@ c_to_cc( Byte *o, Couple *cc, Byte c )
 /* --- routine to convert from T.61 to ISO 8859-n --- */
 
 int
-ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input )
+ldap_t61_to_8859( char **bufp, ber_len_t *buflenp, int free_input )
 {
   Byte         *s, *oo, *o;
   unsigned int  n;
   int           c;
-  unsigned long len;
-  Couple        *cc;
+  ber_len_t len;
 
   Debug( LDAP_DEBUG_TRACE, "ldap_t61_to_8859 input length: %ld\n",
        *buflenp, 0, 0 );
@@ -1035,7 +1035,7 @@ ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input )
   len = *buflenp;
   s = (Byte *) *bufp;
 
-  if ( (o = oo = (Byte *)malloc( 2 * len + 64 )) == NULL ) {
+  if ( (o = oo = (Byte *)LDAP_MALLOC( 2 * len + 64 )) == NULL ) {
         return( 1 );
   }
 
@@ -1137,13 +1137,13 @@ ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input )
   len = o - oo;
   o = oo;
 
-  if ( (oo = (Byte *)realloc( o, len )) == NULL ) {
-    free( o );
+  if ( (oo = (Byte *)LDAP_REALLOC( o, len )) == NULL ) {
+    LDAP_FREE( o );
     return( 1 );
   }
 
   if ( free_input ) {
-    free( *bufp );
+    LDAP_FREE( *bufp );
   }
   *bufp = (char *) oo;
   *buflenp = len;
@@ -1152,7 +1152,7 @@ ldap_t61_to_8859( char **bufp, unsigned long *buflenp, int free_input )
 
 
 static int
-hh_to_c( Byte *h )
+hh_to_c( const Byte *h )
 {
   Byte c;
 
@@ -1173,7 +1173,7 @@ hh_to_c( Byte *h )
 
 
 static Byte *
-cc_to_t61( Byte *o, Byte *s )
+cc_to_t61( Byte *o, const Byte *s )
 {
   int n, c = 0;
 
@@ -1559,12 +1559,12 @@ cc_to_t61( Byte *o, Byte *s )
 /* --- routine to convert from ISO 8859-n to T.61 --- */
 
 int
-ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input )
+ldap_8859_to_t61( char **bufp, ber_len_t *buflenp, int free_input )
 {
   Byte         *s, *oo, *o, *aux;
   int          c;
-  unsigned long len; 
-  Couple       *cc;
+  ber_len_t len; 
+  const Couple *cc;
 
   Debug( LDAP_DEBUG_TRACE, "ldap_8859_to_t61 input length: %ld\n",
        *buflenp, 0, 0 );
@@ -1572,7 +1572,7 @@ ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input )
   len = *buflenp;
   s = (Byte *) *bufp;
 
-  if ( (o = oo = (Byte *)malloc( 2 * len + 64 )) == NULL ) {
+  if ( (o = oo = (Byte *)LDAP_MALLOC( 2 * len + 64 )) == NULL ) {
         return( 1 );
   }
 
@@ -1651,13 +1651,13 @@ ldap_8859_to_t61( char **bufp, unsigned long *buflenp, int free_input )
   len = o - oo;
   o = oo;
 
-  if ( (oo = (Byte *)realloc( o, len )) == NULL ) {
-    free( o );
+  if ( (oo = (Byte *)LDAP_REALLOC( o, len )) == NULL ) {
+    LDAP_FREE( o );
     return( 1 );
   }
 
   if ( free_input ) {
-    free( *bufp );
+    LDAP_FREE( *bufp );
   }
   *bufp = (char *) oo;
   *buflenp = len;
@@ -1676,7 +1676,7 @@ char      *s;
 
   while ( *s ) {
     if ( *s == '\\' ) {
-      if ( (c = hh_to_c( ++s )) != -1 ) {
+      if ( (c = hh_to_c( (Byte *) ++s )) != -1 ) {
        *o++ = c;
        s += 2;
       } else
@@ -1690,12 +1690,12 @@ char    *s;
 /* --- routine to convert 8bits characters to the "escaped" (\hh) form --- */
 
 char *convert_8bit_to_escaped( s )
-Byte  *s;
+const Byte  *s;
 {
   Byte *o, *oo;
   Byte n;
 
-  if ( (o = oo = (Byte *)malloc( 2 * strlen( s ) + 64 )) == NULL ) {
+  if ( (o = oo = (Byte *)LDAP_MALLOC( 2 * strlen( s ) + 64 )) == NULL ) {
         return( NULL );
   }
 
@@ -1714,8 +1714,8 @@ Byte  *s;
 
   o = oo;
 
-  if ( (oo = (Byte *)realloc( o, strlen( o ) + 1 )) == NULL ) {
-    free( o );
+  if ( (oo = (Byte *)LDAP_REALLOC( o, strlen( o ) + 1 )) == NULL ) {
+    LDAP_FREE( o );
     return( NULL );
   }
 
@@ -1731,7 +1731,7 @@ Byte  *s;
    that conversion is language dependent.
 */
 
-static Couple last_t61_printabled[32] = {
+static const Couple last_t61_printabled[32] = {
        {0,0},     {'A','E'}, {'D',0},   {0,0},
        {'H',0},   {0,0},     {'I','J'}, {'L',0},
        {'L',0},   {'O',0},   {'O','E'}, {0,0},
@@ -1747,9 +1747,9 @@ Byte  *s;
 {
   Byte   *o, *oo;
   Byte   n;
-  Couple *cc;
+  const Couple *cc;
 
-  if ( (o = oo = (Byte *)malloc( 2 * strlen( s ) + 64 )) == NULL ) {
+  if ( (o = oo = (Byte *)LDAP_MALLOC( 2 * strlen( s ) + 64 )) == NULL ) {
         return( NULL );
   }
 
@@ -1792,8 +1792,8 @@ Byte  *s;
 
   o = oo;
 
-  if ( (oo = (Byte *)realloc( o, strlen( o ) + 1 )) == NULL ) {
-    free( o );
+  if ( (oo = (Byte *)LDAP_REALLOC( o, strlen( o ) + 1 )) == NULL ) {
+    LDAP_FREE( o );
     return( NULL );
   }