2
0

mysql_mod.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * $Id$
  3. *
  4. * MySQL module interface
  5. *
  6. * Copyright (C) 2001-2003 FhG Fokus
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser 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. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. */
  29. /*
  30. * History:
  31. * --------
  32. * 2003-03-11 updated to the new module exports interface (andrei)
  33. * 2003-03-16 flags export parameter added (janakj)
  34. */
  35. /** @addtogroup mysql
  36. * @{
  37. */
  38. #include "../../sr_module.h"
  39. #include "../../db/db.h"
  40. #include "my_uri.h"
  41. #include "my_con.h"
  42. #include "my_cmd.h"
  43. #include "my_fld.h"
  44. #include "my_res.h"
  45. #include "mysql_mod.h"
  46. int ping_interval = 5 * 60; /* Default is 5 minutes */
  47. int auto_reconnect = 1; /* Default is enabled */
  48. unsigned int my_connect_to = 2; /* 2 s by default */
  49. unsigned int my_send_to = 0; /* enabled only for mysql >= 5.25 */
  50. unsigned int my_recv_to = 0; /* enabled only for mysql >= 5.25 */
  51. unsigned long my_client_ver = 0;
  52. #define DEFAULT_MY_SEND_TO 2 /* in seconds */
  53. #define DEFAULT_MY_RECV_TO 4 /* in seconds */
  54. static int mysql_mod_init(void);
  55. MODULE_VERSION
  56. /*
  57. * MySQL database module interface
  58. */
  59. static cmd_export_t cmds[] = {
  60. {"db_ctx", (cmd_function)NULL, 0, 0, 0},
  61. {"db_con", (cmd_function)my_con, 0, 0, 0},
  62. {"db_uri", (cmd_function)my_uri, 0, 0, 0},
  63. {"db_cmd", (cmd_function)my_cmd, 0, 0, 0},
  64. {"db_put", (cmd_function)my_cmd_write, 0, 0, 0},
  65. {"db_del", (cmd_function)my_cmd_write, 0, 0, 0},
  66. {"db_get", (cmd_function)my_cmd_read, 0, 0, 0},
  67. {"db_upd", (cmd_function)my_cmd_update, 0, 0, 0},
  68. {"db_sql", (cmd_function)my_cmd_sql, 0, 0, 0},
  69. {"db_res", (cmd_function)my_res, 0, 0, 0},
  70. {"db_fld", (cmd_function)my_fld, 0, 0, 0},
  71. {"db_first", (cmd_function)my_cmd_next, 0, 0, 0},
  72. {"db_next", (cmd_function)my_cmd_next, 0, 0, 0},
  73. {0, 0, 0, 0, 0}
  74. };
  75. /*
  76. * Exported parameters
  77. */
  78. static param_export_t params[] = {
  79. {"ping_interval", PARAM_INT, &ping_interval},
  80. {"auto_reconnect", PARAM_INT, &auto_reconnect},
  81. {"connect_timeout", PARAM_INT, &my_connect_to},
  82. {"send_timeout", PARAM_INT, &my_send_to},
  83. {"receive_timeout", PARAM_INT, &my_recv_to},
  84. {0, 0, 0}
  85. };
  86. struct module_exports exports = {
  87. "mysql",
  88. cmds,
  89. 0, /* RPC method */
  90. params, /* module parameters */
  91. mysql_mod_init, /* module initialization function */
  92. 0, /* response function*/
  93. 0, /* destroy function */
  94. 0, /* oncancel function */
  95. 0 /* per-child init function */
  96. };
  97. static int mysql_mod_init(void)
  98. {
  99. #if MYSQL_VERSION_ID >= 40101
  100. my_client_ver = mysql_get_client_version();
  101. if ((my_client_ver >= 50025) ||
  102. ((my_client_ver >= 40122) &&
  103. (my_client_ver < 50000))) {
  104. if (my_send_to == 0) {
  105. my_send_to= DEFAULT_MY_SEND_TO;
  106. }
  107. if (my_recv_to == 0) {
  108. my_recv_to= DEFAULT_MY_RECV_TO;
  109. }
  110. } else if (my_recv_to || my_send_to) {
  111. LOG(L_WARN, "WARNING: mysql send or received timeout set, but "
  112. " not supported by the installed mysql client library"
  113. " (needed at least 4.1.22 or 5.0.25, but installed %ld)\n",
  114. my_client_ver);
  115. }
  116. #else
  117. if (my_recv_to || my_send_to) {
  118. LOG(L_WARN, "WARNING: mysql send or received timeout set, but "
  119. " not supported by the mysql client library used to compile"
  120. " the mysql module (needed at least 4.1.1 but "
  121. " compiled against %ld)\n", MYSQL_VERSION_ID);
  122. }
  123. #endif
  124. return 0;
  125. }
  126. /** @} */