km_db_mysql.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * MySQL module interface
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. * Copyright (C) 2008 1&1 Internet AG
  6. *
  7. * This file is part of Kamailio, a free SIP server.
  8. *
  9. * Kamailio is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * Kamailio is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*! \file
  24. * \brief DB_MYSQL :: Core
  25. * \ingroup db_mysql
  26. * Module: \ref db_mysql
  27. */
  28. /*! \defgroup db_mysql DB_MYSQL :: the MySQL driver for Kamailio
  29. * \brief The Kamailio database interface to the MySQL database
  30. * - http://www.mysql.org
  31. *
  32. */
  33. #include "../../sr_module.h"
  34. #include "../../dprint.h"
  35. #include "km_dbase.h"
  36. #include "km_db_mysql.h"
  37. #include <mysql/mysql.h>
  38. unsigned int db_mysql_timeout_interval = 2; /* Default is 6 seconds */
  39. unsigned int db_mysql_auto_reconnect = 1; /* Default is enabled */
  40. unsigned int db_mysql_insert_all_delayed = 0; /* Default is off */
  41. unsigned int db_mysql_update_affected_found = 0; /* Default is off */
  42. /* MODULE_VERSION */
  43. /*! \brief
  44. * MySQL database module interface
  45. */
  46. static kam_cmd_export_t cmds[] = {
  47. {"db_bind_api", (cmd_function)db_mysql_bind_api, 0, 0, 0, 0},
  48. {0, 0, 0, 0, 0, 0}
  49. };
  50. /*! \brief
  51. * Exported parameters
  52. */
  53. static param_export_t params[] = {
  54. /* {"ping_interval", INT_PARAM, &db_mysql_ping_interval}, */
  55. {"timeout_interval", INT_PARAM, &db_mysql_timeout_interval},
  56. {"auto_reconnect", INT_PARAM, &db_mysql_auto_reconnect},
  57. {0, 0, 0}
  58. };
  59. struct kam_module_exports kam_exports = {
  60. "db_mysql",
  61. DEFAULT_DLFLAGS, /* dlopen flags */
  62. cmds,
  63. params, /* module parameters */
  64. 0, /* exported statistics */
  65. 0, /* exported MI functions */
  66. 0, /* exported pseudo-variables */
  67. 0, /* extra processes */
  68. kam_mysql_mod_init, /* module initialization function */
  69. 0, /* response function*/
  70. 0, /* destroy function */
  71. 0 /* per-child init function */
  72. };
  73. int kam_mysql_mod_init(void)
  74. {
  75. LM_DBG("MySQL client version is %s\n", mysql_get_client_info());
  76. return 0;
  77. }
  78. int db_mysql_bind_api(db_func_t *dbb)
  79. {
  80. if(dbb==NULL)
  81. return -1;
  82. memset(dbb, 0, sizeof(db_func_t));
  83. dbb->use_table = db_mysql_use_table;
  84. dbb->init = db_mysql_init;
  85. dbb->close = db_mysql_close;
  86. dbb->query = db_mysql_query;
  87. dbb->fetch_result = db_mysql_fetch_result;
  88. dbb->raw_query = db_mysql_raw_query;
  89. dbb->free_result = (db_free_result_f) db_mysql_free_result;
  90. dbb->insert = db_mysql_insert;
  91. dbb->delete = db_mysql_delete;
  92. dbb->update = db_mysql_update;
  93. dbb->replace = db_mysql_replace;
  94. dbb->last_inserted_id = db_mysql_last_inserted_id;
  95. dbb->insert_update = db_mysql_insert_update;
  96. dbb->insert_delayed = db_mysql_insert_delayed;
  97. dbb->affected_rows = db_mysql_affected_rows;
  98. dbb->start_transaction= db_mysql_start_transaction;
  99. dbb->end_transaction = db_mysql_end_transaction;
  100. dbb->abort_transaction= db_mysql_abort_transaction;
  101. dbb->raw_query_async = db_mysql_raw_query_async;
  102. dbb->insert_async = db_mysql_insert_async;
  103. return 0;
  104. }