2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2010, Digium, Inc.
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
19 * \brief sip request parsing functions and unit tests
24 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
26 #include "include/sip.h"
27 #include "include/sip_utils.h"
28 #include "include/reqresp_parser.h"
34 /*! \brief * parses a URI in its components.*/
35 int parse_uri_full(char *uri, const char *scheme, char **user, char **pass,
36 char **domain, struct uriparams *params, char **headers,
39 char *userinfo = NULL;
40 char *parameters = NULL;
41 char *endparams = NULL;
45 /* check for valid input */
46 if (ast_strlen_zero(uri)) {
52 char *scheme2 = ast_strdupa(scheme);
53 char *cur = strsep(&scheme2, ",");
54 for (; !ast_strlen_zero(cur); cur = strsep(&scheme2, ",")) {
56 if (!strncasecmp(uri, cur, l)) {
61 if (ast_strlen_zero(cur)) {
62 ast_debug(1, "No supported scheme found in '%s' using the scheme[s] %s\n", uri, scheme);
68 /* if we don't want to split around domain, keep everything as a
69 * userinfo - cos thats how old parse_uri operated*/
73 if ((c = strchr(uri, '@'))) {
77 uri = c; /* userinfo can contain ? and ; chars so step forward before looking for params and headers */
79 /* domain-only URI, according to the SIP RFC. */
87 if (pass && (c = strchr(userinfo, ':'))) { /* user:password */
99 /* strip [?headers] from end of uri - even if no header pointer exists*/
100 if ((c = strrchr(uri, '?'))) {
106 if ((c = strrchr(uri, ';'))) {
109 c = strrchr(uri, '\0');
111 uri = c; /* residue */
114 } else if (headers) {
118 /* parse parameters */
119 endparams = strchr(parameters,'\0');
120 if ((c = strchr(parameters, ';'))) {
124 parameters = endparams;
128 char *rem = parameters; /* unparsed or unrecognised remainder */
133 params->transport = "";
142 while ((value = strchr(parameters, '=')) || (lr = !strncmp(parameters, "lr", 2))) {
143 /* The while condition will not continue evaluation to set lr if it matches "lr=" */
150 if ((c = strchr(value, ';'))) {
154 parameters = endparams;
157 if (!strcmp(label, "transport")) {
158 if (params) {params->transport=value;}
160 } else if (!strcmp(label, "user")) {
161 if (params) {params->user=value;}
163 } else if (!strcmp(label, "method")) {
164 if (params) {params->method=value;}
166 } else if (!strcmp(label, "ttl")) {
167 if (params) {params->ttl=value;}
169 } else if (!strcmp(label, "maddr")) {
170 if (params) {params->maddr=value;}
172 /* Treat "lr", "lr=yes", "lr=on", "lr=1", "lr=almostanything" as lr enabled and "", "lr=no", "lr=off", "lr=0", "lr=" and "lranything" as lr disabled */
173 } else if ((!strcmp(label, "lr") && strcmp(value, "no") && strcmp(value, "off") && strcmp(value, "0") && strcmp(value, "")) || ((lr) && strcmp(value, "lr"))) {
174 if (params) {params->lr=1;}
185 if (rem > uri) { /* no headers */
199 AST_TEST_DEFINE(sip_parse_uri_fully_test)
201 int res = AST_TEST_PASS;
203 char *user, *pass, *domain, *headers, *residue;
204 struct uriparams params;
214 struct uriparams *paramsptr;
220 struct uriparams params;
221 AST_LIST_ENTRY(testdata) list;
225 struct testdata *testdataptr;
227 static AST_LIST_HEAD_NOLOCK(testdataliststruct, testdata) testdatalist;
229 struct testdata td1 = {
230 .desc = "no headers",
231 .uri = "sip:user:secret@host:5060;param=discard;transport=tcp;param2=residue",
234 .domainptr = &domain,
235 .headersptr = &headers,
236 .residueptr = &residue,
237 .paramsptr = ¶ms,
240 .domain = "host:5060",
242 .residue = "param2=residue",
243 .params.transport = "tcp",
248 struct testdata td2 = {
249 .desc = "with headers",
250 .uri = "sip:user:secret@host:5060;param=discard;transport=tcp;param2=discard2?header=blah&header2=blah2;param3=residue",
253 .domainptr = &domain,
254 .headersptr = &headers,
255 .residueptr = &residue,
256 .paramsptr = ¶ms,
259 .domain = "host:5060",
260 .headers = "header=blah&header2=blah2",
261 .residue = "param3=residue",
262 .params.transport = "tcp",
267 struct testdata td3 = {
268 .desc = "difficult user",
269 .uri = "sip:-_.!~*'()&=+$,;?/:secret@host:5060;transport=tcp",
272 .domainptr = &domain,
273 .headersptr = &headers,
274 .residueptr = &residue,
275 .paramsptr = ¶ms,
276 .user = "-_.!~*'()&=+$,;?/",
278 .domain = "host:5060",
281 .params.transport = "tcp",
286 struct testdata td4 = {
287 .desc = "difficult pass",
288 .uri = "sip:user:-_.!~*'()&=+$,@host:5060;transport=tcp",
291 .domainptr = &domain,
292 .headersptr = &headers,
293 .residueptr = &residue,
294 .paramsptr = ¶ms,
296 .pass = "-_.!~*'()&=+$,",
297 .domain = "host:5060",
300 .params.transport = "tcp",
305 struct testdata td5 = {
306 .desc = "difficult host",
307 .uri = "sip:user:secret@1-1.a-1.:5060;transport=tcp",
310 .domainptr = &domain,
311 .headersptr = &headers,
312 .residueptr = &residue,
313 .paramsptr = ¶ms,
316 .domain = "1-1.a-1.:5060",
319 .params.transport = "tcp",
324 struct testdata td6 = {
325 .desc = "difficult params near transport",
326 .uri = "sip:user:secret@host:5060;-_.!~*'()[]/:&+$=-_.!~*'()[]/:&+$;transport=tcp",
329 .domainptr = &domain,
330 .headersptr = &headers,
331 .residueptr = &residue,
332 .paramsptr = ¶ms,
335 .domain = "host:5060",
338 .params.transport = "tcp",
343 struct testdata td7 = {
344 .desc = "difficult params near headers",
345 .uri = "sip:user:secret@host:5060;-_.!~*'()[]/:&+$=-_.!~*'()[]/:&+$?header=blah&header2=blah2;-_.!~*'()[]/:&+$=residue",
348 .domainptr = &domain,
349 .headersptr = &headers,
350 .residueptr = &residue,
351 .paramsptr = ¶ms,
354 .domain = "host:5060",
355 .headers = "header=blah&header2=blah2",
356 .residue = "-_.!~*'()[]/:&+$=residue",
357 .params.transport = "",
362 struct testdata td8 = {
363 .desc = "lr parameter",
364 .uri = "sip:user:secret@host:5060;param=discard;lr?header=blah",
367 .domainptr = &domain,
368 .headersptr = &headers,
369 .residueptr = &residue,
370 .paramsptr = ¶ms,
373 .domain = "host:5060",
374 .headers = "header=blah",
376 .params.transport = "",
381 struct testdata td9 = {
382 .desc = "alternative lr parameter",
383 .uri = "sip:user:secret@host:5060;param=discard;lr=yes?header=blah",
386 .domainptr = &domain,
387 .headersptr = &headers,
388 .residueptr = &residue,
389 .paramsptr = ¶ms,
392 .domain = "host:5060",
393 .headers = "header=blah",
395 .params.transport = "",
400 struct testdata td10 = {
401 .desc = "no lr parameter",
402 .uri = "sip:user:secret@host:5060;paramlr=lr;lr=no;lr=off;lr=0;lr=;=lr;lrextra;lrparam2=lr?header=blah",
405 .domainptr = &domain,
406 .headersptr = &headers,
407 .residueptr = &residue,
408 .paramsptr = ¶ms,
411 .domain = "host:5060",
412 .headers = "header=blah",
414 .params.transport = "",
420 AST_LIST_HEAD_SET_NOLOCK(&testdatalist, &td1);
421 AST_LIST_INSERT_TAIL(&testdatalist, &td2, list);
422 AST_LIST_INSERT_TAIL(&testdatalist, &td3, list);
423 AST_LIST_INSERT_TAIL(&testdatalist, &td4, list);
424 AST_LIST_INSERT_TAIL(&testdatalist, &td5, list);
425 AST_LIST_INSERT_TAIL(&testdatalist, &td6, list);
426 AST_LIST_INSERT_TAIL(&testdatalist, &td7, list);
427 AST_LIST_INSERT_TAIL(&testdatalist, &td8, list);
428 AST_LIST_INSERT_TAIL(&testdatalist, &td9, list);
429 AST_LIST_INSERT_TAIL(&testdatalist, &td10, list);
434 info->name = "sip_uri_full_parse_test";
435 info->category = "/channels/chan_sip/";
436 info->summary = "tests sip full uri parsing";
438 "Tests full parsing of various URIs "
439 "Verifies output matches expected behavior.";
440 return AST_TEST_NOT_RUN;
445 AST_LIST_TRAVERSE(&testdatalist, testdataptr, list) {
446 user = pass = domain = headers = residue = NULL;
447 params.transport = params.user = params.method = params.ttl = params.maddr = NULL;
450 ast_copy_string(uri,testdataptr->uri,sizeof(uri));
451 if (parse_uri_full(uri, "sip:,sips:", testdataptr->userptr,
452 testdataptr->passptr, testdataptr->domainptr,
453 testdataptr->paramsptr,
454 testdataptr->headersptr,
455 testdataptr->residueptr) ||
456 ((testdataptr->userptr) && strcmp(testdataptr->user, user)) ||
457 ((testdataptr->passptr) && strcmp(testdataptr->pass, pass)) ||
458 ((testdataptr->domainptr) && strcmp(testdataptr->domain, domain)) ||
459 ((testdataptr->headersptr) && strcmp(testdataptr->headers, headers)) ||
460 ((testdataptr->residueptr) && strcmp(testdataptr->residue, residue)) ||
461 ((testdataptr->paramsptr) && strcmp(testdataptr->params.transport,params.transport)) ||
462 ((testdataptr->paramsptr) && (testdataptr->params.lr != params.lr)) ||
463 ((testdataptr->paramsptr) && strcmp(testdataptr->params.user,params.user))
465 ast_test_status_update(test, "Sub-Test: %s, failed.\n", testdataptr->desc);
475 int parse_uri(char *uri, const char *scheme, char **user, char **pass,
476 char **domain, char **transport) {
479 struct uriparams params;
482 ret = parse_uri_full(uri, scheme, user, pass, domain, ¶ms, &headers, NULL);
484 *transport=params.transport;
489 AST_TEST_DEFINE(sip_parse_uri_test)
491 int res = AST_TEST_PASS;
492 char *name, *pass, *domain, *transport;
493 char uri1[] = "sip:name@host";
494 char uri2[] = "sip:name@host;transport=tcp";
495 char uri3[] = "sip:name:secret@host;transport=tcp";
496 char uri4[] = "sip:name:secret@host:port;transport=tcp?headers=%40%40testblah&headers2=blah%20blah";
497 /* test 5 is for NULL input */
498 char uri6[] = "sip:name:secret@host:port;transport=tcp?headers=%40%40testblah&headers2=blah%20blah";
499 char uri7[] = "sip:name:secret@host:port;transport=tcp?headers=%40%40testblah&headers2=blah%20blah";
500 char uri8[] = "sip:host";
501 char uri9[] = "sip:host:port;transport=tcp?headers=%40%40testblah&headers2=blah%20blah";
502 char uri10[] = "host:port;transport=tcp?headers=%40%40testblah&headers2=blah%20blah";
503 char uri11[] = "host";
507 info->name = "sip_uri_parse_test";
508 info->category = "/channels/chan_sip/";
509 info->summary = "tests sip uri parsing";
511 "Tests parsing of various URIs "
512 "Verifies output matches expected behavior.";
513 return AST_TEST_NOT_RUN;
518 /* Test 1, simple URI */
519 name = pass = domain = transport = NULL;
520 if (parse_uri(uri1, "sip:,sips:", &name, &pass, &domain, &transport) ||
521 strcmp(name, "name") ||
522 !ast_strlen_zero(pass) ||
523 strcmp(domain, "host") ||
524 !ast_strlen_zero(transport)) {
525 ast_test_status_update(test, "Test 1: simple uri failed. \n");
529 /* Test 2, add tcp transport */
530 name = pass = domain = transport = NULL;
531 if (parse_uri(uri2, "sip:,sips:", &name, &pass, &domain, &transport) ||
532 strcmp(name, "name") ||
533 !ast_strlen_zero(pass) ||
534 strcmp(domain, "host") ||
535 strcmp(transport, "tcp")) {
536 ast_test_status_update(test, "Test 2: uri with addtion of tcp transport failed. \n");
540 /* Test 3, add secret */
541 name = pass = domain = transport = NULL;
542 if (parse_uri(uri3, "sip:,sips:", &name, &pass, &domain, &transport) ||
543 strcmp(name, "name") ||
544 strcmp(pass, "secret") ||
545 strcmp(domain, "host") ||
546 strcmp(transport, "tcp")) {
547 ast_test_status_update(test, "Test 3: uri with addition of secret failed.\n");
551 /* Test 4, add port and unparsed header field*/
552 name = pass = domain = transport = NULL;
553 if (parse_uri(uri4, "sip:,sips:", &name, &pass, &domain, &transport) ||
554 strcmp(name, "name") ||
555 strcmp(pass, "secret") ||
556 strcmp(domain, "host:port") ||
557 strcmp(transport, "tcp")) {
558 ast_test_status_update(test, "Test 4: add port and unparsed header field failed.\n");
562 /* Test 5, verify parse_uri does not crash when given a NULL uri */
563 name = pass = domain = transport = NULL;
564 if (!parse_uri(NULL, "sip:,sips:", &name, &pass, &domain, &transport)) {
565 ast_test_status_update(test, "Test 5: passing a NULL uri failed.\n");
569 /* Test 6, verify parse_uri does not crash when given a NULL output parameters */
570 name = pass = domain = transport = NULL;
571 if (parse_uri(uri6, "sip:,sips:", NULL, NULL, NULL, NULL)) {
572 ast_test_status_update(test, "Test 6: passing NULL output parameters failed.\n");
576 /* Test 7, verify parse_uri returns user:secret and domain when no port or secret output parameters are supplied. */
577 name = pass = domain = transport = NULL;
578 if (parse_uri(uri7, "sip:,sips:", &name, NULL, &domain, NULL) ||
579 strcmp(name, "name:secret") ||
580 strcmp(domain, "host:port")) {
582 ast_test_status_update(test, "Test 7: providing no port and secret output parameters failed.\n");
586 /* Test 8, verify parse_uri can handle a domain only uri */
587 name = pass = domain = transport = NULL;
588 if (parse_uri(uri8, "sip:,sips:", &name, &pass, &domain, &transport) ||
589 strcmp(domain, "host") ||
590 !ast_strlen_zero(name)) {
591 ast_test_status_update(test, "Test 8: add port and unparsed header field failed.\n");
595 /* Test 9, add port and unparsed header field with domain only uri*/
596 name = pass = domain = transport = NULL;
597 if (parse_uri(uri9, "sip:,sips:", &name, &pass, &domain, &transport) ||
598 !ast_strlen_zero(name) ||
599 !ast_strlen_zero(pass) ||
600 strcmp(domain, "host:port") ||
601 strcmp(transport, "tcp")) {
602 ast_test_status_update(test, "Test 9: domain only uri failed \n");
606 /* Test 10, handle invalid/missing "sip:,sips:" scheme
607 * we expect parse_uri to return an error, but still parse
608 * the results correctly here */
609 name = pass = domain = transport = NULL;
610 if (!parse_uri(uri10, "sip:,sips:", &name, &pass, &domain, &transport) ||
611 !ast_strlen_zero(name) ||
612 !ast_strlen_zero(pass) ||
613 strcmp(domain, "host:port") ||
614 strcmp(transport, "tcp")) {
615 ast_test_status_update(test, "Test 10: missing \"sip:sips:\" scheme failed\n");
619 /* Test 11, simple domain only URI with missing scheme
620 * we expect parse_uri to return an error, but still parse
621 * the results correctly here */
622 name = pass = domain = transport = NULL;
623 if (!parse_uri(uri11, "sip:,sips:", &name, &pass, &domain, &transport) ||
624 !ast_strlen_zero(name) ||
625 !ast_strlen_zero(pass) ||
626 strcmp(domain, "host") ||
627 !ast_strlen_zero(transport)) {
628 ast_test_status_update(test, "Test 11: simple uri with missing scheme failed. \n");
635 /*! \brief Get caller id name from SIP headers, copy into output buffer
637 * \retval input string pointer placed after display-name field if possible
639 const char *get_calleridname(const char *input, char *output, size_t outputsize)
643 * From = ( "From" / "f" ) HCOLON from-spec
644 * from-spec = ( name-addr / addr-spec ) *( SEMI from-param )
645 * name-addr = [ display-name ] LAQUOT addr-spec RAQUOT
646 * display-name = *(token LWS)/ quoted-string
647 * token = 1*(alphanum / "-" / "." / "!" / "%" / "*"
648 * / "_" / "+" / "`" / "'" / "~" )
649 * quoted-string = SWS DQUOTE *(qdtext / quoted-pair ) DQUOTE
650 * qdtext = LWS / %x21 / %x23-5B / %x5D-7E
652 * quoted-pair = "\" (%x00-09 / %x0B-0C / %x0E-7F)
654 * HCOLON = *WSP ":" SWS
656 * LWS = *[*WSP CRLF] 1*WSP
659 * Deviations from it:
660 * - following CRLF's in LWS is not done (here at least)
661 * - ascii NUL is never legal as it terminates the C-string
662 * - utf8-nonascii is not checked for validity
664 char *orig_output = output;
665 const char *orig_input = input;
667 /* clear any empty characters in the beginning */
668 input = ast_skip_blanks(input);
670 /* no data at all or no storage room? */
671 if (!input || *input == '<' || !outputsize || !output) {
675 /* make sure the output buffer is initilized */
678 /* make room for '\0' at the end of the output buffer */
681 /* quoted-string rules */
682 if (input[0] == '"') {
683 input++; /* skip the first " */
685 for (;((outputsize > 0) && *input); input++) {
686 if (*input == '"') { /* end of quoted-string */
688 } else if (*input == 0x5c) { /* quoted-pair = "\" (%x00-09 / %x0B-0C / %x0E-7F) */
690 if (!*input || (unsigned char)*input > 0x7f || *input == 0xa || *input == 0xd) {
691 continue; /* not a valid quoted-pair, so skip it */
693 } else if (((*input != 0x9) && ((unsigned char) *input < 0x20)) ||
695 continue; /* skip this invalid character. */
702 /* if this is successful, input should be at the ending quote */
703 if (!input || *input != '"') {
704 ast_log(LOG_WARNING, "No ending quote for display-name was found\n");
709 /* make sure input is past the last quote */
712 /* terminate outbuf */
714 } else { /* either an addr-spec or tokenLWS-combo */
715 for (;((outputsize > 0) && *input); input++) {
716 /* token or WSP (without LWS) */
717 if ((*input >= '0' && *input <= '9') || (*input >= 'A' && *input <= 'Z')
718 || (*input >= 'a' && *input <= 'z') || *input == '-' || *input == '.'
719 || *input == '!' || *input == '%' || *input == '*' || *input == '_'
720 || *input == '+' || *input == '`' || *input == '\'' || *input == '~'
721 || *input == 0x9 || *input == ' ') {
724 } else if (*input == '<') { /* end of tokenLWS-combo */
725 /* we could assert that the previous char is LWS, but we don't care */
727 } else if (*input == ':') {
728 /* This invalid character which indicates this is addr-spec rather than display-name. */
731 } else { /* else, invalid character we can skip. */
732 continue; /* skip this character */
736 if (*input != '<') { /* if we never found the start of addr-spec then this is invalid */
741 /* set NULL while trimming trailing whitespace */
744 } while (*output == 0x9 || *output == ' '); /* we won't go past orig_output as first was a non-space */
750 AST_TEST_DEFINE(get_calleridname_test)
752 int res = AST_TEST_PASS;
753 const char *in1 = "\" quoted-text internal \\\" quote \"<stuff>";
754 const char *in2 = " token text with no quotes <stuff>";
755 const char *overflow1 = " \"quoted-text overflow 1234567890123456789012345678901234567890\" <stuff>";
756 const char *noendquote = " \"quoted-text no end <stuff>";
757 const char *addrspec = " \"sip:blah@blah <stuff>";
758 const char *no_quotes_no_brackets = "blah@blah";
759 const char *after_dname;
764 info->name = "sip_get_calleridname_test";
765 info->category = "/channels/chan_sip/";
766 info->summary = "decodes callerid name from sip header";
767 info->description = "Decodes display-name field of sip header. Checks for valid output and expected failure cases.";
768 return AST_TEST_NOT_RUN;
773 /* quoted-text with backslash escaped quote */
774 after_dname = get_calleridname(in1, dname, sizeof(dname));
775 ast_test_status_update(test, "display-name1: %s\nafter: %s\n", dname, after_dname);
776 if (strcmp(dname, " quoted-text internal \" quote ")) {
777 ast_test_status_update(test, "display-name1 test failed\n");
782 after_dname = get_calleridname(in2, dname, sizeof(dname));
783 ast_test_status_update(test, "display-name2: %s\nafter: %s\n", dname, after_dname);
784 if (strcmp(dname, "token text with no quotes")) {
785 ast_test_status_update(test, "display-name2 test failed\n");
789 /* quoted-text buffer overflow */
790 after_dname = get_calleridname(overflow1, dname, sizeof(dname));
791 ast_test_status_update(test, "overflow display-name1: %s\nafter: %s\n", dname, after_dname);
792 if (*dname != '\0' && after_dname != overflow1) {
793 ast_test_status_update(test, "overflow display-name1 test failed\n");
797 /* quoted-text buffer with no terminating end quote */
798 after_dname = get_calleridname(noendquote, dname, sizeof(dname));
799 ast_test_status_update(test, "noendquote display-name1: %s\nafter: %s\n", dname, after_dname);
800 if (*dname != '\0' && after_dname != noendquote) {
801 ast_test_status_update(test, "no end quote for quoted-text display-name failed\n");
805 /* addr-spec rather than display-name. */
806 after_dname = get_calleridname(addrspec, dname, sizeof(dname));
807 ast_test_status_update(test, "noendquote display-name1: %s\nafter: %s\n", dname, after_dname);
808 if (*dname != '\0' && after_dname != addrspec) {
809 ast_test_status_update(test, "detection of addr-spec failed\n");
813 /* no quotes, no brackets */
814 after_dname = get_calleridname(no_quotes_no_brackets, dname, sizeof(dname));
815 ast_test_status_update(test, "no_quotes_no_brackets display-name1: %s\nafter: %s\n", dname, after_dname);
816 if (*dname != '\0' && after_dname != no_quotes_no_brackets) {
817 ast_test_status_update(test, "detection of addr-spec failed\n");
825 int get_name_and_number(const char *hdr, char **name, char **number)
828 char tmp_name[50] = { 0, };
829 char *tmp_number = NULL;
833 if (!name || !number || ast_strlen_zero(hdr)) {
839 ast_copy_string(header, hdr, sizeof(header));
841 /* strip the display-name portion off the beginning of the header. */
842 get_calleridname(header, tmp_name, sizeof(tmp_name));
844 /* get uri within < > brackets */
845 tmp_number = get_in_brackets(header);
847 /* parse out the number here */
848 if (parse_uri(tmp_number, "sip:,sips:", &tmp_number, &dummy, &domain, NULL) || ast_strlen_zero(tmp_number)) {
849 ast_log(LOG_ERROR, "can not parse name and number from sip header.\n");
853 /* number is not option, and must be present at this point */
854 *number = ast_strdup(tmp_number);
855 ast_uri_decode(*number, ast_uri_sip_user);
857 /* name is optional and may not be present at this point */
858 if (!ast_strlen_zero(tmp_name)) {
859 *name = ast_strdup(tmp_name);
865 AST_TEST_DEFINE(get_name_and_number_test)
867 int res = AST_TEST_PASS;
870 const char *in1 = "NAME <sip:NUMBER@place>";
871 const char *in2 = "\"NA><ME\" <sip:NUMBER@place>";
872 const char *in3 = "NAME";
873 const char *in4 = "<sip:NUMBER@place>";
874 const char *in5 = "This is a screwed up string <sip:LOLCLOWNS<sip:>@place>";
878 info->name = "sip_get_name_and_number_test";
879 info->category = "/channels/chan_sip/";
880 info->summary = "Tests getting name and number from sip header";
882 "Runs through various test situations in which a name and "
883 "and number can be retrieved from a sip header.";
884 return AST_TEST_NOT_RUN;
889 /* Test 1. get name and number */
890 number = name = NULL;
891 if ((get_name_and_number(in1, &name, &number)) ||
892 strcmp(name, "NAME") ||
893 strcmp(number, "NUMBER")) {
895 ast_test_status_update(test, "Test 1, simple get name and number failed.\n");
901 /* Test 2. get quoted name and number */
902 number = name = NULL;
903 if ((get_name_and_number(in2, &name, &number)) ||
904 strcmp(name, "NA><ME") ||
905 strcmp(number, "NUMBER")) {
907 ast_test_status_update(test, "Test 2, get quoted name and number failed.\n");
913 /* Test 3. name only */
914 number = name = NULL;
915 if (!(get_name_and_number(in3, &name, &number))) {
917 ast_test_status_update(test, "Test 3, get name only was expected to fail but did not.\n");
923 /* Test 4. number only */
924 number = name = NULL;
925 if ((get_name_and_number(in4, &name, &number)) ||
926 !ast_strlen_zero(name) ||
927 strcmp(number, "NUMBER")) {
929 ast_test_status_update(test, "Test 4, get number with no name present failed.\n");
935 /* Test 5. malformed string, since number can not be parsed, this should return an error. */
936 number = name = NULL;
937 if (!(get_name_and_number(in5, &name, &number)) ||
938 !ast_strlen_zero(name) ||
939 !ast_strlen_zero(number)) {
941 ast_test_status_update(test, "Test 5, processing malformed string failed.\n");
947 /* Test 6. NULL output parameters */
948 number = name = NULL;
949 if (!(get_name_and_number(in5, NULL, NULL))) {
951 ast_test_status_update(test, "Test 6, NULL output parameters failed.\n");
955 /* Test 7. NULL input parameter */
956 number = name = NULL;
957 if (!(get_name_and_number(NULL, &name, &number)) ||
958 !ast_strlen_zero(name) ||
959 !ast_strlen_zero(number)) {
961 ast_test_status_update(test, "Test 7, NULL input parameter failed.\n");
970 int get_in_brackets_full(char *tmp,char **out,char **residue)
972 const char *parse = tmp;
974 char *second_bracket;
983 if (ast_strlen_zero(tmp)) {
988 * Skip any quoted text until we find the part in brackets.
989 * On any error give up and return -1
991 while ( (first_bracket = strchr(parse, '<')) ) {
992 char *first_quote = strchr(parse, '"');
994 if (!first_quote || first_quote >= first_bracket) {
995 break; /* no need to look at quoted part */
997 /* the bracket is within quotes, so ignore it */
998 parse = find_closing_quote(first_quote + 1, NULL);
1000 ast_log(LOG_WARNING, "No closing quote found in '%s'\n", tmp);
1006 /* If no first bracket then still look for a second bracket as some other parsing functions
1007 may overwrite first bracket with NULL when terminating a token based display-name. As this
1008 only affects token based display-names there is no danger of brackets being in quotes */
1009 if (first_bracket) {
1010 parse = first_bracket;
1015 if ((second_bracket = strchr(parse, '>'))) {
1016 *second_bracket++ = '\0';
1018 *out = first_bracket;
1021 *residue = second_bracket;
1026 if ((first_bracket)) {
1027 ast_log(LOG_WARNING, "No closing bracket found in '%s'\n", tmp);
1038 char *get_in_brackets(char *tmp)
1042 if ((get_in_brackets_full(tmp, &out, NULL))) {
1048 AST_TEST_DEFINE(get_in_brackets_test)
1050 int res = AST_TEST_PASS;
1051 char *in_brackets = "<sip:name:secret@host:port;transport=tcp?headers=testblah&headers2=blahblah>";
1052 char no_name[] = "<sip:name:secret@host:port;transport=tcp?headers=testblah&headers2=blahblah>";
1053 char quoted_string[] = "\"I'm a quote stri><ng\" <sip:name:secret@host:port;transport=tcp?headers=testblah&headers2=blahblah>";
1054 char missing_end_quote[] = "\"I'm a quote string <sip:name:secret@host:port;transport=tcp?headers=testblah&headers2=blahblah>";
1055 char name_no_quotes[] = "name not in quotes <sip:name:secret@host:port;transport=tcp?headers=testblah&headers2=blahblah>";
1056 char no_end_bracket[] = "name not in quotes <sip:name:secret@host:port;transport=tcp?headers=testblah&headers2=blahblah";
1057 char no_name_no_brackets[] = "sip:name@host";
1062 info->name = "sip_get_in_brackets_test";
1063 info->category = "/channels/chan_sip/";
1064 info->summary = "Tests getting a sip uri in <> brackets within a sip header.";
1066 "Runs through various test situations in which a sip uri "
1067 "in angle brackets needs to be retrieved";
1068 return AST_TEST_NOT_RUN;
1073 /* Test 1, simple get in brackets */
1074 if (!(uri = get_in_brackets(no_name)) || !(strcmp(uri, in_brackets))) {
1076 ast_test_status_update(test, "Test 1, simple get in brackets failed.\n");
1077 res = AST_TEST_FAIL;
1080 /* Test 2, starts with quoted string */
1081 if (!(uri = get_in_brackets(quoted_string)) || !(strcmp(uri, in_brackets))) {
1083 ast_test_status_update(test, "Test 2, get in brackets with quoted string in front failed.\n");
1084 res = AST_TEST_FAIL;
1087 /* Test 3, missing end quote */
1088 if (!(uri = get_in_brackets(missing_end_quote)) || !(strcmp(uri, in_brackets))) {
1090 ast_test_status_update(test, "Test 3, missing end quote failed.\n");
1091 res = AST_TEST_FAIL;
1094 /* Test 4, starts with a name not in quotes */
1095 if (!(uri = get_in_brackets(name_no_quotes)) || !(strcmp(uri, in_brackets))) {
1097 ast_test_status_update(test, "Test 4, passing name not in quotes failed.\n");
1098 res = AST_TEST_FAIL;
1101 /* Test 5, no end bracket, should just return everything after the first '<' */
1102 if (!(uri = get_in_brackets(no_end_bracket)) || !(strcmp(uri, in_brackets))) {
1104 ast_test_status_update(test, "Test 5, no end bracket failed.\n");
1105 res = AST_TEST_FAIL;
1108 /* Test 6, NULL input */
1109 if ((uri = get_in_brackets(NULL))) {
1111 ast_test_status_update(test, "Test 6, NULL input failed.\n");
1112 res = AST_TEST_FAIL;
1115 /* Test 7, no name, and no brackets. */
1116 if (!(uri = get_in_brackets(no_name_no_brackets)) || (strcmp(uri, "sip:name@host"))) {
1118 ast_test_status_update(test, "Test 7 failed. %s\n", uri);
1119 res = AST_TEST_FAIL;
1126 int parse_name_andor_addr(char *uri, const char *scheme, char **name,
1127 char **user, char **pass, char **domain,
1128 struct uriparams *params, char **headers,
1132 char **residue2=residue;
1135 get_calleridname(uri,buf,sizeof(buf));
1138 ret = get_in_brackets_full(uri,&uri,residue);
1139 if (ret == 0) { /* uri is in brackets so do not treat unknown trailing uri parameters as potential messageheader parameters */
1140 *residue = *residue + 1; /* step over the first semicolon so as per parse uri residue */
1144 return parse_uri_full(uri, scheme, user, pass, domain, params, headers,
1148 AST_TEST_DEFINE(parse_name_andor_addr_test)
1150 int res = AST_TEST_PASS;
1152 char *name, *user, *pass, *domain, *headers, *residue;
1153 struct uriparams params;
1164 struct uriparams *paramsptr;
1171 struct uriparams params;
1172 AST_LIST_ENTRY(testdata) list;
1175 struct testdata *testdataptr;
1177 static AST_LIST_HEAD_NOLOCK(testdataliststruct, testdata) testdatalist;
1179 struct testdata td1 = {
1180 .desc = "quotes and brackets",
1181 .uri = "\"name :@ \" <sip:user:secret@host:5060;param=discard;transport=tcp>;tag=tag",
1185 .domainptr = &domain,
1186 .headersptr = &headers,
1187 .residueptr = &residue,
1188 .paramsptr = ¶ms,
1192 .domain = "host:5060",
1194 .residue = "tag=tag",
1195 .params.transport = "tcp",
1200 struct testdata td2 = {
1201 .desc = "no quotes",
1202 .uri = "givenname familyname <sip:user:secret@host:5060;param=discard;transport=tcp>;expires=3600",
1206 .domainptr = &domain,
1207 .headersptr = &headers,
1208 .residueptr = &residue,
1209 .paramsptr = ¶ms,
1210 .name = "givenname familyname",
1213 .domain = "host:5060",
1215 .residue = "expires=3600",
1216 .params.transport = "tcp",
1221 struct testdata td3 = {
1222 .desc = "no brackets",
1223 .uri = "sip:user:secret@host:5060;param=discard;transport=tcp;q=1",
1227 .domainptr = &domain,
1228 .headersptr = &headers,
1229 .residueptr = &residue,
1230 .paramsptr = ¶ms,
1234 .domain = "host:5060",
1237 .params.transport = "tcp",
1242 struct testdata td4 = {
1243 .desc = "just host",
1248 .domainptr = &domain,
1249 .headersptr = &headers,
1250 .residueptr = &residue,
1251 .paramsptr = ¶ms,
1258 .params.transport = "",
1264 AST_LIST_HEAD_SET_NOLOCK(&testdatalist, &td1);
1265 AST_LIST_INSERT_TAIL(&testdatalist, &td2, list);
1266 AST_LIST_INSERT_TAIL(&testdatalist, &td3, list);
1267 AST_LIST_INSERT_TAIL(&testdatalist, &td4, list);
1272 info->name = "parse_name_andor_addr_test";
1273 info->category = "/channels/chan_sip/";
1274 info->summary = "tests parsing of name_andor_addr abnf structure";
1276 "Tests parsing of abnf name-andor-addr = name-addr / addr-spec "
1277 "Verifies output matches expected behavior.";
1278 return AST_TEST_NOT_RUN;
1283 AST_LIST_TRAVERSE(&testdatalist, testdataptr, list) {
1284 name = user = pass = domain = headers = residue = NULL;
1285 params.transport = params.user = params.method = params.ttl = params.maddr = NULL;
1287 ast_copy_string(uri,testdataptr->uri,sizeof(uri));
1288 if (parse_name_andor_addr(uri, "sip:,sips:",
1289 testdataptr->nameptr,
1290 testdataptr->userptr,
1291 testdataptr->passptr,
1292 testdataptr->domainptr,
1293 testdataptr->paramsptr,
1294 testdataptr->headersptr,
1295 testdataptr->residueptr) ||
1296 ((testdataptr->nameptr) && strcmp(testdataptr->name, name)) ||
1297 ((testdataptr->userptr) && strcmp(testdataptr->user, user)) ||
1298 ((testdataptr->passptr) && strcmp(testdataptr->pass, pass)) ||
1299 ((testdataptr->domainptr) && strcmp(testdataptr->domain, domain)) ||
1300 ((testdataptr->headersptr) && strcmp(testdataptr->headers, headers)) ||
1301 ((testdataptr->residueptr) && strcmp(testdataptr->residue, residue)) ||
1302 ((testdataptr->paramsptr) && strcmp(testdataptr->params.transport,params.transport)) ||
1303 ((testdataptr->paramsptr) && strcmp(testdataptr->params.user,params.user))
1305 ast_test_status_update(test, "Sub-Test: %s,failed.\n", testdataptr->desc);
1306 res = AST_TEST_FAIL;
1314 int get_comma(char *in, char **out) {
1321 /* Skip any quoted text */
1323 if ((c = strchr(parse, '"'))) {
1324 in = (char *)find_closing_quote((const char *)c + 1, NULL);
1326 ast_log(LOG_WARNING, "No closing quote found in '%s'\n", c);
1338 /* Skip any userinfo components of a uri as they may contain commas */
1339 if ((c = strchr(parse,'@'))) {
1342 if ((out) && (c = strchr(parse,','))) {
1350 int parse_contact_header(char *contactheader, struct contactliststruct *contactlist) {
1357 struct contact *contact=NULL;
1359 if (*contactheader == '*') {
1363 contact = malloc(sizeof(*contact));
1365 AST_LIST_HEAD_SET_NOLOCK(contactlist, contact);
1366 while ((last = get_comma(contactheader,&comma)) != -1) {
1368 res = parse_name_andor_addr(contactheader, "sip:,sips:",
1369 &contact->name, &contact->user,
1370 &contact->pass, &contact->domain,
1371 &contact->params, &contact->headers,
1377 /* parse contact params */
1378 contact->expires = contact->q = "";
1380 while ((value = strchr(residue,'='))) {
1384 if ((residue = strchr(value,';'))) {
1390 if (!strcmp(param,"expires")) {
1391 contact->expires = value;
1392 } else if (!strcmp(param,"q")) {
1400 contactheader = comma;
1402 contact = malloc(sizeof(*contact));
1403 AST_LIST_INSERT_TAIL(contactlist, contact, list);
1409 AST_TEST_DEFINE(parse_contact_header_test)
1411 int res = AST_TEST_PASS;
1412 char contactheader[1024];
1414 struct contactliststruct contactlist;
1415 struct contactliststruct *contactlistptr=&contactlist;
1419 char *contactheader;
1421 struct contactliststruct *contactlist;
1423 AST_LIST_ENTRY(testdata) list;
1426 struct testdata *testdataptr;
1427 struct contact *tdcontactptr;
1428 struct contact *contactptr;
1430 static AST_LIST_HEAD_NOLOCK(testdataliststruct, testdata) testdatalist;
1431 struct contactliststruct contactlist1, contactlist2;
1433 struct testdata td1 = {
1434 .desc = "single contact",
1435 .contactheader = "\"name :@;?&,\" <sip:user:secret@host:5082;param=discard;transport=tcp>;expires=3600",
1436 .contactlist = &contactlist1,
1439 struct contact contact11 = {
1440 .name = "name :@;?&,",
1443 .domain = "host:5082",
1444 .params.transport = "tcp",
1452 struct testdata td2 = {
1453 .desc = "multiple contacts",
1454 .contactheader = "sip:,user1,:,secret1,@host1;ttl=7;q=1;expires=3600,sips:host2",
1455 .contactlist = &contactlist2,
1458 struct contact contact21 = {
1461 .pass = ",secret1,",
1463 .params.transport = "",
1470 struct contact contact22 = {
1475 .params.transport = "",
1483 struct testdata td3 = {
1484 .desc = "star - all contacts",
1485 .contactheader = "*",
1490 AST_LIST_HEAD_SET_NOLOCK(&testdatalist, &td1);
1491 AST_LIST_INSERT_TAIL(&testdatalist, &td2, list);
1492 AST_LIST_INSERT_TAIL(&testdatalist, &td3, list);
1494 AST_LIST_HEAD_SET_NOLOCK(&contactlist1, &contact11);
1496 AST_LIST_HEAD_SET_NOLOCK(&contactlist2, &contact21);
1497 AST_LIST_INSERT_TAIL(&contactlist2, &contact22, list);
1502 info->name = "parse_contact_header_test";
1503 info->category = "/channels/chan_sip/";
1504 info->summary = "tests parsing of sip contact header";
1506 "Tests parsing of a contact header including those with multiple contacts "
1507 "Verifies output matches expected behavior.";
1508 return AST_TEST_NOT_RUN;
1513 AST_LIST_TRAVERSE(&testdatalist, testdataptr, list) {
1514 ast_copy_string(contactheader,testdataptr->contactheader,sizeof(contactheader));
1515 star = parse_contact_header(contactheader,contactlistptr);
1516 if (testdataptr->star) {
1517 /* expecting star rather than list of contacts */
1519 ast_test_status_update(test, "Sub-Test: %s,failed.\n", testdataptr->desc);
1520 res = AST_TEST_FAIL;
1524 contactptr = AST_LIST_FIRST(contactlistptr);
1525 AST_LIST_TRAVERSE(testdataptr->contactlist, tdcontactptr, list) {
1527 strcmp(tdcontactptr->name, contactptr->name) ||
1528 strcmp(tdcontactptr->user, contactptr->user) ||
1529 strcmp(tdcontactptr->pass, contactptr->pass) ||
1530 strcmp(tdcontactptr->domain, contactptr->domain) ||
1531 strcmp(tdcontactptr->headers, contactptr->headers) ||
1532 strcmp(tdcontactptr->expires, contactptr->expires) ||
1533 strcmp(tdcontactptr->q, contactptr->q) ||
1534 strcmp(tdcontactptr->params.transport, contactptr->params.transport) ||
1535 strcmp(tdcontactptr->params.ttl, contactptr->params.ttl) ||
1536 (tdcontactptr->params.lr != contactptr->params.lr)
1538 ast_test_status_update(test, "Sub-Test: %s,failed.\n", testdataptr->desc);
1539 res = AST_TEST_FAIL;
1543 contactptr = AST_LIST_NEXT(contactptr,list);
1553 * \brief Parse supported header in incoming packet
1555 * \details This function parses through the options parameters and
1556 * builds a bit field representing all the SIP options in that field. When an
1557 * item is found that is not supported, it is copied to the unsupported
1560 * \param option list
1561 * \param unsupported out buffer (optional)
1562 * \param unsupported out buffer length (optional)
1564 unsigned int parse_sip_options(const char *options, char *unsupported, size_t unsupported_len)
1568 int i, found, supported;
1569 unsigned int profile = 0;
1571 char *out = unsupported;
1572 size_t outlen = unsupported_len;
1573 char *cur_out = out;
1575 if (out && (outlen > 0)) {
1576 memset(out, 0, outlen);
1579 if (ast_strlen_zero(options) )
1582 temp = ast_strdupa(options);
1584 ast_debug(3, "Begin: parsing SIP \"Supported: %s\"\n", options);
1586 for (next = temp; next; next = sep) {
1589 if ((sep = strchr(next, ',')) != NULL) {
1593 /* trim leading and trailing whitespace */
1594 next = ast_strip(next);
1596 if (ast_strlen_zero(next)) {
1597 continue; /* if there is a blank argument in there just skip it */
1600 ast_debug(3, "Found SIP option: -%s-\n", next);
1601 for (i = 0; i < ARRAY_LEN(sip_options); i++) {
1602 if (!strcasecmp(next, sip_options[i].text)) {
1603 profile |= sip_options[i].id;
1604 if (sip_options[i].supported == SUPPORTED) {
1608 ast_debug(3, "Matched SIP option: %s\n", next);
1613 /* If option is not supported, add to unsupported out buffer */
1614 if (!supported && out && outlen) {
1615 size_t copylen = strlen(next);
1616 size_t cur_outlen = strlen(out);
1617 /* Check to see if there is enough room to store this option.
1618 * Copy length is string length plus 2 for the ',' and '\0' */
1619 if ((cur_outlen + copylen + 2) < outlen) {
1620 /* if this isn't the first item, add the ',' */
1626 ast_copy_string(cur_out, next, (outlen - cur_outlen));
1632 profile |= SIP_OPT_UNKNOWN;
1633 if (!strncasecmp(next, "x-", 2))
1634 ast_debug(3, "Found private SIP option, not supported: %s\n", next);
1636 ast_debug(3, "Found no match for SIP option: %s (Please file bug report!)\n", next);
1643 AST_TEST_DEFINE(sip_parse_options_test)
1645 int res = AST_TEST_PASS;
1646 char unsupported[64];
1647 unsigned int option_profile = 0;
1650 char *input_options;
1651 char *expected_unsupported;
1652 unsigned int expected_profile;
1653 AST_LIST_ENTRY(testdata) list;
1656 struct testdata *testdataptr;
1657 static AST_LIST_HEAD_NOLOCK(testdataliststruct, testdata) testdatalist;
1659 struct testdata test1 = {
1660 .name = "test_all_unsupported",
1661 .input_options = "unsupported1,,, ,unsupported2,unsupported3,unsupported4",
1662 .expected_unsupported = "unsupported1,unsupported2,unsupported3,unsupported4",
1663 .expected_profile = SIP_OPT_UNKNOWN,
1665 struct testdata test2 = {
1666 .name = "test_all_unsupported_one_supported",
1667 .input_options = " unsupported1, replaces, unsupported3 , , , ,unsupported4",
1668 .expected_unsupported = "unsupported1,unsupported3,unsupported4",
1669 .expected_profile = SIP_OPT_UNKNOWN | SIP_OPT_REPLACES
1671 struct testdata test3 = {
1672 .name = "test_two_supported_two_unsupported",
1673 .input_options = ",, timer ,replaces ,unsupported3,unsupported4",
1674 .expected_unsupported = "unsupported3,unsupported4",
1675 .expected_profile = SIP_OPT_UNKNOWN | SIP_OPT_REPLACES | SIP_OPT_TIMER,
1678 struct testdata test4 = {
1679 .name = "test_all_supported",
1680 .input_options = "timer,replaces",
1681 .expected_unsupported = "",
1682 .expected_profile = SIP_OPT_REPLACES | SIP_OPT_TIMER,
1685 struct testdata test5 = {
1686 .name = "test_all_supported_redundant",
1687 .input_options = "timer,replaces,timer,replace,timer,replaces",
1688 .expected_unsupported = "",
1689 .expected_profile = SIP_OPT_REPLACES | SIP_OPT_TIMER,
1691 struct testdata test6 = {
1692 .name = "test_buffer_overflow",
1693 .input_options = "unsupported1,replaces,timer,unsupported4,unsupported_huge____"
1694 "____________________________________,__________________________________________"
1695 "________________________________________________",
1696 .expected_unsupported = "unsupported1,unsupported4",
1697 .expected_profile = SIP_OPT_UNKNOWN | SIP_OPT_REPLACES | SIP_OPT_TIMER,
1699 struct testdata test7 = {
1700 .name = "test_null_input",
1701 .input_options = NULL,
1702 .expected_unsupported = "",
1703 .expected_profile = 0,
1705 struct testdata test8 = {
1706 .name = "test_whitespace_input",
1707 .input_options = " ",
1708 .expected_unsupported = "",
1709 .expected_profile = 0,
1711 struct testdata test9 = {
1712 .name = "test_whitespace_plus_option_input",
1713 .input_options = " , , ,timer , , , , , ",
1714 .expected_unsupported = "",
1715 .expected_profile = SIP_OPT_TIMER,
1720 info->name = "sip_parse_options_test";
1721 info->category = "/channels/chan_sip/";
1722 info->summary = "Tests parsing of sip options";
1724 "Tests parsing of SIP options from supported and required "
1725 "header fields. Verifies when unsupported options are encountered "
1726 "that they are appended to the unsupported out buffer and that the "
1727 "correct bit field representnig the option profile is returned.";
1728 return AST_TEST_NOT_RUN;
1733 AST_LIST_HEAD_SET_NOLOCK(&testdatalist, &test1);
1734 AST_LIST_INSERT_TAIL(&testdatalist, &test2, list);
1735 AST_LIST_INSERT_TAIL(&testdatalist, &test3, list);
1736 AST_LIST_INSERT_TAIL(&testdatalist, &test4, list);
1737 AST_LIST_INSERT_TAIL(&testdatalist, &test5, list);
1738 AST_LIST_INSERT_TAIL(&testdatalist, &test6, list);
1739 AST_LIST_INSERT_TAIL(&testdatalist, &test7, list);
1740 AST_LIST_INSERT_TAIL(&testdatalist, &test8, list);
1741 AST_LIST_INSERT_TAIL(&testdatalist, &test9, list);
1743 /* Test with unsupported char buffer */
1744 AST_LIST_TRAVERSE(&testdatalist, testdataptr, list) {
1745 option_profile = parse_sip_options(testdataptr->input_options, unsupported, ARRAY_LEN(unsupported));
1746 if (option_profile != testdataptr->expected_profile ||
1747 strcmp(unsupported, testdataptr->expected_unsupported)) {
1748 ast_test_status_update(test, "Test with output buffer \"%s\", expected unsupported: %s actual unsupported:"
1749 "%s expected bit profile: %x actual bit profile: %x\n",
1751 testdataptr->expected_unsupported,
1753 testdataptr->expected_profile,
1755 res = AST_TEST_FAIL;
1757 ast_test_status_update(test, "\"%s\" passed got expected unsupported: %s and bit profile: %x\n",
1763 option_profile = parse_sip_options(testdataptr->input_options, NULL, 0);
1764 if (option_profile != testdataptr->expected_profile) {
1765 ast_test_status_update(test, "NULL output test \"%s\", expected bit profile: %x actual bit profile: %x\n",
1767 testdataptr->expected_profile,
1769 res = AST_TEST_FAIL;
1771 ast_test_status_update(test, "\"%s\" with NULL output buf passed, bit profile: %x\n",
1780 /*! \brief helper routine for sip_uri_cmp to compare URI parameters
1782 * This takes the parameters from two SIP URIs and determines
1783 * if the URIs match. The rules for parameters *suck*. Here's a breakdown
1784 * 1. If a parameter appears in both URIs, then they must have the same value
1785 * in order for the URIs to match
1786 * 2. If one URI has a user, maddr, ttl, or method parameter, then the other
1787 * URI must also have that parameter and must have the same value
1788 * in order for the URIs to match
1789 * 3. All other headers appearing in only one URI are not considered when
1790 * determining if URIs match
1792 * \param input1 Parameters from URI 1
1793 * \param input2 Parameters from URI 2
1794 * \retval 0 URIs' parameters match
1795 * \retval nonzero URIs' parameters do not match
1797 static int sip_uri_params_cmp(const char *input1, const char *input2)
1799 char *params1 = NULL;
1800 char *params2 = NULL;
1803 int zerolength1 = 0;
1804 int zerolength2 = 0;
1808 int methodmatch = 0;
1810 if (ast_strlen_zero(input1)) {
1813 params1 = ast_strdupa(input1);
1815 if (ast_strlen_zero(input2)) {
1818 params2 = ast_strdupa(input2);
1821 /* Quick optimization. If both params are zero-length, then
1824 if (zerolength1 && zerolength2) {
1828 for (pos1 = strsep(¶ms1, ";"); pos1; pos1 = strsep(¶ms1, ";")) {
1829 char *value1 = pos1;
1830 char *name1 = strsep(&value1, "=");
1831 char *params2dup = NULL;
1836 /* Checkpoint reached. We have the name and value parsed for param1
1837 * We have to duplicate params2 each time through this loop
1838 * or else the inner loop below will not work properly.
1841 params2dup = ast_strdupa(params2);
1843 for (pos2 = strsep(¶ms2dup, ";"); pos2; pos2 = strsep(¶ms2dup, ";")) {
1845 char *value2 = strchr(pos2, '=');
1851 if (!strcasecmp(name1, name2)) {
1852 if (strcasecmp(value1, value2)) {
1860 /* Check to see if the parameter is one of the 'must-match' parameters */
1861 if (!strcasecmp(name1, "maddr")) {
1867 } else if (!strcasecmp(name1, "ttl")) {
1873 } else if (!strcasecmp(name1, "user")) {
1879 } else if (!strcasecmp(name1, "method")) {
1888 /* We've made it out of that horrible O(m*n) construct and there are no
1889 * failures yet. We're not done yet, though, because params2 could have
1890 * an maddr, ttl, user, or method header and params1 did not.
1892 for (pos2 = strsep(¶ms2, ";"); pos2; pos2 = strsep(¶ms2, ";")) {
1893 char *value2 = pos2;
1894 char *name2 = strsep(&value2, "=");
1898 if ((!strcasecmp(name2, "maddr") && !maddrmatch) ||
1899 (!strcasecmp(name2, "ttl") && !ttlmatch) ||
1900 (!strcasecmp(name2, "user") && !usermatch) ||
1901 (!strcasecmp(name2, "method") && !methodmatch)) {
1911 /*! \brief helper routine for sip_uri_cmp to compare URI headers
1913 * This takes the headers from two SIP URIs and determines
1914 * if the URIs match. The rules for headers is simple. If a header
1915 * appears in one URI, then it must also appear in the other URI. The
1916 * order in which the headers appear does not matter.
1918 * \param input1 Headers from URI 1
1919 * \param input2 Headers from URI 2
1920 * \retval 0 URI headers match
1921 * \retval nonzero URI headers do not match
1923 static int sip_uri_headers_cmp(const char *input1, const char *input2)
1925 char *headers1 = NULL;
1926 char *headers2 = NULL;
1927 int zerolength1 = 0;
1928 int zerolength2 = 0;
1932 if (ast_strlen_zero(input1)) {
1935 headers1 = ast_strdupa(input1);
1938 if (ast_strlen_zero(input2)) {
1941 headers2 = ast_strdupa(input2);
1944 /* If one URI contains no headers and the other
1945 * does, then they cannot possibly match
1947 if (zerolength1 != zerolength2) {
1951 if (zerolength1 && zerolength2)
1954 /* At this point, we can definitively state that both inputs are
1955 * not zero-length. First, one more optimization. If the length
1956 * of the headers is not equal, then we definitely have no match
1958 if (strlen(headers1) != strlen(headers2)) {
1962 for (header1 = strsep(&headers1, "&"); header1; header1 = strsep(&headers1, "&")) {
1963 if (!strcasestr(headers2, header1)) {
1973 * \brief Compare domain sections of SIP URIs
1975 * For hostnames, a case insensitive string comparison is
1976 * used. For IP addresses, a binary comparison is used. This
1977 * is mainly because IPv6 addresses have many ways of writing
1980 * For specifics about IP address comparison, see the following
1981 * document: http://tools.ietf.org/html/draft-ietf-sip-ipv6-abnf-fix-05
1983 * \param host1 The domain from the first URI
1984 * \param host2 THe domain from the second URI
1985 * \retval 0 The domains match
1986 * \retval nonzero The domains do not match
1988 static int sip_uri_domain_cmp(const char *host1, const char *host2)
1990 struct ast_sockaddr addr1;
1991 struct ast_sockaddr addr2;
1995 addr1_parsed = ast_sockaddr_parse(&addr1, host1, 0);
1996 addr2_parsed = ast_sockaddr_parse(&addr2, host2, 0);
1998 if (addr1_parsed != addr2_parsed) {
1999 /* One domain was an IP address and the other had
2000 * a host name. FAIL!
2005 /* Both are host names. A string comparison will work
2006 * perfectly here. Specifying the "C" locale ensures that
2007 * The LC_CTYPE conventions use those defined in ANSI C,
2010 if (!addr1_parsed) {
2011 #ifdef HAVE_XLOCALE_H
2013 return strcasecmp(host1, host2);
2015 return strcasecmp_l(host1, host2, c_locale);
2018 return strcasecmp(host1, host2);
2022 /* Both contain IP addresses */
2023 return ast_sockaddr_cmp(&addr1, &addr2);
2026 int sip_uri_cmp(const char *input1, const char *input2)
2039 /* XXX It would be really nice if we could just use parse_uri_full() here
2040 * to separate the components of the URI, but unfortunately it is written
2041 * in a way that can cause URI parameters to be discarded.
2044 if (!input1 || !input2) {
2048 uri1 = ast_strdupa(input1);
2049 uri2 = ast_strdupa(input2);
2051 ast_uri_decode(uri1, ast_uri_sip_user);
2052 ast_uri_decode(uri2, ast_uri_sip_user);
2054 uri_scheme1 = strsep(&uri1, ":");
2055 uri_scheme2 = strsep(&uri2, ":");
2057 if (strcmp(uri_scheme1, uri_scheme2)) {
2061 /* This function is tailored for SIP and SIPS URIs. There's no
2062 * need to check uri_scheme2 since we have determined uri_scheme1
2063 * and uri_scheme2 are equivalent already.
2065 if (strcmp(uri_scheme1, "sip") && strcmp(uri_scheme1, "sips")) {
2069 if (ast_strlen_zero(uri1) || ast_strlen_zero(uri2)) {
2073 if ((host1 = strchr(uri1, '@'))) {
2076 if ((host2 = strchr(uri2, '@'))) {
2080 /* Check for mismatched username and passwords. This is the
2081 * only case-sensitive comparison of a SIP URI
2083 if ((host1 && !host2) ||
2084 (host2 && !host1) ||
2085 (host1 && host2 && strcmp(uri1, uri2))) {
2096 /* Strip off the parameters and headers so we can compare
2100 if ((params1 = strchr(host1, ';'))) {
2103 if ((params2 = strchr(host2, ';'))) {
2107 /* Headers come after parameters, but there may be headers without
2108 * parameters, thus the S_OR
2110 if ((headers1 = strchr(S_OR(params1, host1), '?'))) {
2113 if ((headers2 = strchr(S_OR(params2, host2), '?'))) {
2117 if (sip_uri_domain_cmp(host1, host2)) {
2121 /* Headers have easier rules to follow, so do those first */
2122 if (sip_uri_headers_cmp(headers1, headers2)) {
2126 /* And now the parameters. Ugh */
2127 return sip_uri_params_cmp(params1, params2);
2130 #define URI_CMP_MATCH 0
2131 #define URI_CMP_NOMATCH 1
2133 AST_TEST_DEFINE(sip_uri_cmp_test)
2135 static const struct {
2138 int expected_result;
2139 } uri_cmp_tests [] = {
2140 /* These are identical, so they match */
2141 { "sip:bob@example.com", "sip:bob@example.com", URI_CMP_MATCH },
2142 /* Different usernames. No match */
2143 { "sip:alice@example.com", "sip:bob@example.com", URI_CMP_NOMATCH },
2144 /* Different hosts. No match */
2145 { "sip:bob@example.com", "sip:bob@examplez.com", URI_CMP_NOMATCH },
2146 /* Now start using IP addresses. Identical, so they match */
2147 { "sip:bob@1.2.3.4", "sip:bob@1.2.3.4", URI_CMP_MATCH },
2148 /* Two identical IPv4 addresses represented differently. Match */
2149 { "sip:bob@1.2.3.4", "sip:bob@001.002.003.004", URI_CMP_MATCH },
2150 /* Logically equivalent IPv4 Address and hostname. No Match */
2151 { "sip:bob@127.0.0.1", "sip:bob@localhost", URI_CMP_NOMATCH },
2152 /* Logically equivalent IPv6 address and hostname. No Match */
2153 { "sip:bob@[::1]", "sip:bob@localhost", URI_CMP_NOMATCH },
2154 /* Try an IPv6 one as well */
2155 { "sip:bob@[2001:db8::1234]", "sip:bob@[2001:db8::1234]", URI_CMP_MATCH },
2156 /* Two identical IPv6 addresses represented differently. Match */
2157 { "sip:bob@[2001:db8::1234]", "sip:bob@[2001:0db8::1234]", URI_CMP_MATCH },
2158 /* Different ports. No match */
2159 { "sip:bob@1.2.3.4:5060", "sip:bob@1.2.3.4:5061", URI_CMP_NOMATCH },
2160 /* Same port logically, but only one address specifies it. No match */
2161 { "sip:bob@1.2.3.4:5060", "sip:bob@1.2.3.4", URI_CMP_NOMATCH },
2162 /* And for safety, try with IPv6 */
2163 { "sip:bob@[2001:db8:1234]:5060", "sip:bob@[2001:db8:1234]", URI_CMP_NOMATCH },
2164 /* User comparison is case sensitive. No match */
2165 { "sip:bob@example.com", "sip:BOB@example.com", URI_CMP_NOMATCH },
2166 /* Host comparison is case insensitive. Match */
2167 { "sip:bob@example.com", "sip:bob@EXAMPLE.COM", URI_CMP_MATCH },
2168 /* Add headers to the URI. Identical, so they match */
2169 { "sip:bob@example.com?header1=value1&header2=value2", "sip:bob@example.com?header1=value1&header2=value2", URI_CMP_MATCH },
2170 /* Headers in URI 1 are not in URI 2. No Match */
2171 { "sip:bob@example.com?header1=value1&header2=value2", "sip:bob@example.com", URI_CMP_NOMATCH },
2172 /* Header present in both URIs does not have matching values. No match */
2173 { "sip:bob@example.com?header1=value1&header2=value2", "sip:bob@example.com?header1=value1&header2=value3", URI_CMP_NOMATCH },
2174 /* Add parameters to the URI. Identical so they match */
2175 { "sip:bob@example.com;param1=value1;param2=value2", "sip:bob@example.com;param1=value1;param2=value2", URI_CMP_MATCH },
2176 /* Same parameters in both URIs but appear in different order. Match */
2177 { "sip:bob@example.com;param2=value2;param1=value1", "sip:bob@example.com;param1=value1;param2=value2", URI_CMP_MATCH },
2178 /* params in URI 1 are not in URI 2. Match */
2179 { "sip:bob@example.com;param1=value1;param2=value2", "sip:bob@example.com", URI_CMP_MATCH },
2180 /* param present in both URIs does not have matching values. No match */
2181 { "sip:bob@example.com;param1=value1;param2=value2", "sip:bob@example.com;param1=value1;param2=value3", URI_CMP_NOMATCH },
2182 /* URI 1 has a maddr param but URI 2 does not. No match */
2183 { "sip:bob@example.com;param1=value1;maddr=192.168.0.1", "sip:bob@example.com;param1=value1", URI_CMP_NOMATCH },
2184 /* URI 1 and URI 2 both have identical maddr params. Match */
2185 { "sip:bob@example.com;param1=value1;maddr=192.168.0.1", "sip:bob@example.com;param1=value1;maddr=192.168.0.1", URI_CMP_MATCH },
2186 /* URI 1 is a SIPS URI and URI 2 is a SIP URI. No Match */
2187 { "sips:bob@example.com", "sip:bob@example.com", URI_CMP_NOMATCH },
2188 /* No URI schemes. No match */
2189 { "bob@example.com", "bob@example.com", URI_CMP_NOMATCH },
2190 /* Crashiness tests. Just an address scheme. No match */
2191 { "sip", "sips", URI_CMP_NOMATCH },
2192 /* Still just an address scheme. Even though they're the same, No match */
2193 { "sip", "sip", URI_CMP_NOMATCH },
2194 /* Empty strings. No match */
2195 { "", "", URI_CMP_NOMATCH },
2196 /* An empty string and a NULL. No match */
2197 { "", NULL, URI_CMP_NOMATCH },
2200 int test_res = AST_TEST_PASS;
2203 info->name = "sip_uri_cmp_test";
2204 info->category = "/channels/chan_sip/";
2205 info->summary = "Tests comparison of SIP URIs";
2206 info->description = "Several would-be tricky URI comparisons are performed";
2207 return AST_TEST_NOT_RUN;
2212 for (i = 0; i < ARRAY_LEN(uri_cmp_tests); ++i) {
2215 if ((cmp_res1 = sip_uri_cmp(uri_cmp_tests[i].uri1, uri_cmp_tests[i].uri2))) {
2216 /* URI comparison may return -1 or +1 depending on the failure. Standardize
2217 * the return value to be URI_CMP_NOMATCH on any failure
2219 cmp_res1 = URI_CMP_NOMATCH;
2221 if (cmp_res1 != uri_cmp_tests[i].expected_result) {
2222 ast_test_status_update(test, "Unexpected comparison result for URIs %s and %s. "
2223 "Expected %s but got %s\n", uri_cmp_tests[i].uri1, uri_cmp_tests[i].uri2,
2224 uri_cmp_tests[i].expected_result == URI_CMP_MATCH ? "Match" : "No Match",
2225 cmp_res1 == URI_CMP_MATCH ? "Match" : "No Match");
2226 test_res = AST_TEST_FAIL;
2229 /* All URI comparisons are commutative, so for the sake of being thorough, we'll
2230 * rerun the comparison with the parameters reversed
2232 if ((cmp_res2 = sip_uri_cmp(uri_cmp_tests[i].uri2, uri_cmp_tests[i].uri1))) {
2233 /* URI comparison may return -1 or +1 depending on the failure. Standardize
2234 * the return value to be URI_CMP_NOMATCH on any failure
2236 cmp_res2 = URI_CMP_NOMATCH;
2238 if (cmp_res2 != uri_cmp_tests[i].expected_result) {
2239 ast_test_status_update(test, "Unexpected comparison result for URIs %s and %s. "
2240 "Expected %s but got %s\n", uri_cmp_tests[i].uri2, uri_cmp_tests[i].uri1,
2241 uri_cmp_tests[i].expected_result == URI_CMP_MATCH ? "Match" : "No Match",
2242 cmp_res2 == URI_CMP_MATCH ? "Match" : "No Match");
2243 test_res = AST_TEST_FAIL;
2250 void free_via(struct sip_via *v)
2263 struct sip_via *parse_via(const char *header)
2265 struct sip_via *v = ast_calloc(1, sizeof(*v));
2272 v->via = ast_strdup(header);
2277 if (ast_strlen_zero(via)) {
2278 ast_log(LOG_ERROR, "received request without a Via header\n");
2283 /* seperate the first via-parm */
2284 via = strsep(&via, ",");
2286 /* chop off sent-protocol */
2287 v->protocol = strsep(&via, " \t\r\n");
2288 if (ast_strlen_zero(v->protocol)) {
2289 ast_log(LOG_ERROR, "missing sent-protocol in Via header\n");
2293 v->protocol = ast_skip_blanks(v->protocol);
2296 via = ast_skip_blanks(via);
2299 /* chop off sent-by */
2300 v->sent_by = strsep(&via, "; \t\r\n");
2301 if (ast_strlen_zero(v->sent_by)) {
2302 ast_log(LOG_ERROR, "missing sent-by in Via header\n");
2306 v->sent_by = ast_skip_blanks(v->sent_by);
2308 /* store the port */
2309 if ((parm = strchr(v->sent_by, ':'))) {
2312 v->port = strtol(++parm, &endptr, 10);
2315 /* evaluate any via-parms */
2316 while ((parm = strsep(&via, "; \t\r\n"))) {
2318 if ((c = strstr(parm, "maddr="))) {
2319 v->maddr = ast_skip_blanks(c + sizeof("maddr=") - 1);
2320 } else if ((c = strstr(parm, "branch="))) {
2321 v->branch = ast_skip_blanks(c + sizeof("branch=") - 1);
2322 } else if ((c = strstr(parm, "ttl="))) {
2324 c = ast_skip_blanks(c + sizeof("ttl=") - 1);
2325 v->ttl = strtol(c, &endptr, 10);
2327 /* make sure we got a valid ttl value */
2337 AST_TEST_DEFINE(parse_via_test)
2339 int res = AST_TEST_PASS;
2341 struct sip_via *via;
2344 char *expected_protocol;
2345 char *expected_branch;
2346 char *expected_sent_by;
2347 char *expected_maddr;
2348 unsigned int expected_port;
2349 unsigned char expected_ttl;
2351 AST_LIST_ENTRY(testdata) list;
2353 struct testdata *testdataptr;
2354 static AST_LIST_HEAD_NOLOCK(testdataliststruct, testdata) testdatalist;
2355 struct testdata t1 = {
2356 .in = "SIP/2.0/UDP host:port;branch=thebranch",
2357 .expected_protocol = "SIP/2.0/UDP",
2358 .expected_sent_by = "host:port",
2359 .expected_branch = "thebranch",
2361 struct testdata t2 = {
2362 .in = "SIP/2.0/UDP host:port",
2363 .expected_protocol = "SIP/2.0/UDP",
2364 .expected_sent_by = "host:port",
2365 .expected_branch = "",
2367 struct testdata t3 = {
2368 .in = "SIP/2.0/UDP",
2371 struct testdata t4 = {
2372 .in = "BLAH/BLAH/BLAH host:port;branch=",
2373 .expected_protocol = "BLAH/BLAH/BLAH",
2374 .expected_sent_by = "host:port",
2375 .expected_branch = "",
2377 struct testdata t5 = {
2378 .in = "SIP/2.0/UDP host:5060;branch=thebranch;maddr=224.0.0.1;ttl=1",
2379 .expected_protocol = "SIP/2.0/UDP",
2380 .expected_sent_by = "host:5060",
2381 .expected_port = 5060,
2382 .expected_branch = "thebranch",
2383 .expected_maddr = "224.0.0.1",
2386 struct testdata t6 = {
2387 .in = "SIP/2.0/UDP host:5060;\n branch=thebranch;\r\n maddr=224.0.0.1; ttl=1",
2388 .expected_protocol = "SIP/2.0/UDP",
2389 .expected_sent_by = "host:5060",
2390 .expected_port = 5060,
2391 .expected_branch = "thebranch",
2392 .expected_maddr = "224.0.0.1",
2397 info->name = "parse_via_test";
2398 info->category = "/channels/chan_sip/";
2399 info->summary = "Tests parsing the Via header";
2401 "Runs through various test situations in which various "
2402 " parameters parameter must be extracted from a VIA header";
2403 return AST_TEST_NOT_RUN;
2408 AST_LIST_HEAD_SET_NOLOCK(&testdatalist, &t1);
2409 AST_LIST_INSERT_TAIL(&testdatalist, &t2, list);
2410 AST_LIST_INSERT_TAIL(&testdatalist, &t3, list);
2411 AST_LIST_INSERT_TAIL(&testdatalist, &t4, list);
2412 AST_LIST_INSERT_TAIL(&testdatalist, &t5, list);
2413 AST_LIST_INSERT_TAIL(&testdatalist, &t6, list);
2416 AST_LIST_TRAVERSE(&testdatalist, testdataptr, list) {
2417 via = parse_via(testdataptr->in);
2419 if (!testdataptr->expected_null) {
2420 ast_test_status_update(test, "TEST#%d FAILED: VIA = \"%s\"\n"
2421 "failed to parse header\n",
2422 i, testdataptr->in);
2423 res = AST_TEST_FAIL;
2429 if (testdataptr->expected_null) {
2430 ast_test_status_update(test, "TEST#%d FAILED: VIA = \"%s\"\n"
2431 "successfully parased invalid via header\n",
2432 i, testdataptr->in);
2433 res = AST_TEST_FAIL;
2439 if ((ast_strlen_zero(via->protocol) && !ast_strlen_zero(testdataptr->expected_protocol))
2440 || (!ast_strlen_zero(via->protocol) && strcmp(via->protocol, testdataptr->expected_protocol))) {
2442 ast_test_status_update(test, "TEST#%d FAILED: VIA = \"%s\"\n"
2443 "parsed protocol = \"%s\"\n"
2444 "expected = \"%s\"\n"
2445 "failed to parse protocol\n",
2446 i, testdataptr->in, via->protocol, testdataptr->expected_protocol);
2447 res = AST_TEST_FAIL;
2450 if ((ast_strlen_zero(via->sent_by) && !ast_strlen_zero(testdataptr->expected_sent_by))
2451 || (!ast_strlen_zero(via->sent_by) && strcmp(via->sent_by, testdataptr->expected_sent_by))) {
2453 ast_test_status_update(test, "TEST#%d FAILED: VIA = \"%s\"\n"
2454 "parsed sent_by = \"%s\"\n"
2455 "expected = \"%s\"\n"
2456 "failed to parse sent-by\n",
2457 i, testdataptr->in, via->sent_by, testdataptr->expected_sent_by);
2458 res = AST_TEST_FAIL;
2461 if (testdataptr->expected_port && testdataptr->expected_port != via->port) {
2462 ast_test_status_update(test, "TEST#%d FAILED: VIA = \"%s\"\n"
2463 "parsed port = \"%d\"\n"
2464 "expected = \"%d\"\n"
2465 "failed to parse port\n",
2466 i, testdataptr->in, via->port, testdataptr->expected_port);
2467 res = AST_TEST_FAIL;
2470 if ((ast_strlen_zero(via->branch) && !ast_strlen_zero(testdataptr->expected_branch))
2471 || (!ast_strlen_zero(via->branch) && strcmp(via->branch, testdataptr->expected_branch))) {
2473 ast_test_status_update(test, "TEST#%d FAILED: VIA = \"%s\"\n"
2474 "parsed branch = \"%s\"\n"
2475 "expected = \"%s\"\n"
2476 "failed to parse branch\n",
2477 i, testdataptr->in, via->branch, testdataptr->expected_branch);
2478 res = AST_TEST_FAIL;
2481 if ((ast_strlen_zero(via->maddr) && !ast_strlen_zero(testdataptr->expected_maddr))
2482 || (!ast_strlen_zero(via->maddr) && strcmp(via->maddr, testdataptr->expected_maddr))) {
2484 ast_test_status_update(test, "TEST#%d FAILED: VIA = \"%s\"\n"
2485 "parsed maddr = \"%s\"\n"
2486 "expected = \"%s\"\n"
2487 "failed to parse maddr\n",
2488 i, testdataptr->in, via->maddr, testdataptr->expected_maddr);
2489 res = AST_TEST_FAIL;
2492 if (testdataptr->expected_ttl && testdataptr->expected_ttl != via->ttl) {
2493 ast_test_status_update(test, "TEST#%d FAILED: VIA = \"%s\"\n"
2494 "parsed ttl = \"%d\"\n"
2495 "expected = \"%d\"\n"
2496 "failed to parse ttl\n",
2497 i, testdataptr->in, via->ttl, testdataptr->expected_ttl);
2498 res = AST_TEST_FAIL;
2507 void sip_request_parser_register_tests(void)
2509 AST_TEST_REGISTER(get_calleridname_test);
2510 AST_TEST_REGISTER(sip_parse_uri_test);
2511 AST_TEST_REGISTER(get_in_brackets_test);
2512 AST_TEST_REGISTER(get_name_and_number_test);
2513 AST_TEST_REGISTER(sip_parse_uri_fully_test);
2514 AST_TEST_REGISTER(parse_name_andor_addr_test);
2515 AST_TEST_REGISTER(parse_contact_header_test);
2516 AST_TEST_REGISTER(sip_parse_options_test);
2517 AST_TEST_REGISTER(sip_uri_cmp_test);
2518 AST_TEST_REGISTER(parse_via_test);
2520 void sip_request_parser_unregister_tests(void)
2522 AST_TEST_UNREGISTER(sip_parse_uri_test);
2523 AST_TEST_UNREGISTER(get_calleridname_test);
2524 AST_TEST_UNREGISTER(get_in_brackets_test);
2525 AST_TEST_UNREGISTER(get_name_and_number_test);
2526 AST_TEST_UNREGISTER(sip_parse_uri_fully_test);
2527 AST_TEST_UNREGISTER(parse_name_andor_addr_test);
2528 AST_TEST_UNREGISTER(parse_contact_header_test);
2529 AST_TEST_UNREGISTER(sip_parse_options_test);
2530 AST_TEST_UNREGISTER(sip_uri_cmp_test);
2531 AST_TEST_UNREGISTER(parse_via_test);
2534 int sip_reqresp_parser_init(void)
2536 #ifdef HAVE_XLOCALE_H
2537 c_locale = newlocale(LC_CTYPE_MASK, "C", NULL);
2545 void sip_reqresp_parser_exit(void)
2547 #ifdef HAVE_XLOCALE_H
2549 freelocale(c_locale);