flat_uri.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2008 iptelorg GmbH
  5. * Written by Jan Janak <[email protected]>
  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 it under the
  10. * terms of the GNU General Public License as published by the Free Software
  11. * Foundation; either version 2 of the License, or (at your option) any later
  12. * version.
  13. *
  14. * SER is distributed in the hope that it will be useful, but WITHOUT ANY
  15. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. /** \addtogroup flatstore
  24. * @{
  25. */
  26. /** \file
  27. * The implementation of parser parsing flatstore:.. URIs.
  28. */
  29. #include "flat_uri.h"
  30. #include "../../mem/mem.h"
  31. #include "../../ut.h"
  32. #include <stdlib.h>
  33. #include <string.h>
  34. static void flat_uri_free(db_uri_t* uri, struct flat_uri* payload)
  35. {
  36. if (payload == NULL) return;
  37. if (payload->path.s) free(payload->path.s);
  38. db_drv_free(&payload->drv);
  39. pkg_free(payload);
  40. }
  41. int flat_uri(db_uri_t* uri)
  42. {
  43. struct flat_uri* furi;
  44. if ((furi = (struct flat_uri*)pkg_malloc(sizeof(*furi))) == NULL) {
  45. ERR("flatstore: No memory left\n");
  46. return -1;
  47. }
  48. memset(furi, '\0', sizeof(*furi));
  49. if (db_drv_init(&furi->drv, flat_uri_free) < 0) goto error;
  50. if ((furi->path.s = get_abs_pathname(NULL, &uri->body)) == NULL) {
  51. ERR("flatstore: Error while obtaining absolute pathname for '%.*s'\n",
  52. STR_FMT(&uri->body));
  53. goto error;
  54. }
  55. furi->path.len = strlen(furi->path.s);
  56. DB_SET_PAYLOAD(uri, furi);
  57. return 0;
  58. error:
  59. if (furi) {
  60. if (furi->path.s) pkg_free(furi->path.s);
  61. db_drv_free(&furi->drv);
  62. pkg_free(furi);
  63. }
  64. return -1;
  65. }
  66. /** @} */