]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/re.c
Make modify/increment conditional
[openldap] / servers / slurpd / re.c
index 7fd254893cf6b7ba015ca22ae2a2e17909f3d441..4e806abc8f7bd542f6b110243e48ed16c675d945 100644 (file)
@@ -1,10 +1,18 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2002 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-2003 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.
 
 #include <stdio.h>
 
+#include <ac/stdlib.h>
 #include <ac/errno.h>
 #include <ac/socket.h>
 #include <ac/string.h>
 #include <ac/ctype.h>
 
+#include "../slapd/slap.h"
+
 #include "slurp.h"
 #include "globals.h"
 
-#include "../slapd/slap.h"
-
 /* Forward references */
 static Rh      *get_repl_hosts LDAP_P(( char *, int *, char ** ));
 static int     gettype LDAP_P(( char * ));
@@ -82,8 +95,8 @@ Re_free(
     }
     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 ));
+       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",
@@ -141,7 +154,7 @@ Re_parse(
 
     if ( re == NULL ) {
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "re", LDAP_LEVEL_ERR, "Re_parse: Error: re is NULL\n" ));
+       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
@@ -149,7 +162,7 @@ Re_parse(
     }
     if ( replbuf == NULL ) {
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "re", LDAP_LEVEL_ERR, "Re_parse: Error: replbuf is NULL\n" ));
+       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
@@ -178,8 +191,8 @@ 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" ));
+               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",
@@ -212,28 +225,26 @@ Re_parse(
        default:
            if ( !( state == GOT_ALL )) {
 #ifdef NEW_LOGGING
-               LDAP_LOG (( "re", LDAP_LEVEL_ERR, 
-                       "Re_parse: Error: bad type <%s>\n", type ));
+               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 );
-               if ( value != NULL )
-                       free( value );
+               free( value );
                return -1;
            }
        }
        free( type );
-       if ( value != NULL )
-               free( value );
+       free( value );
     }
 
     if ( state != GOT_ALL ) {
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "re", LDAP_LEVEL_ERR, 
-               "Re_parse: Error: malformed replog file\n" ));
+       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",
@@ -255,8 +266,8 @@ Re_parse(
        } 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 ));
+               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",
@@ -366,16 +377,15 @@ get_repl_hosts(
        free( type );
        if ( !repl_ok ) {
            warn_unknown_replica( value, port );
-           if ( value != NULL )
-               free( value );
+           free( value );
            continue;
        }
 
        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" ));
+               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 );
@@ -386,8 +396,7 @@ get_repl_hosts(
        rh[ nreplicas ].rh_port = port;
        nreplicas++;
 
-       if ( value != NULL )
-               free( value );
+       free( value );
     }
 
     if ( nreplicas == 0 ) {
@@ -496,7 +505,7 @@ Re_dump(
 
     if ( re == NULL ) {
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "re", LDAP_LEVEL_ERR, "Re_dump: re is NULL\n" ));
+       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
@@ -566,8 +575,8 @@ Re_write(
 
     if ( re == NULL || fp == NULL ) {
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "re", LDAP_LEVEL_ERR, 
-               "Re_write: Internal error: NULL argument\n" ));
+       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 );
@@ -586,7 +595,7 @@ Re_write(
            goto bad;
        }
     } else {                   /* write multiple "replica:" lines */
-       for ( i = 0; re->re_replicas[ i ].rh_hostname != NULL; i++ ) {
+       for ( i = 0; re->re_replicas && re->re_replicas[ i ].rh_hostname != NULL; i++ ) {
            if ( fprintf( fp, "replica: %s:%d\n",
                    re->re_replicas[ i ].rh_hostname,
                    re->re_replicas[ i ].rh_port ) < 0 ) {
@@ -660,8 +669,8 @@ 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 ] ));
+       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 );
@@ -803,9 +812,9 @@ warn_unknown_replica(
     }
     if ( !found ) {
 #ifdef NEW_LOGGING
-       LDAP_LOG (( "re", LDAP_LEVEL_WARNING, "warn_unknown_replica: "
+       LDAP_LOG ( SLURPD, WARNING, "warn_unknown_replica: "
                "Warning: unknown replica %s:%d found in replication log\n",
-               host, port ));
+               host, port, 0 );
 #else
        Debug( LDAP_DEBUG_ANY,
                "Warning: unknown replica %s:%d found in replication log\n",