my_fld.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. */
  28. #include "my_fld.h"
  29. #include "../../mem/mem.h"
  30. #include "../../dprint.h"
  31. #include "../../lib/srdb2/db_gen.h"
  32. #include <string.h>
  33. static void my_fld_free(db_fld_t* fld, struct my_fld* payload)
  34. {
  35. db_drv_free(&payload->gen);
  36. if (payload->buf.s) pkg_free(payload->buf.s);
  37. if (payload->name) pkg_free(payload->name);
  38. pkg_free(payload);
  39. }
  40. int my_fld(db_fld_t* fld, char* table)
  41. {
  42. struct my_fld* res;
  43. res = (struct my_fld*)pkg_malloc(sizeof(struct my_fld));
  44. if (res == NULL) {
  45. ERR("mysql: No memory left\n");
  46. return -1;
  47. }
  48. memset(res, '\0', sizeof(struct my_fld));
  49. if (db_drv_init(&res->gen, my_fld_free) < 0) goto error;
  50. DB_SET_PAYLOAD(fld, res);
  51. return 0;
  52. error:
  53. if (res) pkg_free(res);
  54. return -1;
  55. }