]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/entry.c
Change slapd/delete stats message for consistency.
[openldap] / servers / slapd / entry.c
index 5e7ee6d31b73ab997e0c2cc535cfcc814255478d..bc0f2de4da36bf19bcd5b554d2119f6933bb01ad 100644 (file)
@@ -5,6 +5,7 @@
 #include <stdio.h>
 
 #include <ac/ctype.h>
+#include <ac/errno.h>
 #include <ac/socket.h>
 #include <ac/string.h>
 
@@ -17,7 +18,7 @@ static int            emaxsize;/* max size of ebuf                     */
 Entry *
 str2entry( char        *s )
 {
-       int             i;
+       int                     id = 0;
        Entry           *e;
        Attribute       **a;
        char            *type;
@@ -46,14 +47,10 @@ str2entry( char     *s )
        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",
@@ -62,6 +59,19 @@ str2entry( char      *s )
                }
        }
 
+       /* 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;
@@ -84,6 +94,7 @@ str2entry( char       *s )
                        maxvals = 0;
                        a = NULL;
                }
+
                if ( strcasecmp( type, "dn" ) == 0 ) {
                        if ( e->e_dn != NULL ) {
                                Debug( LDAP_DEBUG_ANY,
@@ -92,6 +103,14 @@ str2entry( char     *s )
                                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;
                }
 
@@ -101,6 +120,7 @@ str2entry( char     *s )
                    != 0 ) {
                        Debug( LDAP_DEBUG_TRACE,
                            "<= str2entry NULL (attr_merge)\n", 0, 0, 0 );
+                       entry_free( e );
                        return( NULL );
                }
                nvals++;
@@ -114,6 +134,14 @@ str2entry( char    *s )
                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 );
@@ -123,7 +151,7 @@ str2entry( char     *s )
 
 #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 ); \
@@ -191,15 +219,27 @@ entry_free( Entry *e )
        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 );
@@ -213,9 +253,9 @@ entry_rdwr_lock(Entry *e, int rw)
        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
@@ -230,15 +270,26 @@ entry_rdwr_wlock(Entry *e)
        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
@@ -256,5 +307,5 @@ entry_rdwr_wunlock(Entry *e)
 int
 entry_rdwr_init(Entry *e)
 {
-       return pthread_rdwr_init_np(&e->e_rdwr, NULL);
+       return ldap_pvt_thread_rdwr_init( &e->e_rdwr );
 }