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