Loading...
Searching...
No Matches
msg_parser.h
Go to the documentation of this file.
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef MSG_PARSER_H
#define MSG_PARSER_H
#ifndef SU_ALLOC_H
#include <sofia-sip/su_alloc.h>
#endif
#ifndef MSG_HEADER_H
#include <sofia-sip/msg_header.h>
#endif
#ifndef BNF_H
#include <sofia-sip/bnf.h>
#endif
#ifndef URL_H
#include <sofia-sip/url.h>
#endif
SOFIA_BEGIN_DECLS
/* ---------------------------------------------------------------------------
* 1) Header class definitions.
*/
/* Do not use keywords until you fix msg_kind_foo_critical thing! */ \
#if HAVE_STRUCT_KEYWORDS && 0
#define MSG_HEADER_CLASS(pr, c, l, s, params, kind, dup, upd) \
{{ \
hc_hash: pr##c##_hash, \
hc_parse: pr##c##_d, \
hc_print: pr##c##_e, \
hc_dxtra: dup##_dup_xtra, \
hc_dup_one: dup##_dup_one, \
hc_update: upd##_update, \
hc_name: l, \
hc_len: sizeof(l) - 1, \
hc_short: s, \
hc_size: MSG_ALIGN(sizeof(pr##c##_t), sizeof(void*)), \
hc_params: offsetof(pr##c##_t, params), \
hc_kind: msg_kind_##kind, \
}}
#else
#define MSG_HEADER_CLASS(pr, c, l, s, params, kind, dup, upd) \
{{ \
pr##c##_hash, \
pr##c##_d, \
pr##c##_e, \
dup##_dup_xtra, \
dup##_dup_one, \
upd##_update, \
l, \
sizeof(l) - 1, \
s, \
MSG_ALIGN(sizeof(pr##c##_t), sizeof(void*)), \
offsetof(pr##c##_t, params), \
msg_kind_##kind, \
}}
#endif
/* Mark headers critical for understanding the message */
#define msg_kind_single_critical msg_kind_single, 1
#define msg_kind_list_critical msg_kind_list, 1
SOFIAPUBFUN issize_t msg_extract_header(msg_t *msg, msg_pub_t *mo,
char b[], isize_t bsiz, int eos);
SOFIAPUBFUN issize_t msg_extract_separator(msg_t *msg, msg_pub_t *mo,
char b[], isize_t bsiz, int eos);
SOFIAPUBFUN 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);
/* ---------------------------------------------------------------------------
* 2) Header processing methods for common headers.
*/
SOFIAPUBFUN int msg_firstline_d(char *s, char **ss2, char **ss3);
SOFIAPUBFUN isize_t msg_default_dup_xtra(msg_header_t const *header, isize_t offset);
SOFIAPUBFUN char *msg_default_dup_one(msg_header_t *dst,
msg_header_t const *src,
char *b,
isize_t xtra);
SOFIAPUBFUN issize_t msg_numeric_d(su_home_t *, msg_header_t *h, char *s, isize_t slen);
SOFIAPUBFUN issize_t msg_numeric_e(char [], isize_t, msg_header_t const *, int);
SOFIAPUBFUN issize_t msg_list_d(su_home_t *, msg_header_t *h, char *s, isize_t slen);
SOFIAPUBFUN issize_t msg_list_e(char [], isize_t, msg_header_t const *, int);
SOFIAPUBFUN isize_t msg_list_dup_xtra(msg_header_t const *h, isize_t offset);
SOFIAPUBFUN char *msg_list_dup_one(msg_header_t *dst,
msg_header_t const *src,
char *b, isize_t xtra);
SOFIAPUBFUN issize_t msg_generic_d(su_home_t *, msg_header_t *, char *, isize_t);
SOFIAPUBFUN issize_t msg_generic_e(char [], isize_t, msg_header_t const *, int);
SOFIAPUBFUN isize_t msg_generic_dup_xtra(msg_header_t const *h, isize_t offset);
SOFIAPUBFUN char *msg_generic_dup_one(msg_header_t *dst,
msg_header_t const *src,
char *b,
isize_t xtra);
SOFIAPUBFUN isize_t msg_unknown_dup_xtra(msg_header_t const *h, isize_t offset);
SOFIAPUBFUN char *msg_unknown_dup_one(msg_header_t *dst,
msg_header_t const *src,
char *b, isize_t xtra);
SOFIAPUBFUN isize_t msg_error_dup_xtra(msg_header_t const *h, isize_t offset);
SOFIAPUBFUN char *msg_error_dup_one(msg_header_t *dst,
msg_header_t const *src,
char *b, isize_t xtra);
SOFIAPUBFUN issize_t msg_payload_d(su_home_t *, msg_header_t *h, char *s, isize_t slen);
SOFIAPUBFUN issize_t msg_payload_e(char b[], isize_t bsiz, msg_header_t const *, int f);
SOFIAPUBFUN isize_t msg_payload_dup_xtra(msg_header_t const *h, isize_t offset);
SOFIAPUBFUN char *msg_payload_dup_one(msg_header_t *dst,
msg_header_t const *src,
char *b, isize_t xtra);
SOFIAPUBFUN issize_t msg_separator_d(su_home_t *, msg_header_t *, char *, isize_t);
SOFIAPUBFUN issize_t msg_separator_e(char [], isize_t, msg_header_t const *, int);
SOFIAPUBFUN issize_t msg_auth_d(su_home_t *, msg_header_t *h, char *s, isize_t slen);
SOFIAPUBFUN issize_t msg_auth_e(char b[], isize_t bsiz, msg_header_t const *h, int f);
SOFIAPUBFUN isize_t msg_auth_dup_xtra(msg_header_t const *h, isize_t offset);
SOFIAPUBFUN char *msg_auth_dup_one(msg_header_t *dst, msg_header_t const *src,
char *b, isize_t xtra);
/* ---------------------------------------------------------------------------
* 2) Macros and prototypes for building header decoding/encoding functions.
*/
#define MSG_HEADER_DATA(h) ((char *)(h) + (h)->sh_class->hc_size)
#define MSG_HEADER_TEST(h) ((h) && (h)->sh_class)
su_inline void *msg_header_data(msg_frg_t *h);
SOFIAPUBFUN int msg_hostport_d(char **ss,
char const **return_host,
char const **return_port);
SOFIAPUBFUN issize_t msg_token_d(char **ss, char const **return_token);
SOFIAPUBFUN issize_t msg_uint32_d(char **ss, uint32_t *return_value);
SOFIAPUBFUN issize_t msg_comment_d(char **ss, char const **return_comment);
SOFIAPUBFUN issize_t msg_quoted_d(char **ss, char **return_unquoted);
SOFIAPUBFUN issize_t msg_unquoted_e(char *b, isize_t bsiz, char const *s);
SOFIAPUBFUN issize_t msg_parse_next_field(su_home_t *home, msg_header_t *prev,
char *s, isize_t slen);
#define MSG_TERM_E(p, e) ((p) < (e) ? (p)[0] = '\0' : '\0')
#define MSG_CHAR_E(p, e, c) (++(p) < (e) ? ((p)[-1]=(c)) : (c))
#define MSG_STRING_LEN(s, sep_size) ((s) ? (strlen(s) + sep_size) : 0)
#define MSG_STRING_E(p, e, s) do { \
size_t _n = strlen(s); if (p + _n+1 < e) memcpy(p, s, _n+1); p+= _n; } while(0)
#define MSG_STRING_DUP(p, d, s) \
(void)((s)?((p)=(char*)memccpy((void *)((d)=(char*)p),(s),0,INT_MAX))\
:((d)=NULL))
/* Solaris has broken memccpy - it considers last argument as signed */
#define MSG_STRING_SIZE(s) ((s) ? (strlen(s) + 1) : 0)
SOFIAPUBFUN issize_t msg_commalist_d(su_home_t *, char **ss,
msg_param_t **append_list,
issize_t (*scanner)(char *s));
SOFIAPUBFUN issize_t msg_token_scan(char *start);
SOFIAPUBFUN issize_t msg_attribute_value_scanner(char *s);
SOFIAPUBFUN issize_t msg_any_list_d(su_home_t *, char **ss,
msg_param_t **append_list,
issize_t (*scanner)(char *s),
int sep);
#define MSG_COMMALIST_E(b, end, params, compact) do { \
char const * const *p_; char const * c_ = ""; \
for (p_ = (params); p_ && *p_; p_++, c_ = (compact ? "," : ", ")) \
{ MSG_STRING_E(b, (end), c_); MSG_STRING_E(b, (end), *p_); } \
} while(0)
/* Parameter lists */
SOFIAPUBFUN int msg_header_update_params(msg_common_t *h, int clear);
#define MSG_PARAM_MATCH(v, s, name) \
(strncasecmp(s, name "=", sizeof(name)) == 0 ? (v = s + sizeof(name)) : NULL)
#define MSG_PARAM_MATCH_P(v, s, name) \
((strncasecmp((s), name "", sizeof(name) - 1) == 0 && \
((s)[sizeof(name) - 1] == '=' || (s)[sizeof(name) - 1] == '\0')) ? \
((v) = 1) : 0)
#define MSG_PARAMS_NUM(n) (((n) + MSG_N_PARAMS - 1) & (size_t)(0 - MSG_N_PARAMS))
SOFIAPUBFUN issize_t msg_avlist_d(su_home_t *, char **ss,
msg_param_t const **return_params);
SOFIAPUBFUN issize_t msg_params_d(su_home_t *, char **ss,
msg_param_t const **return_params);
SOFIAPUBFUN isize_t msg_params_e(char b[], isize_t bsiz, msg_param_t const pparams[]);
SOFIAPUBFUN issize_t msg_params_join(su_home_t *,
msg_param_t **dst,
msg_param_t const *src,
unsigned prune,
int dup);
#define MSG_PARAMS_E(b, end, params, flags) \
(b) += msg_params_e((b), (size_t)((b) < (end) ? (end) - (b) : 0), (params))
#define MSG_PARAMS_SIZE(rv, params) (rv = msg_params_dup_xtra(params, rv))
SOFIAPUBFUN char *msg_params_dup(msg_param_t const **d, msg_param_t const *s,
char *b, isize_t xtra);
su_inline isize_t msg_params_count(msg_param_t const params[])
{
if (params) {
size_t n;
for (n = 0; params[n]; n++)
;
return n;
}
else {
return 0;
}
}
su_inline isize_t msg_params_dup_xtra(msg_param_t const params[], isize_t offset)
{
isize_t n = msg_params_count(params);
if (n) {
MSG_STRUCT_SIZE_ALIGN(offset);
offset += MSG_PARAMS_NUM(n + 1) * sizeof(msg_param_t);
for (n = 0; params[n]; n++)
offset += strlen(params[n]) + 1;
}
return offset;
}
su_inline void *msg_header_data(msg_frg_t *h)
{
if (h)
return (char *)h + h->h_class->hc_size;
else
return NULL;
}
SOFIA_END_DECLS
#endif
msg_auth_d
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_payload_e
msg_print_f msg_payload_e
Print a message payload.
Definition msg_protos.h:815
msg_payload_d
msg_parse_f msg_payload_d
Parse a message payload.
Definition msg_protos.h:812
msg_separator_e
msg_print_f msg_separator_e
Print a separator line between headers and body.
Definition msg_protos.h:566
msg_separator_d
msg_parse_f msg_separator_d
Parse a separator line between headers and body.
Definition msg_protos.h:563
msg_header.h
Message headers.
msg_generic_dup_one
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
msg_params_dup_xtra
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
msg_token_scan
issize_t msg_token_scan(char *start)
Token scanner for msg_commalist_d() accepting also empty entries.
Definition msg_parser_util.c:593
msg_default_dup_xtra
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
msg_extract_payload
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
msg_generic_dup_xtra
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
msg_parse_next_field
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
msg_firstline_d
int msg_firstline_d(char *s, char **ss2, char **ss3)
Parse first line.
Definition msg_parser_util.c:66
msg_auth_dup_one
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
msg_params_join
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
msg_default_dup_one
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
msg_header_update_params
int msg_header_update_params(msg_common_t *h, int clear)
Update shortcuts to parameter values.
Definition msg_parser_util.c:1106
MSG_PARAMS_NUM
#define MSG_PARAMS_NUM(n)
Calculate allocated number of items in parameter list.
Definition msg_parser.h:244
msg_token_d
issize_t msg_token_d(char **ss, char const **return_token)
Parse a token.
Definition msg_parser_util.c:106
msg_extract_separator
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
msg_params_count
isize_t msg_params_count(msg_param_t const params[])
Count number of parameters in the list.
Definition msg_parser.h:276
msg_header_data
void * msg_header_data(msg_frg_t *h)
Return pointer to extra data after header structure.
Definition msg_parser.h:303
msg_attribute_value_scanner
issize_t msg_attribute_value_scanner(char *s)
Scan an attribute (name [= value]) pair.
Definition msg_parser_util.c:290
msg_quoted_d
issize_t msg_quoted_d(char **ss, char **return_unquoted)
Parse a quoted string.
Definition msg_parser_util.c:686
msg_unquoted_e
issize_t msg_unquoted_e(char *b, isize_t bsiz, char const *s)
Quote string.
Definition msg_parser_util.c:1786
msg_generic_e
issize_t msg_generic_e(char[], isize_t, msg_header_t const *, int)
Encode a generic header.
Definition msg_generic.c:82
msg_hostport_d
int msg_hostport_d(char **ss, char const **return_host, char const **return_port)
Parse host[":"port] pair.
Definition msg_parser_util.c:755
msg_comment_d
issize_t msg_comment_d(char **ss, char const **return_comment)
Parse a comment.
Definition msg_parser_util.c:654
msg_avlist_d
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
msg_extract_header
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
msg_params_d
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
msg_uint32_d
issize_t msg_uint32_d(char **ss, uint32_t *return_value)
Parse a 32-bit unsigned int.
Definition msg_parser_util.c:129
msg_generic_d
issize_t msg_generic_d(su_home_t *, msg_header_t *, char *, isize_t)
Parse a generic header.
Definition msg_generic.c:66
msg_params_e
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
msg_params_dup
char * msg_params_dup(msg_param_t const **d, msg_param_t const *s, char *b, isize_t xtra)
Duplicate a parameter list.
msg_commalist_d
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
msg_any_list_d
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_header_t
MSG_HDR_T msg_header_t
Any protocol-specific header object.
Definition msg_types.h:87
msg_t
struct msg_s msg_t
Message object.
Definition msg_types.h:54
msg_common_t
struct msg_common_s msg_common_t
Common part of header.
Definition msg_types.h:89
msg_pub_t
MSG_PUB_T msg_pub_t
Public protocol-specific message structure for accessing the message.
Definition msg_types.h:81
msg_common_s::h_class
msg_hclass_t * h_class
Header class.
Definition msg_types.h:114
su_alloc.h
su_home_t
SU_HOME_T su_home_t
SOFIAPUBFUN
#define SOFIAPUBFUN
su_inline
#define su_inline
uint32_t
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.