Back to index

openldap  2.4.31
addentry.c
Go to the documentation of this file.
00001 /* addentry.c */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 1998-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
00017  * All rights reserved.
00018  */
00019 
00020 #include "portable.h"
00021 
00022 #include <stdio.h>
00023 
00024 #include <ac/stdlib.h>
00025 
00026 #include <ac/socket.h>
00027 #include <ac/string.h>
00028 #include <ac/time.h>
00029 
00030 #include "ldap-int.h"
00031 
00032 LDAPMessage *
00033 ldap_delete_result_entry( LDAPMessage **list, LDAPMessage *e )
00034 {
00035        LDAPMessage   *tmp, *prev = NULL;
00036 
00037        assert( list != NULL );
00038        assert( e != NULL );
00039 
00040        for ( tmp = *list; tmp != NULL && tmp != e; tmp = tmp->lm_chain )
00041               prev = tmp;
00042 
00043        if ( tmp == NULL )
00044               return( NULL );
00045 
00046        if ( prev == NULL ) {
00047               if ( tmp->lm_chain )
00048                      tmp->lm_chain->lm_chain_tail = (*list)->lm_chain_tail;
00049               *list = tmp->lm_chain;
00050        } else {
00051               prev->lm_chain = tmp->lm_chain;
00052               if ( prev->lm_chain == NULL )
00053                      (*list)->lm_chain_tail = prev;
00054        }
00055        tmp->lm_chain = NULL;
00056 
00057        return( tmp );
00058 }
00059 
00060 void
00061 ldap_add_result_entry( LDAPMessage **list, LDAPMessage *e )
00062 {
00063        assert( list != NULL );
00064        assert( e != NULL );
00065 
00066        e->lm_chain = *list;
00067        if ( *list )
00068               e->lm_chain_tail = (*list)->lm_chain_tail;
00069        else
00070               e->lm_chain_tail = e;
00071        *list = e;
00072 }