db_rec.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG FOKUS
  5. * Copyright (C) 2006-2007 iptelorg GmbH
  6. *
  7. * This file is part of ser, a free SIP server.
  8. *
  9. * ser is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * For a license to use the ser software under conditions
  15. * other than those described here, or to purchase support for this
  16. * software, please contact iptel.org by e-mail at the following addresses:
  17. * [email protected]
  18. *
  19. * ser is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. /** \ingroup DB_API
  29. * @{
  30. */
  31. #include "db_rec.h"
  32. #include "../../dprint.h"
  33. #include "../../mem/mem.h"
  34. #include <stdlib.h>
  35. #include <string.h>
  36. db_rec_t* db_rec(db_res_t* res, db_fld_t* fld)
  37. {
  38. db_rec_t* newp;
  39. newp = (db_rec_t*)pkg_malloc(sizeof(db_rec_t));
  40. if (newp == NULL) goto err;
  41. memset(newp, '\0', sizeof(db_rec_t));
  42. if (db_gen_init(&newp->gen) < 0) goto err;
  43. newp->res = res;
  44. newp->fld = fld;
  45. return newp;
  46. err:
  47. ERR("Cannot create db_rec structure\n");
  48. if (newp) {
  49. db_gen_free(&newp->gen);
  50. pkg_free(newp);
  51. }
  52. return NULL;
  53. }
  54. void db_rec_free(db_rec_t* r)
  55. {
  56. if (r == NULL) return;
  57. /* Do not release fld here, it points to an array in db_cmd */
  58. db_gen_free(&r->gen);
  59. pkg_free(r);
  60. }
  61. /** @} */