1 /*
2 * Route & Record-Route Parser
3 *
4 * Copyright (C) 2001-2003 FhG Fokus
5 *
6 * This file is part of Kamailio, a free SIP server.
7 *
8 * Kamailio 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 * Kamailio 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /*! \file
24 * \brief Parser :: Route & Record-Route header field parser
25 *
26 * \ingroup parser
27 */
28
29 #ifndef PARSE_RR_H
30 #define PARSE_RR_H
31
32 #include <stdio.h>
33 #include "msg_parser.h"
34 #include "parse_nameaddr.h"
35 #include "parse_param.h"
36 #include "hf.h"
37
38
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
51 /*
52 * Parse Route & Record-Route header fields
53 */
54 int parse_rr(struct hdr_field* _r);
55
56 /*
57 * Parse the body of Route & Record-Route headers
58 */
59 int parse_rr_body(char *buf, int len, rr_t **head);
60
61 /*
62 * Free list of rr
63 * _c is head of the list
64 */
65 void free_rr(rr_t** _r);
66
67
68 /*
69 * Free list of rr
70 * _c is head of the list
71 */
72 void shm_free_rr(rr_t** _r);
73
74
75 /*
76 * Print list of rrs, just for debugging
77 */
78 void print_rr(FILE* _o, rr_t* _r);
79
80
81 /*
82 * Duplicate a single rr_t structure using pkg_malloc
83 */
84 int duplicate_rr(rr_t** _new, rr_t* _r);
85
86
87 /*
88 * Duplicate a single rr_t structure using pkg_malloc
89 */
90 int shm_duplicate_rr(rr_t** _new, rr_t* _r);
91
92 /*
93 * Find out if a URI contains r2 parameter which indicates
94 * that we put 2 record routes
95 */
is_2rr(str * _params)96 static inline int is_2rr(str* _params)
97 {
98 str s;
99 int i, state = 0;
100
101 if (_params->len == 0) return 0;
102 s = *_params;
103
104 for(i = 0; i < s.len; i++) {
105 switch(state) {
106 case 0:
107 switch(s.s[i]) {
108 case ' ':
109 case '\r':
110 case '\n':
111 case '\t': break;
112 case 'r':
113 case 'R': state = 1; break;
114 default: state = 4; break;
115 }
116 break;
117
118 case 1:
119 switch(s.s[i]) {
120 case '2': state = 2; break;
121 default: state = 4; break;
122 }
123 break;
124
125 case 2:
126 switch(s.s[i]) {
127 case ';': return 1;
128 case '=': return 1;
129 case ' ':
130 case '\r':
131 case '\n':
132 case '\t': state = 3; break;
133 default: state = 4; break;
134 }
135 break;
136
137 case 3:
138 switch(s.s[i]) {
139 case ';': return 1;
140 case '=': return 1;
141 case ' ':
142 case '\r':
143 case '\n':
144 case '\t': break;
145 default: state = 4; break;
146 }
147 break;
148
149 case 4:
150 switch(s.s[i]) {
151 case '\"': state = 5; break;
152 case ';': state = 0; break;
153 default: break;
154 }
155 break;
156
157 case 5:
158 switch(s.s[i]) {
159 case '\\': state = 6; break;
160 case '\"': state = 4; break;
161 default: break;
162 }
163 break;
164
165 case 6: state = 5; break;
166 }
167 }
168
169 if ((state == 2) || (state == 3)) return 1;
170 else return 0;
171 }
172
173 /*!
174 * get first RR header and print comma separated bodies in oroute
175 * - order = 0 normal; order = 1 reverse
176 * - nb_recs - input=skip number of rr; output=number of printed rrs
177 */
178 int print_rr_body(struct hdr_field *iroute, str *oroute, int order,
179 unsigned int * nb_recs);
180
181 int get_path_dst_uri(str *_p, str *_dst);
182
183 #endif /* PARSE_RR_H */
184