]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/re.c
add uptime monitoring (in seconds)
[openldap] / servers / slurpd / re.c
index 05fd60743c9479b217e8ae098ed159d6cc74b666..e0d4ddd8f10ce89c7c5e3e8fa2f67196bc872a44 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -49,6 +49,7 @@
 
 #include "slurp.h"
 #include "globals.h"
+#include "lutil.h"
 
 /* Forward references */
 static Rh      *get_repl_hosts LDAP_P(( char *, int *, char ** ));
@@ -187,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 );
@@ -321,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 );
            }
        }
 
@@ -423,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
@@ -448,6 +463,7 @@ skip_replica_lines(
        }
     }
 }
+#endif /* 0 */
 
 
 
@@ -542,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",