Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

ldap_utils.cc File Reference

#include "ldapconf_defs.h"
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>

Go to the source code of this file.

Functions

int dns2dc (char *buf,int size,int strip_hostname)
int dc2dns (char *buf,int size)
int dc2list (const char *dc_str, SSTRINGS &dc_lst)
int str_chop_num (const char *str)
int str_conv_ascii (const char *str)
int latin1_to_UTF8 (int argc, char** argv)
int UTF8_to_latin1 (int argc, char** argv)

Variables

char UTF8len [64]


Function Documentation

int dns2dc ( char * buf,
int size,
int strip_hostname )
 

Definition at line 26 of file ldap_utils.cc.

Referenced by LDAPDB::init(), ldap_client_config(), and ldap_system_config().

00027 {
00028     SSTRING base;
00029     SSTRINGS dc;
00030     
00031     str_splitline(buf,'.',dc);
00032     if (strip_hostname){
00033         dc.remove_del(dc.getitem(0));
00034     }
00035 
00036     for (int i=0; i<dc.getnb(); i++){
00037         if (i>0) {
00038             base.append(",");
00039         }
00040         sprintf(buf,"dc=%s",dc.getitem(i)->get());
00041         base.append(buf);
00042     }
00043     strcpy(buf,base.get());
00044 
00045     return 0;
00046 }

int dc2dns ( char * buf,
int size )
 

Definition at line 53 of file ldap_utils.cc.

Referenced by LDAPDB::create().

00054 {
00055     SSTRING base;
00056     SSTRINGS dc;
00057     SSTRINGS tb;
00058     
00059     // Split componenents
00060     str_splitline(buf,',',dc);
00061 
00062     for (int i=0; i<dc.getnb(); i++){
00063         tb.remove_all();
00064         // Remove assignement
00065         str_splitline(dc.getitem(i)->get(),'=',tb);
00066         if (i>0) {
00067             base.append(".");
00068         }
00069         sprintf(buf,"%s",tb.getitem(1)->get());
00070         base.append(buf);
00071     }
00072     strcpy(buf,base.get());
00073 
00074     return 0;
00075 }

int dc2list ( const char * dc_str,
SSTRINGS & dc_lst )
 

Definition at line 82 of file ldap_utils.cc.

Referenced by LDAPDB::create().

00083 {
00084     SSTRINGS dc;
00085     SSTRINGS tb;
00086 
00087     // Split componenents
00088     str_splitline(dc_str,',',dc);
00089 
00090     for (int i=0; i<dc.getnb(); i++){
00091         tb.remove_all();
00092         // Remove assignement
00093         D(debugf(4,"dc2list: comp= %s\n",dc.getitem(i)->get()));
00094         str_splitline(dc.getitem(i)->get(),'=',tb);
00095         dc_lst.add(new SSTRING(tb.getitem(1)->get()));
00096     }
00097 
00098     return 0;
00099 }

int str_chop_num ( const char * str )
 

Definition at line 108 of file ldap_utils.cc.

00108                                  {
00109 
00110     int n = strlen(str);
00111 
00112 
00113     for (int i=n; i >= 0; i--){
00114     }
00115 
00116     return n;
00117 }

int str_conv_ascii ( const char * str )
 

Definition at line 125 of file ldap_utils.cc.

Referenced by LDAPOBJECT::at_add(), and LDAPOBJECT::at_set().

00126 {
00127     D(debugf(4,"-->LDAP_UTILS::str_conv_ascii: (%s)",str));
00128 
00129     const char *p = NULL; 
00130     int c = 0;
00131 
00132     p = str;
00133     
00134     while (*p){
00135         if (!isascii(*p)){ // Non-ascii - convert it to '?' and increase counter.
00136             D(debugf(3,"Non-ascii character found %c",*p));
00137             // *p = '?';
00138             // Have to change a bit in ldapobject to get rid of the const
00139             c++;
00140         }
00141         p++;
00142     }
00143 
00144     D(debugf(4,"<--LDAP_UTILS::str_conv_ascii: (%s) %i",str,c));
00145     return c;
00146 }

int latin1_to_UTF8 ( int argc,
char ** argv )
 

Definition at line 165 of file ldap_utils.cc.

00166 {
00167     register int c;
00168     while ((c = getchar()) != EOF) {
00169         if ((c & 0x80) == 0) {
00170             putchar (c);
00171         } else {
00172             putchar (0xC0 | (0x03 & (c << 6)));
00173             putchar (0x80 | (0x3F & c));
00174         }
00175     }
00176     if ( ! feof (stdin)) {
00177         errno = ferror (stdin);
00178         perror (argv[0]);
00179     }
00180     return 0;
00181 }

int UTF8_to_latin1 ( int argc,
char ** argv )
 

Definition at line 197 of file ldap_utils.cc.

00198 {
00199     register int c;
00200     while ((c = getchar()) != EOF) {
00201         auto int len = UTF8len [(c >> 2) & 0x3F];
00202         register unsigned long u = 0;
00203         switch (len) {
00204         case 6: u = c & 0x01; break;
00205         case 5: u = c & 0x03; break;
00206         case 4: u = c & 0x07; break;
00207         case 3: u = c & 0x0F; break;
00208         case 2: u = c & 0x1F; break;
00209         case 1: u = c & 0x7F; break;
00210         case 0: /* erroneous: c is the middle of a character. */
00211             u = c & 0x3F; len = 5; break;
00212         }
00213         while (--len && (c = getchar()) != EOF) {
00214             if ((c & 0xC0) == 0x80) {
00215                 u = (u << 6) | (c & 0x3F);
00216             } else { /* unexpected start of a new character */
00217                 ungetc (c, stdin);
00218                 break;
00219             }
00220         }
00221         if (u <= 0xFF) {
00222             putchar (u);
00223         } else { /* this character can't be represented in Latin-1 */
00224             putchar ('?'); /* a reasonable alternative is 0x1A (SUB) */
00225         }
00226         if (c == EOF) break;
00227     }
00228     if ( ! feof (stdin)) {
00229         errno = ferror (stdin);
00230         perror (argv[0]);
00231     }
00232     return 0;
00233 }


Variable Documentation

char UTF8len[64] [static]
 

Initializer:

{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6}

Definition at line 192 of file ldap_utils.cc.


Generated at Mon Jan 22 08:35:13 2001 for ldapconf by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000