]> git.sur5r.net Git - openldap/blob - servers/slapd/operation.c
Import slap_op changes from -devel.
[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         ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
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_unlock( &op->o_abandonmutex );
29         ldap_pvt_thread_mutex_destroy( &op->o_abandonmutex );
30
31         free( (char *) op );
32 }
33
34 Operation *
35 slap_op_add(
36     Operation           **olist,
37     BerElement          *ber,
38     unsigned long       msgid,
39     unsigned long       tag,
40     char                        *dn,
41     int                         id,
42     int                         connid
43 )
44 {
45         Operation       **tmp;
46
47         for ( tmp = olist; *tmp != NULL; tmp = &(*tmp)->o_next )
48                 ;       /* NULL */
49
50         *tmp = (Operation *) ch_calloc( 1, sizeof(Operation) );
51
52         ldap_pvt_thread_mutex_init( &(*tmp)->o_abandonmutex );
53         (*tmp)->o_ber = ber;
54         (*tmp)->o_msgid = msgid;
55         (*tmp)->o_tag = tag;
56         (*tmp)->o_abandon = 0;
57
58         (*tmp)->o_dn = ch_strdup( dn != NULL ? dn : "" );
59         (*tmp)->o_ndn = dn_normalize_case( ch_strdup( (*tmp)->o_dn ) );
60
61         ldap_pvt_thread_mutex_lock( &currenttime_mutex );
62         (*tmp)->o_time = currenttime;
63         ldap_pvt_thread_mutex_unlock( &currenttime_mutex );
64         (*tmp)->o_opid = id;
65         (*tmp)->o_connid = connid;
66         (*tmp)->o_next = NULL;
67
68         return( *tmp );
69 }
70
71 void
72 slap_op_delete( Operation **olist, Operation *op )
73 {
74         Operation       **tmp;
75
76         for ( tmp = olist; *tmp != NULL && *tmp != op; tmp = &(*tmp)->o_next )
77                 ;       /* NULL */
78
79         if ( *tmp == NULL ) {
80                 Debug( LDAP_DEBUG_ANY, "op_delete: can't find op %ld\n",
81                     op->o_msgid, 0, 0 );
82                 slap_op_free( op );
83                 return; 
84         }
85
86         *tmp = (*tmp)->o_next;
87         slap_op_free( op );
88 }