/src/kamailio/src/core/parser/hf.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2001-2003 FhG Fokus |
3 | | * |
4 | | * This file is part of Kamailio, a free SIP server. |
5 | | * |
6 | | * Kamailio is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 2 of the License, or |
9 | | * (at your option) any later version |
10 | | * |
11 | | * Kamailio is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | | * |
20 | | */ |
21 | | |
22 | | /** Parser :: parse headers. |
23 | | * @file |
24 | | * |
25 | | * @ingroup parser |
26 | | */ |
27 | | |
28 | | |
29 | | #ifndef HF_H |
30 | | #define HF_H |
31 | | |
32 | | #include "../str.h" |
33 | | #include "../comp_defs.h" |
34 | | |
35 | | |
36 | | /** header types enum. |
37 | | * |
38 | | * @note |
39 | | * if you add a new type: |
40 | | * - make sure it's not greater than 63 |
41 | | * - make sure you add the corresponding flag to the hdr_flags_t defs below |
42 | | * - update clean_hdr_field (in hf.c) |
43 | | * - update sip_msg_cloner (modules/tm/sip_msg.c) |
44 | | * - update parse_headers (msg_parser.c) |
45 | | * - update get_hdr_field (msg_parser.c) |
46 | | */ |
47 | | |
48 | | enum _hdr_types_t |
49 | | { |
50 | | HDR_ERROR_T = -1 /*!< Error while parsing */, |
51 | | HDR_OTHER_T = 0 /*!< Some other header field */, |
52 | | HDR_VIA_T = 1 /*!< Via header field */, |
53 | | HDR_VIA1_T = 1 /*!< First Via header field */, |
54 | | HDR_VIA2_T = 2 /*!< only used as flag */, |
55 | | HDR_TO_T = 3 /*!< To header field */, |
56 | | HDR_FROM_T = 4 /*!< From header field */, |
57 | | HDR_CSEQ_T = 5 /*!< CSeq header field */, |
58 | | HDR_CALLID_T = 6 /*!< Call-Id header field */, |
59 | | HDR_CONTACT_T = 7 /*!< Contact header field */, |
60 | | HDR_MAXFORWARDS_T = 8 /*!< MaxForwards header field */, |
61 | | HDR_ROUTE_T = 9 /*!< Route header field */, |
62 | | HDR_RECORDROUTE_T = 10 /*!< Record-Route header field */, |
63 | | HDR_CONTENTTYPE_T = 11 /*!< Content-Type header field */, |
64 | | HDR_CONTENTLENGTH_T = 12 /*!< Content-Length header field */, |
65 | | HDR_AUTHORIZATION_T = 13 /*!< Authorization header field */, |
66 | | HDR_EXPIRES_T = 14 /*!< Expires header field */, |
67 | | HDR_MIN_EXPIRES_T = 15 /*!< Min-Expires header */, |
68 | | HDR_PROXYAUTH_T = 16 /*!< Proxy-Authorization hdr field */, |
69 | | HDR_SUPPORTED_T = 17 /*!< Supported header field */, |
70 | | HDR_REQUIRE_T = 18 /*!< Require header */, |
71 | | HDR_PROXYREQUIRE_T = 19 /*!< Proxy-Require header field */, |
72 | | HDR_UNSUPPORTED_T = 20 /*!< Unsupported header field */, |
73 | | HDR_ALLOW_T = 21 /*!< Allow header field */, |
74 | | HDR_EVENT_T = 22 /*!< Event header field */, |
75 | | HDR_ACCEPT_T = 23 /*!< Accept header field */, |
76 | | HDR_ACCEPTLANGUAGE_T = 24 /*!< Accept-Language header field */, |
77 | | HDR_ORGANIZATION_T = 25 /*!< Organization header field */, |
78 | | HDR_PRIORITY_T = 26 /*!< Priority header field */, |
79 | | HDR_SUBJECT_T = 27 /*!< Subject header field */, |
80 | | HDR_USERAGENT_T = 28 /*!< User-Agent header field */, |
81 | | HDR_SERVER_T = 29 /*!< Server header field */, |
82 | | HDR_CONTENTDISPOSITION_T = 30 /*!< Content-Disposition hdr field */, |
83 | | HDR_DIVERSION_T = 31 /*!< Diversion header field */, |
84 | | HDR_RPID_T = 32 /*!< Remote-Party-ID header field */, |
85 | | HDR_REFER_TO_T = 33 /*!< Refer-To header fields */, |
86 | | HDR_SIPIFMATCH_T = 34 /*!< SIP-If-Match header field */, |
87 | | HDR_SESSIONEXPIRES_T = 35 /*!< Session-Expires header */, |
88 | | HDR_MIN_SE_T = 36 /*!< Min-SE */, |
89 | | HDR_SUBSCRIPTION_STATE_T = 37 /*!< Subscription-State */, |
90 | | HDR_ACCEPTCONTACT_T = 38 /*!< Accept-Contact header */, |
91 | | HDR_ALLOWEVENTS_T = 39 /*!< Allow-Events header */, |
92 | | HDR_CONTENTENCODING_T = 40 /*!< Content-Encoding header */, |
93 | | HDR_REFERREDBY_T = 41 /*!< Referred-By header */, |
94 | | HDR_REJECTCONTACT_T = 42 /*!< Reject-Contact header */, |
95 | | HDR_REQUESTDISPOSITION_T = 43 /*!< Request-Disposition header */, |
96 | | HDR_WWW_AUTHENTICATE_T = 44 /*!< WWW-Authenticate header field */, |
97 | | HDR_PROXY_AUTHENTICATE_T = 45 /*!< Proxy-Authenticate header field */, |
98 | | HDR_DATE_T = 46 /*!< Date header field */, |
99 | | HDR_IDENTITY_T = 47 /*!< Identity header field */, |
100 | | HDR_IDENTITY_INFO_T = 48 /*!< Identity-info header field */, |
101 | | HDR_RETRY_AFTER_T = 49 /*!< Retry-After header field */, |
102 | | HDR_PPI_T = 50 /*!< P-Preferred-Identity header field*/, |
103 | | HDR_PAI_T = 51 /*!< P-Asserted-Identity header field*/, |
104 | | HDR_PATH_T = 52 /*!< Path header field */, |
105 | | HDR_PRIVACY_T = 53 /*!< Privacy header field */, |
106 | | HDR_REASON_T = 54 /**< Reason header field */, |
107 | | HDR_CALLINFO_T = 55 /*!< Call-Info header field*/, |
108 | | |
109 | | HDR_EOH_T = 56 /*!< End of message header (lastid + 1) */ |
110 | | }; |
111 | | |
112 | | |
113 | | typedef unsigned long long hdr_flags_t; |
114 | | |
115 | | /** type to flag conversion. |
116 | | * WARNING: HDR_ERROR_T has no corresponding FLAG ! */ |
117 | | #define HDR_T2F(type) \ |
118 | 402k | (((type) != HDR_EOH_T) ? ((hdr_flags_t)1 << (type)) : (~(hdr_flags_t)0)) |
119 | | |
120 | | /** helper macro for easy defining and keeping in sync the flags enum. */ |
121 | 387k | #define HDR_F_DEF(name) HDR_T2F(HDR_##name##_T) |
122 | | |
123 | | /** @name flags definitions. |
124 | | * (enum won't work with all the compiler (e.g. icc) due to the 64bit size) */ |
125 | | /*!{ */ |
126 | 74.1k | #define HDR_EOH_F HDR_F_DEF(EOH) |
127 | 60.5k | #define HDR_VIA_F HDR_F_DEF(VIA) |
128 | | #define HDR_VIA1_F HDR_F_DEF(VIA1) |
129 | 834 | #define HDR_VIA2_F HDR_F_DEF(VIA2) |
130 | 36.0k | #define HDR_TO_F HDR_F_DEF(TO) |
131 | 30.0k | #define HDR_FROM_F HDR_F_DEF(FROM) |
132 | 13.4k | #define HDR_CSEQ_F HDR_F_DEF(CSEQ) |
133 | 761 | #define HDR_CALLID_F HDR_F_DEF(CALLID) |
134 | 8.40k | #define HDR_CONTACT_F HDR_F_DEF(CONTACT) |
135 | 619 | #define HDR_MAXFORWARDS_F HDR_F_DEF(MAXFORWARDS) |
136 | 1.69k | #define HDR_ROUTE_F HDR_F_DEF(ROUTE) |
137 | 622 | #define HDR_RECORDROUTE_F HDR_F_DEF(RECORDROUTE) |
138 | 4.95k | #define HDR_CONTENTTYPE_F HDR_F_DEF(CONTENTTYPE) |
139 | 844 | #define HDR_CONTENTLENGTH_F HDR_F_DEF(CONTENTLENGTH) |
140 | 314 | #define HDR_AUTHORIZATION_F HDR_F_DEF(AUTHORIZATION) |
141 | 313 | #define HDR_EXPIRES_F HDR_F_DEF(EXPIRES) |
142 | 268 | #define HDR_MIN_EXPIRES_F HDR_F_DEF(MIN_EXPIRES) |
143 | 675 | #define HDR_PROXYAUTH_F HDR_F_DEF(PROXYAUTH) |
144 | 350 | #define HDR_SUPPORTED_F HDR_F_DEF(SUPPORTED) |
145 | 302 | #define HDR_REQUIRE_F HDR_F_DEF(REQUIRE) |
146 | 261 | #define HDR_PROXYREQUIRE_F HDR_F_DEF(PROXYREQUIRE) |
147 | 305 | #define HDR_UNSUPPORTED_F HDR_F_DEF(UNSUPPORTED) |
148 | 265 | #define HDR_ALLOW_F HDR_F_DEF(ALLOW) |
149 | 702 | #define HDR_EVENT_F HDR_F_DEF(EVENT) |
150 | 240 | #define HDR_ACCEPT_F HDR_F_DEF(ACCEPT) |
151 | 240 | #define HDR_ACCEPTLANGUAGE_F HDR_F_DEF(ACCEPTLANGUAGE) |
152 | 243 | #define HDR_ORGANIZATION_F HDR_F_DEF(ORGANIZATION) |
153 | 271 | #define HDR_PRIORITY_F HDR_F_DEF(PRIORITY) |
154 | 537 | #define HDR_SUBJECT_F HDR_F_DEF(SUBJECT) |
155 | 283 | #define HDR_USERAGENT_F HDR_F_DEF(USERAGENT) |
156 | 294 | #define HDR_SERVER_F HDR_F_DEF(SERVER) |
157 | 14.5k | #define HDR_CONTENTDISPOSITION_F HDR_F_DEF(CONTENTDISPOSITION) |
158 | 27.3k | #define HDR_DIVERSION_F HDR_F_DEF(DIVERSION) |
159 | 275 | #define HDR_RPID_F HDR_F_DEF(RPID) |
160 | 16.5k | #define HDR_REFER_TO_F HDR_F_DEF(REFER_TO) |
161 | 405 | #define HDR_SIPIFMATCH_F HDR_F_DEF(SIPIFMATCH) |
162 | 454 | #define HDR_SESSIONEXPIRES_F HDR_F_DEF(SESSIONEXPIRES) |
163 | 292 | #define HDR_MIN_SE_F HDR_F_DEF(MIN_SE) |
164 | 271 | #define HDR_SUBSCRIPTION_STATE_F HDR_F_DEF(SUBSCRIPTION_STATE) |
165 | | #define HDR_ACCEPTCONTACT_F HDR_F_DEF(ACCEPTCONTACT) |
166 | | #define HDR_ALLOWEVENTS_F HDR_F_DEF(ALLOWEVENTS) |
167 | | #define HDR_CONTENTENCODING_F HDR_F_DEF(CONTENTENCODING) |
168 | | #define HDR_REFERREDBY_F HDR_F_DEF(REFERREDBY) |
169 | | #define HDR_REJECTCONTACT_F HDR_F_DEF(REJECTCONTACT) |
170 | | #define HDR_REQUESTDISPOSITION_F HDR_F_DEF(REQUESTDISPOSITION) |
171 | | #define HDR_WWW_AUTHENTICATE_F HDR_F_DEF(WWW_AUTHENTICATE) |
172 | | #define HDR_PROXY_AUTHENTICATE_F HDR_F_DEF(PROXY_AUTHENTICATE) |
173 | 284 | #define HDR_DATE_F HDR_F_DEF(DATE) |
174 | 748 | #define HDR_IDENTITY_F HDR_F_DEF(IDENTITY) |
175 | 15.9k | #define HDR_IDENTITY_INFO_F HDR_F_DEF(IDENTITY_INFO) |
176 | | #define HDR_RETRY_AFTER_F HDR_F_DEF(RETRY_AFTER) |
177 | 281 | #define HDR_PPI_F HDR_F_DEF(PPI) |
178 | 55.0k | #define HDR_PAI_F HDR_F_DEF(PAI) |
179 | 281 | #define HDR_PATH_F HDR_F_DEF(PATH) |
180 | 15.2k | #define HDR_PRIVACY_F HDR_F_DEF(PRIVACY) |
181 | 280 | #define HDR_REASON_F HDR_F_DEF(REASON) |
182 | 268 | #define HDR_CALLINFO_F HDR_F_DEF(CALLINFO) |
183 | | |
184 | | #define HDR_OTHER_F HDR_F_DEF(OTHER) |
185 | | |
186 | | /*!} */ /* Doxygen end marker*/ |
187 | | |
188 | | typedef enum _hdr_types_t hdr_types_t; |
189 | | |
190 | | /** Format: name':' body. |
191 | | */ |
192 | | typedef struct hdr_field |
193 | | { |
194 | | hdr_types_t type; /*!< Header field type */ |
195 | | str name; /*!< Header field name */ |
196 | | str body; /*!< Header field body (may not include CRLF) */ |
197 | | int len; /*!< length from hdr start until EoHF (incl.CRLF) */ |
198 | | void *parsed; /*!< Parsed data structures */ |
199 | | struct hdr_field *next; /*!< Next header field in the list */ |
200 | | } hdr_field_t; |
201 | | |
202 | | |
203 | | /* type of the function to free the structure of parsed header field */ |
204 | | typedef void (*hf_parsed_free_f)(void *parsed); |
205 | | |
206 | | /* structure to hold the function to free the parsed header field */ |
207 | | typedef struct hdr_parsed |
208 | | { |
209 | | hf_parsed_free_f hfree; |
210 | | } hf_parsed_t; |
211 | | |
212 | | /** returns true if the header links allocated memory on parse field. */ |
213 | | static inline int hdr_allocs_parse(struct hdr_field *hdr) |
214 | 0 | { |
215 | 0 | switch(hdr->type) { |
216 | 0 | case HDR_ACCEPT_T: |
217 | 0 | case HDR_ALLOW_T: |
218 | 0 | case HDR_AUTHORIZATION_T: |
219 | 0 | case HDR_CONTACT_T: |
220 | 0 | case HDR_CONTENTDISPOSITION_T: |
221 | 0 | case HDR_CSEQ_T: |
222 | 0 | case HDR_DATE_T: |
223 | 0 | case HDR_DIVERSION_T: |
224 | 0 | case HDR_EVENT_T: |
225 | 0 | case HDR_EXPIRES_T: |
226 | 0 | case HDR_MIN_EXPIRES_T: |
227 | 0 | case HDR_FROM_T: |
228 | 0 | case HDR_IDENTITY_INFO_T: |
229 | 0 | case HDR_IDENTITY_T: |
230 | 0 | case HDR_PAI_T: |
231 | 0 | case HDR_PPI_T: |
232 | 0 | case HDR_PROXYAUTH_T: |
233 | 0 | case HDR_RECORDROUTE_T: |
234 | 0 | case HDR_REFER_TO_T: |
235 | 0 | case HDR_REQUIRE_T: |
236 | 0 | case HDR_ROUTE_T: |
237 | 0 | case HDR_RPID_T: |
238 | 0 | case HDR_SESSIONEXPIRES_T: |
239 | 0 | case HDR_SIPIFMATCH_T: |
240 | 0 | case HDR_SUBSCRIPTION_STATE_T: |
241 | 0 | case HDR_SUPPORTED_T: |
242 | 0 | case HDR_TO_T: |
243 | 0 | case HDR_VIA_T: |
244 | 0 | return 1; |
245 | 0 | default: |
246 | 0 | return 0; |
247 | 0 | } |
248 | 0 | } Unexecuted instantiation: fuzz_parse_msg.c:hdr_allocs_parse Unexecuted instantiation: dprint.c:hdr_allocs_parse Unexecuted instantiation: error.c:hdr_allocs_parse Unexecuted instantiation: main.c:hdr_allocs_parse Unexecuted instantiation: modparam.c:hdr_allocs_parse Unexecuted instantiation: msg_parser.c:hdr_allocs_parse Unexecuted instantiation: nonsip_hooks.c:hdr_allocs_parse Unexecuted instantiation: parse_addr_spec.c:hdr_allocs_parse Unexecuted instantiation: parse_contact.c:hdr_allocs_parse Unexecuted instantiation: parse_content.c:hdr_allocs_parse Unexecuted instantiation: parse_cseq.c:hdr_allocs_parse Unexecuted instantiation: parse_disposition.c:hdr_allocs_parse Unexecuted instantiation: parse_diversion.c:hdr_allocs_parse Unexecuted instantiation: parse_fline.c:hdr_allocs_parse Unexecuted instantiation: parse_from.c:hdr_allocs_parse Unexecuted instantiation: parse_hname2.c:hdr_allocs_parse Unexecuted instantiation: parse_identityinfo.c:hdr_allocs_parse Unexecuted instantiation: parse_methods.c:hdr_allocs_parse Unexecuted instantiation: parse_ppi_pai.c:hdr_allocs_parse Unexecuted instantiation: parse_privacy.c:hdr_allocs_parse Unexecuted instantiation: parse_refer_to.c:hdr_allocs_parse Unexecuted instantiation: parse_rr.c:hdr_allocs_parse Unexecuted instantiation: parse_to.c:hdr_allocs_parse Unexecuted instantiation: parse_via.c:hdr_allocs_parse Unexecuted instantiation: ppcfg.c:hdr_allocs_parse Unexecuted instantiation: pt.c:hdr_allocs_parse Unexecuted instantiation: pv_core.c:hdr_allocs_parse Unexecuted instantiation: pvapi.c:hdr_allocs_parse Unexecuted instantiation: q_malloc.c:hdr_allocs_parse Unexecuted instantiation: re.c:hdr_allocs_parse Unexecuted instantiation: receive.c:hdr_allocs_parse Unexecuted instantiation: route.c:hdr_allocs_parse Unexecuted instantiation: route_struct.c:hdr_allocs_parse Unexecuted instantiation: rvalue.c:hdr_allocs_parse Unexecuted instantiation: script_cb.c:hdr_allocs_parse Unexecuted instantiation: sdp.c:hdr_allocs_parse Unexecuted instantiation: sdp_helpr_funcs.c:hdr_allocs_parse Unexecuted instantiation: select.c:hdr_allocs_parse Unexecuted instantiation: select_core.c:hdr_allocs_parse Unexecuted instantiation: sr_module.c:hdr_allocs_parse Unexecuted instantiation: srapi.c:hdr_allocs_parse Unexecuted instantiation: strutils.c:hdr_allocs_parse Unexecuted instantiation: switch.c:hdr_allocs_parse Unexecuted instantiation: tcp_main.c:hdr_allocs_parse Unexecuted instantiation: tcp_read.c:hdr_allocs_parse Unexecuted instantiation: timer_proc.c:hdr_allocs_parse Unexecuted instantiation: udp_server.c:hdr_allocs_parse Unexecuted instantiation: usr_avp.c:hdr_allocs_parse Unexecuted instantiation: action.c:hdr_allocs_parse Unexecuted instantiation: async_task.c:hdr_allocs_parse Unexecuted instantiation: cfg.tab.c:hdr_allocs_parse Unexecuted instantiation: cfg_core.c:hdr_allocs_parse Unexecuted instantiation: cfg_select.c:hdr_allocs_parse Unexecuted instantiation: cfg_struct.c:hdr_allocs_parse Unexecuted instantiation: core_cmd.c:hdr_allocs_parse Unexecuted instantiation: data_lump.c:hdr_allocs_parse Unexecuted instantiation: data_lump_rpl.c:hdr_allocs_parse Unexecuted instantiation: digest.c:hdr_allocs_parse Unexecuted instantiation: dset.c:hdr_allocs_parse Unexecuted instantiation: dst_blocklist.c:hdr_allocs_parse Unexecuted instantiation: events.c:hdr_allocs_parse Unexecuted instantiation: f_malloc.c:hdr_allocs_parse Unexecuted instantiation: flags.c:hdr_allocs_parse Unexecuted instantiation: fmsg.c:hdr_allocs_parse Unexecuted instantiation: forward.c:hdr_allocs_parse Unexecuted instantiation: hf.c:hdr_allocs_parse Unexecuted instantiation: kemi.c:hdr_allocs_parse Unexecuted instantiation: lex.yy.c:hdr_allocs_parse Unexecuted instantiation: lvalue.c:hdr_allocs_parse Unexecuted instantiation: mod_fix.c:hdr_allocs_parse Unexecuted instantiation: msg_translator.c:hdr_allocs_parse Unexecuted instantiation: onsend.c:hdr_allocs_parse Unexecuted instantiation: parse_allow.c:hdr_allocs_parse Unexecuted instantiation: parse_body.c:hdr_allocs_parse Unexecuted instantiation: parse_date.c:hdr_allocs_parse Unexecuted instantiation: parse_event.c:hdr_allocs_parse Unexecuted instantiation: parse_expires.c:hdr_allocs_parse Unexecuted instantiation: parse_identity.c:hdr_allocs_parse Unexecuted instantiation: parse_rpid.c:hdr_allocs_parse Unexecuted instantiation: parse_sipifmatch.c:hdr_allocs_parse Unexecuted instantiation: parse_subscription_state.c:hdr_allocs_parse Unexecuted instantiation: stun.c:hdr_allocs_parse Unexecuted instantiation: fuzz_uri.c:hdr_allocs_parse |
249 | | |
250 | | /** frees a hdr_field structure. |
251 | | * WARNING: it frees only parsed (and not name.s, body.s) |
252 | | */ |
253 | | void clean_hdr_field(struct hdr_field *const hf); |
254 | | |
255 | | |
256 | | /** frees a hdr_field list. |
257 | | * WARNING: frees only ->parsed and ->next |
258 | | */ |
259 | | void free_hdr_field_lst(struct hdr_field *hf); |
260 | | |
261 | | /* print content of hdr_field */ |
262 | | void dump_hdr_field(struct hdr_field const *const hf); |
263 | | |
264 | | /** |
265 | | * free hdr parsed structure using inner free function |
266 | | * - hdr parsed struct must have as first file a free function, |
267 | | * so it can be caseted to hf_parsed_t |
268 | | */ |
269 | | void hdr_free_parsed(void **h_parsed); |
270 | | |
271 | | #endif /* HF_H */ |