1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
|
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <memory>
#include <iostream>
#include "TestSupport.hxx"
#include "resip/stack/UnknownParameterType.hxx"
#include "resip/stack/Uri.hxx"
#include "rutil/DataStream.hxx"
#include "rutil/Logger.hxx"
#include "rutil/DnsUtil.hxx"
#include "rutil/ParseBuffer.hxx"
#include "resip/stack/SipMessage.hxx"
#include "resip/stack/Helper.hxx"
using namespace resip;
using namespace std;
#define RESIPROCATE_SUBSYSTEM Subsystem::TEST
int
main(int argc, char* argv[])
{
Log::Level l = Log::Debug;
Log::initialize(Log::Cerr, l, argv[0]);
initNetwork();
{
Uri uri("sip:speedy_AT_home.com@whistler.gloo.net:5062");
uri.scheme() = Symbols::Pres;
assert(Data::from(uri) == "pres:speedy_AT_home.com@whistler.gloo.net:5062");
}
{
const char * a = "alice";
const char * e = "example.com";
NameAddr alice;
alice.uri().user() = a;
alice.uri().host() = e;
NameAddr realm;
realm.uri().host() = e;
NameAddr aliceContact;
aliceContact.uri().user() = a;
aliceContact.uri().host() = "127.1.0.1";
aliceContact.uri().port() = 32678;
auto_ptr<SipMessage> msg(Helper::makeRegister(alice,alice,aliceContact));
cout << *msg << endl;
// Make the data
NameAddr original(aliceContact);
original.uri().param(UnknownParameterType("x")) = Data("\"1\"");
Uri tmp = original.uri();
Data buf;
DataStream oldNA(buf);
oldNA << Symbols::LA_QUOTE;
oldNA << original.uri().scheme();
oldNA << Symbols::COLON;
oldNA << original.uri().getAor();
oldNA << Symbols::RA_QUOTE;
oldNA.flush();
NameAddr modified;
modified.uri() = tmp; // copy parameters;
modified.uri().host() = e;
modified.uri().port() = 65530;
modified.uri().user() = "alphabet-soup";
Data gruuData ( Data::from(modified.uri())) ;
msg->header(h_Contacts).back().param(p_pubGruu) = gruuData;
cout << *msg << endl;
Uri s1("sip:alice@example.com;gr=\"foo@example.com\"");
Uri s2("sip:alice@example.com;gr=\"foo@example.com\"");
assert(s1.param(p_gr) == Data("foo@example.com"));
assert(s2.param(p_gr) == Data("foo@example.com"));
cout << s1 << endl;
cout << s2 << endl;
cout << endl;
Uri s3("sip:alice@example.com");
s3.param(UnknownParameterType("foo")) = Data("value");
Uri s4("sip:alice@example.com");
s4.param(UnknownParameterType("foo")) = Data("\"value\"");
cout << "s3's param =" << s3.param(UnknownParameterType("foo")) << endl;
cout << "s4's param =" << s4.param(UnknownParameterType("foo")) << endl;
cout << "s3 = " << s3 << endl;
cout << "s4 = " << s4 << endl;
Uri s5(s4);
cout << "s5 = " << s5 << endl;
Data s5d(Data::from(s5));
cout << "s5d = " << s5d << endl;
Uri s6("sip:bob@example.com");
s6.host();
Uri s7("sip:testproxy.example.com");
assert (s7.user().empty());
s7.user() = "test";
assert (!s7.user().empty());
s7.user().clear();
assert (s7.user().empty());
NameAddr na1;
na1.uri().user() = "alice";
na1.uri().host() = "example.com";
Data q("\"");
na1.param(UnknownParameterType("foo")) = Data(q + Data::from(s6) +q);
NameAddr na2(na1);
cout << "na1=" << na1 << endl;
cout << "na2=" << na2 << endl;
}
//assert(0);
{
// Test order irrelevance of known parameters
Uri sip1("sip:user@domain;ttl=15;method=foo");
Uri sip2("sip:user@domain;method=foo;ttl=15");
cerr << "!!" << sip1.host() << endl;
cerr << "!!" << sip2.host() << endl;
assert (sip1 == sip2);
assert (sip2 == sip1);
}
{
assert(DnsUtil::isIpV6Address("::1"));
}
#ifdef USE_IPV6
{
cerr << "!! " << DnsUtil::canonicalizeIpV6Address("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210") << endl;
assert(DnsUtil::canonicalizeIpV6Address("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210") ==
"fedc:ba98:7654:3210:fedc:ba98:7654:3210");
}
{
cerr << "!! " << DnsUtil::canonicalizeIpV6Address("5f1b:df00:ce3e:e200:20:800:121.12.131.12") << endl;
assert(DnsUtil::canonicalizeIpV6Address("5f1b:df00:ce3e:e200:20:800:121.12.131.12") ==
"5f1b:df00:ce3e:e200:20:800:790c:830c");
}
{
cerr << "!! " << DnsUtil::canonicalizeIpV6Address("5f1B::20:800:121.12.131.12") << endl;
assert(DnsUtil::canonicalizeIpV6Address("5f1B::20:800:121.12.131.12") ==
"5f1b::20:800:790c:830c");
}
{
Uri uri("sip:[5f1b:df00:ce3e:e200:20:800:121.12.131.12]");
cerr << "!! " << uri.host() << endl;
assert(uri.host() == "5f1b:df00:ce3e:e200:20:800:121.12.131.12");
cerr << "!! " << Data::from(uri) << endl;
assert(Data::from(uri) == "sip:[5f1b:df00:ce3e:e200:20:800:121.12.131.12]");
}
{
Uri uri("sip:user@[5f1b:df00:ce3e:e200:20:800:121.12.131.12]");
cerr << "!! " << uri.host() << endl;
assert(uri.host() == "5f1b:df00:ce3e:e200:20:800:121.12.131.12");
cerr << "!! " << Data::from(uri) << endl;
assert(Data::from(uri) == "sip:user@[5f1b:df00:ce3e:e200:20:800:121.12.131.12]");
}
#endif
{
Uri uri("sips:192.168.2.12");
assert(uri.scheme() == "sips");
assert(uri.password() == "");
assert(uri.userParameters() == "");
assert(uri.host() == "192.168.2.12");
assert(uri.port() == 0);
}
{
Uri uri("sips:host.foo.com");
assert(uri.scheme() == "sips");
assert(uri.password() == "");
assert(uri.userParameters() == "");
assert(uri.host() == "host.foo.com");
assert(uri.port() == 0);
}
{
Uri uri("sip:user;x-v17:password@host.com:5555");
cerr << "user!!" << uri.user() << endl;
cerr << "password!!" << uri.password() << endl;
cerr << "userParams!!" << uri.userParameters() << endl;
assert(uri.scheme() == "sip");
assert(uri.user() == "user;x-v17");
assert(uri.password() == "password");
assert(uri.userParameters() == "");
assert(uri.host() == "host.com");
assert(uri.port() == 5555);
}
{
// test bad parses
try
{
Uri("noscheme@foo.com:1202");
assert(false);
}
catch (ParseException& e)
{
}
}
{
Uri w1("sip:wombat@192.168.2.221:5062;transport=Udp");
Uri w2("sip:wombat@192.168.2.221:5063;transport=Udp");
assert(w1 != w2);
assert(w1 < w2);
}
{
Uri tel("tel:+358-555-1234567;pOstd=pP2;isUb=1411");
assert(tel.user() == "+358-555-1234567");
assert(Data::from(tel) == "tel:+358-555-1234567;pOstd=pP2;isUb=1411");
}
{
Uri tel("tel:+358-555-1234567;pOstd=pP2;isUb=1411");
Uri sip(Uri::fromTel(tel, Uri("sip:company.com")));
cerr << "!! " << Data::from(sip) << endl;
assert(Data::from(sip) == "sip:+358-555-1234567;isub=1411;postd=pp2@company.com;user=phone");
}
{
Uri tel("tel:+358-555-1234567;foo=bar;aaaa=baz;pOstd=pP2;isUb=1411");
Uri sip(Uri::fromTel(tel, Uri("sip:company.com")));
cerr << "!! " << Data::from(sip) << endl;
assert(Data::from(sip) == "sip:+358-555-1234567;isub=1411;postd=pp2;aaaa=baz;foo=bar@company.com;user=phone");
}
{
Uri tel("tel:+358-555-1234567;postd=pp22");
Uri sip(Uri::fromTel(tel, Uri("sip:foo.com")));
assert(Data::from(sip) == "sip:+358-555-1234567;postd=pp22@foo.com;user=phone");
}
{
Uri tel1("tel:+358-555-1234567;postd=pp22");
Uri tel2("tel:+358-555-1234567;POSTD=PP22");
cerr << "tel1=" << tel1 << " user=" << tel1.user() << endl;
cerr << "tel2=" << tel2 << " user=" << tel2.user() << endl;
assert (tel1 == tel2);
}
{
Uri tel1("sip:+358-555-1234567;postd=pp22@foo.com;user=phone");
Uri tel2("sip:+358-555-1234567;POSTD=PP22@foo.com;user=phone");
assert (tel1 != tel2);
}
{
Uri tel1("tel:+358-555-1234567;postd=pp22;isub=1411");
Uri tel2("tel:+358-555-1234567;isub=1411;postd=pp22");
// requires us to parse the user parameters
//assert (tel1 == tel2);
}
{
Uri tel1("sip:+358-555-1234567;postd=pp22;isub=1411@foo.com;user=phone");
Uri tel2("sip:+358-555-1234567;isub=1411;postd=pp22@foo.com;user=phone");
assert (tel1 != tel2);
}
{
Uri tel1("tel:+358-555-1234567;postd=pp22");
Uri tel2("tel:+358-555-1234567;POSTD=PP22");
Uri sip1(Uri::fromTel(tel1, Uri("sip:foo.com")));
Uri sip2(Uri::fromTel(tel2, Uri("sip:foo.com")));
assert (sip1 == sip2);
assert (Data::from(sip1) == "sip:+358-555-1234567;postd=pp22@foo.com;user=phone");
assert (Data::from(sip2) == "sip:+358-555-1234567;postd=pp22@foo.com;user=phone");
}
{
Uri tel1("tel:+358-555-1234567;tsp=a.b;phone-context=5");
Uri tel2("tel:+358-555-1234567;phone-context=5;tsp=a.b");
Uri sip1(Uri::fromTel(tel1, Uri("sip:foo.com")));
Uri sip2(Uri::fromTel(tel2, Uri("sip:foo.com")));
assert (sip1 == sip2);
assert (Data::from(sip1) == "sip:+358-555-1234567;phone-context=5;tsp=a.b@foo.com;user=phone");
assert (Data::from(sip2) == "sip:+358-555-1234567;phone-context=5;tsp=a.b@foo.com;user=phone");
}
{
Uri uri("sip:fluffy@iii.ca:666");
assert(uri.scheme() == "sip");
assert(uri.user() == "fluffy");
assert(uri.host() == "iii.ca");
assert(uri.port() == 666);
}
{
Uri uri("sip:fluffy@iii.ca;transport=tcp");
assert(uri.param(p_transport) == "tcp");
}
{
Uri uri("sips:fluffy@iii.ca;transport=tls");
assert(uri.scheme() == "sips");
assert(uri.param(p_transport) == "tls");
}
{
Uri uri("sip:fluffy@iii.ca;transport=sctp");
assert(uri.param(p_transport) == "sctp");
}
{
Uri uri("sip:fluffy:password@iii.ca");
assert(uri.password() == "password");
}
{
Uri uri("sip:fluffy@iii.ca;user=phone;ttl=5;lr;maddr=1.2.3.4");
assert(uri.param(p_ttl) == 5);
assert(uri.exists(p_lr) == true);
assert(uri.param(p_maddr) == "1.2.3.4");
assert(uri.param(p_user) == "phone");
}
{
Uri uri("sip:fluffy@iii.ca;x-fluffy=foo");
assert(uri.exists(UnknownParameterType("x-fluffy")) == true);
assert(uri.exists(UnknownParameterType("x-fufu")) == false);
assert(uri.param(UnknownParameterType("x-fluffy")) == "foo");
}
{
Uri uri("sip:fluffy@iii.ca;method=MESSAGE");
assert(uri.param(p_method) == "MESSAGE");
}
{
Uri uri("sip:+1(408) 444-1212:666@gw1");
assert(uri.user() == "+1(408) 444-1212");
assert(uri.password() == "666");
assert(uri.host() == "gw1");
}
{
Uri uri("sip:fluffy;x-utag=foo@iii.ca");
assert(uri.user() == "fluffy;x-utag=foo");
assert(uri.host() == "iii.ca");
Data out(Data::from(uri));
assert(out == "sip:fluffy;x-utag=foo@iii.ca");
}
{
Uri uri("sip:fluffy;x-utag=foo:password@iii.ca");
assert(uri.user() == "fluffy;x-utag=foo");
assert(uri.host() == "iii.ca");
assert(uri.password() == "password");
Data out(Data::from(uri));
cerr << "!! " << out << endl;
assert(out == "sip:fluffy;x-utag=foo:password@iii.ca");
}
{
Uri uri("tel:+14086661212");
assert(uri.user() == "+14086661212");
assert(uri.userParameters() == "");
assert(uri.host() == "");
assert(uri.password() == "");
Data out(Data::from(uri));
cerr << "!! " << out << endl;
assert(out == "tel:+14086661212");
}
{
Uri uri("tel:+14086661212;foo=bie");
assert(uri.user() == "+14086661212");
assert(uri.userParameters() == "foo=bie");
assert(uri.host() == "");
assert(uri.password() == "");
Data out(Data::from(uri));
cerr << "!! " << out << endl;
assert(out == "tel:+14086661212;foo=bie");
}
{
Uri uri("tel:+14086661212;");
assert(uri.user() == "+14086661212");
assert(uri.userParameters() == "");
assert(uri.host() == "");
assert(uri.password() == "");
Data out(Data::from(uri));
cerr << "!! " << out << endl;
assert(out == "tel:+14086661212");
}
{
Uri uri("sip:;:@");
cerr << "uri.user() = " << uri.user() << endl;
assert(uri.user() == ";");
assert(uri.userParameters() == "");
assert(uri.host() == "");
assert(uri.password() == "");
Data out(Data::from(uri));
cerr << "!! " << out << endl;
assert(out == "sip:;");
}
{
Uri uri("tel:+1 (408) 555-1212");
assert(uri.scheme() == "tel");
}
// Tests for user-less uris (was broken accidentally v1.44 Uri.cxx)
{
Data original("sip:1.2.3.4:5060");
Data encoded;
Uri uri(original);
DataStream ds(encoded);
uri.encode(ds);
ds.flush();
cout << "!! original data: " << original << endl;
cout << "!! original uri : " << uri << endl;
cout << "!! encoded data: " << encoded << endl;
assert( encoded == original );
}
{
// Test order irrelevance of unknown parameters
Uri sip1("sip:user@domain;foo=bar;baz=qux");
Uri sip2("sip:user@domain;baz=qux;foo=bar");
assert (sip1 == sip2);
assert (sip2 == sip1);
}
{
// Test order irrelevance of known parameters
Uri sip1("sip:user@domain;ttl=15;method=foo");
Uri sip2("sip:user@domain;method=foo;ttl=15");
assert (sip1 == sip2);
assert (sip2 == sip1);
}
// tests from 3261 19.1.4
{
Uri sip1("sip:alice@atlanta.com;transport=TCP");
Uri sip2("sip:alice@AtLanTa.CoM;Transport=tcp");
assert(sip1 == sip2);
assert(sip2 == sip1);
}
{
Uri sip1("sip:carol@chicago.com");
Uri sip2("sip:carol@chicago.com;newparam=5");
Uri sip3("sip:carol@chicago.com;security=on");
assert(sip1 == sip2);
assert(sip2 == sip1);
assert(sip2 == sip3);
assert(sip3 == sip2);
assert(sip3 == sip1);
assert(sip1 == sip3);
}
{
Uri sip1("sip:biloxi.com;transport=tcp;method=REGISTER?to=sip:bob%40biloxi.com");
Uri sip2("sip:biloxi.com;method=REGISTER;transport=tcp?to=sip:bob%40biloxi.com");
assert(sip1 == sip2);
assert(sip2 == sip1);
}
{
Uri sip1("sip:alice@atlanta.com?subject=project%20x&priority=urgent");
Uri sip2("sip:alice@atlanta.com?priority=urgent&subject=project%20x");
assert(sip1 == sip2);
assert(sip2 == sip1);
}
{
Uri sip1("SIP:ALICE@AtLanTa.CoM;Transport=udp"); // (different usernames)
Uri sip2("sip:alice@AtLanTa.CoM;Transport=UDP");
assert(sip1 != sip2);
}
{
Uri sip1("sip:bob@biloxi.com"); // (can resolve to different ports)
Uri sip2("sip:bob@biloxi.com:5060");
assert(sip1 != sip2);
}
{
Uri sip1("sip:bob@biloxi.com"); // (can resolve to different transports)
Uri sip2("sip:bob@biloxi.com;transport=udp");
assert(sip1 != sip2);
}
{
Uri sip1("sip:bob@biloxi.com"); // (can resolve to different port and transports)
Uri sip2("sip:bob@biloxi.com:6000;transport=tcp");
assert(sip1 != sip2);
}
// !dlb! we ignore embedded headers at the moment
if (false)
{
Uri sip1("sip:carol@chicago.com"); // (different header component)
Uri sip2("sip:carol@chicago.com?Subject=next%20meeting");
assert(sip1 != sip2);
}
{
Uri sip1("sip:bob@phone21.boxesbybob.com"); // (even though that's what phone21.boxesbybob.com resolves to)
Uri sip2("sip:bob@192.0.2.4");
assert(sip1 != sip2);
}
{
Uri sip1("sip:carol@chicago.com");
Uri sip2("sip:carol@chicago.com;security=on");
Uri sip3("sip:carol@chicago.com;security=off");
assert(sip1 == sip2);
assert(sip1 == sip3);
assert(sip2 != sip3);
assert(sip3 != sip2);
}
{
Uri sip1("sip:carol@chicago.com");
Uri sip2("sip:carol@chicago.com:5060");
Uri sip3("sip:1.2.3.4");
Uri sip4("sip:1.2.3.4:5070");
Uri sip1a("sip:carol@chicago.com;user=phone;foo=bar");
Uri sip2a("sip:carol@chicago.com:5060;user=phone;foo=bar");
Uri sip3a("sip:1.2.3.4;user=phone;foo=bar");
Uri sip4a("sip:1.2.3.4:5070;user=phone;foo=bar");
DebugLog( << "sip1.getAor==" << sip1.getAor() );
DebugLog( << "sip1.getAorNoPort==" << sip1.getAorNoPort() );
DebugLog( << "sip2.getAor==" << sip2.getAor() );
DebugLog( << "sip2.getAorNoPort==" << sip2.getAorNoPort() );
assert( sip1.getAor() == Data("carol@chicago.com") );
assert( sip2.getAor() == Data("carol@chicago.com:5060") );
assert( sip3.getAor() == Data("1.2.3.4") );
assert( sip4.getAor() == Data("1.2.3.4:5070") );
assert( sip1a.getAor() == Data("carol@chicago.com") );
assert( sip2a.getAor() == Data("carol@chicago.com:5060") );
assert( sip3a.getAor() == Data("1.2.3.4") );
assert( sip4a.getAor() == Data("1.2.3.4:5070") );
assert( sip1.getAorNoPort() == Data("carol@chicago.com") );
assert( sip2.getAorNoPort() == Data("carol@chicago.com") );
assert( sip3.getAorNoPort() == Data("1.2.3.4") );
assert( sip4.getAorNoPort() == Data("1.2.3.4") );
assert( sip1a.getAorNoPort() == Data("carol@chicago.com") );
assert( sip2a.getAorNoPort() == Data("carol@chicago.com") );
assert( sip3a.getAorNoPort() == Data("1.2.3.4") );
assert( sip4a.getAorNoPort() == Data("1.2.3.4") );
}
// Displayname parse tests
{
NameAddr sip1("\"DispName\" <sip:user@host.com>");
NameAddr sip2("\"DispName \"<sip:user@host.com>");
NameAddr sip3("\" DispName\"<sip:user@host.com>");
NameAddr sip4("DispName <sip:user@host.com>");
NameAddr sip5("DispName<sip:user@host.com>");
NameAddr sip6(" DispName <sip:user@host.com>");
NameAddr sip7(" DispName<sip:user@host.com>");
NameAddr sip8(" Disp Name <sip:user@host.com>");
DebugLog( << "sip1.displayName=='" << sip1.displayName() << "'" );
DebugLog( << "sip2.displayName=='" << sip2.displayName() << "'" );
DebugLog( << "sip3.displayName=='" << sip3.displayName() << "'" );
DebugLog( << "sip4.displayName=='" << sip4.displayName() << "'" );
DebugLog( << "sip5.displayName=='" << sip5.displayName() << "'" );
DebugLog( << "sip6.displayName=='" << sip6.displayName() << "'" );
DebugLog( << "sip7.displayName=='" << sip7.displayName() << "'" );
DebugLog( << "sip8.displayName=='" << sip8.displayName() << "'" );
assert( sip1.displayName() == Data("DispName") );
assert( sip2.displayName() == Data("DispName ") );
assert( sip3.displayName() == Data(" DispName") );
assert( sip4.displayName() == Data("DispName") );
assert( sip5.displayName() == Data("DispName") );
assert( sip6.displayName() == Data("DispName") );
assert( sip7.displayName() == Data("DispName") );
assert( sip8.displayName() == Data("Disp Name") );
assert( sip1.uri().getAor() == Data("user@host.com") );
assert( sip2.uri().getAor() == Data("user@host.com") );
assert( sip3.uri().getAor() == Data("user@host.com") );
assert( sip4.uri().getAor() == Data("user@host.com") );
assert( sip5.uri().getAor() == Data("user@host.com") );
assert( sip6.uri().getAor() == Data("user@host.com") );
assert( sip7.uri().getAor() == Data("user@host.com") );
assert( sip8.uri().getAor() == Data("user@host.com") );
}
// Embedded header testing
{
NameAddr addr("sip:user@domain.com?Call-Info=%3csip:192.168.0.1%3e%3banswer-after=0");
//cout << addr << endl;
assert(Data::from(addr.uri()) == "sip:user@domain.com?Call-Info=%3csip:192.168.0.1%3e%3banswer-after=0");
//cout << "CallInfo: " << addr.uri().embedded().header(h_CallInfos).front() << endl;
assert(Data::from(addr.uri().embedded().header(h_CallInfos).front()) == "<sip:192.168.0.1>;answer-after=0");
}
// URI containing special character #
// technically, # is meant to be encoded, but some systems (Asterisk,
// some Cisco gear) seem to send this un-encoded
// Some carriers insert # between a phone number and a billing prefix
{
Uri uri = Uri("sip:1234#00442031111111@lvdx.com");
//cout << "Encoded correctly: " << uri << endl;
assert(Data::from(uri) == "sip:1234%2300442031111111@lvdx.com");
Uri::setUriUserEncoding('#', false);
uri = Uri("sip:1234#00442031111111@lvdx.com");
//cout << "Non Encoded # for compatibility: " << uri << endl;
assert(Data::from(uri) == "sip:1234#00442031111111@lvdx.com");
Uri::setUriUserEncoding('#', true);
}
{
Uri uri = Uri("sip:1234#00442031111111;phone-context=+89@lvdx.com");
assert(uri.userIsTelephoneSubscriber());
Token telSub(uri.getUserAsTelephoneSubscriber());
assert(telSub.value()=="1234#00442031111111");
static ExtensionParameter p_phoneContext("phone-context");
assert(telSub.exists(p_phoneContext));
assert(telSub.param(p_phoneContext)=="+89");
telSub.param(p_phoneContext)="+98";
uri.setUserAsTelephoneSubscriber(telSub);
assert(Data::from(uri) == "sip:1234%2300442031111111;phone-context=+98@lvdx.com");
}
{
Uri uri = Uri("sip:+1-(234)-00442031111111@lvdx.com");
assert(uri.userIsTelephoneSubscriber());
Token telSub(uri.getUserAsTelephoneSubscriber());
assert(telSub.value()=="+1-(234)-00442031111111");
assert(!telSub.exists(p_extension));
telSub.param(p_extension)="4545";
uri.setUserAsTelephoneSubscriber(telSub);
assert(Data::from(uri) == "sip:+1-(234)-00442031111111;ext=4545@lvdx.com");
}
cerr << endl << "All OK" << endl;
return 0;
}
/* ====================================================================
* The Vovida Software License, Version 1.0
*
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
* and "Vovida Open Communication Application Library (VOCAL)" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact vocal@vovida.org.
*
* 4. Products derived from this software may not be called "VOCAL", nor
* may "VOCAL" appear in their name, without prior written
* permission of Vovida Networks, Inc.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by Vovida
* Networks, Inc. and many individuals on behalf of Vovida Networks,
* Inc. For more information on Vovida Networks, Inc., please see
* <http://www.vovida.org/>.
*
*/
|