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