]> git.sur5r.net Git - openldap/blob - servers/slapd/operation.c
Happy new year
[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_CLIENT_UPDATE
42         if ( op->o_clientupdate_state.bv_val != NULL ) {
43                 free( op->o_clientupdate_state.bv_val );
44         }
45 #endif /* LDAP_CLIENT_UPDATE */
46
47 #if defined( LDAP_SLAPI )
48         if ( op->o_pb != NULL ) {
49                 slapi_pblock_destroy( (Slapi_PBlock *)op->o_pb );
50         }
51 #endif /* defined( LDAP_SLAPI ) */
52
53         free( (char *) op );
54 }
55
56 Operation *
57 slap_op_alloc(
58     BerElement          *ber,
59     ber_int_t   msgid,
60     ber_tag_t   tag,
61     ber_int_t   id
62 )
63 {
64         Operation       *op;
65
66         op = (Operation *) ch_calloc( 1, sizeof(Operation) );
67
68         op->o_ber = ber;
69         op->o_msgid = msgid;
70         op->o_tag = tag;
71
72         op->o_time = slap_get_time();
73         op->o_opid = id;
74
75 #if defined( LDAP_SLAPI )
76         op->o_pb = slapi_pblock_new();
77 #endif /* defined( LDAP_SLAPI ) */
78
79         return( op );
80 }