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