]> git.sur5r.net Git - openldap/blob - libraries/libldap/txn.c
Initial and rough client-side implementation of the revised LDAP
[openldap] / libraries / libldap / txn.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 2006 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* ACKNOWLEDGEMENTS:
16  * This program was orignally developed by Kurt D. Zeilenga for inclusion
17  * in OpenLDAP Software.
18  */
19
20 /*
21  * LDAPv3 Transactions (draft-zeilenga-ldap-txn)
22  */
23
24 #include "portable.h"
25
26 #include <stdio.h>
27 #include <ac/stdlib.h>
28
29 #include <ac/socket.h>
30 #include <ac/string.h>
31 #include <ac/time.h>
32
33 #include "ldap-int.h"
34 #include "ldap_log.h"
35
36 #ifdef LDAP_X_TXN
37 int
38 ldap_txn_start(
39         LDAP *ld,
40         LDAPControl **sctrls,
41         LDAPControl **cctrls,
42         int *msgidp )
43 {
44         return ldap_extended_operation( ld, LDAP_EXOP_X_TXN_START,
45                 NULL, sctrls, cctrls, msgidp );
46 }
47
48 int
49 ldap_txn_start_s(
50         LDAP *ld,
51         LDAPControl **sctrls,
52         LDAPControl **cctrls,
53         struct berval **txnid )
54 {
55         assert( txnid != NULL );
56
57         return ldap_extended_operation_s( ld, LDAP_EXOP_X_TXN_START,
58                 NULL, sctrls, cctrls, NULL, txnid );
59 }
60
61 int
62 ldap_txn_end(
63         LDAP *ld,
64         int commit,
65         struct berval *txnid,
66         LDAPControl **sctrls,
67         LDAPControl **cctrls,
68         int *msgidp )
69 {
70         int rc;
71         BerElement *txnber = NULL;
72         struct berval *txnval = NULL;
73
74         assert( txnid != NULL );
75
76         txnber = ber_alloc_t( LBER_USE_DER );
77         ber_printf( txnber, "{io}", commit, txnid );
78         ber_flatten( txnber, &txnval );
79
80         rc = ldap_extended_operation( ld, LDAP_EXOP_X_TXN_END,
81                 txnval, sctrls, cctrls, msgidp );
82
83         ber_free( txnber, 1 );
84         return rc;
85 }
86
87 int
88 ldap_txn_end_s(
89         LDAP *ld,
90         int commit,
91         struct berval *txnid,
92         LDAPControl **sctrls,
93         LDAPControl **cctrls,
94         int *retidp )
95 {
96         int rc, msgid;
97         struct berval *retdata = NULL;
98         LDAPMessage *res;
99
100         rc = ldap_txn_end( ld, commit, txnid, sctrls, cctrls, &msgid );
101         if( rc != LDAP_SUCCESS ) return rc;
102
103         if ( ldap_result( ld, msgid, LDAP_MSG_ALL, (struct timeval *) NULL, &res )
104                 == -1 )
105         {
106                 return ld->ld_errno;
107         }
108
109         rc = ldap_parse_extended_result( ld, res, NULL, &retdata, 0 );
110         if( rc != LDAP_SUCCESS ) {
111                 ldap_msgfree( res );
112                 return rc;
113         }
114
115         /* don't bother parsing the retdata (yet) */
116         if( retidp != NULL ) {
117                 *retidp = 0;
118         }
119
120         return ldap_result2error( ld, res, 1 );
121 }
122 #endif