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