km_db_mysql.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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. /* MODULE_VERSION */
  50. /*! \brief
  51. * MySQL database module interface
  52. */
  53. static kam_cmd_export_t cmds[] = {
  54. {"db_bind_api", (cmd_function)db_mysql_bind_api, 0, 0, 0, 0},
  55. {0, 0, 0, 0, 0, 0}
  56. };
  57. /*! \brief
  58. * Exported parameters
  59. */
  60. static param_export_t params[] = {
  61. /* {"ping_interval", INT_PARAM, &db_mysql_ping_interval}, */
  62. {"timeout_interval", INT_PARAM, &db_mysql_timeout_interval},
  63. {"auto_reconnect", INT_PARAM, &db_mysql_auto_reconnect},
  64. {0, 0, 0}
  65. };
  66. struct kam_module_exports kam_exports = {
  67. "db_mysql",
  68. DEFAULT_DLFLAGS, /* dlopen flags */
  69. cmds,
  70. params, /* module parameters */
  71. 0, /* exported statistics */
  72. 0, /* exported MI functions */
  73. 0, /* exported pseudo-variables */
  74. 0, /* extra processes */
  75. kam_mysql_mod_init, /* module initialization function */
  76. 0, /* response function*/
  77. 0, /* destroy function */
  78. 0 /* per-child init function */
  79. };
  80. int kam_mysql_mod_init(void)
  81. {
  82. LM_DBG("MySQL client version is %s\n", mysql_get_client_info());
  83. return 0;
  84. }
  85. int db_mysql_bind_api(db_func_t *dbb)
  86. {
  87. if(dbb==NULL)
  88. return -1;
  89. memset(dbb, 0, sizeof(db_func_t));
  90. dbb->use_table = db_mysql_use_table;
  91. dbb->init = db_mysql_init;
  92. dbb->close = db_mysql_close;
  93. dbb->query = db_mysql_query;
  94. dbb->fetch_result = db_mysql_fetch_result;
  95. dbb->raw_query = db_mysql_raw_query;
  96. dbb->free_result = db_mysql_free_result;
  97. dbb->insert = db_mysql_insert;
  98. dbb->delete = db_mysql_delete;
  99. dbb->update = db_mysql_update;
  100. dbb->replace = db_mysql_replace;
  101. dbb->last_inserted_id = db_mysql_last_inserted_id;
  102. dbb->insert_update = db_mysql_insert_update;
  103. dbb->insert_delayed = db_mysql_insert_delayed;
  104. dbb->affected_rows = db_mysql_affected_rows;
  105. dbb->start_transaction= db_mysql_start_transaction;
  106. dbb->end_transaction = db_mysql_end_transaction;
  107. dbb->abort_transaction= db_mysql_abort_transaction;
  108. return 0;
  109. }