]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/re.c
Added a "dnattr" case for ACIs (still need to check the ACI OID).
[openldap] / servers / slurpd / re.c
index 64f9225ddb97383f354f52bea90a7f82fd74a671..df1780c49e060c902ff1d806ce7a1509af56f481 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright (c) 1996 Regents of the University of Michigan.
  * All rights reserved.
 #include "portable.h"
 
 #include <stdio.h>
+
+#include <ac/errno.h>
+#include <ac/socket.h>
 #include <ac/string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <ac/ctype.h>
 
-#include "../slapd/slap.h"
 #include "slurp.h"
 #include "globals.h"
 
-/* externs */
-extern char *str_getline LDAP_P(( char **next ));
-extern void ch_free LDAP_P(( char *p ));
-
-#ifdef DECL_SYS_ERRLIST
-extern char *sys_errlist[];
-#endif /* DECL_SYS_ERRLIST */
+#include "../slapd/slap.h"
 
 /* Forward references */
 static Rh      *get_repl_hosts LDAP_P(( char *, int *, char ** ));
@@ -66,6 +62,7 @@ Re_getnext(
 
 /*
  * Free an Re
+ * ??? Something should apparently return nonzero here, but I dont know what.
  */
 static int
 Re_free(
@@ -84,10 +81,9 @@ Re_free(
                "Warning: freeing re (dn: %s) with nonzero refcnt\n",
                re->re_dn, 0, 0 );
     }
-#if !defined( THREAD_SUNOS4_LWP )
-    /* This seems to have problems under SunOS lwp */
-    pthread_mutex_destroy( &re->re_mutex );
-#endif /* THREAD_SUNOS4_LWP */
+
+    ldap_pvt_thread_mutex_destroy( &re->re_mutex );
+
     ch_free( re->re_timestamp );
     if (( rh = re->re_replicas ) != NULL ) {
        for ( i = 0; rh[ i ].rh_hostname != NULL; i++ ) {
@@ -104,6 +100,7 @@ Re_free(
        free( mi );
     }
     free( re );
+    return 0;
 }
 
 
@@ -129,9 +126,9 @@ Re_parse(
     int                        state;
     int                        nml;
     char               *buf, *rp, *p;
-    long               buflen;
+    size_t             buflen;
     char               *type, *value;
-    int                        len;
+    ber_len_t  len;
     int                        nreplicas;
 
     if ( re == NULL ) {
@@ -151,7 +148,7 @@ Re_parse(
     re->re_refcnt = sglob->num_replicas;
 
     for (;;) {
-       if (( state == GOT_ALL ) || ( buf = str_getline( &rp )) == NULL ) {
+       if (( state == GOT_ALL ) || ( buf = ldif_getline( &rp )) == NULL ) {
            break;
        }
        /*
@@ -162,8 +159,8 @@ Re_parse(
        if ( strncmp( buf, ERROR_STR, strlen( ERROR_STR )) == 0 ) {
            continue;
        }
-       buflen = ( long ) strlen( buf );
-       if ( str_parse_line( buf, &type, &value, &len ) < 0 ) {
+       buflen = strlen( buf );
+       if ( ldif_parse_line( buf, &type, &value, &len ) < 0 ) {
            Debug( LDAP_DEBUG_ANY,
                    "Error: Re_parse: malformed replog file\n",
                    0, 0, 0 );
@@ -180,7 +177,7 @@ Re_parse(
                *p++ = '\0';
            }
            re->re_timestamp = strdup( value );
-           if ( p != NULL && isdigit( *p )) {
+           if ( p != NULL && isdigit( (unsigned char) *p )) {
                re->re_seq = atoi( p );
            }
            state |= GOT_TIME;
@@ -196,9 +193,15 @@ Re_parse(
                Debug( LDAP_DEBUG_ANY,
                        "Error: Re_parse: bad type <%s>\n",
                        type, 0, 0 );
+               free( type );
+               if ( value != NULL )
+                       free( value );
                return -1;
            }
        }
+       free( type );
+       if ( value != NULL )
+               free( value );
     }
 
     if ( state != GOT_ALL ) {
@@ -209,15 +212,17 @@ Re_parse(
     }
 
     for (;;) {
-       if (( buf = str_getline( &rp )) == NULL ) {
+       char *const dash = "-";
+
+       if (( buf = ldif_getline( &rp )) == NULL ) {
            break;
        }
-       buflen = ( long ) strlen( buf );
+       buflen = strlen( buf );
        if (( buflen == 1 ) && ( buf[ 0 ] == '-' )) {
-           type = "-";
+           type  = dash;
            value = NULL;
        } else {
-           if ( str_parse_line( buf, &type, &value, &len ) < 0 ) {
+           if ( ldif_parse_line( buf, &type, &value, &len ) < 0 ) {
                Debug( LDAP_DEBUG_ANY,
                        "Error: malformed replog line \"%s\"\n",
                        buf, 0, 0 );
@@ -239,6 +244,11 @@ Re_parse(
        re->re_mods[ nml + 1 ].mi_type = NULL;
        re->re_mods[ nml + 1 ].mi_val = NULL;
        nml++;
+
+       if ( type != dash )
+               free( type );
+       if ( value != NULL )
+               free( value );
     }
     return 0;
 }
@@ -260,10 +270,10 @@ get_repl_hosts(
     char       **r_rp
 )
 {
-    char               buf[ LINE_WIDTH + 1 ];
     char               *type, *value, *line, *p;
     Rh                 *rh = NULL;
-    int                        nreplicas, len;
+    int                        nreplicas;
+       ber_len_t       len;
     int                        port;
     int                        repl_ok;
     int                        i;
@@ -282,7 +292,7 @@ get_repl_hosts(
     for (;;) {
        /* If this is a reject log, we need to skip over the ERROR: line */
        if ( !strncmp( *r_rp, ERROR_STR, strlen( ERROR_STR ))) {
-           line = str_getline( r_rp );
+           line = ldif_getline( r_rp );
            if ( line == NULL ) {
                break;
            }
@@ -290,14 +300,14 @@ get_repl_hosts(
        if ( strncasecmp( *r_rp, "replica:", 7 )) {
            break;
        }
-       line = str_getline( r_rp );
+       line = ldif_getline( r_rp );
        if ( line == NULL ) {
            break;
        }
-       if ( str_parse_line( line, &type, &value, &len ) < 0 ) {
+       if ( ldif_parse_line( line, &type, &value, &len ) < 0 ) {
            return( NULL );
        }
-       port = LDAP_PORT;
+       port = 0;
        if (( p = strchr( value, ':' )) != NULL ) {
            *p = '\0';
            p++;
@@ -317,8 +327,11 @@ get_repl_hosts(
                break;
            }
        }
+       free( type );
        if ( !repl_ok ) {
            warn_unknown_replica( value, port );
+           if ( value != NULL )
+               free( value );
            continue;
        }
 
@@ -331,6 +344,9 @@ get_repl_hosts(
        rh[ nreplicas ].rh_hostname = strdup( value );
        rh[ nreplicas ].rh_port = port;
        nreplicas++;
+
+       if ( value != NULL )
+               free( value );
     }
 
     if ( nreplicas == 0 ) {
@@ -502,7 +518,6 @@ Re_write(
     int                i;
     char       *s;
     int                rc = 0;
-    Rh         *rh;
 
     if ( re == NULL || fp == NULL ) {
        Debug( LDAP_DEBUG_ANY, "Internal error: Re_write: NULL argument\n",
@@ -571,7 +586,8 @@ Re_write(
            }
        } else {
            char *obuf;
-           obuf = ldif_type_and_value( re->re_mods[ i ].mi_type,
+           obuf = ldif_put( LDIF_PUT_VALUE,
+                       re->re_mods[ i ].mi_type,
                    re->re_mods[ i ].mi_val ? re->re_mods[ i ].mi_val : "",
                    re->re_mods[ i ].mi_len );
            if ( fputs( obuf, fp ) < 0 ) {
@@ -579,7 +595,7 @@ Re_write(
                free( obuf );
                goto bad;
            } else {
-               free( obuf );
+               ber_memfree( obuf );
            }
        }
     }
@@ -646,7 +662,7 @@ Re_lock(
     Re *re
 )
 {
-    return( pthread_mutex_lock( &re->re_mutex ));
+    return( ldap_pvt_thread_mutex_lock( &re->re_mutex ));
 }
 
 
@@ -660,7 +676,7 @@ Re_unlock(
     Re *re
 )
 {
-    return( pthread_mutex_unlock( &re->re_mutex ));
+    return( ldap_pvt_thread_mutex_unlock( &re->re_mutex ));
 }
 
 
@@ -701,7 +717,7 @@ Re_init(
    (*re)->re_mods = NULL;
    (*re)->re_next = NULL;
 
-   pthread_mutex_init( &((*re)->re_mutex), pthread_mutexattr_default );
+   ldap_pvt_thread_mutex_init( &((*re)->re_mutex) );
    return 0;
 }