dset.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. /* +sip.instance contact header param value */
  53. char instance[MAX_INSTANCE_SIZE];
  54. unsigned int instance_len;
  55. /* reg-id contact header param value */
  56. unsigned int reg_id;
  57. /* Branch flags */
  58. flag_t flags;
  59. };
  60. typedef struct branch branch_t;
  61. /*! \brief
  62. * Return pointer to branch[idx] structure
  63. */
  64. branch_t *get_sip_branch(int idx);
  65. /*! \brief
  66. * Drop branch[idx]
  67. */
  68. int drop_sip_branch(int idx);
  69. /*! \brief
  70. * Add a new branch to current transaction
  71. */
  72. int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
  73. qvalue_t q, unsigned int flags,
  74. struct socket_info* force_socket,
  75. str* instance, unsigned int reg_id);
  76. /*! \brief kamailio compatible version */
  77. #define km_append_branch(msg, uri, dst_uri, path, q, flags, force_socket) \
  78. append_branch(msg, uri, dst_uri, path, q, flags, force_socket, 0, 0)
  79. /*! \brief ser compatible append_branch version.
  80. * append_branch version compatible with ser: no path or branch flags support
  81. * and no str parameters.
  82. */
  83. static inline int ser_append_branch(struct sip_msg* msg,
  84. char* uri, int uri_len,
  85. char* dst_uri, int dst_uri_len,
  86. qvalue_t q,
  87. struct socket_info* force_socket)
  88. {
  89. str s_uri, s_dst_uri;
  90. s_uri.s=uri;
  91. s_uri.len=uri_len;
  92. s_dst_uri.s=dst_uri;
  93. s_dst_uri.len=dst_uri_len;
  94. return append_branch(msg, &s_uri, &s_dst_uri, 0, q, 0, force_socket, 0, 0);
  95. }
  96. /*! \brief
  97. * Init the index to iterate through the list of transaction branches
  98. */
  99. void init_branch_iterator(void);
  100. /*! \brief
  101. * Return branch iterator position
  102. */
  103. int get_branch_iterator(void);
  104. /*! \brief
  105. * Set branch iterator position
  106. */
  107. void set_branch_iterator(int n);
  108. /*! \brief Get the next branch in the current transaction.
  109. * @return pointer to the uri of the next branch (which the length written in
  110. * *len) or 0 if there are no more branches.
  111. */
  112. char* next_branch(int* len, qvalue_t* q, str* dst_uri, str* path,
  113. unsigned int* flags, struct socket_info** force_socket);
  114. char* get_branch( unsigned int i, int* len, qvalue_t* q, str* dst_uri,
  115. str* path, unsigned int *flags,
  116. struct socket_info** force_socket);
  117. /*! \brief
  118. * Empty the array of branches
  119. */
  120. void clear_branches(void);
  121. /*! \brief
  122. * Create a Contact header field from the
  123. * list of current branches
  124. */
  125. char* print_dset(struct sip_msg* msg, int* len);
  126. /*! \brief
  127. * Set the q value of the Request-URI
  128. */
  129. void set_ruri_q(qvalue_t q);
  130. /*! \brief
  131. * Get the q value of the Request-URI
  132. */
  133. qvalue_t get_ruri_q(void);
  134. /*
  135. * Get actual Request-URI
  136. */
  137. inline static int get_request_uri(struct sip_msg* _m, str* _u)
  138. {
  139. *_u=*GET_RURI(_m);
  140. return 0;
  141. }
  142. #define ruri_mark_new() (ruri_is_new = 1)
  143. #define ruri_mark_consumed() (ruri_is_new = 0)
  144. /** returns whether or not ruri should be used when forking.
  145. * (usefull for serial forking)
  146. * @return 0 if already marked as consumed, 1 if not.
  147. */
  148. #define ruri_get_forking_state() (ruri_is_new)
  149. int rewrite_uri(struct sip_msg* _m, str* _s);
  150. /*! \brief
  151. * Set a per-branch flag to 1.
  152. *
  153. * This function sets the value of one particular branch flag to 1.
  154. * @param branch Number of the branch (0 for the main Request-URI branch)
  155. * @param flag Number of the flag to be set (starting with 0)
  156. * @return 1 on success, -1 on failure.
  157. */
  158. int setbflag(unsigned int branch, flag_t flag);
  159. /*! \brief
  160. * Reset a per-branch flag value to 0.
  161. *
  162. * This function resets the value of one particular branch flag to 0.
  163. * @param branch Number of the branch (0 for the main Request-URI branch)
  164. * @param flag Number of the flag to be reset (starting with 0)
  165. * @return 1 on success, -1 on failure.
  166. */
  167. int resetbflag(unsigned int branch, flag_t flag);
  168. /*! \brief
  169. * Determine if a branch flag is set.
  170. *
  171. * This function tests the value of one particular per-branch flag.
  172. * @param branch Number of the branch (0 for the main Request-URI branch)
  173. * @param flag Number of the flag to be tested (starting with 0)
  174. * @return 1 if the branch flag is set, -1 if not or on failure.
  175. */
  176. int isbflagset(unsigned int branch, flag_t flag);
  177. /*! \brief
  178. * Get the value of all branch flags for a branch
  179. *
  180. * This function returns the value of all branch flags
  181. * combined in a single variable.
  182. * @param branch Number of the branch (0 for the main Request-URI branch)
  183. * @param res A pointer to a variable to store the result
  184. * @return 1 on success, -1 on failure
  185. */
  186. int getbflagsval(unsigned int branch, flag_t* res);
  187. /*! \brief
  188. * Set the value of all branch flags at once for a given branch.
  189. *
  190. * This function sets the value of all branch flags for a given
  191. * branch at once.
  192. * @param branch Number of the branch (0 for the main Request-URI branch)
  193. * @param val All branch flags combined into a single variable
  194. * @return 1 on success, -1 on failure
  195. */
  196. int setbflagsval(unsigned int branch, flag_t val);
  197. #endif /* _DSET_H */