]> git.sur5r.net Git - openldap/commitdiff
allow load_extop to replace an existing handler (not by default, though)
authorPierangelo Masarati <ando@openldap.org>
Fri, 6 Jan 2006 17:08:54 +0000 (17:08 +0000)
committerPierangelo Masarati <ando@openldap.org>
Fri, 6 Jan 2006 17:08:54 +0000 (17:08 +0000)
servers/slapd/extended.c
servers/slapd/module.c
servers/slapd/proto-slap.h

index e77ac961e7f8271e7a318a586e98f302470ac026..9d6aeb95052cf951bffe567c0569ca423255e180 100644 (file)
@@ -249,13 +249,15 @@ done:;
 }
 
 int
-load_extop(
+load_extop2(
        const struct berval *ext_oid,
        slap_mask_t ext_flags,
-       SLAP_EXTOP_MAIN_FN *ext_main )
+       SLAP_EXTOP_MAIN_FN *ext_main,
+       unsigned flags )
 {
        struct berval           oidm = BER_BVNULL;
        struct extop_list       *ext;
+       int                     insertme = 0;
 
        if ( !ext_main ) {
                return -1; 
@@ -276,25 +278,34 @@ load_extop(
 
        for ( ext = supp_ext_list; ext; ext = ext->next ) {
                if ( bvmatch( ext_oid, &ext->oid ) ) {
+                       if ( flags == 1 ) {
+                               break;
+                       }
                        return -1;
                }
        }
 
-       ext = ch_calloc(1, sizeof(struct extop_list) + ext_oid->bv_len + 1);
-       if (ext == NULL)
-               return(-1);
+       if ( flags == 0 || ext == NULL ) {
+               ext = ch_calloc( 1, sizeof(struct extop_list) + ext_oid->bv_len + 1 );
+               if ( ext == NULL ) {
+                       return(-1);
+               }
 
-       ext->flags = ext_flags;
+               ext->oid.bv_val = (char *)(ext + 1);
+               AC_MEMCPY( ext->oid.bv_val, ext_oid->bv_val, ext_oid->bv_len );
+               ext->oid.bv_len = ext_oid->bv_len;
+               ext->oid.bv_val[ext->oid.bv_len] = '\0';
 
-       ext->oid.bv_val = (char *)(ext + 1);
-       AC_MEMCPY( ext->oid.bv_val, ext_oid->bv_val, ext_oid->bv_len );
-       ext->oid.bv_len = ext_oid->bv_len;
-       ext->oid.bv_val[ext->oid.bv_len] = '\0';
+               insertme = 1;
+       }
 
+       ext->flags = ext_flags;
        ext->ext_main = ext_main;
-       ext->next = supp_ext_list;
 
-       supp_ext_list = ext;
+       if ( insertme ) {
+               ext->next = supp_ext_list;
+               supp_ext_list = ext;
+       }
 
        return(0);
 }
@@ -304,10 +315,10 @@ extops_init (void)
 {
        int i;
 
-       for (i = 0; builtin_extops[i].oid != NULL; i++) {
-               load_extop((struct berval *)builtin_extops[i].oid,
+       for ( i = 0; builtin_extops[i].oid != NULL; i++ ) {
+               load_extop( (struct berval *)builtin_extops[i].oid,
                        builtin_extops[i].flags,
-                       builtin_extops[i].ext_main);
+                       builtin_extops[i].ext_main );
        }
        return(0);
 }
index c579004e63317b78cce3d38443b7e8c5826b4187..b9e3ff5a6ce32592c1ad8d1ff6ca60f46eea4d07 100644 (file)
@@ -298,6 +298,8 @@ load_extop_module (
                return(-1);
        }
 
+       /* FIXME: this is broken, and no longer needed, 
+        * as a module can call load_extop() itself... */
        rc = load_extop( &oid, ext_main );
        return rc;
 }
index 2fe63f50f3bb4e9cd3177b1cb8d563a957cadb83..18c5000e44231fecaecd38fc75ae576257e54b43 100644 (file)
@@ -875,10 +875,13 @@ typedef int (SLAP_EXTOP_MAIN_FN) LDAP_P(( Operation *op, SlapReply *rs ));
 typedef int (SLAP_EXTOP_GETOID_FN) LDAP_P((
        int index, struct berval *oid, int blen ));
 
-LDAP_SLAPD_F (int) load_extop LDAP_P((
+LDAP_SLAPD_F (int) load_extop2 LDAP_P((
        const struct berval *ext_oid,
        slap_mask_t flags,
-       SLAP_EXTOP_MAIN_FN *ext_main ));
+       SLAP_EXTOP_MAIN_FN *ext_main,
+       unsigned tmpflags ));
+#define load_extop(ext_oid, flags, ext_main) \
+       load_extop2((ext_oid), (flags), (ext_main), 0)
 
 LDAP_SLAPD_F (int) extops_init LDAP_P(( void ));