dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libldap5 / sources / ldap / common / delete.c
blob7123a234f42eaabdc57b1ff4fe9060a2507c06fb
1 #pragma ident "%Z%%M% %I% %E% SMI"
3 /*
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
15 * March 31, 1998.
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
20 * Rights Reserved.
22 * Contributor(s):
25 * delete.c
28 #if 0
29 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
30 #endif
32 #include "ldap-int.h"
35 * ldap_delete - initiate an ldap delete operation. Parameters:
37 * ld LDAP descriptor
38 * dn DN of the object to delete
40 * Example:
41 * msgid = ldap_delete( ld, dn );
43 int
44 LDAP_CALL
45 ldap_delete( LDAP *ld, const char *dn )
47 int msgid;
49 LDAPDebug( LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0 );
51 if ( ldap_delete_ext( ld, dn, NULL, NULL, &msgid ) == LDAP_SUCCESS ) {
52 return( msgid );
53 } else {
54 return( -1 ); /* error is in ld handle */
58 int
59 LDAP_CALL
60 ldap_delete_ext( LDAP *ld, const char *dn, LDAPControl **serverctrls,
61 LDAPControl **clientctrls, int *msgidp )
63 BerElement *ber;
64 int rc, lderr;
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 );
82 if ( dn == NULL ) {
83 dn = "";
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,
94 dn )) != 0 ) {
95 *msgidp = rc;
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 ))
104 != LDAP_SUCCESS ) {
105 return( lderr );
108 if ( ber_printf( ber, "{its", *msgidp, LDAP_REQ_DELETE, dn )
109 == -1 ) {
110 lderr = LDAP_ENCODING_ERROR;
111 LDAP_SET_LDERRNO( ld, lderr, NULL, NULL );
112 ber_free( ber, 1 );
113 return( lderr );
116 if (( lderr = nsldapi_put_controls( ld, serverctrls, 1, ber ))
117 != LDAP_SUCCESS ) {
118 ber_free( ber, 1 );
119 return( lderr );
122 /* send the message */
123 rc = nsldapi_send_initial_request( ld, *msgidp, LDAP_REQ_DELETE,
124 (char *)dn, ber );
125 *msgidp = rc;
126 return( rc < 0 ? LDAP_GET_LDERRNO( ld, NULL, NULL ) : LDAP_SUCCESS );
130 LDAP_CALL
131 ldap_delete_s( LDAP *ld, const char *dn )
133 return( ldap_delete_ext_s( ld, dn, NULL, NULL ));
137 LDAP_CALL
138 ldap_delete_ext_s( LDAP *ld, const char *dn, LDAPControl **serverctrls,
139 LDAPControl **clientctrls )
141 int err, msgid;
142 LDAPMessage *res;
144 if (( err = ldap_delete_ext( ld, dn, serverctrls, clientctrls,
145 &msgid )) != LDAP_SUCCESS ) {
146 return( err );
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 ) );