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
29 static char copyright
[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
35 * ldap_delete - initiate an ldap delete operation. Parameters:
38 * dn DN of the object to delete
41 * msgid = ldap_delete( ld, dn );
45 ldap_delete( LDAP
*ld
, const char *dn
)
49 LDAPDebug( LDAP_DEBUG_TRACE
, "ldap_delete\n", 0, 0, 0 );
51 if ( ldap_delete_ext( ld
, dn
, NULL
, NULL
, &msgid
) == LDAP_SUCCESS
) {
54 return( -1 ); /* error is in ld handle */
60 ldap_delete_ext( LDAP
*ld
, const char *dn
, LDAPControl
**serverctrls
,
61 LDAPControl
**clientctrls
, int *msgidp
)
67 * A delete request looks like this:
68 * DelRequet ::= DistinguishedName,
71 LDAPDebug( LDAP_DEBUG_TRACE
, "ldap_delete_ext\n", 0, 0, 0 );
73 if ( !NSLDAPI_VALID_LDAP_POINTER( ld
)) {
74 return( LDAP_PARAM_ERROR
);
77 if ( !NSLDAPI_VALID_LDAPMESSAGE_POINTER( msgidp
))
79 LDAP_SET_LDERRNO( ld
, LDAP_PARAM_ERROR
, NULL
, NULL
);
80 return( LDAP_PARAM_ERROR
);
86 LDAP_MUTEX_LOCK( ld
, LDAP_MSGID_LOCK
);
87 *msgidp
= ++ld
->ld_msgid
;
88 LDAP_MUTEX_UNLOCK( ld
, LDAP_MSGID_LOCK
);
90 /* see if we should add to the cache */
91 if ( ld
->ld_cache_on
&& ld
->ld_cache_delete
!= NULL
) {
92 LDAP_MUTEX_LOCK( ld
, LDAP_CACHE_LOCK
);
93 if ( (rc
= (ld
->ld_cache_delete
)( ld
, *msgidp
, LDAP_REQ_DELETE
,
96 LDAP_MUTEX_UNLOCK( ld
, LDAP_CACHE_LOCK
);
97 return( LDAP_SUCCESS
);
99 LDAP_MUTEX_UNLOCK( ld
, LDAP_CACHE_LOCK
);
102 /* create a message to send */
103 if (( lderr
= nsldapi_alloc_ber_with_options( ld
, &ber
))
108 if ( ber_printf( ber
, "{its", *msgidp
, LDAP_REQ_DELETE
, dn
)
110 lderr
= LDAP_ENCODING_ERROR
;
111 LDAP_SET_LDERRNO( ld
, lderr
, NULL
, NULL
);
116 if (( lderr
= nsldapi_put_controls( ld
, serverctrls
, 1, ber
))
122 /* send the message */
123 rc
= nsldapi_send_initial_request( ld
, *msgidp
, LDAP_REQ_DELETE
,
126 return( rc
< 0 ? LDAP_GET_LDERRNO( ld
, NULL
, NULL
) : LDAP_SUCCESS
);
131 ldap_delete_s( LDAP
*ld
, const char *dn
)
133 return( ldap_delete_ext_s( ld
, dn
, NULL
, NULL
));
138 ldap_delete_ext_s( LDAP
*ld
, const char *dn
, LDAPControl
**serverctrls
,
139 LDAPControl
**clientctrls
)
144 if (( err
= ldap_delete_ext( ld
, dn
, serverctrls
, clientctrls
,
145 &msgid
)) != LDAP_SUCCESS
) {
149 if ( ldap_result( ld
, msgid
, 1, NULL
, &res
) == -1 ) {
150 return( LDAP_GET_LDERRNO( ld
, NULL
, NULL
) );
153 return( ldap_result2error( ld
, res
, 1 ) );