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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7491 - (show annotations) (download)
Wed Dec 12 20:55:03 2007 UTC (11 years, 11 months ago) by bcampen
File MIME type: text/plain
File size: 15588 byte(s)
Fixing a bug in the copy c'tor of MultipartMixedContents that was causing us
to be unparsed, and leaving parsed copies of everything in mContents. When
we parsed, extra copies of everything would be placed in mContents.

1 #include <iostream>
2 #include <memory>
3
4 #include "resip/stack/MultipartMixedContents.hxx"
5 #include "resip/stack/MultipartRelatedContents.hxx"
6 #include "resip/stack/GenericContents.hxx"
7 #include "resip/stack/Rlmi.hxx"
8 #include "resip/stack/Pidf.hxx"
9 #include "resip/stack/Pkcs7Contents.hxx"
10 #include "resip/stack/MultipartSignedContents.hxx"
11 #include "resip/stack/SipMessage.hxx"
12 #include "resip/stack/test/TestSupport.hxx"
13 #include "rutil/ParseBuffer.hxx"
14
15 using namespace resip;
16 using namespace std;
17
18 void indent(int indent)
19 {
20 for (int i = 0; i < 3*indent; ++i)
21 {
22 cerr << " ";
23 }
24 }
25
26 void
27 traverseMulti(const MultipartMixedContents* mp,
28 int level = 0)
29 {
30 for (MultipartRelatedContents::Parts::const_iterator i = mp->parts().begin();
31 i != mp->parts().end(); ++i)
32 {
33 GenericContents* generic;
34 Pidf* pidf;
35 Rlmi* rlmi;
36 MultipartSignedContents* mps;
37 MultipartMixedContents* mpm;
38 Pkcs7Contents* pkcs7;
39
40 if ((pidf = dynamic_cast<Pidf*>(*i)))
41 {
42 indent(level);
43 cerr << "discovered a Pidf" << endl;
44 }
45 else if ((rlmi = dynamic_cast<Rlmi*>(*i)))
46 {
47 indent(level);
48 cerr << "discovered a Rlmi" << endl;
49 }
50 else if ((pkcs7 = dynamic_cast<Pkcs7Contents*>(*i)))
51 {
52 indent(level);
53 cerr << "discovered a Pkcs7Contents" << endl;
54 }
55 else if ((mps = dynamic_cast<MultipartSignedContents*>(*i)))
56 {
57 indent(level);
58 cerr << "discovered a multipart signed with " << mps->parts().size() << " parts " << endl;
59 traverseMulti(mps, level+1);
60 }
61 else if ((mpm = dynamic_cast<MultipartMixedContents*>(*i)))
62 {
63 indent(level);
64 cerr << "discovered a multipart with " << mpm->parts().size() << " parts " << endl;
65 traverseMulti(mpm, level+1);
66 }
67 else if ((generic = dynamic_cast<GenericContents*>(*i)))
68 {
69 indent(level);
70 cerr << "discovered an unknown type " << generic->getType() << endl;
71 }
72 else
73 {
74 indent(level);
75 cerr << "Some other kind of content!" << endl;
76 }
77 }
78 }
79
80 // http://www.softarmor.com/simple/drafts/draft-ietf-simple-event-list-04.txt
81 int
82 main()
83 {
84 {
85 const Data tx0("NOTIFY sip:terminal.example.com SIP/2.0\r\n"
86 "Via: SIP/2.0/TCP pres.example.com;branch=z9hG4bKMgRenTETmm\r\n"
87 "Max-Forwards: 70\r\n"
88 "From: <sip:adam-buddies@pres.example.com>;tag=zpNctbZq\r\n"
89 "To: <sip:adam@example.com>;tag=ie4hbb8t\r\n"
90 "Call-ID: cdB34qLToC@terminal.example.com\r\n"
91 "CSeq: 997935768 NOTIFY\r\n"
92 "Contact: <sip:pres.example.com>\r\n"
93 "Event: presence\r\n"
94 "Subscription-State: active;expires=7200\r\n"
95 "Require: eventlist\r\n"
96 "Content-Type: multipart/related;type=\"application/rlmi+xml\";\r\n"
97 " start=\"<nXYxAE@pres.example.com>\";boundary=\"50UBfW7LSCVLtggUPe5z\"\r\n"
98 "Content-Length: 1560\r\n"
99 "\r\n"
100 "--50UBfW7LSCVLtggUPe5z\r\n"
101 "Content-Transfer-Encoding: binary\r\n"
102 "Content-ID: <nXYxAE@pres.example.com>\r\n"
103 "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n"
104 "\r\n"
105 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
106 "<list xmlns=\"urn:ietf:params:xml:ns:rmli\"\r\n"
107 " uri=\"sip:adam-friends@pres.example.com\" version=\"1\"\r\n"
108 " name=\"Buddy List at COM\" fullState=\"true\">\r\n"
109 " <resource uri=\"sip:bob@example.com\" name=\"Bob Smith\">\r\n"
110 " <instance id=\"juwigmtboe\" state=\"active\"\r\n"
111 " cid=\"bUZBsM@pres.example.com\"/>\r\n"
112 " </resource>\r\n"
113 " <resource uri=\"sip:dave@example.com\" name=\"Dave Jones\">\r\n"
114 " <instance id=\"hqzsuxtfyq\" state=\"active\"\r\n"
115 " cid=\"ZvSvkz@pres.example.com\"/>\r\n"
116 " </resource>\r\n"
117 " <resource uri=\"sip:ed@example.net\" name=\"Ed at NET\" />\r\n"
118 " <resource uri=\"sip:adam-friends@example.org\"\r\n"
119 " name=\"My Friends at ORG\" />\r\n"
120 "</list>\r\n"
121 "\r\n"
122 "--50UBfW7LSCVLtggUPe5z\r\n"
123 "Content-Transfer-Encoding: binary\r\n"
124 "Content-ID: <bUZBsM@pres.example.com>\r\n"
125 "Content-Type: application/pidf+xml;charset=\"UTF-8\"\r\n"
126 "\r\n"
127 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
128 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n"
129 " entity=\"sip:bob@example.com\">\r\n"
130 " <tuple id=\"sg89ae\">\r\n"
131 " <status>\r\n"
132 " <basic>open</basic>\r\n"
133 " </status>\r\n"
134 " <contact priority=\"1.0\">sip:bob@example.com</contact>\r\n"
135 " </tuple>\r\n"
136 "</presence>\r\n"
137 "\r\n"
138 "--50UBfW7LSCVLtggUPe5z\r\n"
139 "Content-Transfer-Encoding: binary\r\n"
140 "Content-ID: <ZvSvkz@pres.example.com>\r\n"
141 "Content-Type: application/pidf+xml;charset=\"UTF-8\"\r\n"
142 "\r\n"
143 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
144 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n"
145 " entity=\"sip:dave@example.com\">\r\n"
146 " <tuple id=\"slie74\">\r\n"
147 " <status>\r\n"
148 " <basic>closed</basic>\r\n"
149 " </status>\r\n"
150 " </tuple>\r\n"
151 "</presence>\r\n"
152 "\r\n"
153 "--50UBfW7LSCVLtggUPe5z--\r\n");
154
155 const Data txt("NOTIFY sip:terminal.example.com SIP/2.0\r\n"
156 "Via: SIP/2.0/TCP pres.example.com;branch=z9hG4bK4EPlfSFQK1\r\n"
157 "Max-Forwards: 70\r\n"
158 "From: <sip:adam-buddies@pres.example.com>;tag=zpNctbZq\r\n"
159 "To: <sip:adam@example.com>;tag=ie4hbb8t\r\n"
160 "Call-ID: cdB34qLToC@terminal.example.com\r\n"
161 "CSeq: 997935769 NOTIFY\r\n"
162 "Contact: <sip:pres.example.com>\r\n"
163 "Event: presence\r\n"
164 "Subscription-State: active;expires=7200\r\n"
165 "Require: eventlist\r\n"
166 "Content-Type: multipart/related;type=\"application/rlmi+xml\";\r\n"
167 " start=\"<2BEI83@pres.example.com>\";boundary=\"TfZxoxgAvLqgj4wRWPDL\"\r\n"
168 "Content-Length: 2862\r\n"
169 "\r\n"
170 "--TfZxoxgAvLqgj4wRWPDL\r\n"
171 "Content-Transfer-Encoding: binary\r\n"
172 "Content-ID: <2BEI83@pres.example.com>\r\n"
173 "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n"
174 "\r\n"
175 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
176 "<list xmlns=\"urn:ietf:params:xml:ns:rmli\"\r\n"
177 " uri=\"sip:adam-friends@pres.example.com\" version=\"2\"\r\n"
178 " name=\"Buddy List at COM\" fullState=\"false\">\r\n"
179 " <resource uri=\"sip:ed@example.net\" name=\"Ed at NET\">\r\n"
180 " <instance id=\"sdlkmeopdf\" state=\"pending\"/>\r\n"
181 " </resource>\r\n"
182 " <resource uri=\"sip:adam-friends@example.org\"\r\n"
183 " name=\"My Friends at ORG\">\r\n"
184 " <instance id=\"cmpqweitlp\" state=\"active\"\r\n"
185 " cid=\"1KQhyE@pres.example.com\"/>\r\n"
186 " </resource>\r\n"
187 "</list>\r\n"
188 "\r\n"
189 "--TfZxoxgAvLqgj4wRWPDL\r\n"
190 "Content-Transfer-Encoding: binary\r\n"
191 "Content-ID: <1KQhyE@pres.example.com>\r\n"
192 "Content-Type: multipart/signed;\r\n"
193 " protocol=\"application/pkcs7-signature\";\r\n"
194 " micalg=sha1;boundary=\"l3WMZaaL8NpQWGnQ4mlU\"\r\n"
195 "\r\n"
196 "--l3WMZaaL8NpQWGnQ4mlU\r\n"
197 "Content-Transfer-Encoding: binary\r\n"
198 "Content-ID: <ZPvJHL@example.org>\r\n"
199 "Content-Type: multipart/related;type=\"application/rlmi+xml\";\r\n"
200 " start=\"<Cvjpeo@example.org>\";boundary=\"tuLLl3lDyPZX0GMr2YOo\"\r\n"
201 "\r\n"
202 "--tuLLl3lDyPZX0GMr2YOo\r\n"
203 "Content-Transfer-Encoding: binary\r\n"
204 "Content-ID: <Cvjpeo@example.org>\r\n"
205 "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n"
206 "\r\n"
207 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
208 "<list xmlns=\"urn:ietf:params:xml:ns:rmli\"\r\n"
209 " uri=\"sip:adam-friends@example.org\" version=\"1\"\r\n"
210 " name=\"Buddy List at ORG\" fullState=\"true\">\r\n"
211 " <resource uri=\"sip:joe@example.org\" name=\"Joe Thomas\">\r\n"
212 " <instance id=\"1\" state=\"active\" cid=\"mrEakg@example.org\"/>\r\n"
213 " </resource>\r\n"
214 " <resource uri=\"sip:mark@example.org\" name=\"Mark Edwards\">\r\n"
215 " <instance id=\"1\" state=\"active\" cid=\"KKMDmv@example.org\"/>\r\n"
216 " </resource>\r\n"
217 "</list>\r\n"
218 "\r\n"
219 "--tuLLl3lDyPZX0GMr2YOo\r\n"
220 "Content-Transfer-Encoding: binary\r\n"
221 "Content-ID: <mrEakg@example.org>\r\n"
222 "Content-Type: application/pidf+xml;charset=\"UTF-8\"\r\n"
223 "\r\n"
224 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
225 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n"
226 " entity=\"sip:joe@example.org\">\r\n"
227 " <tuple id=\"7823a4\">\r\n"
228 " <status>\r\n"
229 " <basic>open</basic>\r\n"
230 " </status>\r\n"
231 " <contact priority=\"1.0\">sip:joe@example.org</contact>\r\n"
232 " </tuple>\r\n"
233 "</presence>\r\n"
234 "\r\n"
235 "--tuLLl3lDyPZX0GMr2YOo\r\n"
236 "Content-Transfer-Encoding: binary\r\n"
237 "Content-ID: <KKMDmv@example.org>\r\n"
238 "Content-Type: application/pidf+xml;charset=\"UTF-8\"\r\n"
239 "\r\n"
240 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
241 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n"
242 " entity=\"sip:mark@example.org\">\r\n"
243 " <tuple id=\"398075\">\r\n"
244 " <status>\r\n"
245 " <basic>closed</basic>\r\n"
246 " </status>\r\n"
247 " </tuple>\r\n"
248 "</presence>\r\n"
249 "\r\n"
250 "--tuLLl3lDyPZX0GMr2YOo--\r\n"
251 "\r\n"
252 "--l3WMZaaL8NpQWGnQ4mlU\r\n"
253 "Content-Transfer-Encoding: binary\r\n"
254 "Content-ID: <K9LB7k@example.org>\r\n"
255 "Content-Type: application/pkcs7-signature\r\n"
256 "\r\n"
257 "[PKCS #7 signature here]\r\n"
258 "\r\n"
259 "--l3WMZaaL8NpQWGnQ4mlU--\r\n"
260 "\r\n"
261 "--TfZxoxgAvLqgj4wRWPDL--\r\n");
262
263 auto_ptr<SipMessage> msg(TestSupport::makeMessage(txt.c_str()));
264
265 MultipartRelatedContents* mpc = dynamic_cast<MultipartRelatedContents*>(msg->getContents());
266 assert(mpc);
267
268 Contents* copy = msg->getContents()->clone();
269
270 traverseMulti(mpc);
271
272 MultipartRelatedContents* mpcCopy = dynamic_cast<MultipartRelatedContents*>(copy);
273 traverseMulti(mpcCopy);
274 }
275
276 cerr << "All OK" << endl;
277 return 0;
278 }
279
280 /* ====================================================================
281 * The Vovida Software License, Version 1.0
282 *
283 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved.
284 *
285 * Redistribution and use in source and binary forms, with or without
286 * modification, are permitted provided that the following conditions
287 * are met:
288 *
289 * 1. Redistributions of source code must retain the above copyright
290 * notice, this list of conditions and the following disclaimer.
291 *
292 * 2. Redistributions in binary form must reproduce the above copyright
293 * notice, this list of conditions and the following disclaimer in
294 * the documentation and/or other materials provided with the
295 * distribution.
296 *
297 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
298 * and "Vovida Open Communication Application Library (VOCAL)" must
299 * not be used to endorse or promote products derived from this
300 * software without prior written permission. For written
301 * permission, please contact vocal@vovida.org.
302 *
303 * 4. Products derived from this software may not be called "VOCAL", nor
304 * may "VOCAL" appear in their name, without prior written
305 * permission of Vovida Networks, Inc.
306 *
307 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
308 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
309 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
310 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
311 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
312 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
313 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
314 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
315 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
316 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
317 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
318 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
319 * DAMAGE.
320 *
321 * ====================================================================
322 *
323 * This software consists of voluntary contributions made by Vovida
324 * Networks, Inc. and many individuals on behalf of Vovida Networks,
325 * Inc. For more information on Vovida Networks, Inc., please see
326 * <http://www.vovida.org/>.
327 *
328 */

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