#include <sofia-sip/su_alloc.h>
#include <sofia-sip/msg_header.h>
#include <sofia-sip/bnf.h>
#include <sofia-sip/url.h>
Include dependency graph for msg_parser.h:
Go to the source code of this file.
Defines | |
#define | MSG_TERM_E(p, e) |
Terminate encoding. | |
#define | MSG_CHAR_E(p, e, c) |
Encode a character. | |
#define | MSG_STRING_LEN(s, sep_size) |
Calculate separator and string length. | |
#define | MSG_STRING_E(p, e, s) |
Encode a string. | |
#define | MSG_STRING_DUP(p, d, s) |
Duplicate string. | |
#define | MSG_STRING_SIZE(s) |
Calculate string size. | |
#define | MSG_COMMALIST_E(b, end, params, compact) |
Encode a comma-separated parameter list. | |
#define | MSG_PARAM_MATCH(v, s, name) |
Match a parameter with any value. | |
#define | MSG_PARAM_MATCH_P(v, s, name) |
Match a parameter with known value. | |
#define | MSG_PARAMS_NUM(n) |
Calculate allocated number of items in parameter list. | |
#define | MSG_PARAMS_E(b, end, params, flags) |
Encode a list of parameters. | |
#define | MSG_PARAMS_SIZE(rv, params) |
Calculate extra size of parametes. | |
Functions | |
SOFIAPUBFUN int | msg_extract_header (msg_t *msg, msg_pub_t *mo, char b[], int bsiz, int eos) |
Extract a header. | |
SOFIAPUBFUN int | msg_extract_separator (msg_t *msg, msg_pub_t *mo, char b[], int bsiz, int eos) |
Extract a separator line. | |
SOFIAPUBFUN int | msg_extract_payload (msg_t *msg, msg_pub_t *mo, msg_header_t **return_payload, unsigned body_len, char b[], int bsiz, int eos) |
Extract a message body of body_len bytes. | |
SOFIAPUBFUN int | msg_firstline_d (char *s, char **ss2, char **ss3) |
Parse first line. | |
SOFIAPUBFUN int | msg_default_dup_xtra (msg_header_t const *header, int offset) |
Calculate extra size of a plain header. | |
SOFIAPUBFUN char * | msg_default_dup_one (msg_header_t *dst, msg_header_t const *src, char *b, int xtra) |
Duplicate a header object without external references. | |
SOFIAPUBFUN int | msg_generic_d (su_home_t *, msg_header_t *, char *, int n) |
Parse a generic header. | |
SOFIAPUBFUN int | msg_generic_e (char[], int, msg_header_t const *, int) |
Encode a generic header. | |
SOFIAPUBFUN int | msg_generic_dup_xtra (msg_header_t const *h, int offset) |
Calculate the size of strings associated with a msg_generic_t object. | |
SOFIAPUBFUN char * | msg_generic_dup_one (msg_header_t *dst, msg_header_t const *src, char *b, int xtra) |
Duplicate one msg_generic_t object. | |
SOFIAPUBFUN int | msg_payload_d (su_home_t *, msg_header_t *h, char *s, int slen) |
Parse payload. | |
SOFIAPUBFUN int | msg_separator_d (su_home_t *, msg_header_t *, char *, int) |
Parse a separator line. | |
SOFIAPUBFUN int | msg_separator_e (char[], int, msg_header_t const *, int) |
Encode a separator line. | |
SOFIAPUBFUN int | msg_auth_d (su_home_t *, msg_header_t *h, char *s, int slen) |
Parse security headers. | |
SOFIAPUBFUN char * | msg_auth_dup_one (msg_header_t *dst, msg_header_t const *src, char *b, int xtra) |
Duplicate one msg_auth_t object. | |
void * | msg_header_data (msg_frg_t *h) |
Return pointer to extra data after header structure. | |
SOFIAPUBFUN int | msg_hostport_d (char **ss, char const **return_host, char const **return_port) |
Parse host[":"port] pair. | |
SOFIAPUBFUN int | msg_token_d (char **ss, char const **return_token) |
Parse a token. | |
SOFIAPUBFUN int | msg_uint32_d (char **ss, uint32_t *return_value) |
Parse a 32-bit unsigned int. | |
SOFIAPUBFUN int | msg_comment_d (char **ss, char const **return_comment) |
Parse a comment. | |
SOFIAPUBFUN int | msg_quoted_d (char **ss, char **return_unquoted) |
Parse a quoted string. | |
SOFIAPUBFUN int | msg_unquoted_e (char *b, int bsiz, char const *s) |
Quote string. | |
SOFIAPUBFUN int | msg_commalist_d (su_home_t *, char **ss, msg_param_t **return_list, int(*scanner)(char *s)) |
Parse a comma-separated list. | |
SOFIAPUBFUN int | msg_token_scan (char *start) |
Token scanner for msg_commalist_d() accepting also empty entries. | |
SOFIAPUBFUN int | msg_attribute_value_scanner (char *s) |
Scan an attribute [= value] pair. | |
SOFIAPUBFUN int | msg_any_list_d (su_home_t *, char **ss, msg_param_t **retval, int(*scanner)(char *s), int sep) |
Parse any list. | |
SOFIAPUBFUN int | msg_header_update_params (msg_common_t *h, int clear) |
Update all parameters. | |
SOFIAPUBFUN int | msg_avlist_d (su_home_t *, char **ss, msg_param_t const **return_params) |
Parse a semicolong-separated attribute-value list. | |
SOFIAPUBFUN int | msg_params_d (su_home_t *, char **ss, msg_param_t const **return_params) |
Parse a semicolon-separated parameter list starting with semicolon. | |
SOFIAPUBFUN int | msg_params_e (char b[], int bsiz, msg_param_t const pparams[]) |
Encode a list of parameters. | |
SOFIAPUBFUN int | msg_params_join (su_home_t *, msg_param_t **dst, msg_param_t const *src, unsigned prune, int dup) |
Join list of parameters. | |
SOFIAPUBFUN char * | msg_params_dup (msg_param_t const **d, msg_param_t const *s, char *b, int xtra) |
Duplicate a parameter list. | |
int | msg_params_count (msg_param_t const params[]) |
Count number of parameters in the list. | |
int | msg_params_dup_xtra (msg_param_t const params[], int offset) |
Calculate memory size required by parameter list. |
SOFIAPUBFUN int msg_any_list_d | ( | su_home_t * | home, | |
char ** | ss, | |||
msg_param_t ** | return_list, | |||
int(*)(char *s) | scanner, | |||
int | sep | |||
) |
Parse any list.
Parses a list of items, separated by sep. The parsed string is passed in *ss, which is updated to point to the first non-linear-whitespace character after the list. The function modifies the string as it parses it.
A pointer to the resulting list is returned in the return-value parameter return_list. If there already is a list in return_list, new items are appended. Empty list items are ignored, and are not included in the list.
The function must be passed a scanning function scanner. The scanning function scans for a legitimate list item, for example, a token. It should also compact the list item, for instance, if the item consists of name=value
parameter definitions. The scanning function returns the length of the scanned item, including any linear whitespace after it.
home | memory home used to allocate memory for list pointers [IN] | |
ss | pointer to pointer to string to be parsed [IN/OUT] | |
return_list | return-value parameter for parsed list [IN/OUT] | |
sep | separator character [IN] | |
scanner | pointer to function scanning a single item (optional) [IN] |
0 | if successful. | |
-1 | upon an error. |
SOFIAPUBFUN int msg_avlist_d | ( | su_home_t * | home, | |
char ** | ss, | |||
msg_param_t const ** | return_list | |||
) |
Parse a semicolong-separated attribute-value list.
Parses an attribute-value list, which has syntax as follows:
av-list = (av-pair *(";" av-pair) av-pair = token ["=" ( value / quoted-string) ] ; optional value
home | pointer to a memory home [IN] | |
ss | pointer to string at the start of parameter list [IN/OUT] | |
return_list | return-value parameter for parsed list [IN/OUT] |
0 | if successful | |
-1 | upon an error |
SOFIAPUBFUN int msg_commalist_d | ( | su_home_t * | home, | |
char ** | ss, | |||
msg_param_t ** | return_list, | |||
int(*)(char *s) | scanner | |||
) |
Parse a comma-separated list.
Parses a comma-separated list. The parsed string is passed in *ss, which is updated to point to the first non-linear-whitespace character after the list. The function modifies the string as it parses it.
A pointer to the resulting list is returned in *retval. If there already is a list in *retval, new items are appended. Empty list items are ignored, and are not included in the list.
The function can be passed an optional scanning function. The scanning function scans for a legitimate list item, for example, a token. It also compacts the list item, for instance, if the item consists of name=value
parameter definitions. The scanning function returns the length of the scanned item, including any linear whitespace after it.
By default, the scanning function accepts tokens, quoted strings or separators (except comma, of course).
home | memory home used to allocate memory for list pointers [in] | |
ss | pointer to pointer to string to be parsed [in/out] | |
return_list | return-value parameter for parsed list [in/out] | |
scanner | pointer to function scanning a single item (optional) [in] |
0 | if successful. | |
-1 | upon an error. |
SOFIAPUBFUN int msg_comment_d | ( | char ** | ss, | |
char const ** | return_comment | |||
) |
Parse a comment.
Parses a multilevel comment. The comment assigned to return-value parameter return_comment is NUL-terminated. The string at return-value parameter ss is updated to point to first non-linear-whitespace character after the comment.
SOFIAPUBFUN char* msg_default_dup_one | ( | msg_header_t * | h, | |
msg_header_t const * | src, | |||
char * | b, | |||
int | xtra | |||
) |
Duplicate a header object without external references.
The function msg_default_dup_one()
copies the contents of header object src to h. The header object should not contain external references (pointers).
h | pointer to newly allocated header object | |
src | pointer to a header object to be duplicated | |
b | memory buffer used to copy (not used) | |
xtra | number bytes in buffer b (not used) |
msg_default_dup_one()
returns a pointer to the memory buffer b. SOFIAPUBFUN int msg_firstline_d | ( | char * | s, | |
char ** | return_part2, | |||
char ** | return_part3 | |||
) |
Parse first line.
Splits the first line from a message into three whitespace-separated parts.
SOFIAPUBFUN int msg_generic_d | ( | su_home_t * | home, | |
msg_header_t * | h, | |||
char * | s, | |||
int | slen | |||
) |
Parse a generic header.
The function msg_generic_d() parses a generic header structure.
home | memory home [IN] | |
h | header structure [IN/OUT] | |
s | string to be parsed [IN] | |
slen | length of the string [IN] |
0 | when successful, | |
-1 | upon an error. |
SOFIAPUBFUN int msg_generic_e | ( | char | b[], | |
int | bsiz, | |||
msg_header_t const * | h, | |||
int | flags | |||
) |
Encode a generic header.
The function msg_generic_e
encodes a generic header.
SOFIAPUBFUN int msg_hostport_d | ( | char ** | ss, | |
char const ** | return_host, | |||
char const ** | return_port | |||
) |
Parse host[":"port] pair.
Parses a host[":"port] pair. The caller passes function a pointer to a string via ss, and pointers to which parsed host and port are assigned via hhost and pport, respectively. The value-result parameter *pport must be initialized to default value (e.g., NULL).
ss | pointer to pointer to string to be parsed | |
return_host | value-result parameter for host | |
return_port | value-result parameter for port |
SOFIAPUBFUN int msg_params_d | ( | su_home_t * | home, | |
char ** | ss, | |||
msg_param_t const ** | return_list | |||
) |
Parse a semicolon-separated parameter list starting with semicolon.
Parse a parameter list, which has syntax as follows:
*(";" token [ "=" (token | quoted-string)]).
home | pointer to a memory home [IN] | |
ss | pointer to string at the start of parameter list [IN/OUT] | |
return_list | return-value parameter for the parsed list [IN/OUT] |
0 | if successful | |
-1 | upon an error |
SOFIAPUBFUN int msg_params_join | ( | su_home_t * | home, | |
msg_param_t ** | dst, | |||
msg_param_t const * | src, | |||
unsigned | prune, | |||
int | dup | |||
) |
Join list of parameters.
The function msg_params_join()
joins two parameter lists; the first list must have been created by msg_params_d()
or by msg_params_dup()
(or it may contain only NULL
).
home | memory home | |
dst | pointer to pointer to destination parameter list | |
src | source list | |
prune | prune duplicates | |
dup | duplicate parameters in src list |
0 | do not prune |
1 | prune parameters with identical names |
2 | case-insensitive values |
3 | case-sensitive values |
msg_params_join()
returns 0 if successful, or a negative value upon an error. SOFIAPUBFUN int msg_token_d | ( | char ** | ss, | |
char const ** | return_token | |||
) |
Parse a token.
Parses a token from string pointed by *ss. It stores the token value in return_token, and updates the ss to the end of token and possible whitespace.
SOFIAPUBFUN int msg_uint32_d | ( | char ** | ss, | |
uint32_t * | return_value | |||
) |
Parse a 32-bit unsigned int.
The function msg_uint32_d() parses a 32-bit unsigned integer in string pointed by *ss. It stores the value in return_token and updates the ss to the end of integer and possible whitespace.