parse_rr.h 3.9 KB

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