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