|
reSIProcate/stack
9694
|
00001 #ifdef HAVE_CONFIG_H 00002 #include "config.h" 00003 #endif 00004 00005 #include <assert.h> 00006 #include <iostream> 00007 #include <sstream> 00008 #include <string.h> 00009 #include <string> 00010 #include "resip/stack/HeaderFieldValue.hxx" 00011 #include "resip/stack/HeaderTypes.hxx" 00012 #include "resip/stack/Headers.hxx" 00013 #include "resip/stack/ParserCategories.hxx" 00014 #include "resip/stack/ExtensionHeader.hxx" 00015 #include "resip/stack/UnknownParameterType.hxx" 00016 #include "resip/stack/ApiCheckList.hxx" 00017 #include "resip/stack/Uri.hxx" 00018 #include "rutil/DataStream.hxx" 00019 #include "rutil/ParseBuffer.hxx" 00020 #include "rutil/Logger.hxx" 00021 00022 using namespace std; 00023 using namespace resip; 00024 00025 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST 00026 #define RESIP_COOKIE "-524287-" 00027 00028 class TR 00029 { 00030 private: 00031 ostream& os; 00032 Data label; 00033 00034 TR(const TR&); 00035 00036 void show(const char * s) 00037 { 00038 os << s << ' ' << label << endl; 00039 } 00040 00041 void start() 00042 { 00043 show("-->"); 00044 } 00045 00046 void end() 00047 { 00048 show("<--"); 00049 } 00050 00051 public: 00052 TR(Data s,ostream& o = cerr ):os(o),label(s) { start(); } 00053 TR(const char* l,ostream& o = cerr):os(o),label(l) { start(); } 00054 ~TR() { end();} 00055 }; 00056 00057 int 00058 main(int arc, char** argv) 00059 { 00060 Log::initialize(Log::Cout, Log::Debug, argv[0]); 00061 00062 static ExtensionParameter p_mobility_ext("mobility"); 00063 static ExtensionParameter p_lr_ext("lr"); 00064 static ExtensionParameter p_tag_ext("tag"); 00065 static ExtensionParameter p_ttl_ext("ttl"); 00066 00067 { 00068 TR _tr("Test poorly formed NameAddr by construction"); 00069 00070 try 00071 { 00072 NameAddr test("<jason_AT_example.com@10.0.0.1;transport=TCP>"); 00073 assert(false); 00074 } 00075 catch (ParseException& e) 00076 { 00077 resipCerr << e << endl; 00078 } 00079 } 00080 00081 { 00082 TR _tr("Test copy transport param"); 00083 00084 NameAddr test("<sip:jason_AT_example.com@10.0.0.1:5060;transport=TCP>"); 00085 resipCerr << test << endl; 00086 NameAddr copy = test; 00087 resipCerr << copy << endl; 00088 assert(test.uri().exists(p_transport)); 00089 assert(copy.uri().exists(p_transport)); 00090 00091 assert(test.uri().param(p_transport) == copy.uri().param(p_transport)); 00092 } 00093 00094 { 00095 TR _tr("Test iterator erase in ParserContainer"); 00096 00097 NameAddrs nameAddrs; 00098 00099 nameAddrs.push_back(NameAddr(Uri("sip:first@first.com"))); 00100 nameAddrs.push_back(NameAddr(Uri("sip:second@second.com"))); 00101 nameAddrs.push_back(NameAddr(Uri("sip:third@third.com"))); 00102 nameAddrs.push_back(NameAddr(Uri("sip:fourth@fourth.com"))); 00103 00104 assert(nameAddrs.size() == 4); 00105 00106 NameAddrs::iterator i = nameAddrs.begin(); 00107 ++i; 00108 00109 nameAddrs.erase(i); 00110 00111 assert(nameAddrs.size() == 3); 00112 00113 nameAddrs.erase(nameAddrs.begin()); 00114 assert(nameAddrs.size() == 2); 00115 00116 assert(nameAddrs.begin()->uri().user() == "third"); 00117 } 00118 00119 { 00120 TR _tr("Test NameAddr encode from underlying after read-only parse"); 00121 00122 resip::Data raw("<sip:jason_AT_example.com@10.0.0.1:5060;opaque=blah>"); 00123 HeaderFieldValue hfv(raw.data(), raw.size()); 00124 NameAddr test(hfv, Headers::UNKNOWN); 00125 const NameAddr& c_test(test); 00126 // We should be calling the const version of uri() here, since we don't 00127 // need to modify anything. 00128 static ExtensionParameter p_opaque_ext("opaque"); 00129 resip::Data opaque(c_test.uri().param(p_opaque_ext)); 00130 resipCerr << test << endl; 00131 NameAddr copy = test; 00132 resipCerr << copy << endl; 00133 assert(resip::Data::from(test)==raw); 00134 assert(resip::Data::from(copy)==raw); 00135 } 00136 00137 { 00138 TR _tr("Test find in ParserContainer"); 00139 00140 Tokens tokens; 00141 00142 tokens.push_back(Token("Foo")); 00143 tokens.push_back(Token("Bar")); 00144 tokens.push_back(Token("Baz")); 00145 tokens.push_back(Token("Quux")); 00146 00147 assert(tokens.find(Token("Foo"))); 00148 assert(tokens.find(Token("Bar"))); 00149 assert(tokens.find(Token("Baz"))); 00150 assert(tokens.find(Token("Quux"))); 00151 00152 assert(!tokens.find(Token("Zab"))); 00153 } 00154 00155 { 00156 TR _tr("Test remove parameters that appear multiple times"); 00157 Uri uri1("sip:a@b;xtype=1;maddr=local;xtype=2;maddr=remote;xtype=3;maddr=other"); 00158 Uri uri2(uri1); 00159 00160 uri1.remove(p_maddr); 00161 Data res1; 00162 { 00163 DataStream str(res1); 00164 str << uri1; 00165 } 00166 assert(res1 == "sip:a@b;xtype=1;xtype=2;xtype=3"); 00167 00168 UnknownParameterType p_xtype("xtype"); 00169 uri2.remove(p_xtype); 00170 Data res2; 00171 { 00172 DataStream str(res2); 00173 str << uri2; 00174 } 00175 assert(res2 == "sip:a@b;maddr=local;maddr=remote;maddr=other"); 00176 } 00177 00178 { 00179 { 00180 TR _tr("Test remove parameters that appear multiple times"); 00181 Uri uri1("sips:bob@foo.com;transport=udp"); 00182 Uri aor = uri1.getAorAsUri(); 00183 00184 Data res; 00185 { 00186 DataStream str(res); 00187 str << aor; 00188 } 00189 resipCerr << res << endl; 00190 00191 assert(res == "sips:bob@foo.com"); 00192 } 00193 00194 } 00195 00196 00197 { 00198 TR _tr("Test remove parameters that appear multiple times; mixed predefined and extensions"); 00199 Uri uri1("sip:a@b;xtype=1;maddr=local;foo=bar;ttl=17;xtype=2;maddr=remote;foo=baz;ttl=42;xtype=3;maddr=other;foo=foo;ttl=111"); 00200 Uri uri2(uri1); 00201 00202 uri1.remove(p_maddr); 00203 Data res1; 00204 { 00205 DataStream str(res1); 00206 str << uri1; 00207 } 00208 assert(res1 == "sip:a@b;ttl=17;ttl=42;ttl=111;xtype=1;foo=bar;xtype=2;foo=baz;xtype=3;foo=foo"); 00209 00210 UnknownParameterType p_xtype("xtype"); 00211 uri2.remove(p_xtype); 00212 Data res2; 00213 { 00214 DataStream str(res2); 00215 str << uri2; 00216 } 00217 assert(res2 == "sip:a@b;maddr=local;ttl=17;maddr=remote;ttl=42;maddr=other;ttl=111;foo=bar;foo=baz;foo=foo"); 00218 } 00219 00220 { 00221 TR _tr("Test exists unknown parameter"); 00222 00223 Uri uri1("sip:a@b;xaudio"); 00224 assert(uri1.exists(UnknownParameterType("xaudio"))); 00225 assert(uri1.param(UnknownParameterType("xaudio")) == Data::Empty); 00226 00227 Uri uri2("sip:a@b;a=b;xaudio"); 00228 resipCerr << uri2.param(UnknownParameterType("a")) << endl; 00229 00230 assert(uri2.exists(UnknownParameterType("xaudio"))); 00231 assert(uri2.param(UnknownParameterType("xaudio")) == Data::Empty); 00232 00233 Uri uri3("sip:a@b;xaudio;a=b"); 00234 assert(uri3.exists(UnknownParameterType("xaudio"))); 00235 assert(uri3.param(UnknownParameterType("xaudio")) == Data::Empty); 00236 } 00237 00238 { 00239 TR _tr("Test non-quoted tokens displayname in NameAddr (torture test: 2.39)"); 00240 Data data("A. Bell <sip:a.g.bell@bell-tel.com>;tag=459843"); 00241 00242 NameAddr legal(data); 00243 00244 assert(legal.uri().host() == "bell-tel.com"); 00245 00246 resipCerr << "!!" << legal << endl; 00247 00248 assert(legal.displayName() == "A. Bell"); 00249 } 00250 00251 { 00252 TR _tr("Test quoted displayname in NameAddr (torture test: 2.39)"); 00253 Data data("\"A. Bell\" <sip:a.g.bell@bell-tel.com>;tag=459843"); 00254 00255 NameAddr legal(data); 00256 00257 assert(legal.uri().host() == "bell-tel.com"); 00258 00259 resipCerr << "!!" << legal.displayName() << endl; 00260 00261 assert(legal.displayName() == "A. Bell"); 00262 } 00263 00264 { 00265 TR _tr("Test NameAddr parameter handling"); 00266 Data data("sip:foo@bar.com;user=phone"); 00267 00268 NameAddr original(data); 00269 assert(original.uri().exists(p_user)); 00270 00271 resipCerr << "!!" << original << endl; 00272 } 00273 00274 { 00275 TR _tr("Test tel aor canonicalization"); 00276 Data data("tel:+14156268178;pOstd=pP2;isUb=1411"); 00277 00278 Uri original(data); 00279 resipCerr << original.getAor() << endl; 00280 00281 assert(original.getAor() == "+14156268178"); 00282 } 00283 00284 { 00285 TR _tr("Test aor canonicalization"); 00286 Data data("sip:User@kElOwNa.GlOo.NeT:5666"); 00287 Data data1("sip:User@KeLoWnA.gLoO.nEt:5666"); 00288 00289 Uri original(data); 00290 Uri original1(data1); 00291 00292 resipCerr << "!! " << original.getAor() << " " << original1.getAor() << endl; 00293 assert(original.getAor() == original1.getAor()); 00294 } 00295 00296 { 00297 TR _tr("Test tel NameAddr"); 00298 NameAddr n1("<tel:98267168>"); 00299 resipCerr << n1.uri().user() << endl; 00300 } 00301 00302 #ifdef USE_IPV6 00303 { 00304 TR _tr("Test cleverly malformed V6 addr in Uri"); 00305 const char* buf="sip:foo@[:x]"; 00306 HeaderFieldValue hfv(buf, strlen(buf)); 00307 NameAddr nameaddr(hfv, Headers::UNKNOWN); 00308 assert(!nameaddr.isWellFormed()); 00309 } 00310 #endif 00311 00312 { 00313 TR _tr("Test empty NameAddr"); 00314 NameAddr n1; 00315 NameAddr n2; 00316 assert (!(n1 < n2)); 00317 assert (!(n2 < n1)); 00318 assert (n1.uri().getAor() == n2.uri().getAor()); 00319 } 00320 00321 { 00322 TR _tr("Test NameAddr q value"); 00323 00324 NameAddr w("<sip:wombat@192.168.2.221:5062;transport=Udp>;expires=63;q=1"); 00325 #ifndef RESIP_FIXED_POINT 00326 assert(w.param(p_q) == 1.0); 00327 #endif 00328 assert(w.param(p_q) == 1000); 00329 w.param(p_q) = 843; 00330 assert(w.param(p_q) <= 843); 00331 #ifndef RESIP_FIXED_POINT 00332 assert(w.param(p_q) == 0.843); 00333 w.param(p_q) = 0.843; 00334 assert(w.param(p_q) == 843); 00335 assert(w.param(p_q) == 0.843); 00336 w.param(p_q) = 0.65; 00337 assert(w.param(p_q) == 650); 00338 #endif 00339 w.param(p_q) = 0; 00340 assert(w.param(p_q) == 0); 00341 } 00342 00343 { 00344 TR _tr("Test NameAddr comparison"); 00345 00346 NameAddr w1("<sip:wombat@192.168.2.221:5062;transport=Udp>;expires=63"); 00347 NameAddr w2("<sip:wombat@192.168.2.221:5063;transport=Udp>;expires=66"); 00348 assert(w1 < w2); 00349 assert (!(w2 < w1)); 00350 } 00351 00352 { 00353 TR _tr("Test parameter with spaces"); 00354 Data txt("Digest username=\"Alice\", realm = \"atlanta.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", reponse=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"); 00355 HeaderFieldValue hfv(txt.data(), txt.size()); 00356 Auth auth(hfv, Headers::Authorization); 00357 00358 assert(auth.scheme() == "Digest"); 00359 assert(auth.exists(p_realm)); 00360 } 00361 00362 { 00363 TR _tr("Test uri with no user"); 00364 Data data("sip:kelowna.gloo.net"); 00365 00366 Uri original(data); 00367 resipCerr << original << endl; 00368 00369 assert(Data::from(original) == data); 00370 } 00371 00372 { 00373 TR _tr("Test uri with empty transport param"); 00374 Data data("sip:kelowna.gloo.net;transport=;udp"); 00375 00376 try 00377 { 00378 Uri original(data); 00379 assert(0); 00380 } 00381 catch(...) 00382 {} 00383 } 00384 00385 { 00386 TR _tr("Test uri with empty transport param"); 00387 Data data("sip:kelowna.gloo.net;transport=;udp"); 00388 00389 try 00390 { 00391 Uri original(data); 00392 assert(0); 00393 } 00394 catch(...) 00395 {} 00396 } 00397 00398 { 00399 TR _tr("Test assignment for NameAddr"); 00400 NameAddr original(Data("\"Original\"<sip:orig@example.com>;tag=original")); 00401 (void)original.exists(p_tag); 00402 // force parse 00403 NameAddr newna(Data("\"new\"<sip:new@example.com>;tag=new")); 00404 (void)newna.exists(p_tag); 00405 cout << "original NameAddr: ->" << original << "<-"<< endl; 00406 cout << "new NameAddr : ->" << newna << "<-" << endl; 00407 original = newna; 00408 cout << "original : ->" << original << "<-"<< endl; 00409 assert(Data::from(original) == Data::from(newna)); 00410 } 00411 00412 { 00413 TR _tr("Test @ in params for Uri"); 00414 Uri uri(Data("sip:example.com;lr;foo=\"@haha\"")); 00415 assert(uri.user().empty()); 00416 assert(uri.host()=="example.com"); 00417 assert(uri.port()==0); 00418 } 00419 00420 { 00421 TR _tr("Test unquoted @ in params for Uri"); 00422 // This is actually not an ambiguous case; '@' is not valid in either a 00423 // param name or value, and ';' is legal in a userpart 00424 Uri uri(Data("sip:example.com;lr;foo=fooba@haha")); 00425 assert(uri.user()=="example.com;lr;foo=fooba"); 00426 assert(uri.host()=="haha"); 00427 assert(uri.port()==0); 00428 } 00429 00430 { 00431 TR _tr("Test : in params for Uri"); 00432 Uri uri(Data("sip:example.com;lr;foo=\":lol\"")); 00433 assert(uri.user().empty()); 00434 assert(uri.host()=="example.com"); 00435 assert(uri.port()==0); 00436 } 00437 00438 { 00439 TR _tr("Test unquoted : in params for Uri"); 00440 Uri uri(Data("sip:example.com;lr;foo=:lol")); 00441 assert(uri.user().empty()); 00442 assert(uri.host()=="example.com"); 00443 assert(uri.port()==0); 00444 } 00445 00446 { 00447 TR _tr("Test unquoted : in params for Uri (2)"); 00448 Uri uri(Data("sip:example.com;lr;:foo=:lol")); 00449 assert(uri.user().empty()); 00450 assert(uri.host()=="example.com"); 00451 assert(uri.port()==0); 00452 } 00453 00454 { 00455 TR _tr("Test @ in headers for Uri"); 00456 Uri uri(Data("sip:example.com?foo=\"@haha\"")); 00457 assert(uri.user().empty()); 00458 assert(uri.host()=="example.com"); 00459 assert(uri.port()==0); 00460 } 00461 00462 { 00463 TR _tr("Test unquoted @ in headers for Uri"); 00464 // This is actually not an ambiguous case; '@' is not valid in either an 00465 // embedded header name or value, and '?' is legal in a userpart 00466 Uri uri(Data("sip:example.com?foo=fooba@haha")); 00467 assert(uri.user()=="example.com?foo=fooba"); 00468 assert(uri.host()=="haha"); 00469 assert(uri.port()==0); 00470 } 00471 00472 { 00473 TR _tr("Test : in headers for Uri"); 00474 Uri uri(Data("sip:example.com?foo=\":lol\"")); 00475 assert(uri.user().empty()); 00476 assert(uri.host()=="example.com"); 00477 assert(uri.port()==0); 00478 } 00479 00480 { 00481 TR _tr("Test unquoted : in headers for Uri"); 00482 Uri uri(Data("sip:example.com?foo=:lol")); 00483 assert(uri.user().empty()); 00484 assert(uri.host()=="example.com"); 00485 assert(uri.port()==0); 00486 } 00487 00488 { 00489 TR _tr("Test unquoted : in headers for Uri (2)"); 00490 Uri uri(Data("sip:example.com?:foo=:lol")); 00491 assert(uri.user().empty()); 00492 assert(uri.host()=="example.com"); 00493 assert(uri.port()==0); 00494 } 00495 00496 { 00497 TR _tr("Test typeless parameter copy"); 00498 Token s = Token("jason"); 00499 s.value() = "value"; 00500 s.param(p_expires) = 17; 00501 s.param(p_lr_ext); 00502 s.param(UnknownParameterType("foobie")) = "quux"; 00503 00504 Token s1; 00505 s1.value() = "other"; 00506 s1.param(p_retryAfter) = 21; 00507 00508 s.setParameter(s1.getParameterByEnum(ParameterTypes::retryAfter)); 00509 assert(s.value() == "value"); 00510 assert(s.param(p_retryAfter) == 21); 00511 assert(s.exists(p_lr_ext)); 00512 assert(s.param(UnknownParameterType("foobie")) == "quux"); 00513 } 00514 00515 { 00516 TR a("Test typeless parameter overwrite" ); 00517 Token s; 00518 s.value() = "value"; 00519 s.param(p_expires) = 17; 00520 s.param(p_retryAfter) = 12; 00521 s.param(p_lr_ext); 00522 s.param(UnknownParameterType("foobie")) = "quux"; 00523 00524 Token s1; 00525 s1.value() = "other"; 00526 s1.param(p_retryAfter) = 21; 00527 00528 s.setParameter(s1.getParameterByEnum(ParameterTypes::retryAfter)); 00529 assert(s.value() == "value"); 00530 assert(s.param(p_retryAfter) == 21); 00531 assert(s.exists(p_lr_ext)); 00532 assert(s.param(UnknownParameterType("foobie")) == "quux"); 00533 00534 s.encode(resipCerr); 00535 resipCerr << endl; 00536 } 00537 00538 { 00539 TR _tr( "Test StringCategory"); 00540 Data stringString("Lame Agent"); 00541 HeaderFieldValue hfv(stringString.data(), stringString.size()); 00542 00543 StringCategory str(hfv, Headers::UNKNOWN); 00544 assert(str.value() == stringString); 00545 00546 Data buff; 00547 { 00548 DataStream s(buff); 00549 str.encode(s); 00550 } 00551 resipCerr << buff << endl; 00552 assert(buff == stringString); 00553 00554 StringCategory copy(str); 00555 assert(copy.value() == stringString); 00556 00557 str.value() = "foo"; 00558 assert(str.value() == "foo"); 00559 } 00560 00561 { 00562 TR _tr( "Test Token parameters"); 00563 Token state; 00564 state.value() = Data("active"); 00565 state.param(p_expires) = 666; 00566 resipCerr << state << endl; 00567 } 00568 00569 { 00570 TR _tr( "StatusLine, with reason code"); 00571 Data statusLineString("SIP/2.0 180 Ringing"); 00572 HeaderFieldValue hfv(statusLineString.data(), statusLineString.size()); 00573 00574 StatusLine statusLine(hfv); 00575 assert(statusLine.responseCode() == 180); 00576 resipCerr << statusLine.reason() << endl; 00577 assert(statusLine.reason() == "Ringing"); 00578 assert(statusLine.getSipVersion() == "SIP/2.0"); 00579 00580 StatusLine copy(statusLine); 00581 assert(copy.responseCode() == 180); 00582 assert(copy.reason() == "Ringing"); 00583 assert(copy.getSipVersion() == "SIP/2.0"); 00584 } 00585 { 00586 Uri foo; 00587 // valgrind complains, but the problem moves when closely observed 00588 assert(foo.getAor().empty()); 00589 } 00590 00591 #define checkHeaderName(_name) resipCerr << Headers::_name << " " << Headers::getHeaderName(Headers::_name) << " = " << #_name << endl /*;assert(isEqualNoCase(Headers::getHeaderName(Headers::_name), #_name))*/ 00592 { 00593 // test header hash 00594 for (int i = Headers::CSeq; i < Headers::MAX_HEADERS; i++) 00595 { 00596 if (i == Headers::RESIP_DO_NOT_USE) 00597 { 00598 continue; 00599 } 00600 00601 Data hdr = Headers::getHeaderName(i); 00602 if (!hdr.size()) continue; 00603 Data msg("Checking hash of: "); 00604 msg += hdr; 00605 TR _tr(msg); 00606 assert(Headers::getType(Headers::getHeaderName(i).c_str(), Headers::getHeaderName(i).size()) == i); 00607 } 00608 checkHeaderName(To); 00609 checkHeaderName(From); 00610 checkHeaderName(Via); 00611 checkHeaderName(CallID); 00612 checkHeaderName(CSeq); 00613 checkHeaderName(Route); 00614 checkHeaderName(RecordRoute); 00615 checkHeaderName(Contact); 00616 checkHeaderName(Subject); 00617 checkHeaderName(Expires); 00618 checkHeaderName(MaxForwards); 00619 checkHeaderName(Accept); 00620 checkHeaderName(AcceptEncoding); 00621 checkHeaderName(AcceptLanguage); 00622 checkHeaderName(AlertInfo); 00623 checkHeaderName(Allow); 00624 checkHeaderName(AuthenticationInfo); 00625 checkHeaderName(CallInfo); 00626 checkHeaderName(ContentDisposition); 00627 checkHeaderName(ContentEncoding); 00628 checkHeaderName(ContentLanguage); 00629 checkHeaderName(ContentTransferEncoding); 00630 checkHeaderName(ContentType); 00631 checkHeaderName(Date); 00632 checkHeaderName(InReplyTo); 00633 checkHeaderName(MinExpires); 00634 checkHeaderName(MIMEVersion); 00635 checkHeaderName(Organization); 00636 checkHeaderName(Priority); 00637 checkHeaderName(ProxyAuthenticate); 00638 checkHeaderName(ProxyAuthorization); 00639 checkHeaderName(ProxyRequire); 00640 checkHeaderName(ReplyTo); 00641 checkHeaderName(Require); 00642 checkHeaderName(RetryAfter); 00643 checkHeaderName(Server); 00644 checkHeaderName(SIPETag); 00645 checkHeaderName(SIPIfMatch); 00646 checkHeaderName(Supported); 00647 checkHeaderName(Timestamp); 00648 checkHeaderName(Unsupported); 00649 checkHeaderName(UserAgent); 00650 checkHeaderName(Warning); 00651 checkHeaderName(WWWAuthenticate); 00652 checkHeaderName(SubscriptionState); 00653 checkHeaderName(ReferTo); 00654 checkHeaderName(ReferredBy); 00655 checkHeaderName(Authorization); 00656 checkHeaderName(Replaces); 00657 checkHeaderName(Event); 00658 checkHeaderName(AllowEvents); 00659 checkHeaderName(SecurityClient); 00660 checkHeaderName(SecurityServer); 00661 checkHeaderName(SecurityVerify); 00662 checkHeaderName(ContentLength); 00663 checkHeaderName(ContentId); 00664 00665 } 00666 00667 #define checkParameterName(_name) resipCerr << ParameterTypes::_name << " " << ParameterTypes::ParameterNames[ParameterTypes::_name] << " = " << #_name << endl/*;assert(isEqualNoCase(ParameterTypes::ParameterNames[ParameterTypes::_name], #_name))*/ 00668 { 00669 checkParameterName(data); 00670 checkParameterName(control); 00671 checkParameterName(mobility); 00672 checkParameterName(description); 00673 checkParameterName(events); 00674 checkParameterName(priority); 00675 checkParameterName(methods); 00676 checkParameterName(schemes); 00677 checkParameterName(application); 00678 checkParameterName(video); 00679 checkParameterName(language); 00680 checkParameterName(type); 00681 checkParameterName(isFocus); 00682 checkParameterName(actor); 00683 checkParameterName(text); 00684 checkParameterName(extensions); 00685 checkParameterName(Instance); 00686 checkParameterName(gr); 00687 00688 checkParameterName(transport); 00689 checkParameterName(user); 00690 checkParameterName(method); 00691 checkParameterName(ttl); 00692 checkParameterName(maddr); 00693 checkParameterName(lr); 00694 checkParameterName(q); 00695 checkParameterName(purpose); 00696 checkParameterName(expires); 00697 checkParameterName(handling); 00698 checkParameterName(tag); 00699 checkParameterName(toTag); 00700 checkParameterName(fromTag); 00701 checkParameterName(duration); 00702 checkParameterName(branch); 00703 checkParameterName(received); 00704 checkParameterName(comp); 00705 checkParameterName(rport); 00706 checkParameterName(algorithm); 00707 checkParameterName(cnonce); 00708 checkParameterName(domain); 00709 checkParameterName(id); 00710 checkParameterName(nonce); 00711 checkParameterName(nc); 00712 checkParameterName(opaque); 00713 checkParameterName(realm); 00714 checkParameterName(response); 00715 checkParameterName(stale); 00716 checkParameterName(username); 00717 checkParameterName(qop); 00718 checkParameterName(uri); 00719 checkParameterName(retryAfter); 00720 checkParameterName(reason); 00721 checkParameterName(dAlg); 00722 checkParameterName(dQop); 00723 checkParameterName(dVer); 00724 checkParameterName(smimeType); 00725 checkParameterName(name); 00726 checkParameterName(filename); 00727 checkParameterName(protocol); 00728 checkParameterName(micalg); 00729 checkParameterName(boundary); 00730 checkParameterName(expiration); 00731 checkParameterName(size); 00732 checkParameterName(permission); 00733 checkParameterName(site); 00734 checkParameterName(directory); 00735 checkParameterName(mode); 00736 checkParameterName(server); 00737 checkParameterName(charset); 00738 checkParameterName(accessType); 00739 checkParameterName(profileType); 00740 checkParameterName(vendor); 00741 checkParameterName(model); 00742 checkParameterName(version); 00743 checkParameterName(effectiveBy); 00744 checkParameterName(document); 00745 checkParameterName(appId); 00746 checkParameterName(networkUser); 00747 00748 checkParameterName(url); 00749 00750 00751 00752 // test parameter hash 00753 for (int i = 0; i < ParameterTypes::MAX_PARAMETER; i++) 00754 { 00755 if (i != ParameterTypes::qopOptions && 00756 i != ParameterTypes::qop ) 00757 { 00758 00759 TR _tr( Data("Checking hash of: ") + Data(ParameterTypes::ParameterNames[i])); 00760 assert(ParameterTypes::getType(ParameterTypes::ParameterNames[i].c_str(), 00761 ParameterTypes::ParameterNames[i].size()) == i); 00762 } 00763 } 00764 00765 assert(ParameterTypes::ParameterNames[ParameterTypes::qop] == "qop"); 00766 assert(ParameterTypes::ParameterNames[ParameterTypes::qopOptions] == "qop"); 00767 } 00768 00769 { 00770 TR _tr( "simple Token parse test"); 00771 const char *org = "WuggaWuggaFoo"; 00772 00773 HeaderFieldValue hfv(org, strlen(org)); 00774 Token tok(hfv, Headers::UNKNOWN); 00775 assert(tok.value() == org); 00776 } 00777 00778 { 00779 TR _tr( "Token + parameters parse test"); 00780 const char *org = "WuggaWuggaFoo;ttl=2;retry-after=3"; 00781 00782 HeaderFieldValue hfv(org, strlen(org)); 00783 Token tok(hfv, Headers::UNKNOWN); 00784 assert(tok.value() == "WuggaWuggaFoo"); 00785 assert(tok.param(p_ttl_ext) == "2"); 00786 assert(tok.param(p_retryAfter) == 3); 00787 } 00788 00789 { 00790 TR _tr( "Test NameAddr(Data) constructor"); 00791 00792 Data nad("bob<sips:bob@foo.com>;tag=wd834f"); 00793 NameAddr na(nad); 00794 assert(na.uri().user() == "bob"); 00795 } 00796 00797 { 00798 TR _tr( "full on via parse"); 00799 const char *viaString = /* Via: */ " SIP/2.0/UDP a.b.c.com:5000;ttl=3;maddr=1.2.3.4;received=foo.com"; 00800 00801 HeaderFieldValue hfv(viaString, strlen(viaString)); 00802 Via via(hfv, Headers::UNKNOWN); 00803 assert(via.sentPort() == 5000); 00804 assert(via.sentHost() == "a.b.c.com"); 00805 assert(via.param(p_maddr) == "1.2.3.4"); 00806 } 00807 00808 #ifdef USE_IPV6 00809 { 00810 TR _tr( "Via assert bug with malformed IPV6 addr [boom]" ); 00811 const char* viaString = "SIP/2.0/UDP [boom]:5060;branch=z9hG4bKblah"; 00812 HeaderFieldValue hfv(viaString, strlen(viaString)); 00813 Via via(hfv, Headers::UNKNOWN); 00814 assert(!via.isWellFormed()); 00815 } 00816 00817 { 00818 TR _tr( "Via assert bug with malformed IPV6 addr [:z]" ); 00819 const char* viaString = "SIP/2.0/UDP [:z]:5060;branch=z9hG4bKblah"; 00820 HeaderFieldValue hfv(viaString, strlen(viaString)); 00821 Via via(hfv, Headers::UNKNOWN); 00822 assert(!via.isWellFormed()); 00823 } 00824 #endif 00825 00826 { 00827 TR _tr("Test poorly formed DataParameter by construction"); 00828 00829 const char *viaString = /* Via: */ " SIP/2.0/UDP example.com:5000;;tag="; 00830 00831 HeaderFieldValue hfv(viaString, strlen(viaString)); 00832 try 00833 { 00834 Via via(hfv, Headers::UNKNOWN); 00835 via.sentPort(); 00836 assert(false); 00837 } 00838 catch (ParseException& e) 00839 { 00840 resipCerr << "Caught parse exception for Via" << endl; 00841 } 00842 } 00843 00844 { 00845 TR _tr("Test poorly formed UnknownParameter by construction"); 00846 00847 const char *viaString = /* Via: */ " SIP/2.0/UDP example.com:5000;;foobar="; 00848 00849 HeaderFieldValue hfv(viaString, strlen(viaString)); 00850 try 00851 { 00852 Via via(hfv, Headers::UNKNOWN); 00853 via.sentPort(); 00854 UnknownParameterType p_foobar("foobar"); 00855 via.exists(p_foobar); 00856 assert(false); 00857 } 00858 catch (ParseException& e) 00859 { 00860 resipCerr << "Caught parse exception for Via" << endl; 00861 } 00862 } 00863 00864 { 00865 TR _tr("Test poorly formed UInt32Parameter by construction"); 00866 00867 const char *viaString = /* Via: */ " SIP/2.0/UDP example.com:5000;;duration="; 00868 00869 HeaderFieldValue hfv(viaString, strlen(viaString)); 00870 try 00871 { 00872 Via via(hfv, Headers::UNKNOWN); 00873 via.sentPort(); 00874 assert(false); 00875 } 00876 catch (ParseException& e) 00877 { 00878 resipCerr << "Caught parse exception for Via " << endl; 00879 } 00880 } 00881 00882 { 00883 TR _tr("Test poorly formed QuotedDataParameter by construction"); 00884 00885 const char *viaString = /* Via: */ " SIP/2.0/UDP example.com:5000;;domain=\""; 00886 00887 HeaderFieldValue hfv(viaString, strlen(viaString)); 00888 try 00889 { 00890 Via via(hfv, Headers::UNKNOWN); 00891 via.sentPort(); 00892 assert(false); 00893 } 00894 catch (ParseException& e) 00895 { 00896 resipCerr << "Caught parse exception for Via " << endl; 00897 } 00898 } 00899 00900 #ifdef USE_IPV6 00901 { 00902 TR _tr( "full on via parse, IPV6"); 00903 // !dlb! deal with maddr=[5f1b:df00:ce3e:e200:20:800:2b37:6426] 00904 const char *viaString = /* Via: */ " SIP/2.0/UDP [5f1b:df00:ce3e:e200:20:800:2b37:6426]:5000;ttl=3;maddr=1.2.3.4;received=foo.com"; 00905 00906 HeaderFieldValue hfv(viaString, strlen(viaString)); 00907 Via via(hfv, Headers::UNKNOWN); 00908 assert(via.sentPort() == 5000); 00909 assert(via.sentHost() == "5f1b:df00:ce3e:e200:20:800:2b37:6426"); 00910 assert(via.param(p_maddr) == "1.2.3.4"); 00911 } 00912 #endif 00913 { 00914 TR _tr( "URI parse"); 00915 Data uriString = "sip:bob@foo.com"; 00916 ParseBuffer pb(uriString.data(), uriString.size()); 00917 NameAddr to; 00918 to.parse(pb); 00919 Uri& uri = to.uri(); 00920 resipCerr << "!! " << to << endl; 00921 assert(uri.scheme() == "sip"); 00922 assert(uri.user() == "bob"); 00923 assert(uri.host() == "foo.com"); 00924 assert(uri.port() == 0); 00925 } 00926 00927 { 00928 TR _tr( "URI parse, no displayName"); 00929 Data uriString = "sips:foo.com"; 00930 ParseBuffer pb(uriString.data(), uriString.size()); 00931 NameAddr to; 00932 to.parse(pb); 00933 Uri& uri = to.uri(); 00934 assert(uri.scheme() == "sips"); 00935 assert(uri.user() == ""); 00936 assert(uri.host() == "foo.com"); 00937 assert(uri.port() == 0); 00938 } 00939 00940 { 00941 TR _tr( "URI parse, parameters"); 00942 Data uriString = "sips:bob;param=gargle:password@foo.com"; 00943 ParseBuffer pb(uriString.data(), uriString.size()); 00944 NameAddr to; 00945 to.parse(pb); 00946 Uri& uri = to.uri(); 00947 00948 assert(uri.scheme() == "sips"); 00949 assert(uri.user() == "bob;param=gargle"); 00950 assert(uri.password() == "password"); 00951 assert(uri.host() == "foo.com"); 00952 } 00953 00954 { 00955 TR _tr( "URI parse, parameters, port"); 00956 Data uriString = "sips:bob;param=gargle:password@foo.com:6000"; 00957 ParseBuffer pb(uriString.data(), uriString.size()); 00958 00959 NameAddr to; 00960 to.parse(pb); 00961 Uri& uri = to.uri(); 00962 00963 assert(uri.scheme() == "sips"); 00964 assert(uri.user() == "bob;param=gargle"); 00965 assert(uri.password() == "password"); 00966 assert(uri.host() == "foo.com"); 00967 assert(uri.port() == 6000); 00968 } 00969 00970 { 00971 TR _tr( "URI parse, parameters, correct termination check"); 00972 Data uriString = "sips:bob;param=gargle:password@foo.com notHost"; 00973 ParseBuffer pb(uriString.data(), uriString.size()); 00974 00975 NameAddr to; 00976 to.parse(pb); 00977 Uri& uri = to.uri(); 00978 00979 assert(uri.scheme() == "sips"); 00980 assert(uri.user() == "bob;param=gargle"); 00981 assert(uri.password() == "password"); 00982 resipCerr << "Uri:" << uri.host() << endl; 00983 assert(uri.host() == "foo.com"); 00984 } 00985 00986 { 00987 TR _tr( "URI parse, transport parameter"); 00988 Data uriString = "sip:bob@biloxi.com;transport=udp"; 00989 ParseBuffer pb(uriString.data(), uriString.size()); 00990 00991 NameAddr to; 00992 to.parse(pb); 00993 Uri& uri = to.uri(); 00994 00995 assert(uri.param(p_transport) == "udp"); 00996 } 00997 00998 resipCerr << "URI comparison tests" << endl; 00999 { 01000 Data uriStringA("sip:carol@chicago.com"); 01001 Data uriStringB("sip:carol@chicago.com;newparam=5"); 01002 Data uriStringC("sip:carol@chicago.com;security=on"); 01003 ParseBuffer pa(uriStringA.data(), uriStringA.size()); 01004 ParseBuffer pb(uriStringB.data(), uriStringB.size()); 01005 ParseBuffer pc(uriStringC.data(), uriStringC.size()); 01006 NameAddr nA, nB, nC; 01007 01008 nA.parse(pa); 01009 nB.parse(pb); 01010 nC.parse(pc); 01011 01012 Uri& uA = nA.uri(); 01013 Uri& uB = nB.uri(); 01014 Uri& uC = nC.uri(); 01015 01016 assert(uA == uB); 01017 assert(uB == uC); 01018 assert(uA == uC); 01019 } 01020 { 01021 Data uriStringA = "sip:biloxi.com;transport=tcp;method=REGISTER"; 01022 Data uriStringB = "sip:biloxi.com;method=REGISTER;transport=tcp"; 01023 01024 ParseBuffer pa(uriStringA.data(), uriStringA.size()); 01025 ParseBuffer pb(uriStringB.data(), uriStringB.size()); 01026 01027 NameAddr nA, nB; 01028 nA.parse(pa); 01029 nB.parse(pb); 01030 01031 Uri& uA = nA.uri(); 01032 Uri& uB = nB.uri(); 01033 01034 assert(uA == uB); 01035 } 01036 { 01037 Data uriStringA = "sip:alice@atlanta.com"; 01038 Data uriStringB = "sip:alice@atlanta.com"; 01039 01040 ParseBuffer pa(uriStringA.data(), uriStringA.size()); 01041 ParseBuffer pb(uriStringB.data(), uriStringB.size()); 01042 01043 NameAddr nA, nB; 01044 nA.parse(pa); 01045 nB.parse(pb); 01046 Uri& uA = nA.uri(); 01047 Uri& uB = nB.uri(); 01048 01049 assert(uA == uB); 01050 } 01051 { 01052 Data uriStringA = "sip:alice@AtLanTa.CoM;Transport=UDP"; 01053 Data uriStringB = "SIP:ALICE@AtLanTa.CoM;Transport=udp"; 01054 01055 ParseBuffer pa(uriStringA.data(), uriStringA.size()); 01056 ParseBuffer pb(uriStringB.data(), uriStringB.size()); 01057 01058 NameAddr nA, nB; 01059 nA.parse(pa); 01060 nB.parse(pb); 01061 Uri& uA = nA.uri(); 01062 Uri& uB = nB.uri(); 01063 01064 assert(uA != uB); 01065 } 01066 { 01067 Data uriStringA = "sip:bob@192.0.2.4"; 01068 Data uriStringB = "sip:bob@phone21.boxesbybob.com"; 01069 01070 ParseBuffer pa(uriStringA.data(), uriStringA.size()); 01071 ParseBuffer pb(uriStringB.data(), uriStringB.size()); 01072 NameAddr nA, nB; 01073 nA.parse(pa); 01074 nB.parse(pb); 01075 Uri& uA = nA.uri(); 01076 Uri& uB = nB.uri(); 01077 assert(uA != uB); 01078 } 01079 { 01080 Data uriStringA = "sip:bob@biloxi.com:6000;transport=tcp"; 01081 Data uriStringB = "sip:bob@biloxi.com"; 01082 01083 ParseBuffer pa(uriStringA.data(), uriStringA.size()); 01084 ParseBuffer pb(uriStringB.data(), uriStringB.size()); 01085 NameAddr nA, nB; 01086 nA.parse(pa); 01087 nB.parse(pb); 01088 Uri& uA = nA.uri(); 01089 Uri& uB = nB.uri(); 01090 assert(uA != uB); 01091 } 01092 { 01093 Data uriStringA = "sip:bob@biloxi.com;transport=udp"; 01094 Data uriStringB = "sip:bob@biloxi.com"; 01095 01096 ParseBuffer pa(uriStringA.data(), uriStringA.size()); 01097 ParseBuffer pb(uriStringB.data(), uriStringB.size()); 01098 NameAddr nA, nB; 01099 nA.parse(pa); 01100 nB.parse(pb); 01101 Uri& uA = nA.uri(); 01102 Uri& uB = nB.uri(); 01103 resipCerr << "A: " << uA << endl; 01104 resipCerr << "B: " << uB << endl; 01105 resipCerr << "A:exists(transport) " << uA.exists(p_transport) << endl; 01106 assert(uA != uB); 01107 } 01108 01109 { //embedded header comparison, not supported yet 01110 // char *uriStringA = "sip:carol@chicago.com?Subject=next%20meeting"; 01111 // char *uriStringB = "sip:carol@chicago.com"; 01112 01113 // ParseBuffer pa(uriStringA, strlen(uriStringA)); 01114 // ParseBuffer pb(uriStringB, strlen(uriStringB)); 01115 // Uri uA, uB; 01116 // uA.parse(uriStringA); 01117 // uB.parse(uriStringB); 01118 // assert(uA != uB); 01119 } 01120 01121 { 01122 TR _tr( "Request Line parse"); 01123 Data requestLineString("INVITE sips:bob@foo.com SIP/2.0"); 01124 HeaderFieldValue hfv(requestLineString.data(), requestLineString.size()); 01125 01126 RequestLine requestLine(hfv); 01127 assert(requestLine.uri().scheme() == "sips"); 01128 assert(requestLine.uri().user() == "bob"); 01129 resipCerr << requestLine.uri().host() << endl; 01130 assert(requestLine.uri().host() == "foo.com"); 01131 assert(requestLine.getMethod() == INVITE); 01132 assert(requestLine.getSipVersion() == "SIP/2.0"); 01133 } 01134 { 01135 TR _tr( "Request Line parse tel"); 01136 Data requestLineString("INVITE tel:4153331212 SIP/2.0"); 01137 HeaderFieldValue hfv(requestLineString.data(), requestLineString.size()); 01138 01139 RequestLine requestLine(hfv); 01140 assert(requestLine.uri().scheme() == "tel"); 01141 assert(requestLine.uri().user() == "4153331212"); 01142 assert(requestLine.getMethod() == INVITE); 01143 assert(requestLine.getSipVersion() == "SIP/2.0"); 01144 } 01145 { 01146 TR _tr( "Request Line parse, parameters"); 01147 Data requestLineString("INVITE sips:bob@foo.com;maddr=1.2.3.4 SIP/2.0"); 01148 HeaderFieldValue hfv(requestLineString.data(), requestLineString.size()); 01149 01150 RequestLine requestLine(hfv); 01151 assert(requestLine.uri().scheme() == "sips"); 01152 assert(requestLine.uri().user() == "bob"); 01153 resipCerr << requestLine.uri().host() << endl; 01154 assert(requestLine.uri().host() == "foo.com"); 01155 assert(requestLine.getMethod() == INVITE); 01156 assert(requestLine.uri().param(p_maddr) == "1.2.3.4"); 01157 resipCerr << requestLine.getSipVersion() << endl; 01158 assert(requestLine.getSipVersion() == "SIP/2.0"); 01159 } 01160 { 01161 TR _tr( "NameAddr parse"); 01162 Data nameAddrString("sips:bob@foo.com"); 01163 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size()); 01164 01165 NameAddr nameAddr(hfv, Headers::UNKNOWN); 01166 assert(nameAddr.uri().scheme() == "sips"); 01167 assert(nameAddr.uri().user() == "bob"); 01168 assert(nameAddr.uri().host() == "foo.com"); 01169 } 01170 { 01171 TR _tr( "NameAddr parse, displayName"); 01172 Data nameAddrString("Bob<sips:bob@foo.com>"); 01173 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size()); 01174 01175 NameAddr nameAddr(hfv, Headers::UNKNOWN); 01176 assert(nameAddr.displayName() == "Bob"); 01177 assert(nameAddr.uri().scheme() == "sips"); 01178 assert(nameAddr.uri().user() == "bob"); 01179 assert(nameAddr.uri().host() == "foo.com"); 01180 } 01181 { 01182 TR _tr( "NameAddr parse, quoted displayname"); 01183 Data nameAddrString = "\"Bob\"<sips:bob@foo.com>"; 01184 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size()); 01185 01186 NameAddr nameAddr(hfv, Headers::UNKNOWN); 01187 assert(nameAddr.displayName() == "Bob"); 01188 assert(nameAddr.uri().scheme() == "sips"); 01189 assert(nameAddr.uri().user() == "bob"); 01190 assert(nameAddr.uri().host() == "foo.com"); 01191 } 01192 { 01193 TR _tr( "NameAddr parse, quoted displayname, embedded quotes"); 01194 Data nameAddrString("\"Bob \\\" asd \"<sips:bob@foo.com>"); 01195 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size()); 01196 01197 NameAddr nameAddr(hfv, Headers::UNKNOWN); 01198 assert(nameAddr.displayName() == "Bob \\\" asd "); 01199 assert(nameAddr.uri().scheme() == "sips"); 01200 assert(nameAddr.uri().user() == "bob"); 01201 assert(nameAddr.uri().host() == "foo.com"); 01202 } 01203 { 01204 TR _tr( "NameAddr parse, unquoted displayname, paramterMove"); 01205 Data nameAddrString("Bob<sips:bob@foo.com>;tag=456248;mobility=\"hobble\""); 01206 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size()); 01207 01208 NameAddr nameAddr(hfv, Headers::UNKNOWN); 01209 assert(nameAddr.displayName() == "Bob"); 01210 assert(nameAddr.uri().scheme() == "sips"); 01211 assert(nameAddr.uri().user() == "bob"); 01212 01213 assert(nameAddr.uri().host() == "foo.com"); 01214 01215 resipCerr << "Uri params: "; 01216 nameAddr.uri().encodeParameters(resipCerr) << endl; 01217 resipCerr << "Header params: "; 01218 nameAddr.encodeParameters(resipCerr) << endl; 01219 assert(nameAddr.param(p_tag) == "456248"); 01220 assert(nameAddr.param(p_mobility) == "hobble"); 01221 01222 assert(nameAddr.uri().exists(p_tag_ext) == false); 01223 assert(nameAddr.uri().exists(p_mobility_ext) == false); 01224 } 01225 { 01226 TR _tr( "NameAddr parse, quoted displayname, parameterMove"); 01227 Data nameAddrString("\"Bob\"<sips:bob@foo.com>;tag=456248;mobility=\"hobble\""); 01228 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size()); 01229 01230 NameAddr nameAddr(hfv, Headers::UNKNOWN); 01231 assert(nameAddr.displayName() == "Bob"); 01232 assert(nameAddr.uri().scheme() == "sips"); 01233 assert(nameAddr.uri().user() == "bob"); 01234 01235 assert(nameAddr.uri().host() == "foo.com"); 01236 01237 resipCerr << "Uri params: "; 01238 nameAddr.uri().encodeParameters(resipCerr) << endl; 01239 resipCerr << "Header params: "; 01240 nameAddr.encodeParameters(resipCerr) << endl; 01241 01242 assert(nameAddr.param(p_tag) == "456248"); 01243 assert(nameAddr.param(p_mobility) == "hobble"); 01244 01245 assert(nameAddr.uri().exists(p_tag_ext) == false); 01246 assert(nameAddr.uri().exists(p_mobility_ext) == false); 01247 } 01248 { 01249 TR _tr( "NameAddr parse, unquoted displayname, paramterMove"); 01250 Data nameAddrString("Bob<sips:bob@foo.com;tag=456248;mobility=\"hobble\">"); 01251 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size()); 01252 01253 NameAddr nameAddr(hfv, Headers::UNKNOWN); 01254 assert(nameAddr.displayName() == "Bob"); 01255 assert(nameAddr.uri().scheme() == "sips"); 01256 assert(nameAddr.uri().user() == "bob"); 01257 01258 assert(nameAddr.uri().host() == "foo.com"); 01259 01260 resipCerr << "Uri params: "; 01261 nameAddr.uri().encodeParameters(resipCerr) << endl; 01262 resipCerr << "Header params: "; 01263 nameAddr.encodeParameters(resipCerr) << endl; 01264 assert(nameAddr.uri().param(p_tag_ext) == "456248"); 01265 assert(nameAddr.uri().param(p_mobility_ext) == "hobble"); 01266 01267 assert(nameAddr.exists(p_tag) == false); 01268 assert(nameAddr.exists(p_mobility) == false); 01269 } 01270 { 01271 TR _tr( "NameAddr parse, unquoted displayname, paramterMove"); 01272 Data nameAddrString("Bob<sips:bob@foo.com;mobility=\"hobb;le\";tag=\"true;false\">"); 01273 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size()); 01274 01275 NameAddr nameAddr(hfv, Headers::UNKNOWN); 01276 assert(nameAddr.displayName() == "Bob"); 01277 assert(nameAddr.uri().scheme() == "sips"); 01278 assert(nameAddr.uri().user() == "bob"); 01279 01280 assert(nameAddr.uri().host() == "foo.com"); 01281 01282 resipCerr << "Uri params: "; 01283 nameAddr.uri().encodeParameters(resipCerr) << endl; 01284 resipCerr << "Header params: "; 01285 nameAddr.encodeParameters(resipCerr) << endl; 01286 assert(nameAddr.uri().param(p_mobility_ext) == "hobb;le"); 01287 assert(nameAddr.uri().param(p_tag_ext) == "true;false"); 01288 // assert("true;false" == nameAddr.uri().param(Data("useless"))); 01289 01290 assert(nameAddr.exists(p_mobility) == false); 01291 } 01292 { 01293 TR _tr( "NameAddr parse"); 01294 Data nameAddrString("sip:101@localhost:5080;transport=UDP"); 01295 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size()); 01296 01297 NameAddr nameAddr(hfv, Headers::UNKNOWN); 01298 assert(nameAddr.displayName() == ""); 01299 assert(nameAddr.uri().scheme() == "sip"); 01300 assert(nameAddr.uri().user() == "101"); 01301 } 01302 { 01303 TR _tr( "NameAddr parse, no user in uri"); 01304 Data nameAddrString("sip:localhost:5070"); 01305 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size()); 01306 01307 NameAddr nameAddr(hfv, Headers::UNKNOWN); 01308 assert(nameAddr.displayName() == ""); 01309 assert(nameAddr.uri().scheme() == "sip"); 01310 assert(nameAddr.uri().host() == "localhost"); 01311 assert(nameAddr.uri().user() == ""); 01312 assert(nameAddr.uri().port() == 5070); 01313 } 01314 { 01315 TR _tr( "StatusLine, no reason code"); 01316 Data statusLineString("SIP/2.0 100 "); 01317 HeaderFieldValue hfv(statusLineString.data(), statusLineString.size()); 01318 01319 StatusLine statusLine(hfv); 01320 assert(statusLine.responseCode() == 100); 01321 assert(statusLine.reason() == ""); 01322 assert(statusLine.getSipVersion() == "SIP/2.0"); 01323 } 01324 { 01325 TR _tr( "StatusLine, no reason code"); 01326 Data statusLineString("SIP/2.0 100"); 01327 HeaderFieldValue hfv(statusLineString.data(), statusLineString.size()); 01328 01329 StatusLine statusLine(hfv); 01330 assert(statusLine.responseCode() == 100); 01331 assert(statusLine.reason() == ""); 01332 assert(statusLine.getSipVersion() == "SIP/2.0"); 01333 } 01334 { 01335 TR _tr("Auth Schemes"); 01336 const char* authorizationString = "Digest realm=\"66.100.107.120\", username=\"1234\", nonce=\"1011235448\" , uri=\"sip:66.100.107.120\" , algorithm=MD5, response=\"8a5165b024fda362ed9c1e29a7af0ef2\""; 01337 HeaderFieldValue hfv(authorizationString, strlen(authorizationString)); 01338 01339 Auth auth(hfv, Headers::UNKNOWN); 01340 01341 resipCerr << "Auth scheme: " << auth.scheme() << endl; 01342 assert(auth.scheme() == "Digest"); 01343 resipCerr << " realm: " << auth.param(p_realm) << endl; 01344 assert(auth.param(p_realm) == "66.100.107.120"); 01345 assert(auth.param(p_username) == "1234"); 01346 assert(auth.param(p_nonce) == "1011235448"); 01347 assert(auth.param(p_uri) == "sip:66.100.107.120"); 01348 assert(auth.param(p_algorithm) == "MD5"); 01349 assert(auth.param(p_response) == "8a5165b024fda362ed9c1e29a7af0ef2"); 01350 01351 Data dsData; 01352 { 01353 DataStream s(dsData); 01354 auth.encode(s); 01355 } 01356 01357 resipCerr << dsData.c_str() << endl; 01358 01359 assert(dsData == "Digest realm=\"66.100.107.120\",username=\"1234\",nonce=\"1011235448\",uri=\"sip:66.100.107.120\",algorithm=MD5,response=\"8a5165b024fda362ed9c1e29a7af0ef2\""); 01360 } 01361 01362 { 01363 TR _tr("More Auth"); 01364 const char* authorizationString = "realm=\"66.100.107.120\", username=\"1234\", nonce=\"1011235448\" , uri=\"sip:66.100.107.120\" , algorithm=MD5, response=\"8a5165b024fda362ed9c1e29a7af0ef2\""; 01365 HeaderFieldValue hfv(authorizationString, strlen(authorizationString)); 01366 01367 Auth auth(hfv, Headers::UNKNOWN); 01368 01369 resipCerr << "Auth scheme: " << auth.scheme() << endl; 01370 assert(auth.scheme() == ""); 01371 resipCerr << " realm: " << auth.param(p_realm) << endl; 01372 assert(auth.param(p_realm) == "66.100.107.120"); 01373 assert(auth.param(p_username) == "1234"); 01374 assert(auth.param(p_nonce) == "1011235448"); 01375 assert(auth.param(p_uri) == "sip:66.100.107.120"); 01376 assert(auth.param(p_algorithm) == "MD5"); 01377 assert(auth.param(p_response) == "8a5165b024fda362ed9c1e29a7af0ef2"); 01378 01379 Data dsData; 01380 { 01381 DataStream s(dsData); 01382 auth.encode(s); 01383 } 01384 01385 resipCerr << dsData.c_str() << endl; 01386 01387 assert(dsData == "realm=\"66.100.107.120\",username=\"1234\",nonce=\"1011235448\",uri=\"sip:66.100.107.120\",algorithm=MD5,response=\"8a5165b024fda362ed9c1e29a7af0ef2\""); 01388 } 01389 01390 { 01391 TR _tr("Testing qop stuff"); 01392 const char* authenticationString = "realm=\"66.100.107.120\", username=\"1234\", nonce=\"1011235448\" , uri=\"sip:66.100.107.120\" , algorithm=MD5, qop=\"auth,auth-int\""; 01393 const char* authorizationString = "realm=\"66.100.107.120\", username=\"1234\", nonce=\"1011235448\" , uri=\"sip:66.100.107.120\" , algorithm=MD5, response=\"8a5165b024fda362ed9c1e29a7af0ef2\", qop=auth"; 01394 HeaderFieldValue authenHfv(authenticationString, strlen(authenticationString)); 01395 HeaderFieldValue authorHfv(authorizationString, strlen(authorizationString)); 01396 01397 Auth wwwAuthen(authenHfv, Headers::WWWAuthenticate); 01398 Auth pAuthen(authenHfv, Headers::ProxyAuthenticate); 01399 Auth authInfo(authorHfv, Headers::AuthenticationInfo); 01400 Auth pAuthor(authorHfv, Headers::ProxyAuthorization); 01401 Auth author(authorHfv, Headers::Authorization); 01402 01403 assert(wwwAuthen.exists(p_qopOptions)); 01404 assert(!wwwAuthen.exists(p_qop)); 01405 assert(wwwAuthen.param(p_qopOptions)=="auth,auth-int"); 01406 01407 assert(pAuthen.exists(p_qopOptions)); 01408 assert(!pAuthen.exists(p_qop)); 01409 assert(pAuthen.param(p_qopOptions)=="auth,auth-int"); 01410 01411 assert(!authInfo.exists(p_qopOptions)); 01412 assert(authInfo.exists(p_qop)); 01413 assert(authInfo.param(p_qop)=="auth"); 01414 01415 assert(!pAuthor.exists(p_qopOptions)); 01416 assert(pAuthor.exists(p_qop)); 01417 assert(pAuthor.param(p_qop)=="auth"); 01418 01419 assert(!author.exists(p_qopOptions)); 01420 assert(author.exists(p_qop)); 01421 assert(author.param(p_qop)=="auth"); 01422 01423 { 01424 Data encoded; 01425 { 01426 oDataStream str(encoded); 01427 wwwAuthen.encode(str); 01428 } 01429 assert(encoded.find("qop=auth")==Data::npos); 01430 assert(encoded.find("qop=\"auth,auth-int\"")!=Data::npos); 01431 assert(encoded.find("qop=\"auth\"")==Data::npos); 01432 assert(encoded.find("qop=auth,auth-int")==Data::npos); 01433 } 01434 01435 { 01436 Data encoded; 01437 { 01438 oDataStream str(encoded); 01439 pAuthen.encode(str); 01440 } 01441 assert(encoded.find("qop=auth")==Data::npos); 01442 assert(encoded.find("qop=\"auth,auth-int\"")!=Data::npos); 01443 assert(encoded.find("qop=\"auth\"")==Data::npos); 01444 assert(encoded.find("qop=auth,auth-int")==Data::npos); 01445 } 01446 01447 { 01448 Data encoded; 01449 { 01450 oDataStream str(encoded); 01451 authInfo.encode(str); 01452 } 01453 assert(encoded.find("qop=auth")!=Data::npos); 01454 assert(encoded.find("qop=\"auth,auth-int\"")==Data::npos); 01455 assert(encoded.find("qop=\"auth\"")==Data::npos); 01456 assert(encoded.find("qop=auth,auth-int")==Data::npos); 01457 } 01458 01459 { 01460 Data encoded; 01461 { 01462 oDataStream str(encoded); 01463 pAuthor.encode(str); 01464 } 01465 assert(encoded.find("qop=auth")!=Data::npos); 01466 assert(encoded.find("qop=\"auth,auth-int\"")==Data::npos); 01467 assert(encoded.find("qop=\"auth\"")==Data::npos); 01468 assert(encoded.find("qop=auth,auth-int")==Data::npos); 01469 } 01470 01471 { 01472 Data encoded; 01473 { 01474 oDataStream str(encoded); 01475 author.encode(str); 01476 } 01477 assert(encoded.find("qop=auth")!=Data::npos); 01478 assert(encoded.find("qop=\"auth,auth-int\"")==Data::npos); 01479 assert(encoded.find("qop=\"auth\"")==Data::npos); 01480 assert(encoded.find("qop=auth,auth-int")==Data::npos); 01481 } 01482 01483 Auth emptyAuthor; 01484 Auth emptyAuthen; 01485 01486 emptyAuthor.param(p_qop)="auth"; 01487 emptyAuthen.param(p_qopOptions)="auth"; 01488 01489 { 01490 Data encoded; 01491 { 01492 oDataStream str(encoded); 01493 emptyAuthor.encode(str); 01494 } 01495 assert(encoded.find("qop=auth")!=Data::npos); 01496 assert(encoded.find("qop=\"auth\"")==Data::npos); 01497 } 01498 01499 { 01500 Data encoded; 01501 { 01502 oDataStream str(encoded); 01503 emptyAuthen.encode(str); 01504 } 01505 assert(encoded.find("qop=auth")==Data::npos); 01506 assert(encoded.find("qop=\"auth\"")!=Data::npos); 01507 } 01508 } 01509 01510 { 01511 TR _tr("More Auth Encoding"); 01512 01513 Auth auth; 01514 Auth auth2; 01515 auth.scheme() = "Digest"; 01516 auth.param(p_username) = "bob"; 01517 01518 auth2 = auth; 01519 Auth auth3(auth2); 01520 01521 Data a; 01522 Data a1; 01523 Data a2; 01524 { 01525 DataStream s(a); 01526 s << auth; 01527 } 01528 { 01529 DataStream s(a1); 01530 s << auth; 01531 } 01532 { 01533 DataStream s(a2); 01534 s << auth; 01535 } 01536 01537 assert(a == a1); 01538 assert(a1 == a2); 01539 } 01540 01541 { 01542 TR _tr("Generic URI stuff"); 01543 01544 const char* genericString = "<http://www.google.com>;purpose=icon;fake=true"; 01545 HeaderFieldValue hfv(genericString, strlen(genericString)); 01546 01547 GenericUri generic(hfv, Headers::UNKNOWN); 01548 01549 assert(generic.uri() == "http://www.google.com"); 01550 resipCerr << generic.param(p_purpose) << endl; 01551 assert(generic.param(p_purpose) == "icon"); 01552 assert(generic.param(UnknownParameterType("fake")) == "true"); 01553 01554 Data dsData; 01555 { 01556 DataStream s(dsData); 01557 generic.encode(s); 01558 } 01559 01560 resipCerr << dsData.c_str() << endl; 01561 01562 assert(dsData == "<http://www.google.com>;purpose=icon;fake=true"); 01563 } 01564 01565 { 01566 TR _tr("Date testing 1"); 01567 const char *dateString = "Mon, 04 Nov 2002 17:34:15 GMT"; 01568 HeaderFieldValue hfv(dateString, strlen(dateString)); 01569 01570 DateCategory date(hfv, Headers::UNKNOWN); 01571 01572 assert(date.dayOfWeek() == Mon); 01573 assert(date.dayOfMonth() == 04); 01574 assert(date.month() == Nov); 01575 assert(date.year() == 2002); 01576 assert(date.hour() == 17); 01577 assert(date.minute() == 34); 01578 assert(date.second() == 15); 01579 01580 Data dsData; 01581 { 01582 DataStream s(dsData); 01583 date.encode(s); 01584 } 01585 01586 resipCerr << dsData.c_str() << endl; 01587 01588 assert(dsData == dateString); 01589 01590 // copy ctor not working in v1.94 ParserCategories.cxx 01591 01592 dsData.clear(); 01593 01594 DateCategory otherDate(date); 01595 { 01596 DataStream s2(dsData); 01597 otherDate.encode(s2); 01598 } 01599 resipCerr << "!! original date : " << date << endl; 01600 resipCerr << "!! original string : " << dateString << endl; 01601 resipCerr << "!! otherDate : " << otherDate << endl; 01602 resipCerr << "!! encoded otherDate : " << dsData.c_str() << endl; 01603 assert (dsData == dateString); 01604 01605 } 01606 01607 { 01608 TR _tr("Date testing 2"); 01609 const char *dateString = " Sun , 14 Jan 2222 07:04:05 GMT "; 01610 HeaderFieldValue hfv(dateString, strlen(dateString)); 01611 01612 DateCategory date(hfv, Headers::UNKNOWN); 01613 01614 assert(date.dayOfWeek() == Sun); 01615 assert(date.dayOfMonth() == 14); 01616 assert(date.month() == Jan); 01617 assert(date.year() == 2222); 01618 assert(date.hour() == 07); 01619 assert(date.minute() == 04); 01620 assert(date.second() == 05); 01621 01622 Data dsData; 01623 { 01624 DataStream s(dsData); 01625 date.encode(s); 01626 } 01627 assert(dsData == "Sun, 14 Jan 2222 07:04:05 GMT"); 01628 } 01629 01630 01631 { 01632 TR _tr("Mime types 1"); 01633 01634 const char* mimeString = "application/sdp"; 01635 HeaderFieldValue hfv(mimeString, strlen(mimeString)); 01636 01637 Mime mime(hfv, Headers::UNKNOWN); 01638 01639 assert(mime.type() == "application"); 01640 assert(mime.subType() == "sdp"); 01641 01642 Data dsData; 01643 { 01644 DataStream s(dsData); 01645 mime.encode(s); 01646 } 01647 assert(dsData == mimeString); 01648 } 01649 01650 01651 { 01652 TR _tr("Mime types 2"); 01653 const char* mimeString = "text/html ; charset=ISO-8859-4"; 01654 HeaderFieldValue hfv(mimeString, strlen(mimeString)); 01655 01656 Mime mime(hfv, Headers::UNKNOWN); 01657 01658 assert(mime.type() == "text"); 01659 assert(mime.subType() == "html"); 01660 assert(mime.param(p_charset) == "ISO-8859-4"); 01661 01662 Data dsData; 01663 { 01664 DataStream s(dsData); 01665 mime.encode(s); 01666 } 01667 assert(dsData == "text/html;charset=ISO-8859-4"); 01668 } 01669 01670 { 01671 TR _tr("Mime types 3"); 01672 01673 const char* mimeString = " text / html ; charset=ISO-8859-4"; 01674 HeaderFieldValue hfv(mimeString, strlen(mimeString)); 01675 01676 Mime mime(hfv, Headers::UNKNOWN); 01677 01678 assert(mime.type() == "text"); 01679 assert(mime.subType() == "html"); 01680 assert(mime.param(p_charset) == "ISO-8859-4"); 01681 01682 Data dsData; 01683 { 01684 DataStream s(dsData); 01685 mime.encode(s); 01686 } 01687 assert(dsData == "text/html;charset=ISO-8859-4"); 01688 } 01689 01690 { 01691 TR _tr("Via 1"); 01692 01693 Via via; 01694 via.encode(resipCerr); 01695 resipCerr << endl; 01696 01697 assert (via.param(p_branch).hasMagicCookie()); 01698 } 01699 01700 { 01701 TR _tr("Via 2"); 01702 01703 const char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj"; 01704 HeaderFieldValue hfv(viaString, strlen(viaString)); 01705 Via via(hfv, Headers::UNKNOWN); 01706 01707 assert (via.param(p_branch).hasMagicCookie()); 01708 01709 Data dsData; 01710 { 01711 DataStream s0(dsData); 01712 via.encode(s0); 01713 } 01714 resipCerr << dsData.c_str() << endl; 01715 assert(dsData == "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj"); 01716 01717 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj"); 01718 01719 dsData.clear(); 01720 { 01721 DataStream s1(dsData); 01722 via.encode(s1); 01723 } 01724 assert(dsData == "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj"); 01725 01726 via.param(p_branch).reset("jason"); 01727 dsData.clear(); 01728 { 01729 DataStream s2(dsData); 01730 via.encode(s2); 01731 } 01732 01733 resipCerr << "!! " << dsData.c_str() << endl; 01734 assert(dsData == "SIP/2.0/UDP ;branch=z9hG4bK" RESIP_COOKIE "1---jason"); 01735 assert(via.param(p_branch).getTransactionId() == "jason"); 01736 } 01737 01738 { 01739 TR _tr("Via 3"); 01740 const char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj ;ttl=70"; 01741 HeaderFieldValue hfv(viaString, strlen(viaString)); 01742 Via via(hfv, Headers::UNKNOWN); 01743 01744 assert (via.param(p_branch).hasMagicCookie()); 01745 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj"); 01746 assert (via.param(p_ttl) == 70); 01747 } 01748 01749 { 01750 TR _tr("Via 4"); 01751 const char* viaString = "SIP/2.0/UDP ;branch=oldassbranch"; 01752 HeaderFieldValue hfv(viaString, strlen(viaString)); 01753 Via via(hfv, Headers::UNKNOWN); 01754 01755 assert (!via.param(p_branch).hasMagicCookie()); 01756 assert (via.param(p_branch).getTransactionId() == "oldassbranch"); 01757 01758 Data dsData; 01759 DataStream s(dsData); 01760 via.encode(s); 01761 s.flush(); 01762 assert(dsData == "SIP/2.0/UDP ;branch=oldassbranch"); 01763 01764 via.param(p_branch).reset("jason"); 01765 dsData.clear(); 01766 via.encode(s); 01767 s.flush(); 01768 assert(dsData == "SIP/2.0/UDP ;branch=z9hG4bK" RESIP_COOKIE "1---jason"); 01769 assert(via.param(p_branch).getTransactionId() == "jason"); 01770 } 01771 01772 { 01773 TR _tr("Via 5 assignment with unknown parameter"); 01774 const char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj ;ttl=70;stid=abcd.2"; 01775 HeaderFieldValue hfv(viaString, strlen(viaString)); 01776 Via via(hfv, Headers::UNKNOWN); 01777 01778 assert (via.param(p_branch).hasMagicCookie()); 01779 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj"); 01780 assert (via.param(p_ttl) == 70); 01781 01782 Via via1; 01783 via1 = via; 01784 01785 resipCerr << "!! "; via1.encode(resipCerr); resipCerr << endl; 01786 assert(via1.param(UnknownParameterType("stid")) == "abcd.2"); 01787 } 01788 01789 { 01790 TR _tr("Via 6 parse with known parameter"); 01791 const char* viaString = "SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK" RESIP_COOKIE "1---ec1e.0;ttl=4\r\n"; 01792 HeaderFieldValue hfv(viaString, strlen(viaString)); 01793 Via via(hfv, Headers::UNKNOWN); 01794 01795 assert (via.param(p_branch).hasMagicCookie()); 01796 assert (via.param(p_branch).getTransactionId() == "ec1e.0"); 01797 resipCerr << "!! "; via.encode(resipCerr); resipCerr << endl; 01798 assert(via.param(p_ttl) == 4); 01799 } 01800 01801 { 01802 TR _tr("Via 7 parse with unknown parameter"); 01803 const char* viaString = "SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK" RESIP_COOKIE "1---ec1e.0;stid=489573115\r\n"; 01804 HeaderFieldValue hfv(viaString, strlen(viaString)); 01805 Via via(hfv, Headers::UNKNOWN); 01806 01807 assert (via.param(p_branch).hasMagicCookie()); 01808 assert (via.param(p_branch).getTransactionId() == "ec1e.0"); 01809 resipCerr << "!! "; via.encode(resipCerr); resipCerr << endl; 01810 assert(via.param(UnknownParameterType("stid")) == "489573115"); 01811 } 01812 01813 { 01814 TR _tr("Branch parameter 1"); 01815 01816 Data txt("=z9hG4bK" RESIP_COOKIE "1---jason"); 01817 ParseBuffer pb(txt.data(), txt.size()); 01818 BranchParameter bp(ParameterTypes::branch, pb, Data::toBitset(";")); 01819 assert(bp.hasMagicCookie()); 01820 assert(bp.getTransactionId() == "jason"); 01821 01822 bp.reset(bp.getTransactionId() + ".10"); 01823 bp.encode(resipCerr); resipCerr << endl; 01824 assert(bp.getTransactionId() == "jason.10"); 01825 01826 Data o; 01827 { 01828 DataStream s(o); 01829 bp.encode(s); 01830 } 01831 resipCerr << "!! " << o << endl; 01832 assert(o == "branch=z9hG4bK" RESIP_COOKIE "1---jason.10"); 01833 } 01834 01835 01836 { 01837 TR _tr("Branch parameter 2"); 01838 Data txt("=z9hG4bK" RESIP_COOKIE "14---jason.1.2.3"); 01839 ParseBuffer pb(txt.data(), txt.size()); 01840 01841 BranchParameter bpc(ParameterTypes::branch, pb, Data::toBitset(";")); 01842 assert(bpc.hasMagicCookie()); 01843 assert(bpc.getTransactionId() == "jason.1.2.3"); 01844 01845 Data o; 01846 { 01847 DataStream s(o); 01848 bpc.encode(s); 01849 } 01850 resipCerr << "!! " << o << endl; 01851 assert(o == "branch=z9hG4bK" RESIP_COOKIE "14---jason.1.2.3"); 01852 } 01853 01854 { 01855 TR _tr("Branch parameter 3"); 01856 Data txt("=z9hG4bK" RESIP_COOKIE "14---3e565-ef7w-17.1.2.3foobie"); 01857 ParseBuffer pb(txt.data(), txt.size()); 01858 01859 BranchParameter bpcc(ParameterTypes::branch, pb, Data::toBitset(";")); 01860 assert(bpcc.hasMagicCookie()); 01861 assert(bpcc.getTransactionId() == "3e565-ef7w-17.1.2.3foobie"); 01862 01863 Data o; 01864 { 01865 DataStream s(o); 01866 bpcc.encode(s); 01867 } 01868 resipCerr << "!! " << o << endl; 01869 assert(o == "branch=z9hG4bK" RESIP_COOKIE "14---3e565-ef7w-17.1.2.3foobie"); 01870 01871 bpcc.reset("foobie"); 01872 01873 o.clear(); 01874 { 01875 DataStream s(o); 01876 bpcc.encode(s); 01877 } 01878 resipCerr << "!! " << o << endl; 01879 assert(o == "branch=z9hG4bK" RESIP_COOKIE "1---foobie"); 01880 } 01881 01882 { 01883 TR _tr("Branch parameter 4"); 01884 Data txt("=z9hG4bK" RESIP_COOKIE "14---3e565-ef7w-17.1.2.3"); 01885 ParseBuffer pb(txt.data(), txt.size()); 01886 01887 BranchParameter bpcc(ParameterTypes::branch, pb, Data::toBitset(";")); 01888 assert(bpcc.hasMagicCookie()); 01889 assert(bpcc.getTransactionId() == "3e565-ef7w-17.1.2.3"); 01890 01891 Data o; 01892 { 01893 DataStream s(o); 01894 bpcc.encode(s); 01895 } 01896 resipCerr << "!! " << o << endl; 01897 assert(o == "branch=z9hG4bK" RESIP_COOKIE "14---3e565-ef7w-17.1.2.3"); 01898 } 01899 01900 { 01901 TR _tr("Branch parameter 7 empty ours"); 01902 Data txt("=z9hG4bK" RESIP_COOKIE "1---"); 01903 ParseBuffer pb(txt.data(), txt.size()); 01904 01905 BranchParameter bpcc(ParameterTypes::branch, pb, Data::toBitset(";")); 01906 assert(bpcc.hasMagicCookie()); 01907 assert(bpcc.getTransactionId() == ""); 01908 01909 Data o; 01910 { 01911 DataStream s(o); 01912 bpcc.encode(s); 01913 } 01914 resipCerr << "!! " << o << endl; 01915 assert(o == "branch=z9hG4bK" RESIP_COOKIE "1---"); 01916 } 01917 01918 { 01919 TR _tr("Branch parameter 8 badly formed ours"); 01920 Data txt("=z9hG4bK" RESIP_COOKIE "------"); 01921 ParseBuffer pb(txt.data(), txt.size()); 01922 01923 try 01924 { 01925 BranchParameter bpcc(ParameterTypes::branch, pb, Data::toBitset(";")); 01926 assert(bpcc.hasMagicCookie()); 01927 bpcc.getTransactionId(); 01928 assert(false); 01929 } 01930 catch (ParseException &e) 01931 { 01932 } 01933 } 01934 01935 { 01936 TR _tr("Branch parameter 9"); 01937 01938 Data txt("=z9hG4bK" RESIP_COOKIE "1-UEEzMjc2OA..--5b42cb698e8c6827790212ac5bdade1a;rport;received=64.124.66.32"); 01939 ParseBuffer pb(txt.data(), txt.size()); 01940 BranchParameter bp(ParameterTypes::branch, pb, Data::toBitset(";")); 01941 assert(bp.hasMagicCookie()); 01942 assert(bp.getTransactionId() == "5b42cb698e8c6827790212ac5bdade1a"); 01943 resipCerr << "!! " << bp.clientData() << endl; 01944 assert(bp.clientData() == "PA32768"); 01945 01946 bp.encode(resipCerr); resipCerr << endl; 01947 } 01948 01949 { 01950 TR _tr("Branch parameter 10; magic cookie case mismatch"); 01951 01952 Data txt("=z9hG4bk15775865934415"); //little k 01953 ParseBuffer pb(txt.data(), txt.size()); 01954 BranchParameter bp(ParameterTypes::branch, pb, Data::toBitset(";")); 01955 assert(bp.hasMagicCookie()); 01956 01957 assert(bp.getTransactionId() == "15775865934415"); 01958 Data enc; 01959 { 01960 DataStream ds(enc); 01961 bp.encode(ds); 01962 } 01963 cout << "!! " << enc << endl; 01964 01965 assert(enc == "branch=z9hG4bk15775865934415"); 01966 01967 BranchParameter bpCopyCons(bp); 01968 Data encCopyCons; 01969 { 01970 DataStream ds(encCopyCons); 01971 bpCopyCons.encode(ds); 01972 } 01973 cout << "!! " << encCopyCons << endl; 01974 assert(bp == bpCopyCons); 01975 assert(encCopyCons == "branch=z9hG4bk15775865934415"); 01976 01977 Data txt2("=z9hG4bk1577234fhg8df"); 01978 ParseBuffer pb2(txt2.data(), txt2.size()); 01979 01980 BranchParameter bpAssignOp(ParameterTypes::branch, pb2, Data::toBitset(";")); 01981 bpAssignOp = bp; 01982 01983 Data encAssignOp; 01984 { 01985 DataStream ds(encAssignOp); 01986 bpAssignOp.encode(ds); 01987 } 01988 cout << "!! " << encAssignOp << endl; 01989 assert(bp == bpAssignOp); 01990 assert(encAssignOp == "branch=z9hG4bk15775865934415"); 01991 } 01992 01993 { 01994 TR _tr("Branch testing 1"); 01995 const char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj ;ttl=70"; 01996 HeaderFieldValue hfv(viaString, strlen(viaString)); 01997 Via via(hfv, Headers::UNKNOWN); 01998 01999 assert (via.param(p_branch).hasMagicCookie()); 02000 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj"); 02001 assert (via.param(p_ttl) == 70); 02002 assert (!via.exists(p_rport)); 02003 02004 via.param(p_rport); 02005 assert (via.exists(p_rport)); 02006 assert (via.exists(p_rport)); 02007 assert (!via.param(p_rport).hasValue()); 02008 } 02009 02010 { 02011 TR _tr("Branch testing 2"); 02012 const char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj ;ttl=70;rport"; 02013 HeaderFieldValue hfv(viaString, strlen(viaString)); 02014 Via via(hfv, Headers::UNKNOWN); 02015 02016 assert (via.param(p_branch).hasMagicCookie()); 02017 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj"); 02018 assert (via.param(p_ttl) == 70); 02019 assert (via.exists(p_rport)); 02020 assert (!via.param(p_rport).hasValue()); 02021 } 02022 02023 { 02024 TR _tr("Branch testing 3"); 02025 const char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj ;ttl=70;rport=100"; 02026 HeaderFieldValue hfv(viaString, strlen(viaString)); 02027 Via via(hfv, Headers::UNKNOWN); 02028 02029 assert (via.param(p_branch).hasMagicCookie()); 02030 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj"); 02031 assert (via.param(p_ttl) == 70); 02032 assert (via.exists(p_rport)); 02033 assert (via.param(p_rport).hasValue()); 02034 assert (via.param(p_rport).port() == 100); 02035 } 02036 02037 { 02038 TR _tr("Branch testing 4 with clientData"); 02039 Data txt("=z9hG4bK" RESIP_COOKIE "314-Q2xpZW50RGF0YQ..--T-i-D"); 02040 02041 ParseBuffer pb(txt.data(), txt.size()); 02042 02043 BranchParameter bpcc(ParameterTypes::branch, pb, Data::toBitset(";")); 02044 assert (bpcc.getTransactionId() == "T-i-D"); 02045 assert (bpcc.clientData() == "ClientData"); 02046 02047 Data o; 02048 { 02049 DataStream s(o); 02050 bpcc.encode(s); 02051 } 02052 // resipCerr << "!! " << o << endl; 02053 assert(o == "branch=z9hG4bK" RESIP_COOKIE "314-Q2xpZW50RGF0YQ..--T-i-D"); 02054 } 02055 02056 { 02057 TR _tr("Branch testing 5 with sigcomp ID"); 02058 Data txt("=z9hG4bK" RESIP_COOKIE "314--PHVybjp1dWlkOmZhMzNjNzJkLTEyMWYtNDdlOC00MmUyLTFlYjZlMjRhYmE2ND4.-T-i-D"); 02059 02060 ParseBuffer pb(txt.data(), txt.size()); 02061 02062 BranchParameter bpcc(ParameterTypes::branch, pb, Data::toBitset(";")); 02063 assert (bpcc.getTransactionId() == "T-i-D"); 02064 assert (bpcc.clientData() == ""); 02065 assert (bpcc.getSigcompCompartment() == "<urn:uuid:fa33c72d-121f-47e8-42e2-1eb6e24aba64>"); 02066 02067 bpcc.setSigcompCompartment("<urn:uuid:fa33c72d-121f-47e8-42e2-1eb6e24aba64>"); 02068 02069 Data o; 02070 { 02071 DataStream s(o); 02072 bpcc.encode(s); 02073 } 02074 // resipCerr << "!! " << o << endl; 02075 assert(o == "branch=z9hG4bK" RESIP_COOKIE "314--PHVybjp1dWlkOmZhMzNjNzJkLTEyMWYtNDdlOC00MmUyLTFlYjZlMjRhYmE2ND4.-T-i-D"); 02076 } 02077 02078 { 02079 TR _tr("Branch testing 6 with sigcomp ID and Client Data"); 02080 Data txt("=z9hG4bK" RESIP_COOKIE "314-Q2xpZW50RGF0YQ..-PHVybjp1dWlkOmZhMzNjNzJkLTEyMWYtNDdlOC00MmUyLTFlYjZlMjRhYmE2ND4.-T-i-D"); 02081 02082 ParseBuffer pb(txt.data(), txt.size()); 02083 02084 BranchParameter bpcc(ParameterTypes::branch, pb, Data::toBitset(";")); 02085 assert (bpcc.getTransactionId() == "T-i-D"); 02086 assert (bpcc.clientData() == "ClientData"); 02087 assert (bpcc.getSigcompCompartment() == "<urn:uuid:fa33c72d-121f-47e8-42e2-1eb6e24aba64>"); 02088 02089 bpcc.setSigcompCompartment("<urn:uuid:fa33c72d-121f-47e8-42e2-1eb6e24aba64>"); 02090 02091 Data o; 02092 { 02093 DataStream s(o); 02094 bpcc.encode(s); 02095 } 02096 // resipCerr << "!! " << o << endl; 02097 assert(o == "branch=z9hG4bK" RESIP_COOKIE "314-Q2xpZW50RGF0YQ..-PHVybjp1dWlkOmZhMzNjNzJkLTEyMWYtNDdlOC00MmUyLTFlYjZlMjRhYmE2ND4.-T-i-D"); 02098 } 02099 02100 //3329 tests 02101 { 02102 TR _tr( "Token + parameters parse test 3329 "); 02103 const char *org = "digest;d-alg=md5"; 02104 02105 HeaderFieldValue hfv(org, strlen(org)); 02106 Token tok(hfv, Headers::UNKNOWN); 02107 assert(tok.value() == "digest"); 02108 assert(tok.param(p_dAlg) == "md5"); 02109 } 02110 02111 { 02112 TR _tr( "Token + parameters parse test"); 02113 const char *org = "digest;d-qop=verify"; 02114 02115 HeaderFieldValue hfv(org, strlen(org)); 02116 Token tok(hfv, Headers::UNKNOWN); 02117 assert(tok.value() == "digest"); 02118 assert(tok.param(p_dQop) == "verify"); 02119 } 02120 02121 { 02122 TR _tr( "Token + parameters parse test"); 02123 const char *org = "digest;d-ver=\"0000000000000000000000000000abcd\""; 02124 02125 HeaderFieldValue hfv(org, strlen(org)); 02126 Token tok(hfv, Headers::UNKNOWN); 02127 assert(tok.value() == "digest"); 02128 assert(tok.param(p_dVer) == "0000000000000000000000000000abcd"); 02129 } 02130 02131 { 02132 TR _tr( "Test CSeqCategory 1"); 02133 Data cseqString("1 INVITE"); 02134 HeaderFieldValue hfv(cseqString.data(), cseqString.size()); 02135 02136 CSeqCategory str(hfv, Headers::UNKNOWN); 02137 assert(str.sequence() == 1); 02138 assert(str.method() == INVITE); 02139 assert(Data::from(str) == cseqString); 02140 } 02141 02142 { 02143 TR _tr( "Test CSeqCategory 2"); 02144 Data cseqString("4294967295 INVITE"); 02145 HeaderFieldValue hfv(cseqString.data(), cseqString.size()); 02146 02147 CSeqCategory str(hfv, Headers::UNKNOWN); 02148 assert(str.sequence() == 4294967295U); 02149 assert(str.method() == INVITE); 02150 assert(Data::from(str) == cseqString); 02151 } 02152 02153 { 02154 TR _tr( "Test RAckCategory 1"); 02155 Data rackString("1 2 INVITE"); 02156 HeaderFieldValue hfv(rackString.data(), rackString.size()); 02157 02158 RAckCategory str(hfv, Headers::UNKNOWN); 02159 assert(str.rSequence() == 1); 02160 assert(str.cSequence() == 2); 02161 assert(str.method() == INVITE); 02162 assert(Data::from(str) == rackString); 02163 } 02164 02165 { 02166 TR _tr( "Test RAckCategory 2"); 02167 Data rackString("4294967294 4294967295 INVITE"); 02168 HeaderFieldValue hfv(rackString.data(), rackString.size()); 02169 02170 RAckCategory str(hfv, Headers::UNKNOWN); 02171 assert(str.rSequence() == 4294967294U); 02172 assert(str.cSequence() == 4294967295U); 02173 assert(str.method() == INVITE); 02174 assert(Data::from(str) == rackString); 02175 } 02176 02177 { 02178 TR _tr( "Test Privacy Category 1"); 02179 Data privacy("user;session;critical"); 02180 HeaderFieldValue hfv(privacy.data(), privacy.size()); 02181 02182 PrivacyCategory test(hfv, Headers::UNKNOWN); 02183 assert(test.value().size()==3); 02184 assert(test.value().back()=="critical"); 02185 test.value().pop_back(); 02186 assert(test.value().back()=="session"); 02187 test.value().pop_back(); 02188 assert(test.value().back()=="user"); 02189 test.value().pop_back(); 02190 } 02191 02192 { 02193 TR _tr( "Test Privacy Category 2"); 02194 Data privacy("user; session; critical "); 02195 HeaderFieldValue hfv(privacy.data(), privacy.size()); 02196 02197 PrivacyCategory test(hfv, Headers::UNKNOWN); 02198 assert(test.value().size()==3); 02199 assert(test.value().back()=="critical"); 02200 test.value().pop_back(); 02201 assert(test.value().back()=="session"); 02202 test.value().pop_back(); 02203 assert(test.value().back()=="user"); 02204 test.value().pop_back(); 02205 } 02206 02207 { 02208 TR _tr( "Test Privacy Category 3"); 02209 Data privacy("user"); 02210 HeaderFieldValue hfv(privacy.data(), privacy.size()); 02211 02212 PrivacyCategory test(hfv, Headers::UNKNOWN); 02213 assert(test.value().size()==1); 02214 assert(test.value().back()=="user"); 02215 test.value().pop_back(); 02216 } 02217 02218 // Performance tests 02219 02220 { 02221 resip::Data test("Raw header-field-value creation/deletion"); 02222 cout << endl << test << endl; 02223 UInt64 now(Timer::getTimeMicroSec()); 02224 for(int i=0; i<10000000; ++i) 02225 { 02226 HeaderFieldValue hfv(test.data(), test.size()); 02227 // (hfv, Headers::UNKNOWN); 02228 } 02229 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02230 } 02231 02232 // Auth 02233 { 02234 resip::Data test("Auth creation/deletion"); 02235 cout << endl << test << endl; 02236 HeaderFieldValue hfv(test.data(), test.size()); 02237 UInt64 now(Timer::getTimeMicroSec()); 02238 for(int i=0; i<10000000; ++i) 02239 { 02240 Auth auth(hfv, Headers::UNKNOWN); 02241 } 02242 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02243 } 02244 02245 { 02246 resip::Data test("Digest nonce=\"1305231689:fed475e952ee1d3ecaf60b17bce12218\",algorithm=MD5,realm=\"localhost\",qop=\"auth,auth-int\""); 02247 cout << endl << test << endl; 02248 HeaderFieldValue hfv(test.data(), test.size()); 02249 UInt64 now(Timer::getTimeMicroSec()); 02250 for(int i=0; i<10000000; ++i) 02251 { 02252 Auth auth(hfv, Headers::UNKNOWN); 02253 auth.checkParsed(); 02254 } 02255 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02256 cout << "encodes:" << endl; 02257 Auth pc(hfv, Headers::UNKNOWN); 02258 pc.checkParsed(); 02259 Data buffer; 02260 oDataStream str(buffer); 02261 now=Timer::getTimeMicroSec(); 02262 for(int i=0; i<10000000; ++i) 02263 { 02264 pc.encode(str); 02265 str.flush(); 02266 str.reset(); 02267 } 02268 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02269 } 02270 02271 { 02272 resip::Data test("Digest username=\"derek\",realm=\"localhost\",nonce=\"1305231689:fed475e952ee1d3ecaf60b17bce12218\",uri=\"sip:jason@localhost\",response=\"88f519f04c2a09c500af88ff7bccdf52\",cnonce=\"foo\",nc=0000005D,qop=auth-int,algorithm=MD5"); 02273 cout << endl << test << endl; 02274 HeaderFieldValue hfv(test.data(), test.size()); 02275 UInt64 now(Timer::getTimeMicroSec()); 02276 for(int i=0; i<10000000; ++i) 02277 { 02278 Auth auth(hfv, Headers::UNKNOWN); 02279 auth.checkParsed(); 02280 } 02281 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02282 cout << "encodes:" << endl; 02283 Auth pc(hfv, Headers::UNKNOWN); 02284 pc.checkParsed(); 02285 Data buffer; 02286 oDataStream str(buffer); 02287 now=Timer::getTimeMicroSec(); 02288 for(int i=0; i<10000000; ++i) 02289 { 02290 pc.encode(str); 02291 str.flush(); 02292 str.reset(); 02293 } 02294 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02295 } 02296 02297 // CSeq 02298 { 02299 resip::Data test("CSeq creation/deletion"); 02300 cout << endl << test << endl; 02301 HeaderFieldValue hfv(test.data(), test.size()); 02302 UInt64 now(Timer::getTimeMicroSec()); 02303 for(int i=0; i<10000000; ++i) 02304 { 02305 CSeqCategory cseq(hfv, Headers::UNKNOWN); 02306 } 02307 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02308 } 02309 02310 { 02311 resip::Data test("9872643 INVITE"); 02312 cout << endl << test << endl; 02313 HeaderFieldValue hfv(test.data(), test.size()); 02314 UInt64 now(Timer::getTimeMicroSec()); 02315 for(int i=0; i<10000000; ++i) 02316 { 02317 CSeqCategory cseq(hfv, Headers::UNKNOWN); 02318 cseq.checkParsed(); 02319 } 02320 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02321 cout << "encodes:" << endl; 02322 CSeqCategory pc(hfv, Headers::UNKNOWN); 02323 pc.checkParsed(); 02324 Data buffer; 02325 oDataStream str(buffer); 02326 now=Timer::getTimeMicroSec(); 02327 for(int i=0; i<10000000; ++i) 02328 { 02329 pc.encode(str); 02330 str.flush(); 02331 str.reset(); 02332 } 02333 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02334 } 02335 02336 { 02337 resip::Data test("1 INVITE"); 02338 cout << endl << test << endl; 02339 HeaderFieldValue hfv(test.data(), test.size()); 02340 UInt64 now(Timer::getTimeMicroSec()); 02341 for(int i=0; i<10000000; ++i) 02342 { 02343 CSeqCategory cseq(hfv, Headers::UNKNOWN); 02344 cseq.checkParsed(); 02345 } 02346 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02347 cout << "encodes:" << endl; 02348 CSeqCategory pc(hfv, Headers::UNKNOWN); 02349 pc.checkParsed(); 02350 Data buffer; 02351 oDataStream str(buffer); 02352 now=Timer::getTimeMicroSec(); 02353 for(int i=0; i<10000000; ++i) 02354 { 02355 pc.encode(str); 02356 str.flush(); 02357 str.reset(); 02358 } 02359 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02360 } 02361 02362 02363 // CallId 02364 { 02365 resip::Data test("CallId creation/deletion"); 02366 cout << endl << test << endl; 02367 HeaderFieldValue hfv(test.data(), test.size()); 02368 UInt64 now(Timer::getTimeMicroSec()); 02369 for(int i=0; i<10000000; ++i) 02370 { 02371 CallId callid(hfv, Headers::UNKNOWN); 02372 } 02373 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02374 } 02375 02376 { 02377 resip::Data test("NOIUYCEOGoIUBaocuwyVCopiuVAbcs"); 02378 cout << endl << test << endl; 02379 HeaderFieldValue hfv(test.data(), test.size()); 02380 UInt64 now(Timer::getTimeMicroSec()); 02381 for(int i=0; i<10000000; ++i) 02382 { 02383 CallId callid(hfv, Headers::UNKNOWN); 02384 callid.checkParsed(); 02385 } 02386 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02387 cout << "encodes:" << endl; 02388 CallId pc(hfv, Headers::UNKNOWN); 02389 pc.checkParsed(); 02390 Data buffer; 02391 oDataStream str(buffer); 02392 now=Timer::getTimeMicroSec(); 02393 for(int i=0; i<10000000; ++i) 02394 { 02395 pc.encode(str); 02396 str.flush(); 02397 str.reset(); 02398 } 02399 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02400 } 02401 02402 02403 // Date 02404 { 02405 resip::Data test("Date creation/deletion"); 02406 cout << endl << test << endl; 02407 HeaderFieldValue hfv(test.data(), test.size()); 02408 UInt64 now(Timer::getTimeMicroSec()); 02409 for(int i=0; i<10000000; ++i) 02410 { 02411 DateCategory date(hfv, Headers::UNKNOWN); 02412 } 02413 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02414 } 02415 02416 { 02417 resip::Data test("Thu, 21 Feb 2002 13:02:03 GMT"); 02418 cout << endl << test << endl; 02419 HeaderFieldValue hfv(test.data(), test.size()); 02420 UInt64 now(Timer::getTimeMicroSec()); 02421 for(int i=0; i<10000000; ++i) 02422 { 02423 DateCategory date(hfv, Headers::UNKNOWN); 02424 date.checkParsed(); 02425 } 02426 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02427 cout << "encodes:" << endl; 02428 DateCategory pc(hfv, Headers::UNKNOWN); 02429 pc.checkParsed(); 02430 Data buffer; 02431 oDataStream str(buffer); 02432 now=Timer::getTimeMicroSec(); 02433 for(int i=0; i<10000000; ++i) 02434 { 02435 pc.encode(str); 02436 str.flush(); 02437 str.reset(); 02438 } 02439 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02440 } 02441 02442 02443 // Expires 02444 { 02445 resip::Data test("Expires creation/deletion"); 02446 cout << endl << test << endl; 02447 HeaderFieldValue hfv(test.data(), test.size()); 02448 UInt64 now(Timer::getTimeMicroSec()); 02449 for(int i=0; i<10000000; ++i) 02450 { 02451 ExpiresCategory pc(hfv, Headers::UNKNOWN); 02452 } 02453 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02454 } 02455 02456 { 02457 resip::Data test("3600"); 02458 cout << endl << test << endl; 02459 HeaderFieldValue hfv(test.data(), test.size()); 02460 UInt64 now(Timer::getTimeMicroSec()); 02461 for(int i=0; i<10000000; ++i) 02462 { 02463 ExpiresCategory pc(hfv, Headers::UNKNOWN); 02464 pc.checkParsed(); 02465 } 02466 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02467 cout << "encodes:" << endl; 02468 ExpiresCategory pc(hfv, Headers::UNKNOWN); 02469 pc.checkParsed(); 02470 Data buffer; 02471 oDataStream str(buffer); 02472 now=Timer::getTimeMicroSec(); 02473 for(int i=0; i<10000000; ++i) 02474 { 02475 pc.encode(str); 02476 str.flush(); 02477 str.reset(); 02478 } 02479 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02480 } 02481 02482 02483 // Mime 02484 { 02485 resip::Data test("Mime creation/deletion"); 02486 cout << endl << test << endl; 02487 HeaderFieldValue hfv(test.data(), test.size()); 02488 UInt64 now(Timer::getTimeMicroSec()); 02489 for(int i=0; i<10000000; ++i) 02490 { 02491 Mime pc(hfv, Headers::UNKNOWN); 02492 } 02493 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02494 } 02495 02496 { 02497 resip::Data test("application/rlmi+xml"); 02498 cout << endl << test << endl; 02499 HeaderFieldValue hfv(test.data(), test.size()); 02500 UInt64 now(Timer::getTimeMicroSec()); 02501 for(int i=0; i<10000000; ++i) 02502 { 02503 Mime pc(hfv, Headers::UNKNOWN); 02504 pc.checkParsed(); 02505 } 02506 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02507 cout << "encodes:" << endl; 02508 Mime pc(hfv, Headers::UNKNOWN); 02509 pc.checkParsed(); 02510 Data buffer; 02511 oDataStream str(buffer); 02512 now=Timer::getTimeMicroSec(); 02513 for(int i=0; i<10000000; ++i) 02514 { 02515 pc.encode(str); 02516 str.flush(); 02517 str.reset(); 02518 } 02519 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02520 } 02521 02522 { 02523 resip::Data test("application/sdp"); 02524 cout << endl << test << endl; 02525 HeaderFieldValue hfv(test.data(), test.size()); 02526 UInt64 now(Timer::getTimeMicroSec()); 02527 for(int i=0; i<10000000; ++i) 02528 { 02529 Mime pc(hfv, Headers::UNKNOWN); 02530 pc.checkParsed(); 02531 } 02532 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02533 cout << "encodes:" << endl; 02534 Mime pc(hfv, Headers::UNKNOWN); 02535 pc.checkParsed(); 02536 Data buffer; 02537 oDataStream str(buffer); 02538 now=Timer::getTimeMicroSec(); 02539 for(int i=0; i<10000000; ++i) 02540 { 02541 pc.encode(str); 02542 str.flush(); 02543 str.reset(); 02544 } 02545 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02546 } 02547 02548 02549 // NameAddr 02550 { 02551 resip::Data test("NameAddr creation/deletion"); 02552 cout << endl << test << endl; 02553 HeaderFieldValue hfv(test.data(), test.size()); 02554 UInt64 now(Timer::getTimeMicroSec()); 02555 for(int i=0; i<10000000; ++i) 02556 { 02557 NameAddr pc(hfv, Headers::UNKNOWN); 02558 } 02559 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02560 } 02561 02562 { 02563 resip::Data test("<sip:rls.example.com>"); 02564 cout << endl << test << endl; 02565 HeaderFieldValue hfv(test.data(), test.size()); 02566 UInt64 now(Timer::getTimeMicroSec()); 02567 for(int i=0; i<10000000; ++i) 02568 { 02569 NameAddr pc(hfv, Headers::UNKNOWN); 02570 pc.checkParsed(); 02571 } 02572 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02573 cout << "encodes:" << endl; 02574 NameAddr pc(hfv, Headers::UNKNOWN); 02575 pc.checkParsed(); 02576 Data buffer; 02577 oDataStream str(buffer); 02578 now=Timer::getTimeMicroSec(); 02579 for(int i=0; i<10000000; ++i) 02580 { 02581 pc.encode(str); 02582 str.flush(); 02583 str.reset(); 02584 } 02585 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02586 } 02587 02588 { 02589 resip::Data test("<sip:rls.example.com;lr>"); 02590 cout << endl << test << endl; 02591 HeaderFieldValue hfv(test.data(), test.size()); 02592 UInt64 now(Timer::getTimeMicroSec()); 02593 for(int i=0; i<10000000; ++i) 02594 { 02595 NameAddr pc(hfv, Headers::UNKNOWN); 02596 pc.checkParsed(); 02597 } 02598 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02599 cout << "encodes:" << endl; 02600 NameAddr pc(hfv, Headers::UNKNOWN); 02601 pc.checkParsed(); 02602 Data buffer; 02603 oDataStream str(buffer); 02604 now=Timer::getTimeMicroSec(); 02605 for(int i=0; i<10000000; ++i) 02606 { 02607 pc.encode(str); 02608 str.flush(); 02609 str.reset(); 02610 } 02611 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02612 } 02613 02614 { 02615 resip::Data test("<sipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsipsip:rls.example.com;lr>"); 02616 cout << endl << test << endl; 02617 HeaderFieldValue hfv(test.data(), test.size()); 02618 UInt64 now(Timer::getTimeMicroSec()); 02619 for(int i=0; i<10000000; ++i) 02620 { 02621 NameAddr pc(hfv, Headers::UNKNOWN); 02622 pc.checkParsed(); 02623 } 02624 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02625 cout << "encodes:" << endl; 02626 NameAddr pc(hfv, Headers::UNKNOWN); 02627 pc.checkParsed(); 02628 Data buffer; 02629 oDataStream str(buffer); 02630 now=Timer::getTimeMicroSec(); 02631 for(int i=0; i<10000000; ++i) 02632 { 02633 pc.encode(str); 02634 str.flush(); 02635 str.reset(); 02636 } 02637 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02638 } 02639 02640 { 02641 resip::Data strangeUser("работающий"); 02642 strangeUser=strangeUser.charEncoded(); 02643 resip::Data test("<sip:" + strangeUser+ "@example.com;lr>"); 02644 cout << endl << test << endl; 02645 HeaderFieldValue hfv(test.data(), test.size()); 02646 UInt64 now(Timer::getTimeMicroSec()); 02647 for(int i=0; i<10000000; ++i) 02648 { 02649 NameAddr pc(hfv, Headers::UNKNOWN); 02650 pc.checkParsed(); 02651 } 02652 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02653 cout << "encodes:" << endl; 02654 NameAddr pc(hfv, Headers::UNKNOWN); 02655 pc.checkParsed(); 02656 Data buffer; 02657 oDataStream str(buffer); 02658 now=Timer::getTimeMicroSec(); 02659 for(int i=0; i<10000000; ++i) 02660 { 02661 pc.encode(str); 02662 str.flush(); 02663 str.reset(); 02664 } 02665 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02666 } 02667 02668 { 02669 resip::Data test(" \"Derek\" <sip:derek@localhost>;tag=16d1246e"); 02670 cout << endl << test << endl; 02671 HeaderFieldValue hfv(test.data(), test.size()); 02672 UInt64 now(Timer::getTimeMicroSec()); 02673 for(int i=0; i<10000000; ++i) 02674 { 02675 NameAddr pc(hfv, Headers::UNKNOWN); 02676 pc.checkParsed(); 02677 } 02678 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02679 cout << "encodes:" << endl; 02680 NameAddr pc(hfv, Headers::UNKNOWN); 02681 pc.checkParsed(); 02682 Data buffer; 02683 oDataStream str(buffer); 02684 now=Timer::getTimeMicroSec(); 02685 for(int i=0; i<10000000; ++i) 02686 { 02687 pc.encode(str); 02688 str.flush(); 02689 str.reset(); 02690 } 02691 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02692 } 02693 02694 { 02695 resip::Data test("<sip:line1@192.0.2.2;transport=tcp>; reg-id=1;+sip.instance=\"<urn:uuid:00000000-0000-1000-8000-000A95A0E128>\""); 02696 cout << endl << test << endl; 02697 HeaderFieldValue hfv(test.data(), test.size()); 02698 UInt64 now(Timer::getTimeMicroSec()); 02699 for(int i=0; i<10000000; ++i) 02700 { 02701 NameAddr pc(hfv, Headers::UNKNOWN); 02702 pc.checkParsed(); 02703 } 02704 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02705 cout << "encodes:" << endl; 02706 NameAddr pc(hfv, Headers::UNKNOWN); 02707 pc.checkParsed(); 02708 Data buffer; 02709 oDataStream str(buffer); 02710 now=Timer::getTimeMicroSec(); 02711 for(int i=0; i<10000000; ++i) 02712 { 02713 pc.encode(str); 02714 str.flush(); 02715 str.reset(); 02716 } 02717 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02718 } 02719 02720 { 02721 resip::Data test("<sip:line1@192.0.2.2:5060;transport=tcp>; reg-id=1;+sip.instance=\"<urn:uuid:00000000-0000-1000-8000-000A95A0E128>\""); 02722 cout << endl << test << endl; 02723 HeaderFieldValue hfv(test.data(), test.size()); 02724 UInt64 now(Timer::getTimeMicroSec()); 02725 for(int i=0; i<10000000; ++i) 02726 { 02727 NameAddr pc(hfv, Headers::UNKNOWN); 02728 pc.checkParsed(); 02729 } 02730 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02731 cout << "encodes:" << endl; 02732 NameAddr pc(hfv, Headers::UNKNOWN); 02733 pc.checkParsed(); 02734 Data buffer; 02735 oDataStream str(buffer); 02736 now=Timer::getTimeMicroSec(); 02737 for(int i=0; i<10000000; ++i) 02738 { 02739 pc.encode(str); 02740 str.flush(); 02741 str.reset(); 02742 } 02743 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02744 } 02745 02746 02747 // RequestLine 02748 { 02749 resip::Data test("RequestLine creation/deletion"); 02750 cout << endl << test << endl; 02751 HeaderFieldValue hfv(test.data(), test.size()); 02752 UInt64 now(Timer::getTimeMicroSec()); 02753 for(int i=0; i<10000000; ++i) 02754 { 02755 RequestLine pc(hfv); 02756 } 02757 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02758 } 02759 02760 { 02761 resip::Data test("INVITE sip:bob@example.com SIP/2.0"); 02762 cout << endl << test << endl; 02763 HeaderFieldValue hfv(test.data(), test.size()); 02764 UInt64 now(Timer::getTimeMicroSec()); 02765 for(int i=0; i<10000000; ++i) 02766 { 02767 RequestLine pc(hfv); 02768 pc.checkParsed(); 02769 } 02770 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02771 cout << "encodes:" << endl; 02772 RequestLine pc(hfv); 02773 pc.checkParsed(); 02774 Data buffer; 02775 oDataStream str(buffer); 02776 now=Timer::getTimeMicroSec(); 02777 for(int i=0; i<10000000; ++i) 02778 { 02779 pc.encode(str); 02780 str.flush(); 02781 str.reset(); 02782 } 02783 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02784 } 02785 02786 { 02787 resip::Data test("UNKNOWN sip:bob@example.com SIP/2.0"); 02788 cout << endl << test << endl; 02789 HeaderFieldValue hfv(test.data(), test.size()); 02790 UInt64 now(Timer::getTimeMicroSec()); 02791 for(int i=0; i<10000000; ++i) 02792 { 02793 RequestLine pc(hfv); 02794 pc.checkParsed(); 02795 } 02796 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02797 cout << "encodes:" << endl; 02798 RequestLine pc(hfv); 02799 pc.checkParsed(); 02800 Data buffer; 02801 oDataStream str(buffer); 02802 now=Timer::getTimeMicroSec(); 02803 for(int i=0; i<10000000; ++i) 02804 { 02805 pc.encode(str); 02806 str.flush(); 02807 str.reset(); 02808 } 02809 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02810 } 02811 02812 02813 // StatusLine 02814 { 02815 resip::Data test("StatusLine creation/deletion"); 02816 cout << endl << test << endl; 02817 HeaderFieldValue hfv(test.data(), test.size()); 02818 UInt64 now(Timer::getTimeMicroSec()); 02819 for(int i=0; i<10000000; ++i) 02820 { 02821 StatusLine pc(hfv); 02822 } 02823 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02824 } 02825 02826 { 02827 resip::Data test("SIP/2.0 200 OK"); 02828 cout << endl << test << endl; 02829 HeaderFieldValue hfv(test.data(), test.size()); 02830 UInt64 now(Timer::getTimeMicroSec()); 02831 for(int i=0; i<10000000; ++i) 02832 { 02833 StatusLine pc(hfv); 02834 pc.checkParsed(); 02835 } 02836 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02837 cout << "encodes:" << endl; 02838 StatusLine pc(hfv); 02839 pc.checkParsed(); 02840 Data buffer; 02841 oDataStream str(buffer); 02842 now=Timer::getTimeMicroSec(); 02843 for(int i=0; i<10000000; ++i) 02844 { 02845 pc.encode(str); 02846 str.flush(); 02847 str.reset(); 02848 } 02849 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02850 } 02851 02852 { 02853 resip::Data test("SIP/2.0 200 OKokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokokok"); 02854 cout << endl << test << endl; 02855 HeaderFieldValue hfv(test.data(), test.size()); 02856 UInt64 now(Timer::getTimeMicroSec()); 02857 for(int i=0; i<10000000; ++i) 02858 { 02859 StatusLine pc(hfv); 02860 pc.checkParsed(); 02861 } 02862 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02863 cout << "encodes:" << endl; 02864 StatusLine pc(hfv); 02865 pc.checkParsed(); 02866 Data buffer; 02867 oDataStream str(buffer); 02868 now=Timer::getTimeMicroSec(); 02869 for(int i=0; i<10000000; ++i) 02870 { 02871 pc.encode(str); 02872 str.flush(); 02873 str.reset(); 02874 } 02875 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02876 } 02877 02878 { 02879 resip::Data test("NOTSIP/2.0 200 OK"); 02880 cout << endl << test << endl; 02881 HeaderFieldValue hfv(test.data(), test.size()); 02882 UInt64 now(Timer::getTimeMicroSec()); 02883 for(int i=0; i<10000000; ++i) 02884 { 02885 StatusLine pc(hfv); 02886 pc.checkParsed(); 02887 } 02888 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02889 cout << "encodes:" << endl; 02890 StatusLine pc(hfv); 02891 pc.checkParsed(); 02892 Data buffer; 02893 oDataStream str(buffer); 02894 now=Timer::getTimeMicroSec(); 02895 for(int i=0; i<10000000; ++i) 02896 { 02897 pc.encode(str); 02898 str.flush(); 02899 str.reset(); 02900 } 02901 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02902 } 02903 02904 02905 // Via 02906 { 02907 resip::Data test("Via creation/deletion"); 02908 cout << endl << test << endl; 02909 HeaderFieldValue hfv(test.data(), test.size()); 02910 UInt64 now(Timer::getTimeMicroSec()); 02911 for(int i=0; i<10000000; ++i) 02912 { 02913 Via pc(hfv, Headers::UNKNOWN); 02914 } 02915 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02916 } 02917 02918 { 02919 resip::Data test("SIP/2.0/TCP 127.0.0.1:5060;branch=z9hG4bK-524287-1---307cd5596615cb2e;rport"); 02920 cout << endl << test << endl; 02921 HeaderFieldValue hfv(test.data(), test.size()); 02922 UInt64 now(Timer::getTimeMicroSec()); 02923 for(int i=0; i<10000000; ++i) 02924 { 02925 Via pc(hfv, Headers::UNKNOWN); 02926 pc.checkParsed(); 02927 } 02928 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02929 cout << "encodes:" << endl; 02930 Via pc(hfv, Headers::UNKNOWN); 02931 pc.checkParsed(); 02932 Data buffer; 02933 oDataStream str(buffer); 02934 now=Timer::getTimeMicroSec(); 02935 for(int i=0; i<10000000; ++i) 02936 { 02937 pc.encode(str); 02938 str.flush(); 02939 str.reset(); 02940 } 02941 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02942 } 02943 02944 02945 { 02946 resip::Data test(""); 02947 cout << endl << test << endl; 02948 HeaderFieldValue hfv(test.data(), test.size()); 02949 UInt64 now(Timer::getTimeMicroSec()); 02950 for(int i=0; i<10000000; ++i) 02951 { 02952 Token pc(hfv, Headers::UNKNOWN); 02953 } 02954 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02955 } 02956 02957 { 02958 resip::Data test(""); 02959 cout << endl << test << endl; 02960 HeaderFieldValue hfv(test.data(), test.size()); 02961 UInt64 now(Timer::getTimeMicroSec()); 02962 for(int i=0; i<10000000; ++i) 02963 { 02964 Token pc(hfv, Headers::UNKNOWN); 02965 pc.checkParsed(); 02966 } 02967 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02968 cout << "encodes:" << endl; 02969 Token pc(hfv, Headers::UNKNOWN); 02970 pc.checkParsed(); 02971 Data buffer; 02972 oDataStream str(buffer); 02973 now=Timer::getTimeMicroSec(); 02974 for(int i=0; i<10000000; ++i) 02975 { 02976 pc.encode(str); 02977 str.flush(); 02978 str.reset(); 02979 } 02980 cout << Timer::getTimeMicroSec() - now << " microseconds" << endl; 02981 } 02982 02983 resipCerr << "\nTEST OK" << endl; 02984 02985 return 0; 02986 } 02987 02988 /* ==================================================================== 02989 * The Vovida Software License, Version 1.0 02990 * 02991 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 02992 * 02993 * Redistribution and use in source and binary forms, with or without 02994 * modification, are permitted provided that the following conditions 02995 * are met: 02996 * 02997 * 1. Redistributions of source code must retain the above copyright 02998 * notice, this list of conditions and the following disclaimer. 02999 * 03000 * 2. Redistributions in binary form must reproduce the above copyright 03001 * notice, this list of conditions and the following disclaimer in 03002 * the documentation and/or other materials provided with the 03003 * distribution. 03004 * 03005 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 03006 * and "Vovida Open Communication Application Library (VOCAL)" must 03007 * not be used to endorse or promote products derived from this 03008 * software without prior written permission. For written 03009 * permission, please contact vocal@vovida.org. 03010 * 03011 * 4. Products derived from this software may not be called "VOCAL", nor 03012 * may "VOCAL" appear in their name, without prior written 03013 * permission of Vovida Networks, Inc. 03014 * 03015 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 03016 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 03017 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 03018 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 03019 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 03020 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 03021 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 03022 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 03023 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 03024 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 03025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 03026 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 03027 * DAMAGE. 03028 * 03029 * ==================================================================== 03030 * 03031 * This software consists of voluntary contributions made by Vovida 03032 * Networks, Inc. and many individuals on behalf of Vovida Networks, 03033 * Inc. For more information on Vovida Networks, Inc., please see 03034 * <http://www.vovida.org/>. 03035 * 03036 */ 03037 03038 /* Local Variables: */ 03039 /* c-file-style: "ellemtel" */ 03040 /* End: */
1.7.5.1