]> git.sur5r.net Git - openldap/blob - servers/slapd/operation.c
e7b9600af0ab94eabdef9b66969b8ee8a67f109d
[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 /* LDAP_CLIENT_UPDATE */
50
51 #if defined( LDAP_SLAPI )
52         if ( op->o_pb != NULL ) {
53                 slapi_pblock_destroy( (Slapi_PBlock *)op->o_pb );
54         }
55 #endif /* defined( LDAP_SLAPI ) */
56
57         free( (char *) op );
58 }
59
60 Operation *
61 slap_op_alloc(
62     BerElement          *ber,
63     ber_int_t   msgid,
64     ber_tag_t   tag,
65     ber_int_t   id
66 )
67 {
68         Operation       *op;
69
70         op = (Operation *) ch_calloc( 1, sizeof(Operation) );
71
72         op->o_ber = ber;
73         op->o_msgid = msgid;
74         op->o_tag = tag;
75
76         op->o_time = slap_get_time();
77         op->o_opid = id;
78 #ifdef LDAP_CONNECTIONLESS
79         op->o_res_ber = NULL;
80 #endif
81
82 #if defined( LDAP_SLAPI )
83         op->o_pb = slapi_pblock_new();
84 #endif /* defined( LDAP_SLAPI ) */
85
86         return( op );
87 }