]> git.sur5r.net Git - openldap/blob - libraries/libldap/delete.c
C portability from HEAD
[openldap] / libraries / libldap / delete.c
1 /*
2  *  Copyright (c) 1990 Regents of the University of Michigan.
3  *  All rights reserved.
4  *
5  *  delete.c
6  */
7
8 #ifndef lint 
9 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
10 #endif
11
12 #include <stdio.h>
13 #include <string.h>
14
15 #ifdef MACOS
16 #include "macos.h"
17 #endif /* MACOS */
18
19 #if defined( DOS ) || defined( _WIN32 )
20 #include "msdos.h"
21 #endif /* DOS */
22
23 #if !defined( MACOS ) && !defined( DOS )
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #endif
27
28 #include "lber.h"
29 #include "ldap.h"
30 #include "ldap-int.h"
31
32 /*
33  * ldap_delete - initiate an ldap (and X.500) delete operation. Parameters:
34  *
35  *      ld              LDAP descriptor
36  *      dn              DN of the object to delete
37  *
38  * Example:
39  *      msgid = ldap_delete( ld, dn );
40  */
41 int
42 ldap_delete( LDAP *ld, char *dn )
43 {
44         BerElement      *ber;
45
46         /*
47          * A delete request looks like this:
48          *      DelRequet ::= DistinguishedName,
49          */
50
51         Debug( LDAP_DEBUG_TRACE, "ldap_delete\n", 0, 0, 0 );
52
53         /* create a message to send */
54         if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) {
55                 return( -1 );
56         }
57
58         if ( ber_printf( ber, "{its}", ++ld->ld_msgid, LDAP_REQ_DELETE, dn )
59             == -1 ) {
60                 ld->ld_errno = LDAP_ENCODING_ERROR;
61                 ber_free( ber, 1 );
62                 return( -1 );
63         }
64
65         /* send the message */
66         return ( send_initial_request( ld, LDAP_REQ_DELETE, dn, ber ));
67 }
68
69
70 int
71 ldap_delete_s( LDAP *ld, char *dn )
72 {
73         int             msgid;
74         LDAPMessage     *res;
75
76         if ( (msgid = ldap_delete( ld, dn )) == -1 )
77                 return( ld->ld_errno );
78
79         if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
80                 return( ld->ld_errno );
81
82         return( ldap_result2error( ld, res, 1 ) );
83 }