]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/entry.c
Import unprotected strtok fix from -devel. Yes, you have to edit 8 files
[openldap] / servers / slapd / entry.c
index d5ee966b570ad152344a50176022a9083e5173df..5de991f4c45991f321e2fb2ca5f180007ddb13bc 100644 (file)
@@ -1,14 +1,14 @@
 /* entry.c - routines for dealing with entries */
 
+#include "portable.h"
+
 #include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "slap.h"
 
-void   entry_free();
-char   *entry2str();
+#include <ac/ctype.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+
+#include "slap.h"
 
 static unsigned char   *ebuf;  /* buf returned by entry2str             */
 static unsigned char   *ecur;  /* pointer to end of currently used ebuf */
@@ -43,7 +43,8 @@ str2entry( char       *s )
         * or newline.
         */
 
-       Debug( LDAP_DEBUG_TRACE, "=> str2entry\n", s, 0, 0 );
+       Debug( LDAP_DEBUG_TRACE, "=> str2entry\n",
+               s ? s : "NULL", 0, 0 );
 
        e = (Entry *) ch_calloc( 1, sizeof(Entry) );
 
@@ -55,10 +56,14 @@ str2entry( char     *s )
                        Debug( LDAP_DEBUG_TRACE,
                            "<= str2entry NULL (missing newline after id)\n",
                            0, 0, 0 );
+                       free( e );
                        return( NULL );
                }
        }
 
+       /* initialize reader/writer lock */
+       entry_rdwr_init(e);
+
        /* dn + attributes */
        e->e_attrs = NULL;
        vals[0] = &bval;
@@ -84,11 +89,11 @@ str2entry( char     *s )
                if ( strcasecmp( type, "dn" ) == 0 ) {
                        if ( e->e_dn != NULL ) {
                                Debug( LDAP_DEBUG_ANY,
   "str2entry: entry %d has multiple dns \"%s\" and \"%s\" (second ignored)\n",
"str2entry: entry %lu has multiple dns \"%s\" and \"%s\" (second ignored)\n",
                                    e->e_id, e->e_dn, value );
                                continue;
                        }
-                       e->e_dn = strdup( value );
+                       e->e_dn = ch_strdup( value );
                        continue;
                }
 
@@ -98,6 +103,7 @@ str2entry( char      *s )
                    != 0 ) {
                        Debug( LDAP_DEBUG_TRACE,
                            "<= str2entry NULL (attr_merge)\n", 0, 0, 0 );
+                       entry_free( e );
                        return( NULL );
                }
                nvals++;
@@ -105,13 +111,14 @@ str2entry( char   *s )
 
        /* check to make sure there was a dn: line */
        if ( e->e_dn == NULL ) {
-               Debug( LDAP_DEBUG_ANY, "str2entry: entry %d has no dn\n",
+               Debug( LDAP_DEBUG_ANY, "str2entry: entry %lu has no dn\n",
                    e->e_id, 0, 0 );
                entry_free( e );
                return( NULL );
        }
 
-       Debug( LDAP_DEBUG_TRACE, "<= str2entry 0x%x\n", e, 0, 0 );
+       Debug(LDAP_DEBUG_TRACE, "<= str2entry 0x%lx\n", (unsigned long)e, 0,0);
+
        return( e );
 }
 
@@ -187,6 +194,12 @@ entry_free( Entry *e )
        int             i;
        Attribute       *a, *next;
 
+       /* XXX check that no reader/writer locks exist */
+#ifdef LDAP_DEBUG
+       assert( !pthread_rdwr_wchk_np(&e->e_rdwr) &&
+               !pthread_rdwr_rchk_np(&e->e_rdwr) );
+#endif
+
        if ( e->e_dn != NULL ) {
                free( e->e_dn );
        }
@@ -196,3 +209,55 @@ entry_free( Entry *e )
        }
        free( e );
 }
+
+int
+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);
+       else
+               return pthread_rdwr_rlock_np(&e->e_rdwr);
+}
+
+int
+entry_rdwr_rlock(Entry *e)
+{
+       return entry_rdwr_lock( e, 0 );
+}
+
+int
+entry_rdwr_wlock(Entry *e)
+{
+       return entry_rdwr_lock( e, 1 );
+}
+
+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);
+       else
+               return pthread_rdwr_runlock_np(&e->e_rdwr);
+}
+
+int
+entry_rdwr_runlock(Entry *e)
+{
+       return entry_rdwr_unlock( e, 0 );
+}
+
+int
+entry_rdwr_wunlock(Entry *e)
+{
+       return entry_rdwr_unlock( e, 1 );
+}
+
+int
+entry_rdwr_init(Entry *e)
+{
+       return pthread_rdwr_init_np(&e->e_rdwr, NULL);
+}