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