Asterisk - The Open Source Telephony Project
18.5.0
|
sip request parsing functions and unit tests More...
#include "asterisk.h"
#include "include/sip.h"
#include "include/sip_utils.h"
#include "include/reqresp_parser.h"
Go to the source code of this file.
Macros | |
#define | URI_CMP_MATCH 0 |
#define | URI_CMP_NOMATCH 1 |
Functions | |
AST_TEST_DEFINE (sip_parse_uri_full_test) | |
AST_TEST_DEFINE (sip_parse_uri_test) | |
AST_TEST_DEFINE (get_calleridname_test) | |
AST_TEST_DEFINE (get_name_and_number_test) | |
AST_TEST_DEFINE (get_in_brackets_test) | |
AST_TEST_DEFINE (parse_name_andor_addr_test) | |
AST_TEST_DEFINE (parse_contact_header_test) | |
AST_TEST_DEFINE (sip_parse_options_test) | |
AST_TEST_DEFINE (sip_uri_cmp_test) | |
AST_TEST_DEFINE (parse_via_test) | |
void | free_via (struct sip_via *v) |
const char * | get_calleridname (const char *input, char *output, size_t outputsize) |
Get caller id name from SIP headers, copy into output buffer. More... | |
int | get_comma (char *in, char **out) |
Parse all contact header contacts. More... | |
char * | get_in_brackets (char *tmp) |
Pick out text in brackets from character string. More... | |
int | get_in_brackets_const (const char *src, const char **start, int *length) |
Get text in brackets on a const without copy. More... | |
int | get_in_brackets_full (char *tmp, char **out, char **residue) |
Get text in brackets and any trailing residue. More... | |
int | get_name_and_number (const char *hdr, char **name, char **number) |
Get name and number from sip header. More... | |
int | parse_contact_header (char *contactheader, struct contactliststruct *contactlist) |
int | parse_name_andor_addr (char *uri, const char *scheme, char **name, char **user, char **pass, char **hostport, struct uriparams *params, char **headers, char **residue) |
Parse the ABNF structure name-andor-addr = name-addr / addr-spec into its components and return any trailing message-header parameters. More... | |
unsigned int | parse_sip_options (const char *options, char *unsupported, size_t unsupported_len) |
Parse supported header in incoming packet. More... | |
int | parse_uri (char *uri, const char *scheme, char **user, char **pass, char **hostport, char **transport) |
parses a URI in its components. More... | |
int | parse_uri_full (char *uri, const char *scheme, char **user, char **pass, char **hostport, struct uriparams *params, char **headers, char **residue) |
| |
struct sip_via * | parse_via (const char *header) |
Parse a Via header. More... | |
void | sip_reqresp_parser_exit (void) |
Free resources used by request and response parser. More... | |
int | sip_reqresp_parser_init (void) |
initialize request and response parser data More... | |
void | sip_request_parser_register_tests (void) |
register request parsing tests More... | |
void | sip_request_parser_unregister_tests (void) |
unregister request parsing tests More... | |
int | sip_uri_cmp (const char *input1, const char *input2) |
Compare two URIs as described in RFC 3261 Section 19.1.4. More... | |
static int | sip_uri_domain_cmp (const char *host1, const char *host2) |
Compare domain sections of SIP URIs. More... | |
static int | sip_uri_headers_cmp (const char *input1, const char *input2) |
helper routine for sip_uri_cmp to compare URI headers More... | |
static int | sip_uri_params_cmp (const char *input1, const char *input2) |
helper routine for sip_uri_cmp to compare URI parameters More... | |
Variables | |
locale_t | c_locale |
sip request parsing functions and unit tests
Definition in file reqresp_parser.c.
#define URI_CMP_MATCH 0 |
Definition at line 2257 of file reqresp_parser.c.
Referenced by AST_TEST_DEFINE().
#define URI_CMP_NOMATCH 1 |
Definition at line 2258 of file reqresp_parser.c.
Referenced by AST_TEST_DEFINE().
AST_TEST_DEFINE | ( | sip_parse_uri_full_test | ) |
Definition at line 260 of file reqresp_parser.c.
References ast_copy_string(), AST_LIST_ENTRY, AST_LIST_HEAD_NOLOCK(), AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, desc, sip_to_pjsip::info(), uriparams::lr, uriparams::maddr, uriparams::method, NULL, parse_uri_full(), pass, TEST_EXECUTE, TEST_INIT, uriparams::transport, uriparams::ttl, uriparams::user, and user.
AST_TEST_DEFINE | ( | sip_parse_uri_test | ) |
Definition at line 532 of file reqresp_parser.c.
References ast_strlen_zero, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), name, NULL, parse_uri(), pass, TEST_EXECUTE, TEST_INIT, and uriparams::transport.
AST_TEST_DEFINE | ( | get_calleridname_test | ) |
Definition at line 821 of file reqresp_parser.c.
References AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, get_calleridname(), sip_to_pjsip::info(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | get_name_and_number_test | ) |
Definition at line 946 of file reqresp_parser.c.
References ast_free, ast_strlen_zero, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, get_name_and_number(), sip_to_pjsip::info(), name, NULL, TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | get_in_brackets_test | ) |
Definition at line 1184 of file reqresp_parser.c.
References AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, get_in_brackets(), sip_to_pjsip::info(), NULL, TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | parse_name_andor_addr_test | ) |
Definition at line 1307 of file reqresp_parser.c.
References ast_copy_string(), AST_LIST_ENTRY, AST_LIST_HEAD_NOLOCK(), AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, desc, sip_to_pjsip::info(), uriparams::lr, uriparams::maddr, uriparams::method, name, NULL, parse_name_andor_addr(), pass, TEST_EXECUTE, TEST_INIT, uriparams::transport, uriparams::ttl, uriparams::user, and user.
AST_TEST_DEFINE | ( | parse_contact_header_test | ) |
Definition at line 1534 of file reqresp_parser.c.
References ast_copy_string(), ast_free, AST_LIST_ENTRY, AST_LIST_FIRST, AST_LIST_HEAD_NOLOCK(), AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_NEXT, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, desc, contact::expires, contact::headers, contact::hostport, sip_to_pjsip::info(), uriparams::lr, contact::name, NULL, contact::params, parse_contact_header(), contact::pass, contact::q, TEST_EXECUTE, TEST_INIT, uriparams::transport, uriparams::ttl, and contact::user.
AST_TEST_DEFINE | ( | sip_parse_options_test | ) |
Definition at line 1768 of file reqresp_parser.c.
References ARRAY_LEN, AST_LIST_ENTRY, AST_LIST_HEAD_NOLOCK(), AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), name, NULL, parse_sip_options(), SIP_OPT_REPLACES, SIP_OPT_TIMER, SIP_OPT_UNKNOWN, TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | sip_uri_cmp_test | ) |
Definition at line 2261 of file reqresp_parser.c.
References ARRAY_LEN, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), NULL, sip_uri_cmp(), TEST_EXECUTE, TEST_INIT, test_res, URI_CMP_MATCH, and URI_CMP_NOMATCH.
AST_TEST_DEFINE | ( | parse_via_test | ) |
Definition at line 2465 of file reqresp_parser.c.
References AST_LIST_ENTRY, AST_LIST_HEAD_NOLOCK(), AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_strlen_zero, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_via::branch, free_via(), in, sip_to_pjsip::info(), sip_via::maddr, parse_via(), sip_via::port, sip_via::protocol, sip_via::sent_by, TEST_EXECUTE, TEST_INIT, sip_via::ttl, and sip_via::via.
void free_via | ( | struct sip_via * | v | ) |
Definition at line 2379 of file reqresp_parser.c.
References ast_free, and sip_via::via.
Referenced by __find_call(), __sip_alloc(), AST_TEST_DEFINE(), parse_via(), and process_via().
const char* get_calleridname | ( | const char * | input, |
char * | output, | ||
size_t | outputsize | ||
) |
Get caller id name from SIP headers, copy into output buffer.
input | string pointer placed after display-name field if possible |
Definition at line 695 of file reqresp_parser.c.
References ast_log, ast_skip_blanks(), input(), and LOG_WARNING.
Referenced by AST_TEST_DEFINE(), check_user_full(), get_name_and_number(), parse_name_andor_addr(), and receive_message().
int get_comma | ( | char * | parse, |
char ** | out | ||
) |
Parse all contact header contacts.
0 | success |
-1 | failure |
1 | all contacts (star) |
Definition at line 1438 of file reqresp_parser.c.
References ast_log, c, find_closing_quote(), in, LOG_WARNING, NULL, and parse().
Referenced by parse_contact_header().
char* get_in_brackets | ( | char * | tmp | ) |
Pick out text in brackets from character string.
tmp | input string that will be modified |
Examples:
* "foo" <bar> valid input, returns bar * foo returns the whole string * < "foo ... > returns the string between brackets * < "foo... bogus (missing closing bracket), returns the whole string *
Definition at line 1173 of file reqresp_parser.c.
References get_in_brackets_full(), NULL, out, and tmp().
Referenced by AST_TEST_DEFINE(), check_user_full(), extract_uri(), get_also_info(), get_destination(), get_domain(), get_name_and_number(), get_pai(), get_rdnis(), get_refer_info(), handle_cc_notify(), parse_moved_contact(), parse_ok_contact(), parse_register_contact(), receive_message(), register_verify(), reqprep(), sip_get_cc_information(), sip_msg_send(), transmit_refer(), transmit_state_notify(), uac_sips_contact(), and uas_sips_contact().
int get_in_brackets_const | ( | const char * | src, |
const char ** | start, | ||
int * | length | ||
) |
Get text in brackets on a const without copy.
src | String to search | |
[out] | start | Set to first character inside left bracket. |
[out] | length | Set to lenght of string inside brackets |
0 | success |
-1 | failure |
1 | no brackets so got all |
Definition at line 1052 of file reqresp_parser.c.
References ast_log, ast_strlen_zero, find_closing_quote(), LOG_WARNING, NULL, and parse().
Referenced by build_route(), and sip_route_process_header().
int get_in_brackets_full | ( | char * | tmp, |
char ** | out, | ||
char ** | residue | ||
) |
Get text in brackets and any trailing residue.
0 | success |
-1 | failure |
1 | no brackets so got all |
Definition at line 1105 of file reqresp_parser.c.
References ast_log, ast_strlen_zero, find_closing_quote(), LOG_WARNING, NULL, parse(), and tmp().
Referenced by get_in_brackets(), and parse_name_andor_addr().
int get_name_and_number | ( | const char * | hdr, |
char ** | name, | ||
char ** | number | ||
) |
Get name and number from sip header.
0 | success |
-1 | failure |
Definition at line 905 of file reqresp_parser.c.
References ast_copy_string(), ast_log, ast_strdup, ast_strlen_zero, ast_uri_decode(), ast_uri_sip_user, dummy(), get_calleridname(), get_in_brackets(), LOG_ERROR, NULL, and parse_uri().
Referenced by AST_TEST_DEFINE(), change_redirecting_information(), and get_pai().
int parse_contact_header | ( | char * | contactheader, |
struct contactliststruct * | contactlist | ||
) |
Definition at line 1475 of file reqresp_parser.c.
References ast_calloc, AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, contact::expires, get_comma(), contact::headers, contact::hostport, last, contact::name, NULL, contact::params, parse_name_andor_addr(), contact::pass, contact::q, contact::user, and value.
Referenced by AST_TEST_DEFINE().
int parse_name_andor_addr | ( | char * | uri, |
const char * | scheme, | ||
char ** | name, | ||
char ** | user, | ||
char ** | pass, | ||
char ** | domain, | ||
struct uriparams * | params, | ||
char ** | headers, | ||
char ** | remander | ||
) |
Parse the ABNF structure name-andor-addr = name-addr / addr-spec into its components and return any trailing message-header parameters.
0 | success |
-1 | failure |
Definition at line 1262 of file reqresp_parser.c.
References buf, get_calleridname(), get_in_brackets_full(), NULL, and parse_uri_full().
Referenced by AST_TEST_DEFINE(), and parse_contact_header().
unsigned int parse_sip_options | ( | const char * | options, |
char * | unsupported, | ||
size_t | unsupported_len | ||
) |
Parse supported header in incoming packet.
This function parses through the options parameters and builds a bit field representing all the SIP options in that field. When an item is found that is not supported, it is copied to the unsupported out buffer.
options | list |
unsupported | out buffer (optional) |
unsupported_len | out buffer length (optional) |
Definition at line 1693 of file reqresp_parser.c.
References ARRAY_LEN, ast_copy_string(), ast_debug, ast_strdupa, ast_strip(), ast_strlen_zero, FALSE, cfsip_options::id, NULL, out, SIP_OPT_UNKNOWN, sip_options, SUPPORTED, text, and TRUE.
Referenced by AST_TEST_DEFINE(), handle_request_bye(), and handle_request_invite().
int parse_uri | ( | char * | uri, |
const char * | scheme, | ||
char ** | ret_name, | ||
char ** | pass, | ||
char ** | hostport, | ||
char ** | transport | ||
) |
parses a URI in its components.
0 | on success |
-1 | on error. |
* general form we are expecting is sip:user:password;user-parameters@host:port;uri-parameters?headers *
Definition at line 517 of file reqresp_parser.c.
References NULL, parse_uri_full(), and uriparams::transport.
Referenced by AST_TEST_DEFINE(), check_peer_ok(), get_name_and_number(), parse_uri_legacy_check(), and sip_msg_send().
int parse_uri_full | ( | char * | uri, |
const char * | scheme, | ||
char ** | user, | ||
char ** | pass, | ||
char ** | hostport, | ||
struct uriparams * | params, | ||
char ** | headers, | ||
char ** | residue | ||
) |
parses a URI in to all of its components and any trailing residue
Definition at line 37 of file reqresp_parser.c.
References ast_debug, ast_strdupa, ast_strlen_zero, c, error(), uriparams::lr, uriparams::maddr, uriparams::method, NULL, strsep(), uriparams::transport, uriparams::ttl, uriparams::user, and value.
Referenced by AST_TEST_DEFINE(), parse_name_andor_addr(), and parse_uri().
struct sip_via* parse_via | ( | const char * | header | ) |
Parse a Via header.
This function parses the Via header and processes it according to section 18.2 of RFC 3261 and RFC 3581. Since we don't have a transport layer, we only care about the maddr and ttl parms. The received and rport params are not parsed.
Definition at line 2389 of file reqresp_parser.c.
References ast_calloc, ast_log, ast_skip_blanks(), ast_strdup, ast_strlen_zero, sip_via::branch, c, free_via(), LOG_ERROR, sip_via::maddr, NULL, sip_via::port, sip_via::protocol, sip_via::sent_by, strsep(), sip_via::ttl, and sip_via::via.
Referenced by __find_call(), __sip_alloc(), AST_TEST_DEFINE(), and process_via().
void sip_reqresp_parser_exit | ( | void | ) |
Free resources used by request and response parser.
Definition at line 2682 of file reqresp_parser.c.
References c_locale, and NULL.
Referenced by unload_module().
int sip_reqresp_parser_init | ( | void | ) |
initialize request and response parser data
0 | Success |
-1 | Failure |
Definition at line 2671 of file reqresp_parser.c.
References c_locale, and NULL.
Referenced by load_module().
void sip_request_parser_register_tests | ( | void | ) |
register request parsing tests
Definition at line 2644 of file reqresp_parser.c.
References AST_TEST_REGISTER.
Referenced by sip_register_tests().
void sip_request_parser_unregister_tests | ( | void | ) |
unregister request parsing tests
Definition at line 2657 of file reqresp_parser.c.
References AST_TEST_UNREGISTER.
Referenced by sip_unregister_tests().
int sip_uri_cmp | ( | const char * | input1, |
const char * | input2 | ||
) |
Compare two URIs as described in RFC 3261 Section 19.1.4.
input1 | First URI |
input2 | Second URI |
0 | URIs match |
nonzero | URIs do not match or one or both is malformed |
Definition at line 2153 of file reqresp_parser.c.
References ast_strdupa, ast_strlen_zero, ast_uri_decode(), ast_uri_sip_user, S_OR, sip_uri_domain_cmp(), sip_uri_headers_cmp(), sip_uri_params_cmp(), and strsep().
Referenced by AST_TEST_DEFINE(), find_by_notify_uri_helper(), find_by_subscribe_uri_helper(), handle_request_invite(), and match_req_to_dialog().
|
static |
Compare domain sections of SIP URIs.
For hostnames, a case insensitive string comparison is used. For IP addresses, a binary comparison is used. This is mainly because IPv6 addresses have many ways of writing the same address.
For specifics about IP address comparison, see the following document: http://tools.ietf.org/html/draft-ietf-sip-ipv6-abnf-fix-05
host1 | The domain from the first URI |
host2 | THe domain from the second URI |
0 | The domains match |
nonzero | The domains do not match |
Definition at line 2115 of file reqresp_parser.c.
References ast_sockaddr_cmp(), ast_sockaddr_parse(), and c_locale.
Referenced by sip_uri_cmp().
|
static |
helper routine for sip_uri_cmp to compare URI headers
This takes the headers from two SIP URIs and determines if the URIs match. The rules for headers is simple. If a header appears in one URI, then it must also appear in the other URI. The order in which the headers appear does not matter.
input1 | Headers from URI 1 |
input2 | Headers from URI 2 |
0 | URI headers match |
nonzero | URI headers do not match |
Definition at line 2050 of file reqresp_parser.c.
References ast_strdupa, ast_strlen_zero, NULL, strcasestr(), and strsep().
Referenced by sip_uri_cmp().
|
static |
helper routine for sip_uri_cmp to compare URI parameters
This takes the parameters from two SIP URIs and determines if the URIs match. The rules for parameters suck. Here's a breakdown
input1 | Parameters from URI 1 |
input2 | Parameters from URI 2 |
0 | URIs' parameters match |
nonzero | URIs' parameters do not match |
Definition at line 1924 of file reqresp_parser.c.
References ast_strdupa, ast_strlen_zero, NULL, and strsep().
Referenced by sip_uri_cmp().
locale_t c_locale |
Definition at line 33 of file reqresp_parser.c.
Referenced by sip_reqresp_parser_exit(), sip_reqresp_parser_init(), and sip_uri_domain_cmp().