]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/re.c
Cleaned up getdn normalization
[openldap] / servers / slurpd / re.c
index 4d6ee77a65a76743aeeac3fc7f29e5ee01b202f5..7fd254893cf6b7ba015ca22ae2a2e17909f3d441 100644 (file)
@@ -1,3 +1,8 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * Copyright (c) 1996 Regents of the University of Michigan.
  * All rights reserved.
@@ -76,14 +81,18 @@ Re_free(
        return 0;
     }
     if ( re->re_refcnt > 0 ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG (( "re", LDAP_LEVEL_WARNING, "Re_free: "
+               "Warning: freeing re (dn: %s) with nonzero refcnt\n", re->re_dn ));
+#else
        Debug( LDAP_DEBUG_ANY,
                "Warning: freeing re (dn: %s) with nonzero refcnt\n",
                re->re_dn, 0, 0 );
+#endif
     }
 
     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++ ) {
            free( rh[ i ].rh_hostname );
@@ -131,11 +140,19 @@ Re_parse(
     int                        nreplicas;
 
     if ( re == NULL ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG (( "re", LDAP_LEVEL_ERR, "Re_parse: Error: re is NULL\n" ));
+#else
        Debug( LDAP_DEBUG_ANY, "Re_parse: error: re is NULL\n", 0, 0, 0 );
+#endif
        return -1;
     }
     if ( replbuf == NULL ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG (( "re", LDAP_LEVEL_ERR, "Re_parse: Error: replbuf is NULL\n" ));
+#else
        Debug( LDAP_DEBUG_ANY, "Re_parse: error: replbuf is NULL\n", 0, 0, 0 );
+#endif
        return -1;
     }
 
@@ -160,9 +177,14 @@ Re_parse(
        }
        buflen = strlen( buf );
        if ( ldif_parse_line( buf, &type, &value, &len ) < 0 ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG (( "re", LDAP_LEVEL_ERR, 
+                       "Re_parse: Error: malformed replog file\n" ));
+#else
            Debug( LDAP_DEBUG_ANY,
                    "Error: Re_parse: malformed replog file\n",
                    0, 0, 0 );
+#endif
            return -1;
        }
        switch ( gettype( type )) {
@@ -175,7 +197,7 @@ Re_parse(
                /* there was a sequence number */
                *p++ = '\0';
            }
-           re->re_timestamp = strdup( value );
+           re->re_timestamp = atol( value );
            if ( p != NULL && isdigit( (unsigned char) *p )) {
                re->re_seq = atoi( p );
            }
@@ -183,15 +205,20 @@ Re_parse(
            break;
        case T_DN:
            re->re_dn = ch_malloc( len + 1 );
-               memcpy( re->re_dn, value, len );
+               AC_MEMCPY( re->re_dn, value, len );
                re->re_dn[ len ]='\0';
            state |= GOT_DN;
            break;
        default:
            if ( !( state == GOT_ALL )) {
+#ifdef NEW_LOGGING
+               LDAP_LOG (( "re", LDAP_LEVEL_ERR, 
+                       "Re_parse: Error: bad type <%s>\n", type ));
+#else
                Debug( LDAP_DEBUG_ANY,
                        "Error: Re_parse: bad type <%s>\n",
                        type, 0, 0 );
+#endif
                free( type );
                if ( value != NULL )
                        free( value );
@@ -204,9 +231,14 @@ Re_parse(
     }
 
     if ( state != GOT_ALL ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG (( "re", LDAP_LEVEL_ERR, 
+               "Re_parse: Error: malformed replog file\n" ));
+#else
        Debug( LDAP_DEBUG_ANY,
                "Error: Re_parse: malformed replog file\n",
                0, 0, 0 );
+#endif
        return -1;
     }
 
@@ -222,9 +254,14 @@ Re_parse(
            value = NULL;
        } else {
            if ( ldif_parse_line( buf, &type, &value, &len ) < 0 ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG (( "re", LDAP_LEVEL_ERR, 
+                       "Re_parse: Error: malformed replog line \"%s\"\n", buf ));
+#else
                Debug( LDAP_DEBUG_ANY,
                        "Error: malformed replog line \"%s\"\n",
                        buf, 0, 0 );
+#endif
                return -1;
            }
        }
@@ -233,7 +270,7 @@ Re_parse(
        re->re_mods[ nml ].mi_type = strdup( type );
        if ( value != NULL ) {
            re->re_mods[ nml ].mi_val = ch_malloc( len + 1 );
-               memcpy( re->re_mods[ nml ].mi_val, value, len );
+               AC_MEMCPY( re->re_mods[ nml ].mi_val, value, len );
                re->re_mods[ nml ].mi_val[ len ] = '\0';
            re->re_mods[ nml ].mi_len = len;
        } else {
@@ -269,7 +306,6 @@ get_repl_hosts(
     char       **r_rp
 )
 {
-    char               buf[ LDIF_LINE_WIDTH + 1 ];
     char               *type, *value, *line, *p;
     Rh                 *rh = NULL;
     int                        nreplicas;
@@ -337,8 +373,13 @@ get_repl_hosts(
 
        rh = (Rh *) ch_realloc((char *) rh, ( nreplicas + 2 ) * sizeof( Rh ));
        if ( rh == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG (( "re", LDAP_LEVEL_ERR, 
+                       "get_repl_hosts: Out of memory\n" ));
+#else
            Debug( LDAP_DEBUG_ANY, "Out of memory in get_repl_hosts\n",
                    0, 0, 0 );
+#endif
            return NULL;
        }
        rh[ nreplicas ].rh_hostname = strdup( value );
@@ -454,12 +495,16 @@ Re_dump(
     Mi *mi;
 
     if ( re == NULL ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG (( "re", LDAP_LEVEL_ERR, "Re_dump: re is NULL\n" ));
+#else
        Debug( LDAP_DEBUG_TRACE, "Re_dump: re is NULL\n", 0, 0, 0 );
+#endif
        return;
     }
     fprintf( fp, "Re_dump: ******\n" );
     fprintf( fp, "re_refcnt: %d\n", re->re_refcnt );
-    fprintf( fp, "re_timestamp: %s\n", re->re_timestamp );
+    fprintf( fp, "re_timestamp: %ld\n", (long) re->re_timestamp );
     fprintf( fp, "re_seq: %d\n", re->re_seq );
     for ( i = 0; re->re_replicas && re->re_replicas[ i ].rh_hostname != NULL;
                i++ ) {
@@ -520,8 +565,13 @@ Re_write(
     int                rc = 0;
 
     if ( re == NULL || fp == NULL ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG (( "re", LDAP_LEVEL_ERR, 
+               "Re_write: Internal error: NULL argument\n" ));
+#else
        Debug( LDAP_DEBUG_ANY, "Internal error: Re_write: NULL argument\n",
                0, 0, 0 );
+#endif
        return -1;
     }
 
@@ -545,7 +595,7 @@ Re_write(
            }
        }
     }
-    if ( fprintf( fp, "time: %s.%d\n", re->re_timestamp, re->re_seq ) < 0 ) {
+    if ( fprintf( fp, "time: %ld.%d\n", (long) re->re_timestamp, re->re_seq ) < 0 ) {
        rc = -1;
        goto bad;
     }
@@ -609,8 +659,13 @@ Re_write(
     }
 bad:
     if ( rc != 0 ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG (( "re", LDAP_LEVEL_ERR, 
+               "Re_write: Error while writing: %s\n", sys_errlist[ errno ] ));
+#else
        Debug( LDAP_DEBUG_ANY, "Error while writing: %s\n",
                sys_errlist[ errno ], 0, 0 );
+#endif
     }
     return rc;
 }
@@ -709,7 +764,7 @@ Re_init(
 
     /* Initialize private data */
    (*re)->re_refcnt = sglob->num_replicas;
-   (*re)->re_timestamp = NULL;
+   (*re)->re_timestamp = (time_t) 0L;
    (*re)->re_replicas = NULL;
    (*re)->re_dn = NULL;
    (*re)->re_changetype = 0;
@@ -747,9 +802,15 @@ warn_unknown_replica(
        }
     }
     if ( !found ) {
+#ifdef NEW_LOGGING
+       LDAP_LOG (( "re", LDAP_LEVEL_WARNING, "warn_unknown_replica: "
+               "Warning: unknown replica %s:%d found in replication log\n",
+               host, port ));
+#else
        Debug( LDAP_DEBUG_ANY,
                "Warning: unknown replica %s:%d found in replication log\n",
                host, port, 0 );
+#endif
        nur++;
        ur = (Rh *) ch_realloc( (char *) ur, ( nur * sizeof( Rh )));
        ur[ nur - 1 ].rh_hostname = strdup( host );