/[resiprocate]/main/resip/dum/test/testSMIMEInvite.cxx
ViewVC logotype

Contents of /main/resip/dum/test/testSMIMEInvite.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8437 - (show annotations) (download)
Wed Mar 4 23:47:10 2009 UTC (10 years, 9 months ago) by adam
File MIME type: text/plain
File size: 14850 byte(s)
Fixing various C++ language violations, mostly due to unintended symbol hiding

1 #include "resip/dum/DialogUsageManager.hxx"
2 #include "resip/dum/ClientRegistration.hxx"
3 #include "resip/dum/ClientInviteSession.hxx"
4 #include "resip/dum/ServerInviteSession.hxx"
5 #include "resip/dum/ClientAuthManager.hxx"
6
7 #include "resip/dum/RegistrationHandler.hxx"
8 #include "resip/dum/InviteSessionHandler.hxx"
9 #include "resip/dum/DumShutdownHandler.hxx"
10
11 #include "resip/dum/MasterProfile.hxx"
12 #include "resip/stack/ShutdownMessage.hxx"
13
14 #include "resip/stack/SdpContents.hxx"
15 #include "resip/stack/Pkcs7Contents.hxx"
16 #include "resip/stack/MultipartSignedContents.hxx"
17 #include "resip/stack/MultipartAlternativeContents.hxx"
18 #include "resip/stack/Mime.hxx"
19
20 #include "resip/stack/SecurityAttributes.hxx"
21 #include "resip/stack/Helper.hxx"
22
23 #include "rutil/Log.hxx"
24 #include "rutil/Logger.hxx"
25
26 #ifdef WIN32
27 #include "resip/stack/ssl/WinSecurity.hxx"
28 #else
29 #include "resip/stack/ssl/Security.hxx"
30 #endif
31
32 #include "TestDumHandlers.hxx"
33
34 #include <time.h>
35 #include <sstream>
36
37 using namespace std;
38 using namespace resip;
39
40 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
41
42
43 class TestSMIMEInviteHandler : public TestClientRegistrationHandler,
44 public TestInviteSessionHandler,
45 public TestDumShutdownHandler
46 {
47 public:
48
49 TestSMIMEInviteHandler(Security *sec) : handles(0), security(sec), registered(0), done(0), dumShutDown(0), connected(0), callFailed(false)
50 {
51 }
52
53 virtual ~TestSMIMEInviteHandler()
54 {
55 }
56
57 void resetRegistered(void)
58 {
59 registered = 0;
60 }
61
62 bool isConnected(void)
63 {
64 return (connected == 2);
65 }
66
67 bool isDumShutDown(void)
68 {
69 return (dumShutDown == 2);
70 }
71
72 bool isRegistered(void)
73 {
74 return (registered == 2);
75 }
76
77 bool isDone(void)
78 {
79 return (done == 2);
80
81 }
82
83 bool isCallFailed(void)
84 {
85 return callFailed;
86 }
87
88 SdpContents* generateBody()
89 {
90 HeaderFieldValue* hfv;
91 Data* txt = new Data("v=0\r\n"
92 "o=1900 369696545 369696545 IN IP4 192.168.2.15\r\n"
93 "s=X-Lite\r\n"
94 "c=IN IP4 192.168.2.15\r\n"
95 "t=0 0\r\n"
96 "m=audio 8000 RTP/AVP 8 3 101\r\n"
97 "a=rtpmap:8 pcma/8000\r\n"
98 "a=rtpmap:3 gsm/8000\r\n"
99 "a=rtpmap:101 telephone-event/8000\r\n"
100 "a=fmtp:101 0-15\r\n");
101
102 hfv = new HeaderFieldValue(txt->data(), txt->size());
103 SdpContents *sdp = new SdpContents(hfv, Mime("application", "sdp"));
104 return sdp;
105 }
106
107
108 virtual void onSuccess(ClientRegistrationHandle r,
109 const SipMessage& response)
110 {
111 InfoLog( << "ClientRegistrationHandler::onSuccess" );
112 handles.push_back(r);
113 registered++;
114 }
115
116 virtual void onConnected(ClientInviteSessionHandle,
117 const SipMessage& msg)
118 {
119 InfoLog( << "ClientInviteSessionHandler::onConnected" );
120 connected++;
121 }
122
123 using TestClientRegistrationHandler::onFailure;
124 virtual void onFailure(ClientInviteSessionHandle,
125 const SipMessage& msg)
126 {
127 InfoLog( << "TestInviteSessionHander::onFailure" );
128 callFailed = true;
129 }
130
131 using TestInviteSessionHandler::onNewSession;
132 virtual void onNewSession(ServerInviteSessionHandle is,
133 InviteSession::OfferAnswerType oat,
134 const SipMessage& msg)
135 {
136 InfoLog( << "ServerInviteSessionHandler::onNewSession" );
137 sis = is;
138 is->provisional(180);
139 }
140
141 virtual void onConnected(InviteSessionHandle,
142 const SipMessage& msg)
143 {
144 InfoLog( << "InviteSessionHandler::onConnected()" );
145 connected++;
146 }
147
148 virtual void onTerminated(InviteSessionHandle,
149 InviteSessionHandler::TerminatedReason reason,
150 const SipMessage* msg)
151 {
152 InfoLog( << "InviteSessionHandler::onTerminated");
153 done++;
154 }
155
156 virtual void onOffer(InviteSessionHandle is,
157 const SipMessage& msg,
158 const SdpContents& sdp)
159 {
160 InfoLog( << "InviteSessionHandler::onOffer" );
161 InfoLog( << "Server received SDP: " << sdp );
162
163 const SecurityAttributes *attr = msg.getSecurityAttributes();
164 if (attr)
165 {
166 InfoLog( << *attr );
167 }
168 else
169 {
170 InfoLog( << "no Security Attributes" );
171 }
172
173 if (sis.isValid())
174 {
175 NameAddr fromAor(msg.header(h_From).uri());
176 NameAddr toAor(msg.header(h_To).uri());
177 is->provideAnswer(*generateBody());
178 sis->accept();
179 }
180 }
181
182 virtual void onAnswer(InviteSessionHandle,
183 const SipMessage& msg,
184 const SdpContents& sdp)
185 {
186 InfoLog( << "InviteSessionHandler::onAnswer");
187 InfoLog( << "Client received SDP: " << sdp );
188
189 const SecurityAttributes *attr = msg.getSecurityAttributes();
190 if (attr)
191 {
192 InfoLog( << *attr );
193 }
194 else
195 {
196 InfoLog( << "no Security Attributes" );
197 }
198
199 }
200
201 virtual void onDumCanBeDeleted()
202 {
203 InfoLog( << "DumShutDownHandler::onDumCanBeDeleted" );
204 dumShutDown++;
205 }
206
207 virtual void onReferNoSub(InviteSessionHandle, const SipMessage& msg)
208 {
209 InfoLog(<< "InviteSessionHandler::onReferNoSub(): " << msg.brief());
210 }
211
212 public:
213 std::vector<ClientRegistrationHandle> handles;
214 ServerInviteSessionHandle sis;
215
216 private:
217 Security *security;
218 int registered;
219 int done;
220 int dumShutDown;
221 int connected;
222 bool callFailed;
223
224 };
225
226
227 int
228 main (int argc, char** argv)
229 {
230 if ( argc < 5 ) {
231 cout << "usage: " << argv[0] << " sip:user1 passwd1 sip:user2 passwd2" << endl;
232 return 1;
233 }
234
235 Log::initialize(Log::Cout, Log::Debug, argv[0]);
236
237 NameAddr clientAor(argv[1]);
238 Data clientPasswd(argv[2]);
239 NameAddr serverAor(argv[3]);
240 Data serverPasswd(argv[4]);
241
242 #ifdef WIN32
243 Security* security = new WinSecurity;
244 #else
245 Security* security = new Security;
246 #endif
247
248 TestSMIMEInviteHandler handler(security);
249
250 // set up UAC
251 SipStack clientStack(security);
252 DialogUsageManager clientDum(clientStack);
253 srand(time(NULL));
254 clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V4);
255 clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V4);
256 clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V4);
257 #ifdef USE_IPV6
258 clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V6);
259 clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V6);
260 clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V6);
261 #endif
262
263 SharedPtr<MasterProfile> clientProfile(new MasterProfile);
264 auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager());
265
266 clientDum.setClientAuthManager(clientAuth);
267 clientDum.setClientRegistrationHandler(&handler);
268 clientDum.setInviteSessionHandler(&handler);
269
270 clientProfile->setDefaultFrom(clientAor);
271 clientProfile->setDigestCredential(clientAor.uri().host(),clientAor.uri().user(),clientPasswd);
272 clientProfile->setDefaultRegistrationTime(60);
273 clientProfile->addSupportedMethod(INVITE);
274 clientProfile->addSupportedMimeType(INVITE, Mime("application", "pkcs7-mime"));
275 clientProfile->addSupportedMimeType(INVITE, Mime("multipart", "signed"));
276 clientProfile->addSupportedMimeType(INVITE, Mime("multipart", "alternative"));
277 clientDum.setMasterProfile(clientProfile);
278
279 //set up UAS
280 SipStack serverStack(security);
281 DialogUsageManager serverDum(serverStack);
282 //serverDum.addTransport(UDP, 10000 + rand()&0x7fff, V4);
283 serverDum.addTransport(TCP, 10000 + rand()&0x7fff, V4);
284 //serverDum.addTransport(TLS, 10000 + rand()&0x7fff, V4);
285
286 SharedPtr<MasterProfile> serverProfile(new MasterProfile);
287 std::auto_ptr<ClientAuthManager> serverAuth(new ClientAuthManager);
288
289 serverDum.setClientAuthManager(serverAuth);
290 serverDum.setClientRegistrationHandler(&handler);
291 serverDum.setInviteSessionHandler(&handler);
292
293 serverProfile->setDefaultFrom(serverAor);
294 serverProfile->setDigestCredential(serverAor.uri().host(),serverAor.uri().user(),serverPasswd);
295 serverProfile->setDefaultRegistrationTime(60);
296 serverProfile->addSupportedMethod(INVITE);
297 serverProfile->addSupportedMimeType(INVITE, Mime("application", "pkcs7-mime"));
298 serverProfile->addSupportedMimeType(INVITE, Mime("multipart", "signed"));
299 serverProfile->addSupportedMimeType(INVITE, Mime("multipart", "alternative"));
300 serverDum.setMasterProfile(serverProfile);
301
302 enum
303 {
304 Registering,
305 Inviting,
306 Waiting,
307 HangingUp,
308 Unregistering,
309 ShuttingDown,
310 Finished
311 } state;
312 time_t endTime;
313
314 // register client and server
315 SharedPtr<SipMessage> clientRegMessage = clientDum.makeRegistration(clientAor);
316 clientDum.send(clientRegMessage);
317 SharedPtr<SipMessage> serverRegMessage = serverDum.makeRegistration(serverAor);
318 serverDum.send(serverRegMessage);
319 state = Registering;
320
321 while (state != Finished)
322 {
323 FdSet fdset;
324
325 clientStack.buildFdSet(fdset);
326 serverStack.buildFdSet(fdset);
327
328 int err = fdset.selectMilliSeconds(resipMin((int)clientStack.getTimeTillNextProcessMS(), 50));
329 assert ( err != -1 );
330
331 clientStack.process(fdset);
332 serverStack.process(fdset);
333 while(clientDum.process() || serverDum.process());
334
335 switch (state)
336 {
337 case Registering:
338 {
339 if (handler.isRegistered())
340 {
341 InfoLog( << "Sending INVITE request" );
342 clientDum.send(clientDum.makeInviteSession(serverAor,
343 handler.generateBody()));
344 state = Inviting;
345 }
346 break;
347 }
348
349 case Inviting:
350 {
351 if (handler.isConnected())
352 {
353 InfoLog( << "Starting timer, waiting for 5 seconds" );
354 endTime = time(NULL) + 5;
355 state = Waiting;
356 }
357 break;
358 }
359
360 case Waiting:
361 {
362 if (handler.isCallFailed())
363 {
364 InfoLog( << "Call Failed" );
365 for (std::vector<ClientRegistrationHandle>::iterator it = handler.handles.begin();
366 it != handler.handles.end(); it++)
367 {
368 (*it)->end();
369 }
370 state = Unregistering;
371 }
372
373 if (time(NULL) > endTime)
374 {
375 InfoLog( << "Timer expired, hanging up" );
376 handler.sis->end();
377 state = HangingUp;
378 }
379 break;
380 }
381
382 case HangingUp:
383 {
384 if (handler.isDone())
385 {
386 for (std::vector<ClientRegistrationHandle>::iterator it = handler.handles.begin();
387 it != handler.handles.end(); it++)
388 {
389 (*it)->end();
390 }
391 state = Unregistering;
392 }
393 break;
394 }
395
396 case Unregistering:
397 {
398 if (handler.isRegistered())
399 {
400 InfoLog( << "Shutting down" );
401 serverDum.shutdown(&handler);
402 clientDum.shutdown(&handler);
403 state = ShuttingDown;
404 }
405 break;
406 }
407
408 case ShuttingDown:
409 {
410 if (handler.isDumShutDown())
411 {
412 InfoLog( << "Finished" );
413 state = Finished;
414 }
415
416 break;
417 }
418
419 default:
420 {
421 InfoLog( << "Unrecognised state" );
422 assert(0);
423 }
424 }
425
426 }
427
428 return 0;
429
430 }
431
432 /* ====================================================================
433 * The Vovida Software License, Version 1.0
434 *
435 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
436 *
437 * Redistribution and use in source and binary forms, with or without
438 * modification, are permitted provided that the following conditions
439 * are met:
440 *
441 * 1. Redistributions of source code must retain the above copyright
442 * notice, this list of conditions and the following disclaimer.
443 *
444 * 2. Redistributions in binary form must reproduce the above copyright
445 * notice, this list of conditions and the following disclaimer in
446 * the documentation and/or other materials provided with the
447 * distribution.
448 *
449 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
450 * and "Vovida Open Communication Application Library (VOCAL)" must
451 * not be used to endorse or promote products derived from this
452 * software without prior written permission. For written
453 * permission, please contact vocal@vovida.org.
454 *
455 * 4. Products derived from this software may not be called "VOCAL", nor
456 * may "VOCAL" appear in their name, without prior written
457 * permission of Vovida Networks, Inc.
458 *
459 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
460 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
461 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
462 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
463 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
464 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
465 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
466 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
467 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
468 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
469 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
470 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
471 * DAMAGE.
472 *
473 * ====================================================================
474 *
475 * This software consists of voluntary contributions made by Vovida
476 * Networks, Inc. and many individuals on behalf of Vovida Networks,
477 * Inc. For more information on Vovida Networks, Inc., please see
478 * <http://www.vovida.org/>.
479 *
480 */

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