db_cluster_mod.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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. int dbcl_max_query_length = 0;
  36. /*! \brief
  37. * DB Cluster module interface
  38. */
  39. static cmd_export_t cmds[] = {
  40. {"db_bind_api", (cmd_function)db_cluster_bind_api, 0, 0, 0, 0},
  41. {0, 0, 0, 0, 0, 0}
  42. };
  43. /*! \brief
  44. * Exported parameters
  45. */
  46. static param_export_t params[] = {
  47. {"connection", PARAM_STRING|USE_FUNC_PARAM, (void*)dbcl_con_param},
  48. {"cluster", PARAM_STRING|USE_FUNC_PARAM, (void*)dbcl_cls_param},
  49. {"inactive_interval", INT_PARAM, &dbcl_inactive_interval},
  50. {"max_query_length", INT_PARAM, &dbcl_max_query_length},
  51. {0, 0, 0}
  52. };
  53. struct module_exports exports = {
  54. "db_cluster",
  55. DEFAULT_DLFLAGS, /* dlopen flags */
  56. cmds,
  57. params, /* module parameters */
  58. 0, /* exported statistics */
  59. 0, /* exported MI functions */
  60. 0, /* exported pseudo-variables */
  61. 0, /* extra processes */
  62. mod_init, /* module initialization function */
  63. 0, /* response function*/
  64. 0, /* destroy function */
  65. 0 /* per-child init function */
  66. };
  67. int mod_init(void)
  68. {
  69. LM_DBG("Setting up DB cluster\n");
  70. return 0;
  71. }
  72. int db_cluster_bind_api(db_func_t *dbb)
  73. {
  74. if(dbb==NULL)
  75. return -1;
  76. memset(dbb, 0, sizeof(db_func_t));
  77. dbb->use_table = db_cluster_use_table;
  78. dbb->init = db_cluster_init;
  79. dbb->close = db_cluster_close;
  80. dbb->query = db_cluster_query;
  81. dbb->fetch_result = db_cluster_fetch_result;
  82. dbb->raw_query = db_cluster_raw_query;
  83. dbb->free_result = db_cluster_free_result;
  84. dbb->insert = db_cluster_insert;
  85. dbb->delete = db_cluster_delete;
  86. dbb->update = db_cluster_update;
  87. dbb->replace = db_cluster_replace;
  88. dbb->last_inserted_id = db_cluster_last_inserted_id;
  89. dbb->insert_update = db_cluster_insert_update;
  90. dbb->insert_delayed = db_cluster_insert_delayed;
  91. dbb->affected_rows = db_cluster_affected_rows;
  92. return 0;
  93. }
  94. int dbcl_con_param(modparam_t type, void *val)
  95. {
  96. return dbcl_parse_con_param((char*)val);
  97. }
  98. int dbcl_cls_param(modparam_t type, void *val)
  99. {
  100. return dbcl_parse_cls_param((char*)val);
  101. }