ld_res.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * $Id$
  3. *
  4. * LDAP Database Driver for SER
  5. *
  6. * Copyright (C) 2008 iptelorg GmbH
  7. *
  8. * This file is part of SER, a free SIP server.
  9. *
  10. * SER is free software; you can redistribute it and/or modify it under the
  11. * terms of the GNU General Public License as published by the Free Software
  12. * Foundation; either version 2 of the License, or (at your option) any later
  13. * version.
  14. *
  15. * SER is distributed in the hope that it will be useful, but WITHOUT ANY
  16. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  17. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  18. * details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. /** \addtogroup ldap
  25. * @{
  26. */
  27. /** \file
  28. * Functions working with result structures received from LDAP servers.
  29. */
  30. #include <string.h>
  31. #include "ld_res.h"
  32. #include "ld_cmd.h"
  33. #include "../../mem/mem.h"
  34. #include "../../dprint.h"
  35. #include "../../lib/srdb2/db_gen.h"
  36. static void ld_res_free(db_res_t* res, struct ld_res* payload)
  37. {
  38. db_drv_free(&payload->gen);
  39. if (payload->msg) ldap_msgfree(payload->msg);
  40. payload->msg = NULL;
  41. pkg_free(payload);
  42. }
  43. int ld_res(db_res_t* res)
  44. {
  45. struct ld_res* lres;
  46. lres = (struct ld_res*)pkg_malloc(sizeof(struct ld_res));
  47. if (lres == NULL) {
  48. ERR("ldap: No memory left\n");
  49. return -1;
  50. }
  51. memset(lres, '\0', sizeof(struct ld_res));
  52. if (db_drv_init(&lres->gen, ld_res_free) < 0) goto error;
  53. DB_SET_PAYLOAD(res, lres);
  54. return 0;
  55. error:
  56. if (lres) {
  57. db_drv_free(&lres->gen);
  58. pkg_free(lres);
  59. }
  60. return -1;
  61. }
  62. /** @} */