]> git.sur5r.net Git - openldap/blob - servers/slapd/operation.c
a4401bced5a7a47ebedebe1518a72ec7aa5daa8f
[openldap] / servers / slapd / operation.c
1 /* operation.c - routines to deal with pending ldap operations */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10
11 #include <ac/string.h>
12 #include <ac/socket.h>
13
14 #include "slap.h"
15
16
17 void
18 slap_op_free( Operation *op )
19 {
20         assert( op->o_next == NULL );
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         if ( op->o_authmech != NULL ) {
32                 free( op->o_authmech );
33         }
34         if ( op->o_ctrls != NULL ) {
35                 ldap_controls_free( op->o_ctrls );
36         }
37
38         ldap_pvt_thread_mutex_destroy( &op->o_abandonmutex );
39
40         free( (char *) op );
41 }
42
43 Operation *
44 slap_op_alloc(
45     BerElement          *ber,
46     ber_int_t   msgid,
47     ber_tag_t   tag,
48     ber_int_t   id
49 )
50 {
51         Operation       *op;
52
53         op = (Operation *) ch_calloc( 1, sizeof(Operation) );
54
55         ldap_pvt_thread_mutex_init( &op->o_abandonmutex );
56         op->o_abandon = 0;
57
58         op->o_ber = ber;
59         op->o_msgid = msgid;
60         op->o_tag = tag;
61
62         op->o_dn = NULL;
63         op->o_ndn = NULL;
64         op->o_authmech = NULL;
65         op->o_ctrls = NULL;
66
67         op->o_time = slap_get_time();
68         op->o_opid = id;
69         op->o_next = NULL;
70
71         return( op );
72 }
73
74 int slap_op_add(
75     Operation           **olist,
76         Operation               *op
77 )
78 {
79         Operation       **tmp;
80
81         for ( tmp = olist; *tmp != NULL; tmp = &(*tmp)->o_next )
82                 ;       /* NULL */
83
84         *tmp = op;
85
86         return 0;
87 }
88
89 int
90 slap_op_remove( Operation **olist, Operation *op )
91 {
92         Operation       **tmp;
93
94         for ( tmp = olist; *tmp != NULL && *tmp != op; tmp = &(*tmp)->o_next )
95                 ;       /* NULL */
96
97         if ( *tmp == NULL ) {
98                 Debug( LDAP_DEBUG_ANY, "op_delete: can't find op %ld\n",
99                     op->o_msgid, 0, 0 );
100                 return -1; 
101         }
102
103         *tmp = (*tmp)->o_next;
104         op->o_next = NULL;
105
106         return 0;
107 }
108
109 Operation * slap_op_pop( Operation **olist )
110 {
111         Operation *tmp = *olist;
112
113         if(tmp != NULL) {
114                 *olist = tmp->o_next;
115                 tmp->o_next = NULL;
116         }
117
118         return tmp;
119 }
120