Coverage Report

Created: 2025-07-11 06:28

/src/opensips/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 opensips, a free SIP server.
5
 *
6
 * opensips 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
 * opensips 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
 * History:
21
 * ---------
22
 * 2006-02-17 Session-Expires, Min-SE (dhsueh@somanetworks.com)
23
 * 2006-03-02 header of same type are linked as sibling (bogdan)
24
 */
25
26
/**
27
 * \file parser/hf.h
28
 * \brief Defines for SIP header types
29
 */
30
31
32
#ifndef HF_H
33
#define HF_H
34
35
#include "../str.h"
36
37
/**
38
 * SIP Header types.
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
 */
46
47
enum _hdr_types_t {
48
  HDR_ERROR_T         = -1 /**< Error while parsing */,
49
  HDR_OTHER_T         =  0 /**< Some other header field */,
50
  HDR_VIA_T         =  1 /**< Via header field */,
51
  HDR_VIA1_T          =  1 /**< First Via header field */,
52
  HDR_VIA2_T          =  2 /**< only used as flag */,
53
  HDR_TO_T               /**< To header field */,
54
  HDR_FROM_T               /**< From header field */,
55
  HDR_CSEQ_T               /**< CSeq header field */,
56
  HDR_CALLID_T             /**< Call-Id header field */,
57
  HDR_CONTACT_T            /**< Contact header field */,
58
  HDR_MAXFORWARDS_T          /**< MaxForwards header field */,
59
  HDR_ROUTE_T              /**< Route header field */,
60
  HDR_RECORDROUTE_T          /**< Record-Route header field */,
61
  HDR_PATH_T               /**< Path header fiels */,
62
  HDR_CONTENTTYPE_T          /**< Content-Type header field */,
63
  HDR_CONTENTLENGTH_T          /**< Content-Length header field */,
64
  HDR_AUTHORIZATION_T          /**< Authorization header field */,
65
  HDR_EXPIRES_T            /**< Expires header field */,
66
  HDR_PROXYAUTH_T            /**< Proxy-Authorization hdr field */,
67
  HDR_SUPPORTED_T            /**< Supported  header field */,
68
  HDR_PROXYREQUIRE_T           /**< Proxy-Require header field */,
69
  HDR_UNSUPPORTED_T          /**< Unsupported header field */,
70
  HDR_ALLOW_T              /**< Allow header field */,
71
  HDR_EVENT_T              /**< Event header field */,
72
  HDR_ACCEPT_T             /**< Accept header field */,
73
  HDR_ACCEPTLANGUAGE_T         /**< Accept-Language header field */,
74
  HDR_ORGANIZATION_T           /**< Organization header field */,
75
  HDR_PRIORITY_T             /**< Priority header field */,
76
  HDR_SUBJECT_T            /**< Subject header field */,
77
  HDR_USERAGENT_T            /**< User-Agent header field */,
78
  HDR_ACCEPTDISPOSITION_T        /**< Accept-Disposition hdr field */,
79
  HDR_CONTENTDISPOSITION_T       /**< Content-Disposition hdr field */,
80
  HDR_DIVERSION_T            /**< Diversion header field */,
81
  HDR_RPID_T               /**< Remote-Party-ID header field */,
82
  HDR_REFER_TO_T             /**< Refer-To header fiels */,
83
  HDR_SESSION_EXPIRES_T        /**< Session-Expires header field */,
84
  HDR_MIN_SE_T             /**< Min-SE header field */,
85
  HDR_PPI_T              /**< P-Preferred-Identity header field */,
86
  HDR_PAI_T              /**< P-Asserted-Identity header field */,
87
  HDR_PRIVACY_T            /**< Privacy header field */,
88
  HDR_RETRY_AFTER_T          /**< Retry-After header field */,
89
  HDR_CALL_INFO_T            /**< Call-Info header field */,
90
  HDR_WWW_AUTHENTICATE_T         /**< WWW-Authenticate header field */,
91
  HDR_PROXY_AUTHENTICATE_T       /**< Proxy-Authenticate header field */,
92
  HDR_MIN_EXPIRES_T          /**> Min-Expires header field */,
93
  HDR_FEATURE_CAPS_T           /**> Feature-Caps header field */,
94
  HDR_REPLACES_T             /**> Replaces header field */,
95
  HDR_TO_PATH_T            /**> MSRP To-Path header field */,
96
  HDR_FROM_PATH_T            /**> MSRP From-Path header field */,
97
  HDR_MESSAGE_ID_T           /**> MSRP Message-ID header field */,
98
  HDR_BYTE_RANGE_T           /**> MSRP Byte-Range header field */,
99
  HDR_FAILURE_REPORT_T         /**> MSRP Failure-Report header field */,
100
  HDR_SUCCESS_REPORT_T         /**> MSRP Success-Report header field */,
101
  HDR_STATUS_T             /**> MSRP Status header field */,
102
  HDR_USE_PATH_T             /**> MSRP Use-Path header field */,
103
  HDR_SECURITY_CLIENT_T        /**> sec-agree RFC3329 Security-Client header field */,
104
  HDR_SECURITY_SERVER_T        /**> sec-agree RFC3329 Security-Server header field */,
105
  HDR_SECURITY_VERIFY_T        /**> sec-agree RFC3329 Security-Verify header field */,
106
  HDR_EOH_T              /**< Some other header field */
107
};
108
109
110
typedef unsigned long long hdr_flags_t;
111
112
/**
113
 * Type to flag conversion
114
 * WARNING: HDR_ERROR_T has no corresponding FLAG!
115
 */
