*/
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "../slapd/slap.h"
+#include <ac/errno.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/ctype.h>
+
#include "slurp.h"
#include "globals.h"
-/* externs */
-extern char *str_getline( char **next );
-extern void ch_free( char *p );
-
-#ifndef SYSERRLIST_IN_STDIO
-extern char *sys_errlist[];
-#endif /* SYSERRLIST_IN_STDIO
+#include "../slapd/slap.h"
/* Forward references */
-static Rh *get_repl_hosts( char *, int *, char ** );
-static int gettype( char * );
-static int getchangetype( char *);
-static int Re_parse( Re *re, char *replbuf );
-static void Re_dump( Re *re, FILE *fp );
-static void warn_unknown_replica( char *, int port );
+static Rh *get_repl_hosts LDAP_P(( char *, int *, char ** ));
+static int gettype LDAP_P(( char * ));
+static int getchangetype LDAP_P(( char * ));
+static int Re_parse LDAP_P(( Re *re, char *replbuf ));
+static void Re_dump LDAP_P(( Re *re, FILE *fp ));
+static void warn_unknown_replica LDAP_P(( char *, int port ));
/* Globals, scoped within this file */
static int nur = 0; /* Number of unknown replicas */
/*
* Free an Re
+ * ??? Something should apparently return nonzero here, but I dont know what.
*/
static int
Re_free(
"Warning: freeing re (dn: %s) with nonzero refcnt\n",
re->re_dn, 0, 0 );
}
-#if !defined( THREAD_SUNOS4_LWP )
+#if !defined( HAVE_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 );
+#endif /* HAVE_LWP */
ch_free( re->re_timestamp );
if (( rh = re->re_replicas ) != NULL ) {
for ( i = 0; rh[ i ].rh_hostname != NULL; i++ ) {
free( mi );
}
free( re );
+ return 0;
}
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;
}
/*
continue;
}
buflen = ( long ) strlen( buf );
- if ( str_parse_line( buf, &type, &value, &len ) < 0 ) {
+ if ( ldif_parse_line( buf, &type, &value, &len ) < 0 ) {
Debug( LDAP_DEBUG_ANY,
"Error: Re_parse: malformed replog file\n",
0, 0, 0 );
*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;
break;
case T_DN:
- re->re_dn = strdup( value );
+ re->re_dn = ch_malloc( len + 1 );
+ memcpy( re->re_dn, value, len );
+ re->re_dn[ len ]='\0';
state |= GOT_DN;
break;
default:
}
for (;;) {
- if (( buf = str_getline( &rp )) == NULL ) {
+ if (( buf = ldif_getline( &rp )) == NULL ) {
break;
}
buflen = ( long ) strlen( buf );
type = "-";
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 );
sizeof( Mi ) * ( nml + 2 ));
re->re_mods[ nml ].mi_type = strdup( type );
if ( value != NULL ) {
- re->re_mods[ nml ].mi_val = strdup( value );
+ re->re_mods[ nml ].mi_val = ch_malloc( len + 1 );
+ 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 {
re->re_mods[ nml ].mi_val = NULL;
char **r_rp
)
{
- char buf[ LINE_WIDTH + 1 ];
+ char buf[ LDIF_LINE_WIDTH + 1 ];
char *type, *value, *line, *p;
Rh *rh = NULL;
int nreplicas, len;
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;
}
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++;
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",
Re *re
)
{
- return( pthread_mutex_lock( &re->re_mutex ));
+ return( ldap_pvt_thread_mutex_lock( &re->re_mutex ));
}
Re *re
)
{
- return( pthread_mutex_unlock( &re->re_mutex ));
+ return( ldap_pvt_thread_mutex_unlock( &re->re_mutex ));
}
(*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;
}