/[resiprocate]/main/resip/stack/test/testSipMessage.cxx
ViewVC logotype

Contents of /main/resip/stack/test/testSipMessage.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11169 - (show annotations) (download)
Thu May 1 21:33:13 2014 UTC (5 years, 6 months ago) by sgodin
File MIME type: text/plain
File size: 112624 byte(s)
-fix for a use-after-free bug when adding multi-headers to a list that has been copied, and then 
 one of the headers is accessed (but not necessarily parsed) - thanks to Byron Campen for this fix!
1 #include <iostream>
2 #include <memory>
3
4 #include "rutil/DataStream.hxx"
5 #include "resip/stack/SipMessage.hxx"
6 #include "resip/stack/Helper.hxx"
7 #include "resip/stack/Uri.hxx"
8 #include "resip/stack/Helper.hxx"
9 #include "resip/stack/SdpContents.hxx"
10 #include "resip/stack/test/TestSupport.hxx"
11 #include "resip/stack/PlainContents.hxx"
12 #include "resip/stack/UnknownHeaderType.hxx"
13 #include "resip/stack/UnknownParameterType.hxx"
14 #include "rutil/Logger.hxx"
15 #include "rutil/ParseBuffer.hxx"
16 #include "rutil/Inserter.hxx"
17
18 using namespace resip;
19 using namespace std;
20
21 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
22 #define CRLF "\r\n"
23 #define RESIP_COOKIE "-524287-"
24
25 //vis -o to make binary bodies text
26
27 int
28 main(int argc, char** argv)
29 {
30 Log::initialize(Log::Cout, Log::Debug, argv[0]);
31 initNetwork();
32
33 {
34 // This test excercises a now fixed use-after-free bug when adding multi-headers to a list that has been copied, and then
35 // one of the headers is accessed (but not necessarily parsed).
36 Data txt("INVITE sip:192.168.2.92:5100;q=1 SIP/2.0\r\n"
37 "Record-Route: <sip:rruser@rrdomain;lr>\r\n"
38 "To: <sip:yiwen_AT_meet2talk.com@whistler.gloo.net>\r\n"
39 "From: Jason Fischl<sip:jason_AT_meet2talk.com@whistler.gloo.net>;tag=ba1aee2d\r\n"
40 "Via: SIP/2.0/UDP 192.168.2.220:5060;branch=z9hG4bK-c87542-da4d3e6a.0-1--c87542-;rport=5060;received=192.168.2.220;stid=579667358\r\n"
41 "Via: SIP/2.0/UDP 192.168.2.15:5100;branch=z9hG4bK-c87542-579667358-1--c87542-;rport=5100;received=192.168.2.15\r\n"
42 "Call-ID: 6c64b42fce01b007\r\n"
43 "CSeq: 2 INVITE\r\n"
44 "Route: <sip:proxy@192.168.2.220:5060;lr>\r\n"
45 "Contact: <sip:192.168.2.15:5100>\r\n"
46 "Content-Length: 0\r\n"
47 "\r\n");
48
49 auto_ptr<SipMessage> msg(SipMessage::make(txt, true /* isExternal */));
50
51 SipMessage response;
52 Helper::makeResponse(response, *msg, 200);
53
54 // Trigger a parse of Record-Route
55 NameAddr rr("sip:test@rr.com");
56 if(!(response.header(h_RecordRoutes).front() == rr))
57 {
58 //
59 }
60 // Now push a new Record-Route
61 response.header(h_RecordRoutes).push_front(rr);
62 assert(response.header(h_RecordRoutes).back().uri().user() == "rruser");
63
64 //InfoLog(<< response);
65 }
66
67 static ExtensionParameter p_tag_ext("tag");
68 {
69 Data txt(
70 "SIP/2.0 401 Unauthorized\r\n"
71 "To: <sip:6309790007@ahenc1.ascc.lucent.com>;tag=43822895-1132606320408559\r\n"
72 "From: \"Kit LDAP\"<sip:6309790007@ahenc1.ascc.lucent.com>;tag=64505823\r\n"
73 "Call-ID: 7574556ad424b15c@aW5zcDc1MDAudW5pY29uLWludGwuY29t\r\n"
74 "CSeq: 1 PUBLISH\r\n"
75 "Via: SIP/2.0/UDP 67.184.22.204:33001;received=67.184.22.204;branch=z9hG4bK" RESIP_COOKIE "1---861ee62db418b378\r\n"
76 "Server: Lucent SIPTRANS 1.2\r\n"
77 "WWW-Authenticate: Digest realm=\"aP3nFt10ziWg41Su4s8\", \r\n"
78 " nonce=\"d6cb083cced5583c140c5f99eb81feda\", algorithm=MD5, qop=\"auth\", \r\n"
79 " opaque=\"f2a62109ee6526c8760e4e7497861aac\"\r\n"
80 "Content-Length: 0\r\n"
81 "\r\n"
82 );
83
84 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
85 assert(msg.get());
86 resipCerr << Inserter(msg->header(h_WWWAuthenticates)) << endl;
87
88 resipCerr << "[" << msg->header(h_WWWAuthenticates).back().param(p_opaque) << "]" << endl;
89
90 assert(msg->header(h_WWWAuthenticates).back().param(p_opaque) == "f2a62109ee6526c8760e4e7497861aac");
91 }
92
93 {
94 Data txt(
95 "To: sip:fluffy@h1.cs.sipit.net\r\n"
96 "From: tofu <sip:tofu@ua.ntt.sipit.net>;tag=5494179792598219348\r\n"
97 "CSeq: 1 SUBSCRIBE\r\n"
98 "Call-ID: 1129541551360711705\r\n"
99 "Contact: sip:tofu@ua.ntt.sipit.net:5060\r\n"
100 "Event: presence\r\n"
101 "Content-Length: 0\r\n"
102 "Expires: 3600\r\n"
103 "User-Agent: NTT SecureSession User-Agent\r\n"
104 "\r\n"
105 "--Dfk2rISgfWIirrOJ\r\n"
106 "Content-Type: application/pkcs7-signature; name=\"smime.p7s\"\r\n"
107 "Content-Transfer-Encoding: binary\r\n"
108 "Content-Disposition: attachment; filename=\"smime.p7s\"; handling=required\r\n"
109 "0\202\004\201\327\006 *\206H\206\367\001\007\002\201\240\202\004\201\3100\202\004\201\304\002\001\0011\0130 \006\005+\003\002\032\005\000\201\260\013\006 \201\252\206\201\310\206\367\001\007\001\201\240\202\003\201\376\201\260\202\003\201\372\201\260\202\002\201\343\201\240\003\002\001\002\002\007\201\322\000\002\000\201\327\003\201\313\201\260\006 \201\252\206\201\310\206\367\001\001\005\005\000\201\260\201\360\201\261\013\201\260 \006\003\201\325\004\006\023\002\201\325\201\323\201\261\023\201\260\021\006\003\201\325\004\010\023r\201\303\201\341\201\354\201\351\201\346\201\357\201\362\201\356\201\351\201\341\201\261\021\201\260\006\003U\004\007\023\010San Jose1\201\260\014\006\003\201\325\004\023\005\201\363\201\351\201\360\201\351\201\364\201\261\201\251\201\260\201\247\006\003\201\325\004\013\023\201\240\201\323\201\351\201\360\201\351\201\364\201\240\201\324\201\345\201\363\201\364\201\240\201\303\201\345\201\362\201\364\201\351\201\346\201\351\201\343\201\341\201\364\201\345\201\240\201\301\201\365\201\364\201\350\201\357\201\362\201\351\201\364\201\371\201\260\036\027\201\260\201\264\201\260\201\270\201\262\201\265\201\260\201\262\201\261\201\270\201\264\201\270\201\332\027\201\260\201\267\201\260\201\270\201\262\201\265\201\260\201\262\201\261\201\270\201\264\201\270\201\332\201\260\201\345\201\261\013\201\260 \006\003\201\325\004\006\023\002\201\325\201\323\201\261\023\201\260\021\006\003\201\325\004\010\023\201\303\201\341\201\354\201\351\201\346\201\357\201\362\201\356\201\351\201\341\201\261\021\201\260\006\003U\004\007\023\010San Jose1\201\260\014\006\003\201\325\004\005\201\363\201\351\201\360\201\351\201\364\201\261\036\201\260\034\006\003\201\325\004\003\024\025\201\364\201\357\201\346\201\365\201\300\201\365\201\341\201\256\201\356\201\364\201\364\201\256\201\363\201\351\201\360\201\351\201\364\201\256\201\356\201\345\201\364\201\260\201\237\201\260\006 \201\252\206\201\310\206\367\001\001\001\005\000\003\201\215\000\201\260\201\211\002\201\201\000\201\331\201\322\201\267\201\345\201\263\201\337\201\201\365\201\246\201\317\201\337\201\314\201\343\201\350\201\370\201\332\201\372\201\366\201\356\227\201\260\010\201\304\201\326\005\201\253\014\201\316\201\335\201\362\201\253\201\336\036\201\326\201\247\201\365\201\321\201\342\201\312\201\336\201\310\030\201\310\034\201\325\201\274\201\255\201\336\201\372\201\306\201\277\201\303\201\364\201\343\201\355\201\240\201\323\201\374\201\347\201\240\004\201\363\205\316\230\205\320\205\261\205\255\211\205\205\261\205\276\205\333\205\277\205\350\205\274\205\361\021\201\260\201\255\201\265\201\276\201\373\203\201\267\201\356\201\355\201\256\201\337\201\262\201\244\201\305\033\023\000\201\266\206\021\201\303\201\252\201\265\201\364\001\201\246\201\251\030\201\372\235\201\325\201\273\037\201\251\201\332\201\354\201\331\201\371\201\263\201\261\201\347\236\201\322\201\376\201\274\201\332\201\377\002\003\001\000\001\201\243\202\001\201\247\201\260\202\001\201\243\201\260\201\332\006\003\201\325\035\021\004\201\323\201\260\201\321\206\031\201\363\201\351\201\360\201\272\201\364\201\357\201\346\201\365\201\300\201\365\201\341\201\256\201\356\201\364\201\364\201\256\201\363\201\351\201\360\201\351\201\364\201\256\201\356\201\345\201\364\206\030\201\351\201\355\201\272\201\364\201\357\201\346\201\365\201\300\201\365\201\341\201\256\201\356\201\364\201\364\201\256\201\363\201\351\201\360\201\351\201\364\201\256\201\356\201\345\201\364\206\032\201\360\201\362\201\345\201\363\201\272\201\364\201\357\201\346\201\365\201\300\201\365\201\341\201\256\201\356\201\364\201\364\201\256\201\363\201\351\201\360\201\351\201\364\201\256\201\356\201\345\201\364\201\260 \006\003\201\325\035\023\004\002\201\260\000\201\260\035\006\003\201\325\035\004\026\004\024 \026\201\307\201\306l\201\242\234\013\201\261\034\237\201\247\201\262\035\201\254B\201\357\201\324\201\2660\201\232\006\003U\035#\004\201\2220\201\217\200\024kF\027\024\201\352\224v%\200Tn\023T\201\332\201\241\201\343T\024\201\241\201\266\201\241t\201\244r0p1\0130 \006\003U\004\006\023\002US1\0230\021\006\003U\004\010\023California1\0210\006\003U\004\007\023\010San Jose1\201\260\014\006\003\201\325\004\023\005\201\363\201\351\201\360\201\351\201\364\201\261\201\251\201\260\201\247\006\003\201\325\004\013\023\201\240\201\323\201\351\201\360\201\351\201\364\201\240\201\324\201\345\201\363\201\364\201\240\201\303\201\345\201\362\201\364\201\351\201\346\201\351\201\343\201\341\201\364\201\345\201\240\201\301\201\365\201\364\201\350\201\357\201\362\201\351\201\364\201\371\202\001\000\201\260\006 \201\252\206\201\310\206\367\001\001\005\005\000\003\201\201\000\201\241\201\311\201\336\226\201\321\201\365\201\256\201\256\005\201\245\215\310\215\320\215\260\024\201\351\201\301\201\377\201\270\201\337\201\260\201\306\203\201\241\201\307\203\355\032\201\246\003\201\334\201\264\010\201\321\000\201\261\201\255\201\261\201\366\201\304\201\346\201\270\201\313\226\210\201\363\014\201\256\201\277\201\302\201\240\201\361\201\366\201\352\201\344\201\255\201\327\201\263\236\201\355\201\272\010\236\201\277\201\245\201\267\201\316\201\300\201\311\201\357\201\336\201\277\201\360\201\366\201\302\201\262\201\373\201\261\201\351\201\345\201\243\201\330\201\325\201\271\201\277\201\264\234\201\363\007\021\201\247\201\314\201\265\201\243\201\242\201\253\201\353\201\266\201\313\201\341\201\341\201\340\201\316\232\205\244\205\324\205\267\205\363\205\351\205\257\205\373\205\267\010\201\362\201\240\201\273\201\324\201\265\211\264\030\201\372\201\356\201\326\201\323\201\261\202\001\201\241\201\260\202\001\035\002\001\001\201\260\201\373\201\260\201\360\201\261\013\201\260 \006\003\201\325\004\006\023\002\201\325\201\323\201\261\023\201\260\021\006\003\201\325\004\010\023\201\303\201\341\201\354\201\351\201\346\201\357\201\362\201\356\201\351\201\341\201\261\021\201\260\006\003U\004\007\023\010San Jose1\201\260\014\006\003\201\325\004\023\005\201\363\201\351\201\360\201\351\201\364\201\261\201\251\201\260\201\247\006\003\201\325\004\013\023\201\240\201\323\201\351\201\360\201\351\201\364\201\240\201\324\201\345\201\363\201\364\201\240\201\303\201\345\201\362\201\364\201\351\201\346\201\351\201\343\201\341\201\364\201\345\201\240\201\301\201\365\201\364\201\350\201\357\201\362\201\351\201\364\201\371\002\007\201\322\000\002\000\201\327\003\201\313\201\260 \006\005\201\253\003\002\032\005\000\201\260\006 \201\252\206\201\310\206\367\001\001\001\005\000\004\201\200\201\246\201\255\202\350\202\242\202\261\207\227\033\027\201\375 \201\332\201\267\201\246\201\375\031\201\326\201\255\001\201\271\201\333\201\306\201\351\201\367\201\344\031\201\356\233\201\353\031\003\201\336 \003\201\353\201\260\201\323\201\267\026\022\201\307\233\201\316\201\362\201\304\201\256\201\247\201\243\201\256\201\261\211\202\243\202\324\202\314\027\222\027\222\034\230\201\240\201\323\037\201\345\034\220\201\372\201\261\201\377\201\333\201\310\201\343\201\300\201\335\201\310 \236\201\274\201\315\201\301\201\352\202\201\261\201\324\201\347\222\203\333\203\316\203\336\203\360<\211\236\203\276[\203\301\003\010\201\373rR\236\201\322\027\201\242\201\374b\027d:\225(\030\225\217\032\202\025\201\373\226\201\255\201\255\201\304\201\346\201\353\201\262\201\362\201\311\201\323\201\347\201\346\201\327\201\311\201\351\201\362\201\362\201\317\201\312\201\255\201\255" );
110
111 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
112 // !ah! deleted resipCerr output that was messing up terminals
113 }
114
115 {
116 SipMessage empty;
117
118 try
119 {
120 resipCerr << empty.brief() << endl;
121 empty.header(h_CSeq);
122 resipCerr << empty.brief() << endl;
123 empty.header(h_Vias).push_back(Via());
124 resipCerr << empty.brief() << endl;
125 }
126 catch (SipMessage::Exception& e)
127 {}
128 }
129
130 {
131 Data txt("INVITE sip:192.168.2.92:5100;q=1 SIP/2.0\r\n"
132 "To: <sip:yiwen_AT_meet2talk.com@whistler.gloo.net>\r\n"
133 "From: Jason Fischl<sip:jason_AT_meet2talk.com@whistler.gloo.net>;tag=ba1aee2d\r\n"
134 "Via: SIP/2.0/UDP 192.168.2.220:5060;branch=z9hG4bK-c87542-da4d3e6a.0-1--c87542-;rport=5060;received=192.168.2.220;stid=579667358\r\n"
135 "Via: SIP/2.0/UDP 192.168.2.15:5100;branch=z9hG4bK-c87542-579667358-1--c87542-;rport=5100;received=192.168.2.15\r\n"
136 "Call-ID: 6c64b42fce01b007\r\n"
137 "CSeq: 2 INVITE\r\n"
138 "Route: <sip:proxy@192.168.2.220:5060;lr>\r\n"
139 "Contact: <sip:192.168.2.15:5100>\r\n"
140 "Content-Length: 0\r\n"
141 "\r\n");
142
143 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
144 msg->header(h_Routes).pop_back();
145 resipCerr << *msg << endl;
146 }
147
148 {
149 Data txt("INVITE sip:192.168.2.92:5100;q=1 SIP/2.0\r\n"
150 "To: <sip:yiwen_AT_meet2talk.com@whistler.gloo.net>\r\n"
151 "From: Jason Fischl<sip:jason_AT_meet2talk.com@whistler.gloo.net>;tag=ba1aee2d\r\n"
152 "Via: SIP/2.0/UDP 192.168.2.220:5060;branch=z9hG4bK-c87542-da4d3e6a.0-1--c87542-;rport=5060;received=192.168.2.220;stid=579667358\r\n"
153 "Via: SIP/2.0/UDP 192.168.2.15:5100;branch=z9hG4bK-c87542-579667358-1--c87542-;rport=5100;received=192.168.2.15\r\n"
154 "Call-ID: 6c64b42fce01b007\r\n"
155 "CSeq: 2 INVITE\r\n"
156 "Record-Route: <sip:proxy@192.168.2.220:5060;lr>\r\n"
157 "Contact: <sip:192.168.2.15:5100>\r\n"
158 "Max-Forwards: 69\r\n"
159 "Content-Type: application/sdp\r\n"
160 "Content-Length: 307\r\n"
161 "\r\n"
162 "v=0\r\n"
163 "o=M2TUA 1589993278 1032390928 IN IP4 192.168.2.15\r\n"
164 "s=-\r\n"
165 "c=IN IP4 192.168.2.15\r\n"
166 "t=0 0\r\n"
167 "m=audio 9000 RTP/AVP 103 97 100 101 0 8 102\r\n"
168 "a=rtpmap:103 ISAC/16000\r\n"
169 "a=rtpmap:97 IPCMWB/16000\r\n"
170 "a=rtpmap:100 EG711U/8000\r\n"
171 "a=rtpmap:101 EG711A/8000\r\n"
172 "a=rtpmap:0 PCMU/8000\r\n"
173 "a=rtpmap:8 PCMA/8000\r\n"
174 "a=rtpmap:102 iLBC/8000\r\n");
175
176 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
177 SdpContents* sdp = dynamic_cast<SdpContents*>(msg->getContents());
178
179 sdp->session().media().front();
180
181 SdpContents osdp;
182 osdp.session().version() = 0;
183 osdp.session().name() = "-";
184 osdp.session().origin() = SdpContents::Session::Origin(Data("M2TUA"),
185 77,
186 99,
187 SdpContents::IP4,
188 "localhost");
189 osdp.session().addTime(SdpContents::Session::Time(0,0));
190 osdp.session().connection() =
191 SdpContents::Session::Connection(SdpContents::IP4, "localhost", 0);
192 SdpContents::Session::Medium medium(Symbols::audio, 0, 1, Symbols::RTP_AVP);
193
194 SdpContents::Session::Codec codec1("iLBC", 102, 8000);
195 medium.addCodec(codec1);
196
197 SdpContents::Session::Codec codec2("PCMA", 8, 8000);
198 medium.addCodec(codec2);
199
200 SdpContents::Session::Codec codec3("PCMU", 0, 8000);
201 medium.addCodec(codec3);
202
203 SdpContents::Session::Codec codec4("EG711A", 101, 8000);
204 medium.addCodec(codec4);
205
206 SdpContents::Session::Codec codec5("EG711U", 100, 8000);
207 medium.addCodec(codec5);
208
209 SdpContents::Session::Codec codec6("IPCMWB", 97, 16000);
210 medium.addCodec(codec6);
211
212 SdpContents::Session::Codec codec7("ISAC", 103, 16000);
213 medium.addCodec(codec7);
214
215 osdp.session().addMedium(medium);
216 SdpContents::Session::Medium& myMedium = osdp.session().media().front();
217
218 SdpContents csdp;
219 csdp = *sdp;
220 SdpContents::Session::Medium& my1Medium = csdp.session().media().front();
221 resipCerr << myMedium.protocol() << " : " << my1Medium.protocol() << endl;
222
223 SdpContents c2sdp;
224 c2sdp = *sdp;
225
226
227 SdpContents::Session::Medium& myMedium2 = c2sdp.session().media().front();
228 resipCerr << myMedium2.protocol() << endl;
229 }
230
231 {
232 Data txt1 = "SIP/2.0 407 Proxy Authentication Required\r\n"
233 "To: <sip:jason_AT_meet2talk.com@beta.meet2talk.com>\r\n"
234 "From: <sip:jason_AT_meet2talk.com@beta.meet2talk.com>;tag=113cba09\r\n"
235 "Via: SIP/2.0/64.124.66.32:9091;branch=z9hG4bK-c87542-5b42cb698e8c6827790212ac5bdade1a-1-PA32768-c87542-;rport;received=64.124.66.32\r\n"
236 "Via: SIP/2.0/UDP 192.168.1.102:5100;branch=z9hG4bK-c87542-175255966-1--c87542-;rport\r\n"
237 "Call-ID: d8023c1dc2559a21\r\n"
238 "CSeq: 1 REGISTER\r\n"
239 "Contact: <sip:64.124.66.32:5060>\r\n"
240 "Content-Length: 0\r\n\r\n";
241
242 auto_ptr<SipMessage> message1(TestSupport::makeMessage(txt1));
243
244 try
245 {
246 resipCerr << "transport=" << message1->header(h_Vias).front().transport() << endl;
247 assert(false);
248 }
249 catch (ParseException& e)
250 {
251 }
252 }
253
254 {
255 resipCerr << "test CRLFs before the start line" << endl;
256 Data txt1 = "\r\n\r\n\r\nSIP/2.0 407 Proxy Authentication Required\r\n"
257 "To: <sip:jason_AT_meet2talk.com@beta.meet2talk.com>\r\n"
258 "From: <sip:jason_AT_meet2talk.com@beta.meet2talk.com>;tag=113cba09\r\n"
259 "Via: SIP/2.0/UDP 64.124.66.32:9091;branch=z9hG4bK-c87542-5b42cb698e8c6827790212ac5bdade1a-1-PA32768-c87542-;rport;received=64.124.66.32\r\n"
260 "Via: SIP/2.0/UDP 192.168.1.102:5100;branch=z9hG4bK-c87542-175255966-1--c87542-;rport\r\n"
261 "Call-ID: d8023c1dc2559a21\r\n"
262 "CSeq: 1 REGISTER\r\n"
263 "Contact: <sip:64.124.66.32:5060>\r\n"
264 "Content-Length: 0\r\n\r\n";
265
266 try
267 {
268 auto_ptr<SipMessage> message1(TestSupport::makeMessage(txt1));
269 if (message1->header(h_StatusLine).statusCode() == 407){;}
270 }
271 catch (BaseException& e)
272 {
273 assert(false);
274 }
275 }
276
277 {
278 resipCerr << "test complex content copy" << endl;
279
280 Data txt = ("MESSAGE sip:fluffy@212.157.205.40 SIP/2.0\r\n"
281 "Via: SIP/2.0/TCP 212.157.205.198:5060;branch=z9hG4bK2367411811584019109\r\n"
282 "Via: SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK-c87542-107338443-1--c87542-;stid=489573115\r\n"
283 "Via: SIP/2.0/UDP whistler.gloo.net:5068;branch=z9hG4bK-c87542-489573115-1--c87542-;received=192.168.2.220\r\n"
284 "To: sip:fluffy@212.157.205.40\r\n"
285 "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
286 "Max-Forwards: 70\r\n"
287 "CSeq: 1 NOTIFY\r\n"
288 "Call-ID: 28067261571992032320\r\n"
289 "Contact: sip:ntt2@212.157.205.198:5060\r\n"
290 "Expires: 47\r\n"
291 "Content-Length: 1929\r\n"
292 "Content-Type: multipart/signed;\r\n"
293 " protocol=\"application/pkcs7-signature\";\r\n"
294 " micalg=sha1; boundary=\"----YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\"\r\n"
295 "\r\n"
296 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
297 "Content-Type: multipart/mixed;boundary=\"----lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\"\r\n"
298 "Content-Length: 870\r\n"
299 "Content-Disposition: attachment;handling=required\r\n"
300 "\r\n"
301 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
302 "Content-Type: application/sipfrag\r\n"
303 "Content-Length: 320\r\n"
304 "\r\n"
305 "To: sip:fluffy@212.157.205.40\r\n"
306 "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
307 "CSeq: 1 NOTIFY\r\n"
308 "Call-ID: 28067261571992032320\r\n"
309 "Contact: sip:ntt2@212.157.205.198:5060\r\n"
310 "Event: presence\r\n"
311 "Content-Length: 210\r\n"
312 "Content-Type: application/xpidf+xml\r\n"
313 "Subscription-State: active\r\n"
314 "User-Agent: XXX SecureSession User-Agent\r\n"
315 "\r\n"
316 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
317 "Content-Type: application/xpidf+xml\r\n"
318 "Content-Length: 210\r\n"
319 "\r\n"
320 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
321 "<presence xmlns:impp=\"urn:ietf:params:xml:ns:pidf\" entity=\"pres:someone@example.com\">\r\n"
322 "<tuple id=\"765\">\r\n"
323 "<status>\r\n"
324 "<basic>open</basic>\r\n"
325 "</status>\r\n"
326 "</tuple>\r\n"
327 "</presence>\r\n"
328 "\r\n"
329 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY--\r\n"
330 "\r\n"
331 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
332 "Content-Type: application/pkcs7-signature; name=\"smime.p7s\"\r\n"
333 "Content-Transfer-Encoding: base64\r\n"
334 "Content-Disposition: attachment; filename=\"smime.p7s\"; handling=required\r\n"
335 "\r\n"
336 "MIIBVgYJKoZIhvcNAQcCoIIBRzCCAUMCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3\r\n"
337 "DQEHATGCASIwggEeAgEBMHwwcDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlm\r\n"
338 "b3JuaWExETAPBgNVBAcTCFNhbiBKb3NlMQ4wDAYDVQQKEwVzaXBpdDEpMCcGA1UE\r\n"
339 "CxMgU2lwaXQgVGVzdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkCCAIWABUCBgIVMAkG\r\n"
340 "BSsOAwIaBQAwDQYJKoZIhvcNAQEBBQAEgYAer8TPSMtA3ZqweGnXLUYKR51bp52N\r\n"
341 "oGBEqHZz7xR0Nhs6DsAOXiSFv19vTR//33u6Se3zpNNHP/zj7NRr+olimI2PeBNB\r\n"
342 "tczNdqexoN0pjRW7l7mHZ0e39pqZmI5bhFl+z9CJJu5xW0aSarw84CZxbh5RQaYr\r\n"
343 "zhSvTYdki20aiQ==\r\n"
344 "\r\n"
345 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC--\r\n"
346 );
347
348 std::auto_ptr<SipMessage> msg(SipMessage::make(txt));
349
350 SipMessage msg1;
351 msg1.setContents(msg->getContents());
352
353 CerrLog(<< Data::from(*msg1.getContents()));
354 CerrLog(<< Data::from(*msg->getContents()));
355 }
356
357 {
358 InfoLog(<< "Testing assignment");
359
360 Data txt1 = ("SIP/2.0 401 Unauthorized\r\n"
361 "To: <sip:foobie@example.com>;tag=12345678\r\n"
362 "From: <sip:bar@example.com>;tag=83ec8345\r\n"
363 "Via: SIP/2.0/TLS 192.168.2.205:5061;branch=z9hG4bK-c87542-488593999-1--c87542-;rport\r\n"
364 "Call-ID: 3f0b546f89f28456\r\n"
365 "CSeq: 1 REGISTER\r\n"
366 "Expires: 3600\r\n"
367 "Max-Forwards: 70\r\n"
368 "Www-Authenticate: Basic realm=test\r\n"
369 "Allow-Events: presence\r\n"
370 "Content-Length: 0\r\n"
371 "\r\n");
372
373 auto_ptr<SipMessage> message1(TestSupport::makeMessage(txt1));
374
375
376 Data txt2 = ("NOTIFY sip:fluffy@212.157.205.40 SIP/2.0\r\n"
377 "Via: SIP/2.0/TCP 212.157.205.198:5060;branch=z9hG4bK2367411811584019109\r\n"
378 "Via: SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK-c87542-107338443-1--c87542-;stid=489573115\r\n"
379 "Via: SIP/2.0/UDP whistler.gloo.net:5068;branch=z9hG4bK-c87542-489573115-1--c87542-;received=192.168.2.220\r\n"
380 "To: sip:fluffy@212.157.205.40\r\n"
381 "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
382 "Max-Forwards: 70\r\n"
383 "CSeq: 1 NOTIFY\r\n"
384 "Call-ID: 28067261571992032320\r\n"
385 "Contact: sip:ntt2@212.157.205.198:5060\r\n"
386 "Content-Length: 1929\r\n"
387 "Content-Type: multipart/signed;\r\n"
388 " protocol=\"application/pkcs7-signature\";\r\n"
389 " micalg=sha1; boundary=\"----YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\"\r\n"
390 "\r\n"
391 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
392 "Content-Type: multipart/mixed;boundary=\"----lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\"\r\n"
393 "Content-Length: 870\r\n"
394 "Content-Disposition: attachment;handling=required\r\n"
395 "\r\n"
396 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
397 "Content-Type: application/sipfrag\r\n"
398 "Content-Length: 320\r\n"
399 "\r\n"
400 "To: sip:fluffy@212.157.205.40\r\n"
401 "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
402 "CSeq: 1 NOTIFY\r\n"
403 "Call-ID: 28067261571992032320\r\n"
404 "Contact: sip:ntt2@212.157.205.198:5060\r\n"
405 "Event: presence\r\n"
406 "Content-Length: 210\r\n"
407 "Content-Type: application/xpidf+xml\r\n"
408 "Subscription-State: active\r\n"
409 "User-Agent: XXX SecureSession User-Agent\r\n"
410 "\r\n"
411 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
412 "Content-Type: application/xpidf+xml\r\n"
413 "Content-Length: 210\r\n"
414 "\r\n"
415 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
416 "<presence xmlns:impp=\"urn:ietf:params:xml:ns:pidf\" entity=\"pres:someone@example.com\">\r\n"
417 "<tuple id=\"765\">\r\n"
418 "<status>\r\n"
419 "<basic>open</basic>\r\n"
420 "</status>\r\n"
421 "</tuple>\r\n"
422 "</presence>\r\n"
423 "\r\n"
424 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY--\r\n"
425 "\r\n"
426 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
427 "Content-Type: application/pkcs7-signature; name=\"smime.p7s\"\r\n"
428 "Content-Transfer-Encoding: base64\r\n"
429 "Content-Disposition: attachment; filename=\"smime.p7s\"; handling=required\r\n"
430 "\r\n"
431 "MIIBVgYJKoZIhvcNAQcCoIIBRzCCAUMCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3\r\n"
432 "DQEHATGCASIwggEeAgEBMHwwcDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlm\r\n"
433 "b3JuaWExETAPBgNVBAcTCFNhbiBKb3NlMQ4wDAYDVQQKEwVzaXBpdDEpMCcGA1UE\r\n"
434 "CxMgU2lwaXQgVGVzdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkCCAIWABUCBgIVMAkG\r\n"
435 "BSsOAwIaBQAwDQYJKoZIhvcNAQEBBQAEgYAer8TPSMtA3ZqweGnXLUYKR51bp52N\r\n"
436 "oGBEqHZz7xR0Nhs6DsAOXiSFv19vTR//33u6Se3zpNNHP/zj7NRr+olimI2PeBNB\r\n"
437 "tczNdqexoN0pjRW7l7mHZ0e39pqZmI5bhFl+z9CJJu5xW0aSarw84CZxbh5RQaYr\r\n"
438 "zhSvTYdki20aiQ==\r\n"
439 "\r\n"
440 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC--\r\n"
441 );
442
443 auto_ptr<SipMessage> message2(TestSupport::makeMessage(txt2));
444
445 SipMessage message3;
446 UnknownHeaderType h_Foo("foo");
447 UnknownHeaderType h_Bar("bar");
448
449 message3.header(h_Foo);
450 message3.header(h_Bar).push_back(StringCategory("bar1"));
451 message3.header(h_Bar).push_back(StringCategory("bar2"));
452
453 //message3.header(h_Vias);
454 message3.header(h_To);
455
456 message3.header(h_RequestLine) = RequestLine(INVITE);
457 message3.header(h_RequestLine).uri() = Uri("sip:bob@biloxi.com");
458 message3.header(h_To) = NameAddr("sip:bob@biloxi.com");
459 message3.header(h_From) = NameAddr("Alice <sip:alice@atlanta.com>;tag=1928301774");
460 message3.header(h_CallId).value() = "314159";
461 message3.header(h_CSeq).sequence() = 14;
462 message3.header(h_CSeq).method() = INVITE;
463
464 PlainContents pc("here is some plain ol' contents");
465 message3.setContents(&pc);
466
467 message3 = *message2;
468
469 // cause some parsing
470 assert(!message2->header(h_To).exists(p_tag));
471 message2->getContents();
472
473 // cause some parsing
474 assert(message1->header(h_Vias).front().param(p_branch).clientData().empty());
475
476 assert(message1.get());
477 *message2 = *message1;
478
479 // cause some parsing
480 message3.getContents();
481 message3 = *message2;
482
483 CerrLog(<< Data::from(message3));
484 CerrLog(<< Data::from(*message1));
485
486 assert(message1.get());
487 assert(message3.isRequest() == message1->isRequest());
488 assert(message3.isResponse() == message1->isResponse());
489
490 assert(Data::from(message3) == Data::from(*message1));
491 }
492
493 // !dlb! we seem to have relaxed the quoting requirement in general
494 // we accept unquoted when the grammar says quoted, but always emit quoted
495 #if 0
496 {
497 char* txt = ("SIP/2.0 401 Unauthorized\r\n"
498 "To: <sip:foobie@example.com>;tag=12345678\r\n"
499 "From: <sip:bar@example.com>;tag=83ec8345\r\n"
500 "Via: SIP/2.0/TLS 192.168.2.205:5061;branch=z9hG4bK-c87542-488593999-1--c87542-;rport\r\n"
501 "Call-ID: 3f0b546f89f28456\r\n"
502 "CSeq: 1 REGISTER\r\n"
503 "Expires: 3600\r\n"
504 "Max-Forwards: 70\r\n"
505 "Www-Authenticate: Basic realm=test\r\n"
506 "Allow-Events: presence\r\n"
507 "Content-Length: 0\r\n"
508 "\r\n");
509 try
510 {
511 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
512 assert(message->exists(h_WWWAuthenticates));
513 assert(message->header(h_WWWAuthenticates).size() == 1);
514 assert(message->header(h_WWWAuthenticates).front().scheme() == "Basic");
515 assert(0);
516 }
517 catch (ParseException& e)
518 {
519 InfoLog (<< "Rejected unquoted realm");
520 }
521 }
522 #endif
523
524 {
525 Data txt(
526 "NOTIFY sip:fluffy@212.157.205.40 SIP/2.0\r\n"
527 "Via: SIP/2.0/TCP 212.157.205.198:5060;branch=z9hG4bK2367411811584019109\r\n"
528 "To: sip:fluffy@212.157.205.40\r\n"
529 "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
530 "Max-Forwards: 70\r\n"
531 "CSeq: 1 NOTIFY\r\n"
532 "Call-ID: 28067261571992032320\r\n"
533 "Contact: sip:ntt2@212.157.205.198:5060\r\n"
534 "Content-Length: 1929\r\n"
535 "Content-Type: multipart/signed;\r\n"
536 " protocol=\"application/pkcs7-signature\";\r\n"
537 " micalg=sha1; boundary=\"----YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\"\r\n"
538 "\r\n"
539 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
540 "Content-Type: multipart/mixed;boundary=\"----lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\"\r\n"
541 "Content-Length: 870\r\n"
542 "Content-Disposition: attachment;handling=required\r\n"
543 "\r\n"
544 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
545 "Content-Type: application/sipfrag\r\n"
546 "Content-Length: 320\r\n"
547 "\r\n"
548 "To: sip:fluffy@212.157.205.40\r\n"
549 "From: sip:ntt2@h1.ntt2.sipit.net;tag=727823805122397238\r\n"
550 "CSeq: 1 NOTIFY\r\n"
551 "Call-ID: 28067261571992032320\r\n"
552 "Contact: sip:ntt2@212.157.205.198:5060\r\n"
553 "Event: presence\r\n"
554 "Content-Length: 210\r\n"
555 "Content-Type: application/xpidf+xml\r\n"
556 "Subscription-State: active\r\n"
557 "User-Agent: XXX SecureSession User-Agent\r\n"
558 "\r\n"
559 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY\r\n"
560 "Content-Type: application/xpidf+xml\r\n"
561 "Content-Length: 210\r\n"
562 "\r\n"
563 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
564 "<presence xmlns:impp=\"urn:ietf:params:xml:ns:pidf\" entity=\"pres:someone@example.com\">\r\n"
565 "<tuple id=\"765\">\r\n"
566 "<status>\r\n"
567 "<basic>open</basic>\r\n"
568 "</status>\r\n"
569 "</tuple>\r\n"
570 "</presence>\r\n"
571 "\r\n"
572 "------lRIGMC8E2Px6I2IODfk2rISgfWIirrOJwS3tY52HuxDP3pdTiFjsghJJWhvyRCEY--\r\n"
573 "\r\n"
574 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC\r\n"
575 "Content-Type: application/pkcs7-signature; name=\"smime.p7s\"\r\n"
576 "Content-Transfer-Encoding: base64\r\n"
577 "Content-Disposition: attachment; filename=\"smime.p7s\"; handling=required\r\n"
578 "\r\n"
579 "MIIBVgYJKoZIhvcNAQcCoIIBRzCCAUMCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3\r\n"
580 "DQEHATGCASIwggEeAgEBMHwwcDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlm\r\n"
581 "b3JuaWExETAPBgNVBAcTCFNhbiBKb3NlMQ4wDAYDVQQKEwVzaXBpdDEpMCcGA1UE\r\n"
582 "CxMgU2lwaXQgVGVzdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkCCAIWABUCBgIVMAkG\r\n"
583 "BSsOAwIaBQAwDQYJKoZIhvcNAQEBBQAEgYAer8TPSMtA3ZqweGnXLUYKR51bp52N\r\n"
584 "oGBEqHZz7xR0Nhs6DsAOXiSFv19vTR//33u6Se3zpNNHP/zj7NRr+olimI2PeBNB\r\n"
585 "tczNdqexoN0pjRW7l7mHZ0e39pqZmI5bhFl+z9CJJu5xW0aSarw84CZxbh5RQaYr\r\n"
586 "zhSvTYdki20aiQ==\r\n"
587 "\r\n"
588 "------YvhIjyjTU8lfNqGe8Fyvxcmb4mleF6quxsMFpT2hOhrDfS3LLs1MyYBdLNgBLsSC--\r\n"
589 );
590
591 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
592 InfoLog (<< "msg->header(h_ContentLength).value() == " << msg->header(h_ContentLength).value());
593 assert( msg->header(h_ContentLength).value() == 1929 );
594 }
595 {
596 Data txt(
597 "MESSAGE sip:fluffy@h1.cisco1.sipit.net:5060;transport=UDP SIP/2.0\r\n"
598 "To: <sip:fluffy@h1.cisco1.sipit.net:5060>\r\n"
599 "From: <sip:user@localhost:5080>;tag=20f94fd6\r\n"
600 "Via: SIP/2.0/UDP 212.157.205.40:5080;branch=z9hG4bK-c87542-1005764096-2--c87542-;rport=5080;received=212.157.205.40\r\n"
601 "Call-ID: 16f7f8fd368d8bcd\r\n"
602 "CSeq: 1 MESSAGE\r\n"
603 "Contact: <sip:user@212.157.205.40:5080>\r\n"
604 "Max-Forwards: 70\r\n"
605 "Content-Disposition: attachment;handling=required;filename=smime.p7\r\n"
606 "Content-Type: application/pkcs7-mime;smime-type=enveloped-data;name=smime.p7m\r\n"
607 "User-Agent: SIPimp.org/0.2.3 (curses)\r\n"
608 "Content-Length: 4\r\n"
609 "\r\n"
610 "1234" );
611
612 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
613
614 assert( msg->exists(h_ContentDisposition) );
615 msg->header(h_ContentDisposition);
616 assert( msg->header(h_ContentLength).value() == 4 );
617 }
618 {
619 // exercise header remove
620 const char* txt = ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
621 "Allow-Events: foo\r\n"
622 "Allow-Events: bar\r\n"
623 "Allow-Events: baz\r\n"
624 "Allow-Events: quux\r\n"
625 "Unsupported: \r\n"
626 "To: <sip:ext101@whistler.gloo.net:5061>\r\n"
627 "From: <sip:ext103@whistler.gloo.net:5061>;tag=a731\r\n"
628 "Via: SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK-c87542-107338443-1--c87542-;stid=489573115\r\n"
629 "Via: SIP/2.0/UDP whistler.gloo.net:5068;branch=z9hG4bK-c87542-489573115-1--c87542-;received=192.168.2.220\r\n"
630 "Call-ID: 643f2f06\r\n"
631 "CSeq: 1 INVITE\r\n"
632 "Proxy-Authorization: Digest username=\"Alice\", realm = \"atlanta.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
633 "Proxy-Authorization: Digest username=\"Betty\", realm = \"fresno.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
634 "Record-Route: <sip:proxy@whistler.gloo.net:5061;lr>\r\n"
635 "Contact: <sip:ext103@192.168.2.220:5068;transport=UDP>\r\n"
636 "Max-Forwards: 69\r\n"
637 "Content-Length: 0\r\n"
638 "Unknown: foobie\r\n"
639 "Unknown: biefoo\r\n"
640 "\r\n");
641
642 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
643 // note message has not been parsed
644
645 message->remove(h_AllowEvents);
646 message->remove(h_Unsupporteds);
647 message->remove(h_To);
648 message->remove(h_From);
649 message->remove(h_Vias);
650 message->remove(h_CallId);
651 message->remove(h_CSeq);
652 message->remove(h_ProxyAuthorizations);
653 message->remove(h_RecordRoutes);
654 message->remove(h_Contacts);
655 message->remove(h_MaxForwards);
656 message->remove(h_ContentLength);
657 message->remove(UnknownHeaderType("Unknown"));
658
659 Data enc;
660 {
661 DataStream str(enc);
662 str << *message;
663 }
664
665 InfoLog (<< enc);
666 assert(enc == ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
667 "Content-Length: 0\r\n"
668 "\r\n"));
669 }
670
671 {
672 // exercise header remove
673 const char* txt = ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
674 "Allow-Events: foo\r\n"
675 "Allow-Events: bar\r\n"
676 "Allow-Events: baz\r\n"
677 "Allow-Events: quux\r\n"
678 "Unsupported: \r\n"
679 "To: <sip:ext101@whistler.gloo.net:5061>\r\n"
680 "From: <sip:ext103@whistler.gloo.net:5061>;tag=a731\r\n"
681 "Via: SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK-c87542-107338443-1--c87542-;stid=489573115\r\n"
682 "Via: SIP/2.0/UDP whistler.gloo.net:5068;branch=z9hG4bK-c87542-489573115-1--c87542-;received=192.168.2.220\r\n"
683 "Call-ID: 643f2f06\r\n"
684 "CSeq: 1 INVITE\r\n"
685 "Proxy-Authorization: Digest username=\"Alice\", realm = \"atlanta.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
686 "Proxy-Authorization: Digest username=\"Betty\", realm = \"fresno.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
687 "Record-Route: <sip:proxy@whistler.gloo.net:5061;lr>\r\n"
688 "Contact: <sip:ext103@192.168.2.220:5068;transport=UDP>\r\n"
689 "Max-Forwards: 69\r\n"
690 "Content-Length: 0\r\n"
691 "Unknown: foobie\r\n"
692 "Unknown: biefoo\r\n"
693 "\r\n");
694
695 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
696
697 message->header(h_AllowEvents).front().value();
698 message->header(h_Unsupporteds).empty();
699 message->header(h_To).uri().user();
700 message->header(h_From);
701 message->header(h_Vias).front();
702 message->header(h_CallId).value();
703 message->header(h_CSeq).sequence();
704 message->header(h_ProxyAuthorizations).size();
705 message->header(h_RecordRoutes).front().uri().host();
706 message->header(h_Contacts).size();
707 message->header(h_MaxForwards).value();
708 message->header(h_ContentLength).value();
709 message->header(UnknownHeaderType("Unknown")).size();
710
711 // note message has been parsed
712 message->remove(h_AllowEvents);
713 message->remove(h_Unsupporteds);
714 message->remove(h_To);
715 message->remove(h_From);
716 message->remove(h_Vias);
717 message->remove(h_CallId);
718 message->remove(h_CSeq);
719 message->remove(h_ProxyAuthorizations);
720 message->remove(h_RecordRoutes);
721 message->remove(h_Contacts);
722 message->remove(h_MaxForwards);
723 message->remove(h_ContentLength);
724 message->remove(UnknownHeaderType("Unknown"));
725
726 // not present
727 message->remove(h_Routes);
728
729 Data enc;
730 {
731 DataStream str(enc);
732 str << *message;
733 }
734
735 assert(enc == ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
736 "Content-Length: 0\r\n"
737 "\r\n"));
738 }
739
740 {
741 // demonstrate comma encoding
742 const char* txt = ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
743 "Allow-Events: foo\r\n"
744 "Allow-Events: bar\r\n"
745 "Allow-Events: baz\r\n"
746 "Allow-Events: quux\r\n"
747 "Unsupported: \r\n"
748 "To: <sip:ext101@whistler.gloo.net:5061>\r\n"
749 "From: <sip:ext103@whistler.gloo.net:5061>;tag=a731\r\n"
750 "Via: SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK-c87542-107338443-1--c87542-;stid=489573115\r\n"
751 "Via: SIP/2.0/UDP whistler.gloo.net:5068;branch=z9hG4bK-c87542-489573115-1--c87542-;received=192.168.2.220\r\n"
752 "Call-ID: 643f2f06\r\n"
753 "CSeq: 1 INVITE\r\n"
754 "Proxy-Authorization: Digest username=\"Alice\", realm = \"atlanta.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
755 "Proxy-Authorization: Digest username=\"Betty\", realm = \"fresno.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
756 "Record-Route: <sip:proxy@whistler.gloo.net:5061;lr>\r\n"
757 "Contact: <sip:ext103@192.168.2.220:5068;transport=UDP>\r\n"
758 "Max-Forwards: 69\r\n"
759 "Content-Length: 0\r\n"
760 "\r\n");
761
762 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
763 assert(message->exists(h_Unsupporteds));
764 resipCerr << message->header(h_AllowEvents).size() << endl;
765 resipCerr << message->header(h_Vias).size() << endl;
766 resipCerr << message->header(h_ProxyAuthorizations).size() << endl;
767 resipCerr << *message << endl;
768 }
769
770 {
771 SipMessage msg;
772 msg.header(h_CallId).value() = "8d057730fba2cd5e";
773
774 resipCerr << msg.header(h_CallId) << endl;
775
776 const SipMessage msg1(msg);
777 resipCerr << msg1.header(h_CallId) << endl;
778 }
779
780 {
781 const char * txt = ("SIP/2.0 489 Bad Event" CRLF
782 "Via: SIP/2.0/UDP RjS.localdomain:5070;branch=z9hG4bK-c87542-899769382-1--c87542-" CRLF
783 "CSeq: " CRLF
784 "Call-ID: f354ce714fb8a95c" CRLF
785 "From: <sip:RjS@127.0.0.1:5070>;tag=59e7dd57" CRLF
786 "To: <sip:RjS@127.0.0.1:5060>" CRLF
787 CRLF);
788 TestSupport::prettyPrint(txt,strlen(txt));
789
790 auto_ptr<SipMessage> response(TestSupport::makeMessage(txt,true));
791 try
792 {
793 response->header(h_CSeq).method();
794 assert(false);
795 }
796 catch (ParseException& e)
797 {
798 resipCerr << e << endl;
799 }
800 }
801
802 {
803 const char * txt = ("SIP/2.0 489 Bad Event" CRLF
804 "Via: SIP/2.0/UDP RjS.localdomain:5070;branch=z9hG4bK-c87542-899769382-1--c87542-" CRLF
805 "CSeq: " CRLF
806 "Call-ID: f354ce714fb8a95c" CRLF
807 "From: <sip:RjS@127.0.0.1:5070>;tag=59e7dd57" CRLF
808 "To: <sip:RjS@127.0.0.1:5060>" CRLF
809 CRLF);
810 TestSupport::prettyPrint(txt,strlen(txt));
811
812 auto_ptr<SipMessage> response(TestSupport::makeMessage(txt,true));
813 try
814 {
815 const SipMessage& constSip(*response);
816 assert(!constSip.header(h_CSeq).isWellFormed());
817 }
818 catch (...)
819 {
820 assert(false);
821 }
822 }
823
824 {
825 const char * txt = ("SIP/2.0 489 Bad Event" CRLF
826 "Via: SIP/2.0/UDP RjS.localdomain:5070;branch=z9hG4bK" RESIP_COOKIE "1---899769382" CRLF
827 "CSeq: 1 SUBSCRIBE" CRLF
828 "Allow-Events: " CRLF
829 "Call-ID: f354ce714fb8a95c" CRLF
830 "From: <sip:RjS@127.0.0.1:5070>;tag=59e7dd57" CRLF
831 "To: <sip:RjS@127.0.0.1:5060>" CRLF
832 CRLF);
833 TestSupport::prettyPrint(txt,strlen(txt));
834
835 auto_ptr<SipMessage> response(TestSupport::makeMessage(txt,true));
836 assert(response->exists(h_AllowEvents));
837 assert(response->header(h_AllowEvents).size() == 0);
838
839 resipCerr << response->brief() << endl;
840 assert(Data::from(response->brief()) == "SipResp: 489 tid=899769382 cseq=1 SUBSCRIBE / 1 from(wire)");
841
842 const char * txt2 = ("SIP/2.0 489 Bad Event" CRLF
843 "Via: SIP/2.0/UDP RjS.localdomain:5070;branch=z9hG4bK" RESIP_COOKIE "1---899769382" CRLF
844 "CSeq: 1 SUBSCRIBE" CRLF
845 "Call-ID: f354ce714fb8a95c" CRLF
846 "From: <sip:RjS@127.0.0.1:5070>;tag=59e7dd57" CRLF
847 "To: <sip:RjS@127.0.0.1:5060>" CRLF
848 "Allow-Events:" CRLF
849 CRLF);
850 TestSupport::prettyPrint(txt2,strlen(txt2));
851
852 auto_ptr<SipMessage> r2(TestSupport::makeMessage(txt2,true));
853 assert(r2->exists(h_AllowEvents));
854 assert(r2->header(h_AllowEvents).size() == 0);
855
856 const char * txt3 =("SIP/2.0 489 Bad Event" CRLF
857 "Via: SIP/2.0/UDP RjS.localdomain:5070;branch=z9hG4bK" RESIP_COOKIE "1---899769382" CRLF
858 "CSeq: 1 SUBSCRIBE" CRLF
859 "Call-ID: f354ce714fb8a95c" CRLF
860 "From: <sip:RjS@127.0.0.1:5070>;tag=59e7dd57" CRLF
861 "To: <sip:RjS@127.0.0.1:5060>" CRLF
862 "Allow-Events: foo" CRLF
863 "Allow-Events: bar" CRLF
864 "Allow-Events: " CRLF
865 CRLF);
866
867 auto_ptr<SipMessage> r3(TestSupport::makeMessage(txt3,false));
868 assert(r3->exists(h_AllowEvents));
869 assert(r3->header(h_AllowEvents).size() == 2);
870 assert(r3->header(h_AllowEvents).front().value() == "foo");
871 resipCerr << r3->brief() << endl;
872 assert(Data::from(r3->brief()) == "SipResp: 489 tid=899769382 cseq=1 SUBSCRIBE / 1 from(tu)");
873
874 const char * txt4 = ("SIP/2.0 489 Bad Event" CRLF
875 "Via: SIP/2.0/UDP RjS.localdomain:5070;branch=z9hG4bK" RESIP_COOKIE "1---899769382" CRLF
876 "CSeq: 1 SUBSCRIBE" CRLF
877 "Call-ID: f354ce714fb8a95c" CRLF
878 "From: <sip:RjS@127.0.0.1:5070>;tag=59e7dd57" CRLF
879 "To: <sip:RjS@127.0.0.1:5060>" CRLF
880 "Allow-Events: foo,foobar" CRLF
881 "Allow-Events: bar,gak" CRLF
882 "Allow-Events: " CRLF
883 CRLF);
884
885 auto_ptr<SipMessage> r4(TestSupport::makeMessage(txt4,true));
886 assert(r4->exists(h_AllowEvents) );
887
888 resipCerr << r4->header(h_AllowEvents).size() << endl;
889 resipCerr << r4->header(h_AllowEvents).front().value() << endl;
890
891 assert(r4->header(h_AllowEvents).size() == 4);
892 assert(r4->header(h_AllowEvents).front().value() == "foo");
893
894
895 const char * txt5 = ("SIP/2.0 489 Bad Event" CRLF
896 "Via: SIP/2.0/UDP RjS.localdomain:5070;branch=z9hG4bK" RESIP_COOKIE "1---899769382" CRLF
897 "CSeq: 1 SUBSCRIBE" CRLF
898 "Call-ID: f354ce714fb8a95c" CRLF
899 "From: <sip:RjS@127.0.0.1:5070>;tag=59e7dd57" CRLF
900 "To: <sip:RjS@127.0.0.1:5060>" CRLF
901 "Allow-Events: " CRLF
902 "Allow-Events: " CRLF
903 "Allow-Events: " CRLF
904 CRLF);
905
906 auto_ptr<SipMessage> r5(TestSupport::makeMessage(txt5,true));
907 assert(r5->exists(h_AllowEvents) );
908 assert(r5->header(h_AllowEvents).size() == 0);
909 }
910
911 {
912 // Test just in time parsing with comparison: NameAddr;
913 const char* txt = ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
914 "To: <sip:ext101@whistler.gloo.net:5061>\r\n"
915 "From: <sip:ext103@whistler.gloo.net:5061>;tag=a731\r\n"
916 "Via: SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK" RESIP_COOKIE "1-client_data--11111;stid=489573115\r\n"
917 "Call-ID: 643f2f06\r\n"
918 "CSeq: 1 INVITE\r\n"
919 "Record-Route: <sip:proxy@whistler.gloo.net:5061;lr>\r\n"
920 "Contact: <sip:ext103@192.168.2.220:5068;transport=UDP>\r\n"
921 "Max-Forwards: 69\r\n"
922 "Accept: foo/bar\r\n"
923 "Content-Type: bar/foo\r\n"
924 "Content-Encoding: foo\r\n"
925 "Content-Disposition: bar\r\n"
926 "Content-Length: 0\r\n"
927 "\r\n");
928
929 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
930
931 assert(message->header(h_ContentDisposition) < message->header(h_ContentEncoding));
932 assert(message->header(h_ContentType) < message->header(h_Accepts).front());
933 assert(message->header(h_To) < message->header(h_From));
934
935 resipCerr << message->brief() << endl;
936 assert(Data::from(message->brief()) == "SipReq: INVITE ext101@192.168.2.220:5064 tid=11111 cseq=1 INVITE contact=ext103@192.168.2.220:5068 / 1 from(tu)");
937 }
938
939 {
940 resipCerr << "!Proxy-Authorization params" << endl;
941 const char* txt = ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
942 "To: <sip:ext101@whistler.gloo.net:5061>\r\n"
943 "From: <sip:ext103@whistler.gloo.net:5061>;tag=a731\r\n"
944 "Via: SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK" RESIP_COOKIE "1---563465;stid=489573115\r\n"
945 "Via: SIP/2.0/UDP whistler.gloo.net:5068;branch=z9hG4bK" RESIP_COOKIE "1---489573115;received=192.168.2.220\r\n"
946 "Call-ID: 643f2f06\r\n"
947 "CSeq: 1 INVITE\r\n"
948 "Proxy-Authorization: Digest username=\"Alice\",realm=\"atlanta.com\",nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
949 "Proxy-Authorization: Digest username=\"Alice\", realm = \"atlanta.com\", nonce=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\", response=\"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\"\r\n"
950 "Record-Route: <sip:proxy@whistler.gloo.net:5061;lr>\r\n"
951 "Contact: <sip:ext103@192.168.2.220:5068;transport=UDP>\r\n"
952 "Max-Forwards: 69\r\n"
953 "Content-Length: 0\r\n"
954 "\r\n");
955
956 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
957
958 assert(message->header(h_ProxyAuthorizations).size() == 2);
959 assert(message->header(h_ProxyAuthorizations).front().param(p_realm) == "atlanta.com");
960 assert(message->header(h_ProxyAuthorizations).front().param(p_response) == "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY");
961
962 resipCerr << *message << endl;
963 }
964
965 {
966 const char* txt = ("INVITE sip:ext101@192.168.2.220:5064;transport=UDP SIP/2.0\r\n"
967 "To: <sip:ext101@whistler.gloo.net:5061>\r\n"
968 "From: <sip:ext103@whistler.gloo.net:5061>;tag=a731\r\n"
969 "Via: SIP/2.0/UDP whistler.gloo.net:5061;branch=z9hG4bK" RESIP_COOKIE "1---21312;stid=489573115\r\n"
970 "Via: SIP/2.0/UDP whistler.gloo.net:5068;branch=z9hG4bK" RESIP_COOKIE "1---489573115;received=192.168.2.220\r\n"
971 "Call-ID: 643f2f06\r\n"
972 "CSeq: 1 INVITE\r\n"
973 "Record-Route: <sip:proxy@whistler.gloo.net:5061;lr>\r\n"
974 "Contact: <sip:ext103@192.168.2.220:5068;transport=UDP>\r\n"
975 "Max-Forwards: 69\r\n"
976 "Content-Length: 0\r\n"
977 "\r\n");
978
979 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
980 resipCerr << *message << endl;
981
982 assert(message->header(h_Vias).front().param(UnknownParameterType("stid")) == "489573115");
983 message->header(h_Vias).front().param(p_received) = "received";
984 assert(message->header(h_Vias).front().param(UnknownParameterType("stid")) == "489573115");
985 }
986
987 {
988 const char* txt = ("SIP/2.0 200 OK""\r\n"
989 "From: 1245<sip:4000@193.12.63.124:5060>;tag=7c3f0cc1-13c4-3e5a380c-1ac5646-257e""\r\n"
990 "To: prolab<sip:5000@host2.sipdragon.sipit.net>;tag=7c3f0cc1-13c5-3e5a380d-1ac5827-618f""\r\n"
991 "Call-ID: 9e9017c-7c3f0cc1-13c4-3e5a380c-1ac5646-3700@193.12.63.124""\r\n"
992 "CSeq: 1 INVITE""\r\n"
993 "Via: SIP/2.0/UDP host2.sipdragon.sipit.net;received=193.12.62.209;branch=z9hG4bK-3e5a380c-1ac5646-adf1-1""\r\n"
994 "Via: SIP/2.0/UDP 193.12.63.124:5060;received=193.12.63.124;branch=z9hG4bK-3e5a380c-1ac5646-adf""\r\n"
995 "Contact: <sip:5000@193.12.63.124:5061>""\r\n"
996 "Record-Route: <sip:proxy@host2.sipdragon.sipit.net:5060;lr>""\r\n"
997 "Content-Length:0\r\n\r\n");
998
999
1000 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1001 resipCerr << *message << endl;
1002 message->header(h_Vias).front();
1003 message->header(h_From);
1004 message->header(h_To);
1005 resipCerr << message->header(h_Vias).front().param(p_branch).getTransactionId() << endl;
1006 resipCerr << message->header(h_Vias).back().param(p_branch).getTransactionId() << endl;
1007 }
1008
1009 {
1010 const char *txt = ("SIP/2.0 200 OK\r\n"
1011 "From: 1245<sip:4000@193.12.63.124:5060>;tag=7c3f0cc1-13c4-3e5a380c-1ac5646-257e\r\n"
1012 "To: prolab<sip:5000@host2.sipdragon.sipit.net>;tag=7c3f0cc1-13c5-3e5a380d-1ac5827-618f\r\n"
1013 "Call-ID: 9e9017c-7c3f0cc1-13c4-3e5a380c-1ac5646-3700@193.12.63.124\r\n"
1014 "CSeq: 1 INVITE\r\n"
1015 "Via: SIP/2.0/UDP host2.sipdragon.sipit.net;received=193.12.62.209;branch=z9hG4bK-3e5a380c-1ac5646-adf1-1\r\n"
1016 "Via: SIP/2.0/UDP 193.12.63.124:5060;received=193.12.63.124;branch=z9hG4bK-3e5a380c-1ac5646-adf\r\n"
1017 "Contact: <sip:5000@193.12.63.124:5061>\r\n"
1018 "Record-Route: <sip:proxy@host2.sipdragon.sipit.net:5060;lr>\r\n"
1019 "Content-Length:0\r\n\r\n");
1020
1021 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1022 assert(message.get());
1023 for (Vias::iterator i = message->header(h_Vias).begin();
1024 i != message->header(h_Vias).end(); i++)
1025 {
1026 i->param(p_branch).encode(resipCerr);
1027 resipCerr << endl;
1028 }
1029 }
1030
1031 {
1032 const char* txt = ("SIP/2.0 200 OK""\r\n"
1033 "From: 1245<sip:4000@193.12.63.124:5060>;tag=7c3f0cc1-13c4-3e5a380c-1ac5646-257e""\r\n"
1034 "To: prolab<sip:5000@host2.sipdragon.sipit.net>;tag=7c3f0cc1-13c5-3e5a380d-1ac5827-618f""\r\n"
1035 "Call-ID: 9e9017c-7c3f0cc1-13c4-3e5a380c-1ac5646-3700@193.12.63.124""\r\n"
1036 "CSeq: 1 INVITE""\r\n"
1037 "Via: SIP/2.0/UDP host2.sipdragon.sipit.net;received=193.12.62.209;branch=z9hG4bK-3e5a380c-1ac5646-adf1-1""\r\n"
1038 "Via: SIP/2.0/UDP 193.12.63.124:5060;received=193.12.63.124;branch=z9hG4bK-3e5a380c-1ac5646-adf""\r\n"
1039 "Contact: <sip:5000@193.12.63.124:5061>""\r\n"
1040 "Record-Route: <sip:proxy@host2.sipdragon.sipit.net:5060;lr>""\r\n"
1041 "Content-Length:0\r\n\r\n");
1042
1043
1044 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1045 resipCerr << *message << endl;
1046 message->header(h_Vias).front();
1047 message->header(h_From);
1048 message->header(h_To);
1049 resipCerr << message->header(h_Vias).front() << endl;
1050 resipCerr << message->header(h_Vias).back() << endl;
1051 resipCerr << message->header(h_Vias).front().param(p_branch).getTransactionId() << endl;
1052 resipCerr << message->header(h_Vias).back().param(p_branch).getTransactionId() << endl;
1053 }
1054
1055 {
1056 const char *txt = ("To: <sip:106@kelowna.gloo.net>"
1057 "From: <sip:106@kelowna.gloo.net>;tag=18c7b33a-430c-429c-9f46-e5b509264519\r\n"
1058 "Via: SIP/2.0/UDP 192.168.2.15:10276;received=192.168.2.15\r\n"
1059 "Call-ID: cb15283c-6efb-452e-aef2-5e44e02e2440@192.168.2.15\r\n"
1060 "CSeq: 2 REGISTER\r\n"
1061 "Contact: <sip:192.168.2.15:10276>;xmethods=\"INVITE, MESSAGE, INFO, SUBSCRIBE, OPTIONS, BYE, CANCEL, NOTIFY, ACK\"\r\n"
1062 "Expires: 0\r\n"
1063 "User-Agent: Windows RTC/1.0\r\n"
1064 "Content-Length: 0\r\n"
1065 "\r\n");
1066 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1067 resipCerr << message->header(h_Contacts).front().param(UnknownParameterType("xmethods")) << endl;
1068 resipCerr << *message << endl;
1069 }
1070
1071 {
1072 Data txt1("INVITE sip:bob@biloxi.com SIP/2.0\r\n"
1073 "Via: SIP/2.0/UDP pc33.atlanta.com\r\n"
1074 "To: Bob <sip:bob@biloxi.com>\r\n"
1075 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1076 "Call-ID: a84b4c76e66710\r\n"
1077 "CSeq: 314159 INVITE\r\n"
1078 "Max-Forwards: 70\r\n"
1079 "Foobie-Blech: it is not a glass paperweight\r\n"
1080 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1081 "Content-Length: 0\r\n"
1082 "\r\n");
1083
1084 Data txt2("INVITE sip:joe@biloxi.com SIP/2.0\r\n"
1085 "Via: SIP/2.0/UDP pc33.atlanta.com\r\n"
1086 "To: Bob <sip:bob@biloxi.com>\r\n"
1087 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1088 "Call-ID: a84b4c76e66710\r\n"
1089 "CSeq: 314159 INVITE\r\n"
1090 "Max-Forwards: 70\r\n"
1091 "Foobie-Blech: it is not a glass paperweight\r\n"
1092 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1093 "Content-Length: 0\r\n"
1094 "\r\n");
1095
1096 Data txt3("INVITE sip:bob@biloxi.com;user=phone SIP/2.0\r\n"
1097 "Via: SIP/2.0/UDP pc33.atlanta.com\r\n"
1098 "To: Bob <sip:bob@biloxi.com>\r\n"
1099 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1100 "Call-ID: a84b4c76e66710\r\n"
1101 "CSeq: 314159 INVITE\r\n"
1102 "Max-Forwards: 70\r\n"
1103 "Foobie-Blech: it is not a glass paperweight\r\n"
1104 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1105 "Content-Length: 0\r\n"
1106 "\r\n");
1107
1108 Data txt4("INVITE sip:bob@biloxi.com;user=phone;lr SIP/2.0\r\n"
1109 "Via: SIP/2.0/UDP pc33.atlanta.com\r\n"
1110 "To: Bob <sip:bob@biloxi.com>\r\n"
1111 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1112 "Call-ID: a84b4c76e66710\r\n"
1113 "CSeq: 314159 INVITE\r\n"
1114 "Max-Forwards: 70\r\n"
1115 "Foobie-Blech: it is not a glass paperweight\r\n"
1116 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1117 "Content-Length: 0\r\n"
1118 "\r\n");
1119
1120 Data txt5("INVITE sip:bob@biloxi.com;user=phone;lr;maddr=192.168.1.1 SIP/2.0\r\n"
1121 "Via: SIP/2.0/UDP pc33.atlanta.com\r\n"
1122 "To: Bob <sip:bob@biloxi.com>\r\n"
1123 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1124 "Call-ID: a84b4c76e66710\r\n"
1125 "CSeq: 314159 INVITE\r\n"
1126 "Max-Forwards: 70\r\n"
1127 "Foobie-Blech: it is not a glass paperweight\r\n"
1128 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1129 "Content-Length: 0\r\n"
1130 "\r\n");
1131
1132 Data txt6("INVITE sip:bob@biloxi.com;maddr=192.168.1.1;user=phone SIP/2.0\r\n"
1133 "Via: SIP/2.0/UDP pc33.atlanta.com\r\n"
1134 "To: Bob <sip:bob@biloxi.com>\r\n"
1135 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1136 "Call-ID: a84b4c76e66710\r\n"
1137 "CSeq: 314159 INVITE\r\n"
1138 "Max-Forwards: 70\r\n"
1139 "Foobie-Blech: it is not a glass paperweight\r\n"
1140 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1141 "Content-Length: 0\r\n"
1142 "\r\n");
1143
1144 Data txt7("INVITE sip:bob@biloxi.com;maddr=192.168.1.1;user=phone;jason=foo SIP/2.0\r\n"
1145 "Via: SIP/2.0/UDP pc33.atlanta.com\r\n"
1146 "To: Bob <sip:bob@biloxi.com>\r\n"
1147 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1148 "Call-ID: a84b4c76e66710\r\n"
1149 "CSeq: 314159 INVITE\r\n"
1150 "Max-Forwards: 70\r\n"
1151 "Foobie-Blech: it is not a glass paperweight\r\n"
1152 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1153 "Content-Length: 0\r\n"
1154 "\r\n");
1155
1156 Data txt8("INVITE sip:bob@biloxi.com;maddr=192.168.1.1;lr;jason=foo;user=phone SIP/2.0\r\n"
1157 "Via: SIP/2.0/UDP pc33.atlanta.com\r\n"
1158 "To: Bob <sip:bob@biloxi.com>\r\n"
1159 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1160 "Call-ID: a84b4c76e66710\r\n"
1161 "CSeq: 314159 INVITE\r\n"
1162 "Max-Forwards: 70\r\n"
1163 "Foobie-Blech: it is not a glass paperweight\r\n"
1164 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1165 "Content-Length: 0\r\n"
1166 "\r\n");
1167
1168 Data txt9("INVITE sip:bob@biloxi.com;maddr=192.168.1.1;lr;jason=foo;user=phone SIP/2.0\r\n"
1169 "Via: SIP/2.0/UDP pc33.atlanta.com; branch=foobar\r\n"
1170 "To: Bob <sip:bob@biloxi.com>\r\n"
1171 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1172 "Call-ID: a84b4c76e66710\r\n"
1173 "CSeq: 314159 INVITE\r\n"
1174 "Max-Forwards: 70\r\n"
1175 "Foobie-Blech: it is not a glass paperweight\r\n"
1176 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1177 "Content-Length: 0\r\n"
1178 "\r\n");
1179
1180 Data txt10("INVITE sip:bob@biloxi.com;maddr=192.168.1.1;lr;jason=foo;user=phone SIP/2.0\r\n"
1181 "Via: SIP/2.0/UDP pc33.atlanta.com; branch=foobar\r\n"
1182 "To: Bob <sip:bob@biloxi.com>\r\n"
1183 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1184 "Call-ID: a84b4c76e66710\r\n"
1185 "CSeq: 314158 INVITE\r\n"
1186 "Max-Forwards: 70\r\n"
1187 "Foobie-Blech: it is not a glass paperweight\r\n"
1188 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1189 "Content-Length: 0\r\n"
1190 "\r\n");
1191
1192 Data txt11("INVITE sip:bob@biloxi.com;maddr=192.168.1.1;lr;jason=foo;user=phone SIP/2.0\r\n"
1193 "Via: SIP/2.0/UDP pc33.atlanta.com; branch=foobar\r\n"
1194 "To: Bob <sip:bob@biloxi.com>\r\n"
1195 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1196 "Call-ID: a84b4c76e66710\r\n"
1197 "CSeq: 314158 INVITE\r\n"
1198 "Max-Forwards: 73\r\n"
1199 "Foobie-Blech: it is not a glass paperweight\r\n"
1200 "Contact: <sip:alice@pc.atlanta.com>\r\n"
1201 "Content-Length: 0\r\n"
1202 "\r\n");
1203
1204
1205 auto_ptr<SipMessage> msg1(TestSupport::makeMessage(txt1));
1206 auto_ptr<SipMessage> msg2(TestSupport::makeMessage(txt2));
1207 auto_ptr<SipMessage> msg3(TestSupport::makeMessage(txt3));
1208 auto_ptr<SipMessage> msg4(TestSupport::makeMessage(txt4));
1209 auto_ptr<SipMessage> msg5(TestSupport::makeMessage(txt5));
1210 auto_ptr<SipMessage> msg6(TestSupport::makeMessage(txt6));
1211 auto_ptr<SipMessage> msg7(TestSupport::makeMessage(txt7));
1212 auto_ptr<SipMessage> msg8(TestSupport::makeMessage(txt8));
1213 auto_ptr<SipMessage> msg9(TestSupport::makeMessage(txt9));
1214 auto_ptr<SipMessage> msg10(TestSupport::makeMessage(txt10));
1215 auto_ptr<SipMessage> msg11(TestSupport::makeMessage(txt11));
1216
1217 assert(msg1->getTransactionId() == msg1->getTransactionId());
1218 resipCerr << "msg2=" << msg2->getTransactionId() << endl;
1219 resipCerr << "msg3=" << msg3->getTransactionId() << endl;
1220 assert(msg2->getTransactionId() != msg3->getTransactionId());
1221 assert(msg3->getTransactionId() == msg4->getTransactionId());
1222 assert(msg4->getTransactionId() != msg5->getTransactionId());
1223 assert(msg4->getTransactionId() != msg6->getTransactionId());
1224
1225 resipCerr << "msg5=" << msg5->getTransactionId() << endl;
1226 resipCerr << "msg6=" << msg6->getTransactionId() << endl;
1227 assert(msg5->header(h_RequestLine).uri() == msg6->header(h_RequestLine).uri());
1228 assert(msg5->header(h_RequestLine).uri().commutativeParameterHash() == msg6->header(h_RequestLine).uri().commutativeParameterHash());
1229
1230 assert(msg5->getTransactionId() == msg6->getTransactionId());
1231 assert(msg7->getTransactionId() == msg8->getTransactionId());
1232 assert(msg6->getTransactionId() != msg8->getTransactionId());
1233 assert(msg8->getTransactionId() != msg9->getTransactionId());
1234 assert(msg9->getTransactionId() != msg10->getTransactionId());
1235 assert(msg10->getTransactionId() == msg11->getTransactionId());
1236 }
1237
1238 {
1239 SipMessage inv;
1240
1241 UnknownHeaderType h_Foo("foo");
1242 UnknownHeaderType h_Bar("bar");
1243
1244 inv.header(h_Foo);
1245 inv.header(h_Bar).push_back(StringCategory("bar1"));
1246 inv.header(h_Bar).push_back(StringCategory("bar2"));
1247
1248 inv.header(h_To);
1249
1250 inv.header(h_RequestLine) = RequestLine(INVITE);
1251 inv.header(h_RequestLine).uri() = Uri("sip:bob@biloxi.com");
1252 inv.header(h_To) = NameAddr("sip:bob@biloxi.com");
1253 inv.header(h_From) = NameAddr("Alice <sip:alice@atlanta.com>;tag=1928301774");
1254 inv.header(h_CallId).value() = "314159";
1255 inv.header(h_CSeq).sequence() = 14;
1256 inv.header(h_CSeq).method() = INVITE;
1257
1258 PlainContents pc("here is some plain ol' contents");
1259 inv.setContents(&pc);
1260
1261 resipCerr << inv.header(h_ContentType).type() << endl;
1262 assert(inv.header(h_ContentType).type() == "text");
1263 assert(inv.header(h_ContentType).subType() == "plain");
1264
1265 assert(!inv.exists(h_ContentLength));
1266
1267 assert(inv.getContents());
1268 assert(dynamic_cast<PlainContents*>(inv.getContents()));
1269 assert(dynamic_cast<PlainContents*>(inv.getContents())->text() == "here is some plain ol' contents");
1270
1271 const Data d(Data::from(inv));
1272
1273 resipCerr << "!! " << d;
1274 assert(d == ("INVITE sip:bob@biloxi.com SIP/2.0\r\n"
1275 "To: <sip:bob@biloxi.com>\r\n"
1276 "From: \"Alice\"<sip:alice@atlanta.com>;tag=1928301774\r\n"
1277 "Call-ID: 314159\r\n"
1278 "CSeq: 14 INVITE\r\n"
1279 "Content-Type: text/plain\r\n"
1280 "bar: bar1\r\n"
1281 "bar: bar2\r\n"
1282 "Content-Length: 31\r\n"
1283 "\r\n"
1284 "here is some plain ol' contents"));
1285 }
1286
1287 {
1288 SipMessage inv;
1289
1290 UnknownHeaderType h_Foo("foo");
1291 UnknownHeaderType h_Bar("bar");
1292
1293 inv.header(h_Foo);
1294 inv.header(h_Bar).push_back(StringCategory("bar1"));
1295 inv.header(h_Bar).push_back(StringCategory("bar2"));
1296
1297 //inv.header(h_Vias);
1298 inv.header(h_To);
1299
1300 inv.header(h_RequestLine) = RequestLine(INVITE);
1301 inv.header(h_RequestLine).uri() = Uri("sip:bob@biloxi.com");
1302 inv.header(h_To) = NameAddr("sip:bob@biloxi.com");
1303 inv.header(h_From) = NameAddr("Alice <sip:alice@atlanta.com>;tag=1928301774");
1304 inv.header(h_CallId).value() = "314159";
1305 inv.header(h_CSeq).sequence() = 14;
1306 inv.header(h_CSeq).method() = INVITE;
1307
1308 auto_ptr<Contents> pc(new PlainContents("here is some plain ol' contents"));
1309 inv.setContents(pc);
1310
1311 resipCerr << inv.header(h_ContentType).type() << endl;
1312 assert(inv.header(h_ContentType).type() == "text");
1313 assert(inv.header(h_ContentType).subType() == "plain");
1314
1315 assert(!inv.exists(h_ContentLength));
1316
1317 assert(inv.getContents());
1318 assert(dynamic_cast<PlainContents*>(inv.getContents()));
1319 assert(dynamic_cast<PlainContents*>(inv.getContents())->text() == "here is some plain ol' contents");
1320
1321 Data d;
1322 {
1323 DataStream s(d);
1324 inv.encode(s);
1325 }
1326
1327 resipCerr << "!! " << d;
1328 assert(d == ("INVITE sip:bob@biloxi.com SIP/2.0\r\n"
1329 "To: <sip:bob@biloxi.com>\r\n"
1330 "From: \"Alice\"<sip:alice@atlanta.com>;tag=1928301774\r\n"
1331 "Call-ID: 314159\r\n"
1332 "CSeq: 14 INVITE\r\n"
1333 "Content-Type: text/plain\r\n"
1334 // "foo: \r\n"
1335 "bar: bar1\r\n"
1336 "bar: bar2\r\n"
1337 "Content-Length: 31\r\n"
1338 "\r\n"
1339 "here is some plain ol' contents"));
1340 }
1341
1342 {
1343 Data txt("INVITE sip:bob@biloxi.com SIP/2.0\r\n"
1344 "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\r\n"
1345 "To: \"Bob\"<sip:bob@biloxi.com>\r\n"
1346 "From: \"Alice\"<sip:alice@atlanta.com>;tag=1928301774\r\n"
1347 "Call-ID: a84b4c76e66710\r\n"
1348 "CSeq: 314159 INVITE\r\n"
1349 "Max-Forwards: 70\r\n"
1350 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1351 "Content-Type: application/sdp\r\n"
1352 "Content-Length: 150\r\n"
1353 "\r\n"
1354 "v=0\r\n"
1355 "o=alice 53655765 2353687637 IN IP4 pc33.atlanta.com\r\n"
1356 "s=-\r\n"
1357 "c=IN IP4 pc33.atlanta.com\r\n"
1358 "t=0 0\r\n"
1359 "m=audio 3456 RTP/AVP 0 1 3 99\r\n"
1360 "a=rtpmap:0 PCMU/8000\r\n");
1361
1362 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
1363
1364 assert(msg->exists(h_ContentType));
1365 assert(msg->exists(h_ContentLength));
1366 assert(msg->header(h_ContentLength).value() == 150);
1367
1368 Contents* body = msg->getContents();
1369
1370 assert(body != 0);
1371 SdpContents* sdp = dynamic_cast<SdpContents*>(body);
1372 assert(sdp != 0);
1373
1374 assert(sdp->session().version() == 0);
1375 assert(sdp->session().origin().user() == "alice");
1376 assert(!sdp->session().media().empty());
1377 assert(sdp->session().media().front().getValues("rtpmap").front() == "0 PCMU/8000");
1378
1379 msg->encode(resipCerr);
1380 }
1381
1382 {
1383 InfoLog(<< "Test SipMessage::releaseContents; no contents");
1384
1385 SipMessage msg;
1386 assert(msg.getContents() == 0);
1387 auto_ptr<Contents> old = msg.releaseContents();
1388 assert(old.get() == 0);
1389 assert(msg.getContents() == 0);
1390 }
1391
1392 {
1393 Data txt("INVITE sip:bob@biloxi.com SIP/2.0\r\n"
1394 "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\r\n"
1395 "To: Bob <sip:bob@biloxi.com>\r\n"
1396 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1397 "Call-ID: a84b4c76e66710\r\n"
1398 "CSeq: 314159 INVITE\r\n"
1399 "Max-Forwards: 70\r\n"
1400 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1401 "Content-Type: application/sdp\r\n"
1402 "Content-Length: 150\r\n"
1403 "\r\n"
1404 "v=0\r\n"
1405 "o=alice 53655765 2353687637 IN IP4 pc33.atlanta.com\r\n"
1406 "s=-\r\n"
1407 "c=IN IP4 pc33.atlanta.com\r\n"
1408 "t=0 0\r\n"
1409 "m=audio 3456 RTP/AVP 0 1 3 99\r\n"
1410 "a=rtpmap:0 PCMU/8000\r\n");
1411
1412 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
1413
1414 assert(msg->exists(h_ContentType));
1415 auto_ptr<Contents> abody = msg->releaseContents();
1416 Contents* body = abody.release();
1417
1418 assert(body != 0);
1419 SdpContents* sdp = dynamic_cast<SdpContents*>(body);
1420 assert(sdp != 0);
1421
1422 assert(sdp->session().version() == 0);
1423 assert(sdp->session().origin().user() == "alice");
1424 assert(!sdp->session().media().empty());
1425 assert(sdp->session().media().front().getValues("rtpmap").front() == "0 PCMU/8000");
1426
1427 delete sdp;
1428
1429 assert(msg->getContents() == 0);
1430 }
1431
1432 {
1433 Data txt("INVITE sip:bob@biloxi.com SIP/2.0\r\n"
1434 "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\r\n"
1435 "To: Bob <sip:bob@biloxi.com>\r\n"
1436 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1437 "Call-ID: a84b4c76e66710\r\n"
1438 "CSeq: 314159 INVITE\r\n"
1439 "Max-Forwards: 70\r\n"
1440 "Foobie-Blech: it is not a glass paperweight\r\n"
1441 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1442 "Content-Type: application/sdp\r\n"
1443 "Content-Length: 150\r\n"
1444 "\r\n"
1445 "v=0\r\n"
1446 "o=alice 53655765 2353687637 IN IP4 pc33.atlanta.com\r\n"
1447 "s=-\r\n"
1448 "c=IN IP4 pc33.atlanta.com\r\n"
1449 "t=0 0\r\n"
1450 "m=audio 3456 RTP/AVP 0 1 3 99\r\n"
1451 "a=rtpmap:0 PCMU/8000\r\n");
1452
1453 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
1454
1455 assert(!msg->header(UnknownHeaderType("Foobie-Blech")).empty());
1456 assert(msg->header(UnknownHeaderType("Foobie-Blech")).front().value() == "it is not a glass paperweight");
1457
1458 Contents* body = msg->getContents();
1459
1460 assert(body != 0);
1461 SdpContents* sdp = dynamic_cast<SdpContents*>(body);
1462 assert(sdp != 0);
1463
1464 assert(sdp->session().version() == 0);
1465 assert(sdp->session().origin().user() == "alice");
1466 assert(!sdp->session().media().empty());
1467 assert(sdp->session().media().front().getValues("rtpmap").front() == "0 PCMU/8000");
1468
1469 msg->encode(resipCerr);
1470 }
1471
1472 {
1473 Data txt("INVITE sip:bob@biloxi.com SIP/2.0\r\n"
1474 "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\r\n"
1475 "To: Bob <sip:bob@biloxi.com>\r\n"
1476 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
1477 "Call-ID: a84b4c76e66710\r\n"
1478 "CSeq: 314159 INVITE\r\n"
1479 "Max-Forwards: 70\r\n"
1480 "Foobie-Blech: \r\n"
1481 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
1482 "Content-Type: application/sdp\r\n"
1483 "Content-Length: 150\r\n"
1484 "\r\n"
1485 "v=0\r\n"
1486 "o=alice 53655765 2353687637 IN IP4 pc33.atlanta.com\r\n"
1487 "s=-\r\n"
1488 "c=IN IP4 pc33.atlanta.com\r\n"
1489 "t=0 0\r\n"
1490 "m=audio 3456 RTP/AVP 0 1 3 99\r\n"
1491 "a=rtpmap:0 PCMU/8000\r\n");
1492
1493 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
1494
1495 msg->header(UnknownHeaderType("Foobie-Blech")).empty();
1496 //assert(!msg->header(UnknownHeaderType("Foobie-Blech")).empty());
1497 //assert(msg->header(UnknownHeaderType("Foobie-Blech")).front().value() == "");
1498 msg->encode(resipCerr);
1499 }
1500
1501 {
1502 const char* b = "shared buffer";
1503 HeaderFieldValue h1(b, strlen(b));
1504 HeaderFieldValue h2(h1);
1505 }
1506
1507 {
1508 const char *txt =
1509 ("SIP/2.0 200\r\n"
1510 "To: <sip:ext102@squamish.gloo.net:5060>;tag=8be36d98\r\n"
1511 "From: <sip:ext102@squamish.gloo.net:5060>;tag=38810b6d\r\n"
1512 "Call-ID: a6aea86d75a6bb45\r\n"
1513 "CSeq: 2 REGISTER\r\n"
1514 "Contact: <sip:ext102@whistler.gloo.net:6064>;expires=63\r\n"
1515 "Via: SIP/2.0/UDP whistler.gloo.net:6064;rport=6064;received=192.168.2.220;branch=z9hG4bK-kcD23-4-1\r\n"
1516 "Content-Length: 0\r\n"
1517 "\r\n");
1518
1519 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt));
1520 resipCerr << msg->header(h_Contacts).front().param(p_expires) << endl;
1521 assert(msg->header(h_Contacts).front().param(p_expires) == 63);
1522 }
1523
1524 {
1525 resipCerr << "test backward compatible expires parameter" << endl;
1526 const char *txt1 = ("REGISTER sip:registrar.biloxi.com SIP/2.0\r\n"
1527 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=first\r\n"
1528 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=second\r\n"
1529 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=third\r\n"
1530 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=fourth\r\n"
1531 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=fifth\r\n"
1532 "Max-Forwards: 70\r\n"
1533 "To: Bob <sip:bob@biloxi.com>\r\n"
1534 "From: Bob <sip:bob@biloxi.com>;tag=456248\r\n"
1535 "Call-ID: 843817637684230@998sdasdh09\r\n"
1536 "CSeq: 1826 REGISTER\r\n"
1537 "Contact: <sip:bob@192.0.2.4>;expires=\"Sat, 01 Dec 2040 16:00:00 GMT\";foo=bar\r\n"
1538 "Contact: <sip:qoq@192.0.2.4>\r\n"
1539 "Content-Length: 0\r\n\r\n");
1540 auto_ptr<SipMessage> message1(TestSupport::makeMessage(txt1));
1541 resipCerr << message1->header(h_Contacts).front().param(p_expires) << endl;
1542 assert(message1->header(h_Contacts).front().param(p_expires) == 3600);
1543 assert(message1->header(h_Contacts).front().param(UnknownParameterType("foo")) == "bar");
1544 }
1545
1546 {
1547 resipCerr << "test header copying between unparsed messages" << endl;
1548 const char *txt1 = ("REGISTER sip:registrar.biloxi.com SIP/2.0\r\n"
1549 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=first\r\n"
1550 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=second\r\n"
1551 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=third\r\n"
1552 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=fourth\r\n"
1553 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=fifth\r\n"
1554 "Max-Forwards: 70\r\n"
1555 "To: Bob <sip:bob@biloxi.com>\r\n"
1556 "From: Bob <sip:bob@biloxi.com>;tag=456248\r\n"
1557 "Call-ID: 843817637684230@998sdasdh09\r\n"
1558 "CSeq: 1826 REGISTER\r\n"
1559 "Contact: <sip:bob@192.0.2.4>\r\n"
1560 "Contact: <sip:qoq@192.0.2.4>\r\n"
1561 "Expires: 7200\r\n"
1562 "Content-Length: 0\r\n\r\n");
1563 auto_ptr<SipMessage> message1(TestSupport::makeMessage(txt1));
1564 auto_ptr<SipMessage> r(Helper::makeResponse(*message1, 100));
1565 r->encode(resipCerr);
1566
1567 const char *txt2 = ("REGISTER sip:registrar.ixolib.com SIP/2.0\r\n"
1568 "Via: SIP/2.0/UDP speedyspc.biloxi.com:5060;branch=sfirst\r\n"
1569 "Via: SIP/2.0/UDP speedyspc.biloxi.com:5060;branch=ssecond\r\n"
1570 "Via: SIP/2.0/UDP speedyspc.biloxi.com:5060;branch=sthird\r\n"
1571 "Via: SIP/2.0/UDP speedyspc.biloxi.com:5060;branch=sfourth\r\n"
1572 "Max-Forwards: 7\r\n"
1573 "To: Speedy <sip:speedy@biloxi.com>\r\n"
1574 "From: Speedy <sip:speedy@biloxi.com>;tag=88888\r\n"
1575 "Call-ID: 88888@8888\r\n"
1576 "CSeq: 6281 REGISTER\r\n"
1577 "Contact: <sip:speedy@192.0.2.4>\r\n"
1578 "Contact: <sip:qoq@192.0.2.4>\r\n"
1579 "Expires: 2700\r\n"
1580 "Content-Length: 0\r\n\r\n");
1581 auto_ptr<SipMessage> message2(TestSupport::makeMessage(txt2));
1582
1583 // copy over everything
1584 message1->header(h_RequestLine) = message2->header(h_RequestLine);
1585 message1->header(h_Vias) = message2->header(h_Vias);
1586 message1->header(h_MaxForwards) = message2->header(h_MaxForwards);
1587 message1->header(h_To) = message2->header(h_To);
1588 message1->header(h_From) = message2->header(h_From);
1589 message1->header(h_CallId) = message2->header(h_CallId);
1590 message1->header(h_CSeq) = message2->header(h_CSeq);
1591 message1->header(h_Contacts) = message2->header(h_Contacts);
1592 message1->header(h_Expires) = message2->header(h_Expires);
1593 message1->header(h_ContentLength) = message2->header(h_ContentLength);
1594
1595 assert(message1->header(h_To).uri().user() == "speedy");
1596 assert(message1->header(h_From).uri().user() == "speedy");
1597 assert(message1->header(h_MaxForwards).value() == 7);
1598 assert(message1->header(h_Contacts).empty() == false);
1599 assert(message1->header(h_CallId).value() == "88888@8888");
1600 assert(message1->header(h_CSeq).sequence() == 6281);
1601 assert(message1->header(h_CSeq).method() == REGISTER);
1602 assert(message1->header(h_Vias).empty() == false);
1603 assert(message1->header(h_Vias).size() == 4);
1604 assert(message1->header(h_Expires).value() == 2700);
1605 assert(message1->header(h_ContentLength).value() == 0);
1606 resipCerr << "Port: " << message1->header(h_RequestLine).uri().port() << endl;
1607 resipCerr << "AOR: " << message1->header(h_RequestLine).uri().getAor() << endl;
1608 assert(message1->header(h_RequestLine).uri().getAor() == "registrar.ixolib.com");
1609 }
1610
1611 {
1612 resipCerr << "test header copying between parsed messages" << endl;
1613 resipCerr << " should NOT COPY any HeaderFieldValues" << endl;
1614 const char *txt1 = ("REGISTER sip:registrar.biloxi.com SIP/2.0\r\n"
1615 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=first\r\n"
1616 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=second\r\n"
1617 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=third\r\n"
1618 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=fourth\r\n"
1619 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=fifth\r\n"
1620 "Max-Forwards: 70\r\n"
1621 "To: Bob <sip:bob@biloxi.com>\r\n"
1622 "From: Bob <sip:bob@biloxi.com>;tag=456248\r\n"
1623 "Call-ID: 843817637684230@998sdasdh09\r\n"
1624 "CSeq: 1826 REGISTER\r\n"
1625 "Contact: <sip:bob@192.0.2.4>\r\n"
1626 "Contact: <sip:qoq@192.0.2.4>\r\n"
1627 "Expires: 7200\r\n"
1628 "Content-Length: 0\r\n\r\n");
1629 auto_ptr<SipMessage> message1(TestSupport::makeMessage(txt1));
1630
1631 // parse it
1632 message1->header(h_RequestLine).getMethod();
1633 for (NameAddrs::iterator i = message1->header(h_Contacts).begin();
1634 i != message1->header(h_Contacts).end(); i++)
1635 {
1636 i->uri();
1637 }
1638
1639 for (Vias::iterator i = message1->header(h_Vias).begin();
1640 i != message1->header(h_Vias).end(); i++)
1641 {
1642 i->sentPort();
1643 }
1644
1645 message1->header(h_To).uri().user();
1646 message1->header(h_From).uri().user();
1647 message1->header(h_MaxForwards).value();
1648 message1->header(h_Contacts).empty();
1649 message1->header(h_CallId).value();
1650 message1->header(h_CSeq).sequence();
1651 message1->header(h_CSeq).method();
1652 message1->header(h_Vias).empty();
1653 message1->header(h_Vias).size();
1654 message1->header(h_Expires).value();
1655 message1->header(h_ContentLength).value();
1656
1657 const char *txt2 = ("REGISTER sip:registrar.ixolib.com SIP/2.0\r\n"
1658 "Via: SIP/2.0/UDP speedyspc.biloxi.com:5061;branch=sfirst\r\n"
1659 "Via: SIP/2.0/UDP speedyspc.biloxi.com:5061;branch=ssecond\r\n"
1660 "Via: SIP/2.0/UDP speedyspc.biloxi.com:5061;branch=sthird\r\n"
1661 "Via: SIP/2.0/UDP speedyspc.biloxi.com:5061;branch=sfourth\r\n"
1662 "Max-Forwards: 7\r\n"
1663 "To: Speedy <sip:speedy@biloxi.com>\r\n"
1664 "From: Belle <sip:belle@biloxi.com>;tag=88888\r\n"
1665 "Call-ID: 88888@8888\r\n"
1666 "CSeq: 6281 REGISTER\r\n"
1667 "Contact: <sip:belle@192.0.2.4>\r\n"
1668 "Contact: <sip:qoq@192.0.2.4>\r\n"
1669 "Expires: 2700\r\n"
1670 "Content-Length: 0\r\n\r\n");
1671 auto_ptr<SipMessage> message2(TestSupport::makeMessage(txt2));
1672
1673 assert(message2->header(h_RequestLine).getMethod() == REGISTER);
1674 assert(message2->header(h_To).uri().user() == "speedy");
1675 assert(message2->header(h_From).uri().user() == "belle");
1676 assert(message2->header(h_MaxForwards).value() == 7);
1677 for (NameAddrs::iterator i = message2->header(h_Contacts).begin();
1678 i != message2->header(h_Contacts).end(); i++)
1679 {
1680 i->uri();
1681 }
1682
1683 for (Vias::iterator i = message2->header(h_Vias).begin();
1684 i != message2->header(h_Vias).end(); i++)
1685 {
1686 assert(i->sentPort() == 5061);
1687 }
1688 assert(message2->header(h_CallId).value() == "88888@8888");
1689 assert(message2->header(h_CSeq).sequence() == 6281);
1690 assert(message2->header(h_CSeq).method() == REGISTER);
1691 assert(message2->header(h_Vias).empty() == false);
1692 assert(message2->header(h_Vias).size() == 4);
1693 assert(message2->header(h_Expires).value() == 2700);
1694 assert(message2->header(h_ContentLength).value() == 0);
1695
1696 // copy over everything
1697 message1->header(h_RequestLine) = message2->header(h_RequestLine);
1698 message1->header(h_Vias) = message2->header(h_Vias);
1699 message1->header(h_MaxForwards) = message2->header(h_MaxForwards);
1700 message1->header(h_To) = message2->header(h_To);
1701 message1->header(h_From) = message2->header(h_From);
1702 message1->header(h_CallId) = message2->header(h_CallId);
1703 message1->header(h_CSeq) = message2->header(h_CSeq);
1704 message1->header(h_Contacts) = message2->header(h_Contacts);
1705 message1->header(h_Expires) = message2->header(h_Expires);
1706 message1->header(h_ContentLength) = message2->header(h_ContentLength);
1707
1708 assert(message1->header(h_To).uri().user() == "speedy");
1709 assert(message1->header(h_From).uri().user() == "belle");
1710 assert(message1->header(h_MaxForwards).value() == 7);
1711 assert(message1->header(h_Contacts).empty() == false);
1712 assert(message1->header(h_CallId).value() == "88888@8888");
1713 assert(message1->header(h_CSeq).sequence() == 6281);
1714 assert(message1->header(h_CSeq).method() == REGISTER);
1715 assert(message1->header(h_Vias).empty() == false);
1716 assert(message1->header(h_Vias).size() == 4);
1717 assert(message1->header(h_Expires).value() == 2700);
1718 assert(message1->header(h_ContentLength).value() == 0);
1719 assert(message1->header(h_RequestLine).uri().getAor() == "registrar.ixolib.com");
1720 }
1721
1722 {
1723 resipCerr << "test unparsed message copy" << endl;
1724 const char *txt = ("REGISTER sip:registrar.biloxi.com SIP/2.0\r\n"
1725 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=first\r\n"
1726 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=second\r\n"
1727 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=third\r\n"
1728 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=fourth\r\n"
1729 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=fifth\r\n"
1730 "Max-Forwards: 70\r\n"
1731 "To: Bob <sip:bob@biloxi.com>\r\n"
1732 "From: Bob <sip:bob@biloxi.com>;tag=456248\r\n"
1733 "Call-ID: 843817637684230@998sdasdh09\r\n"
1734 "CSeq: 1826 REGISTER\r\n"
1735 "Contact: <sip:bob@192.0.2.4>\r\n"
1736 "Contact: <sip:qoq@192.0.2.4>\r\n"
1737 "Expires: 7200\r\n"
1738 "Content-Length: 0\r\n\r\n");
1739 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1740
1741 SipMessage copy(*message);
1742 copy.encode(resipCerr);
1743 resipCerr << endl;
1744 }
1745
1746 {
1747 resipCerr << "test header creation" << endl;
1748 SipMessage message;
1749
1750 message.header(h_CSeq).sequence() = 123456;
1751 assert(message.header(h_CSeq).sequence() == 123456);
1752
1753 message.header(h_To).uri().user() = "speedy";
1754 assert(message.header(h_To).uri().user() == "speedy");
1755
1756 message.encode(resipCerr);
1757
1758 }
1759
1760 {
1761 resipCerr << "test multiheaders access" << endl;
1762
1763 const char *txt = ("REGISTER sip:registrar.biloxi.com SIP/2.0\r\n"
1764 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=first\r\n"
1765 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=second\r\n"
1766 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=third\r\n"
1767 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=fourth\r\n"
1768 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=fifth\r\n"
1769 "Max-Forwards: 70\r\n"
1770 "To: Bob <sip:bob@biloxi.com>\r\n"
1771 "From: Bob <sip:bob@biloxi.com>;tag=456248\r\n"
1772 "Call-ID: 843817637684230@998sdasdh09\r\n"
1773 "CSeq: 1826 REGISTER\r\n"
1774 "Contact: <sip:bob@192.0.2.4>\r\n"
1775 "Contact: <sip:qoq@192.0.2.4>\r\n"
1776 "Expires: 7200\r\n"
1777 "Content-Length: 0\r\n\r\n");
1778 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1779
1780 resipCerr << "Encode from unparsed: " << endl;
1781 message->encode(resipCerr);
1782
1783 assert(message->header(h_To).uri().user() == "bob");
1784 assert(message->header(h_From).uri().user() == "bob");
1785 assert(message->header(h_MaxForwards).value() == 70);
1786 assert(message->header(h_Contacts).empty() == false);
1787 assert(message->header(h_CallId).value() == "843817637684230@998sdasdh09");
1788 assert(message->header(h_CSeq).sequence() == 1826);
1789 assert(message->header(h_CSeq).method() == REGISTER);
1790 assert(message->header(h_Vias).empty() == false);
1791 assert(message->header(h_Vias).size() == 5);
1792 assert(message->header(h_Expires).value() == 7200);
1793 assert(message->header(h_ContentLength).value() == 0);
1794 assert(message->header(h_RequestLine).uri().getAor() == "registrar.biloxi.com");
1795
1796 resipCerr << "Encode from parsed: " << endl;
1797 message->encode(resipCerr);
1798
1799 message->header(h_Contacts).front().uri().user() = "jason";
1800
1801 resipCerr << "Encode after messing: " << endl;
1802 message->encode(resipCerr);
1803
1804 SipMessage copy(*message);
1805 assert(copy.header(h_To).uri().user() == "bob");
1806 assert(copy.header(h_From).uri().user() == "bob");
1807 assert(copy.header(h_MaxForwards).value() == 70);
1808 assert(copy.header(h_Contacts).empty() == false);
1809 assert(copy.header(h_CallId).value() == "843817637684230@998sdasdh09");
1810 assert(copy.header(h_CSeq).sequence() == 1826);
1811 assert(copy.header(h_CSeq).method() == REGISTER);
1812 assert(copy.header(h_Vias).empty() == false);
1813 assert(copy.header(h_Vias).size() == 5);
1814 assert(copy.header(h_Expires).value() == 7200);
1815 assert(copy.header(h_ContentLength).value() == 0);
1816 resipCerr << "RequestLine Uri AOR = " << copy.header(h_RequestLine).uri().getAor() << endl;
1817 assert(copy.header(h_RequestLine).uri().getAor() == "registrar.biloxi.com");
1818
1819
1820 resipCerr << "Encode after copying: " << endl;
1821 copy.encode(resipCerr);
1822 }
1823
1824 {
1825 resipCerr << "test callId access" << endl;
1826
1827 const char *txt = ("REGISTER sip:registrar.biloxi.com SIP/2.0\r\n"
1828 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=z9hG4bKnashds7\r\n"
1829 "Max-Forwards: 70\r\n"
1830 "To: Bob <sip:bob@biloxi.com>\r\n"
1831 "From: Bob <sip:bob@biloxi.com>;tag=456248\r\n"
1832 "Call-ID: 843817637684230@998sdasdh09\r\n"
1833 "CSeq: 1826 REGISTER\r\n"
1834 "Contact: <sip:bob@192.0.2.4>\r\n"
1835 "Expires: 7200\r\n"
1836 "Content-Length: 0\r\n\r\n");
1837 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1838
1839 message->encode(resipCerr);
1840
1841 //Data v = message->header(h_CallId).value();
1842 assert(message->header(h_CallId).value() == "843817637684230@998sdasdh09");
1843 //StatusLine& foo = message->header(h_StatusLine);
1844 //RequestLine& bar = message->header(h_RequestLine);
1845 //resipCerr << bar.getMethod() << endl;
1846 }
1847
1848 {
1849 const char *txt = ("REGISTER sip:registrar.biloxi.com SIP/2.0\r\n"
1850 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=z9hG4bKnashds7\r\n"
1851 "Max-Forwards: 70\r\n"
1852 "To: Bob <sip:bob@biloxi.com>\r\n"
1853 "From: Bob <sip:bob@biloxi.com>;tag=456248;xmobility=hobble\r\n"
1854 "Call-ID: 843817637684230@998sdasdh09\r\n"
1855 "CSeq: 1826 REGISTER\r\n"
1856 "Contact: <sip:bob@192.0.2.4>\r\n"
1857 "Expires: 7200\r\n"
1858 "Content-Length: 0\r\n\r\n");
1859 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1860
1861 Data v = message->header(h_CallId).value();
1862 resipCerr << "Call-ID is " << v << endl;
1863
1864 message->encode(resipCerr);
1865
1866 //StatusLine& foo = message->header(h_StatusLine);
1867 //RequestLine& bar = message->header(h_RequestLine);
1868 //resipCerr << bar.getMethod() << endl;
1869 }
1870
1871 {
1872
1873 const char *txt = ("REGISTER sip:registrar.biloxi.com SIP/2.0\r\n"
1874 "Via: SIP/2.0/UDP bobspc.biloxi.com:5060;branch=z9hG4bKnashds7\r\n"
1875 "Max-Forwards: 70\r\n"
1876 "To: Bob <sip:bob@biloxi.com>\r\n"
1877 "From: Bob <sip:bob@biloxi.com>;tag=456248;mobility=\"hobble\"\r\n"
1878 "Call-ID: 843817637684230@998sdasdh09\r\n"
1879 "CSeq: 1826 REGISTER\r\n"
1880 "Contact: <sip:bob@192.0.2.4>\r\n"
1881 "Expires: 7200\r\n"
1882 "Content-Length: 0\r\n\r\n");
1883 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1884
1885 assert(message->getRawHeader(Headers::From));
1886 assert(&message->header(h_From));
1887 assert(message->header(h_From).exists(p_tag) == true);
1888 assert(message->header(h_From).exists(p_mobility) == true);
1889 assert(message->header(h_From).param(p_tag) == "456248");
1890 assert(message->header(h_From).param(p_mobility) == "hobble");
1891
1892 message->encode(resipCerr);
1893
1894 //StatusLine& foo = message->header(h_StatusLine);
1895 //RequestLine& bar = message->header(h_RequestLine);
1896 //resipCerr << bar.getMethod() << endl;
1897 }
1898
1899 {
1900 resipCerr << "first REGISTER in torture test" << endl;
1901
1902 const char *txt = ("REGISTER sip:company.com SIP/2.0\r\n"
1903 "To: sip:user@company.com\r\n"
1904 "From: sip:user@company.com;tag=3411345\r\n"
1905 "Max-Forwards: 8\r\n"
1906 "Contact: sip:user@host.company.com\r\n"
1907 "Call-ID: 0ha0isndaksdj@10.0.0.1\r\n"
1908 "CSeq: 8 REGISTER\r\n"
1909 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
1910 "Expires: 353245\r\n\r\n");
1911
1912 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1913
1914 assert(message->isRequest());
1915 assert(message->isResponse() == false);
1916
1917 assert(message->exists(h_To));
1918 assert(message->header(h_To).uri().user() == "user");
1919 assert(message->header(h_To).uri().host() == "company.com");
1920 assert(message->header(h_To).uri().exists(p_tag_ext) == false);
1921
1922 assert(message->exists(h_From));
1923 assert(message->header(h_From).uri().user() == "user");
1924 assert(message->header(h_From).uri().host() == "company.com");
1925 assert(message->header(h_From).param(p_tag) == "3411345");
1926
1927 assert(message->exists(h_MaxForwards));
1928 assert(message->header(h_MaxForwards).value() == 8);
1929 assert(message->header(h_MaxForwards).exists(p_tag_ext) == false);
1930
1931 assert(message->exists(h_Contacts));
1932 assert(message->header(h_Contacts).empty() == false);
1933 assert(message->header(h_Contacts).front().uri().user() == "user");
1934 assert(message->header(h_Contacts).front().uri().host() == "host.company.com");
1935 assert(message->header(h_Contacts).front().uri().port() == 0);
1936
1937 assert(message->exists(h_CallId));
1938 assert(message->header(h_CallId).value() == "0ha0isndaksdj@10.0.0.1");
1939
1940 assert(message->exists(h_CSeq));
1941 assert(message->header(h_CSeq).sequence() == 8);
1942 assert(message->header(h_CSeq).method() == REGISTER);
1943
1944 assert(message->exists(h_Vias));
1945 assert(message->header(h_Vias).empty() == false);
1946 assert(message->header(h_Vias).front().protocolName() == "SIP");
1947 assert(message->header(h_Vias).front().protocolVersion() == "2.0");
1948 assert(message->header(h_Vias).front().transport() == "UDP");
1949 assert(message->header(h_Vias).front().sentHost() == "135.180.130.133");
1950 assert(message->header(h_Vias).front().sentPort() == 0);
1951
1952 assert(message->exists(h_Expires));
1953 assert(message->header(h_Expires).value() == 353245);
1954
1955 resipCerr << "Headers::Expires enum = " << h_Expires.getTypeNum() << endl;
1956
1957 message->encode(resipCerr);
1958 }
1959
1960 {
1961 resipCerr << "first REGISTER in torture test" << endl;
1962
1963 const char *txt = ("REGISTER sip:company.com SIP/2.0\r\n"
1964 "To: sip:user@company.com\r\n"
1965 "From: sip:user@company.com;tag=3411345\r\n"
1966 "Max-Forwards: 8\r\n"
1967 "Contact: sip:user@host.company.com\r\n"
1968 "Call-ID: 0ha0isndaksdj@10.0.0.1\r\n"
1969 "CSeq: 8 REGISTER\r\n"
1970 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
1971 "Expires: 353245\r\n\r\n");
1972
1973 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1974
1975 assert(message->header(h_MaxForwards).value() == 8);
1976 message->getRawHeader(Headers::MaxForwards)->getParserContainer()->encode(Headers::getHeaderName(Headers::MaxForwards), resipCerr) << endl;
1977 }
1978
1979 {
1980 resipCerr << "response to REGISTER" << endl;
1981
1982 const char *txt = ("SIP/2.0 100 Trying\r\n"
1983 "To: sip:localhost:5070\r\n"
1984 "From: sip:localhost:5070;tag=73483366\r\n"
1985 "Call-ID: 51dcb07418a21008e0ba100800000000\r\n"
1986 "CSeq: 1 REGISTER\r\n"
1987 "Via: SIP/2.0/UDP squamish.gloo.net:5060;branch=z9hG4bKff5c491951e40f08\r\n"
1988 "Content-Length: 0\r\n\r\n");
1989
1990 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
1991
1992 assert(message->header(h_To).uri().host() == "localhost");
1993 }
1994 {
1995 NameAddr me;
1996 me.uri().host() = "localhost";
1997 me.uri().port() = 5070;
1998 //auto_ptr<SipMessage> msg(Helper::makeRegister(me, me));
1999 auto_ptr<SipMessage> msg(Helper::makeRegister(me, me, me));
2000 resipCerr << "encoded=" << *msg << endl;
2001 }
2002 {
2003 const char *txt = ("REGISTER sip:company.com SIP/2.0\r\n"
2004 "To: sip:user@company.com\r\n"
2005 "From: sip:user@company.com;tag=3411345\r\n"
2006 "Max-Forwards: 8\r\n"
2007 "Contact: sip:user@host.company.com\r\n"
2008 "Call-ID: 0ha0isndaksdj@10.0.0.1\r\n"
2009 "CSeq: 8 REGISTER\r\n"
2010 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
2011 "Expires: 353245\r\n\r\n");
2012
2013 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
2014 message->header(h_RequestLine).uri();
2015 auto_ptr<SipMessage> copy(new SipMessage(*message));
2016 assert(message->header(h_RequestLine).getMethod() == copy->header(h_RequestLine).getMethod());
2017 }
2018 {
2019 const char *txt = ("REGISTER sip:company.com SIP/2.0\r\n"
2020 "To: sip:user@company.com\r\n"
2021 "From: sip:user@company.com;tag=3411345\r\n"
2022 "Max-Forwards: 8\r\n"
2023 "Contact: sip:user@host.company.com\r\n"
2024 "Call-ID: 0ha0isndaksdj@10.0.0.1\r\n"
2025 "Security-Client: ipsec-ike;d-alg=md5;q=0.1\r\n"
2026 "Security-Server: tls;q=0.2;d-qop=verify\r\n"
2027 "Security-Verify: tls;q=0.2;d-ver=\"0000000000000000000000000000abcd\"\r\n"
2028 "CSeq: 8 REGISTER\r\n"
2029 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
2030 "Expires: 353245\r\n\r\n");
2031
2032 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
2033 assert(message->header(h_SecurityClients).front().value() == "ipsec-ike");
2034 assert(message->header(h_SecurityClients).front().param(p_dAlg) == "md5");
2035 assert(message->header(h_SecurityClients).front().param(p_q) == 100);
2036 #ifndef RESIP_FIXED_POINT
2037 assert(message->header(h_SecurityClients).front().param(p_q) == double(0.1));
2038 assert(message->header(h_SecurityClients).front().param(p_q) == 0.1);
2039 assert(message->header(h_SecurityClients).front().param(p_q) == float(0.1));
2040 #endif
2041
2042 assert(message->header(h_SecurityServers).front().value() == "tls");
2043 assert(message->header(h_SecurityServers).front().param(p_dQop) == "verify");
2044 #ifndef RESIP_FIXED_POINT
2045 assert(message->header(h_SecurityServers).front().param(p_q) == double(0.2));
2046 assert(message->header(h_SecurityServers).front().param(p_q) == 0.2f);
2047 #endif
2048 assert(message->header(h_SecurityServers).front().param(p_q) == 200);
2049
2050 assert(message->header(h_SecurityVerifies).front().value() == "tls");
2051 assert(message->header(h_SecurityVerifies).front().param(p_dVer) == "0000000000000000000000000000abcd");
2052 #ifndef RESIP_FIXED_POINT
2053 assert(message->header(h_SecurityVerifies).front().param(p_q) == double(0.2));
2054 assert(message->header(h_SecurityVerifies).front().param(p_q) == 0.2f);
2055 #endif
2056 assert(message->header(h_SecurityVerifies).front().param(p_q) == 200);
2057
2058 assert(message->exists(h_AllowEvents) == false);
2059 }
2060
2061 {
2062 const char *txt = ("REGISTER sip:company.com SIP/2.0\r\n"
2063 "To: sip:user@company.com\r\n"
2064 "From: sip:user@company.com;tag=3411345\r\n"
2065 "Max-Forwards: 8\r\n"
2066 "Contact: sip:user@host.company.com\r\n"
2067 "Call-ID: 0ha0isndaksdj@10.0.0.1\r\n"
2068 "CSeq: 8 REGISTER\r\n"
2069 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
2070 "Expires: 353245\r\n\r\n");
2071
2072 const char *txt2 = ("REGISTER sip:company.com SIP/2.0\r\n"
2073 "To: sip:user@company.com\r\n"
2074 "From: sip:user@company.com;tag=3411345\r\n"
2075 "Max-Forwards: 8\r\n"
2076 "Contact: sip:user@host.company.com\r\n"
2077 "Call-ID: 0ha0isndaksdj@10.0.0.1\r\n"
2078 "Security-Client: ipsec-ike;d-alg=md5;q=0.1\r\n"
2079 "Security-Server: tls;q=0.2;d-qop=verify\r\n"
2080 "Security-Verify: tls;q=0.2;d-ver=\"0000000000000000000000000000abcd\"\r\n"
2081 "CSeq: 8 REGISTER\r\n"
2082 "Via: SIP/2.0/UDP 135.180.130.133;branch=z9hG4bKkdjuw\r\n"
2083 "Expires: 353245\r\n\r\n");
2084
2085 auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));
2086
2087 {
2088 Token sec;
2089 sec.value() = "ipsec-ike";
2090 sec.param(p_dAlg) = "md5";
2091 sec.param(p_q) = 100;
2092 message->header(h_SecurityClients).push_back(sec);
2093 }
2094 {
2095 Token sec;
2096 sec.value() = "tls";
2097 sec.param(p_q) = 200;
2098 sec.param(p_dQop) = "verify";
2099 message->header(h_SecurityServers).push_back(sec);
2100 }
2101 {
2102 Token sec;
2103 sec.value() = "tls";
2104 sec.param(p_q) = 200;
2105 sec.param(p_dVer) = "0000000000000000000000000000abcd";
2106 message->header(h_SecurityVerifies).push_back(sec);
2107 }
2108
2109 auto_ptr<SipMessage> message2(TestSupport::makeMessage(txt2));
2110
2111 Data msgEncoded;
2112 {
2113 DataStream s(msgEncoded);
2114 s << *message;
2115 }
2116
2117 Data msg2Encoded;
2118 {
2119 DataStream s(msg2Encoded);
2120 s << *message2;
2121 }
2122
2123 assert(msgEncoded == msg2Encoded);
2124 }
2125
2126 {
2127 Data txt("INVITE sip:bob@biloxi.com SIP/2.0\r\n"
2128 "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\r\n"
2129 "To: Bob <sip:bob@biloxi.com>\r\n"
2130 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
2131 "Call-ID: a84b4c76e66710\r\n"
2132 "CSeq: 314159 INVITE\r\n"
2133 "Max-Forwards: 70\r\n"
2134 "Accept: \r\n"
2135 "Foobie-Blech: \r\n"
2136 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
2137 "Content-Type: application/sdp\r\n"
2138 "Content-Length: 150\r\n"
2139 "\r\n"
2140 "v=0\r\n"
2141 "o=alice 53655765 2353687637 IN IP4 pc33.atlanta.com\r\n"
2142 "s=-\r\n"
2143 "c=IN IP4 pc33.atlanta.com\r\n"
2144 "t=0 0\r\n"
2145 "m=audio 3456 RTP/AVP 0 1 3 99\r\n"
2146 "a=rtpmap:0 PCMU/8000\r\n");
2147
2148 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
2149
2150 assert(msg->exists(h_Accepts));
2151 assert(msg->header(h_Accepts).empty());
2152
2153 assert(msg->exists(UnknownHeaderType("Foobie-Blech")));
2154 assert(msg->header(UnknownHeaderType("Foobie-Blech")).empty());
2155 }
2156
2157 {
2158 Data txt("INVITE sip:bob@biloxi.com SIP/2.0\r\n"
2159 "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8\r\n"
2160 "To: Bob <sip:bob@biloxi.com>\r\n"
2161 "From: Alice <sip:alice@atlanta.com>;tag=1928301774\r\n"
2162 "Call-ID: a84b4c76e66710\r\n"
2163 "CSeq: 314159 INVITE\r\n"
2164 "Max-Forwards: 70\r\n"
2165 "Accept: \r\n"
2166 "Foobie-Blech: \r\n"
2167 "Contact: <sip:alice@pc33.atlanta.com>\r\n"
2168 "Content-Type: application/sdp\r\n"
2169 "Content-Length: 150\r\n"
2170 "FooBarBaz: yetmorestuff\r\n"
2171 "FooBar: morestuff\r\n"
2172 "Foo: stuff\r\n"
2173 "\r\n"
2174 "v=0\r\n"
2175 "o=alice 53655765 2353687637 IN IP4 pc33.atlanta.com\r\n"
2176 "s=-\r\n"
2177 "c=IN IP4 pc33.atlanta.com\r\n"
2178 "t=0 0\r\n"
2179 "m=audio 3456 RTP/AVP 0 1 3 99\r\n"
2180 "a=rtpmap:0 PCMU/8000\r\n");
2181
2182 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
2183
2184 assert(msg->exists(h_Accepts));
2185 assert(msg->header(h_Accepts).empty());
2186
2187 assert(msg->exists(UnknownHeaderType("Foobie-Blech")));
2188 assert(msg->header(UnknownHeaderType("Foobie-Blech")).empty());
2189
2190 assert(msg->exists(UnknownHeaderType("Foo")));
2191 assert(msg->header(UnknownHeaderType("Foo")).size()==1);
2192
2193 assert(msg->exists(UnknownHeaderType("FooBar")));
2194 assert(msg->header(UnknownHeaderType("FooBar")).size()==1);
2195
2196 assert(msg->exists(UnknownHeaderType("FooBarBaz")));
2197 assert(msg->header(UnknownHeaderType("FooBarBaz")).size()==1);
2198 }
2199
2200 {
2201 resip::Data invBuf;
2202 {
2203 resip::DataStream ds(invBuf);
2204
2205 ds << "INVITE sip:7003@192.122.24.94:20060?REQUIRE=replaces SIP/2.0\r\n";
2206 ds << "Via: SIP/2.0/UDP 192.122.24.109;branch=z9hG4bKfc4a20db5EC58FB8\r\n";
2207 ds << "From: \"7006 601\" <sip:7006@scsuk.europe.nortel.com>;tag=29C49D21-D9FDBDBC\r\n";
2208 ds << "To: <sip:7003@192.122.24.94:20060?REQUIRE=replaces>\r\n";
2209 ds << "CSeq: 1 INVITE\r\n";
2210 ds << "Call-ID: a9ad18fd-5fd391bf-309febea@192.122.24.109\r\n";
2211 ds << "Contact: <sip:7006@192.122.24.109>\r\n";
2212 ds << "Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, INFO, MESSAGE, SUBSCRIBE, NOTIFY, PRACK, UPDATE, REFER\r\n";
2213 ds << "User-Agent: PolycomSoundPointIP-SPIP_601-UA/2.1.1.0052\r\n";
2214 ds << "Supported: 100rel,replaces\r\n";
2215 ds << "Allow-Events: talk,hold,conference\r\n";
2216 ds << "Replaces: MDQ5MDJmZGEyYTkyNTBhZjBhNDg0NjUyMzE1MTc2Mjk.;to-tag=cf71d002;from-tag=1394930945\r\n";
2217 ds << "Referred-By: <sip:7776@scsuk.europe.nortel.com>\r\n";
2218 ds << "Max-Forwards: 70\r\n";
2219 ds << "Content-Type: application/sdp\r\n";
2220 ds << "Content-Length: 253\r\n";
2221 ds << "\r\n";
2222 ds << "v=0\r\n";
2223 ds << "o=- 1210601497 1210601497 IN IP4 192.122.24.109\r\n";
2224 ds << "s=Polycom IP Phone\r\n";
2225 ds << "c=IN IP4 192.122.24.109\r\n";
2226 ds << "t=0 0\r\n";
2227 ds << "m=audio 2224 RTP/AVP 0 8 18 101\r\n";
2228 ds << "a=sendrecv\r\n";
2229 ds << "a=rtpmap:0 PCMU/8000\r\n";
2230 ds << "a=rtpmap:8 PCMA/8000\r\n";
2231 ds << "a=rtpmap:18 G729/8000\r\n";
2232 ds << "a=rtpmap:101 telephone-event/8000\r\n";
2233 }
2234
2235 auto_ptr<SipMessage> testMsg(TestSupport::makeMessage(invBuf));
2236 assert(testMsg->header(h_RequestLine).isWellFormed());
2237 assert(testMsg->header(h_RequestLine).method() == INVITE);
2238 assert(testMsg->header(h_RequestLine).getSipVersion() == "SIP/2.0");
2239 assert(testMsg->header(h_RequestLine).uri().hasEmbedded());
2240 SipMessage& embeddedMsg = testMsg->header(h_RequestLine).uri().embedded();
2241 assert(embeddedMsg.exists(h_Requires));
2242 assert(embeddedMsg.header(h_Requires).find(Token(Symbols::Replaces)));
2243 assert(testMsg->header(h_To).uri().hasEmbedded());
2244 SipMessage& embeddedMsg2 = testMsg->header(h_To).uri().embedded();
2245 assert(embeddedMsg2.exists(h_Requires));
2246 assert(embeddedMsg2.header(h_Requires).find(Token(Symbols::Replaces)));
2247 }
2248
2249 resipCerr << "\nTEST OK" << endl;
2250 return 0;
2251 }
2252
2253 /* vim: softtabstop=3:shiftwidth=3:expandtab */
2254
2255 /* ====================================================================
2256 * The Vovida Software License, Version 1.0
2257 *
2258 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
2259 *
2260 * Redistribution and use in source and binary forms, with or without
2261 * modification, are permitted provided that the following conditions
2262 * are met:
2263 *
2264 * 1. Redistributions of source code must retain the above copyright
2265 * notice, this list of conditions and the following disclaimer.
2266 *
2267 * 2. Redistributions in binary form must reproduce the above copyright
2268 * notice, this list of conditions and the following disclaimer in
2269 * the documentation and/or other materials provided with the
2270 * distribution.
2271 *
2272 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
2273 * and "Vovida Open Communication Application Library (VOCAL)" must
2274 * not be used to endorse or promote products derived from this
2275 * software without prior written permission. For written
2276 * permission, please contact vocal@vovida.org.
2277 *
2278 * 4. Products derived from this software may not be called "VOCAL", nor
2279 * may "VOCAL" appear in their name, without prior written
2280 * permission of Vovida Networks, Inc.
2281 *
2282 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
2283 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2284 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
2285 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
2286 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
2287 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
2288 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2289 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2290 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
2291 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2292 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
2293 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2294 * DAMAGE.
2295 *
2296 * ====================================================================
2297 *
2298 * This software consists of voluntary contributions made by Vovida
2299 * Networks, Inc. and many individuals on behalf of Vovida Networks,
2300 * Inc. For more information on Vovida Networks, Inc., please see
2301 * <http://www.vovida.org/>.
2302 *
2303 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27