]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/re.c
some more debug logging
[openldap] / servers / slurpd / re.c
index f063c39f96e82f9559ef941ffc59d0813fa0cec5..591db0d6462d41a2fd322df5d1583b6c98ce11ca 100644 (file)
@@ -1,10 +1,18 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2006 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
-/*
- * Copyright (c) 1996 Regents of the University of Michigan.
+/* Portions Copyright (c) 1996 Regents of the University of Michigan.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * software without specific prior written permission. This software
  * is provided ``as is'' without express or implied warranty.
  */
+/* ACKNOWLEDGEMENTS:
+ * This work was originally developed by the University of Michigan
+ * (as part of U-MICH LDAP).
+ */
 
 /* 
  * re.c - routines which deal with Re (Replication entry) structures.
@@ -37,6 +49,7 @@
 
 #include "slurp.h"
 #include "globals.h"
+#include "lutil.h"
 
 /* Forward references */
 static Rh      *get_repl_hosts LDAP_P(( char *, int *, char ** ));
@@ -82,14 +95,9 @@ Re_free(
        return 0;
     }
     if ( re->re_refcnt > 0 ) {
-#ifdef NEW_LOGGING
-       LDAP_LOG ( SLURPD, WARNING, "Re_free: "
-               "Warning: freeing re (dn: %s) with nonzero refcnt\n", re->re_dn, 0, 0 );
-#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 );
@@ -141,19 +149,11 @@ Re_parse(
     int                        nreplicas;
 
     if ( re == NULL ) {
-#ifdef NEW_LOGGING
-       LDAP_LOG ( SLURPD, ERR, "Re_parse: Error: re is NULL\n", 0, 0, 0 );
-#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 ( SLURPD, ERR, "Re_parse: Error: replbuf is NULL\n", 0, 0, 0 );
-#else
        Debug( LDAP_DEBUG_ANY, "Re_parse: error: replbuf is NULL\n", 0, 0, 0 );
-#endif
        return -1;
     }
 
@@ -178,14 +178,9 @@ Re_parse(
        }
        buflen = strlen( buf );
        if ( ldif_parse_line( buf, &type, &value, &len ) < 0 ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG ( SLURPD, ERR, 
-                       "Re_parse: Error: malformed replog file\n", 0, 0, 0 );
-#else
            Debug( LDAP_DEBUG_ANY,
                    "Error: Re_parse: malformed replog file\n",
                    0, 0, 0 );
-#endif
            return -1;
        }
        switch ( gettype( type )) {
@@ -193,17 +188,30 @@ Re_parse(
            re->re_changetype = getchangetype( value );
            state |= GOT_CHANGETYPE;
            break;
-       case T_TIME:
+       case T_TIME: {
+           unsigned long       t;
+
            if (( p = strchr( value, '.' )) != NULL ) {
                /* there was a sequence number */
                *p++ = '\0';
            }
-           re->re_timestamp = atol( value );
-           if ( p != NULL && isdigit( (unsigned char) *p )) {
-               re->re_seq = atoi( p );
+           if ( lutil_atoul( &t, value ) != 0 ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "Error: Re_parse: unable to parse timestamp \"%s\"\n",
+                       value, 0, 0 );
+               return -1;
+           }
+           re->re_timestamp = (time_t)t;
+           if ( p != NULL && isdigit( (unsigned char) *p )
+               && lutil_atoi( &re->re_seq, p ) != 0 )
+           {
+               Debug( LDAP_DEBUG_ANY,
+                       "Error: Re_parse: unable to parse sequence number \"%s\"\n",
+                       p, 0, 0 );
+               return -1;
            }
            state |= GOT_TIME;
-           break;
+           break;
        case T_DN:
            re->re_dn = ch_malloc( len + 1 );
                AC_MEMCPY( re->re_dn, value, len );
@@ -212,14 +220,9 @@ Re_parse(
            break;
        default:
            if ( !( state == GOT_ALL )) {
-#ifdef NEW_LOGGING
-               LDAP_LOG ( SLURPD, ERR, 
-                       "Re_parse: Error: bad type <%s>\n", type, 0, 0 );
-#else
                Debug( LDAP_DEBUG_ANY,
                        "Error: Re_parse: bad type <%s>\n",
                        type, 0, 0 );
-#endif
                free( type );
                free( value );
                return -1;
@@ -230,14 +233,9 @@ Re_parse(
     }
 
     if ( state != GOT_ALL ) {
-#ifdef NEW_LOGGING
-       LDAP_LOG ( SLURPD, ERR, 
-               "Re_parse: Error: malformed replog file\n", 0, 0, 0 );
-#else
        Debug( LDAP_DEBUG_ANY,
                "Error: Re_parse: malformed replog file\n",
                0, 0, 0 );
-#endif
        return -1;
     }
 
@@ -253,14 +251,9 @@ Re_parse(
            value = NULL;
        } else {
            if ( ldif_parse_line( buf, &type, &value, &len ) < 0 ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG ( SLURPD, ERR, 
-                       "Re_parse: Error: malformed replog line \"%s\"\n", buf, 0, 0 );
-#else
                Debug( LDAP_DEBUG_ANY,
                        "Error: malformed replog line \"%s\"\n",
                        buf, 0, 0 );
-#endif
                return -1;
            }
        }
@@ -342,12 +335,12 @@ get_repl_hosts(
        if ( ldif_parse_line( line, &type, &value, &len ) < 0 ) {
            return( NULL );
        }
-       port = 0;
+       port = LDAP_PORT;
        if (( p = strchr( value, ':' )) != NULL ) {
            *p = '\0';
            p++;
-           if ( *p != '\0' ) {
-               port = atoi( p );
+           if ( *p != '\0' && lutil_atoi( &port, p ) != 0 ) {
+               return( NULL );
            }
        }
 
@@ -371,13 +364,8 @@ get_repl_hosts(
 
        rh = (Rh *) ch_realloc((char *) rh, ( nreplicas + 2 ) * sizeof( Rh ));
        if ( rh == NULL ) {
-#ifdef NEW_LOGGING
-               LDAP_LOG ( SLURPD, ERR, 
-                       "get_repl_hosts: Out of memory\n", 0, 0, 0 );
-#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 );
@@ -449,6 +437,7 @@ getchangetype(
 
 
 
+#if 0
 /*
  * Find the first line which is not a "replica:" line in buf.
  * Returns a pointer to the line.  Returns NULL if there are
@@ -474,6 +463,7 @@ skip_replica_lines(
        }
     }
 }
+#endif /* 0 */
 
 
 
@@ -492,11 +482,7 @@ Re_dump(
     Mi *mi;
 
     if ( re == NULL ) {
-#ifdef NEW_LOGGING
-       LDAP_LOG ( SLURPD, ERR, "Re_dump: re is NULL\n", 0, 0, 0 );
-#else
        Debug( LDAP_DEBUG_TRACE, "Re_dump: re is NULL\n", 0, 0, 0 );
-#endif
        return;
     }
     fprintf( fp, "Re_dump: ******\n" );
@@ -562,13 +548,8 @@ Re_write(
     int                rc = 0;
 
     if ( re == NULL || fp == NULL ) {
-#ifdef NEW_LOGGING
-       LDAP_LOG ( SLURPD, ERR, 
-               "Re_write: Internal error: NULL argument\n", 0, 0, 0 );
-#else
        Debug( LDAP_DEBUG_ANY, "Internal error: Re_write: NULL argument\n",
                0, 0, 0 );
-#endif
        return -1;
     }
 
@@ -577,11 +558,18 @@ Re_write(
     }
 
     if ( ri != NULL ) {                /* write a single "replica:" line */
-       if ( fprintf( fp, "replica: %s:%d\n", ri->ri_hostname,
-               ri->ri_port ) < 0 ) {
+       if ( ri->ri_port != 0 ) {
+           rc = fprintf( fp, "replica: %s:%d\n", ri->ri_hostname,
+                   ri->ri_port );
+       } else {
+           rc = fprintf( fp, "replica: %s\n", ri->ri_hostname );
+       }
+       if ( rc < 0 ) {
            rc = -1;
            goto bad;
        }
+       rc = 0;
+
     } else {                   /* write multiple "replica:" lines */
        for ( i = 0; re->re_replicas && re->re_replicas[ i ].rh_hostname != NULL; i++ ) {
            if ( fprintf( fp, "replica: %s:%d\n",
@@ -656,13 +644,8 @@ Re_write(
     }
 bad:
     if ( rc != 0 ) {
-#ifdef NEW_LOGGING
-       LDAP_LOG ( SLURPD, ERR, 
-               "Re_write: Error while writing: %s\n", sys_errlist[ errno ], 0, 0 );
-#else
        Debug( LDAP_DEBUG_ANY, "Error while writing: %s\n",
                sys_errlist[ errno ], 0, 0 );
-#endif
     }
     return rc;
 }
@@ -799,15 +782,9 @@ warn_unknown_replica(
        }
     }
     if ( !found ) {
-#ifdef NEW_LOGGING
-       LDAP_LOG ( SLURPD, WARNING, "warn_unknown_replica: "
-               "Warning: unknown replica %s:%d found in replication log\n",
-               host, port, 0 );
-#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 );