openldap/servers/slapd/operation.c

122 lines
1.9 KiB
C
Raw Normal View History

1998-08-09 08:43:13 +08:00
/* operation.c - routines to deal with pending ldap operations */
/* $OpenLDAP$ */
1999-08-07 07:07:46 +08:00
/*
2000-05-13 10:47:56 +08:00
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
1999-08-07 07:07:46 +08:00
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
1998-08-09 08:43:13 +08:00
1998-10-25 09:41:42 +08:00
#include "portable.h"
1998-08-09 08:43:13 +08:00
#include <stdio.h>
1998-10-25 09:41:42 +08:00
#include <ac/string.h>
#include <ac/socket.h>
1998-08-09 08:43:13 +08:00
#include "slap.h"
void
slap_op_free( Operation *op )
1998-08-09 08:43:13 +08:00
{
assert( op->o_next == NULL );
if ( op->o_ber != NULL ) {
1998-08-09 08:43:13 +08:00
ber_free( op->o_ber, 1 );
}
1998-08-09 08:43:13 +08:00
if ( op->o_dn != NULL ) {
free( op->o_dn );
}
if ( op->o_ndn != NULL ) {
free( op->o_ndn );
}
if ( op->o_authmech != NULL ) {
free( op->o_authmech );
}
1999-07-06 07:01:17 +08:00
if ( op->o_ctrls != NULL ) {
ldap_controls_free( op->o_ctrls );
}
ldap_pvt_thread_mutex_destroy( &op->o_abandonmutex );
1998-08-09 08:43:13 +08:00
free( (char *) op );
}
Operation *
slap_op_alloc(
1998-08-09 08:43:13 +08:00
BerElement *ber,
ber_int_t msgid,
ber_tag_t tag,
ber_int_t id
1998-08-09 08:43:13 +08:00
)
{
Operation *op;
1998-08-09 08:43:13 +08:00
op = (Operation *) ch_calloc( 1, sizeof(Operation) );
ldap_pvt_thread_mutex_init( &op->o_abandonmutex );
op->o_abandon = 0;
op->o_ber = ber;
op->o_msgid = msgid;
op->o_tag = tag;
op->o_dn = NULL;
op->o_ndn = NULL;
op->o_authmech = NULL;
1999-07-06 07:01:17 +08:00
op->o_ctrls = NULL;
op->o_time = slap_get_time();
op->o_opid = id;
op->o_next = NULL;
1998-08-09 08:43:13 +08:00
return( op );
1998-08-09 08:43:13 +08:00
}
int slap_op_add(
Operation **olist,
Operation *op
)
{
Operation **tmp;
for ( tmp = olist; *tmp != NULL; tmp = &(*tmp)->o_next )
; /* NULL */
*tmp = op;
return 0;
}
int
slap_op_remove( Operation **olist, Operation *op )
1998-08-09 08:43:13 +08:00
{
Operation **tmp;
for ( tmp = olist; *tmp != NULL && *tmp != op; tmp = &(*tmp)->o_next )
; /* NULL */
if ( *tmp == NULL ) {
Debug( LDAP_DEBUG_ANY, "op_delete: can't find op %ld\n",
1999-09-02 16:11:54 +08:00
(long) op->o_msgid, 0, 0 );
return -1;
1998-08-09 08:43:13 +08:00
}
*tmp = (*tmp)->o_next;
op->o_next = NULL;
return 0;
1998-08-09 08:43:13 +08:00
}
Operation * slap_op_pop( Operation **olist )
{
Operation *tmp = *olist;
if(tmp != NULL) {
*olist = tmp->o_next;
tmp->o_next = NULL;
}
return tmp;
}