]> git.sur5r.net Git - openldap/blob - servers/slapd/operation.c
if continuation line starts with a tab, rewrite it to a space
[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 != NULL ) {
27                 free( op->o_dn );
28         }
29         if ( op->o_ndn != NULL ) {
30                 free( op->o_ndn );
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 = NULL;
64         op->o_ndn = NULL;
65         op->o_authmech = NULL;
66         op->o_ctrls = NULL;
67
68         op->o_time = slap_get_time();
69         op->o_opid = id;
70         op->o_next = NULL;
71
72         return( op );
73 }
74
75 int slap_op_add(
76     Operation           **olist,
77         Operation               *op
78 )
79 {
80         Operation       **tmp;
81
82         for ( tmp = olist; *tmp != NULL; tmp = &(*tmp)->o_next )
83                 ;       /* NULL */
84
85         *tmp = op;
86
87         return 0;
88 }
89
90 int
91 slap_op_remove( Operation **olist, Operation *op )
92 {
93         Operation       **tmp;
94
95         for ( tmp = olist; *tmp != NULL && *tmp != op; tmp = &(*tmp)->o_next )
96                 ;       /* NULL */
97
98         if ( *tmp == NULL ) {
99 #ifdef NEW_LOGGING
100                 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
101                            "slap_op_remove: can't find op %ld.\n",
102                            (long)op->o_msgid ));
103 #else
104                 Debug( LDAP_DEBUG_ANY, "op_delete: can't find op %ld\n",
105                        (long) op->o_msgid, 0, 0 );
106 #endif
107
108                 return -1; 
109         }
110
111         *tmp = (*tmp)->o_next;
112         op->o_next = NULL;
113
114         return 0;
115 }
116
117 Operation * slap_op_pop( Operation **olist )
118 {
119         Operation *tmp = *olist;
120
121         if(tmp != NULL) {
122                 *olist = tmp->o_next;
123                 tmp->o_next = NULL;
124         }
125
126         return tmp;
127 }
128