]> git.sur5r.net Git - openldap/blob - servers/slapd/operation.c
42f52b2c71dc619c01d2a6d7fa5e45893d484541
[openldap] / servers / slapd / operation.c
1 /* operation.c - routines to deal with pending ldap operations */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16 #include "slapi.h"
17
18
19 void
20 slap_op_free( Operation *op )
21 {
22         assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );
23
24         if ( op->o_ber != NULL ) {
25                 ber_free( op->o_ber, 1 );
26         }
27         if ( op->o_dn.bv_val != NULL ) {
28                 free( op->o_dn.bv_val );
29         }
30         if ( op->o_ndn.bv_val != NULL ) {
31                 free( op->o_ndn.bv_val );
32         }
33         if ( op->o_authmech.bv_val != NULL ) {
34                 free( op->o_authmech.bv_val );
35         }
36         if ( op->o_ctrls != NULL ) {
37                 ldap_controls_free( op->o_ctrls );
38         }
39
40 #ifdef LDAP_CONNECTIONLESS
41         if ( op->o_res_ber != NULL ) {
42                 ber_free( op->o_res_ber, 1 );
43         }
44 #endif
45 #ifdef LDAP_CLIENT_UPDATE
46         if ( op->o_clientupdate_state.bv_val != NULL ) {
47                 free( op->o_clientupdate_state.bv_val );
48         }
49 #endif
50 #ifdef LDAP_SYNC
51         if ( op->o_sync_state.bv_val != NULL ) {
52                 free( op->o_sync_state.bv_val );
53         }
54 #endif
55
56 #if defined( LDAP_SLAPI )
57         if ( op->o_pb != NULL ) {
58                 slapi_pblock_destroy( (Slapi_PBlock *)op->o_pb );
59         }
60 #endif /* defined( LDAP_SLAPI ) */
61
62         free( (char *) op );
63 }
64
65 Operation *
66 slap_op_alloc(
67     BerElement          *ber,
68     ber_int_t   msgid,
69     ber_tag_t   tag,
70     ber_int_t   id
71 )
72 {
73         Operation       *op;
74
75         op = (Operation *) ch_calloc( 1, sizeof(Operation) );
76
77         op->o_ber = ber;
78         op->o_msgid = msgid;
79         op->o_tag = tag;
80
81         op->o_time = slap_get_time();
82         op->o_opid = id;
83 #ifdef LDAP_CONNECTIONLESS
84         op->o_res_ber = NULL;
85 #endif
86
87 #if defined( LDAP_SLAPI )
88         op->o_pb = slapi_pblock_new();
89 #endif /* defined( LDAP_SLAPI ) */
90
91         return( op );
92 }