km_db_mysql.c 3.8 KB

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