xref: /netbsd-src/external/bsd/openldap/dist/libraries/libldap/addentry.c (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1 /*	$NetBSD: addentry.c,v 1.1.1.4 2014/05/28 09:58:41 tron Exp $	*/
2 
3 /* addentry.c */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6  *
7  * Copyright 1998-2014 The OpenLDAP Foundation.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
19  * All rights reserved.
20  */
21 
22 #include "portable.h"
23 
24 #include <stdio.h>
25 
26 #include <ac/stdlib.h>
27 
28 #include <ac/socket.h>
29 #include <ac/string.h>
30 #include <ac/time.h>
31 
32 #include "ldap-int.h"
33 
34 LDAPMessage *
35 ldap_delete_result_entry( LDAPMessage **list, LDAPMessage *e )
36 {
37 	LDAPMessage	*tmp, *prev = NULL;
38 
39 	assert( list != NULL );
40 	assert( e != NULL );
41 
42 	for ( tmp = *list; tmp != NULL && tmp != e; tmp = tmp->lm_chain )
43 		prev = tmp;
44 
45 	if ( tmp == NULL )
46 		return( NULL );
47 
48 	if ( prev == NULL ) {
49 		if ( tmp->lm_chain )
50 			tmp->lm_chain->lm_chain_tail = (*list)->lm_chain_tail;
51 		*list = tmp->lm_chain;
52 	} else {
53 		prev->lm_chain = tmp->lm_chain;
54 		if ( prev->lm_chain == NULL )
55 			(*list)->lm_chain_tail = prev;
56 	}
57 	tmp->lm_chain = NULL;
58 
59 	return( tmp );
60 }
61 
62 void
63 ldap_add_result_entry( LDAPMessage **list, LDAPMessage *e )
64 {
65 	assert( list != NULL );
66 	assert( e != NULL );
67 
68 	e->lm_chain = *list;
69 	if ( *list )
70 		e->lm_chain_tail = (*list)->lm_chain_tail;
71 	else
72 		e->lm_chain_tail = e;
73 	*list = e;
74 }
75