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