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