116
#define HDR_T2F(type) \
117
707k
    (((type)!=HDR_EOH_T)?((hdr_flags_t)1<<(type)):(~(hdr_flags_t)0))
118
119
/** helper macro for easy defining and keeping in sync. the flags enum */
120
707k
#define HDR_F_DEF(name)   HDR_T2F(HDR_##name##_T)
121
122
/**
123
 * Flags definitions
124
 * (enums won't work with all the compilers (e.g. icc) due to the 64bit size)
125
 */
126
39.8k
#define HDR_EOH_F         HDR_F_DEF(EOH)
127
144k
#define HDR_VIA_F         HDR_F_DEF(VIA)
128
#define HDR_VIA1_F          HDR_F_DEF(VIA1)
129
200
#define HDR_VIA2_F          HDR_F_DEF(VIA2)
130
65.8k
#define HDR_TO_F          HDR_F_DEF(TO)
131
19.4k
#define HDR_FROM_F          HDR_F_DEF(FROM)
132
79.2k
#define HDR_CSEQ_F          HDR_F_DEF(CSEQ)
133
20.9k
#define HDR_CALLID_F        HDR_F_DEF(CALLID)
134
19.2k
#define HDR_CONTACT_F       HDR_F_DEF(CONTACT)
135
5.35k
#define HDR_MAXFORWARDS_F     HDR_F_DEF(MAXFORWARDS)
136
6.30k
#define HDR_ROUTE_F         HDR_F_DEF(ROUTE)
137
8.13k
#define HDR_RECORDROUTE_F     HDR_F_DEF(RECORDROUTE)
138
6.83k
#define HDR_PATH_F          HDR_F_DEF(PATH)
139
13.5k
#define HDR_CONTENTTYPE_F     HDR_F_DEF(CONTENTTYPE)
140
7.30k
#define HDR_CONTENTLENGTH_F     HDR_F_DEF(CONTENTLENGTH)
141
6.39k
#define HDR_AUTHORIZATION_F     HDR_F_DEF(AUTHORIZATION)
142
12.5k
#define HDR_EXPIRES_F       HDR_F_DEF(EXPIRES)
143
7.73k
#define HDR_PROXYAUTH_F       HDR_F_DEF(PROXYAUTH)
144
11.1k
#define HDR_SUPPORTED_F       HDR_F_DEF(SUPPORTED)
145
11.9k
#define HDR_PROXYREQUIRE_F      HDR_F_DEF(PROXYREQUIRE)
146
8.09k
#define HDR_UNSUPPORTED_F     HDR_F_DEF(UNSUPPORTED)
147
11.4k
#define HDR_ALLOW_F         HDR_F_DEF(ALLOW)
148
14.2k
#define HDR_EVENT_F         HDR_F_DEF(EVENT)
149
5.10k
#define HDR_ACCEPT_F        HDR_F_DEF(ACCEPT)
150
8.58k
#define HDR_ACCEPTLANGUAGE_F    HDR_F_DEF(ACCEPTLANGUAGE)
151
3.19k
#define HDR_ORGANIZATION_F      HDR_F_DEF(ORGANIZATION)
152
6.71k
#define HDR_PRIORITY_F        HDR_F_DEF(PRIORITY)
153
11.2k
#define HDR_SUBJECT_F       HDR_F_DEF(SUBJECT)
154
7.32k
#define HDR_USERAGENT_F       HDR_F_DEF(USERAGENT)
155
13.2k
#define HDR_ACCEPTDISPOSITION_F   HDR_F_DEF(ACCEPTDISPOSITION)
156
7.42k
#define HDR_CONTENTDISPOSITION_F  HDR_F_DEF(CONTENTDISPOSITION)
157
6.57k
#define HDR_DIVERSION_F       HDR_F_DEF(DIVERSION)
158
3.22k
#define HDR_RPID_F          HDR_F_DEF(RPID)
159
6.51k
#define HDR_REFER_TO_F        HDR_F_DEF(REFER_TO)
160
22.7k
#define HDR_SESSION_EXPIRES_F   HDR_F_DEF(SESSION_EXPIRES)
161
9.40k
#define HDR_MIN_SE_F        HDR_F_DEF(MIN_SE)
162
5.57k
#define HDR_PPI_F         HDR_F_DEF(PPI)
163
3.76k
#define HDR_PAI_F         HDR_F_DEF(PAI)
164
11.9k
#define HDR_PRIVACY_F       HDR_F_DEF(PRIVACY)
165
#define HDR_RETRY_AFTER_F     HDR_F_DEF(RETRY_AFTER)
166
3.46k
#define HDR_CALL_INFO_F       HDR_F_DEF(CALL_INFO)
167
14.3k
#define HDR_WWW_AUTHENTICATE_F    HDR_F_DEF(WWW_AUTHENTICATE)
168
7.52k
#define HDR_PROXY_AUTHENTICATE_F  HDR_F_DEF(PROXY_AUTHENTICATE)
169
5.33k
#define HDR_MIN_EXPIRES_F     HDR_F_DEF(MIN_EXPIRES)
170
1.79k
#define HDR_FEATURE_CAPS_F      HDR_F_DEF(FEATURE_CAPS)
171
1.40k
#define HDR_REPLACES_F        HDR_F_DEF(REPLACES)
172
#define HDR_TO_PATH_F       HDR_F_DEF(TO_PATH)
173
#define HDR_FROM_PATH_F       HDR_F_DEF(FROM_PATH)
174
#define HDR_MESSAGE_ID_F      HDR_F_DEF(MESSAGE_ID)
175
#define HDR_BYTE_RANGE_F      HDR_F_DEF(BYTE_RANGE)
176
#define HDR_FAILURE_REPORT_F    HDR_F_DEF(FAILURE_REPORT)
177
#define HDR_SUCCESS_REPORT_F    HDR_F_DEF(SUCCESS_REPORT)
178
#define HDR_STATUS_F        HDR_F_DEF(STATUS)
179
#define HDR_USE_PATH_F        HDR_F_DEF(USE_PATH)
180
7.35k
#define HDR_SECURITY_CLIENT_F   HDR_F_DEF(SECURITY_CLIENT)
181
8.53k
#define HDR_SECURITY_SERVER_F   HDR_F_DEF(SECURITY_SERVER)
182
5.50k
#define HDR_SECURITY_VERIFY_F   HDR_F_DEF(SECURITY_VERIFY)
183
#define HDR_OTHER_F         HDR_F_DEF(OTHER)
184
185
typedef enum _hdr_types_t hdr_types_t;
186
187
/**
188
 * Data structure for a SIP header.
189
 * Format: name':' body
190
 */
