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