]> git.sur5r.net Git - openldap/blob - servers/slapd/operation.c
7f90af431d0bb55f4199d85af5f7bc6d85287280
[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 #include "slapi_common.h"
10
11 #include <stdio.h>
12
13 #include <ac/string.h>
14 #include <ac/socket.h>
15
16 #include "slap.h"
17 #include "slapi.h"
18
19
20 void
21 slap_op_free( Operation *op )
22 {
23         assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );
24
25         if ( op->o_ber != NULL ) {
26                 ber_free( op->o_ber, 1 );
27         }
28         if ( op->o_dn.bv_val != NULL ) {
29                 free( op->o_dn.bv_val );
30         }
31         if ( op->o_ndn.bv_val != NULL ) {
32                 free( op->o_ndn.bv_val );
33         }
34         if ( op->o_authmech.bv_val != NULL ) {
35                 free( op->o_authmech.bv_val );
36         }
37         if ( op->o_ctrls != NULL ) {
38                 ldap_controls_free( op->o_ctrls );
39         }
40
41 #ifdef LDAP_CONNECTIONLESS
42         if ( op->o_res_ber != NULL ) {
43                 ber_free( op->o_res_ber, 1 );
44         }
45 #endif
46 #ifdef LDAP_CLIENT_UPDATE
47         if ( op->o_clientupdate_state.bv_val != NULL ) {
48                 free( op->o_clientupdate_state.bv_val );
49         }
50 #endif /* LDAP_CLIENT_UPDATE */
51
52 #if defined( LDAP_SLAPI )
53         if ( op->o_pb != NULL ) {
54                 slapi_pblock_destroy( (Slapi_PBlock *)op->o_pb );
55         }
56 #endif /* defined( LDAP_SLAPI ) */
57
58         free( (char *) op );
59 }
60
61 Operation *
62 slap_op_alloc(
63     BerElement          *ber,
64     ber_int_t   msgid,
65     ber_tag_t   tag,
66     ber_int_t   id
67 )
68 {
69         Operation       *op;
70
71         op = (Operation *) ch_calloc( 1, sizeof(Operation) );
72
73         op->o_ber = ber;
74         op->o_msgid = msgid;
75         op->o_tag = tag;
76
77         op->o_time = slap_get_time();
78         op->o_opid = id;
79 #ifdef LDAP_CONNECTIONLESS
80         op->o_res_ber = NULL;
81 #endif
82
83 #if defined( LDAP_SLAPI )
84         op->o_pb = slapi_pblock_new();
85 #endif /* defined( LDAP_SLAPI ) */
86
87         return( op );
88 }