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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9392 - (show annotations) (download)
Fri Feb 10 18:19:59 2012 UTC (7 years, 9 months ago) by sgodin
File MIME type: text/plain
File size: 16481 byte(s)
-merged work from b-repro-enh-20120205 branch

-added a new Command interface/server to repro that operates over a TCP socket and uses
 XML formatted messaging
-implemented the following commands:
  - GetStackInfo
  - GetStackStats
  - ResetStackStats
  - LogDnsCache
  - ClearDnsCache
  - GetDnsCache
  - GetCongestionStats
  - SetCongestionTolerance
  - Shutdown
  - GetProxyConfig
-added new reprocmd executable that connects to repro via new command socket server and sends commands
 base on command line arguments
-moved XMLCursor class from resip/stack to rutil

-added operator<< for Statistics Payload
-added ability to encode Congestion stats to a stream 
-modified GeneralCongestionManager::updateFifoTolerance to allow updating
 all fifos by specifying fifoDescription as an empty string
-added current fifo behaviour and tolerance settings to congestion stats output
-renamed configuration setting XmlRpcPort to RegSyncPort to differentiate it with new Command Port setting
-add new TCP server (CommandServer) to repro that accepts commands via XML formatted messages
-allow SipStack statistics to be reset/zero'd out
-modified GetStackStats command to be able to retrieve statistics that are accurate at the time of the request, 
 instead of just returning the statistics as of the last statistics interval
-added operator<< to ConfigParse

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

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