/[resiprocate]/main/sip/resiprocate/test/testParserCategories.cxx
ViewVC logotype

Contents of /main/sip/resiprocate/test/testParserCategories.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4601 - (show annotations) (download)
Thu May 12 01:10:49 2005 UTC (14 years, 6 months ago) by derek
File size: 53832 byte(s)
merged identity branch(4598) into main--removing identity branch after this
1 #include <assert.h>
2 #include <iostream>
3 #include <sstream>
4 #include <string.h>
5 #include <string>
6 #include "resiprocate/HeaderFieldValue.hxx"
7 #include "resiprocate/HeaderTypes.hxx"
8 #include "resiprocate/Headers.hxx"
9 #include "resiprocate/ParserCategories.hxx"
10 #include "resiprocate/ExtensionHeader.hxx"
11 #include "resiprocate/UnknownParameterType.hxx"
12 #include "resiprocate/Uri.hxx"
13 #include "resiprocate/os/DataStream.hxx"
14 #include "resiprocate/os/ParseBuffer.hxx"
15 #include "resiprocate/os/Logger.hxx"
16
17 using namespace std;
18 using namespace resip;
19
20 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
21
22 class TR
23 {
24 private:
25 ostream& os;
26 Data label;
27
28 TR(const TR&);
29
30 void show(const char * s)
31 {
32 os << s << ' ' << label << endl;
33 }
34
35 void start()
36 {
37 show("-->");
38 }
39
40 void end()
41 {
42 show("<--");
43 }
44
45 public:
46 TR(Data s,ostream& o = cerr ):os(o),label(s) { start(); }
47 TR(const char* l,ostream& o = cerr):os(o),label(l) { start(); }
48 ~TR() { end();}
49 };
50
51 int
52 main(int arc, char** argv)
53 {
54 Log::initialize(Log::Cout, Log::Debug, argv[0]);
55
56 {
57 TR _tr("Test poorly formed NameAddr by construction");
58
59 try
60 {
61 NameAddr test("<jason_AT_example.com@10.0.0.1;transport=TCP>");
62 assert(false);
63 }
64 catch (ParseBuffer::Exception& e)
65 {
66 cerr << e << endl;
67 }
68 }
69
70 {
71 TR _tr("Test copy transport param");
72
73 NameAddr test("<sip:jason_AT_example.com@10.0.0.1:5060;transport=TCP>");
74 cerr << test << endl;
75 NameAddr copy = test;
76 cerr << copy << endl;
77 assert(test.uri().exists(p_transport));
78 assert(copy.uri().exists(p_transport));
79
80 assert(test.uri().param(p_transport) == copy.uri().param(p_transport));
81 }
82
83 {
84 TR _tr("Test iterator erase in ParserContainer");
85
86 NameAddrs nameAddrs;
87
88 nameAddrs.push_back(NameAddr(Uri("sip:first@first.com")));
89 nameAddrs.push_back(NameAddr(Uri("sip:second@second.com")));
90 nameAddrs.push_back(NameAddr(Uri("sip:third@third.com")));
91 nameAddrs.push_back(NameAddr(Uri("sip:fourth@fourth.com")));
92
93 assert(nameAddrs.size() == 4);
94
95 NameAddrs::iterator i = nameAddrs.begin();
96 ++i;
97
98 nameAddrs.erase(i);
99
100 assert(nameAddrs.size() == 3);
101
102 nameAddrs.erase(nameAddrs.begin());
103 assert(nameAddrs.size() == 2);
104
105 assert(nameAddrs.begin()->uri().user() == "third");
106 }
107
108 {
109 TR _tr("Test find in ParserContainer");
110
111 Tokens tokens;
112
113 tokens.push_back(Token("Foo"));
114 tokens.push_back(Token("Bar"));
115 tokens.push_back(Token("Baz"));
116 tokens.push_back(Token("Quux"));
117
118 assert(tokens.find(Token("Foo")));
119 assert(tokens.find(Token("Bar")));
120 assert(tokens.find(Token("Baz")));
121 assert(tokens.find(Token("Quux")));
122
123 assert(!tokens.find(Token("Zab")));
124 }
125
126 {
127 TR _tr("Test remove parameters that appear multiple times");
128 Uri uri1("sip:a@b;xtype=1;maddr=local;xtype=2;maddr=remote;xtype=3;maddr=other");
129 Uri uri2(uri1);
130
131 uri1.remove(p_maddr);
132 Data res1;
133 {
134 DataStream str(res1);
135 str << uri1;
136 }
137 assert(res1 == "sip:a@b;xtype=1;xtype=2;xtype=3");
138
139 UnknownParameterType p_xtype("xtype");
140 uri2.remove(p_xtype);
141 Data res2;
142 {
143 DataStream str(res2);
144 str << uri2;
145 }
146 assert(res2 == "sip:a@b;maddr=local;maddr=remote;maddr=other");
147 }
148
149 {
150 TR _tr("Test remove parameters that appear multiple times; mixed predefined and extensions");
151 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");
152 Uri uri2(uri1);
153
154 uri1.remove(p_maddr);
155 Data res1;
156 {
157 DataStream str(res1);
158 str << uri1;
159 }
160 assert(res1 == "sip:a@b;ttl=17;ttl=42;ttl=111;xtype=1;foo=bar;xtype=2;foo=baz;xtype=3;foo=foo");
161
162 UnknownParameterType p_xtype("xtype");
163 uri2.remove(p_xtype);
164 Data res2;
165 {
166 DataStream str(res2);
167 str << uri2;
168 }
169 assert(res2 == "sip:a@b;maddr=local;ttl=17;maddr=remote;ttl=42;maddr=other;ttl=111;foo=bar;foo=baz;foo=foo");
170 }
171
172 {
173 TR _tr("Test exists unknown parameter");
174
175 Uri uri1("sip:a@b;xaudio");
176 assert(uri1.exists(UnknownParameterType("xaudio")));
177 assert(uri1.param(UnknownParameterType("xaudio")) == Data::Empty);
178
179 Uri uri2("sip:a@b;a=b;xaudio");
180 cerr << uri2.param(UnknownParameterType("a")) << endl;
181
182 assert(uri2.exists(UnknownParameterType("xaudio")));
183 assert(uri2.param(UnknownParameterType("xaudio")) == Data::Empty);
184
185 Uri uri3("sip:a@b;xaudio;a=b");
186 assert(uri3.exists(UnknownParameterType("xaudio")));
187 assert(uri3.param(UnknownParameterType("xaudio")) == Data::Empty);
188 }
189
190 {
191 TR _tr("Test non-quoted tokens displayname in NameAddr (torture test: 2.39)");
192 Data data("A. Bell <sip:a.g.bell@bell-tel.com>;tag=459843");
193
194 NameAddr legal(data);
195
196 assert(legal.uri().host() == "bell-tel.com");
197
198 cerr << "!!" << legal << endl;
199
200 assert(legal.displayName() == "A. Bell ");
201 }
202
203 {
204 TR _tr("Test quoted displayname in NameAddr (torture test: 2.39)");
205 Data data("\"A. Bell\" <sip:a.g.bell@bell-tel.com>;tag=459843");
206
207 NameAddr legal(data);
208
209 assert(legal.uri().host() == "bell-tel.com");
210
211 cerr << "!!" << legal.displayName() << endl;
212
213 assert(legal.displayName() == "A. Bell");
214 }
215
216 {
217 TR _tr("Test NameAddr parameter handling");
218 Data data("sip:foo@bar.com;user=phone");
219
220 NameAddr original(data);
221 assert(original.uri().exists(p_user));
222
223 cerr << "!!" << original << endl;
224 }
225
226 {
227 TR _tr("Test tel aor canonicalization");
228 Data data("tel:+14156268178;pOstd=pP2;isUb=1411");
229
230 Uri original(data);
231 cerr << original.getAor() << endl;
232
233 assert(original.getAor() == "+14156268178");
234 }
235
236 {
237 TR _tr("Test aor canonicalization");
238 Data data("sip:User@kElOwNa.GlOo.NeT:5666");
239 Data data1("sip:User@KeLoWnA.gLoO.nEt:5666");
240
241 Uri original(data);
242 Uri original1(data1);
243
244 cerr << "!! " << original.getAor() << " " << original1.getAor() << endl;
245 assert(original.getAor() == original1.getAor());
246 }
247
248 {
249 TR _tr("Test tel NameAddr");
250 NameAddr n1("<tel:98267168>");
251 cerr << n1.uri().user() << endl;
252 }
253
254 {
255 TR _tr("Test empty NameAddr");
256 NameAddr n1;
257 NameAddr n2;
258 assert (!(n1 < n2));
259 assert (!(n2 < n1));
260 assert (n1.uri().getAor() == n2.uri().getAor());
261 }
262
263 {
264 TR _tr("Test NameAddr q value");
265
266 NameAddr w("<sip:wombat@192.168.2.221:5062;transport=Udp>;expires=63;q=1");
267 assert(w.param(p_q) == 1.0);
268 }
269
270 {
271 TR _tr("Test NameAddr comparison");
272
273 NameAddr w1("<sip:wombat@192.168.2.221:5062;transport=Udp>;expires=63");
274 NameAddr w2("<sip:wombat@192.168.2.221:5063;transport=Udp>;expires=66");
275 assert(w1 < w2);
276 assert (!(w2 < w1));
277 }
278
279 {
280 TR _tr("Test parameter with spaces");
281 Data txt("Digest username=\"Alice\", realm = \"atlanta.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", reponse=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n");
282 HeaderFieldValue hfv(txt.data(), txt.size());
283 Auth auth(&hfv, Headers::Authorization);
284
285 assert(auth.scheme() == "Digest");
286 assert(auth.exists(p_realm));
287 }
288
289 {
290 TR _tr("Test uri with no user");
291 Data data("sip:kelowna.gloo.net");
292
293 Uri original(data);
294 cerr << original << endl;
295
296 assert(Data::from(original) == data);
297 }
298
299 {
300 TR _tr("Test assignment for NameAddr");
301 NameAddr original(Data("\"Original\"<sip:orig@example.com>;tag=original"));
302 (void)original.exists(p_tag);
303 // force parse
304 NameAddr newna(Data("\"new\"<sip:new@example.com>;tag=new"));
305 (void)newna.exists(p_tag);
306 cout << "original NameAddr: ->" << original << "<-"<< endl;
307 cout << "new NameAddr : ->" << newna << "<-" << endl;
308 original = newna;
309 cout << "original : ->" << original << "<-"<< endl;
310 assert(Data::from(original) == Data::from(newna));
311 }
312 {
313 TR _tr("Test typeless parameter copy");
314 Token s = Token("jason");
315 s.value() = "value";
316 s.param(p_expires) = 17;
317 s.param(p_lr);
318 s.param(UnknownParameterType("foobie")) = "quux";
319
320 Token s1;
321 s1.value() = "other";
322 s1.param(p_ttl) = 21;
323
324 s.setParameter(s1.getParameterByEnum(ParameterTypes::ttl));
325 assert(s.value() == "value");
326 assert(s.param(p_ttl) == 21);
327 assert(s.param(p_lr));
328 assert(s.param(UnknownParameterType("foobie")) == "quux");
329 }
330
331 {
332 TR a("Test typeless parameter overwrite" );
333 Token s;
334 s.value() = "value";
335 s.param(p_expires) = 17;
336 s.param(p_ttl) = 12;
337 s.param(p_lr);
338 s.param(UnknownParameterType("foobie")) = "quux";
339
340 Token s1;
341 s1.value() = "other";
342 s1.param(p_ttl) = 21;
343
344 s.setParameter(s1.getParameterByEnum(ParameterTypes::ttl));
345 assert(s.value() == "value");
346 assert(s.param(p_ttl) == 21);
347 assert(s.param(p_lr));
348 assert(s.param(UnknownParameterType("foobie")) == "quux");
349
350 s.encode(cerr);
351 cerr << endl;
352 }
353
354 {
355 TR _tr( "Test StringCategory");
356 Data stringString("Lame Agent");
357 HeaderFieldValue hfv(stringString.data(), stringString.size());
358
359 StringCategory str(&hfv, Headers::UNKNOWN);
360 assert(str.value() == stringString);
361
362 Data buff;
363 {
364 DataStream s(buff);
365 str.encode(s);
366 }
367 cerr << buff << endl;
368 assert(buff == stringString);
369
370 StringCategory copy(str);
371 assert(copy.value() == stringString);
372
373 str.value() = "foo";
374 assert(str.value() == "foo");
375 }
376
377 {
378 TR _tr( "Test Token parameters");
379 Token state;
380 state.value() = Data("active");
381 state.param(p_expires) = 666;
382 cerr << state << endl;
383 }
384
385 {
386 TR _tr( "StatusLine, with reason code");
387 Data statusLineString("SIP/2.0 180 Ringing");
388 HeaderFieldValue hfv(statusLineString.data(), statusLineString.size());
389
390 StatusLine statusLine(&hfv, Headers::UNKNOWN);
391 assert(statusLine.responseCode() == 180);
392 cerr << statusLine.reason() << endl;
393 assert(statusLine.reason() == "Ringing");
394 assert(statusLine.getSipVersion() == "SIP/2.0");
395
396 StatusLine copy(statusLine);
397 assert(copy.responseCode() == 180);
398 assert(copy.reason() == "Ringing");
399 assert(copy.getSipVersion() == "SIP/2.0");
400 }
401 {
402 Uri foo;
403 // valgrind complains, but the problem moves when closely observed
404 assert(foo.getAor().empty());
405 }
406
407 #define checkHeaderName(_name) cerr << Headers::_name << " " << Headers::getHeaderName(Headers::_name) << " = " << #_name << endl /*;assert(isEqualNoCase(Headers::getHeaderName(Headers::_name), #_name))*/
408 {
409 // test header hash
410 for (int i = Headers::CSeq; i < Headers::MAX_HEADERS; i++)
411 {
412 Data hdr = Headers::getHeaderName(i);
413 if (!hdr.size()) continue;
414 Data msg("Checking hash of: ");
415 msg += hdr;
416 TR _tr(msg);
417 assert(Headers::getType(Headers::getHeaderName(i).c_str(), Headers::getHeaderName(i).size()) == i);
418 }
419 checkHeaderName(To);
420 checkHeaderName(From);
421 checkHeaderName(Via);
422 checkHeaderName(CallID);
423 checkHeaderName(CSeq);
424 checkHeaderName(Route);
425 checkHeaderName(RecordRoute);
426 checkHeaderName(Contact);
427 checkHeaderName(Subject);
428 checkHeaderName(Expires);
429 checkHeaderName(MaxForwards);
430 checkHeaderName(Accept);
431 checkHeaderName(AcceptEncoding);
432 checkHeaderName(AcceptLanguage);
433 checkHeaderName(AlertInfo);
434 checkHeaderName(Allow);
435 checkHeaderName(AuthenticationInfo);
436 checkHeaderName(CallInfo);
437 checkHeaderName(ContentDisposition);
438 checkHeaderName(ContentEncoding);
439 checkHeaderName(ContentLanguage);
440 checkHeaderName(ContentTransferEncoding);
441 checkHeaderName(ContentType);
442 checkHeaderName(Date);
443 checkHeaderName(InReplyTo);
444 checkHeaderName(MinExpires);
445 checkHeaderName(MIMEVersion);
446 checkHeaderName(Organization);
447 checkHeaderName(Priority);
448 checkHeaderName(ProxyAuthenticate);
449 checkHeaderName(ProxyAuthorization);
450 checkHeaderName(ProxyRequire);
451 checkHeaderName(ReplyTo);
452 checkHeaderName(Require);
453 checkHeaderName(RetryAfter);
454 checkHeaderName(Server);
455 checkHeaderName(SIPETag);
456 checkHeaderName(SIPIfMatch);
457 checkHeaderName(Supported);
458 checkHeaderName(Timestamp);
459 checkHeaderName(Unsupported);
460 checkHeaderName(UserAgent);
461 checkHeaderName(Warning);
462 checkHeaderName(WWWAuthenticate);
463 checkHeaderName(SubscriptionState);
464 checkHeaderName(ReferTo);
465 checkHeaderName(ReferredBy);
466 checkHeaderName(Authorization);
467 checkHeaderName(Replaces);
468 checkHeaderName(Event);
469 checkHeaderName(AllowEvents);
470 checkHeaderName(SecurityClient);
471 checkHeaderName(SecurityServer);
472 checkHeaderName(SecurityVerify);
473 checkHeaderName(ContentLength);
474 checkHeaderName(ContentId);
475
476 }
477
478 #define checkParameterName(_name) cerr << ParameterTypes::_name << " " << ParameterTypes::ParameterNames[ParameterTypes::_name] << " = " << #_name << endl/*;assert(isEqualNoCase(ParameterTypes::ParameterNames[ParameterTypes::_name], #_name))*/
479 {
480 checkParameterName(data);
481 checkParameterName(control);
482 checkParameterName(mobility);
483 checkParameterName(description);
484 checkParameterName(events);
485 checkParameterName(priority);
486 checkParameterName(methods);
487 checkParameterName(schemes);
488 checkParameterName(application);
489 checkParameterName(video);
490 checkParameterName(language);
491 checkParameterName(type);
492 checkParameterName(isFocus);
493 checkParameterName(actor);
494 checkParameterName(text);
495 checkParameterName(extensions);
496 checkParameterName(Instance);
497 checkParameterName(gruu);
498
499 checkParameterName(transport);
500 checkParameterName(user);
501 checkParameterName(method);
502 checkParameterName(ttl);
503 checkParameterName(maddr);
504 checkParameterName(lr);
505 checkParameterName(q);
506 checkParameterName(purpose);
507 checkParameterName(expires);
508 checkParameterName(handling);
509 checkParameterName(tag);
510 checkParameterName(toTag);
511 checkParameterName(fromTag);
512 checkParameterName(duration);
513 checkParameterName(branch);
514 checkParameterName(received);
515 checkParameterName(comp);
516 checkParameterName(rport);
517 checkParameterName(algorithm);
518 checkParameterName(cnonce);
519 checkParameterName(domain);
520 checkParameterName(id);
521 checkParameterName(nonce);
522 checkParameterName(nc);
523 checkParameterName(opaque);
524 checkParameterName(realm);
525 checkParameterName(response);
526 checkParameterName(stale);
527 checkParameterName(username);
528 checkParameterName(qop);
529 checkParameterName(uri);
530 checkParameterName(retryAfter);
531 checkParameterName(reason);
532 checkParameterName(dAlg);
533 checkParameterName(dQop);
534 checkParameterName(dVer);
535 checkParameterName(smimeType);
536 checkParameterName(name);
537 checkParameterName(filename);
538 checkParameterName(protocol);
539 checkParameterName(micalg);
540 checkParameterName(boundary);
541 checkParameterName(expiration);
542 checkParameterName(size);
543 checkParameterName(permission);
544 checkParameterName(site);
545 checkParameterName(directory);
546 checkParameterName(mode);
547 checkParameterName(server);
548 checkParameterName(charset);
549 checkParameterName(accessType);
550 checkParameterName(profileType);
551 checkParameterName(vendor);
552 checkParameterName(model);
553 checkParameterName(version);
554 checkParameterName(effectiveBy);
555 checkParameterName(document);
556 checkParameterName(appId);
557 checkParameterName(networkUser);
558
559 checkParameterName(url);
560
561
562
563 // test parameter hash
564 for (int i = 0; i < ParameterTypes::MAX_PARAMETER; i++)
565 {
566 if (i != ParameterTypes::qopOptions &&
567 i != ParameterTypes::qop &&
568 i != ParameterTypes::qopFactory)
569 {
570
571 TR _tr( Data("Checking hash of: ") + Data(ParameterTypes::ParameterNames[i]));
572 assert(ParameterTypes::getType(ParameterTypes::ParameterNames[i].c_str(),
573 ParameterTypes::ParameterNames[i].size()) == i);
574 }
575 }
576
577 assert(ParameterTypes::ParameterNames[ParameterTypes::qop] == "qop");
578 assert(ParameterTypes::ParameterNames[ParameterTypes::qopOptions] == "qop");
579 assert(ParameterTypes::getType("qop", 3) == ParameterTypes::qopFactory);
580 }
581
582 {
583 TR _tr( "simple Token parse test");
584 char *org = "WuggaWuggaFoo";
585
586 HeaderFieldValue hfv(org, strlen(org));
587 Token tok(&hfv, Headers::UNKNOWN);
588 assert(tok.value() == org);
589 }
590
591 {
592 TR _tr( "Token + parameters parse test");
593 char *org = "WuggaWuggaFoo;ttl=2";
594
595 HeaderFieldValue hfv(org, strlen(org));
596 Token tok(&hfv, Headers::UNKNOWN);
597 assert(tok.value() == "WuggaWuggaFoo");
598 assert(tok.param(p_ttl) == 2);
599 }
600
601 {
602 TR _tr( "Test NameAddr(Data) constructor");
603
604 Data nad("bob<sips:bob@foo.com>;tag=wd834f");
605 NameAddr na(nad);
606 assert(na.uri().user() == "bob");
607 }
608
609 {
610 TR _tr( "full on via parse");
611 char *viaString = /* Via: */ " SIP/2.0/UDP a.b.c.com:5000;ttl=3;maddr=1.2.3.4;received=foo.com";
612
613 HeaderFieldValue hfv(viaString, strlen(viaString));
614 Via via(&hfv, Headers::UNKNOWN);
615 assert(via.sentPort() == 5000);
616 assert(via.sentHost() == "a.b.c.com");
617 assert(via.param(p_maddr) == "1.2.3.4");
618 }
619
620 #ifdef USE_IPV6
621 {
622 TR _tr( "full on via parse, IPV6");
623 // !dlb! deal with maddr=[5f1b:df00:ce3e:e200:20:800:2b37:6426]
624 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";
625
626 HeaderFieldValue hfv(viaString, strlen(viaString));
627 Via via(&hfv, Headers::UNKNOWN);
628 assert(via.sentPort() == 5000);
629 assert(via.sentHost() == "5f1b:df00:ce3e:e200:20:800:2b37:6426");
630 assert(via.param(p_maddr) == "1.2.3.4");
631 }
632 #endif
633 {
634 TR _tr( "URI parse");
635 Data uriString = "sip:bob@foo.com";
636 ParseBuffer pb(uriString.data(), uriString.size());
637 NameAddr to;
638 to.parse(pb);
639 Uri& uri = to.uri();
640 cerr << "!! " << to << endl;
641 assert(uri.scheme() == "sip");
642 assert(uri.user() == "bob");
643 assert(uri.host() == "foo.com");
644 assert(uri.port() == 0);
645 }
646
647 {
648 TR _tr( "URI parse, no displayName");
649 Data uriString = "sips:foo.com";
650 ParseBuffer pb(uriString.data(), uriString.size());
651 NameAddr to;
652 to.parse(pb);
653 Uri& uri = to.uri();
654 assert(uri.scheme() == "sips");
655 assert(uri.user() == "");
656 assert(uri.host() == "foo.com");
657 assert(uri.port() == 0);
658 }
659
660 {
661 TR _tr( "URI parse, parameters");
662 Data uriString = "sips:bob;param=gargle:password@foo.com";
663 ParseBuffer pb(uriString.data(), uriString.size());
664 NameAddr to;
665 to.parse(pb);
666 Uri& uri = to.uri();
667
668 assert(uri.scheme() == "sips");
669 assert(uri.user() == "bob;param=gargle");
670 assert(uri.password() == "password");
671 assert(uri.host() == "foo.com");
672 }
673
674 {
675 TR _tr( "URI parse, parameters, port");
676 Data uriString = "sips:bob;param=gargle:password@foo.com:6000";
677 ParseBuffer pb(uriString.data(), uriString.size());
678
679 NameAddr to;
680 to.parse(pb);
681 Uri& uri = to.uri();
682
683 assert(uri.scheme() == "sips");
684 assert(uri.user() == "bob;param=gargle");
685 assert(uri.password() == "password");
686 assert(uri.host() == "foo.com");
687 assert(uri.port() == 6000);
688 }
689
690 {
691 TR _tr( "URI parse, parameters, correct termination check");
692 Data uriString = "sips:bob;param=gargle:password@foo.com notHost";
693 ParseBuffer pb(uriString.data(), uriString.size());
694
695 NameAddr to;
696 to.parse(pb);
697 Uri& uri = to.uri();
698
699 assert(uri.scheme() == "sips");
700 assert(uri.user() == "bob;param=gargle");
701 assert(uri.password() == "password");
702 cerr << "Uri:" << uri.host() << endl;
703 assert(uri.host() == "foo.com");
704 }
705
706 {
707 TR _tr( "URI parse, transport parameter");
708 Data uriString = "sip:bob@biloxi.com;transport=udp";
709 ParseBuffer pb(uriString.data(), uriString.size());
710
711 NameAddr to;
712 to.parse(pb);
713 Uri& uri = to.uri();
714
715 assert(uri.param(p_transport) == "udp");
716 }
717
718 cerr << "URI comparison tests" << endl;
719 {
720 Data uriStringA("sip:carol@chicago.com");
721 Data uriStringB("sip:carol@chicago.com;newparam=5");
722 Data uriStringC("sip:carol@chicago.com;security=on");
723 ParseBuffer pa(uriStringA.data(), uriStringA.size());
724 ParseBuffer pb(uriStringB.data(), uriStringB.size());
725 ParseBuffer pc(uriStringC.data(), uriStringC.size());
726 NameAddr nA, nB, nC;
727
728 nA.parse(pa);
729 nB.parse(pb);
730 nC.parse(pc);
731
732 Uri& uA = nA.uri();
733 Uri& uB = nB.uri();
734 Uri& uC = nC.uri();
735
736 assert(uA == uB);
737 assert(uB == uC);
738 assert(uA == uC);
739 }
740 {
741 Data uriStringA = "sip:biloxi.com;transport=tcp;method=REGISTER";
742 Data uriStringB = "sip:biloxi.com;method=REGISTER;transport=tcp";
743
744 ParseBuffer pa(uriStringA.data(), uriStringA.size());
745 ParseBuffer pb(uriStringB.data(), uriStringB.size());
746
747 NameAddr nA, nB;
748 nA.parse(pa);
749 nB.parse(pb);
750
751 Uri& uA = nA.uri();
752 Uri& uB = nB.uri();
753
754 assert(uA == uB);
755 }
756 {
757 Data uriStringA = "sip:alice@atlanta.com";
758 Data uriStringB = "sip:alice@atlanta.com";
759
760 ParseBuffer pa(uriStringA.data(), uriStringA.size());
761 ParseBuffer pb(uriStringB.data(), uriStringB.size());
762
763 NameAddr nA, nB;
764 nA.parse(pa);
765 nB.parse(pb);
766 Uri& uA = nA.uri();
767 Uri& uB = nB.uri();
768
769 assert(uA == uB);
770 }
771 {
772 Data uriStringA = "sip:alice@AtLanTa.CoM;Transport=UDP";
773 Data uriStringB = "SIP:ALICE@AtLanTa.CoM;Transport=udp";
774
775 ParseBuffer pa(uriStringA.data(), uriStringA.size());
776 ParseBuffer pb(uriStringB.data(), uriStringB.size());
777
778 NameAddr nA, nB;
779 nA.parse(pa);
780 nB.parse(pb);
781 Uri& uA = nA.uri();
782 Uri& uB = nB.uri();
783
784 assert(uA != uB);
785 }
786 {
787 Data uriStringA = "sip:bob@192.0.2.4";
788 Data uriStringB = "sip:bob@phone21.boxesbybob.com";
789
790 ParseBuffer pa(uriStringA.data(), uriStringA.size());
791 ParseBuffer pb(uriStringB.data(), uriStringB.size());
792 NameAddr nA, nB;
793 nA.parse(pa);
794 nB.parse(pb);
795 Uri& uA = nA.uri();
796 Uri& uB = nB.uri();
797 assert(uA != uB);
798 }
799 {
800 Data uriStringA = "sip:bob@biloxi.com:6000;transport=tcp";
801 Data uriStringB = "sip:bob@biloxi.com";
802
803 ParseBuffer pa(uriStringA.data(), uriStringA.size());
804 ParseBuffer pb(uriStringB.data(), uriStringB.size());
805 NameAddr nA, nB;
806 nA.parse(pa);
807 nB.parse(pb);
808 Uri& uA = nA.uri();
809 Uri& uB = nB.uri();
810 assert(uA != uB);
811 }
812 {
813 Data uriStringA = "sip:bob@biloxi.com;transport=udp";
814 Data uriStringB = "sip:bob@biloxi.com";
815
816 ParseBuffer pa(uriStringA.data(), uriStringA.size());
817 ParseBuffer pb(uriStringB.data(), uriStringB.size());
818 NameAddr nA, nB;
819 nA.parse(pa);
820 nB.parse(pb);
821 Uri& uA = nA.uri();
822 Uri& uB = nB.uri();
823 cerr << "A: " << uA << endl;
824 cerr << "B: " << uB << endl;
825 cerr << "A:exists(transport) " << uA.exists(p_transport) << endl;
826 assert(uA != uB);
827 }
828
829 { //embedded header comparison, not supported yet
830 // char *uriStringA = "sip:carol@chicago.com?Subject=next%20meeting";
831 // char *uriStringB = "sip:carol@chicago.com";
832
833 // ParseBuffer pa(uriStringA, strlen(uriStringA));
834 // ParseBuffer pb(uriStringB, strlen(uriStringB));
835 // Uri uA, uB;
836 // uA.parse(uriStringA);
837 // uB.parse(uriStringB);
838 // assert(uA != uB);
839 }
840
841 {
842 TR _tr( "Request Line parse");
843 Data requestLineString("INVITE sips:bob@foo.com SIP/2.0");
844 HeaderFieldValue hfv(requestLineString.data(), requestLineString.size());
845
846 RequestLine requestLine(&hfv, Headers::UNKNOWN);
847 assert(requestLine.uri().scheme() == "sips");
848 assert(requestLine.uri().user() == "bob");
849 cerr << requestLine.uri().host() << endl;
850 assert(requestLine.uri().host() == "foo.com");
851 assert(requestLine.getMethod() == INVITE);
852 assert(requestLine.getSipVersion() == "SIP/2.0");
853 }
854 {
855 TR _tr( "Request Line parse tel");
856 Data requestLineString("INVITE tel:4153331212 SIP/2.0");
857 HeaderFieldValue hfv(requestLineString.data(), requestLineString.size());
858
859 RequestLine requestLine(&hfv, Headers::UNKNOWN);
860 assert(requestLine.uri().scheme() == "tel");
861 assert(requestLine.uri().user() == "4153331212");
862 assert(requestLine.getMethod() == INVITE);
863 assert(requestLine.getSipVersion() == "SIP/2.0");
864 }
865 {
866 TR _tr( "Request Line parse, parameters");
867 Data requestLineString("INVITE sips:bob@foo.com;maddr=1.2.3.4 SIP/2.0");
868 HeaderFieldValue hfv(requestLineString.data(), requestLineString.size());
869
870 RequestLine requestLine(&hfv, Headers::UNKNOWN);
871 assert(requestLine.uri().scheme() == "sips");
872 assert(requestLine.uri().user() == "bob");
873 cerr << requestLine.uri().host() << endl;
874 assert(requestLine.uri().host() == "foo.com");
875 assert(requestLine.getMethod() == INVITE);
876 assert(requestLine.uri().param(p_maddr) == "1.2.3.4");
877 cerr << requestLine.getSipVersion() << endl;
878 assert(requestLine.getSipVersion() == "SIP/2.0");
879 }
880 {
881 TR _tr( "NameAddr parse");
882 Data nameAddrString("sips:bob@foo.com");
883 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size());
884
885 NameAddr nameAddr(&hfv, Headers::UNKNOWN);
886 assert(nameAddr.uri().scheme() == "sips");
887 assert(nameAddr.uri().user() == "bob");
888 assert(nameAddr.uri().host() == "foo.com");
889 }
890 {
891 TR _tr( "NameAddr parse, displayName");
892 Data nameAddrString("Bob<sips:bob@foo.com>");
893 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size());
894
895 NameAddr nameAddr(&hfv, Headers::UNKNOWN);
896 assert(nameAddr.displayName() == "Bob");
897 assert(nameAddr.uri().scheme() == "sips");
898 assert(nameAddr.uri().user() == "bob");
899 assert(nameAddr.uri().host() == "foo.com");
900 }
901 {
902 TR _tr( "NameAddr parse, quoted displayname");
903 Data nameAddrString = "\"Bob\"<sips:bob@foo.com>";
904 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size());
905
906 NameAddr nameAddr(&hfv, Headers::UNKNOWN);
907 assert(nameAddr.displayName() == "Bob");
908 assert(nameAddr.uri().scheme() == "sips");
909 assert(nameAddr.uri().user() == "bob");
910 assert(nameAddr.uri().host() == "foo.com");
911 }
912 {
913 TR _tr( "NameAddr parse, quoted displayname, embedded quotes");
914 Data nameAddrString("\"Bob \\\" asd \"<sips:bob@foo.com>");
915 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size());
916
917 NameAddr nameAddr(&hfv, Headers::UNKNOWN);
918 assert(nameAddr.displayName() == "Bob \\\" asd ");
919 assert(nameAddr.uri().scheme() == "sips");
920 assert(nameAddr.uri().user() == "bob");
921 assert(nameAddr.uri().host() == "foo.com");
922 }
923 {
924 TR _tr( "NameAddr parse, unquoted displayname, paramterMove");
925 Data nameAddrString("Bob<sips:bob@foo.com>;tag=456248;mobility=\"hobble\"");
926 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size());
927
928 NameAddr nameAddr(&hfv, Headers::UNKNOWN);
929 assert(nameAddr.displayName() == "Bob");
930 assert(nameAddr.uri().scheme() == "sips");
931 assert(nameAddr.uri().user() == "bob");
932
933 assert(nameAddr.uri().host() == "foo.com");
934
935 cerr << "Uri params: ";
936 nameAddr.uri().encodeParameters(cerr) << endl;
937 cerr << "Header params: ";
938 nameAddr.encodeParameters(cerr) << endl;
939 assert(nameAddr.param(p_tag) == "456248");
940 assert(nameAddr.param(p_mobility) == "hobble");
941
942 assert(nameAddr.uri().exists(p_tag) == false);
943 assert(nameAddr.uri().exists(p_mobility) == false);
944 }
945 {
946 TR _tr( "NameAddr parse, quoted displayname, parameterMove");
947 Data nameAddrString("\"Bob\"<sips:bob@foo.com>;tag=456248;mobility=\"hobble\"");
948 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size());
949
950 NameAddr nameAddr(&hfv, Headers::UNKNOWN);
951 assert(nameAddr.displayName() == "Bob");
952 assert(nameAddr.uri().scheme() == "sips");
953 assert(nameAddr.uri().user() == "bob");
954
955 assert(nameAddr.uri().host() == "foo.com");
956
957 cerr << "Uri params: ";
958 nameAddr.uri().encodeParameters(cerr) << endl;
959 cerr << "Header params: ";
960 nameAddr.encodeParameters(cerr) << endl;
961
962 assert(nameAddr.param(p_tag) == "456248");
963 assert(nameAddr.param(p_mobility) == "hobble");
964
965 assert(nameAddr.uri().exists(p_tag) == false);
966 assert(nameAddr.uri().exists(p_mobility) == false);
967 }
968 {
969 TR _tr( "NameAddr parse, unquoted displayname, paramterMove");
970 Data nameAddrString("Bob<sips:bob@foo.com;tag=456248;mobility=\"hobble\">");
971 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size());
972
973 NameAddr nameAddr(&hfv, Headers::UNKNOWN);
974 assert(nameAddr.displayName() == "Bob");
975 assert(nameAddr.uri().scheme() == "sips");
976 assert(nameAddr.uri().user() == "bob");
977
978 assert(nameAddr.uri().host() == "foo.com");
979
980 cerr << "Uri params: ";
981 nameAddr.uri().encodeParameters(cerr) << endl;
982 cerr << "Header params: ";
983 nameAddr.encodeParameters(cerr) << endl;
984 assert(nameAddr.uri().param(p_tag) == "456248");
985 assert(nameAddr.uri().param(p_mobility) == "hobble");
986
987 assert(nameAddr.exists(p_tag) == false);
988 assert(nameAddr.exists(p_mobility) == false);
989 }
990 {
991 TR _tr( "NameAddr parse, unquoted displayname, paramterMove");
992 Data nameAddrString("Bob<sips:bob@foo.com;mobility=\"hobb;le\";tag=\"true;false\">");
993 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size());
994
995 NameAddr nameAddr(&hfv, Headers::UNKNOWN);
996 assert(nameAddr.displayName() == "Bob");
997 assert(nameAddr.uri().scheme() == "sips");
998 assert(nameAddr.uri().user() == "bob");
999
1000 assert(nameAddr.uri().host() == "foo.com");
1001
1002 cerr << "Uri params: ";
1003 nameAddr.uri().encodeParameters(cerr) << endl;
1004 cerr << "Header params: ";
1005 nameAddr.encodeParameters(cerr) << endl;
1006 assert(nameAddr.uri().param(p_mobility) == "hobb;le");
1007 assert(nameAddr.uri().param(p_tag) == "true;false");
1008 // assert("true;false" == nameAddr.uri().param(Data("useless")));
1009
1010 assert(nameAddr.exists(p_mobility) == false);
1011 }
1012 {
1013 TR _tr( "NameAddr parse");
1014 Data nameAddrString("sip:101@localhost:5080;transport=UDP");
1015 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size());
1016
1017 NameAddr nameAddr(&hfv, Headers::UNKNOWN);
1018 assert(nameAddr.displayName() == "");
1019 assert(nameAddr.uri().scheme() == "sip");
1020 assert(nameAddr.uri().user() == "101");
1021 }
1022 {
1023 TR _tr( "NameAddr parse, no user in uri");
1024 Data nameAddrString("sip:localhost:5070");
1025 HeaderFieldValue hfv(nameAddrString.data(), nameAddrString.size());
1026
1027 NameAddr nameAddr(&hfv, Headers::UNKNOWN);
1028 assert(nameAddr.displayName() == "");
1029 assert(nameAddr.uri().scheme() == "sip");
1030 assert(nameAddr.uri().host() == "localhost");
1031 assert(nameAddr.uri().user() == "");
1032 assert(nameAddr.uri().port() == 5070);
1033 }
1034 {
1035 TR _tr( "StatusLine, no reason code");
1036 Data statusLineString("SIP/2.0 100 ");
1037 HeaderFieldValue hfv(statusLineString.data(), statusLineString.size());
1038
1039 StatusLine statusLine(&hfv, Headers::UNKNOWN);
1040 assert(statusLine.responseCode() == 100);
1041 assert(statusLine.reason() == "");
1042 assert(statusLine.getSipVersion() == "SIP/2.0");
1043 }
1044 {
1045 TR _tr( "StatusLine, no reason code");
1046 Data statusLineString("SIP/2.0 100");
1047 HeaderFieldValue hfv(statusLineString.data(), statusLineString.size());
1048
1049 StatusLine statusLine(&hfv, Headers::UNKNOWN);
1050 assert(statusLine.responseCode() == 100);
1051 assert(statusLine.reason() == "");
1052 assert(statusLine.getSipVersion() == "SIP/2.0");
1053 }
1054 {
1055 TR _tr("Auth Schemes");
1056 char* authorizationString = "Digest realm=\"66.100.107.120\", username=\"1234\", nonce=\"1011235448\" , uri=\"sip:66.100.107.120\" , algorithm=MD5, response=\"8a5165b024fda362ed9c1e29a7af0ef2\"";
1057 HeaderFieldValue hfv(authorizationString, strlen(authorizationString));
1058
1059 Auth auth(&hfv, Headers::UNKNOWN);
1060
1061 cerr << "Auth scheme: " << auth.scheme() << endl;
1062 assert(auth.scheme() == "Digest");
1063 cerr << " realm: " << auth.param(p_realm) << endl;
1064 assert(auth.param(p_realm) == "66.100.107.120");
1065 assert(auth.param(p_username) == "1234");
1066 assert(auth.param(p_nonce) == "1011235448");
1067 assert(auth.param(p_uri) == "sip:66.100.107.120");
1068 assert(auth.param(p_algorithm) == "MD5");
1069 assert(auth.param(p_response) == "8a5165b024fda362ed9c1e29a7af0ef2");
1070
1071 stringstream s;
1072 auth.encode(s);
1073
1074 cerr << s.str() << endl;
1075
1076 assert(s.str() == "Digest realm=\"66.100.107.120\",username=\"1234\",nonce=\"1011235448\",uri=\"sip:66.100.107.120\",algorithm=MD5,response=\"8a5165b024fda362ed9c1e29a7af0ef2\"");
1077 }
1078
1079 {
1080 TR _tr("More Auth");
1081 char* authorizationString = "realm=\"66.100.107.120\", username=\"1234\", nonce=\"1011235448\" , uri=\"sip:66.100.107.120\" , algorithm=MD5, response=\"8a5165b024fda362ed9c1e29a7af0ef2\"";
1082 HeaderFieldValue hfv(authorizationString, strlen(authorizationString));
1083
1084 Auth auth(&hfv, Headers::UNKNOWN);
1085
1086 cerr << "Auth scheme: " << auth.scheme() << endl;
1087 assert(auth.scheme() == "");
1088 cerr << " realm: " << auth.param(p_realm) << endl;
1089 assert(auth.param(p_realm) == "66.100.107.120");
1090 assert(auth.param(p_username) == "1234");
1091 assert(auth.param(p_nonce) == "1011235448");
1092 assert(auth.param(p_uri) == "sip:66.100.107.120");
1093 assert(auth.param(p_algorithm) == "MD5");
1094 assert(auth.param(p_response) == "8a5165b024fda362ed9c1e29a7af0ef2");
1095
1096 stringstream s;
1097 auth.encode(s);
1098
1099 cerr << s.str() << endl;
1100
1101 assert(s.str() == "realm=\"66.100.107.120\",username=\"1234\",nonce=\"1011235448\",uri=\"sip:66.100.107.120\",algorithm=MD5,response=\"8a5165b024fda362ed9c1e29a7af0ef2\"");
1102 }
1103
1104 {
1105 TR _tr("More Auth Encoding");
1106
1107 Auth auth;
1108 Auth auth2;
1109 auth.scheme() = "Digest";
1110 auth.param(p_username) = "bob";
1111
1112 auth2 = auth;
1113 Auth auth3(auth2);
1114
1115 Data a;
1116 Data a1;
1117 Data a2;
1118 {
1119 DataStream s(a);
1120 s << auth;
1121 }
1122 {
1123 DataStream s(a1);
1124 s << auth;
1125 }
1126 {
1127 DataStream s(a2);
1128 s << auth;
1129 }
1130
1131 assert(a == a1);
1132 assert(a1 == a2);
1133 }
1134
1135 {
1136 TR _tr("Generic URI stuff");
1137
1138 char* genericString = "<http://www.google.com>;purpose=icon;fake=true";
1139 HeaderFieldValue hfv(genericString, strlen(genericString));
1140
1141 GenericUri generic(&hfv, Headers::UNKNOWN);
1142
1143 assert(generic.uri() == "http://www.google.com");
1144 cerr << generic.param(p_purpose) << endl;
1145 assert(generic.param(p_purpose) == "icon");
1146 assert(generic.param(UnknownParameterType("fake")) == "true");
1147
1148 stringstream s;
1149 generic.encode(s);
1150
1151 cerr << s.str() << endl;
1152
1153 assert(s.str() == "<http://www.google.com>;purpose=icon;fake=true");
1154 }
1155
1156 {
1157 TR _tr("Date testing 1");
1158 char *dateString = "Mon, 04 Nov 2002 17:34:15 GMT";
1159 HeaderFieldValue hfv(dateString, strlen(dateString));
1160
1161 DateCategory date(&hfv, Headers::UNKNOWN);
1162
1163 assert(date.dayOfWeek() == Mon);
1164 assert(date.dayOfMonth() == 04);
1165 assert(date.month() == Nov);
1166 assert(date.year() == 2002);
1167 assert(date.hour() == 17);
1168 assert(date.minute() == 34);
1169 assert(date.second() == 15);
1170
1171 stringstream s;
1172 date.encode(s);
1173
1174 cerr << s.str() << endl;
1175
1176 assert(s.str() == dateString);
1177
1178 // copy ctor not working in v1.94 ParserCategories.cxx
1179
1180 stringstream s2;
1181 DateCategory otherDate(date);
1182 otherDate.encode(s2);
1183 cerr << "!! original date : " << date << endl;
1184 cerr << "!! original string : " << dateString << endl;
1185 cerr << "!! otherDate : " << otherDate << endl;
1186 cerr << "!! encoded otherDate : " << s2.str() << endl;
1187 assert (s2.str() == dateString);
1188
1189 }
1190
1191 {
1192 TR _tr("Date testing 2");
1193 char *dateString = " Sun , 14 Jan 2222 07:04:05 GMT ";
1194 HeaderFieldValue hfv(dateString, strlen(dateString));
1195
1196 DateCategory date(&hfv, Headers::UNKNOWN);
1197
1198 assert(date.dayOfWeek() == Sun);
1199 assert(date.dayOfMonth() == 14);
1200 assert(date.month() == Jan);
1201 assert(date.year() == 2222);
1202 assert(date.hour() == 07);
1203 assert(date.minute() == 04);
1204 assert(date.second() == 05);
1205
1206 stringstream s;
1207 date.encode(s);
1208 assert(s.str() == "Sun, 14 Jan 2222 07:04:05 GMT");
1209 }
1210
1211
1212 {
1213 TR _tr("Mime types 1");
1214
1215 char* mimeString = "application/sdp";
1216 HeaderFieldValue hfv(mimeString, strlen(mimeString));
1217
1218 Mime mime(&hfv, Headers::UNKNOWN);
1219
1220 assert(mime.type() == "application");
1221 assert(mime.subType() == "sdp");
1222
1223 stringstream s;
1224 mime.encode(s);
1225 assert(s.str() == mimeString);
1226 }
1227
1228
1229 {
1230 TR _tr("Mime types 2");
1231 char* mimeString = "text/html ; charset=ISO-8859-4";
1232 HeaderFieldValue hfv(mimeString, strlen(mimeString));
1233
1234 Mime mime(&hfv, Headers::UNKNOWN);
1235
1236 assert(mime.type() == "text");
1237 assert(mime.subType() == "html");
1238 assert(mime.param(p_charset) == "ISO-8859-4");
1239
1240 stringstream s;
1241 mime.encode(s);
1242 assert(s.str() == "text/html;charset=ISO-8859-4");
1243 }
1244
1245 {
1246 TR _tr("Mime types 3");
1247
1248 char* mimeString = " text / html ; charset=ISO-8859-4";
1249 HeaderFieldValue hfv(mimeString, strlen(mimeString));
1250
1251 Mime mime(&hfv, Headers::UNKNOWN);
1252
1253 assert(mime.type() == "text");
1254 assert(mime.subType() == "html");
1255 assert(mime.param(p_charset) == "ISO-8859-4");
1256
1257 stringstream s;
1258 mime.encode(s);
1259 assert(s.str() == "text/html;charset=ISO-8859-4");
1260 }
1261
1262 {
1263 TR _tr("Via 1");
1264
1265 Via via;
1266 via.encode(cerr);
1267 cerr << endl;
1268
1269 assert (via.param(p_branch).hasMagicCookie());
1270 }
1271
1272 {
1273 TR _tr("Via 2");
1274
1275 char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj";
1276 HeaderFieldValue hfv(viaString, strlen(viaString));
1277 Via via(&hfv, Headers::UNKNOWN);
1278
1279 assert (via.param(p_branch).hasMagicCookie());
1280
1281 stringstream s0;
1282 via.encode(s0);
1283 cerr << s0.str() << endl;
1284 assert(s0.str() == "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj");
1285
1286 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj");
1287
1288 stringstream s1;
1289 via.encode(s1);
1290 assert(s1.str() == "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj");
1291
1292 via.param(p_branch).reset("jason");
1293 stringstream s2;
1294 via.encode(s2);
1295 cerr << "!! " << s2.str() << endl;
1296 assert(s2.str() == "SIP/2.0/UDP ;branch=z9hG4bK-d87543-jason-1--d87543-");
1297 assert(via.param(p_branch).getTransactionId() == "jason");
1298 }
1299
1300 {
1301 TR _tr("Via 3");
1302 char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj ;ttl=70";
1303 HeaderFieldValue hfv(viaString, strlen(viaString));
1304 Via via(&hfv, Headers::UNKNOWN);
1305
1306 assert (via.param(p_branch).hasMagicCookie());
1307 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj");
1308 assert (via.param(p_ttl) == 70);
1309 }
1310
1311 {
1312 TR _tr("Via 4");
1313 char* viaString = "SIP/2.0/UDP ;branch=oldassbranch";
1314 HeaderFieldValue hfv(viaString, strlen(viaString));
1315 Via via(&hfv, Headers::UNKNOWN);
1316
1317 assert (!via.param(p_branch).hasMagicCookie());
1318 assert (via.param(p_branch).getTransactionId() == "oldassbranch");
1319
1320 stringstream s;
1321 via.encode(s);
1322 assert(s.str() == "SIP/2.0/UDP ;branch=oldassbranch");
1323
1324 via.param(p_branch).reset("jason");
1325 stringstream s2;
1326 via.encode(s2);
1327 assert(s2.str() == "SIP/2.0/UDP ;branch=z9hG4bK-d87543-jason-1--d87543-");
1328 assert(via.param(p_branch).getTransactionId() == "jason");
1329 }
1330
1331 {
1332 TR _tr("Via 5 assignment with unknown parameter");
1333 char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj ;ttl=70;stid=abcd.2";
1334 HeaderFieldValue hfv(viaString, strlen(viaString));
1335 Via via(&hfv, Headers::UNKNOWN);
1336
1337 assert (via.param(p_branch).hasMagicCookie());
1338 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj");
1339 assert (via.param(p_ttl) == 70);
1340
1341 Via via1;
1342 via1 = via;
1343
1344 cerr << "!! "; via1.encode(cerr); cerr << endl;
1345 assert(via1.param(UnknownParameterType("stid")) == "abcd.2");
1346 }
1347
1348 {
1349 TR _tr("Via 6 parse with known parameter");
1350 char* viaString = "SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK-d87543-ec1e.0-1--d87543-;ttl=4\r\n";
1351 HeaderFieldValue hfv(viaString, strlen(viaString));
1352 Via via(&hfv, Headers::UNKNOWN);
1353
1354 assert (via.param(p_branch).hasMagicCookie());
1355 assert (via.param(p_branch).getTransactionId() == "ec1e.0");
1356 cerr << "!! "; via.encode(cerr); cerr << endl;
1357 assert(via.param(p_ttl) == 4);
1358 }
1359
1360 {
1361 TR _tr("Via 7 parse with unknown parameter");
1362 char* viaString = "SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK-d87543-ec1e.0-1--d87543-;stid=489573115\r\n";
1363 HeaderFieldValue hfv(viaString, strlen(viaString));
1364 Via via(&hfv, Headers::UNKNOWN);
1365
1366 assert (via.param(p_branch).hasMagicCookie());
1367 assert (via.param(p_branch).getTransactionId() == "ec1e.0");
1368 cerr << "!! "; via.encode(cerr); cerr << endl;
1369 assert(via.param(UnknownParameterType("stid")) == "489573115");
1370 }
1371
1372 {
1373 TR _tr("Branch parameter 1");
1374
1375 Data txt("=z9hG4bK-d87543-jason-1--d87543-");
1376 ParseBuffer pb(txt.data(), txt.size());
1377 BranchParameter bp(ParameterTypes::branch, pb, ";");
1378 assert(bp.hasMagicCookie());
1379 assert(bp.getTransactionId() == "jason");
1380
1381 bp.reset(bp.getTransactionId() + ".10");
1382 bp.encode(cerr); cerr << endl;
1383 assert(bp.getTransactionId() == "jason.10");
1384
1385 Data o;
1386 {
1387 DataStream s(o);
1388 bp.encode(s);
1389 }
1390 cerr << "!! " << o << endl;
1391 assert(o == "branch=z9hG4bK-d87543-jason.10-1--d87543-");
1392 }
1393
1394
1395 {
1396 TR _tr("Branch parameter 2");
1397 Data txt("=z9hG4bK-d87543-jason.1.2.3-14--d87543-");
1398 ParseBuffer pb(txt.data(), txt.size());
1399
1400 BranchParameter bpc(ParameterTypes::branch, pb, ";");
1401 assert(bpc.hasMagicCookie());
1402 assert(bpc.getTransactionId() == "jason.1.2.3");
1403
1404 Data o;
1405 {
1406 DataStream s(o);
1407 bpc.encode(s);
1408 }
1409 cerr << "!! " << o << endl;
1410 assert(o == "branch=z9hG4bK-d87543-jason.1.2.3-14--d87543-");
1411 }
1412
1413 {
1414 TR _tr("Branch parameter 3");
1415 Data txt("=z9hG4bK-d87543-3e565-ef7w-17.1.2.3-14--d87543-foobie");
1416 ParseBuffer pb(txt.data(), txt.size());
1417
1418 BranchParameter bpcc(ParameterTypes::branch, pb, ";");
1419 assert(bpcc.hasMagicCookie());
1420 assert(bpcc.getTransactionId() == "-d87543-3e565-ef7w-17.1.2.3-14--d87543-foobie");
1421
1422 Data o;
1423 {
1424 DataStream s(o);
1425 bpcc.encode(s);
1426 }
1427 cerr << "!! " << o << endl;
1428 assert(o == "branch=z9hG4bK-d87543-3e565-ef7w-17.1.2.3-14--d87543-foobie");
1429
1430 bpcc.reset("foobie");
1431
1432 o.clear();
1433 {
1434 DataStream s(o);
1435 bpcc.encode(s);
1436 }
1437 cerr << "!! " << o << endl;
1438 assert(o == "branch=z9hG4bK-d87543-foobie-1--d87543-");
1439 }
1440
1441 {
1442 TR _tr("Branch parameter 4");
1443 Data txt("=z9hG4bK-d87543-3e565-ef7w-17.1.2.3-14--d87543-");
1444 ParseBuffer pb(txt.data(), txt.size());
1445
1446 BranchParameter bpcc(ParameterTypes::branch, pb, ";");
1447 assert(bpcc.hasMagicCookie());
1448 assert(bpcc.getTransactionId() == "3e565-ef7w-17.1.2.3");
1449
1450 Data o;
1451 {
1452 DataStream s(o);
1453 bpcc.encode(s);
1454 }
1455 cerr << "!! " << o << endl;
1456 assert(o == "branch=z9hG4bK-d87543-3e565-ef7w-17.1.2.3-14--d87543-");
1457 }
1458
1459 {
1460 TR _tr("Branch parameter 5 externally spiralled branch returns");
1461 Data txt("=z9hG4bK-d87543--d87543-3e565-ef7w-17.1.2.3-14-d87543-foobie-1--d87543-");
1462 ParseBuffer pb(txt.data(), txt.size());
1463
1464 BranchParameter bpcc(ParameterTypes::branch, pb, ";");
1465 assert(bpcc.hasMagicCookie());
1466 assert(bpcc.getTransactionId() == "-d87543-3e565-ef7w-17.1.2.3-14-d87543-foobie");
1467
1468 Data o;
1469 {
1470 DataStream s(o);
1471 bpcc.encode(s);
1472 }
1473 cerr << "!! " << o << endl;
1474 assert(o == "branch=z9hG4bK-d87543--d87543-3e565-ef7w-17.1.2.3-14-d87543-foobie-1--d87543-");
1475 }
1476
1477 {
1478 TR _tr("Branch parameter 6 not one of ours");
1479 Data txt("=z9hG4bK-d87543-");
1480 ParseBuffer pb(txt.data(), txt.size());
1481
1482 BranchParameter bpcc(ParameterTypes::branch, pb, ";");
1483 assert(bpcc.hasMagicCookie());
1484 assert(bpcc.getTransactionId() == "-d87543-");
1485
1486 Data o;
1487 {
1488 DataStream s(o);
1489 bpcc.encode(s);
1490 }
1491 cerr << "!! " << o << endl;
1492 assert(o == "branch=z9hG4bK-d87543-");
1493 }
1494
1495 {
1496 TR _tr("Branch parameter 7 empty ours");
1497 Data txt("=z9hG4bK-d87543--1--d87543-");
1498 ParseBuffer pb(txt.data(), txt.size());
1499
1500 BranchParameter bpcc(ParameterTypes::branch, pb, ";");
1501 assert(bpcc.hasMagicCookie());
1502 assert(bpcc.getTransactionId() == "");
1503
1504 Data o;
1505 {
1506 DataStream s(o);
1507 bpcc.encode(s);
1508 }
1509 cerr << "!! " << o << endl;
1510 assert(o == "branch=z9hG4bK-d87543--1--d87543-");
1511 }
1512
1513 {
1514 TR _tr("Branch parameter 8 badly formed ours");
1515 Data txt("=z9hG4bK-d87543--------d87543-");
1516 ParseBuffer pb(txt.data(), txt.size());
1517
1518 try
1519 {
1520 BranchParameter bpcc(ParameterTypes::branch, pb, ";");
1521 assert(bpcc.hasMagicCookie());
1522 bpcc.getTransactionId();
1523 assert(false);
1524 }
1525 catch (ParseBuffer::Exception &e)
1526 {
1527 }
1528 }
1529
1530 {
1531 TR _tr("Branch parameter 9");
1532
1533 Data txt("=z9hG4bK-d87543-5b42cb698e8c6827790212ac5bdade1a-1-UEEzMjc2OA..-d87543-;rport;received=64.124.66.32");
1534 ParseBuffer pb(txt.data(), txt.size());
1535 BranchParameter bp(ParameterTypes::branch, pb, ";");
1536 assert(bp.hasMagicCookie());
1537 assert(bp.getTransactionId() == "5b42cb698e8c6827790212ac5bdade1a");
1538 cerr << "!! " << bp.clientData() << endl;
1539 assert(bp.clientData() == "PA32768");
1540
1541 bp.encode(cerr); cerr << endl;
1542 }
1543
1544 {
1545 TR _tr("Branch testing 1");
1546 char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj ;ttl=70";
1547 HeaderFieldValue hfv(viaString, strlen(viaString));
1548 Via via(&hfv, Headers::UNKNOWN);
1549
1550 assert (via.param(p_branch).hasMagicCookie());
1551 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj");
1552 assert (via.param(p_ttl) == 70);
1553 assert (!via.exists(p_rport));
1554
1555 via.param(p_rport);
1556 assert (via.exists(p_rport));
1557 assert (via.exists(p_rport));
1558 assert (!via.param(p_rport).hasValue());
1559 }
1560
1561 {
1562 TR _tr("Branch testing 2");
1563 char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj ;ttl=70;rport";
1564 HeaderFieldValue hfv(viaString, strlen(viaString));
1565 Via via(&hfv, Headers::UNKNOWN);
1566
1567 assert (via.param(p_branch).hasMagicCookie());
1568 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj");
1569 assert (via.param(p_ttl) == 70);
1570 assert (via.exists(p_rport));
1571 assert (!via.param(p_rport).hasValue());
1572 }
1573
1574 {
1575 TR _tr("Branch testing 3");
1576 char* viaString = "SIP/2.0/UDP ;branch=z9hG4bKwkl3lkjsdfjklsdjklfdsjlkdklj ;ttl=70;rport=100";
1577 HeaderFieldValue hfv(viaString, strlen(viaString));
1578 Via via(&hfv, Headers::UNKNOWN);
1579
1580 assert (via.param(p_branch).hasMagicCookie());
1581 assert (via.param(p_branch).getTransactionId() == "wkl3lkjsdfjklsdjklfdsjlkdklj");
1582 assert (via.param(p_ttl) == 70);
1583 assert (via.exists(p_rport));
1584 assert (via.param(p_rport).hasValue());
1585 assert (via.param(p_rport).port() == 100);
1586 }
1587
1588 {
1589 TR _tr("Branch testing 4 with clientData");
1590 Data txt("=z9hG4bK-d87543-T-i-D-314-Q2xpZW50RGF0YQ..-d87543-");
1591
1592 ParseBuffer pb(txt.data(), txt.size());
1593
1594 BranchParameter bpcc(ParameterTypes::branch, pb, ";");
1595 assert (bpcc.getTransactionId() == "T-i-D");
1596 assert (bpcc.clientData() == "ClientData");
1597
1598 Data o;
1599 {
1600 DataStream s(o);
1601 bpcc.encode(s);
1602 }
1603 // cerr << "!! " << o << endl;
1604 assert(o == "branch=z9hG4bK-d87543-T-i-D-314-Q2xpZW50RGF0YQ..-d87543-");
1605 }
1606
1607 //3329 tests
1608 {
1609 TR _tr( "Token + parameters parse test 3329 ");
1610 char *org = "digest;d-alg=md5";
1611
1612 HeaderFieldValue hfv(org, strlen(org));
1613 Token tok(&hfv, Headers::UNKNOWN);
1614 assert(tok.value() == "digest");
1615 assert(tok.param(p_dAlg) == "md5");
1616 }
1617
1618 {
1619 TR _tr( "Token + parameters parse test");
1620 char *org = "digest;d-qop=verify";
1621
1622 HeaderFieldValue hfv(org, strlen(org));
1623 Token tok(&hfv, Headers::UNKNOWN);
1624 assert(tok.value() == "digest");
1625 assert(tok.param(p_dQop) == "verify");
1626 }
1627
1628 {
1629 TR _tr( "Token + parameters parse test");
1630 char *org = "digest;d-ver=\"0000000000000000000000000000abcd\"";
1631
1632 HeaderFieldValue hfv(org, strlen(org));
1633 Token tok(&hfv, Headers::UNKNOWN);
1634 assert(tok.value() == "digest");
1635 assert(tok.param(p_dVer) == "0000000000000000000000000000abcd");
1636 }
1637
1638 cerr << "\nTEST OK" << endl;
1639
1640 return 0;
1641 }
1642
1643 /* ====================================================================
1644 * The Vovida Software License, Version 1.0
1645 *
1646 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
1647 *
1648 * Redistribution and use in source and binary forms, with or without
1649 * modification, are permitted provided that the following conditions
1650 * are met:
1651 *
1652 * 1. Redistributions of source code must retain the above copyright
1653 * notice, this list of conditions and the following disclaimer.
1654 *
1655 * 2. Redistributions in binary form must reproduce the above copyright
1656 * notice, this list of conditions and the following disclaimer in
1657 * the documentation and/or other materials provided with the
1658 * distribution.
1659 *
1660 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
1661 * and "Vovida Open Communication Application Library (VOCAL)" must
1662 * not be used to endorse or promote products derived from this
1663 * software without prior written permission. For written
1664 * permission, please contact vocal@vovida.org.
1665 *
1666 * 4. Products derived from this software may not be called "VOCAL", nor
1667 * may "VOCAL" appear in their name, without prior written
1668 * permission of Vovida Networks, Inc.
1669 *
1670 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
1671 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1672 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
1673 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
1674 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
1675 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
1676 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
1677 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
1678 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
1679 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1680 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
1681 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1682 * DAMAGE.
1683 *
1684 * ====================================================================
1685 *
1686 * This software consists of voluntary contributions made by Vovida
1687 * Networks, Inc. and many individuals on behalf of Vovida Networks,
1688 * Inc. For more information on Vovida Networks, Inc., please see
1689 * <http://www.vovida.org/>.
1690 *
1691 */
1692
1693 /* Local Variables: */
1694 /* c-file-style: "ellemtel" */
1695 /* End: */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27