dlg_mod.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2005 iptelorg GmbH
  3. *
  4. * This file is part of ser, a free SIP server.
  5. *
  6. * ser is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * For a license to use the ser software under conditions
  12. * other than those described here, or to purchase support for this
  13. * software, please contact iptel.org by e-mail at the following addresses:
  14. * [email protected]
  15. *
  16. * ser 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. #include "dlg_mod.h"
  26. #include "db_dlg.h"
  27. #include "serialize_dlg.h"
  28. #include "../../sr_module.h"
  29. #include "../../modules/tm/tm_load.h"
  30. #include <cds/sstr.h>
  31. #include "dlg_utils.h"
  32. #include "dlg_request.h"
  33. #include "../../locking.h"
  34. MODULE_VERSION
  35. /* "public" data members */
  36. static int db_mode = 0;
  37. static str db_url = STR_NULL;
  38. /* internal data members */
  39. /* data members for pregenerated tags - taken from TM */
  40. char dialog_tags[TOTAG_VALUE_LEN];
  41. char *dialog_tag_suffix = NULL;
  42. struct tm_binds tmb;
  43. static int dlg_mod_init(void);
  44. static void dlg_mod_destroy(void);
  45. static int dlg_mod_child_init(int _rank);
  46. /*
  47. * Exported functions
  48. */
  49. static cmd_export_t cmds[]={
  50. {"bind_dlg_mod", (cmd_function)bind_dlg_mod, -1, 0, 0},
  51. {0, 0, 0, 0, 0}
  52. };
  53. /*
  54. * Exported parameters
  55. */
  56. static param_export_t params[]={
  57. {"db_mode", PARAM_INT, &db_mode },
  58. {"db_url", PARAM_STR, &db_url },
  59. {0, 0, 0}
  60. };
  61. struct module_exports exports = {
  62. "dialog",
  63. cmds, /* Exported functions */
  64. 0, /* RPC methods */
  65. params, /* Exported parameters */
  66. dlg_mod_init, /* module initialization function */
  67. 0, /* response function*/
  68. dlg_mod_destroy, /* destroy function */
  69. 0, /* oncancel function */
  70. dlg_mod_child_init/* per-child init function */
  71. };
  72. static void init_dialog_tags()
  73. {
  74. /* taken from tm, might be useful */
  75. init_tags(dialog_tags, &dialog_tag_suffix, "SER-DIALOG/tags", '-');
  76. }
  77. #include <cds/dstring.h>
  78. gen_lock_t *dlg_mutex = NULL;
  79. static int init_dialog_mutex()
  80. {
  81. dlg_mutex = (gen_lock_t*)shm_malloc(sizeof(*dlg_mutex));
  82. if (!dlg_mutex) return -1;
  83. lock_init(dlg_mutex);
  84. return 0;
  85. }
  86. static void destroy_dialog_mutex()
  87. {
  88. if (dlg_mutex) {
  89. lock_destroy(dlg_mutex);
  90. shm_free((void*)dlg_mutex);
  91. }
  92. }
  93. static int dlg_mod_init(void)
  94. {
  95. load_tm_f load_tm;
  96. if (init_dialog_mutex() < 0) {
  97. ERR("can't initialize mutex\n");
  98. return -1;
  99. }
  100. init_dialog_tags();
  101. load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0);
  102. if (!load_tm) {
  103. LOG(L_ERR, "dlg_mod_init(): Can't import tm\n");
  104. return -1;
  105. }
  106. if (load_tm(&tmb) < 0) {
  107. LOG(L_ERR, "dlg_mod_init(): Can't import tm functions\n");
  108. return -1;
  109. }
  110. return 0;
  111. }
  112. static int dlg_mod_child_init(int _rank)
  113. {
  114. return 0;
  115. }
  116. static void dlg_mod_destroy(void)
  117. {
  118. destroy_dialog_mutex();
  119. }