1 #pragma ident "%Z%%M% %I% %E% SMI"
4 * The contents of this file are subject to the Netscape Public
5 * License Version 1.1 (the "License"); you may not use this file
6 * except in compliance with the License. You may obtain a copy of
7 * the License at http://www.mozilla.org/NPL/
9 * Software distributed under the License is distributed on an "AS
10 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 * implied. See the License for the specific language governing
12 * rights and limitations under the License.
14 * The Original Code is Mozilla Communicator client code, released
17 * The Initial Developer of the Original Code is Netscape
18 * Communications Corporation. Portions created by Netscape are
19 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
30 static char copyright
[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
37 * ldap_delete - initiate an ldap delete operation. Parameters:
40 * dn DN of the object to delete
43 * msgid = ldap_delete( ld, dn );
47 ldap_delete( LDAP
*ld
, const char *dn
)
51 LDAPDebug( LDAP_DEBUG_TRACE
, "ldap_delete\n", 0, 0, 0 );
53 if ( ldap_delete_ext( ld
, dn
, NULL
, NULL
, &msgid
) == LDAP_SUCCESS
) {
56 return( -1 ); /* error is in ld handle */
62 ldap_delete_ext( LDAP
*ld
, const char *dn
, LDAPControl
**serverctrls
,
63 LDAPControl
**clientctrls
, int *msgidp
)
69 * A delete request looks like this:
70 * DelRequet ::= DistinguishedName,
73 LDAPDebug( LDAP_DEBUG_TRACE
, "ldap_delete_ext\n", 0, 0, 0 );
75 if ( !NSLDAPI_VALID_LDAP_POINTER( ld
)) {
76 return( LDAP_PARAM_ERROR
);
79 if ( !NSLDAPI_VALID_LDAPMESSAGE_POINTER( msgidp
))
81 LDAP_SET_LDERRNO( ld
, LDAP_PARAM_ERROR
, NULL
, NULL
);
82 return( LDAP_PARAM_ERROR
);
88 LDAP_MUTEX_LOCK( ld
, LDAP_MSGID_LOCK
);
89 *msgidp
= ++ld
->ld_msgid
;
90 LDAP_MUTEX_UNLOCK( ld
, LDAP_MSGID_LOCK
);
92 /* see if we should add to the cache */
93 if ( ld
->ld_cache_on
&& ld
->ld_cache_delete
!= NULL
) {
94 LDAP_MUTEX_LOCK( ld
, LDAP_CACHE_LOCK
);
95 if ( (rc
= (ld
->ld_cache_delete
)( ld
, *msgidp
, LDAP_REQ_DELETE
,
98 LDAP_MUTEX_UNLOCK( ld
, LDAP_CACHE_LOCK
);
99 return( LDAP_SUCCESS
);
101 LDAP_MUTEX_UNLOCK( ld
, LDAP_CACHE_LOCK
);
104 /* create a message to send */
105 if (( lderr
= nsldapi_alloc_ber_with_options( ld
, &ber
))
110 if ( ber_printf( ber
, "{its", *msgidp
, LDAP_REQ_DELETE
, dn
)
112 lderr
= LDAP_ENCODING_ERROR
;
113 LDAP_SET_LDERRNO( ld
, lderr
, NULL
, NULL
);
118 if (( lderr
= nsldapi_put_controls( ld
, serverctrls
, 1, ber
))
124 /* send the message */
125 rc
= nsldapi_send_initial_request( ld
, *msgidp
, LDAP_REQ_DELETE
,
128 return( rc
< 0 ? LDAP_GET_LDERRNO( ld
, NULL
, NULL
) : LDAP_SUCCESS
);
133 ldap_delete_s( LDAP
*ld
, const char *dn
)
135 return( ldap_delete_ext_s( ld
, dn
, NULL
, NULL
));
140 ldap_delete_ext_s( LDAP
*ld
, const char *dn
, LDAPControl
**serverctrls
,
141 LDAPControl
**clientctrls
)
146 if (( err
= ldap_delete_ext( ld
, dn
, serverctrls
, clientctrls
,
147 &msgid
)) != LDAP_SUCCESS
) {
151 if ( ldap_result( ld
, msgid
, 1, (struct timeval
*)NULL
, &res
) == -1 ) {
152 return( LDAP_GET_LDERRNO( ld
, NULL
, NULL
) );
155 return( ldap_result2error( ld
, res
, 1 ) );