191
struct hdr_field {
192
  hdr_types_t type;       /**< Header field type */
193
  str name;               /**< Header field name */
194
  str body;               /**< Header field body (may not include CRLF) */
195
  int len;                /**< length from hdr start until EoHF (incl.CRLF) */
196
  void* parsed;           /**< Parsed data structures */
197
  struct hdr_field* next; /**< Next header field in the list */
198
  struct hdr_field* sibling; /**< Next header of same type */
199
};
200
201
202
203
/* returns true if the header links allocated memory on parse field */
204
static inline int hdr_allocs_parse(struct hdr_field* hdr)
205
0
{
206
0
  switch(hdr->type){
207
0
    case HDR_VIA_T:
208
0
    case HDR_TO_T:
209
0
    case HDR_FROM_T:
210
0
    case HDR_CONTACT_T:
211
0
    case HDR_ROUTE_T:
212
0
    case HDR_RECORDROUTE_T:
213
0
    case HDR_PATH_T:
214
0
    case HDR_AUTHORIZATION_T:
215
0
    case HDR_EXPIRES_T:
216
0
    case HDR_PROXYAUTH_T:
217
0
    case HDR_EVENT_T:
218
0
    case HDR_ACCEPT_T:
219
0
    case HDR_CONTENTTYPE_T:
220
0
    case HDR_CONTENTDISPOSITION_T:
221
0
    case HDR_DIVERSION_T:
222
0
    case HDR_RPID_T:
223
0
    case HDR_REFER_TO_T:
224
0
    case HDR_SESSION_EXPIRES_T:
225
0
    case HDR_PPI_T:
226
0
    case HDR_PAI_T:
227
0
    case HDR_CALL_INFO_T:
228
0
    case HDR_WWW_AUTHENTICATE_T:
229
0
    case HDR_PROXY_AUTHENTICATE_T:
230
0
    case HDR_ALLOW_T:
231
0
    case HDR_SUPPORTED_T:
232
0
    case HDR_SECURITY_CLIENT_T:
233
0
    case HDR_SECURITY_SERVER_T:
234
0
    case HDR_SECURITY_VERIFY_T:
235
0
      return 1;
236
0
    default:
237
0
      return 0;
238
0
  }
239
0
}
Unexecuted instantiation: fuzz_csv_parser.c:hdr_allocs_parse
Unexecuted instantiation: csv.c:hdr_allocs_parse
Unexecuted instantiation: dprint.c:hdr_allocs_parse
Unexecuted instantiation: pt.c:hdr_allocs_parse
Unexecuted instantiation: ut.c:hdr_allocs_parse
Unexecuted instantiation: statistics.c:hdr_allocs_parse
Unexecuted instantiation: route.c:hdr_allocs_parse
Unexecuted instantiation: ipc.c:hdr_allocs_parse
Unexecuted instantiation: core_stats.c:hdr_allocs_parse
Unexecuted instantiation: route_struct.c:hdr_allocs_parse
Unexecuted instantiation: dset.c:hdr_allocs_parse
Unexecuted instantiation: pt_load.c:hdr_allocs_parse
Unexecuted instantiation: sr_module.c:hdr_allocs_parse
Unexecuted instantiation: action.c:hdr_allocs_parse
Unexecuted instantiation: db_insertq.c:hdr_allocs_parse
Unexecuted instantiation: db.c:hdr_allocs_parse
Unexecuted instantiation: proto_tcp.c:hdr_allocs_parse
Unexecuted instantiation: proto_udp.c:hdr_allocs_parse
Unexecuted instantiation: net_tcp_proc.c:hdr_allocs_parse
Unexecuted instantiation: net_tcp.c:hdr_allocs_parse
Unexecuted instantiation: tcp_common.c:hdr_allocs_parse
Unexecuted instantiation: net_udp.c:hdr_allocs_parse
Unexecuted instantiation: tcp_conn_profile.c:hdr_allocs_parse
Unexecuted instantiation: trans_trace.c:hdr_allocs_parse
Unexecuted instantiation: net_tcp_report.c:hdr_allocs_parse
Unexecuted instantiation: shm_mem.c:hdr_allocs_parse
Unexecuted instantiation: mi.c:hdr_allocs_parse
Unexecuted instantiation: item.c:hdr_allocs_parse
Unexecuted instantiation: msg_parser.c:hdr_allocs_parse
Unexecuted instantiation: parse_uri.c:hdr_allocs_parse
Unexecuted instantiation: parse_fline.c:hdr_allocs_parse
Unexecuted instantiation: parse_methods.c:hdr_allocs_parse
Unexecuted instantiation: parse_hname2.c:hdr_allocs_parse
Unexecuted instantiation: parse_content.c:hdr_allocs_parse
Unexecuted instantiation: hf.c:hdr_allocs_parse
Unexecuted instantiation: parse_to.c:hdr_allocs_parse
Unexecuted instantiation: parse_via.c:hdr_allocs_parse
Unexecuted instantiation: event_interface.c:hdr_allocs_parse
Unexecuted instantiation: receive.c:hdr_allocs_parse
Unexecuted instantiation: error.c:hdr_allocs_parse
Unexecuted instantiation: script_cb.c:hdr_allocs_parse
Unexecuted instantiation: ip_addr.c:hdr_allocs_parse
Unexecuted instantiation: data_lump_rpl.c:hdr_allocs_parse
Unexecuted instantiation: async.c:hdr_allocs_parse
Unexecuted instantiation: daemonize.c:hdr_allocs_parse
Unexecuted instantiation: timer.c:hdr_allocs_parse
Unexecuted instantiation: trace_api.c:hdr_allocs_parse
Unexecuted instantiation: mod_fix.c:hdr_allocs_parse
Unexecuted instantiation: reactor.c:hdr_allocs_parse
Unexecuted instantiation: strcommon.c:hdr_allocs_parse
Unexecuted instantiation: forward.c:hdr_allocs_parse
Unexecuted instantiation: xlog.c:hdr_allocs_parse
Unexecuted instantiation: blacklists.c:hdr_allocs_parse
Unexecuted instantiation: msg_callbacks.c:hdr_allocs_parse
Unexecuted instantiation: usr_avp.c:hdr_allocs_parse
Unexecuted instantiation: sl_cb.c:hdr_allocs_parse
Unexecuted instantiation: sdp_ops.c:hdr_allocs_parse
Unexecuted instantiation: resolve.c:hdr_allocs_parse
Unexecuted instantiation: io_wait.c:hdr_allocs_parse
Unexecuted instantiation: transformations.c:hdr_allocs_parse
Unexecuted instantiation: pvar.c:hdr_allocs_parse
Unexecuted instantiation: sr_module_deps.c:hdr_allocs_parse
Unexecuted instantiation: cfg_reload.c:hdr_allocs_parse
Unexecuted instantiation: socket_info.c:hdr_allocs_parse
Unexecuted instantiation: time_rec.c:hdr_allocs_parse
Unexecuted instantiation: data_lump.c:hdr_allocs_parse
Unexecuted instantiation: status_report.c:hdr_allocs_parse
Unexecuted instantiation: pt_scaling.c:hdr_allocs_parse
Unexecuted instantiation: signals.c:hdr_allocs_parse
Unexecuted instantiation: flags.c:hdr_allocs_parse
Unexecuted instantiation: db_id.c:hdr_allocs_parse
Unexecuted instantiation: trans.c:hdr_allocs_parse
Unexecuted instantiation: sdp.c:hdr_allocs_parse
Unexecuted instantiation: sdp_helpr_funcs.c:hdr_allocs_parse
Unexecuted instantiation: digest_parser.c:hdr_allocs_parse
Unexecuted instantiation: param_parser.c:hdr_allocs_parse
Unexecuted instantiation: digest.c:hdr_allocs_parse
Unexecuted instantiation: parse_contact.c:hdr_allocs_parse
Unexecuted instantiation: parse_body.c:hdr_allocs_parse
Unexecuted instantiation: parse_security.c:hdr_allocs_parse
Unexecuted instantiation: parse_call_info.c:hdr_allocs_parse
Unexecuted instantiation: parse_event.c:hdr_allocs_parse
Unexecuted instantiation: parse_disposition.c:hdr_allocs_parse
Unexecuted instantiation: parse_authenticate.c:hdr_allocs_parse
Unexecuted instantiation: parser_f.c:hdr_allocs_parse
Unexecuted instantiation: parse_rpid.c:hdr_allocs_parse
Unexecuted instantiation: parse_ppi.c:hdr_allocs_parse
Unexecuted instantiation: parse_fcaps.c:hdr_allocs_parse
Unexecuted instantiation: parse_sst.c:hdr_allocs_parse
Unexecuted instantiation: parse_rr.c:hdr_allocs_parse
Unexecuted instantiation: parse_param.c:hdr_allocs_parse
Unexecuted instantiation: parse_diversion.c:hdr_allocs_parse
Unexecuted instantiation: parse_nameaddr.c:hdr_allocs_parse
Unexecuted instantiation: parse_expires.c:hdr_allocs_parse
Unexecuted instantiation: parse_refer_to.c:hdr_allocs_parse
Unexecuted instantiation: parse_from.c:hdr_allocs_parse
Unexecuted instantiation: parse_pai.c:hdr_allocs_parse
Unexecuted instantiation: evi_transport.c:hdr_allocs_parse
Unexecuted instantiation: msg_translator.c:hdr_allocs_parse
Unexecuted instantiation: md5utils.c:hdr_allocs_parse
Unexecuted instantiation: cfg.tab.c:hdr_allocs_parse
Unexecuted instantiation: modparam.c:hdr_allocs_parse
Unexecuted instantiation: crc.c:hdr_allocs_parse
Unexecuted instantiation: re.c:hdr_allocs_parse
Unexecuted instantiation: lex.yy.c:hdr_allocs_parse
Unexecuted instantiation: cfg_pp.c:hdr_allocs_parse
Unexecuted instantiation: shutdown.c:hdr_allocs_parse
Unexecuted instantiation: cmds.c:hdr_allocs_parse
Unexecuted instantiation: core_cmds.c:hdr_allocs_parse
Unexecuted instantiation: serialize.c:hdr_allocs_parse
Unexecuted instantiation: cachedb.c:hdr_allocs_parse
Unexecuted instantiation: cachedb_id.c:hdr_allocs_parse
Unexecuted instantiation: fuzz_uri_parser.c:hdr_allocs_parse
Unexecuted instantiation: fuzz_core_funcs.c:hdr_allocs_parse
Unexecuted instantiation: fuzz_msg_parser.c:hdr_allocs_parse
240
241
/**
242
 * Frees a hdr_field structure.
243
 * WARNING: it frees only parsed (and not name.s, body.s)
244
 *
245
 * \param hf header that should be freed
246
 */
247
void clean_hdr_field(struct hdr_field* hf);
248
249
/**
250
 * Frees a hdr_field list.
251
 * WARNING: frees only ->parsed and ->next
252
 *
253
 * \param hf header field that should be freed
254
 */
255
void free_hdr_field_lst(struct hdr_field* hf);
256
257
/**
258
 * Output the contents of a header to the opensips logging system
259
 * with log level ERROR.
260
 * \param hf header that is dumped
261
 */
262
void dump_hdr_field( struct hdr_field* hf );
263
264
#endif /* HF_H */