parse_rr.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * $Id$
  3. *
  4. * Route & Record-Route Parser
  5. *
  6. * Copyright (C) 2001-2003 FhG Fokus
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser 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. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. */
  29. /*! \file
  30. * \brief Parser :: Route & Record-Route header field parser
  31. *
  32. * \ingroup parser
  33. */
  34. #ifndef PARSE_RR_H
  35. #define PARSE_RR_H
  36. #include <stdio.h>
  37. #include "msg_parser.h"
  38. #include "parse_nameaddr.h"
  39. #include "parse_param.h"
  40. #include "hf.h"
  41. /*! \brief
  42. * Structure representing a Route & Record-Route HF body
  43. */
  44. typedef struct rr {
  45. name_addr_t nameaddr; /*!< Name-addr part */
  46. param_t* r2; /*!< Hook to r2 parameter */
  47. param_t* params; /*!< Linked list of other parameters */
  48. int len; /*!< Length of the whole route field */
  49. struct rr* next; /*!< Next RR in the list */
  50. } rr_t;
  51. /*
  52. * Parse Route & Record-Route header fields
  53. */
  54. int parse_rr(struct hdr_field* _r);
  55. /*
  56. * Parse the body of Route & Record-Route headers
  57. */
  58. int parse_rr_body(char *buf, int len, rr_t **head);
  59. /*
  60. * Free list of rr
  61. * _c is head of the list
  62. */
  63. void free_rr(rr_t** _r);
  64. /*
  65. * Free list of rr
  66. * _c is head of the list
  67. */
  68. void shm_free_rr(rr_t** _r);
  69. /*
  70. * Print list of rrs, just for debugging
  71. */
  72. void print_rr(FILE* _o, rr_t* _r);
  73. /*
  74. * Duplicate a single rr_t structure using pkg_malloc
  75. */
  76. int duplicate_rr(rr_t** _new, rr_t* _r);
  77. /*
  78. * Duplicate a single rr_t structure using pkg_malloc
  79. */
  80. int shm_duplicate_rr(rr_t** _new, rr_t* _r);
  81. /*
  82. * Find out if a URI contains r2 parameter which indicates
  83. * that we put 2 record routes
  84. */
  85. static inline int is_2rr(str* _params)
  86. {
  87. str s;
  88. int i, state = 0;
  89. if (_params->len == 0) return 0;
  90. s = *_params;
  91. for(i = 0; i < s.len; i++) {
  92. switch(state) {
  93. case 0:
  94. switch(s.s[i]) {
  95. case ' ':
  96. case '\r':
  97. case '\n':
  98. case '\t': break;
  99. case 'r':
  100. case 'R': state = 1; break;
  101. default: state = 4; break;
  102. }
  103. break;
  104. case 1:
  105. switch(s.s[i]) {
  106. case '2': state = 2; break;
  107. default: state = 4; break;
  108. }
  109. break;
  110. case 2:
  111. switch(s.s[i]) {
  112. case ';': return 1;
  113. case '=': return 1;
  114. case ' ':
  115. case '\r':
  116. case '\n':
  117. case '\t': state = 3; break;
  118. default: state = 4; break;
  119. }
  120. break;
  121. case 3:
  122. switch(s.s[i]) {
  123. case ';': return 1;
  124. case '=': return 1;
  125. case ' ':
  126. case '\r':
  127. case '\n':
  128. case '\t': break;
  129. default: state = 4; break;
  130. }
  131. break;
  132. case 4:
  133. switch(s.s[i]) {
  134. case '\"': state = 5; break;
  135. case ';': state = 0; break;
  136. default: break;
  137. }
  138. break;
  139. case 5:
  140. switch(s.s[i]) {
  141. case '\\': state = 6; break;
  142. case '\"': state = 4; break;
  143. default: break;
  144. }
  145. break;
  146. case 6: state = 5; break;
  147. }
  148. }
  149. if ((state == 2) || (state == 3)) return 1;
  150. else return 0;
  151. }
  152. /*!
  153. * get first RR header and print comma separated bodies in oroute
  154. * - order = 0 normal; order = 1 reverse
  155. * - nb_recs - input=skip number of rr; output=number of printed rrs
  156. */
  157. int print_rr_body(struct hdr_field *iroute, str *oroute, int order,
  158. unsigned int * nb_recs);
  159. int get_path_dst_uri(str *_p, str *_dst);
  160. #endif /* PARSE_RR_H */