43 char *userpart =
NULL, *hostpart =
NULL;
98 if ((hostpart = strrchr(buf,
'@'))) {
104 ast_log(
LOG_WARNING,
"Format for registration is [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] at line %d\n", lineno);
115 pre1.userpart = pre1.peer;
127 pre2.userpart = pre2.transport;
128 pre2.transport =
NULL;
130 pre2.transport[strlen(pre2.transport) - 1] =
'\0';
134 ast_log(
LOG_WARNING,
"Format for registration is [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] at line %d\n", lineno);
215 if (user3.argc == 2) {
216 char *reorder = user3.domainport;
217 user3.domainport = user1.secret;
218 user1.secret = user3.authuser;
219 user3.authuser = reorder;
224 ast_log(
LOG_NOTICE,
"'%s' is not a valid port number on line %d of sip.conf. using default.\n", host3.port, lineno);
227 if (user3.domainport) {
228 if (!(domainport =
port_str2int(user3.domainport, 0))) {
229 ast_log(
LOG_NOTICE,
"'%s' is not a valid domain port number on line %d of sip.conf. using default.\n", user3.domainport, lineno);
234 if (!pre2.transport) {
236 }
else if (!strncasecmp(pre2.transport,
"tcp", 3)) {
238 }
else if (!strncasecmp(pre2.transport,
"tls", 3)) {
240 }
else if (!strncasecmp(pre2.transport,
"udp", 3)) {
244 ast_log(
LOG_NOTICE,
"'%.3s' is not a valid transport type on line %d of sip.conf. defaulting to udp.\n", pre2.transport, lineno);
275 #ifdef TEST_FRAMEWORK 281 const char *reg1 =
"name@domain";
282 const char *reg2 =
"name:pass@domain";
283 const char *reg3 =
"name@namedomain:pass:authuser@domain";
284 const char *reg4 =
"name@namedomain:pass:authuser@domain/extension";
285 const char *reg5 =
"tcp://name@namedomain:pass:authuser@domain/extension";
286 const char *reg6 =
"tls://name@namedomain:pass:authuser@domain/extension~111";
287 const char *reg7 =
"peer?tcp://name@namedomain:pass:authuser@domain:1234/extension~111";
288 const char *reg8 =
"peer?name@namedomain:pass:authuser@domain:1234/extension~111";
289 const char *reg9 =
"peer?name:pass:authuser:1234/extension~111";
290 const char *reg10 =
"@domin:1234";
291 const char *reg12 =
"name@namedomain:4321:pass:authuser@domain";
292 const char *reg13 =
"name@namedomain:4321::@domain";
296 info->name =
"sip_parse_register_line_test";
297 info->category =
"/channels/chan_sip/";
298 info->summary =
"tests sip register line parsing";
300 "Tests parsing of various register line configurations. " 301 "Verifies output matches expected behavior.";
317 strcmp(reg->
secret,
"") ||
322 reg->
refresh != default_expiry ||
323 reg->
expiry != default_expiry ||
346 strcmp(reg->
secret,
"pass") ||
351 reg->
refresh != default_expiry ||
352 reg->
expiry != default_expiry ||
374 strcmp(reg->
authuser,
"authuser") ||
375 strcmp(reg->
secret,
"pass") ||
380 reg->
refresh != default_expiry ||
381 reg->
expiry != default_expiry ||
399 strcmp(reg->
callback,
"extension") ||
403 strcmp(reg->
authuser,
"authuser") ||
404 strcmp(reg->
secret,
"pass") ||
409 reg->
refresh != default_expiry ||
410 reg->
expiry != default_expiry ||
428 strcmp(reg->
callback,
"extension") ||
432 strcmp(reg->
authuser,
"authuser") ||
433 strcmp(reg->
secret,
"pass") ||
438 reg->
refresh != default_expiry ||
439 reg->
expiry != default_expiry ||
457 strcmp(reg->
callback,
"extension") ||
461 strcmp(reg->
authuser,
"authuser") ||
462 strcmp(reg->
secret,
"pass") ||
486 strcmp(reg->
callback,
"extension") ||
490 strcmp(reg->
authuser,
"authuser") ||
491 strcmp(reg->
secret,
"pass") ||
515 strcmp(reg->
callback,
"extension") ||
519 strcmp(reg->
authuser,
"authuser") ||
520 strcmp(reg->
secret,
"pass") ||
544 "Test 9, missing domain, expected to fail but did not.\n");
555 "Test 10, missing user expected to fail but did not\n");
564 "Test 11, no registry object, expected to fail but did not.\n");
574 "Test 12, NULL register line expected to fail but did not.\n");
589 strcmp(reg->
authuser,
"authuser") ||
590 strcmp(reg->
secret,
"pass") ||
595 reg->
refresh != default_expiry ||
596 reg->
expiry != default_expiry ||
619 strcmp(reg->
secret,
"") ||
624 reg->
refresh != default_expiry ||
625 reg->
expiry != default_expiry ||
655 if ((*hostname = strstr(line,
"://"))) {
658 if (!strncasecmp(line,
"tcp", 3)) {
660 }
else if (!strncasecmp(line,
"tls", 3)) {
662 }
else if (!strncasecmp(line,
"udp", 3)) {
665 ast_log(
LOG_NOTICE,
"'%.3s' is not a valid transport type on line %d of sip.conf. defaulting to udp.\n", line, lineno);
667 ast_log(
LOG_NOTICE,
"'%.3s' is not a valid transport type in sip config. defaulting to udp.\n", line);
674 if ((line = strrchr(*hostname,
'@')))
690 if (!sscanf(port,
"%5d", portnum)) {
692 ast_log(
LOG_NOTICE,
"'%s' is not a valid port number on line %d of sip.conf. using default.\n", port, lineno);
694 ast_log(
LOG_NOTICE,
"'%s' is not a valid port number in sip config. using default.\n", port);
711 #ifdef TEST_FRAMEWORK 718 char host1[] =
"www.blah.com";
719 char host2[] =
"tcp://www.blah.com";
720 char host3[] =
"tls://10.10.10.10";
721 char host4[] =
"tls://10.10.10.10:1234";
722 char host5[] =
"10.10.10.10:1234";
726 info->name =
"sip_parse_host_line_test";
727 info->category =
"/channels/chan_sip/";
728 info->summary =
"tests sip.conf host line parsing";
730 "Tests parsing of various host line configurations. " 731 "Verifies output matches expected behavior.";
767 strcmp(host,
"10.10.10.10") ||
776 strcmp(host,
"10.10.10.10") ||
809 while ((
this =
strsep(&parse,
","))) {
816 }
else if (!strcasecmp(
this,
"yes")) {
827 }
else if (!strcasecmp(
this,
"auto_force_rport")) {
831 }
else if (!strcasecmp(
this,
"auto_comedia")) {
839 #ifdef TEST_FRAMEWORK 840 #define TEST_FORCE_RPORT 1 << 0 841 #define TEST_COMEDIA 1 << 1 842 #define TEST_AUTO_FORCE_RPORT 1 << 2 843 #define TEST_AUTO_COMEDIA 1 << 3 882 {
"auto_comedia,no,yes", 0 },
887 info->name =
"sip_parse_nat_test";
888 info->category =
"/channels/chan_sip/";
889 info->summary =
"tests sip.conf nat line parsing";
891 "Tests parsing of various nat line configurations. " 892 "Verifies output matches expected behavior.";
905 memset(mask, 0,
sizeof(mask));
Asterisk main include file. File version handling, generic pbx functions.
const ast_string_field hostname
const ast_string_field username
#define ast_test_flag(p, flag)
int sip_parse_register_line(struct sip_registry *reg, int default_expiry, const char *value, int lineno)
Parse register=> line in sip.conf.
#define ast_set_flag(p, flag)
#define AST_TEST_REGISTER(cb)
Registrations with other SIP proxies.
#define SIP_NAT_FORCE_RPORT
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
void sip_config_parser_register_tests(void)
SIP test registration.
#define ast_strlen_zero(foo)
#define TEST_AUTO_FORCE_RPORT
void sip_config_parser_unregister_tests(void)
SIP test registration.
const ast_string_field authuser
#define SIP_PAGE2_SYMMETRICRTP
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
#define STANDARD_TLS_PORT
Standard SIP TLS port from RFC 3261. DO NOT CHANGE THIS.
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
Splits a string into its host and port components.
#define STANDARD_SIP_PORT
Standard SIP unsecure port for UDP and TCP from RFC 3261. DO NOT CHANGE THIS.
static int match_nat_options(int val, struct ast_flags *flags)
#define ast_test_status_update(a, b, c...)
structure to hold extensions
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define AST_NONSTANDARD_RAW_ARGS(args, parse, sep)
static int default_expiry
#define TEST_AUTO_COMEDIA
#define AST_TEST_UNREGISTER(cb)
#define SIP_PAGE3_NAT_AUTO_RPORT
AST_TEST_DEFINE(sip_parse_register_line_test)
static void parse(struct mgcp_request *req)
void sip_parse_nat_option(const char *value, struct ast_flags *mask, struct ast_flags *flags)
Parse the comma-separated nat= option values.
sip.conf parser header file
structure to hold users read from users.conf
Structure used to handle boolean flags.
int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum ast_transport *transport)
parses a config line for a host with a transport
const ast_string_field secret
#define ast_clear_flag(p, flag)
#define SIP_PAGE3_NAT_AUTO_COMEDIA
char * strsep(char **str, const char *delims)
const ast_string_field peername
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"...
unsigned int port_str2int(const char *pt, unsigned int standard)
converts ascii port to int representation. If no pt buffer is provided or the pt has errors when bein...
const ast_string_field regdomain
static struct ast_str * hostname
const ast_string_field callback
enum ast_transport transport
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
#define AST_APP_ARG(name)
Define an application argument.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.