1 /* $NetBSD: addentry.c,v 1.3 2021/08/14 16:14:55 christos Exp $ */
2
3 /* addentry.c */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 1998-2021 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 <sys/cdefs.h>
23 __RCSID("$NetBSD: addentry.c,v 1.3 2021/08/14 16:14:55 christos Exp $");
24
25 #include "portable.h"
26
27 #include <stdio.h>
28
29 #include <ac/stdlib.h>
30
31 #include <ac/socket.h>
32 #include <ac/string.h>
33 #include <ac/time.h>
34
35 #include "ldap-int.h"
36
37 LDAPMessage *
ldap_delete_result_entry(LDAPMessage ** list,LDAPMessage * e)38 ldap_delete_result_entry( LDAPMessage **list, LDAPMessage *e )
39 {
40 LDAPMessage *tmp, *prev = NULL;
41
42 assert( list != NULL );
43 assert( e != NULL );
44
45 for ( tmp = *list; tmp != NULL && tmp != e; tmp = tmp->lm_chain )
46 prev = tmp;
47
48 if ( tmp == NULL )
49 return( NULL );
50
51 if ( prev == NULL ) {
52 if ( tmp->lm_chain )
53 tmp->lm_chain->lm_chain_tail = (*list)->lm_chain_tail;
54 *list = tmp->lm_chain;
55 } else {
56 prev->lm_chain = tmp->lm_chain;
57 if ( prev->lm_chain == NULL )
58 (*list)->lm_chain_tail = prev;
59 }
60 tmp->lm_chain = NULL;
61
62 return( tmp );
63 }
64
65 void
ldap_add_result_entry(LDAPMessage ** list,LDAPMessage * e)66 ldap_add_result_entry( LDAPMessage **list, LDAPMessage *e )
67 {
68 assert( list != NULL );
69 assert( e != NULL );
70
71 e->lm_chain = *list;
72 if ( *list )
73 e->lm_chain_tail = (*list)->lm_chain_tail;
74 else
75 e->lm_chain_tail = e;
76 *list = e;
77 }
78