]> git.sur5r.net Git - openldap/blob - servers/slapd/operation.c
Update copyright statements
[openldap] / servers / slapd / operation.c
1 /* operation.c - routines to deal with pending ldap operations */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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
17
18 void
19 slap_op_free( Operation *op )
20 {
21         assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );
22
23         if ( op->o_ber != NULL ) {
24                 ber_free( op->o_ber, 1 );
25         }
26         if ( op->o_dn.bv_val != NULL ) {
27                 free( op->o_dn.bv_val );
28         }
29         if ( op->o_ndn.bv_val != NULL ) {
30                 free( op->o_ndn.bv_val );
31         }
32         if ( op->o_authmech != NULL ) {
33                 free( op->o_authmech );
34         }
35         if ( op->o_ctrls != NULL ) {
36                 ldap_controls_free( op->o_ctrls );
37         }
38
39         ldap_pvt_thread_mutex_destroy( &op->o_abandonmutex );
40
41         free( (char *) op );
42 }
43
44 Operation *
45 slap_op_alloc(
46     BerElement          *ber,
47     ber_int_t   msgid,
48     ber_tag_t   tag,
49     ber_int_t   id
50 )
51 {
52         Operation       *op;
53
54         op = (Operation *) ch_calloc( 1, sizeof(Operation) );
55
56         ldap_pvt_thread_mutex_init( &op->o_abandonmutex );
57
58         op->o_ber = ber;
59         op->o_msgid = msgid;
60         op->o_tag = tag;
61
62         op->o_time = slap_get_time();
63         op->o_opid = id;
64
65         return( op );
66 }
67
68 #if 0
69 int slap_op_add(
70     Operation           **olist,
71         Operation               *op
72 )
73 {
74         Operation       **tmp;
75
76         for ( tmp = olist; *tmp != NULL; tmp = &(*tmp)->o_next )
77                 ;       /* NULL */
78
79         *tmp = op;
80
81         return 0;
82 }
83
84 int
85 slap_op_remove( Operation **olist, Operation *op )
86 {
87         Operation       **tmp;
88
89         for ( tmp = olist; *tmp != NULL && *tmp != op; tmp = &(*tmp)->o_next )
90                 ;       /* NULL */
91
92         if ( *tmp == NULL ) {
93 #ifdef NEW_LOGGING
94                 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
95                            "slap_op_remove: can't find op %ld.\n",
96                            (long)op->o_msgid ));
97 #else
98                 Debug( LDAP_DEBUG_ANY, "op_delete: can't find op %ld\n",
99                        (long) op->o_msgid, 0, 0 );
100 #endif
101
102                 return -1; 
103         }
104
105         *tmp = (*tmp)->o_next;
106         op->o_next = NULL;
107
108         return 0;
109 }
110
111 Operation * slap_op_pop( Operation **olist )
112 {
113         Operation *tmp = *olist;
114
115         if(tmp != NULL) {
116                 *olist = tmp->o_next;
117                 tmp->o_next = NULL;
118         }
119
120         return tmp;
121 }
122 #endif