1 /* operation.c - routines to deal with pending ldap operations */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
21 static ldap_pvt_thread_mutex_t slap_op_mutex;
22 static LDAP_STAILQ_HEAD(s_o, slap_op) slap_free_ops;
24 void slap_op_init(void)
26 ldap_pvt_thread_mutex_init( &slap_op_mutex );
27 LDAP_STAILQ_INIT(&slap_free_ops);
30 void slap_op_destroy(void)
34 while ( (o = LDAP_STAILQ_FIRST( &slap_free_ops )) != NULL) {
35 LDAP_STAILQ_REMOVE_HEAD( &slap_free_ops, o_next );
36 LDAP_STAILQ_NEXT(o, o_next) = NULL;
39 ldap_pvt_thread_mutex_destroy( &slap_op_mutex );
43 slap_op_free( Operation *op )
45 assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );
47 if ( op->o_ber != NULL ) {
48 /* Note - the ber and its buffer are in regular memory,
49 * so make sure not to use sl_free here.
51 ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, NULL );
52 ber_free( op->o_ber, 1 );
54 if ( op->o_dn.bv_val != NULL ) {
55 free( op->o_dn.bv_val );
57 if ( op->o_ndn.bv_val != NULL ) {
58 free( op->o_ndn.bv_val );
60 if ( op->o_authmech.bv_val != NULL ) {
61 free( op->o_authmech.bv_val );
63 if ( op->o_ctrls != NULL ) {
64 slap_free_ctrls( op, op->o_ctrls );
67 #ifdef LDAP_CONNECTIONLESS
68 if ( op->o_res_ber != NULL ) {
69 ber_free( op->o_res_ber, 1 );
72 #ifdef LDAP_CLIENT_UPDATE
73 if ( op->o_clientupdate_state.bv_val != NULL ) {
74 free( op->o_clientupdate_state.bv_val );
78 if ( op->o_sync_state.bv_val != NULL ) {
79 free( op->o_sync_state.bv_val );
83 #if defined( LDAP_SLAPI )
84 if ( op->o_pb != NULL ) {
85 slapi_pblock_destroy( (Slapi_PBlock *)op->o_pb );
87 #endif /* defined( LDAP_SLAPI ) */
89 memset( op, 0, sizeof(Operation) );
90 ldap_pvt_thread_mutex_lock( &slap_op_mutex );
91 LDAP_STAILQ_INSERT_HEAD( &slap_free_ops, op, o_next );
92 ldap_pvt_thread_mutex_unlock( &slap_op_mutex );
105 ldap_pvt_thread_mutex_lock( &slap_op_mutex );
106 if ((op = LDAP_STAILQ_FIRST( &slap_free_ops ))) {
107 LDAP_STAILQ_REMOVE_HEAD( &slap_free_ops, o_next );
109 ldap_pvt_thread_mutex_unlock( &slap_op_mutex );
112 op = (Operation *) ch_calloc( 1, sizeof(Operation) );
118 op->o_time = slap_get_time();
120 #ifdef LDAP_CONNECTIONLESS
121 op->o_res_ber = NULL;
124 #if defined( LDAP_SLAPI )
125 op->o_pb = slapi_pblock_new();
126 #endif /* defined( LDAP_SLAPI ) */