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) |
char * | get_in_brackets (char *tmp) |
int | get_in_brackets_const (const char *src, const char **start, int *length) |
int | get_in_brackets_full (char *tmp, char **out, char **residue) |
int | get_name_and_number (const char *hdr, char **name, char **number) |
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) |
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) |
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) |
void | sip_reqresp_parser_exit (void) |
int | sip_reqresp_parser_init (void) |
void | sip_request_parser_register_tests (void) |
void | sip_request_parser_unregister_tests (void) |
int | sip_uri_cmp (const char *input1, const char *input2) |
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 2149 of file reqresp_parser.c.
Referenced by AST_TEST_DEFINE().
#define URI_CMP_NOMATCH 1 |
Definition at line 2150 of file reqresp_parser.c.
Referenced by AST_TEST_DEFINE().
AST_TEST_DEFINE | ( | sip_parse_uri_full_test | ) |
Definition at line 224 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, parse_uri_full(), pass, TEST_EXECUTE, TEST_INIT, and user.
AST_TEST_DEFINE | ( | sip_parse_uri_test | ) |
Definition at line 448 of file reqresp_parser.c.
References ast_strlen_zero(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, name, parse_uri(), pass, TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | get_calleridname_test | ) |
Definition at line 723 of file reqresp_parser.c.
References AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, get_calleridname(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | get_name_and_number_test | ) |
Definition at line 846 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(), name, TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | get_in_brackets_test | ) |
Definition at line 1082 of file reqresp_parser.c.
References AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, get_in_brackets(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | parse_name_andor_addr_test | ) |
Definition at line 1204 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, name, parse_name_andor_addr(), pass, TEST_EXECUTE, TEST_INIT, and user.
AST_TEST_DEFINE | ( | parse_contact_header_test | ) |
Definition at line 1429 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, parse_contact_header(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | sip_parse_options_test | ) |
Definition at line 1661 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, name, parse_sip_options(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | sip_uri_cmp_test | ) |
Definition at line 2152 of file reqresp_parser.c.
References ARRAY_LEN, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_uri_cmp(), TEST_EXECUTE, TEST_INIT, URI_CMP_MATCH, and URI_CMP_NOMATCH.
AST_TEST_DEFINE | ( | parse_via_test | ) |
Definition at line 2354 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, free_via(), parse_via(), TEST_EXECUTE, and TEST_INIT.
void free_via | ( | struct sip_via * | v | ) |
Definition at line 2269 of file reqresp_parser.c.
References ast_free.
Referenced by AST_TEST_DEFINE(), find_call(), parse_via(), process_via(), and sip_alloc().
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 598 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(), and parse_name_andor_addr().
int get_comma | ( | char * | in, |
char ** | out | ||
) |
Definition at line 1334 of file reqresp_parser.c.
References ast_log(), find_closing_quote(), LOG_WARNING, and parse().
Referenced by parse_contact_header().
char* get_in_brackets | ( | char * | tmp | ) |
Definition at line 1072 of file reqresp_parser.c.
References get_in_brackets_full().
Referenced by AST_TEST_DEFINE(), build_route(), 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(), register_verify(), reqprep(), sip_get_cc_information(), transmit_refer(), and transmit_state_notify().
int get_in_brackets_const | ( | const char * | src, |
const char ** | start, | ||
int * | length | ||
) |
Definition at line 951 of file reqresp_parser.c.
References ast_log(), ast_strlen_zero(), find_closing_quote(), LOG_WARNING, and parse().
Referenced by build_route().
int get_in_brackets_full | ( | char * | tmp, |
char ** | out, | ||
char ** | residue | ||
) |
Definition at line 1004 of file reqresp_parser.c.
References ast_log(), ast_strlen_zero(), find_closing_quote(), LOG_WARNING, and parse().
Referenced by get_in_brackets(), and parse_name_andor_addr().
int get_name_and_number | ( | const char * | hdr, |
char ** | name, | ||
char ** | number | ||
) |
Definition at line 806 of file reqresp_parser.c.
References ast_copy_string(), ast_log(), ast_strdup, ast_strlen_zero(), ast_uri_decode(), dummy(), get_calleridname(), get_in_brackets(), LOG_ERROR, 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 1371 of file reqresp_parser.c.
References ast_calloc, AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, get_comma(), last, parse_name_andor_addr(), and value.
Referenced by AST_TEST_DEFINE().
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 | ||
) |
Definition at line 1160 of file reqresp_parser.c.
References get_calleridname(), get_in_brackets_full(), 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.
option | list |
unsupported | out buffer (optional) |
unsupported | out buffer length (optional) |
Definition at line 1587 of file reqresp_parser.c.
References ARRAY_LEN, ast_copy_string(), ast_debug, ast_strdupa, ast_strip(), ast_strlen_zero(), FALSE, text, and TRUE.
Referenced by AST_TEST_DEFINE(), handle_request_bye(), and handle_request_invite().
int parse_uri | ( | char * | uri, |
const char * | scheme, | ||
char ** | user, | ||
char ** | pass, | ||
char ** | hostport, | ||
char ** | transport | ||
) |
Definition at line 434 of file reqresp_parser.c.
References parse_uri_full().
Referenced by AST_TEST_DEFINE(), get_name_and_number(), and parse_uri_legacy_check().
int parse_uri_full | ( | char * | uri, |
const char * | scheme, | ||
char ** | user, | ||
char ** | pass, | ||
char ** | hostport, | ||
struct uriparams * | params, | ||
char ** | headers, | ||
char ** | residue | ||
) |
Definition at line 39 of file reqresp_parser.c.
References ast_debug, ast_strdupa, ast_strlen_zero(), strsep(), and value.
Referenced by AST_TEST_DEFINE(), parse_name_andor_addr(), and parse_uri().
struct sip_via* parse_via | ( | const char * | header | ) |
Definition at line 2279 of file reqresp_parser.c.
References ast_calloc, ast_log(), ast_skip_blanks(), ast_strdup, ast_strlen_zero(), free_via(), LOG_ERROR, and strsep().
Referenced by AST_TEST_DEFINE(), find_call(), process_via(), and sip_alloc().
void sip_reqresp_parser_exit | ( | void | ) |
int sip_reqresp_parser_init | ( | void | ) |
void sip_request_parser_register_tests | ( | void | ) |
Definition at line 2532 of file reqresp_parser.c.
References AST_TEST_REGISTER.
Referenced by sip_register_tests().
void sip_request_parser_unregister_tests | ( | void | ) |
Definition at line 2545 of file reqresp_parser.c.
References AST_TEST_UNREGISTER.
Referenced by sip_unregister_tests().
int sip_uri_cmp | ( | const char * | input1, |
const char * | input2 | ||
) |
Definition at line 2045 of file reqresp_parser.c.
References ast_strdupa, ast_strlen_zero(), ast_uri_decode(), 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 2007 of file reqresp_parser.c.
References ast_sockaddr_cmp(), and ast_sockaddr_parse().
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 1942 of file reqresp_parser.c.
References ast_strdupa, ast_strlen_zero(), 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 1816 of file reqresp_parser.c.
References ast_strdupa, ast_strlen_zero(), and strsep().
Referenced by sip_uri_cmp().
locale_t c_locale |
Definition at line 35 of file reqresp_parser.c.