#include <stdio.h>
#include <ac/ctype.h>
+#include <ac/errno.h>
#include <ac/socket.h>
#include <ac/string.h>
Entry *
str2entry( char *s )
{
- int i;
+ int id = 0;
Entry *e;
Attribute **a;
char *type;
Debug( LDAP_DEBUG_TRACE, "=> str2entry\n",
s ? s : "NULL", 0, 0 );
- e = (Entry *) ch_calloc( 1, sizeof(Entry) );
- /* initialize reader/writer lock */
- entry_rdwr_init(e);
-
/* check to see if there's an id included */
next = s;
- if ( isdigit( *s ) ) {
- e->e_id = atoi( s );
+ if ( isdigit( (unsigned char) *s ) ) {
+ id = atoi( s );
if ( (s = str_getline( &next )) == NULL ) {
Debug( LDAP_DEBUG_TRACE,
"<= str2entry NULL (missing newline after id)\n",
}
}
+ /* initialize reader/writer lock */
+ e = (Entry *) ch_calloc( 1, sizeof(Entry) );
+
+ if( e == NULL ) {
+ Debug( LDAP_DEBUG_TRACE,
+ "<= str2entry NULL (entry allocation failed)\n",
+ 0, 0, 0 );
+ return( NULL );
+ }
+ e->e_id = id;
+
+ entry_rdwr_init(e);
+
/* dn + attributes */
e->e_attrs = NULL;
vals[0] = &bval;
maxvals = 0;
a = NULL;
}
+
if ( strcasecmp( type, "dn" ) == 0 ) {
if ( e->e_dn != NULL ) {
Debug( LDAP_DEBUG_ANY,
continue;
}
e->e_dn = ch_strdup( value );
+
+ if ( e->e_ndn != NULL ) {
+ Debug( LDAP_DEBUG_ANY,
+ "str2entry: entry %lu already has a normalized dn \"%s\" for \"%s\" (first ignored)\n",
+ e->e_id, e->e_ndn, value );
+ free( e->e_ndn );
+ }
+ e->e_ndn = dn_normalize_case( ch_strdup( value ) );
continue;
}
!= 0 ) {
Debug( LDAP_DEBUG_TRACE,
"<= str2entry NULL (attr_merge)\n", 0, 0, 0 );
+ entry_free( e );
return( NULL );
}
nvals++;
return( NULL );
}
+ if ( e->e_ndn == NULL ) {
+ Debug( LDAP_DEBUG_ANY,
+ "str2entry: entry %lu (\"%s\") has no normalized dn\n",
+ e->e_id, e->e_dn, 0 );
+ entry_free( e );
+ return( NULL );
+ }
+
Debug(LDAP_DEBUG_TRACE, "<= str2entry 0x%lx\n", (unsigned long)e, 0,0);
return( e );
#define MAKE_SPACE( n ) { \
while ( ecur + (n) > ebuf + emaxsize ) { \
- int offset; \
+ ptrdiff_t offset; \
offset = (int) (ecur - ebuf); \
ebuf = (unsigned char *) ch_realloc( (char *) ebuf, \
emaxsize + GRABSIZE ); \
int i;
Attribute *a, *next;
- /* XXX check that no reader/writer locks exist */
+ /* check that no reader/writer locks exist */
+
+ if ( ldap_pvt_thread_rdwr_wtrylock( &e->e_rdwr ) ==
+ LDAP_PVT_THREAD_EBUSY )
+ {
+ Debug( LDAP_DEBUG_ANY, "entry_free(%ld): active (%d, %d)\n",
+ e->e_id,
+ ldap_pvt_thread_rdwr_readers( &e->e_rdwr ),
+ ldap_pvt_thread_rdwr_writers( &e->e_rdwr ));
+
#ifdef LDAP_DEBUG
- assert( !pthread_rdwr_wchk_np(&e->e_rdwr) &&
- !pthread_rdwr_rchk_np(&e->e_rdwr) );
+ assert(!ldap_pvt_thread_rdwr_active( &e->e_rdwr ));
#endif
+ }
if ( e->e_dn != NULL ) {
free( e->e_dn );
}
+ if ( e->e_ndn != NULL ) {
+ free( e->e_ndn );
+ }
for ( a = e->e_attrs; a != NULL; a = next ) {
next = a->a_next;
attr_free( a );
Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%slock: ID: %ld\n",
rw ? "w" : "r", e->e_id, 0);
if (rw)
- return pthread_rdwr_wlock_np(&e->e_rdwr);
+ return ldap_pvt_thread_rdwr_wlock(&e->e_rdwr);
else
- return pthread_rdwr_rlock_np(&e->e_rdwr);
+ return ldap_pvt_thread_rdwr_rlock(&e->e_rdwr);
}
int
return entry_rdwr_lock( e, 1 );
}
+int
+entry_rdwr_trylock(Entry *e, int rw)
+{
+ Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%strylock: ID: %ld\n",
+ rw ? "w" : "r", e->e_id, 0);
+ if (rw)
+ return ldap_pvt_thread_rdwr_wtrylock(&e->e_rdwr);
+ else
+ return ldap_pvt_thread_rdwr_rtrylock(&e->e_rdwr);
+}
+
int
entry_rdwr_unlock(Entry *e, int rw)
{
Debug( LDAP_DEBUG_ARGS, "entry_rdwr_%sunlock: ID: %ld\n",
rw ? "w" : "r", e->e_id, 0);
if (rw)
- return pthread_rdwr_wunlock_np(&e->e_rdwr);
+ return ldap_pvt_thread_rdwr_wunlock(&e->e_rdwr);
else
- return pthread_rdwr_runlock_np(&e->e_rdwr);
+ return ldap_pvt_thread_rdwr_runlock(&e->e_rdwr);
}
int
int
entry_rdwr_init(Entry *e)
{
- return pthread_rdwr_init_np(&e->e_rdwr, NULL);
+ return ldap_pvt_thread_rdwr_init( &e->e_rdwr );
}