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