db_oracle.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * $Id$
  3. *
  4. * Oracle module interface
  5. *
  6. * Copyright (C) 2007,2008 TRUNK MOBILE
  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. /*
  25. * History:
  26. * --------
  27. */
  28. #include <sys/time.h>
  29. #include <oci.h>
  30. #include "../../sr_module.h"
  31. #include "../../lib/srdb1/db.h"
  32. #include "../../lib/srdb1/db_query.h"
  33. #include "dbase.h"
  34. #include "asynch.h"
  35. static int oracle_mod_init(void);
  36. static void destroy(void);
  37. static int db_oracle_bind_api(db_func_t *dbb);
  38. MODULE_VERSION
  39. /*
  40. * Oracle database module interface
  41. */
  42. static cmd_export_t cmds[] = {
  43. {"db_bind_api", (cmd_function)db_oracle_bind_api, 0, 0, 0, 0},
  44. {0, 0, 0, 0, 0, 0}
  45. };
  46. /*
  47. * Exported parameters
  48. */
  49. static param_export_t params[] = {
  50. {"timeout", PARAM_STRING|USE_FUNC_PARAM, (void*)&set_timeout },
  51. {"reconnect", PARAM_STRING|USE_FUNC_PARAM, (void*)&set_reconnect },
  52. {0, 0, 0}
  53. };
  54. struct module_exports exports = {
  55. "db_oracle",
  56. DEFAULT_DLFLAGS, /* dlopen flags */
  57. cmds,
  58. params, /* module parameters */
  59. 0, /* exported statistics */
  60. 0, /* exported MI functions */
  61. 0, /* exported pseudo-variables */
  62. 0, /* extra processes */
  63. oracle_mod_init, /* module initialization function */
  64. 0, /* response function*/
  65. destroy, /* destroy function */
  66. 0 /* per-child init function */
  67. };
  68. int mod_register(char *path, int *dlflags, void *p1, void *p2)
  69. {
  70. if(db_api_init()<0)
  71. return -1;
  72. return 0;
  73. }
  74. static int oracle_mod_init(void)
  75. {
  76. sword major, minor, update, patch, port;
  77. OCIClientVersion(&major, &minor, &update, &patch, &port);
  78. LM_DBG("Oracle client version is %d.%d.%d.%d.%d\n",
  79. major, minor, update, patch, port);
  80. return 0;
  81. }
  82. static void destroy(void)
  83. {
  84. LM_INFO("Oracle terminate\n");
  85. OCITerminate(OCI_DEFAULT);
  86. }
  87. static int db_oracle_bind_api(db_func_t *dbb)
  88. {
  89. if(dbb==NULL)
  90. return -1;
  91. memset(dbb, 0, sizeof(db_func_t));
  92. dbb->use_table = db_oracle_use_table;
  93. dbb->init = db_oracle_init;
  94. dbb->close = db_oracle_close;
  95. dbb->query = db_oracle_query;
  96. dbb->raw_query = db_oracle_raw_query;
  97. dbb->free_result = db_oracle_free_result;
  98. dbb->insert = db_oracle_insert;
  99. dbb->delete = db_oracle_delete;
  100. dbb->update = db_oracle_update;
  101. return 0;
  102. }