]> git.sur5r.net Git - openldap/blob - servers/slapd/operation.c
404e20d888c1b48a5b4df5c1dac178e332ceb52d
[openldap] / servers / slapd / operation.c
1 /* operation.c - routines to deal with pending ldap operations */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/string.h>
8 #include <ac/socket.h>
9
10 #include "slap.h"
11
12
13 void
14 slap_op_free( Operation *op )
15 {
16 #ifdef LDAP_DEBUG
17         assert( op->o_next == NULL );
18 #endif
19
20         ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
21
22         if ( op->o_ber != NULL ) {
23                 ber_free( op->o_ber, 1 );
24         }
25         if ( op->o_dn != NULL ) {
26                 free( op->o_dn );
27         }
28         if ( op->o_ndn != NULL ) {
29                 free( op->o_ndn );
30         }
31
32         ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
33         ldap_pvt_thread_mutex_destroy( &op->o_abandonmutex );
34         free( (char *) op );
35 }
36
37 Operation *
38 slap_op_alloc(
39     BerElement          *ber,
40     unsigned long       msgid,
41     unsigned long       tag,
42     int                         id,
43     int                         connid
44 )
45 {
46         Operation       *op;
47
48         op = (Operation *) ch_calloc( 1, sizeof(Operation) );
49
50         ldap_pvt_thread_mutex_init( &op->o_abandonmutex );
51         op->o_ber = ber;
52         op->o_msgid = msgid;
53         op->o_tag = tag;
54         op->o_abandon = 0;
55
56         op->o_dn = NULL;
57         op->o_ndn = NULL;
58
59         ldap_pvt_thread_mutex_lock( &currenttime_mutex );
60         op->o_time = currenttime;
61         ldap_pvt_thread_mutex_unlock( &currenttime_mutex );
62         op->o_opid = id;
63         op->o_connid = connid;
64         op->o_next = NULL;
65
66         return( op );
67 }
68
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                 Debug( LDAP_DEBUG_ANY, "op_delete: can't find op %ld\n",
94                     op->o_msgid, 0, 0 );
95                 return -1; 
96         }
97
98         *tmp = (*tmp)->o_next;
99         op->o_next = NULL;
100
101         return 0;
102 }
103
104 Operation * slap_op_pop( Operation **olist )
105 {
106         Operation *tmp = *olist;
107
108         if(tmp != NULL) {
109                 *olist = tmp->o_next;
110                 tmp->o_next = NULL;
111         }
112
113         return tmp;
114 }
115