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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10833 - (show annotations) (download)
Sun Jan 5 18:06:08 2014 UTC (5 years, 5 months ago) by sgodin
File MIME type: text/plain
File size: 28622 byte(s)
-use SipStack addTransport instead of newly deprecated DiaglogUsageManager::addTransport 
1 #include "resip/stack/SdpContents.hxx"
2 #include "resip/stack/PlainContents.hxx"
3 #include "resip/stack/SipMessage.hxx"
4 #include "resip/stack/ShutdownMessage.hxx"
5 #include "resip/stack/SipStack.hxx"
6 #include "resip/dum/ClientAuthManager.hxx"
7 #include "resip/dum/ClientInviteSession.hxx"
8 #include "resip/dum/ClientRegistration.hxx"
9 #include "resip/dum/DialogUsageManager.hxx"
10 #include "resip/dum/DumShutdownHandler.hxx"
11 #include "resip/dum/InviteSessionHandler.hxx"
12 #include "resip/dum/MasterProfile.hxx"
13 #include "resip/dum/RegistrationHandler.hxx"
14 #include "resip/dum/ServerInviteSession.hxx"
15 #include "resip/dum/ServerOutOfDialogReq.hxx"
16 #include "resip/dum/OutOfDialogHandler.hxx"
17 #include "resip/dum/AppDialog.hxx"
18 #include "resip/dum/AppDialogSet.hxx"
19 #include "resip/dum/AppDialogSetFactory.hxx"
20 #include "rutil/Log.hxx"
21 #include "rutil/Logger.hxx"
22 #include "rutil/Random.hxx"
23 #include "rutil/WinLeakCheck.hxx"
24
25 #include <sstream>
26 #include <time.h>
27
28 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
29 /* #define NO_REGISTRATION 1 -- This is now run-time option */
30
31 using namespace resip;
32 using namespace std;
33
34 /////////////////////////////////////////////////////////////////////////////////
35 //
36 // Classes that provide the mapping between Application Data and DUM
37 // dialogs/dialogsets
38 //
39 // The DUM layer creates an AppDialog/AppDialogSet object for inbound/outbound
40 // SIP Request that results in Dialog creation.
41 //
42 /////////////////////////////////////////////////////////////////////////////////
43 class testAppDialog : public AppDialog
44 {
45 public:
46 testAppDialog(HandleManager& ham, Data &SampleAppData) : AppDialog(ham), mSampleAppData(SampleAppData)
47 {
48 cout << mSampleAppData << ": testAppDialog: created." << endl;
49 }
50 virtual ~testAppDialog()
51 {
52 cout << mSampleAppData << ": testAppDialog: destroyed." << endl;
53 }
54 Data mSampleAppData;
55 };
56
57 class testAppDialogSet : public AppDialogSet
58 {
59 public:
60 testAppDialogSet(DialogUsageManager& dum, Data SampleAppData) : AppDialogSet(dum), mSampleAppData(SampleAppData)
61 {
62 cout << mSampleAppData << ": testAppDialogSet: created." << endl;
63 }
64 virtual ~testAppDialogSet()
65 {
66 cout << mSampleAppData << ": testAppDialogSet: destroyed." << endl;
67 }
68 virtual AppDialog* createAppDialog(const SipMessage& msg)
69 {
70 return new testAppDialog(mDum, mSampleAppData);
71 }
72 virtual SharedPtr<UserProfile> selectUASUserProfile(const SipMessage& msg)
73 {
74 cout << mSampleAppData << ": testAppDialogSet: UAS UserProfile requested for msg: " << msg.brief() << endl;
75 return mDum.getMasterUserProfile();
76 }
77 Data mSampleAppData;
78 };
79
80 class testAppDialogSetFactory : public AppDialogSetFactory
81 {
82 public:
83 virtual AppDialogSet* createAppDialogSet(DialogUsageManager& dum, const SipMessage& msg)
84 { return new testAppDialogSet(dum, Data("UAS") + Data("(") + getMethodName(msg.header(h_RequestLine).getMethod()) + Data(")")); }
85 // For a UAS the testAppDialogSet will be created by DUM using this function. If you want to set
86 // Application Data, then one approach is to wait for onNewSession(ServerInviteSessionHandle ...)
87 // to be called, then use the ServerInviteSessionHandle to get at the AppDialogSet or AppDialog,
88 // then cast to your derived class and set the desired application data.
89 };
90
91
92 // Generic InviteSessionHandler
93 class TestInviteSessionHandler : public InviteSessionHandler, public ClientRegistrationHandler, public OutOfDialogHandler
94 {
95 public:
96 Data name;
97 bool registered;
98 ClientRegistrationHandle registerHandle;
99
100 TestInviteSessionHandler(const Data& n) : name(n), registered(false)
101 {
102 }
103
104 virtual ~TestInviteSessionHandler()
105 {
106 }
107
108 virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response)
109 {
110 registerHandle = h;
111 assert(registerHandle.isValid());
112 cout << name << ": ClientRegistration-onSuccess - " << response.brief() << endl;
113 registered = true;
114 }
115
116 virtual void onFailure(ClientRegistrationHandle, const SipMessage& msg)
117 {
118 cout << name << ": ClientRegistration-onFailure - " << msg.brief() << endl;
119 throw; // Ungracefully end
120 }
121
122 virtual void onRemoved(ClientRegistrationHandle, const SipMessage& response)
123 {
124 cout << name << ": ClientRegistration-onRemoved" << endl;
125 }
126
127 virtual int onRequestRetry(ClientRegistrationHandle, int retrySeconds, const SipMessage& response)
128 {
129 cout << name << ": ClientRegistration-onRequestRetry (" << retrySeconds << ") - " << response.brief() << endl;
130 return -1;
131 }
132
133 virtual void onNewSession(ClientInviteSessionHandle, InviteSession::OfferAnswerType oat, const SipMessage& msg)
134 {
135 cout << name << ": ClientInviteSession-onNewSession - " << msg.brief() << endl;
136 }
137
138 virtual void onNewSession(ServerInviteSessionHandle, InviteSession::OfferAnswerType oat, const SipMessage& msg)
139 {
140 cout << name << ": ServerInviteSession-onNewSession - " << msg.brief() << endl;
141 }
142
143 virtual void onFailure(ClientInviteSessionHandle, const SipMessage& msg)
144 {
145 cout << name << ": ClientInviteSession-onFailure - " << msg.brief() << endl;
146 }
147
148 virtual void onProvisional(ClientInviteSessionHandle, const SipMessage& msg)
149 {
150 cout << name << ": ClientInviteSession-onProvisional - " << msg.brief() << endl;
151 }
152
153 virtual void onConnected(ClientInviteSessionHandle, const SipMessage& msg)
154 {
155 cout << name << ": ClientInviteSession-onConnected - " << msg.brief() << endl;
156 }
157
158 virtual void onStaleCallTimeout(ClientInviteSessionHandle handle)
159 {
160 cout << name << ": ClientInviteSession-onStaleCallTimeout" << endl;
161 }
162
163 virtual void onConnected(InviteSessionHandle, const SipMessage& msg)
164 {
165 cout << name << ": InviteSession-onConnected - " << msg.brief() << endl;
166 }
167
168 virtual void onRedirected(ClientInviteSessionHandle, const SipMessage& msg)
169 {
170 cout << name << ": ClientInviteSession-onRedirected - " << msg.brief() << endl;
171 }
172
173 virtual void onTerminated(InviteSessionHandle, InviteSessionHandler::TerminatedReason reason, const SipMessage* msg)
174 {
175 cout << name << ": InviteSession-onTerminated - " << msg->brief() << endl;
176 assert(0); // This is overrideen in UAS and UAC specific handlers
177 }
178
179 virtual void onAnswer(InviteSessionHandle, const SipMessage& msg, const SdpContents& sdp)
180 {
181 cout << name << ": InviteSession-onAnswer(SDP)" << endl;
182 //sdp->encode(cout);
183 }
184
185 virtual void onOffer(InviteSessionHandle is, const SipMessage& msg, const SdpContents& sdp)
186 {
187 cout << name << ": InviteSession-onOffer(SDP)" << endl;
188 //sdp->encode(cout);
189 }
190
191 virtual void onEarlyMedia(ClientInviteSessionHandle, const SipMessage& msg, const SdpContents& sdp)
192 {
193 cout << name << ": InviteSession-onEarlyMedia(SDP)" << endl;
194 //sdp->encode(cout);
195 }
196
197 virtual void onOfferRequired(InviteSessionHandle, const SipMessage& msg)
198 {
199 cout << name << ": InviteSession-onOfferRequired - " << msg.brief() << endl;
200 }
201
202 virtual void onOfferRejected(InviteSessionHandle, const SipMessage* msg)
203 {
204 cout << name << ": InviteSession-onOfferRejected" << endl;
205 }
206
207 virtual void onRefer(InviteSessionHandle, ServerSubscriptionHandle, const SipMessage& msg)
208 {
209 cout << name << ": InviteSession-onRefer - " << msg.brief() << endl;
210 }
211
212 virtual void onReferAccepted(InviteSessionHandle, ClientSubscriptionHandle, const SipMessage& msg)
213 {
214 cout << name << ": InviteSession-onReferAccepted - " << msg.brief() << endl;
215 }
216
217 virtual void onReferRejected(InviteSessionHandle, const SipMessage& msg)
218 {
219 cout << name << ": InviteSession-onReferRejected - " << msg.brief() << endl;
220 }
221
222 virtual void onReferNoSub(InviteSessionHandle, const SipMessage& msg)
223 {
224 cout << name << ": InviteSession-onReferNoSub - " << msg.brief() << endl;
225 }
226
227 virtual void onInfo(InviteSessionHandle, const SipMessage& msg)
228 {
229 cout << name << ": InviteSession-onInfo - " << msg.brief() << endl;
230 }
231
232 virtual void onInfoSuccess(InviteSessionHandle, const SipMessage& msg)
233 {
234 cout << name << ": InviteSession-onInfoSuccess - " << msg.brief() << endl;
235 }
236
237 virtual void onInfoFailure(InviteSessionHandle, const SipMessage& msg)
238 {
239 cout << name << ": InviteSession-onInfoFailure - " << msg.brief() << endl;
240 }
241
242 virtual void onMessage(InviteSessionHandle, const SipMessage& msg)
243 {
244 cout << name << ": InviteSession-onMessage - " << msg.brief() << endl;
245 }
246
247 virtual void onMessageSuccess(InviteSessionHandle, const SipMessage& msg)
248 {
249 cout << name << ": InviteSession-onMessageSuccess - " << msg.brief() << endl;
250 }
251
252 virtual void onMessageFailure(InviteSessionHandle, const SipMessage& msg)
253 {
254 cout << name << ": InviteSession-onMessageFailure - " << msg.brief() << endl;
255 }
256
257 virtual void onForkDestroyed(ClientInviteSessionHandle)
258 {
259 cout << name << ": ClientInviteSession-onForkDestroyed" << endl;
260 }
261
262 // Out-of-Dialog Callbacks
263 virtual void onSuccess(ClientOutOfDialogReqHandle, const SipMessage& successResponse)
264 {
265 cout << name << ": ClientOutOfDialogReq-onSuccess - " << successResponse.brief() << endl;
266 }
267 virtual void onFailure(ClientOutOfDialogReqHandle, const SipMessage& errorResponse)
268 {
269 cout << name << ": ClientOutOfDialogReq-onFailure - " << errorResponse.brief() << endl;
270 }
271 virtual void onReceivedRequest(ServerOutOfDialogReqHandle ood, const SipMessage& request)
272 {
273 cout << name << ": ServerOutOfDialogReq-onReceivedRequest - " << request.brief() << endl;
274 // Add SDP to response here if required
275 cout << name << ": Sending 200 response to OPTIONS." << endl;
276 ood->send(ood->answerOptions());
277 }
278 };
279
280 class TestUac : public TestInviteSessionHandler
281 {
282 public:
283 bool done;
284 SdpContents* mSdp;
285 HeaderFieldValue* hfv;
286 Data* txt;
287 int mNumExpectedMessages;
288
289 TestUac()
290 : TestInviteSessionHandler("UAC"),
291 done(false),
292 mSdp(0),
293 hfv(0),
294 txt(0),
295 mNumExpectedMessages(2)
296 {
297 txt = new Data("v=0\r\n"
298 "o=1900 369696545 369696545 IN IP4 192.168.2.15\r\n"
299 "s=X-Lite\r\n"
300 "c=IN IP4 192.168.2.15\r\n"
301 "t=0 0\r\n"
302 "m=audio 8000 RTP/AVP 8 3 98 97 101\r\n"
303 "a=rtpmap:8 pcma/8000\r\n"
304 "a=rtpmap:3 gsm/8000\r\n"
305 "a=rtpmap:98 iLBC\r\n"
306 "a=rtpmap:97 speex/8000\r\n"
307 "a=rtpmap:101 telephone-event/8000\r\n"
308 "a=fmtp:101 0-15\r\n");
309
310 hfv = new HeaderFieldValue(txt->data(), (unsigned int)txt->size());
311 Mime type("application", "sdp");
312 mSdp = new SdpContents(*hfv, type);
313 }
314
315 virtual ~TestUac()
316 {
317 assert(mNumExpectedMessages == 0);
318 delete mSdp;
319 delete txt;
320 delete hfv;
321 }
322
323 virtual void onOffer(InviteSessionHandle is, const SipMessage& msg, const SdpContents& sdp)
324 {
325 cout << name << ": InviteSession-onOffer(SDP)" << endl;
326 //sdp->encode(cout);
327 is->provideAnswer(sdp);
328 }
329
330 using TestInviteSessionHandler::onConnected;
331 virtual void onConnected(ClientInviteSessionHandle is, const SipMessage& msg)
332 {
333 cout << name << ": ClientInviteSession-onConnected - " << msg.brief() << endl;
334 cout << "Connected now - requestingOffer from UAS" << endl;
335 is->requestOffer();
336
337 // At this point no NIT should have been sent
338 assert(!is->getLastSentNITRequest());
339
340 // Send a first MESSAGE from UAC with some contents (we use a fake PlainContents contents here for
341 // simplicity)
342 PlainContents contents("Hi there!!!");
343 is->message(contents);
344
345 // Immediately send another one, which will end up queued on the
346 // InviteSession's NIT queue
347 PlainContents contentsOther("Hi again!!!");
348 is->message(contentsOther);
349 }
350
351 virtual void onMessageSuccess(InviteSessionHandle is, const SipMessage& msg)
352 {
353 cout << name << ": InviteSession-onMessageSuccess - " << msg.brief() << endl;
354
355 assert(is->getLastSentNITRequest());
356 PlainContents* pContents = dynamic_cast<PlainContents*>(is->getLastSentNITRequest()->getContents());
357 assert(pContents != NULL);
358
359 if(mNumExpectedMessages == 2)
360 {
361 assert(pContents->text() == Data("Hi there!!!"));
362 mNumExpectedMessages--;
363 }
364 else if(mNumExpectedMessages == 1)
365 {
366 assert(pContents->text() == Data("Hi again!!!"));
367 mNumExpectedMessages--;
368 }
369 }
370
371 virtual void onInfo(InviteSessionHandle is, const SipMessage& msg)
372 {
373 cout << name << ": InviteSession-onInfo - " << msg.brief() << endl;
374 is->acceptNIT();
375 }
376
377 virtual void onTerminated(InviteSessionHandle, InviteSessionHandler::TerminatedReason reason, const SipMessage* msg)
378 {
379 if(msg)
380 {
381 cout << name << ": InviteSession-onTerminated - " << msg->brief() << endl;
382 }
383 else
384 {
385 cout << name << ": InviteSession-onTerminated" << endl;
386 }
387 done = true;
388 }
389 };
390
391 class TestUas : public TestInviteSessionHandler
392 {
393
394 public:
395 bool done;
396 bool requestedOffer;
397 time_t* pHangupAt;
398
399 SdpContents* mSdp;
400 HeaderFieldValue* hfv;
401 Data* txt;
402
403 int mNumExpectedInfos;
404
405 TestUas(time_t* pH)
406 : TestInviteSessionHandler("UAS"),
407 done(false),
408 requestedOffer(false),
409 pHangupAt(pH),
410 hfv(0),
411 mNumExpectedInfos(2)
412 {
413 txt = new Data("v=0\r\n"
414 "o=1900 369696545 369696545 IN IP4 192.168.2.15\r\n"
415 "s=X-Lite\r\n"
416 "c=IN IP4 192.168.2.15\r\n"
417 "t=0 0\r\n"
418 "m=audio 8001 RTP/AVP 8 3 98 97 101\r\n"
419 "a=rtpmap:8 pcma/8000\r\n"
420 "a=rtpmap:3 gsm/8000\r\n"
421 "a=rtpmap:98 iLBC\r\n"
422 "a=rtpmap:97 speex/8000\r\n"
423 "a=rtpmap:101 telephone-event/8000\r\n"
424 "a=fmtp:101 0-15\r\n");
425
426 hfv = new HeaderFieldValue(txt->data(), (unsigned int)txt->size());
427 Mime type("application", "sdp");
428 mSdp = new SdpContents(*hfv, type);
429 }
430
431 ~TestUas()
432 {
433 assert(mNumExpectedInfos == 0);
434 delete mSdp;
435 delete txt;
436 delete hfv;
437 }
438
439 using TestInviteSessionHandler::onNewSession;
440 virtual void
441 onNewSession(ServerInviteSessionHandle sis, InviteSession::OfferAnswerType oat, const SipMessage& msg)
442 {
443 cout << name << ": ServerInviteSession-onNewSession - " << msg.brief() << endl;
444 cout << name << ": Sending 180 response." << endl;
445 mSis = sis;
446 sis->provisional(180);
447 }
448
449 virtual void onTerminated(InviteSessionHandle, InviteSessionHandler::TerminatedReason reason, const SipMessage* msg)
450 {
451 cout << name << ": InviteSession-onTerminated - " << endl;
452 done = true;
453 }
454
455 virtual void onOffer(InviteSessionHandle is, const SipMessage& msg, const SdpContents& sdp)
456 {
457 cout << name << ": InviteSession-onOffer(SDP)" << endl;
458 //sdp->encode(cout);
459 cout << name << ": Sending 200 response with SDP answer." << endl;
460 is->provideAnswer(sdp);
461 mSis->accept();
462 }
463
464 virtual void onOfferRequired(InviteSessionHandle is, const SipMessage& msg)
465 {
466 cout << name << ": InviteSession-onOfferRequired - " << msg.brief() << endl;
467 is->provideOffer(*mSdp);
468 }
469
470 virtual void onConnected(InviteSessionHandle is, const SipMessage& msg)
471 {
472 cout << name << ": InviteSession-onConnected - " << msg.brief() << endl;
473
474 // At this point no NIT should have been sent
475 assert(!is->getLastSentNITRequest());
476
477 // Send a first INFO from UAS with some contents (we use a fake PlainContents contents here for
478 // simplicity)
479 PlainContents contents("Hello there!!!");
480 is->info(contents);
481
482 // Immediately send another one, which will end up queued on the
483 // InviteSession's NIT queue
484 PlainContents contentsOther("Hello again!!!");
485 is->info(contentsOther);
486 }
487
488 virtual void onInfoSuccess(InviteSessionHandle is, const SipMessage& msg)
489 {
490 cout << name << ": InviteSession-onInfoSuccess - " << msg.brief() << endl;
491
492 assert(is->getLastSentNITRequest());
493 PlainContents* pContents = dynamic_cast<PlainContents*>(is->getLastSentNITRequest()->getContents());
494 assert(pContents != NULL);
495
496 if(mNumExpectedInfos == 2)
497 {
498 assert(pContents->text() == Data("Hello there!!!"));
499 mNumExpectedInfos--;
500 }
501 else if(mNumExpectedInfos == 1)
502 {
503 assert(pContents->text() == Data("Hello again!!!"));
504 mNumExpectedInfos--;
505
506 // Schedule a BYE in 5 seconds
507 if(*pHangupAt == 0)
508 {
509 *pHangupAt = time(NULL) + 5;
510 }
511 }
512 }
513
514 virtual void onMessage(InviteSessionHandle is, const SipMessage& msg)
515 {
516 cout << name << ": InviteSession-onMessage - " << msg.brief() << endl;
517
518 is->acceptNIT();
519 }
520
521 // Normal people wouldn't put this functionality in the handler
522 // it's a kludge for this test for right now
523 void hangup()
524 {
525 if (mSis.isValid())
526 {
527 cout << name << ": Sending BYE." << endl;
528 mSis->end();
529 done = true;
530 }
531 }
532 private:
533 ServerInviteSessionHandle mSis;
534 };
535
536 class TestShutdownHandler : public DumShutdownHandler
537 {
538 public:
539 TestShutdownHandler(const Data& n) : name(n), dumShutDown(false) { }
540 virtual ~TestShutdownHandler(){}
541
542 Data name;
543 bool dumShutDown;
544 virtual void onDumCanBeDeleted()
545 {
546 cout << name << ": onDumCanBeDeleted." << endl;
547 dumShutDown = true;
548 }
549 };
550
551
552 int
553 main (int argc, char** argv)
554 {
555 //Log::initialize(Log::Cout, resip::Log::Warning, argv[0]);
556 //Log::initialize(Log::Cout, resip::Log::Debug, argv[0]);
557 Log::initialize(Log::Cout, resip::Log::Info, argv[0]);
558 //Log::initialize(Log::Cout, resip::Log::Debug, argv[0]);
559
560 #if defined(WIN32) && defined(_DEBUG) && defined(LEAK_CHECK)
561 FindMemoryLeaks fml;
562 {
563 #endif
564 bool doReg = false;
565 NameAddr uacAor;
566 NameAddr uasAor;
567 Data uacPasswd;
568 Data uasPasswd;
569 bool useOutbound = false;
570 Uri outboundUri;
571
572 if ( argc == 1 )
573 {
574 uacAor = NameAddr("sip:UAC@127.0.0.1:12005");
575 uasAor = NameAddr("sip:UAS@127.0.0.1:12010");
576 cout << "Skipping registration (no arguments)." << endl;
577 }
578 else
579 {
580 if ( argc < 5 )
581 {
582 cout << "usage: " << argv[0] <<
583 " sip:user1 passwd1 sip:user2 passwd2 [outbound]" << endl;
584 return 1;
585 }
586 doReg = true;
587 uacAor = NameAddr(argv[1]);
588 uacPasswd = Data(argv[2]);
589 uasAor = NameAddr(argv[3]);
590 uasPasswd = Data(argv[4]);
591 if ( argc >= 6 )
592 {
593 useOutbound = true;
594 outboundUri = Uri(Data(argv[5]));
595 }
596 }
597
598 //set up UAC
599 SipStack stackUac;
600 DialogUsageManager* dumUac = new DialogUsageManager(stackUac);
601 stackUac.addTransport(UDP, 12005);
602 stackUac.addTransport(TCP, 12005);
603
604 SharedPtr<MasterProfile> uacMasterProfile(new MasterProfile);
605 auto_ptr<ClientAuthManager> uacAuth(new ClientAuthManager);
606 dumUac->setMasterProfile(uacMasterProfile);
607 dumUac->setClientAuthManager(uacAuth);
608
609 TestUac uac;
610 dumUac->setInviteSessionHandler(&uac);
611 dumUac->setClientRegistrationHandler(&uac);
612 dumUac->addOutOfDialogHandler(OPTIONS, &uac);
613
614 auto_ptr<AppDialogSetFactory> uac_dsf(new testAppDialogSetFactory);
615 dumUac->setAppDialogSetFactory(uac_dsf);
616
617 if ( doReg )
618 {
619 dumUac->getMasterProfile()->setDigestCredential(uacAor.uri().host(), uacAor.uri().user(), uacPasswd);
620 }
621 if (useOutbound)
622 {
623 dumUac->getMasterProfile()->setOutboundProxy(outboundUri);
624 dumUac->getMasterProfile()->addSupportedOptionTag(Token(Symbols::Outbound));
625 }
626
627 dumUac->getMasterProfile()->setDefaultFrom(uacAor);
628 dumUac->getMasterProfile()->addSupportedMethod(INFO);
629 dumUac->getMasterProfile()->addSupportedMethod(MESSAGE);
630 dumUac->getMasterProfile()->addSupportedMimeType(INFO, PlainContents::getStaticType());
631 dumUac->getMasterProfile()->addSupportedMimeType(MESSAGE, PlainContents::getStaticType());
632 dumUac->getMasterProfile()->setDefaultRegistrationTime(70);
633
634 //set up UAS
635 SipStack stackUas;
636 DialogUsageManager* dumUas = new DialogUsageManager(stackUas);
637 stackUas.addTransport(UDP, 12010);
638 stackUas.addTransport(TCP, 12010);
639
640 SharedPtr<MasterProfile> uasMasterProfile(new MasterProfile);
641 std::auto_ptr<ClientAuthManager> uasAuth(new ClientAuthManager);
642 dumUas->setMasterProfile(uasMasterProfile);
643 dumUas->setClientAuthManager(uasAuth);
644
645 if(doReg)
646 {
647 dumUas->getMasterProfile()->setDigestCredential(uasAor.uri().host(), uasAor.uri().user(), uasPasswd);
648 }
649 if(useOutbound)
650 {
651 dumUas->getMasterProfile()->setOutboundProxy(outboundUri);
652 dumUas->getMasterProfile()->addSupportedOptionTag(Token(Symbols::Outbound));
653 }
654
655 dumUas->getMasterProfile()->setDefaultFrom(uasAor);
656 dumUas->getMasterProfile()->addSupportedMethod(INFO);
657 dumUas->getMasterProfile()->addSupportedMethod(MESSAGE);
658 dumUas->getMasterProfile()->addSupportedMimeType(INFO, PlainContents::getStaticType());
659 dumUas->getMasterProfile()->addSupportedMimeType(MESSAGE, PlainContents::getStaticType());
660 dumUas->getMasterProfile()->setDefaultRegistrationTime(70);
661
662 time_t bHangupAt = 0;
663 TestUas uas(&bHangupAt);
664 dumUas->setClientRegistrationHandler(&uas);
665 dumUas->setInviteSessionHandler(&uas);
666 dumUas->addOutOfDialogHandler(OPTIONS, &uas);
667
668 auto_ptr<AppDialogSetFactory> uas_dsf(new testAppDialogSetFactory);
669 dumUas->setAppDialogSetFactory(uas_dsf);
670
671 if (doReg)
672 {
673 SharedPtr<SipMessage> regMessage = dumUas->makeRegistration(uasAor, new testAppDialogSet(*dumUac, "UAS(Registration)"));
674 cout << "Sending register for Uas: " << endl << regMessage << endl;
675 dumUas->send(regMessage);
676 }
677 else
678 {
679 uas.registered = true;
680 }
681 if (doReg)
682 {
683 SharedPtr<SipMessage> regMessage = dumUac->makeRegistration(uacAor, new testAppDialogSet(*dumUac, "UAC(Registration)"));
684 cout << "Sending register for Uac: " << endl << regMessage << endl;
685 dumUac->send(regMessage);
686 }
687 else
688 {
689 uac.registered = true;
690 }
691
692 bool finishedTest = false;
693 bool stoppedRegistering = false;
694 bool startedCallFlow = false;
695 bool hungup = false;
696 TestShutdownHandler uasShutdownHandler("UAS");
697 TestShutdownHandler uacShutdownHandler("UAC");
698
699 while (!(uasShutdownHandler.dumShutDown && uacShutdownHandler.dumShutDown))
700 {
701 if (!uacShutdownHandler.dumShutDown)
702 {
703 stackUac.process(50);
704 while(dumUac->process());
705 }
706 if (!uasShutdownHandler.dumShutDown)
707 {
708 stackUas.process(50);
709 while(dumUas->process());
710 }
711
712 if (!(uas.done && uac.done))
713 {
714 if (uas.registered && uac.registered && !startedCallFlow)
715 {
716 if (!startedCallFlow)
717 {
718 startedCallFlow = true;
719 if ( doReg ) {
720 cout << "!!!!!!!!!!!!!!!! Registered !!!!!!!!!!!!!!!! " << endl;
721 }
722
723 // Kick off call flow by sending an OPTIONS request then an INVITE request from the UAC to the UAS
724 cout << "UAC: Sending Options Request to UAS." << endl;
725 dumUac->send(dumUac->makeOutOfDialogRequest(uasAor, OPTIONS, new testAppDialogSet(*dumUac, "UAC(OPTIONS)"))); // Should probably add Allow, Accept, Accept-Encoding, Accept-Language and Supported headers - but this is fine for testing/demonstration
726
727 cout << "UAC: Sending Invite Request to UAS." << endl;
728 dumUac->send(dumUac->makeInviteSession(uasAor, uac.mSdp, new testAppDialogSet(*dumUac, "UAC(INVITE)")));
729 }
730 }
731
732 // Check if we should hangup yet
733 if (bHangupAt!=0)
734 {
735 if (time(NULL)>bHangupAt && !hungup)
736 {
737 hungup = true;
738 uas.hangup();
739 }
740 }
741 }
742 else
743 {
744 if (!stoppedRegistering)
745 {
746 finishedTest = true;
747 stoppedRegistering = true;
748 dumUas->shutdown(&uasShutdownHandler);
749 dumUac->shutdown(&uacShutdownHandler);
750 if ( doReg )
751 {
752 uas.registerHandle->stopRegistering();
753 uac.registerHandle->stopRegistering();
754 }
755 }
756 }
757 }
758
759 // OK to delete DUM objects now
760 delete dumUac;
761 delete dumUas;
762
763 cout << "!!!!!!!!!!!!!!!!!! Successful !!!!!!!!!! " << endl;
764 #if defined(WIN32) && defined(_DEBUG) && defined(LEAK_CHECK)
765 }
766 #endif
767
768 }
769
770 /* ====================================================================
771 * The Vovida Software License, Version 1.0
772 *
773 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
774 *
775 * Redistribution and use in source and binary forms, with or without
776 * modification, are permitted provided that the following conditions
777 * are met:
778 *
779 * 1. Redistributions of source code must retain the above copyright
780 * notice, this list of conditions and the following disclaimer.
781 *
782 * 2. Redistributions in binary form must reproduce the above copyright
783 * notice, this list of conditions and the following disclaimer in
784 * the documentation and/or other materials provided with the
785 * distribution.
786 *
787 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
788 * and "Vovida Open Communication Application Library (VOCAL)" must
789 * not be used to endorse or promote products derived from this
790 * software without prior written permission. For written
791 * permission, please contact vocal@vovida.org.
792 *
793 * 4. Products derived from this software may not be called "VOCAL", nor
794 * may "VOCAL" appear in their name, without prior written
795 * permission of Vovida Networks, Inc.
796 *
797 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
798 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
799 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
800 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
801 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
802 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
803 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
804 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
805 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
806 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
807 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
808 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
809 * DAMAGE.
810 *
811 * ====================================================================
812 *
813 * This software consists of voluntary contributions made by Vovida
814 * Networks, Inc. and many individuals on behalf of Vovida Networks,
815 * Inc. For more snformation on Vovida Networks, Inc., please see
816 * <http://www.vovida.org/>.
817 *
818 */

Properties

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

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.26