dset.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2004 FhG FOKUS
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * ser is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. /*!
  23. * \file
  24. * \brief SIP-router core :: Destination set handling
  25. * \ingroup core
  26. * Module: \ref core
  27. */
  28. #ifndef _DSET_H
  29. #define _DSET_H
  30. #include "ip_addr.h"
  31. #include "qvalue.h"
  32. #include "flags.h"
  33. #include "parser/msg_parser.h"
  34. extern unsigned int nr_branches;
  35. extern int ruri_is_new;
  36. /*! \brief
  37. * Structure for storing branch attributes
  38. */
  39. struct branch
  40. {
  41. char uri[MAX_URI_SIZE];
  42. unsigned int len;
  43. /* Real destination of the request */
  44. char dst_uri[MAX_URI_SIZE];
  45. unsigned int dst_uri_len;
  46. /* Path set */
  47. char path[MAX_PATH_SIZE];
  48. unsigned int path_len;
  49. int q; /* Preference of the contact among
  50. * contact within the array */
  51. struct socket_info* force_send_socket;
  52. /* Branch flags */
  53. flag_t flags;
  54. };
  55. typedef struct branch branch_t;
  56. /*! \brief
  57. * Return pointer to branch[idx] structure
  58. */
  59. branch_t *get_sip_branch(int idx);
  60. /*! \brief
  61. * Drop branch[idx]
  62. */
  63. int drop_sip_branch(int idx);
  64. /*! \brief
  65. * Add a new branch to current transaction
  66. */
  67. int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
  68. qvalue_t q, unsigned int flags,
  69. struct socket_info* force_socket);
  70. /*! \brief kamailio compatible version */
  71. #define km_append_branch(msg, uri, dst_uri, path, q, flags, force_socket) \
  72. append_branch(msg, uri, dst_uri, path, q, flags, force_socket)
  73. /*! \brief ser compatible append_branch version.
  74. * append_branch version compatible with ser: no path or branch flags support
  75. * and no str parameters.
  76. */
  77. static inline int ser_append_branch(struct sip_msg* msg,
  78. char* uri, int uri_len,
  79. char* dst_uri, int dst_uri_len,
  80. qvalue_t q,
  81. struct socket_info* force_socket)
  82. {
  83. str s_uri, s_dst_uri;
  84. s_uri.s=uri;
  85. s_uri.len=uri_len;
  86. s_dst_uri.s=dst_uri;
  87. s_dst_uri.len=dst_uri_len;
  88. return append_branch(msg, &s_uri, &s_dst_uri, 0, q, 0, force_socket);
  89. }
  90. /*! \brief
  91. * Init the index to iterate through the list of transaction branches
  92. */
  93. void init_branch_iterator(void);
  94. /*! \brief
  95. * Return branch iterator position
  96. */
  97. int get_branch_iterator(void);
  98. /*! \brief
  99. * Set branch iterator position
  100. */
  101. void set_branch_iterator(int n);
  102. /*! \brief Get the next branch in the current transaction.
  103. * @return pointer to the uri of the next branch (which the length written in
  104. * *len) or 0 if there are no more branches.
  105. */
  106. char* next_branch(int* len, qvalue_t* q, str* dst_uri, str* path,
  107. unsigned int* flags, struct socket_info** force_socket);
  108. char* get_branch( unsigned int i, int* len, qvalue_t* q, str* dst_uri,
  109. str* path, unsigned int *flags,
  110. struct socket_info** force_socket);
  111. /*! \brief
  112. * Empty the array of branches
  113. */
  114. void clear_branches(void);
  115. /*! \brief
  116. * Create a Contact header field from the
  117. * list of current branches
  118. */
  119. char* print_dset(struct sip_msg* msg, int* len);
  120. /*! \brief
  121. * Set the q value of the Request-URI
  122. */
  123. void set_ruri_q(qvalue_t q);
  124. /*! \brief
  125. * Get the q value of the Request-URI
  126. */
  127. qvalue_t get_ruri_q(void);
  128. /*
  129. * Get actual Request-URI
  130. */
  131. inline static int get_request_uri(struct sip_msg* _m, str* _u)
  132. {
  133. *_u=*GET_RURI(_m);
  134. return 0;
  135. }
  136. #define ruri_mark_new() (ruri_is_new = 1)
  137. #define ruri_mark_consumed() (ruri_is_new = 0)
  138. /** returns whether or not ruri should be used when forking.
  139. * (usefull for serial forking)
  140. * @return 0 if already marked as consumed, 1 if not.
  141. */
  142. #define ruri_get_forking_state() (ruri_is_new)
  143. int rewrite_uri(struct sip_msg* _m, str* _s);
  144. /*! \brief
  145. * Set a per-branch flag to 1.
  146. *
  147. * This function sets the value of one particular branch flag to 1.
  148. * @param branch Number of the branch (0 for the main Request-URI branch)
  149. * @param flag Number of the flag to be set (starting with 0)
  150. * @return 1 on success, -1 on failure.
  151. */
  152. int setbflag(unsigned int branch, flag_t flag);
  153. /*! \brief
  154. * Reset a per-branch flag value to 0.
  155. *
  156. * This function resets the value of one particular branch flag to 0.
  157. * @param branch Number of the branch (0 for the main Request-URI branch)
  158. * @param flag Number of the flag to be reset (starting with 0)
  159. * @return 1 on success, -1 on failure.
  160. */
  161. int resetbflag(unsigned int branch, flag_t flag);
  162. /*! \brief
  163. * Determine if a branch flag is set.
  164. *
  165. * This function tests the value of one particular per-branch flag.
  166. * @param branch Number of the branch (0 for the main Request-URI branch)
  167. * @param flag Number of the flag to be tested (starting with 0)
  168. * @return 1 if the branch flag is set, -1 if not or on failure.
  169. */
  170. int isbflagset(unsigned int branch, flag_t flag);
  171. /*! \brief
  172. * Get the value of all branch flags for a branch
  173. *
  174. * This function returns the value of all branch flags
  175. * combined in a single variable.
  176. * @param branch Number of the branch (0 for the main Request-URI branch)
  177. * @param res A pointer to a variable to store the result
  178. * @return 1 on success, -1 on failure
  179. */
  180. int getbflagsval(unsigned int branch, flag_t* res);
  181. /*! \brief
  182. * Set the value of all branch flags at once for a given branch.
  183. *
  184. * This function sets the value of all branch flags for a given
  185. * branch at once.
  186. * @param branch Number of the branch (0 for the main Request-URI branch)
  187. * @param val All branch flags combined into a single variable
  188. * @return 1 on success, -1 on failure
  189. */
  190. int setbflagsval(unsigned int branch, flag_t val);
  191. #endif /* _DSET_H */