30 #include "include/sip.h"
31 #include "include/config_parser.h"
32 #include "include/sip_utils.h"
43 enum sip_transport transport = SIP_TRANSPORT_UDP;
45 char *userpart = NULL, *hostpart = NULL;
96 if ((hostpart = strrchr(buf,
'@'))) {
102 ast_log(
LOG_WARNING,
"Format for registration is [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] at line %d\n", lineno);
113 pre1.userpart = pre1.peer;
125 pre2.userpart = pre2.transport;
126 pre2.transport = NULL;
128 pre2.transport[strlen(pre2.transport) - 1] =
'\0';
132 ast_log(
LOG_WARNING,
"Format for registration is [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] at line %d\n", lineno);
213 if (user3.argc == 2) {
214 char *reorder = user3.domainport;
215 user3.domainport = user1.secret;
216 user1.secret = user3.authuser;
217 user3.authuser = reorder;
222 ast_log(
LOG_NOTICE,
"'%s' is not a valid port number on line %d of sip.conf. using default.\n", host3.port, lineno);
225 if (user3.domainport) {
226 if (!(domainport =
port_str2int(user3.domainport, 0))) {
227 ast_log(
LOG_NOTICE,
"'%s' is not a valid domain port number on line %d of sip.conf. using default.\n", user3.domainport, lineno);
232 if (!pre2.transport) {
233 transport = SIP_TRANSPORT_UDP;
234 }
else if (!strncasecmp(pre2.transport,
"tcp", 3)) {
235 transport = SIP_TRANSPORT_TCP;
236 }
else if (!strncasecmp(pre2.transport,
"tls", 3)) {
237 transport = SIP_TRANSPORT_TLS;
238 }
else if (!strncasecmp(pre2.transport,
"udp", 3)) {
239 transport = SIP_TRANSPORT_UDP;
241 transport = SIP_TRANSPORT_UDP;
242 ast_log(
LOG_NOTICE,
"'%.3s' is not a valid transport type on line %d of sip.conf. defaulting to udp.\n", pre2.transport, lineno);
247 if (transport == SIP_TRANSPORT_TLS) {
248 portnum = STANDARD_TLS_PORT;
250 portnum = STANDARD_SIP_PORT;
263 reg->transport = transport;
264 reg->timeout = reg->expire = -1;
265 reg->portno = portnum;
266 reg->regdomainport = domainport;
267 reg->callid_valid =
FALSE;
268 reg->ocseq = INITIAL_CSEQ;
277 struct sip_registry *reg;
279 const char *reg1 =
"name@domain";
280 const char *reg2 =
"name:pass@domain";
281 const char *reg3 =
"name@namedomain:pass:authuser@domain";
282 const char *reg4 =
"name@namedomain:pass:authuser@domain/extension";
283 const char *reg5 =
"tcp://name@namedomain:pass:authuser@domain/extension";
284 const char *reg6 =
"tls://name@namedomain:pass:authuser@domain/extension~111";
285 const char *reg7 =
"peer?tcp://name@namedomain:pass:authuser@domain:1234/extension~111";
286 const char *reg8 =
"peer?name@namedomain:pass:authuser@domain:1234/extension~111";
287 const char *reg9 =
"peer?name:pass:authuser:1234/extension~111";
288 const char *reg10 =
"@domin:1234";
289 const char *reg12 =
"name@namedomain:4321:pass:authuser@domain";
290 const char *reg13 =
"name@namedomain:4321::@domain";
294 info->name =
"sip_parse_register_line_test";
295 info->category =
"/channels/chan_sip/";
296 info->summary =
"tests sip register line parsing";
298 "Tests parsing of various register line configurations. "
299 "Verifies output matches expected behavior.";
310 strcmp(reg->callback,
"s") ||
311 strcmp(reg->username,
"name") ||
312 strcmp(reg->regdomain,
"") ||
313 strcmp(reg->hostname,
"domain") ||
314 strcmp(reg->authuser,
"") ||
315 strcmp(reg->secret,
"") ||
316 strcmp(reg->peername,
"") ||
317 reg->transport != SIP_TRANSPORT_UDP ||
318 reg->timeout != -1 ||
320 reg->refresh != default_expiry ||
321 reg->expiry != default_expiry ||
322 reg->configured_expiry != default_expiry ||
323 reg->portno != STANDARD_SIP_PORT ||
324 (reg->regdomainport) ||
325 reg->callid_valid !=
FALSE ||
326 reg->ocseq != INITIAL_CSEQ) {
339 strcmp(reg->callback,
"s") ||
340 strcmp(reg->username,
"name") ||
341 strcmp(reg->regdomain,
"") ||
342 strcmp(reg->hostname,
"domain") ||
343 strcmp(reg->authuser,
"") ||
344 strcmp(reg->secret,
"pass") ||
345 strcmp(reg->peername,
"") ||
346 reg->transport != SIP_TRANSPORT_UDP ||
347 reg->timeout != -1 ||
349 reg->refresh != default_expiry ||
350 reg->expiry != default_expiry ||
351 reg->configured_expiry != default_expiry ||
352 reg->portno != STANDARD_SIP_PORT ||
353 (reg->regdomainport) ||
354 reg->callid_valid !=
FALSE ||
355 reg->ocseq != INITIAL_CSEQ) {
368 strcmp(reg->callback,
"s") ||
369 strcmp(reg->username,
"name") ||
370 strcmp(reg->regdomain,
"namedomain") ||
371 strcmp(reg->hostname,
"domain") ||
372 strcmp(reg->authuser,
"authuser") ||
373 strcmp(reg->secret,
"pass") ||
374 strcmp(reg->peername,
"") ||
375 reg->transport != SIP_TRANSPORT_UDP ||
376 reg->timeout != -1 ||
378 reg->refresh != default_expiry ||
379 reg->expiry != default_expiry ||
380 reg->configured_expiry != default_expiry ||
381 reg->portno != STANDARD_SIP_PORT ||
382 (reg->regdomainport) ||
383 reg->callid_valid !=
FALSE ||
384 reg->ocseq != INITIAL_CSEQ) {
397 strcmp(reg->callback,
"extension") ||
398 strcmp(reg->username,
"name") ||
399 strcmp(reg->regdomain,
"namedomain") ||
400 strcmp(reg->hostname,
"domain") ||
401 strcmp(reg->authuser,
"authuser") ||
402 strcmp(reg->secret,
"pass") ||
403 strcmp(reg->peername,
"") ||
404 reg->transport != SIP_TRANSPORT_UDP ||
405 reg->timeout != -1 ||
407 reg->refresh != default_expiry ||
408 reg->expiry != default_expiry ||
409 reg->configured_expiry != default_expiry ||
410 reg->portno != STANDARD_SIP_PORT ||
411 (reg->regdomainport) ||
412 reg->callid_valid !=
FALSE ||
413 reg->ocseq != INITIAL_CSEQ) {
426 strcmp(reg->callback,
"extension") ||
427 strcmp(reg->username,
"name") ||
428 strcmp(reg->regdomain,
"namedomain") ||
429 strcmp(reg->hostname,
"domain") ||
430 strcmp(reg->authuser,
"authuser") ||
431 strcmp(reg->secret,
"pass") ||
432 strcmp(reg->peername,
"") ||
433 reg->transport != SIP_TRANSPORT_TCP ||
434 reg->timeout != -1 ||
436 reg->refresh != default_expiry ||
437 reg->expiry != default_expiry ||
438 reg->configured_expiry != default_expiry ||
439 reg->portno != STANDARD_SIP_PORT ||
440 (reg->regdomainport) ||
441 reg->callid_valid !=
FALSE ||
442 reg->ocseq != INITIAL_CSEQ) {
455 strcmp(reg->callback,
"extension") ||
456 strcmp(reg->username,
"name") ||
457 strcmp(reg->regdomain,
"namedomain") ||
458 strcmp(reg->hostname,
"domain") ||
459 strcmp(reg->authuser,
"authuser") ||
460 strcmp(reg->secret,
"pass") ||
461 strcmp(reg->peername,
"") ||
462 reg->transport != SIP_TRANSPORT_TLS ||
463 reg->timeout != -1 ||
465 reg->refresh != 111 ||
466 reg->expiry != 111 ||
467 reg->configured_expiry != 111 ||
468 reg->portno != STANDARD_TLS_PORT ||
469 (reg->regdomainport) ||
470 reg->callid_valid !=
FALSE ||
471 reg->ocseq != INITIAL_CSEQ) {
484 strcmp(reg->callback,
"extension") ||
485 strcmp(reg->username,
"name") ||
486 strcmp(reg->regdomain,
"namedomain") ||
487 strcmp(reg->hostname,
"domain") ||
488 strcmp(reg->authuser,
"authuser") ||
489 strcmp(reg->secret,
"pass") ||
490 strcmp(reg->peername,
"peer") ||
491 reg->transport != SIP_TRANSPORT_TCP ||
492 reg->timeout != -1 ||
494 reg->refresh != 111 ||
495 reg->expiry != 111 ||
496 reg->configured_expiry != 111 ||
497 reg->portno != 1234 ||
498 (reg->regdomainport) ||
499 reg->callid_valid !=
FALSE ||
500 reg->ocseq != INITIAL_CSEQ) {
513 strcmp(reg->callback,
"extension") ||
514 strcmp(reg->username,
"name") ||
515 strcmp(reg->regdomain,
"namedomain") ||
516 strcmp(reg->hostname,
"domain") ||
517 strcmp(reg->authuser,
"authuser") ||
518 strcmp(reg->secret,
"pass") ||
519 strcmp(reg->peername,
"peer") ||
520 reg->transport != SIP_TRANSPORT_UDP ||
521 reg->timeout != -1 ||
523 reg->refresh != 111 ||
524 reg->expiry != 111 ||
525 reg->configured_expiry != 111 ||
526 reg->portno != 1234 ||
527 (reg->regdomainport) ||
528 reg->callid_valid !=
FALSE ||
529 reg->ocseq != INITIAL_CSEQ) {
542 "Test 9, missing domain, expected to fail but did not.\n");
553 "Test 10, missing user expected to fail but did not\n");
562 "Test 11, no registry object, expected to fail but did not.\n");
572 "Test 12, NULL register line expected to fail but did not.\n");
583 strcmp(reg->callback,
"s") ||
584 strcmp(reg->username,
"name") ||
585 strcmp(reg->regdomain,
"namedomain") ||
586 strcmp(reg->hostname,
"domain") ||
587 strcmp(reg->authuser,
"authuser") ||
588 strcmp(reg->secret,
"pass") ||
589 strcmp(reg->peername,
"") ||
590 reg->transport != SIP_TRANSPORT_UDP ||
591 reg->timeout != -1 ||
593 reg->refresh != default_expiry ||
594 reg->expiry != default_expiry ||
595 reg->configured_expiry != default_expiry ||
596 reg->portno != STANDARD_SIP_PORT ||
597 reg->regdomainport != 4321 ||
598 reg->callid_valid !=
FALSE ||
599 reg->ocseq != INITIAL_CSEQ) {
612 strcmp(reg->callback,
"s") ||
613 strcmp(reg->username,
"name") ||
614 strcmp(reg->regdomain,
"namedomain") ||
615 strcmp(reg->hostname,
"domain") ||
616 strcmp(reg->authuser,
"") ||
617 strcmp(reg->secret,
"") ||
618 strcmp(reg->peername,
"") ||
619 reg->transport != SIP_TRANSPORT_UDP ||
620 reg->timeout != -1 ||
622 reg->refresh != default_expiry ||
623 reg->expiry != default_expiry ||
624 reg->configured_expiry != default_expiry ||
625 reg->portno != STANDARD_SIP_PORT ||
626 reg->regdomainport != 4321 ||
627 reg->callid_valid !=
FALSE ||
628 reg->ocseq != INITIAL_CSEQ) {
652 if ((*hostname = strstr(line,
"://"))) {
655 if (!strncasecmp(line,
"tcp", 3)) {
656 *transport = SIP_TRANSPORT_TCP;
657 }
else if (!strncasecmp(line,
"tls", 3)) {
658 *transport = SIP_TRANSPORT_TLS;
659 }
else if (!strncasecmp(line,
"udp", 3)) {
660 *transport = SIP_TRANSPORT_UDP;
662 ast_log(
LOG_NOTICE,
"'%.3s' is not a valid transport type on line %d of sip.conf. defaulting to udp.\n", line, lineno);
664 ast_log(
LOG_NOTICE,
"'%.3s' is not a valid transport type in sip config. defaulting to udp.\n", line);
668 *transport = SIP_TRANSPORT_UDP;
671 if ((line = strrchr(*hostname,
'@')))
687 if (!sscanf(port,
"%5d", portnum)) {
689 ast_log(
LOG_NOTICE,
"'%s' is not a valid port number on line %d of sip.conf. using default.\n", port, lineno);
691 ast_log(
LOG_NOTICE,
"'%s' is not a valid port number in sip config. using default.\n", port);
698 if (*transport & SIP_TRANSPORT_TLS) {
699 *portnum = STANDARD_TLS_PORT;
701 *portnum = STANDARD_SIP_PORT;
713 enum sip_transport transport;
714 char host1[] =
"www.blah.com";
715 char host2[] =
"tcp://www.blah.com";
716 char host3[] =
"tls://10.10.10.10";
717 char host4[] =
"tls://10.10.10.10:1234";
718 char host5[] =
"10.10.10.10:1234";
722 info->name =
"sip_parse_host_line_test";
723 info->category =
"/channels/chan_sip/";
724 info->summary =
"tests sip.conf host line parsing";
726 "Tests parsing of various host line configurations. "
727 "Verifies output matches expected behavior.";
735 if (port != STANDARD_SIP_PORT ||
737 transport != SIP_TRANSPORT_UDP) {
744 if (port != STANDARD_SIP_PORT ||
746 transport != SIP_TRANSPORT_TCP) {
753 if (port != STANDARD_TLS_PORT ||
755 transport != SIP_TRANSPORT_TLS) {
763 strcmp(host,
"10.10.10.10") ||
764 transport != SIP_TRANSPORT_TLS) {
772 strcmp(host,
"10.10.10.10") ||
773 transport != SIP_TRANSPORT_UDP) {
Asterisk main include file. File version handling, generic pbx functions.
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_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_TEST_REGISTER(cb)
#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.
void sip_config_parser_unregister_tests(void)
SIP test registration.
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
Splits a string into its host and port components.
#define ast_test_status_update(a, b, c...)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
static int default_expiry
#define AST_TEST_UNREGISTER(cb)
int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum sip_transport *transport)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
structure to hold users read from users.conf
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...
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...
#define AST_TEST_DEFINE(hdr)
#define AST_APP_ARG(name)
Define an application argument.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
#define AST_NONSTANDARD_RAW_ARGS(args, parse, sep)
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
static char hostname[MAXHOSTNAMELEN]
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.