bdb_fld.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * $Id$
  3. *
  4. * BDB Database Driver for SIP-router
  5. *
  6. * Copyright (C) 2008 iptelorg GmbH
  7. *
  8. * This file is part of SIP-router, a free SIP server.
  9. *
  10. * SIP-router 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. * SIP-router 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 bdb
  25. * @{
  26. */
  27. /** \file
  28. * Data field conversion and type checking functions.
  29. *
  30. * \ingroup database
  31. */
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <strings.h>
  35. #include <stdint.h>
  36. #include <string.h>
  37. #include <time.h> /* strptime, XOPEN issue must be >= 4 */
  38. #include "../../lib/srdb2/db_drv.h"
  39. #include "../../mem/mem.h"
  40. #include "../../dprint.h"
  41. #include "../../ut.h"
  42. #include "bdb_fld.h"
  43. static void bdb_fld_free(db_fld_t* fld, bdb_fld_t* payload)
  44. {
  45. db_drv_free(&payload->gen);
  46. if (payload->buf.s) pkg_free(payload->buf.s);
  47. if (payload->name) pkg_free(payload->name);
  48. pkg_free(payload);
  49. }
  50. int bdb_fld(db_fld_t* fld, char* table)
  51. {
  52. bdb_fld_t *res;
  53. res = (bdb_fld_t*)pkg_malloc(sizeof(bdb_fld_t));
  54. if (res == NULL) {
  55. ERR("oracle: No memory left\n");
  56. return -1;
  57. }
  58. memset(res, '\0', sizeof(bdb_fld_t));
  59. res->col_pos = -1;
  60. if (db_drv_init(&res->gen, bdb_fld_free) < 0) goto error;
  61. DB_SET_PAYLOAD(fld, res);
  62. return 0;
  63. error:
  64. if (res) pkg_free(res);
  65. return -1;
  66. }
  67. /** @} */