addentry.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* addentry.c */
  2. /* $OpenLDAP$ */
  3. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  4. *
  5. * Copyright 1998-2022 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. #include "portable.h"
  20. #include <stdio.h>
  21. #include <ac/stdlib.h>
  22. #include <ac/socket.h>
  23. #include <ac/string.h>
  24. #include <ac/time.h>
  25. #include "ldap-int.h"
  26. LDAPMessage *
  27. ldap_delete_result_entry( LDAPMessage **list, LDAPMessage *e )
  28. {
  29. LDAPMessage *tmp, *prev = NULL;
  30. assert( list != NULL );
  31. assert( e != NULL );
  32. for ( tmp = *list; tmp != NULL && tmp != e; tmp = tmp->lm_chain )
  33. prev = tmp;
  34. if ( tmp == NULL )
  35. return( NULL );
  36. if ( prev == NULL ) {
  37. if ( tmp->lm_chain )
  38. tmp->lm_chain->lm_chain_tail = (*list)->lm_chain_tail;
  39. *list = tmp->lm_chain;
  40. } else {
  41. prev->lm_chain = tmp->lm_chain;
  42. if ( prev->lm_chain == NULL )
  43. (*list)->lm_chain_tail = prev;
  44. }
  45. tmp->lm_chain = NULL;
  46. return( tmp );
  47. }
  48. void
  49. ldap_add_result_entry( LDAPMessage **list, LDAPMessage *e )
  50. {
  51. assert( list != NULL );
  52. assert( e != NULL );
  53. e->lm_chain = *list;
  54. if ( *list )
  55. e->lm_chain_tail = (*list)->lm_chain_tail;
  56. else
  57. e->lm_chain_tail = e;
  58. *list = e;
  59. }