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