|
reSIProcate/stack
9694
|
00001 #ifdef HAVE_CONFIG_H 00002 #include "config.h" 00003 #endif 00004 00005 #include <memory> 00006 #include <iostream> 00007 00008 #include "TestSupport.hxx" 00009 #include "resip/stack/UnknownParameterType.hxx" 00010 #include "resip/stack/Uri.hxx" 00011 #include "rutil/DataStream.hxx" 00012 #include "rutil/Logger.hxx" 00013 #include "rutil/DnsUtil.hxx" 00014 #include "rutil/ParseBuffer.hxx" 00015 #include "resip/stack/SipMessage.hxx" 00016 #include "resip/stack/Helper.hxx" 00017 00018 using namespace resip; 00019 using namespace std; 00020 00021 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST 00022 00023 int 00024 main(int argc, char* argv[]) 00025 { 00026 Log::Level l = Log::Debug; 00027 Log::initialize(Log::Cerr, l, argv[0]); 00028 initNetwork(); 00029 00030 { 00031 Uri uri("sip:speedy_AT_home.com@whistler.gloo.net:5062"); 00032 uri.scheme() = Symbols::Pres; 00033 assert(Data::from(uri) == "pres:speedy_AT_home.com@whistler.gloo.net:5062"); 00034 } 00035 { 00036 const char * a = "alice"; 00037 const char * e = "example.com"; 00038 00039 NameAddr alice; 00040 alice.uri().user() = a; 00041 alice.uri().host() = e; 00042 00043 NameAddr realm; 00044 realm.uri().host() = e; 00045 00046 NameAddr aliceContact; 00047 aliceContact.uri().user() = a; 00048 aliceContact.uri().host() = "127.1.0.1"; 00049 aliceContact.uri().port() = 32678; 00050 00051 00052 00053 auto_ptr<SipMessage> msg(Helper::makeRegister(alice,alice,aliceContact)); 00054 00055 cout << *msg << endl; 00056 00057 // Make the data 00058 NameAddr original(aliceContact); 00059 original.uri().param(UnknownParameterType("x")) = Data("\"1\""); 00060 00061 Uri tmp = original.uri(); 00062 Data buf; 00063 DataStream oldNA(buf); 00064 oldNA << Symbols::LA_QUOTE; 00065 oldNA << original.uri().scheme(); 00066 oldNA << Symbols::COLON; 00067 oldNA << original.uri().getAor(); 00068 oldNA << Symbols::RA_QUOTE; 00069 oldNA.flush(); 00070 00071 NameAddr modified; 00072 modified.uri() = tmp; // copy parameters; 00073 modified.uri().host() = e; 00074 modified.uri().port() = 65530; 00075 modified.uri().user() = "alphabet-soup"; 00076 00077 Data gruuData ( Data::from(modified.uri())) ; 00078 msg->header(h_Contacts).back().param(p_pubGruu) = gruuData; 00079 00080 00081 cout << *msg << endl; 00082 00083 Uri s1("sip:alice@example.com;gr=\"foo@example.com\""); 00084 Uri s2("sip:alice@example.com;gr=\"foo@example.com\""); 00085 assert(s1.param(p_gr) == Data("foo@example.com")); 00086 assert(s2.param(p_gr) == Data("foo@example.com")); 00087 cout << s1 << endl; 00088 cout << s2 << endl; 00089 cout << endl; 00090 Uri s3("sip:alice@example.com"); 00091 s3.param(UnknownParameterType("foo")) = Data("value"); 00092 Uri s4("sip:alice@example.com"); 00093 s4.param(UnknownParameterType("foo")) = Data("\"value\""); 00094 cout << "s3's param =" << s3.param(UnknownParameterType("foo")) << endl; 00095 cout << "s4's param =" << s4.param(UnknownParameterType("foo")) << endl; 00096 cout << "s3 = " << s3 << endl; 00097 cout << "s4 = " << s4 << endl; 00098 Uri s5(s4); 00099 cout << "s5 = " << s5 << endl; 00100 Data s5d(Data::from(s5)); 00101 cout << "s5d = " << s5d << endl; 00102 00103 Uri s6("sip:bob@example.com"); 00104 s6.host(); 00105 00106 Uri s7("sip:testproxy.example.com"); 00107 assert (s7.user().empty()); 00108 s7.user() = "test"; 00109 assert (!s7.user().empty()); 00110 s7.user().clear(); 00111 assert (s7.user().empty()); 00112 00113 NameAddr na1; 00114 na1.uri().user() = "alice"; 00115 na1.uri().host() = "example.com"; 00116 00117 Data q("\""); 00118 na1.param(UnknownParameterType("foo")) = Data(q + Data::from(s6) +q); 00119 NameAddr na2(na1); 00120 cout << "na1=" << na1 << endl; 00121 cout << "na2=" << na2 << endl; 00122 00123 } 00124 //assert(0); 00125 { 00126 // Test order irrelevance of known parameters 00127 Uri sip1("sip:user@domain;ttl=15;method=foo"); 00128 Uri sip2("sip:user@domain;method=foo;ttl=15"); 00129 00130 cerr << "!!" << sip1.host() << endl; 00131 cerr << "!!" << sip2.host() << endl; 00132 00133 assert (sip1 == sip2); 00134 assert (sip2 == sip1); 00135 } 00136 00137 { 00138 assert(DnsUtil::isIpV6Address("::1")); 00139 } 00140 00141 #ifdef USE_IPV6 00142 { 00143 cerr << "!! " << DnsUtil::canonicalizeIpV6Address("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210") << endl; 00144 assert(DnsUtil::canonicalizeIpV6Address("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210") == 00145 "fedc:ba98:7654:3210:fedc:ba98:7654:3210"); 00146 } 00147 00148 { 00149 cerr << "!! " << DnsUtil::canonicalizeIpV6Address("5f1b:df00:ce3e:e200:20:800:121.12.131.12") << endl; 00150 assert(DnsUtil::canonicalizeIpV6Address("5f1b:df00:ce3e:e200:20:800:121.12.131.12") == 00151 "5f1b:df00:ce3e:e200:20:800:790c:830c"); 00152 } 00153 00154 { 00155 cerr << "!! " << DnsUtil::canonicalizeIpV6Address("5f1B::20:800:121.12.131.12") << endl; 00156 assert(DnsUtil::canonicalizeIpV6Address("5f1B::20:800:121.12.131.12") == 00157 "5f1b::20:800:790c:830c"); 00158 } 00159 00160 { 00161 Uri uri("sip:[5f1b:df00:ce3e:e200:20:800:121.12.131.12]"); 00162 00163 cerr << "!! " << uri.host() << endl; 00164 assert(uri.host() == "5f1b:df00:ce3e:e200:20:800:121.12.131.12"); 00165 cerr << "!! " << Data::from(uri) << endl; 00166 assert(Data::from(uri) == "sip:[5f1b:df00:ce3e:e200:20:800:121.12.131.12]"); 00167 } 00168 00169 { 00170 Uri uri("sip:user@[5f1b:df00:ce3e:e200:20:800:121.12.131.12]"); 00171 00172 cerr << "!! " << uri.host() << endl; 00173 assert(uri.host() == "5f1b:df00:ce3e:e200:20:800:121.12.131.12"); 00174 cerr << "!! " << Data::from(uri) << endl; 00175 assert(Data::from(uri) == "sip:user@[5f1b:df00:ce3e:e200:20:800:121.12.131.12]"); 00176 } 00177 #endif 00178 00179 { 00180 Uri uri("sips:192.168.2.12"); 00181 00182 assert(uri.scheme() == "sips"); 00183 assert(uri.password() == ""); 00184 assert(uri.userParameters() == ""); 00185 assert(uri.host() == "192.168.2.12"); 00186 assert(uri.port() == 0); 00187 } 00188 00189 { 00190 Uri uri("sips:host.foo.com"); 00191 assert(uri.scheme() == "sips"); 00192 assert(uri.password() == ""); 00193 assert(uri.userParameters() == ""); 00194 assert(uri.host() == "host.foo.com"); 00195 assert(uri.port() == 0); 00196 } 00197 00198 { 00199 Uri uri("sip:user;x-v17:password@host.com:5555"); 00200 00201 cerr << "user!!" << uri.user() << endl; 00202 cerr << "password!!" << uri.password() << endl; 00203 cerr << "userParams!!" << uri.userParameters() << endl; 00204 00205 assert(uri.scheme() == "sip"); 00206 assert(uri.user() == "user;x-v17"); 00207 assert(uri.password() == "password"); 00208 assert(uri.userParameters() == ""); 00209 assert(uri.host() == "host.com"); 00210 assert(uri.port() == 5555); 00211 } 00212 00213 { 00214 // test bad parses 00215 try 00216 { 00217 Uri("noscheme@foo.com:1202"); 00218 assert(false); 00219 } 00220 catch (ParseException& e) 00221 { 00222 } 00223 } 00224 00225 { 00226 Uri w1("sip:wombat@192.168.2.221:5062;transport=Udp"); 00227 Uri w2("sip:wombat@192.168.2.221:5063;transport=Udp"); 00228 assert(w1 != w2); 00229 assert(w1 < w2); 00230 } 00231 { 00232 Uri tel("tel:+358-555-1234567;pOstd=pP2;isUb=1411"); 00233 assert(tel.user() == "+358-555-1234567"); 00234 00235 assert(Data::from(tel) == "tel:+358-555-1234567;pOstd=pP2;isUb=1411"); 00236 } 00237 00238 { 00239 Uri tel("tel:+358-555-1234567;pOstd=pP2;isUb=1411"); 00240 Uri sip(Uri::fromTel(tel, Uri("sip:company.com"))); 00241 00242 cerr << "!! " << Data::from(sip) << endl; 00243 assert(Data::from(sip) == "sip:+358-555-1234567;isub=1411;postd=pp2@company.com;user=phone"); 00244 } 00245 00246 { 00247 Uri tel("tel:+358-555-1234567;foo=bar;aaaa=baz;pOstd=pP2;isUb=1411"); 00248 Uri sip(Uri::fromTel(tel, Uri("sip:company.com"))); 00249 00250 cerr << "!! " << Data::from(sip) << endl; 00251 assert(Data::from(sip) == "sip:+358-555-1234567;isub=1411;postd=pp2;aaaa=baz;foo=bar@company.com;user=phone"); 00252 } 00253 00254 { 00255 Uri tel("tel:+358-555-1234567;postd=pp22"); 00256 Uri sip(Uri::fromTel(tel, Uri("sip:foo.com"))); 00257 assert(Data::from(sip) == "sip:+358-555-1234567;postd=pp22@foo.com;user=phone"); 00258 } 00259 { 00260 Uri tel1("tel:+358-555-1234567;postd=pp22"); 00261 Uri tel2("tel:+358-555-1234567;POSTD=PP22"); 00262 cerr << "tel1=" << tel1 << " user=" << tel1.user() << endl; 00263 cerr << "tel2=" << tel2 << " user=" << tel2.user() << endl; 00264 assert (tel1 == tel2); 00265 } 00266 { 00267 Uri tel1("sip:+358-555-1234567;postd=pp22@foo.com;user=phone"); 00268 Uri tel2("sip:+358-555-1234567;POSTD=PP22@foo.com;user=phone"); 00269 assert (tel1 != tel2); 00270 } 00271 { 00272 Uri tel1("tel:+358-555-1234567;postd=pp22;isub=1411"); 00273 Uri tel2("tel:+358-555-1234567;isub=1411;postd=pp22"); 00274 // requires us to parse the user parameters 00275 //assert (tel1 == tel2); 00276 } 00277 { 00278 Uri tel1("sip:+358-555-1234567;postd=pp22;isub=1411@foo.com;user=phone"); 00279 Uri tel2("sip:+358-555-1234567;isub=1411;postd=pp22@foo.com;user=phone"); 00280 assert (tel1 != tel2); 00281 } 00282 { 00283 Uri tel1("tel:+358-555-1234567;postd=pp22"); 00284 Uri tel2("tel:+358-555-1234567;POSTD=PP22"); 00285 Uri sip1(Uri::fromTel(tel1, Uri("sip:foo.com"))); 00286 Uri sip2(Uri::fromTel(tel2, Uri("sip:foo.com"))); 00287 assert (sip1 == sip2); 00288 assert (Data::from(sip1) == "sip:+358-555-1234567;postd=pp22@foo.com;user=phone"); 00289 assert (Data::from(sip2) == "sip:+358-555-1234567;postd=pp22@foo.com;user=phone"); 00290 } 00291 { 00292 Uri tel1("tel:+358-555-1234567;tsp=a.b;phone-context=5"); 00293 Uri tel2("tel:+358-555-1234567;phone-context=5;tsp=a.b"); 00294 Uri sip1(Uri::fromTel(tel1, Uri("sip:foo.com"))); 00295 Uri sip2(Uri::fromTel(tel2, Uri("sip:foo.com"))); 00296 assert (sip1 == sip2); 00297 assert (Data::from(sip1) == "sip:+358-555-1234567;phone-context=5;tsp=a.b@foo.com;user=phone"); 00298 assert (Data::from(sip2) == "sip:+358-555-1234567;phone-context=5;tsp=a.b@foo.com;user=phone"); 00299 } 00300 00301 { 00302 Uri uri("sip:fluffy@iii.ca:666"); 00303 assert(uri.scheme() == "sip"); 00304 assert(uri.user() == "fluffy"); 00305 assert(uri.host() == "iii.ca"); 00306 assert(uri.port() == 666); 00307 } 00308 00309 { 00310 Uri uri("sip:fluffy@iii.ca;transport=tcp"); 00311 assert(uri.param(p_transport) == "tcp"); 00312 } 00313 00314 { 00315 Uri uri("sips:fluffy@iii.ca;transport=tls"); 00316 assert(uri.scheme() == "sips"); 00317 assert(uri.param(p_transport) == "tls"); 00318 } 00319 00320 { 00321 Uri uri("sip:fluffy@iii.ca;transport=sctp"); 00322 assert(uri.param(p_transport) == "sctp"); 00323 } 00324 00325 { 00326 Uri uri("sip:fluffy:password@iii.ca"); 00327 assert(uri.password() == "password"); 00328 } 00329 00330 { 00331 Uri uri("sip:fluffy@iii.ca;user=phone;ttl=5;lr;maddr=1.2.3.4"); 00332 assert(uri.param(p_ttl) == 5); 00333 assert(uri.exists(p_lr) == true); 00334 assert(uri.param(p_maddr) == "1.2.3.4"); 00335 assert(uri.param(p_user) == "phone"); 00336 } 00337 00338 { 00339 Uri uri("sip:fluffy@iii.ca;x-fluffy=foo"); 00340 assert(uri.exists(UnknownParameterType("x-fluffy")) == true); 00341 assert(uri.exists(UnknownParameterType("x-fufu")) == false); 00342 assert(uri.param(UnknownParameterType("x-fluffy")) == "foo"); 00343 } 00344 00345 { 00346 Uri uri("sip:fluffy@iii.ca;method=MESSAGE"); 00347 assert(uri.param(p_method) == "MESSAGE"); 00348 } 00349 00350 { 00351 Uri uri("sip:+1(408) 444-1212:666@gw1"); 00352 assert(uri.user() == "+1(408) 444-1212"); 00353 assert(uri.password() == "666"); 00354 assert(uri.host() == "gw1"); 00355 } 00356 00357 { 00358 Uri uri("sip:fluffy;x-utag=foo@iii.ca"); 00359 assert(uri.user() == "fluffy;x-utag=foo"); 00360 assert(uri.host() == "iii.ca"); 00361 00362 Data out(Data::from(uri)); 00363 assert(out == "sip:fluffy;x-utag=foo@iii.ca"); 00364 } 00365 00366 { 00367 Uri uri("sip:fluffy;x-utag=foo:password@iii.ca"); 00368 assert(uri.user() == "fluffy;x-utag=foo"); 00369 assert(uri.host() == "iii.ca"); 00370 assert(uri.password() == "password"); 00371 00372 Data out(Data::from(uri)); 00373 cerr << "!! " << out << endl; 00374 assert(out == "sip:fluffy;x-utag=foo:password@iii.ca"); 00375 } 00376 00377 { 00378 Uri uri("tel:+14086661212"); 00379 assert(uri.user() == "+14086661212"); 00380 assert(uri.userParameters() == ""); 00381 assert(uri.host() == ""); 00382 assert(uri.password() == ""); 00383 00384 Data out(Data::from(uri)); 00385 cerr << "!! " << out << endl; 00386 assert(out == "tel:+14086661212"); 00387 } 00388 00389 { 00390 Uri uri("tel:+14086661212;foo=bie"); 00391 assert(uri.user() == "+14086661212"); 00392 assert(uri.userParameters() == "foo=bie"); 00393 assert(uri.host() == ""); 00394 assert(uri.password() == ""); 00395 00396 Data out(Data::from(uri)); 00397 cerr << "!! " << out << endl; 00398 assert(out == "tel:+14086661212;foo=bie"); 00399 } 00400 00401 { 00402 Uri uri("tel:+14086661212;"); 00403 assert(uri.user() == "+14086661212"); 00404 assert(uri.userParameters() == ""); 00405 assert(uri.host() == ""); 00406 assert(uri.password() == ""); 00407 00408 Data out(Data::from(uri)); 00409 cerr << "!! " << out << endl; 00410 assert(out == "tel:+14086661212"); 00411 } 00412 00413 { 00414 Uri uri("sip:;:@"); 00415 cerr << "uri.user() = " << uri.user() << endl; 00416 assert(uri.user() == ";"); 00417 assert(uri.userParameters() == ""); 00418 assert(uri.host() == ""); 00419 assert(uri.password() == ""); 00420 00421 Data out(Data::from(uri)); 00422 cerr << "!! " << out << endl; 00423 assert(out == "sip:;"); 00424 } 00425 00426 { 00427 Uri uri("tel:+1 (408) 555-1212"); 00428 assert(uri.scheme() == "tel"); 00429 } 00430 // Tests for user-less uris (was broken accidentally v1.44 Uri.cxx) 00431 { 00432 Data original("sip:1.2.3.4:5060"); 00433 Data encoded; 00434 Uri uri(original); 00435 00436 DataStream ds(encoded); 00437 uri.encode(ds); 00438 ds.flush(); 00439 cout << "!! original data: " << original << endl; 00440 cout << "!! original uri : " << uri << endl; 00441 cout << "!! encoded data: " << encoded << endl; 00442 00443 assert( encoded == original ); 00444 } 00445 00446 { 00447 // Test order irrelevance of unknown parameters 00448 Uri sip1("sip:user@domain;foo=bar;baz=qux"); 00449 Uri sip2("sip:user@domain;baz=qux;foo=bar"); 00450 assert (sip1 == sip2); 00451 assert (sip2 == sip1); 00452 } 00453 00454 { 00455 // Test order irrelevance of known parameters 00456 Uri sip1("sip:user@domain;ttl=15;method=foo"); 00457 Uri sip2("sip:user@domain;method=foo;ttl=15"); 00458 00459 assert (sip1 == sip2); 00460 assert (sip2 == sip1); 00461 } 00462 00463 00464 // tests from 3261 19.1.4 00465 { 00466 Uri sip1("sip:alice@atlanta.com;transport=TCP"); 00467 Uri sip2("sip:alice@AtLanTa.CoM;Transport=tcp"); 00468 00469 assert(sip1 == sip2); 00470 assert(sip2 == sip1); 00471 } 00472 00473 { 00474 Uri sip1("sip:carol@chicago.com"); 00475 Uri sip2("sip:carol@chicago.com;newparam=5"); 00476 Uri sip3("sip:carol@chicago.com;security=on"); 00477 00478 assert(sip1 == sip2); 00479 assert(sip2 == sip1); 00480 assert(sip2 == sip3); 00481 assert(sip3 == sip2); 00482 assert(sip3 == sip1); 00483 assert(sip1 == sip3); 00484 } 00485 00486 { 00487 Uri sip1("sip:biloxi.com;transport=tcp;method=REGISTER?to=sip:bob%40biloxi.com"); 00488 Uri sip2("sip:biloxi.com;method=REGISTER;transport=tcp?to=sip:bob%40biloxi.com"); 00489 00490 assert(sip1 == sip2); 00491 assert(sip2 == sip1); 00492 } 00493 00494 { 00495 Uri sip1("sip:alice@atlanta.com?subject=project%20x&priority=urgent"); 00496 Uri sip2("sip:alice@atlanta.com?priority=urgent&subject=project%20x"); 00497 00498 assert(sip1 == sip2); 00499 assert(sip2 == sip1); 00500 } 00501 00502 { 00503 Uri sip1("SIP:ALICE@AtLanTa.CoM;Transport=udp"); // (different usernames) 00504 Uri sip2("sip:alice@AtLanTa.CoM;Transport=UDP"); 00505 00506 assert(sip1 != sip2); 00507 } 00508 00509 { 00510 Uri sip1("sip:bob@biloxi.com"); // (can resolve to different ports) 00511 Uri sip2("sip:bob@biloxi.com:5060"); 00512 00513 assert(sip1 != sip2); 00514 } 00515 00516 { 00517 Uri sip1("sip:bob@biloxi.com"); // (can resolve to different transports) 00518 Uri sip2("sip:bob@biloxi.com;transport=udp"); 00519 00520 assert(sip1 != sip2); 00521 } 00522 00523 { 00524 Uri sip1("sip:bob@biloxi.com"); // (can resolve to different port and transports) 00525 Uri sip2("sip:bob@biloxi.com:6000;transport=tcp"); 00526 00527 assert(sip1 != sip2); 00528 } 00529 00530 // !dlb! we ignore embedded headers at the moment 00531 if (false) 00532 { 00533 Uri sip1("sip:carol@chicago.com"); // (different header component) 00534 Uri sip2("sip:carol@chicago.com?Subject=next%20meeting"); 00535 00536 assert(sip1 != sip2); 00537 } 00538 00539 { 00540 Uri sip1("sip:bob@phone21.boxesbybob.com"); // (even though that's what phone21.boxesbybob.com resolves to) 00541 Uri sip2("sip:bob@192.0.2.4"); 00542 00543 assert(sip1 != sip2); 00544 } 00545 00546 { 00547 Uri sip1("sip:carol@chicago.com"); 00548 Uri sip2("sip:carol@chicago.com;security=on"); 00549 Uri sip3("sip:carol@chicago.com;security=off"); 00550 00551 assert(sip1 == sip2); 00552 assert(sip1 == sip3); 00553 assert(sip2 != sip3); 00554 assert(sip3 != sip2); 00555 } 00556 00557 { 00558 Uri sip1("sip:carol@chicago.com"); 00559 Uri sip2("sip:carol@chicago.com:5060"); 00560 Uri sip3("sip:1.2.3.4"); 00561 Uri sip4("sip:1.2.3.4:5070"); 00562 Uri sip1a("sip:carol@chicago.com;user=phone;foo=bar"); 00563 Uri sip2a("sip:carol@chicago.com:5060;user=phone;foo=bar"); 00564 Uri sip3a("sip:1.2.3.4;user=phone;foo=bar"); 00565 Uri sip4a("sip:1.2.3.4:5070;user=phone;foo=bar"); 00566 00567 DebugLog( << "sip1.getAor==" << sip1.getAor() ); 00568 DebugLog( << "sip1.getAorNoPort==" << sip1.getAorNoPort() ); 00569 DebugLog( << "sip2.getAor==" << sip2.getAor() ); 00570 DebugLog( << "sip2.getAorNoPort==" << sip2.getAorNoPort() ); 00571 00572 assert( sip1.getAor() == Data("carol@chicago.com") ); 00573 assert( sip2.getAor() == Data("carol@chicago.com:5060") ); 00574 assert( sip3.getAor() == Data("1.2.3.4") ); 00575 assert( sip4.getAor() == Data("1.2.3.4:5070") ); 00576 00577 assert( sip1a.getAor() == Data("carol@chicago.com") ); 00578 assert( sip2a.getAor() == Data("carol@chicago.com:5060") ); 00579 assert( sip3a.getAor() == Data("1.2.3.4") ); 00580 assert( sip4a.getAor() == Data("1.2.3.4:5070") ); 00581 00582 assert( sip1.getAorNoPort() == Data("carol@chicago.com") ); 00583 assert( sip2.getAorNoPort() == Data("carol@chicago.com") ); 00584 assert( sip3.getAorNoPort() == Data("1.2.3.4") ); 00585 assert( sip4.getAorNoPort() == Data("1.2.3.4") ); 00586 00587 assert( sip1a.getAorNoPort() == Data("carol@chicago.com") ); 00588 assert( sip2a.getAorNoPort() == Data("carol@chicago.com") ); 00589 assert( sip3a.getAorNoPort() == Data("1.2.3.4") ); 00590 assert( sip4a.getAorNoPort() == Data("1.2.3.4") ); 00591 } 00592 00593 // Displayname parse tests 00594 { 00595 NameAddr sip1("\"DispName\" <sip:user@host.com>"); 00596 NameAddr sip2("\"DispName \"<sip:user@host.com>"); 00597 NameAddr sip3("\" DispName\"<sip:user@host.com>"); 00598 NameAddr sip4("DispName <sip:user@host.com>"); 00599 NameAddr sip5("DispName<sip:user@host.com>"); 00600 NameAddr sip6(" DispName <sip:user@host.com>"); 00601 NameAddr sip7(" DispName<sip:user@host.com>"); 00602 NameAddr sip8(" Disp Name <sip:user@host.com>"); 00603 00604 DebugLog( << "sip1.displayName=='" << sip1.displayName() << "'" ); 00605 DebugLog( << "sip2.displayName=='" << sip2.displayName() << "'" ); 00606 DebugLog( << "sip3.displayName=='" << sip3.displayName() << "'" ); 00607 DebugLog( << "sip4.displayName=='" << sip4.displayName() << "'" ); 00608 DebugLog( << "sip5.displayName=='" << sip5.displayName() << "'" ); 00609 DebugLog( << "sip6.displayName=='" << sip6.displayName() << "'" ); 00610 DebugLog( << "sip7.displayName=='" << sip7.displayName() << "'" ); 00611 DebugLog( << "sip8.displayName=='" << sip8.displayName() << "'" ); 00612 00613 assert( sip1.displayName() == Data("DispName") ); 00614 assert( sip2.displayName() == Data("DispName ") ); 00615 assert( sip3.displayName() == Data(" DispName") ); 00616 assert( sip4.displayName() == Data("DispName") ); 00617 assert( sip5.displayName() == Data("DispName") ); 00618 assert( sip6.displayName() == Data("DispName") ); 00619 assert( sip7.displayName() == Data("DispName") ); 00620 assert( sip8.displayName() == Data("Disp Name") ); 00621 00622 assert( sip1.uri().getAor() == Data("user@host.com") ); 00623 assert( sip2.uri().getAor() == Data("user@host.com") ); 00624 assert( sip3.uri().getAor() == Data("user@host.com") ); 00625 assert( sip4.uri().getAor() == Data("user@host.com") ); 00626 assert( sip5.uri().getAor() == Data("user@host.com") ); 00627 assert( sip6.uri().getAor() == Data("user@host.com") ); 00628 assert( sip7.uri().getAor() == Data("user@host.com") ); 00629 assert( sip8.uri().getAor() == Data("user@host.com") ); 00630 } 00631 00632 // Embedded header testing 00633 { 00634 NameAddr addr("sip:user@domain.com?Call-Info=%3csip:192.168.0.1%3e%3banswer-after=0"); 00635 //cout << addr << endl; 00636 assert(Data::from(addr.uri()) == "sip:user@domain.com?Call-Info=%3csip:192.168.0.1%3e%3banswer-after=0"); 00637 //cout << "CallInfo: " << addr.uri().embedded().header(h_CallInfos).front() << endl; 00638 assert(Data::from(addr.uri().embedded().header(h_CallInfos).front()) == "<sip:192.168.0.1>;answer-after=0"); 00639 } 00640 00641 // URI containing special character # 00642 // technically, # is meant to be encoded, but some systems (Asterisk, 00643 // some Cisco gear) seem to send this un-encoded 00644 // Some carriers insert # between a phone number and a billing prefix 00645 { 00646 Uri uri = Uri("sip:1234#00442031111111@lvdx.com"); 00647 //cout << "Encoded correctly: " << uri << endl; 00648 assert(Data::from(uri) == "sip:1234%2300442031111111@lvdx.com"); 00649 00650 Uri::setUriUserEncoding('#', false); 00651 uri = Uri("sip:1234#00442031111111@lvdx.com"); 00652 //cout << "Non Encoded # for compatibility: " << uri << endl; 00653 assert(Data::from(uri) == "sip:1234#00442031111111@lvdx.com"); 00654 Uri::setUriUserEncoding('#', true); 00655 } 00656 00657 { 00658 Uri uri = Uri("sip:1234#00442031111111;phone-context=+89@lvdx.com"); 00659 assert(uri.userIsTelephoneSubscriber()); 00660 Token telSub(uri.getUserAsTelephoneSubscriber()); 00661 assert(telSub.value()=="1234#00442031111111"); 00662 static ExtensionParameter p_phoneContext("phone-context"); 00663 assert(telSub.exists(p_phoneContext)); 00664 assert(telSub.param(p_phoneContext)=="+89"); 00665 telSub.param(p_phoneContext)="+98"; 00666 uri.setUserAsTelephoneSubscriber(telSub); 00667 assert(Data::from(uri) == "sip:1234%2300442031111111;phone-context=+98@lvdx.com"); 00668 } 00669 00670 { 00671 Uri uri = Uri("sip:+1-(234)-00442031111111@lvdx.com"); 00672 assert(uri.userIsTelephoneSubscriber()); 00673 Token telSub(uri.getUserAsTelephoneSubscriber()); 00674 assert(telSub.value()=="+1-(234)-00442031111111"); 00675 assert(!telSub.exists(p_extension)); 00676 telSub.param(p_extension)="4545"; 00677 uri.setUserAsTelephoneSubscriber(telSub); 00678 assert(Data::from(uri) == "sip:+1-(234)-00442031111111;ext=4545@lvdx.com"); 00679 } 00680 cerr << endl << "All OK" << endl; 00681 return 0; 00682 } 00683 /* ==================================================================== 00684 * The Vovida Software License, Version 1.0 00685 * 00686 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00687 * 00688 * Redistribution and use in source and binary forms, with or without 00689 * modification, are permitted provided that the following conditions 00690 * are met: 00691 * 00692 * 1. Redistributions of source code must retain the above copyright 00693 * notice, this list of conditions and the following disclaimer. 00694 * 00695 * 2. Redistributions in binary form must reproduce the above copyright 00696 * notice, this list of conditions and the following disclaimer in 00697 * the documentation and/or other materials provided with the 00698 * distribution. 00699 * 00700 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00701 * and "Vovida Open Communication Application Library (VOCAL)" must 00702 * not be used to endorse or promote products derived from this 00703 * software without prior written permission. For written 00704 * permission, please contact vocal@vovida.org. 00705 * 00706 * 4. Products derived from this software may not be called "VOCAL", nor 00707 * may "VOCAL" appear in their name, without prior written 00708 * permission of Vovida Networks, Inc. 00709 * 00710 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00711 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00712 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00713 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00714 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00715 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00716 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00717 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00718 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00719 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00720 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00721 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00722 * DAMAGE. 00723 * 00724 * ==================================================================== 00725 * 00726 * This software consists of voluntary contributions made by Vovida 00727 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00728 * Inc. For more information on Vovida Networks, Inc., please see 00729 * <http://www.vovida.org/>. 00730 * 00731 */
1.7.5.1