8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libldap5 / sources / ldap / common / delete.c
blobe8c975bfc508ef525288a3fe2d277fe6b3b7a41b
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 #ifndef lint
30 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
31 #endif
32 #endif
34 #include "ldap-int.h"
37 * ldap_delete - initiate an ldap delete operation. Parameters:
39 * ld LDAP descriptor
40 * dn DN of the object to delete
42 * Example:
43 * msgid = ldap_delete( ld, dn );
45 int
46 LDAP_CALL
47 ldap_delete( LDAP *ld, const char *dn )
49 int msgid;
51 LDAPDebug( LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0 );
53 if ( ldap_delete_ext( ld, dn, NULL, NULL, &msgid ) == LDAP_SUCCESS ) {
54 return( msgid );
55 } else {
56 return( -1 ); /* error is in ld handle */
60 int
61 LDAP_CALL
62 ldap_delete_ext( LDAP *ld, const char *dn, LDAPControl **serverctrls,
63 LDAPControl **clientctrls, int *msgidp )
65 BerElement *ber;
66 int rc, lderr;
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 );
84 if ( dn == NULL ) {
85 dn = "";
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,
96 dn )) != 0 ) {
97 *msgidp = rc;
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 ))
106 != LDAP_SUCCESS ) {
107 return( lderr );
110 if ( ber_printf( ber, "{its", *msgidp, LDAP_REQ_DELETE, dn )
111 == -1 ) {
112 lderr = LDAP_ENCODING_ERROR;
113 LDAP_SET_LDERRNO( ld, lderr, NULL, NULL );
114 ber_free( ber, 1 );
115 return( lderr );
118 if (( lderr = nsldapi_put_controls( ld, serverctrls, 1, ber ))
119 != LDAP_SUCCESS ) {
120 ber_free( ber, 1 );
121 return( lderr );
124 /* send the message */
125 rc = nsldapi_send_initial_request( ld, *msgidp, LDAP_REQ_DELETE,
126 (char *)dn, ber );
127 *msgidp = rc;
128 return( rc < 0 ? LDAP_GET_LDERRNO( ld, NULL, NULL ) : LDAP_SUCCESS );
132 LDAP_CALL
133 ldap_delete_s( LDAP *ld, const char *dn )
135 return( ldap_delete_ext_s( ld, dn, NULL, NULL ));
139 LDAP_CALL
140 ldap_delete_ext_s( LDAP *ld, const char *dn, LDAPControl **serverctrls,
141 LDAPControl **clientctrls )
143 int err, msgid;
144 LDAPMessage *res;
146 if (( err = ldap_delete_ext( ld, dn, serverctrls, clientctrls,
147 &msgid )) != LDAP_SUCCESS ) {
148 return( err );
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 ) );