db_sqlite.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * $Id$
  3. *
  4. * SQlite module interface
  5. *
  6. * Copyright (C) 2010 Timo Teräs
  7. *
  8. * This file is part of Kamailio, a free SIP server.
  9. *
  10. * Kamailio is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * Kamailio is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include <sys/time.h>
  25. #include <sqlite3.h>
  26. #include "../../sr_module.h"
  27. #include "../../lib/srdb1/db_query.h"
  28. #include "../../lib/srdb1/db.h"
  29. #include "dbase.h"
  30. MODULE_VERSION
  31. static int sqlite_bind_api(db_func_t *dbb)
  32. {
  33. if(dbb==NULL)
  34. return -1;
  35. memset(dbb, 0, sizeof(db_func_t));
  36. dbb->use_table = db_sqlite_use_table;
  37. dbb->init = db_sqlite_init;
  38. dbb->close = db_sqlite_close;
  39. dbb->free_result = db_sqlite_free_result;
  40. dbb->query = db_sqlite_query;
  41. dbb->insert = db_sqlite_insert;
  42. dbb->delete = db_sqlite_delete;
  43. dbb->update = db_sqlite_update;
  44. dbb->raw_query = db_sqlite_raw_query;
  45. return 0;
  46. }
  47. static cmd_export_t cmds[] = {
  48. {"db_bind_api", (cmd_function)sqlite_bind_api, 0, 0, 0, 0},
  49. {0, 0, 0, 0, 0, 0}
  50. };
  51. int mod_register(char *path, int *dlflags, void *p1, void *p2)
  52. {
  53. if(db_api_init()<0)
  54. return -1;
  55. return 0;
  56. }
  57. static int sqlite_mod_init(void)
  58. {
  59. sqlite3_initialize();
  60. LM_INFO("SQlite library version %s (compiled using %s)\n",
  61. sqlite3_libversion(),
  62. SQLITE_VERSION);
  63. return 0;
  64. }
  65. static void sqlite_mod_destroy(void)
  66. {
  67. LM_INFO("SQlite terminate\n");
  68. sqlite3_shutdown();
  69. }
  70. struct module_exports exports = {
  71. "db_sqlite",
  72. DEFAULT_DLFLAGS, /* dlopen flags */
  73. cmds, /* module commands */
  74. 0, /* module parameters */
  75. 0, /* exported statistics */
  76. 0, /* exported MI functions */
  77. 0, /* exported pseudo-variables */
  78. 0, /* extra processes */
  79. sqlite_mod_init, /* module initialization function */
  80. 0, /* response function*/
  81. sqlite_mod_destroy, /* destroy function */
  82. 0 /* per-child init function */
  83. };