db_cluster_mod.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * $Id$
  3. *
  4. * Generic db cluster module interface
  5. *
  6. * Copyright (C) 2012 Daniel-Constantin Mierla (asipto.com)
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #include "../../sr_module.h"
  25. #include "../../dprint.h"
  26. #include "../../lib/srdb1/db.h"
  27. #include "dbcl_data.h"
  28. #include "dbcl_api.h"
  29. MODULE_VERSION
  30. int mod_init(void);
  31. int db_cluster_bind_api(db_func_t *dbb);
  32. int dbcl_con_param(modparam_t type, void *val);
  33. int dbcl_cls_param(modparam_t type, void *val);
  34. int dbcl_inactive_interval = 300;
  35. /*! \brief
  36. * DB Cluster module interface
  37. */
  38. static cmd_export_t cmds[] = {
  39. {"db_bind_api", (cmd_function)db_cluster_bind_api, 0, 0, 0, 0},
  40. {0, 0, 0, 0, 0, 0}
  41. };
  42. /*! \brief
  43. * Exported parameters
  44. */
  45. static param_export_t params[] = {
  46. {"connection", STR_PARAM|USE_FUNC_PARAM, (void*)dbcl_con_param},
  47. {"cluster", STR_PARAM|USE_FUNC_PARAM, (void*)dbcl_cls_param},
  48. {"inactive_interval", INT_PARAM, &dbcl_inactive_interval},
  49. {0, 0, 0}
  50. };
  51. struct module_exports exports = {
  52. "db_cluster",
  53. DEFAULT_DLFLAGS, /* dlopen flags */
  54. cmds,
  55. params, /* module parameters */
  56. 0, /* exported statistics */
  57. 0, /* exported MI functions */
  58. 0, /* exported pseudo-variables */
  59. 0, /* extra processes */
  60. mod_init, /* module initialization function */
  61. 0, /* response function*/
  62. 0, /* destroy function */
  63. 0 /* per-child init function */
  64. };
  65. int mod_init(void)
  66. {
  67. LM_DBG("Setting up DB cluster\n");
  68. return 0;
  69. }
  70. int db_cluster_bind_api(db_func_t *dbb)
  71. {
  72. if(dbb==NULL)
  73. return -1;
  74. memset(dbb, 0, sizeof(db_func_t));
  75. dbb->use_table = db_cluster_use_table;
  76. dbb->init = db_cluster_init;
  77. dbb->close = db_cluster_close;
  78. dbb->query = db_cluster_query;
  79. dbb->fetch_result = db_cluster_fetch_result;
  80. dbb->raw_query = db_cluster_raw_query;
  81. dbb->free_result = db_cluster_free_result;
  82. dbb->insert = db_cluster_insert;
  83. dbb->delete = db_cluster_delete;
  84. dbb->update = db_cluster_update;
  85. dbb->replace = db_cluster_replace;
  86. dbb->last_inserted_id = db_cluster_last_inserted_id;
  87. dbb->insert_update = db_cluster_insert_update;
  88. dbb->insert_delayed = db_cluster_insert_delayed;
  89. dbb->affected_rows = db_cluster_affected_rows;
  90. return 0;
  91. }
  92. int dbcl_con_param(modparam_t type, void *val)
  93. {
  94. return dbcl_parse_con_param((char*)val);
  95. }
  96. int dbcl_cls_param(modparam_t type, void *val)
  97. {
  98. return dbcl_parse_cls_param((char*)val);
  99. }