struct hostent **result,
int *herrno_ptr ));
+
+/* charray.c */
+
+LDAP_F( int )
+ldap_charray_add LDAP_P((
+ char ***a,
+ char *s ));
+
+LDAP_F( int )
+ldap_charray_merge LDAP_P((
+ char ***a,
+ char **s ));
+
+LDAP_F( void )
+ldap_charray_free LDAP_P(( char **a ));
+
+LDAP_F( int )
+ldap_charray_inlist LDAP_P((
+ char **a,
+ char *s ));
+
+LDAP_F( char ** )
+ldap_charray_dup LDAP_P(( char **a ));
+
+LDAP_F( char ** )
+ldap_str2charray LDAP_P((
+ char *str,
+ char *brkstr ));
+
LDAP_END_DECL
#endif
free.c disptmpl.c srchpref.c dsparse.c tmplout.c sort.c \
getdn.c getentry.c getattr.c getvalues.c addentry.c \
request.c getdxbyname.c os-ip.c url.c charset.c \
- init.c options.c print.c string.c util-int.c schema.c
+ init.c options.c print.c string.c util-int.c schema.c \
+ charray.c digest.c
OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \
controls.lo messages.lo references.lo extended.lo \
modify.lo add.lo modrdn.lo delete.lo abandon.lo ufn.lo cache.lo \
free.lo disptmpl.lo srchpref.lo dsparse.lo tmplout.lo sort.lo \
getdn.lo getentry.lo getattr.lo getvalues.lo addentry.lo \
request.lo getdxbyname.lo os-ip.lo url.lo charset.lo \
- init.lo options.lo print.lo string.lo util-int.lo schema.lo
+ init.lo options.lo print.lo string.lo util-int.lo schema.lo \
+ charray.lo digest.lo
LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries
--- /dev/null
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/* charray.c - routines for dealing with char * arrays */
+
+#include "portable.h"
+
+#include <stdio.h>
+
+#include <ac/string.h>
+#include <ac/socket.h>
+
+#include "ldap-int.h"
+
+int
+ldap_charray_add(
+ char ***a,
+ char *s
+)
+{
+ int n;
+
+ if ( *a == NULL ) {
+ *a = (char **) LDAP_MALLOC( 2 * sizeof(char *) );
+ n = 0;
+ } else {
+ for ( n = 0; *a != NULL && (*a)[n] != NULL; n++ ) {
+ ; /* NULL */
+ }
+
+ *a = (char **) LDAP_REALLOC( (char *) *a,
+ (n + 2) * sizeof(char *) );
+ }
+
+ if( *a == NULL ) {
+ return -1;
+ }
+
+ (*a)[n] = LDAP_STRDUP(s);
+
+ if( (*a)[n] == NULL ) {
+ return 1;
+ }
+
+ (*a)[++n] = NULL;
+
+ return 0;
+}
+
+int
+ldap_charray_merge(
+ char ***a,
+ char **s
+)
+{
+ int i, n, nn;
+ char **aa;
+
+ for ( n = 0; *a != NULL && (*a)[n] != NULL; n++ ) {
+ ; /* NULL */
+ }
+ for ( nn = 0; s[nn] != NULL; nn++ ) {
+ ; /* NULL */
+ }
+
+ aa = (char **) LDAP_REALLOC( (char *) *a, (n + nn + 1) * sizeof(char *) );
+
+ if( aa == NULL )
+ return -1;
+
+ *a = aa;
+
+ for ( i = 0; i < nn; i++ ) {
+ (*a)[n + i] = LDAP_STRDUP(s[i]);
+
+ if( (*a)[n + i] == NULL ) {
+ for( --i ; i >= 0 ; i-- ) {
+ LDAP_FREE( (*a)[n + i] );
+ (*a)[n + i] = NULL;
+ }
+ return -1;
+ }
+ }
+
+ (*a)[n + nn] = NULL;
+ return 0;
+}
+
+void
+ldap_charray_free( char **a )
+{
+ char **p;
+
+ if ( a == NULL ) {
+ return;
+ }
+
+ for ( p = a; *p != NULL; p++ ) {
+ if ( *p != NULL ) {
+ LDAP_FREE( *p );
+ }
+ }
+
+ LDAP_FREE( (char *) a );
+}
+
+int
+ldap_charray_inlist(
+ char **a,
+ char *s
+)
+{
+ int i;
+
+ for ( i = 0; a[i] != NULL; i++ ) {
+ if ( strcasecmp( s, a[i] ) == 0 ) {
+ return( 1 );
+ }
+ }
+
+ return( 0 );
+}
+
+char **
+ldap_charray_dup( char **a )
+{
+ int i;
+ char **new;
+
+ for ( i = 0; a[i] != NULL; i++ )
+ ; /* NULL */
+
+ new = (char **) LDAP_MALLOC( (i + 1) * sizeof(char *) );
+
+ if( new == NULL ) {
+ return NULL;
+ }
+
+ for ( i = 0; a[i] != NULL; i++ ) {
+ new[i] = LDAP_STRDUP( a[i] );
+
+ if( new[i] == NULL ) {
+ for( --i ; i >= 0 ; i-- ) {
+ LDAP_FREE( new[i] );
+ }
+ LDAP_FREE( new );
+ return NULL;
+ }
+ }
+ new[i] = NULL;
+
+ return( new );
+}
+
+char **
+ldap_str2charray( char *str, char *brkstr )
+{
+ char **res;
+ char *s;
+ char *lasts;
+ int i;
+
+ /* protect the input string from strtok */
+ str = LDAP_STRDUP( str );
+ if( str == NULL ) {
+ return NULL;
+ }
+
+ i = 1;
+ for ( s = str; *s; s++ ) {
+ if ( strchr( brkstr, *s ) != NULL ) {
+ i++;
+ }
+ }
+
+ res = (char **) LDAP_MALLOC( (i + 1) * sizeof(char *) );
+
+ if( res == NULL ) {
+ LDAP_FREE( str );
+ return NULL;
+ }
+
+ i = 0;
+
+ for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
+ s != NULL;
+ s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
+ {
+ res[i] = LDAP_STRDUP( s );
+
+ if(res[i] == NULL) {
+ for( --i ; i >= 0 ; i-- ) {
+ LDAP_FREE( res[i] );
+ }
+ LDAP_FREE( res );
+ LDAP_FREE( str );
+ return NULL;
+ }
+
+ i++;
+ }
+
+ res[i] = NULL;
+
+ LDAP_FREE( str );
+ return( res );
+}
--- /dev/null
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/* digest.c:
+ * DIGEST-MD5 routines
+ */
+
+#include <portable.h>
+
+#include <ac/ctype.h>
+#include <ac/string.h>
+#include <ac/time.h>
+
+#include "ldap-int.h"
+#include <ldap_pvt.h>
+
+#define TK_NOENDQUOTE -2
+#define TK_OUTOFMEM -1
+
+#define TK_EOS 0
+#define TK_UNEXPCHAR 1
+#define TK_BAREWORD 2
+#define TK_COMMA 3
+#define TK_EQUALS 4
+#define TK_QDSTRING 5
+
+struct token {
+ int type;
+ char *sval;
+};
+
+static int
+get_token(const char ** sp, char ** token_val)
+{
+ int kind;
+ const char * p;
+ const char * q;
+ char * res;
+
+ *token_val = NULL;
+
+ if( (**sp) != '\0' || iscntrl(**sp) || !isascii(**sp) ) {
+ (*sp)++;
+ return TK_UNEXPCHAR;
+ }
+
+ switch (**sp) {
+ case '\0':
+ kind = TK_EOS;
+ (*sp)++;
+ break;
+
+ case ',':
+ kind = TK_COMMA;
+ (*sp)++;
+ break;
+
+ case '=':
+ kind = TK_EQUALS;
+ (*sp)++;
+ break;
+
+ case '\"':
+ kind = TK_QDSTRING;
+ (*sp)++;
+
+ for (p = *sp;
+ **sp != '\"' && **sp != '\0' && isascii(**sp);
+ (*sp)++ )
+ {
+ if(**sp == '\\') {
+ (*sp)++;
+ if( **sp == '\0' ) break;
+ }
+ }
+
+ if ( **sp == '\"' ) {
+ q = *sp;
+ res = LDAP_MALLOC(q-p+1);
+ if ( !res ) {
+ kind = TK_OUTOFMEM;
+ } else {
+ strncpy(res,p,q-p);
+ res[q-p] = '\0';
+ *token_val = res;
+ }
+ (*sp)++;
+
+ } else {
+ kind = TK_NOENDQUOTE;
+ }
+
+ break;
+
+ default:
+ kind = TK_BAREWORD;
+ p = *sp;
+ while ( isascii(**sp) &&
+ !iscntrl(**sp) &&
+ !isspace(**sp) &&
+ **sp != '(' &&
+ **sp != ')' &&
+ **sp != '<' &&
+ **sp != '>' &&
+ **sp != '@' &&
+ **sp != ',' &&
+ **sp != ';' &&
+ **sp != ':' &&
+ **sp != '\\'&&
+ **sp != '\"'&&
+ **sp != '/' &&
+ **sp != '[' &&
+ **sp != ']' &&
+ **sp != '?' &&
+ **sp != '=' &&
+ **sp != '{' &&
+ **sp != '}' &&
+ **sp != '\0' )
+ (*sp)++;
+ q = *sp;
+ res = LDAP_MALLOC(q-p+1);
+ if ( !res ) {
+ kind = TK_OUTOFMEM;
+ } else {
+ strncpy(res,p,q-p);
+ res[q-p] = '\0';
+ *token_val = res;
+ }
+ }
+
+ return kind;
+}
+
+struct kv {
+ char *key;
+ char *value;
+};
+
+static void kv_destory( struct kv **kv )
+{
+ int i;
+
+ if( kv == NULL ) return;
+
+ for( i=0; kv[i] != NULL; i++ ) {
+ if( kv[i]->key != NULL ) {
+ LDAP_FREE( kv[i]->key );
+ }
+
+ if( kv[i]->value != NULL ) {
+ LDAP_FREE( kv[i]->value );
+ }
+
+ LDAP_FREE( kv[i] );
+ }
+
+ LDAP_FREE( kv );
+}
+
+static int kv_add( struct kv ***kvs, const struct kv *kv )
+{
+ int n;
+ struct kv **tmp_kvs;
+ struct kv *tmp_kv;
+
+ assert( kvs != NULL );
+ assert( kv != NULL );
+
+ tmp_kv = LDAP_MALLOC( sizeof(struct kv) );
+
+ if( tmp_kv == NULL ) {
+ return -1;
+ }
+
+ *tmp_kv = *kv;
+
+ if( *kvs == NULL ) {
+ tmp_kvs = LDAP_MALLOC( 2 * sizeof(struct kv *) );
+ n = 0;
+
+ } else {
+ for( n=0; (*kvs)[n] != NULL; n++ ) {
+ /* EMPTY */ ;
+ }
+
+ tmp_kvs = LDAP_REALLOC( kvs, (n+2) * sizeof(struct kv *) );
+ }
+
+ if( tmp_kvs == NULL ) {
+ LDAP_FREE( tmp_kv );
+ return -1;
+ }
+
+ *kvs = tmp_kvs;
+ kvs[n] = tmp_kvs;
+ kvs[n+1] = NULL;
+
+ return 0;
+}
+
+#define ST_ERROR -1
+#define ST_DONE 0
+#define ST_KEY 1
+#define ST_EQUALS 2
+#define ST_VALUE 3
+#define ST_SEP 4
+
+static int
+parse_key_value(
+ struct kv ***kvsp,
+ const char *str )
+{
+ int rc = 0;
+ int kind, state;
+ const char *ss = str;
+ char *sval;
+
+ struct kv **kvs = NULL;
+ struct kv kv;
+
+ assert( kvsp != NULL );
+ assert( str != NULL );
+
+ kv.key = NULL;
+ kv.value = NULL;
+
+ state = ST_KEY;
+
+ while( state > ST_DONE ) {
+ kind = get_token( &ss, &sval );
+ switch( kind ) {
+ case TK_EOS:
+ state = ( state == ST_SEP )
+ ? ST_DONE : ST_ERROR;
+ break;
+
+ case TK_BAREWORD:
+ if( state == ST_KEY ) {
+ state = ST_EQUALS;
+
+ assert( kv.key == NULL );
+ assert( kv.value == NULL );
+ kv.key = sval;
+
+ } else if ( state == ST_VALUE ) {
+ state = ST_SEP;
+
+ assert( kv.key != NULL );
+ assert( kv.value == NULL );
+ kv.value = sval;
+
+ } else {
+ state = ST_ERROR;
+ }
+ break;
+
+ case TK_COMMA:
+ state = ( state == ST_SEP )
+ ? ST_KEY : ST_ERROR;
+ break;
+
+ case TK_EQUALS:
+ state = ( state == ST_EQUALS )
+ ? ST_VALUE : ST_ERROR;
+ break;
+
+ case TK_QDSTRING:
+ if( state == ST_VALUE ) {
+ state = ST_SEP;
+
+ assert( kv.key != NULL );
+ assert( kv.value == NULL );
+ kv.value = sval;
+
+ } else {
+ state = ST_ERROR;
+ }
+ break;
+
+ default:
+ state = ST_ERROR;
+ }
+
+ if( state == ST_SEP ) {
+ /* add kv to return */
+ if( kv_add( &kvs, &kv ) != 0 ) {
+ state = ST_ERROR;
+ kind = TK_OUTOFMEM;
+
+ } else {
+ kv.key = NULL;
+ kv.value = NULL;
+ }
+ }
+ }
+
+ if( state == ST_ERROR ) {
+ if( kv.key != NULL ) LDAP_FREE(kv.key);
+ if( kv.value != NULL ) LDAP_FREE( kv.value );
+
+ kv_destory( kvs );
+ kvs = NULL;
+
+ rc = ( kind == TK_OUTOFMEM ) ? -1 : 1 ;
+ }
+
+ *kvsp = kvs;
+ return rc;
+}
+
+static int
+parse_value_list(
+ char ***valuesp,
+ const char* str )
+{
+ int rc = 0;
+ char **values = NULL;
+
+ int kind, state;
+ const char *ss = str;
+ char *sval;
+
+ assert( valuesp != NULL );
+ assert( str != NULL );
+
+ state = ST_VALUE;
+
+ while( state > ST_DONE ) {
+ kind = get_token( &ss, &sval );
+ switch( kind ) {
+ case TK_EOS:
+ state = ( state == ST_SEP )
+ ? ST_DONE : ST_ERROR;
+ break;
+
+ case TK_BAREWORD:
+ if( state == ST_VALUE ) {
+ state = ST_SEP;
+
+ } else {
+ state = ST_ERROR;
+ }
+ break;
+
+ case TK_COMMA:
+ state = ( state == ST_SEP )
+ ? ST_VALUE : ST_ERROR;
+ break;
+
+ default:
+ state = ST_ERROR;
+ }
+
+ if( state == ST_SEP ) {
+ if( ldap_charray_add( &values, sval ) != 0 ) {
+ state = ST_ERROR;
+ kind = TK_OUTOFMEM;
+ }
+
+ LDAP_FREE( sval );
+ sval = NULL;
+ }
+ }
+
+ if( state == ST_ERROR ) {
+ if( sval != NULL ) LDAP_FREE( sval );
+
+ LDAP_VFREE( values );
+ values = NULL;
+
+ rc = ( kind == TK_OUTOFMEM ) ? -1 : 1 ;
+ }
+
+ *valuesp = values;
+ return rc;
+}
# End Source File
# Begin Source File
+SOURCE=.\charray.c
+# End Source File
+# Begin Source File
+
SOURCE=.\charset.c
# End Source File
# Begin Source File
# End Source File
# Begin Source File
+SOURCE=.\digest.c
+# End Source File
+# Begin Source File
+
SOURCE=.\disptmpl.c
# End Source File
# Begin Source File
free.c disptmpl.c srchpref.c dsparse.c tmplout.c sort.c \
getdn.c getentry.c getattr.c getvalues.c addentry.c \
request.c getdxbyname.c os-ip.c url.c charset.c \
- init.c options.c print.c string.c util-int.c schema.c
+ init.c options.c print.c string.c util-int.c schema.c \
+ charray.c digest.c
SRCS = thr_posix.c thr_cthreads.c thr_thr.c thr_lwp.c thr_nt.c \
thr_sleep.c thr_stub.c rdwr.c
OBJS = extended.lo \
request.lo getdxbyname.lo os-ip.lo url.lo charset.lo \
init.lo options.lo print.lo string.lo util-int.lo schema.lo \
thr_posix.lo thr_cthreads.lo thr_thr.lo thr_lwp.lo thr_nt.lo \
- thr_sleep.lo thr_stub.lo rdwr.lo
+ thr_sleep.lo thr_stub.lo rdwr.lo \
+ charray.lo digest.lo
LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries
# End Source File
# Begin Source File
+SOURCE=..\libldap\charray.c
+# End Source File
+# Begin Source File
+
SOURCE=..\libldap\charset.c
# End Source File
# Begin Source File
# End Source File
# Begin Source File
+SOURCE=..\libldap\digest.c
+# End Source File
+# Begin Source File
+
SOURCE=..\libldap\disptmpl.c
# End Source File
# Begin Source File