msg 1.12.11devel
Loading...
Searching...
No Matches
msg_parser.h
Go to the documentation of this file.
1/*
2 * This file is part of the Sofia-SIP package
3 *
4 * Copyright (C) 2005 Nokia Corporation.
5 *
6 * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef MSG_PARSER_H
27#define MSG_PARSER_H
28
40#ifndef SU_ALLOC_H
41#include <sofia-sip/su_alloc.h>
42#endif
43#ifndef MSG_HEADER_H
45#endif
46#ifndef BNF_H
47#include <sofia-sip/bnf.h>
48#endif
49#ifndef URL_H
50#include <sofia-sip/url.h>
51#endif
52
53SOFIA_BEGIN_DECLS
54
55/* ---------------------------------------------------------------------------
56 * 1) Header class definitions.
57 */
58
59/* Do not use keywords until you fix msg_kind_foo_critical thing! */ \
60#if HAVE_STRUCT_KEYWORDS && 0
62#define MSG_HEADER_CLASS(pr, c, l, s, params, kind, dup, upd) \
63 {{ \
64 hc_hash: pr##c##_hash, \
65 hc_parse: pr##c##_d, \
66 hc_print: pr##c##_e, \
67 hc_dxtra: dup##_dup_xtra, \
68 hc_dup_one: dup##_dup_one, \
69 hc_update: upd##_update, \
70 hc_name: l, \
71 hc_len: sizeof(l) - 1, \
72 hc_short: s, \
73 hc_size: MSG_ALIGN(sizeof(pr##c##_t), sizeof(void*)), \
74 hc_params: offsetof(pr##c##_t, params), \
75 hc_kind: msg_kind_##kind, \
76 }}
77#else
79#define MSG_HEADER_CLASS(pr, c, l, s, params, kind, dup, upd) \
80 {{ \
81 pr##c##_hash, \
82 pr##c##_d, \
83 pr##c##_e, \
84 dup##_dup_xtra, \
85 dup##_dup_one, \
86 upd##_update, \
87 l, \
88 sizeof(l) - 1, \
89 s, \
90 MSG_ALIGN(sizeof(pr##c##_t), sizeof(void*)), \
91 offsetof(pr##c##_t, params), \
92 msg_kind_##kind, \
93 }}
94#endif
95
96/* Mark headers critical for understanding the message */
97#define msg_kind_single_critical msg_kind_single, 1
98#define msg_kind_list_critical msg_kind_list, 1
99
101 char b[], isize_t bsiz, int eos);
103 char b[], isize_t bsiz, int eos);
105 msg_header_t **return_payload,
106 usize_t body_len,
107 char b[], isize_t bsiz, int eos);
108
109/* ---------------------------------------------------------------------------
110 * 2) Header processing methods for common headers.
111 */
112
113SOFIAPUBFUN int msg_firstline_d(char *s, char **ss2, char **ss3);
114
115SOFIAPUBFUN isize_t msg_default_dup_xtra(msg_header_t const *header, isize_t offset);
117 msg_header_t const *src,
118 char *b,
119 isize_t xtra);
120
121SOFIAPUBFUN issize_t msg_numeric_d(su_home_t *, msg_header_t *h, char *s, isize_t slen);
122SOFIAPUBFUN issize_t msg_numeric_e(char [], isize_t, msg_header_t const *, int);
123
124SOFIAPUBFUN issize_t msg_list_d(su_home_t *, msg_header_t *h, char *s, isize_t slen);
125SOFIAPUBFUN issize_t msg_list_e(char [], isize_t, msg_header_t const *, int);
126SOFIAPUBFUN isize_t msg_list_dup_xtra(msg_header_t const *h, isize_t offset);
127SOFIAPUBFUN char *msg_list_dup_one(msg_header_t *dst,
128 msg_header_t const *src,
129 char *b, isize_t xtra);
130
131SOFIAPUBFUN issize_t msg_generic_d(su_home_t *, msg_header_t *, char *, isize_t);
132SOFIAPUBFUN issize_t msg_generic_e(char [], isize_t, msg_header_t const *, int);
133SOFIAPUBFUN isize_t msg_generic_dup_xtra(msg_header_t const *h, isize_t offset);
135 msg_header_t const *src,
136 char *b,
137 isize_t xtra);
138
139SOFIAPUBFUN isize_t msg_unknown_dup_xtra(msg_header_t const *h, isize_t offset);
140SOFIAPUBFUN char *msg_unknown_dup_one(msg_header_t *dst,
141 msg_header_t const *src,
142 char *b, isize_t xtra);
143
144SOFIAPUBFUN isize_t msg_error_dup_xtra(msg_header_t const *h, isize_t offset);
145SOFIAPUBFUN char *msg_error_dup_one(msg_header_t *dst,
146 msg_header_t const *src,
147 char *b, isize_t xtra);
148
149SOFIAPUBFUN issize_t msg_payload_d(su_home_t *, msg_header_t *h, char *s, isize_t slen);
150SOFIAPUBFUN issize_t msg_payload_e(char b[], isize_t bsiz, msg_header_t const *, int f);
151SOFIAPUBFUN isize_t msg_payload_dup_xtra(msg_header_t const *h, isize_t offset);
152SOFIAPUBFUN char *msg_payload_dup_one(msg_header_t *dst,
153 msg_header_t const *src,
154 char *b, isize_t xtra);
155
156SOFIAPUBFUN issize_t msg_separator_d(su_home_t *, msg_header_t *, char *, isize_t);
157SOFIAPUBFUN issize_t msg_separator_e(char [], isize_t, msg_header_t const *, int);
158
159SOFIAPUBFUN issize_t msg_auth_d(su_home_t *, msg_header_t *h, char *s, isize_t slen);
160SOFIAPUBFUN issize_t msg_auth_e(char b[], isize_t bsiz, msg_header_t const *h, int f);
161SOFIAPUBFUN isize_t msg_auth_dup_xtra(msg_header_t const *h, isize_t offset);
163 char *b, isize_t xtra);
164
165/* ---------------------------------------------------------------------------
166 * 2) Macros and prototypes for building header decoding/encoding functions.
167 */
168
169#define MSG_HEADER_DATA(h) ((char *)(h) + (h)->sh_class->hc_size)
170
171#define MSG_HEADER_TEST(h) ((h) && (h)->sh_class)
172
174
175SOFIAPUBFUN int msg_hostport_d(char **ss,
176 char const **return_host,
177 char const **return_port);
178
179SOFIAPUBFUN issize_t msg_token_d(char **ss, char const **return_token);
180SOFIAPUBFUN issize_t msg_uint32_d(char **ss, uint32_t *return_value);
181SOFIAPUBFUN issize_t msg_comment_d(char **ss, char const **return_comment);
182SOFIAPUBFUN issize_t msg_quoted_d(char **ss, char **return_unquoted);
183SOFIAPUBFUN issize_t msg_unquoted_e(char *b, isize_t bsiz, char const *s);
184
186 char *s, isize_t slen);
187
189#define MSG_TERM_E(p, e) ((p) < (e) ? (p)[0] = '\0' : '\0')
190
192#define MSG_CHAR_E(p, e, c) (++(p) < (e) ? ((p)[-1]=(c)) : (c))
193
195#define MSG_STRING_LEN(s, sep_size) ((s) ? (strlen(s) + sep_size) : 0)
196
198#define MSG_STRING_E(p, e, s) do { \
199 size_t _n = strlen(s); if (p + _n+1 < e) memcpy(p, s, _n+1); p+= _n; } while(0)
200
202#define MSG_STRING_DUP(p, d, s) \
203 (void)((s)?((p)=(char*)memccpy((void *)((d)=(char*)p),(s),0,INT_MAX))\
204 :((d)=NULL))
205
206/* Solaris has broken memccpy - it considers last argument as signed */
207
209#define MSG_STRING_SIZE(s) ((s) ? (strlen(s) + 1) : 0)
210
211SOFIAPUBFUN issize_t msg_commalist_d(su_home_t *, char **ss,
212 msg_param_t **append_list,
213 issize_t (*scanner)(char *s));
214SOFIAPUBFUN issize_t msg_token_scan(char *start);
216
217SOFIAPUBFUN issize_t msg_any_list_d(su_home_t *, char **ss,
218 msg_param_t **append_list,
219 issize_t (*scanner)(char *s),
220 int sep);
221
223#define MSG_COMMALIST_E(b, end, params, compact) do { \
224 char const * const *p_; char const * c_ = ""; \
225 for (p_ = (params); p_ && *p_; p_++, c_ = (compact ? "," : ", ")) \
226 { MSG_STRING_E(b, (end), c_); MSG_STRING_E(b, (end), *p_); } \
227} while(0)
228
229/* Parameter lists */
230
232
234#define MSG_PARAM_MATCH(v, s, name) \
235 (strncasecmp(s, name "=", sizeof(name)) == 0 ? (v = s + sizeof(name)) : NULL)
236
238#define MSG_PARAM_MATCH_P(v, s, name) \
239 ((strncasecmp((s), name "", sizeof(name) - 1) == 0 && \
240 ((s)[sizeof(name) - 1] == '=' || (s)[sizeof(name) - 1] == '\0')) ? \
241 ((v) = 1) : 0)
242
244#define MSG_PARAMS_NUM(n) (((n) + MSG_N_PARAMS - 1) & (size_t)(0 - MSG_N_PARAMS))
245
247SOFIAPUBFUN issize_t msg_avlist_d(su_home_t *, char **ss,
248 msg_param_t const **return_params);
249
251SOFIAPUBFUN issize_t msg_params_d(su_home_t *, char **ss,
252 msg_param_t const **return_params);
253
255SOFIAPUBFUN isize_t msg_params_e(char b[], isize_t bsiz, msg_param_t const pparams[]);
256
259 msg_param_t **dst,
260 msg_param_t const *src,
261 unsigned prune,
262 int dup);
263
265#define MSG_PARAMS_E(b, end, params, flags) \
266 (b) += msg_params_e((b), (size_t)((b) < (end) ? (end) - (b) : 0), (params))
267
269#define MSG_PARAMS_SIZE(rv, params) (rv = msg_params_dup_xtra(params, rv))
270
272SOFIAPUBFUN char *msg_params_dup(msg_param_t const **d, msg_param_t const *s,
273 char *b, isize_t xtra);
274
276su_inline isize_t msg_params_count(msg_param_t const params[])
277{
278 if (params) {
279 size_t n;
280 for (n = 0; params[n]; n++)
281 ;
282 return n;
283 }
284 else {
285 return 0;
286 }
287}
288
290su_inline isize_t msg_params_dup_xtra(msg_param_t const params[], isize_t offset)
291{
292 isize_t n = msg_params_count(params);
293 if (n) {
294 MSG_STRUCT_SIZE_ALIGN(offset);
295 offset += MSG_PARAMS_NUM(n + 1) * sizeof(msg_param_t);
296 for (n = 0; params[n]; n++)
297 offset += strlen(params[n]) + 1;
298 }
299 return offset;
300}
301
304{
305 if (h)
306 return (char *)h + h->h_class->hc_size;
307 else
308 return NULL;
309}
310
311SOFIA_END_DECLS
312
313#endif
issize_t msg_auth_d(su_home_t *, msg_header_t *h, char *s, isize_t slen)
Parse security headers.
Definition msg_auth.c:88
msg_print_f msg_payload_e
Print a message payload.
Definition msg_protos.h:815
msg_parse_f msg_payload_d
Parse a message payload.
Definition msg_protos.h:812
msg_print_f msg_separator_e
Print a separator line between headers and body.
Definition msg_protos.h:566
msg_parse_f msg_separator_d
Parse a separator line between headers and body.
Definition msg_protos.h:563
Message headers.
char * msg_generic_dup_one(msg_header_t *dst, msg_header_t const *src, char *b, isize_t xtra)
Duplicate one msg_generic_t object.
Definition msg_generic.c:101
isize_t msg_params_dup_xtra(msg_param_t const params[], isize_t offset)
Calculate memory size required by parameter list.
Definition msg_parser.h:290
issize_t msg_token_scan(char *start)
Token scanner for msg_commalist_d() accepting also empty entries.
Definition msg_parser_util.c:593
isize_t msg_default_dup_xtra(msg_header_t const *header, isize_t offset)
Calculate extra size of a plain header.
Definition msg_header_copy.c:325
issize_t msg_extract_payload(msg_t *msg, msg_pub_t *mo, msg_header_t **return_payload, usize_t body_len, char b[], isize_t bsiz, int eos)
Extract a message body of body_len bytes.
Definition msg_parser.c:1312
isize_t msg_generic_dup_xtra(msg_header_t const *h, isize_t offset)
Calculate the size of strings associated with a msg_generic_t object.
Definition msg_generic.c:94
issize_t msg_parse_next_field(su_home_t *home, msg_header_t *prev, char *s, isize_t slen)
Complete this header field and parse next header field.
Definition msg_parser.c:1212
int msg_firstline_d(char *s, char **ss2, char **ss3)
Parse first line.
Definition msg_parser_util.c:66
char * msg_auth_dup_one(msg_header_t *dst, msg_header_t const *src, char *b, isize_t xtra)
Duplicate one msg_auth_t object.
Definition msg_auth.c:142
issize_t msg_params_join(su_home_t *, msg_param_t **dst, msg_param_t const *src, unsigned prune, int dup)
Join list of parameters.
Definition msg_parser_util.c:1501
char * msg_default_dup_one(msg_header_t *dst, msg_header_t const *src, char *b, isize_t xtra)
Duplicate a header object without external references.
Definition msg_header_copy.c:344
int msg_header_update_params(msg_common_t *h, int clear)
Update shortcuts to parameter values.
Definition msg_parser_util.c:1106
#define MSG_PARAMS_NUM(n)
Calculate allocated number of items in parameter list.
Definition msg_parser.h:244
issize_t msg_token_d(char **ss, char const **return_token)
Parse a token.
Definition msg_parser_util.c:106
issize_t msg_extract_separator(msg_t *msg, msg_pub_t *mo, char b[], isize_t bsiz, int eos)
Extract a separator line.
Definition msg_parser.c:1283
isize_t msg_params_count(msg_param_t const params[])
Count number of parameters in the list.
Definition msg_parser.h:276
void * msg_header_data(msg_frg_t *h)
Return pointer to extra data after header structure.
Definition msg_parser.h:303
issize_t msg_attribute_value_scanner(char *s)
Scan an attribute (name [= value]) pair.
Definition msg_parser_util.c:290
issize_t msg_quoted_d(char **ss, char **return_unquoted)
Parse a quoted string.
Definition msg_parser_util.c:686
issize_t msg_unquoted_e(char *b, isize_t bsiz, char const *s)
Quote string.
Definition msg_parser_util.c:1786
issize_t msg_generic_e(char[], isize_t, msg_header_t const *, int)
Encode a generic header.
Definition msg_generic.c:82
int msg_hostport_d(char **ss, char const **return_host, char const **return_port)
Parse host[":"port] pair.
Definition msg_parser_util.c:755
issize_t msg_comment_d(char **ss, char const **return_comment)
Parse a comment.
Definition msg_parser_util.c:654
issize_t msg_avlist_d(su_home_t *, char **ss, msg_param_t const **return_params)
Parse a semicolong-separated attribute-value list.
Definition msg_parser_util.c:351
issize_t msg_extract_header(msg_t *msg, msg_pub_t *mo, char b[], isize_t bsiz, int eos)
Extract a header.
Definition msg_parser.c:1005
issize_t msg_params_d(su_home_t *, char **ss, msg_param_t const **return_params)
Parse a semicolon-separated parameter list starting with semicolon.
Definition msg_parser_util.c:485
issize_t msg_uint32_d(char **ss, uint32_t *return_value)
Parse a 32-bit unsigned int.
Definition msg_parser_util.c:129
issize_t msg_generic_d(su_home_t *, msg_header_t *, char *, isize_t)
Parse a generic header.
Definition msg_generic.c:66
isize_t msg_params_e(char b[], isize_t bsiz, msg_param_t const pparams[])
Encode a list of parameters.
Definition msg_parser_util.c:503
char * msg_params_dup(msg_param_t const **d, msg_param_t const *s, char *b, isize_t xtra)
Duplicate a parameter list.
issize_t msg_commalist_d(su_home_t *, char **ss, msg_param_t **append_list, issize_t(*scanner)(char *s))
Parse a comma-separated list.
Definition msg_parser_util.c:583
issize_t msg_any_list_d(su_home_t *, char **ss, msg_param_t **append_list, issize_t(*scanner)(char *s), int sep)
Parse any list.
Definition msg_parser_util.c:189
MSG_HDR_T msg_header_t
Any protocol-specific header object.
Definition msg_types.h:87
MSG_PUB_T msg_pub_t
Public protocol-specific message structure for accessing the message.
Definition msg_types.h:81
Common part of the header objects (or message fragments).
Definition msg_types.h:111
msg_hclass_t * h_class
Header class.
Definition msg_types.h:114
Message object.
Definition msg_internal.h:59
SU_HOME_T su_home_t
#define SOFIAPUBFUN
#define su_inline
SU_U32_T uint32_t

Sofia-SIP 1.12.11devel - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.