return pConn;\r
}\r
\r
-/* \r
- * Function : ValuestoBValues \r
- * Convert an array of char ptrs to an array of berval ptrs.\r
- * return value : LDAP_SUCCESS\r
- * LDAP_NO_MEMORY\r
- * LDAP_OTHER\r
-*/\r
-\r
-static int \r
-ValuesToBValues(\r
- char **ppValue, \r
- struct berval ***pppBV )\r
+/*\r
+ * Function : values2obj\r
+ * Convert an array of strings into a BerVarray.\r
+ * the strings.\r
+ */\r
+static int\r
+values2obj(\r
+ char **ppValue,\r
+ BerVarray *bvobj)\r
{\r
- int rc = LDAP_SUCCESS;\r
- int i;\r
- struct berval *pTmpBV;\r
- struct berval **ppNewBV;\r
-\r
- /* count the number of char ptrs. */\r
- for ( i = 0; ppValue != NULL && ppValue[i] != NULL; i++ ) {\r
- ; /* NULL */\r
+ int rc = LDAP_SUCCESS;\r
+ int i;\r
+ BerVarray tmpberval;\r
+\r
+ if ( ppValue == NULL ) {\r
+ *bvobj = NULL;\r
+ return LDAP_SUCCESS;\r
}\r
\r
- if ( i == 0 ) {\r
- rc = LDAP_OTHER;\r
- } else {\r
- *pppBV = ppNewBV = (struct berval **)slapi_ch_malloc( (i+1)*(sizeof(struct berval *)) );\r
- if ( *pppBV == NULL ) {\r
- rc = LDAP_NO_MEMORY;\r
- } else {\r
- while ( ppValue != NULL && *ppValue != NULL && rc == LDAP_SUCCESS ) {\r
- pTmpBV = (struct berval *)slapi_ch_malloc(sizeof(struct berval));\r
- if ( pTmpBV == NULL) {\r
- rc = LDAP_NO_MEMORY;\r
- } else {\r
- pTmpBV->bv_val = slapi_ch_strdup(*ppValue);\r
- if ( pTmpBV->bv_val == NULL ) {\r
- rc = LDAP_NO_MEMORY;\r
- } else {\r
- pTmpBV->bv_len = strlen(*ppValue);\r
- *ppNewBV = pTmpBV;\r
- ppNewBV++;\r
- }\r
- ppValue++;\r
- }\r
- }\r
- /* null terminate the array of berval ptrs */\r
- *ppNewBV = NULL;\r
- }\r
+ for ( i = 0; ppValue[i] != NULL; i++ )\r
+ ;\r
+\r
+ tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );\r
+ if ( tmpberval == NULL ) {\r
+ return LDAP_NO_MEMORY;\r
}\r
- return( rc );\r
+ for ( i = 0; ppValue[i] != NULL; i++ ) {\r
+ tmpberval[i].bv_val = ppValue[i];\r
+ tmpberval[i].bv_len = strlen( ppValue[i] );\r
+ }\r
+ tmpberval[i].bv_val = NULL;\r
+ tmpberval[i].bv_len = 0;\r
+\r
+ *bvobj = tmpberval;\r
+\r
+ return LDAP_SUCCESS;\r
}\r
\r
+static void\r
+freeMods( Modifications *ml )\r
+{\r
+ /*\r
+ * Free a modification list whose values have been \r
+ * set with bvptr2obj() or values2obj() (ie. they\r
+ * do not own the pointer to the underlying values)\r
+ */\r
+ Modifications *next;\r
+\r
+ for ( ; ml != NULL; ml = next ) {\r
+ next = ml->sml_next;\r
+\r
+ slapi_ch_free( (void **)&ml->sml_bvalues );\r
+ slapi_ch_free( (void **)&ml );\r
+ }\r
+}\r
\r
/*\r
* Function : LDAPModToEntry \r
Entry *pEntry=NULL;\r
LDAPMod *pMod;\r
struct berval *bv;\r
- struct berval **ppBV;\r
Backend *be;\r
Operation *op;\r
\r
/* convert an array of pointers to bervals to an array of bervals */\r
rc = bvptr2obj(pMod->mod_bvalues, &bv);\r
if (rc != LDAP_SUCCESS) goto cleanup;\r
- tmp.sml_type.bv_val = slapi_ch_strdup(pMod->mod_type);\r
- tmp.sml_type.bv_len = slapi_ch_stlen(pMod->mod_type);\r
+ tmp.sml_type.bv_val = pMod->mod_type;\r
+ tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
tmp.sml_bvalues = bv;\r
\r
mod = (Modifications *) ch_malloc( sizeof(Modifications) );\r
if ( pMod->mod_values == NULL ) {\r
rc = LDAP_OTHER;\r
} else {\r
- rc = ValuesToBValues( pMod->mod_values, &ppBV );\r
+ rc = values2obj( pMod->mod_values, &bv );\r
if (rc != LDAP_SUCCESS) goto cleanup;\r
- rc = bvptr2obj(ppBV, &bv);\r
- if (rc != LDAP_SUCCESS) goto cleanup;\r
- tmp.sml_type.bv_val = slapi_ch_strdup(pMod->mod_type);\r
- tmp.sml_type.bv_len = slapi_ch_stlen(pMod->mod_type);\r
+ tmp.sml_type.bv_val = pMod->mod_type;\r
+ tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
tmp.sml_bvalues = bv;\r
\r
mod = (Modifications *) ch_malloc( sizeof(Modifications) );\r
\r
*modtail = mod;\r
modtail = &mod->sml_next;\r
-\r
- if ( ppBV != NULL ) {\r
- ber_bvecfree( ppBV );\r
- }\r
}\r
}\r
} /* for each LDAPMod */\r
\r
if ( dn.bv_val ) slapi_ch_free( (void **)&dn.bv_val );\r
if ( op ) slapi_ch_free( (void **)&op );\r
- if ( modlist != NULL ) slap_mods_free( modlist );\r
+ if ( modlist != NULL ) freeMods( modlist );\r
if ( rc != LDAP_SUCCESS ) {\r
if ( pEntry != NULL ) {\r
slapi_entry_free( pEntry );\r
goto cleanup;\r
}\r
\r
- pConn = fakeConnection( NULL, LDAP_REQ_DELETE );\r
+ pConn = fakeConnection( NULL, LDAP_REQ_DELETE );\r
if (pConn == NULL) {\r
rc = LDAP_NO_MEMORY;\r
goto cleanup;\r
goto cleanup;\r
}\r
\r
- op->o_ndn.bv_val = slapi_ch_strdup(be->be_rootdn.bv_val);\r
- op->o_ndn.bv_len = be->be_rootdn.bv_len;\r
- pConn->c_dn.bv_val = slapi_ch_strdup(be->be_rootdn.bv_val);\r
- pConn->c_dn.bv_len = be->be_rootdn.bv_len;\r
+ op->o_dn = pConn->c_dn = be->be_rootdn;\r
+ op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
\r
suffix_alias( be, &ndn );\r
\r
\r
if ( pConn != NULL ) {\r
if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
- if ( pConn->c_dn.bv_val ) slapi_ch_free( (void **)&pConn->c_dn.bv_val );\r
- if ( op->o_dn.bv_val ) slapi_ch_free( (void **)&op->o_dn.bv_val );\r
if ( op ) slapi_ch_free( (void **)&op );\r
pSavePB = pPB;\r
free( pConn );\r
goto cleanup;\r
}\r
\r
- op->o_ndn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
- op->o_ndn.bv_len = be->be_rootdn.bv_len;\r
- pConn->c_dn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
- pConn->c_dn.bv_len = be->be_rootdn.bv_len;\r
+ op->o_dn = pConn->c_dn = be->be_rootdn;\r
+ op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
\r
if ( be->be_add ) {\r
int repl_user = be_isupdate( be, &op->o_ndn );\r
\r
if ( pConn != NULL ) {\r
if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
- if ( pConn->c_dn.bv_val ) slapi_ch_free( (void **)&pConn->c_dn.bv_val );\r
- if ( op ) {\r
- if ( op->o_ndn.bv_val ) {\r
- slapi_ch_free( (void **)&op->o_ndn.bv_val );\r
- }\r
- free(op);\r
- }\r
+ if ( op != NULL ) slapi_ch_free( (void **)&op );\r
pSavePB = pPB;\r
free( pConn );\r
}\r
goto cleanup;\r
}\r
\r
- op->o_ndn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
- op->o_ndn.bv_len = be->be_rootdn.bv_len;\r
- pConn->c_dn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
- pConn->c_dn.bv_len = be->be_rootdn.bv_len;\r
+ op->o_dn = pConn->c_dn = be->be_rootdn;\r
+ op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
\r
suffix_alias( be, &ndn );\r
\r
\r
if ( pConn != NULL ) {\r
if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
- if ( pConn->c_dn.bv_val ) slapi_ch_free( (void **)&pConn->c_dn.bv_val );\r
- if ( op ) {\r
- if ( op->o_dn.bv_val ) slapi_ch_free( (void **)&op->o_dn.bv_val );\r
- slapi_ch_free( (void **)&op );\r
- }\r
+ if ( op != NULL ) slapi_ch_free( (void **)&op );\r
pSavePB = pPB;\r
free( pConn );\r
}\r
int isCritical;\r
Backend *be;\r
struct berval *bv;\r
- struct berval **ppBV;\r
LDAPMod *pMod;\r
\r
Modifications *modlist = NULL;\r
goto cleanup;\r
}\r
\r
- op->o_ndn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
- op->o_ndn.bv_len = be->be_rootdn.bv_len;\r
- pConn->c_dn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
- pConn->c_dn.bv_len = be->be_rootdn.bv_len;\r
+ op->o_dn = pConn->c_dn = be->be_rootdn;\r
+ op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
\r
suffix_alias( be, &ndn );\r
\r
*/\r
rc = bvptr2obj( pMod->mod_bvalues, &bv );\r
if ( rc != LDAP_SUCCESS ) goto cleanup;\r
- tmp.sml_type.bv_val = slapi_ch_strdup( pMod->mod_type );\r
- tmp.sml_type.bv_len = slapi_ch_stlen( pMod->mod_type );\r
+ tmp.sml_type.bv_val = pMod->mod_type;\r
+ tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
tmp.sml_bvalues = bv;\r
\r
mod = (Modifications *)ch_malloc( sizeof(Modifications) );\r
mod->sml_type = tmp.sml_type;\r
mod->sml_bvalues = tmp.sml_bvalues;\r
} else { \r
- rc = ValuesToBValues( pMod->mod_values, &ppBV );\r
- if ( rc != LDAP_SUCCESS ) goto cleanup;\r
- rc = bvptr2obj( ppBV, &bv );\r
+ rc = values2obj( pMod->mod_values, &bv );\r
if ( rc != LDAP_SUCCESS ) goto cleanup;\r
- tmp.sml_type.bv_val = slapi_ch_strdup( pMod->mod_type );\r
- tmp.sml_type.bv_len = slapi_ch_stlen( pMod->mod_type );\r
+ tmp.sml_type.bv_val = pMod->mod_type;\r
+ tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
tmp.sml_bvalues = bv;\r
\r
mod = (Modifications *) ch_malloc( sizeof(Modifications) );\r
mod->sml_desc = NULL;\r
mod->sml_type = tmp.sml_type;\r
mod->sml_bvalues = tmp.sml_bvalues;\r
-\r
- if ( ppBV != NULL ) {\r
- ber_bvecfree( ppBV );\r
- }\r
}\r
*modtail = mod;\r
modtail = &mod->sml_next;\r
if ( pdn.bv_val ) ch_free( pdn.bv_val );\r
if ( ndn.bv_val ) ch_free( ndn.bv_val );\r
\r
- if ( modlist != NULL ) slap_mods_free( modlist );\r
+ if ( modlist != NULL ) freeMods( modlist );\r
\r
if ( pConn != NULL ) {\r
if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
- if ( pConn->c_dn.bv_val ) slapi_ch_free( (void **)&pConn->c_dn.bv_val );\r
- if ( op ) {\r
- if ( op->o_dn.bv_val ) slapi_ch_free( (void **)&op->o_dn.bv_val );\r
- slapi_ch_free( (void **)&op );\r
- }\r
+ if ( op != NULL ) slapi_ch_free( (void **)&op );\r
pSavePB = pPB;\r
free( pConn );\r
}\r
goto cleanup;\r
} \r
\r
- op->o_ndn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
- op->o_ndn.bv_len = be->be_rootdn.bv_len;\r
- c->c_dn.bv_val = slapi_ch_strdup( be->be_rootdn.bv_val );\r
- c->c_dn.bv_len = be->be_rootdn.bv_len;\r
+ op->o_dn = c->c_dn = be->be_rootdn;\r
+ op->o_ndn = c->c_ndn = be->be_rootndn;\r
\r
if ( be->be_search ) {\r
rc = (*be->be_search)( be, c, op, &pdn, &ndn,\r
\r
if ( c != NULL ) {\r
if ( c->c_sb != NULL ) ber_sockbuf_free( c->c_sb );\r
- if ( c->c_dn.bv_val ) slapi_ch_free( (void **)&c->c_dn.bv_val );\r
- if ( op ) {\r
- if ( op->o_ndn.bv_val ) slapi_ch_free( (void **)&op->o_ndn.bv_val );\r
- free( op );\r
- }\r
+ if ( op != NULL ) slapi_ch_free( (void **)&op );\r
pSavePB = ptr;\r
free( c );\r
}\r