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