path_mod.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * $Id$
  3. *
  4. * Path handling for intermediate proxies
  5. *
  6. * Copyright (C) 2006 Inode GmbH (Andreas Granig <[email protected]>)
  7. *
  8. * This file is part of Kamailio, a free SIP server.
  9. *
  10. * Kamailio 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. * Kamailio is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. */
  25. /*! \file
  26. * \brief Path :: Core
  27. *
  28. * \ingroup path
  29. * - Module: path
  30. */
  31. /*! \defgroup path Path:: Handling of "path" header for intermediate proxies
  32. * This module is designed to be used at intermediate sip proxies
  33. * like loadbalancers in front of registrars and proxies. It
  34. * provides functions for inserting a Path header including a
  35. * parameter for passing forward the received-URI of a
  36. * registration to the next hop. It also provides a mechanism for
  37. * evaluating this parameter in subsequent requests and to set the
  38. * destination URI according to it.
  39. *
  40. * - No developer API
  41. * - No MI functions
  42. */
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include "../../sr_module.h"
  47. #include "../../mem/mem.h"
  48. #include "../../mod_fix.h"
  49. #include "../outbound/api.h"
  50. #include "../rr/api.h"
  51. #include "path.h"
  52. #include "path_mod.h"
  53. MODULE_VERSION
  54. /*! \brief If received-param of current Route uri should be used
  55. * as dst-uri. */
  56. int use_received = 0;
  57. /*! \brief
  58. * Module initialization function prototype
  59. */
  60. static int mod_init(void);
  61. /*! \brief
  62. * rr callback API
  63. */
  64. struct rr_binds path_rrb;
  65. /*! \brief
  66. * outbound API
  67. */
  68. ob_api_t path_obb;
  69. /*! \brief
  70. * Exported functions
  71. */
  72. static cmd_export_t cmds[] = {
  73. { "add_path", (cmd_function)add_path, 0,
  74. 0, 0, REQUEST_ROUTE },
  75. { "add_path", (cmd_function)add_path_usr, 1,
  76. fixup_spve_null, 0, REQUEST_ROUTE },
  77. { "add_path", (cmd_function)add_path_usr, 2,
  78. fixup_spve_spve, 0, REQUEST_ROUTE },
  79. { "add_path_received", (cmd_function)add_path_received, 0,
  80. 0, 0, REQUEST_ROUTE },
  81. { "add_path_received", (cmd_function)add_path_received_usr, 1,
  82. fixup_spve_null, 0, REQUEST_ROUTE },
  83. { "add_path_received", (cmd_function)add_path_received_usr, 2,
  84. fixup_spve_spve, 0, REQUEST_ROUTE },
  85. { 0, 0, 0, 0, 0, 0 }
  86. };
  87. /*! \brief
  88. * Exported parameters
  89. */
  90. static param_export_t params[] = {
  91. {"use_received", INT_PARAM, &use_received },
  92. { 0, 0, 0 }
  93. };
  94. /*! \brief
  95. * Module interface
  96. */
  97. struct module_exports exports = {
  98. "path",
  99. DEFAULT_DLFLAGS, /* dlopen flags */
  100. cmds, /* Exported functions */
  101. params, /* Exported parameters */
  102. 0, /* exported statistics */
  103. 0, /* exported MI functions */
  104. 0, /* exported pseudo-variables */
  105. 0, /* extra processes */
  106. mod_init, /* module initialization function */
  107. 0, /* response function */
  108. 0, /* destroy function */
  109. 0 /* child initialization function */
  110. };
  111. static int mod_init(void)
  112. {
  113. if (use_received) {
  114. if (load_rr_api(&path_rrb) != 0) {
  115. LM_ERR("failed to load rr-API\n");
  116. return -1;
  117. }
  118. if (path_rrb.register_rrcb(path_rr_callback, 0) != 0) {
  119. LM_ERR("failed to register rr callback\n");
  120. return -1;
  121. }
  122. }
  123. if (ob_load_api(&path_obb) == 0)
  124. LM_DBG("Bound path module to outbound module\n");
  125. else {
  126. LM_INFO("outbound module not available\n");
  127. memset(&path_obb, 0, sizeof(ob_api_t));
  128. }
  129. return 0;
  130. }