dset.h 6.8 KB

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