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

Annotation of /main/resip/dum/test/basicClientUserAgent.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9011 - (hide annotations) (download)
Sun Feb 13 20:30:51 2011 UTC (8 years, 10 months ago) by sgodin
Original Path: branches/b-client-outbound-20110213/resip/dum/test/basicClientUserAgent.cxx
File MIME type: text/plain
File size: 29255 byte(s)
-new dum test program basicClient that provides a good reference starting
 place for people developing user agents
  - demonstrates how to use client outbound support (RFC5626)
  - uses AppDialogSet -> Call abstraction
  - uses recommended SelectInterruptor to drive the stack
1 sgodin 9011 #include <rutil/Log.hxx>
2     #include <rutil/Logger.hxx>
3     #include <rutil/DnsUtil.hxx>
4     #include <resip/stack/SdpContents.hxx>
5     #include <resip/stack/ConnectionTerminated.hxx>
6     #include <resip/dum/AppDialogSetFactory.hxx>
7     #include <resip/dum/ClientAuthManager.hxx>
8     #include <resip/dum/KeepAliveManager.hxx>
9     #include <resip/dum/ClientInviteSession.hxx>
10     #include <resip/dum/ServerInviteSession.hxx>
11     #include <resip/dum/ClientSubscription.hxx>
12     #include <resip/dum/ServerSubscription.hxx>
13     #include <resip/dum/ClientRegistration.hxx>
14     #include <resip/dum/ServerRegistration.hxx>
15     #include <resip/dum/ServerOutOfDialogReq.hxx>
16    
17     #if defined (USE_SSL)
18     #if defined(WIN32)
19     #include "resip/stack/ssl/WinSecurity.hxx"
20     #else
21     #include "resip/stack/ssl/Security.hxx"
22     #endif
23     #endif
24    
25     #include "basicClientUserAgent.hxx"
26     #include "basicClientCall.hxx"
27    
28     using namespace resip;
29     using namespace std;
30    
31     #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
32    
33     class ClientAppDialogSetFactory : public AppDialogSetFactory
34     {
35     public:
36     ClientAppDialogSetFactory(BasicClientUserAgent& ua) : mUserAgent(ua) {}
37     resip::AppDialogSet* createAppDialogSet(DialogUsageManager& dum, const SipMessage& msg)
38     {
39     switch(msg.method())
40     {
41     case INVITE:
42     return new BasicClientCall(mUserAgent);
43     break;
44     default:
45     return AppDialogSetFactory::createAppDialogSet(dum, msg);
46     break;
47     }
48     }
49     private:
50     BasicClientUserAgent& mUserAgent;
51     };
52    
53     // Used to set the IP Address in outbound SDP to match the IP address choosen by the stack to send the message on
54     class SdpMessageDecorator : public MessageDecorator
55     {
56     public:
57     virtual ~SdpMessageDecorator() {}
58     virtual void decorateMessage(SipMessage &msg,
59     const Tuple &source,
60     const Tuple &destination,
61     const Data& sigcompId)
62     {
63     SdpContents* sdp = dynamic_cast<SdpContents*>(msg.getContents());
64     if(sdp)
65     {
66     // Fill in IP and Port from source
67     sdp->session().connection().setAddress(Tuple::inet_ntop(source), source.ipVersion() == V6 ? SdpContents::IP6 : SdpContents::IP4);
68     sdp->session().origin().setAddress(Tuple::inet_ntop(source), source.ipVersion() == V6 ? SdpContents::IP6 : SdpContents::IP4);
69     InfoLog( << "SdpMessageDecorator: src=" << source << ", dest=" << destination << ", msg=" << endl << msg.brief());
70     }
71     }
72     virtual void rollbackMessage(SipMessage& msg) {} // Nothing to do
73     virtual MessageDecorator* clone() const { return new SdpMessageDecorator; }
74     };
75    
76     BasicClientUserAgent::BasicClientUserAgent(int argc, char** argv) :
77     BasicClientCmdLineParser(argc, argv),
78     mProfile(new MasterProfile),
79     #if defined(USE_SSL)
80     mSecurity(new Security(mCertPath)),
81     #else
82     mSecurity(0),
83     #endif
84     mStack(mSecurity, DnsStub::EmptyNameserverList, &mSelectInterruptor),
85     mDum(new DialogUsageManager(mStack)),
86     mStackThread(mStack, mSelectInterruptor),
87     mDumShutdownRequested(false),
88     mDumShutdown(false)
89     {
90     Log::initialize(mLogType, mLogLevel, argv[0]);
91    
92     addTransport(UDP, mUdpPort);
93     addTransport(TCP, mTcpPort);
94     #if defined(USE_SSL)
95     addTransport(TLS, mTlsPort);
96     #endif
97     #if defined(USED_DTLS)
98     addTransport(DTLS, mDtlsPort);
99     #endif
100    
101     // Disable Statistics Manager
102     mStack.statisticsManagerEnabled() = false;
103    
104     // Supported Methods
105     mProfile->clearSupportedMethods();
106     mProfile->addSupportedMethod(INVITE);
107     mProfile->addSupportedMethod(ACK);
108     mProfile->addSupportedMethod(CANCEL);
109     mProfile->addSupportedMethod(OPTIONS);
110     mProfile->addSupportedMethod(BYE);
111     //mProfile->addSupportedMethod(REFER);
112     //mProfile->addSupportedMethod(NOTIFY);
113     //mProfile->addSupportedMethod(SUBSCRIBE);
114     //mProfile->addSupportedMethod(UPDATE);
115     mProfile->addSupportedMethod(INFO);
116     mProfile->addSupportedMethod(PRACK);
117     //mProfile->addSupportedOptionTag(Token(Symbols::C100rel)); // Automatically added when using setUacReliableProvisionalMode
118     mProfile->setUacReliableProvisionalMode(MasterProfile::Supported);
119     //mProfile->setUasReliableProvisionalMode(MasterProfile::Supported); // TODO - needs support in DUM, currently unimplemented
120    
121     // Support Languages
122     mProfile->clearSupportedLanguages();
123     mProfile->addSupportedLanguage(Token("en"));
124    
125     // Support Mime Types
126     mProfile->clearSupportedMimeTypes();
127     mProfile->addSupportedMimeType(INVITE, Mime("application", "sdp"));
128     mProfile->addSupportedMimeType(INVITE, Mime("multipart", "mixed"));
129     mProfile->addSupportedMimeType(INVITE, Mime("multipart", "signed"));
130     mProfile->addSupportedMimeType(INVITE, Mime("multipart", "alternative"));
131     mProfile->addSupportedMimeType(OPTIONS,Mime("application", "sdp"));
132     mProfile->addSupportedMimeType(OPTIONS,Mime("multipart", "mixed"));
133     mProfile->addSupportedMimeType(OPTIONS, Mime("multipart", "signed"));
134     mProfile->addSupportedMimeType(OPTIONS, Mime("multipart", "alternative"));
135     mProfile->addSupportedMimeType(PRACK, Mime("application", "sdp"));
136     mProfile->addSupportedMimeType(PRACK, Mime("multipart", "mixed"));
137     mProfile->addSupportedMimeType(PRACK, Mime("multipart", "signed"));
138     mProfile->addSupportedMimeType(PRACK, Mime("multipart", "alternative"));
139     mProfile->addSupportedMimeType(UPDATE, Mime("application", "sdp"));
140     mProfile->addSupportedMimeType(UPDATE, Mime("multipart", "mixed"));
141     mProfile->addSupportedMimeType(UPDATE, Mime("multipart", "signed"));
142     mProfile->addSupportedMimeType(UPDATE, Mime("multipart", "alternative"));
143     //mProfile->addSupportedMimeType(NOTIFY, Mime("message", "sipfrag"));
144    
145     // Supported Options Tags
146     mProfile->clearSupportedOptionTags();
147     //mMasterProfile->addSupportedOptionTag(Token(Symbols::Replaces));
148     mProfile->addSupportedOptionTag(Token(Symbols::Timer)); // Enable Session Timers
149     if(mOutboundEnabled)
150     {
151     mProfile->addSupportedOptionTag(Token(Symbols::Outbound)); // RFC 5626 - outbound
152     mProfile->addSupportedOptionTag(Token(Symbols::Path)); // RFC 3327 - path
153     }
154     //mMasterProfile->addSupportedOptionTag(Token(Symbols::NoReferSub));
155     //mMasterProfile->addSupportedOptionTag(Token(Symbols::TargetDialog));
156    
157     // Supported Schemes
158     mProfile->clearSupportedSchemes();
159     mProfile->addSupportedScheme("sip");
160     #if defined(USE_SSL)
161     mProfile->addSupportedScheme("sips");
162     #endif
163    
164     // Validation Settings
165     mProfile->validateContentEnabled() = false;
166     mProfile->validateContentLanguageEnabled() = false;
167     mProfile->validateAcceptEnabled() = false;
168    
169     // Have stack add Allow/Supported/Accept headers to INVITE dialog establishment messages
170     mProfile->clearAdvertisedCapabilities(); // Remove Profile Defaults, then add our preferences
171     mProfile->addAdvertisedCapability(Headers::Allow);
172     //mProfile->addAdvertisedCapability(Headers::AcceptEncoding); // This can be misleading - it might specify what is expected in response
173     mProfile->addAdvertisedCapability(Headers::AcceptLanguage);
174     mProfile->addAdvertisedCapability(Headers::Supported);
175     mProfile->setMethodsParamEnabled(true);
176    
177     // Install Sdp Message Decorator
178     SharedPtr<MessageDecorator> outboundDecorator(new SdpMessageDecorator);
179     mProfile->setOutboundDecorator(outboundDecorator);
180    
181     // Other Profile Settings
182     mProfile->setUserAgent("basicClient/1.0");
183     mProfile->setDefaultRegistrationTime(mRegisterDuration);
184     mProfile->setDefaultRegistrationRetryTime(120);
185     if(!mContact.host().empty())
186     {
187     mProfile->setOverrideHostAndPort(mContact);
188     }
189     if(!mOutboundProxy.host().empty())
190     {
191     mProfile->setOutboundProxy(Uri(mOutboundProxy));
192     //mProfile->setForceOutboundProxyOnAllRequestsEnabled(true);
193     mProfile->setExpressOutboundAsRouteSetEnabled(true);
194     }
195    
196     // UserProfile Settings
197     mProfile->setDefaultFrom(NameAddr(mAor));
198     mProfile->setDigestCredential(mAor.host(), mAor.user(), mPassword);
199     // Generate InstanceId appropriate for testing only. Should be UUID that persists
200     // across machine re-starts and is unique to this applicaiton instance. The one used
201     // here is only as unique as the hostname of this machine. If someone runs two
202     // instances of this application on the same host for the same Aor, then things will
203     // break. See RFC5626 section 4.1
204     Data hostname = DnsUtil::getLocalHostName();
205     Data instanceHash = hostname.md5().uppercase();
206     assert(instanceHash.size() == 32);
207     Data instanceId(48, Data::Preallocate);
208     instanceId += "<urn:uuid:";
209     instanceId += instanceHash.substr(0, 8);
210     instanceId += "-";
211     instanceId += instanceHash.substr(8, 4);
212     instanceId += "-";
213     instanceId += instanceHash.substr(12, 4);
214     instanceId += "-";
215     instanceId += instanceHash.substr(16, 4);
216     instanceId += "-";
217     instanceId += instanceHash.substr(20, 12);
218     instanceId += ">";
219     mProfile->setInstanceId(instanceId);
220     if(mOutboundEnabled)
221     {
222     mProfile->setRegId(1);
223     mProfile->clientOutboundEnabled() = true;
224     }
225    
226     // Install Managers
227     mDum->setClientAuthManager(std::auto_ptr<ClientAuthManager>(new ClientAuthManager));
228     mDum->setKeepAliveManager(std::auto_ptr<KeepAliveManager>(new KeepAliveManager));
229     mProfile->setKeepAliveTimeForDatagram(30);
230     //mProfile->setKeepAliveTimeForStream(120);
231     mProfile->setKeepAliveTimeForStream(30); // !slg! TODO - testing only
232    
233     // Install Handlers
234     mDum->setInviteSessionHandler(this);
235     mDum->setDialogSetHandler(this);
236     mDum->addOutOfDialogHandler(OPTIONS, this);
237     //mDum->addOutOfDialogHandler(REFER, this);
238     mDum->setRedirectHandler(this);
239     mDum->setClientRegistrationHandler(this);
240     //mDum->addClientSubscriptionHandler("refer", this);
241     //mDum->addServerSubscriptionHandler("refer", this);
242    
243     // Set AppDialogSetFactory
244     auto_ptr<AppDialogSetFactory> dsf(new ClientAppDialogSetFactory(*this));
245     mDum->setAppDialogSetFactory(dsf);
246    
247     mDum->setMasterProfile(mProfile);
248    
249     mDum->registerForConnectionTermination(this);
250     }
251    
252     BasicClientUserAgent::~BasicClientUserAgent()
253     {
254     mStackThread.shutdown();
255     mStackThread.join();
256    
257     delete mDum;
258     }
259    
260     void
261     BasicClientUserAgent::startup()
262     {
263     mStackThread.run();
264    
265     if (mRegisterDuration)
266     {
267     InfoLog (<< "register for " << mAor);
268     mDum->send(mDum->makeRegistration(NameAddr(mAor)));
269     }
270     }
271    
272     void
273     BasicClientUserAgent::shutdown()
274     {
275     assert(mDum);
276     mDumShutdownRequested = true; // Set flag so that shutdown operations can be run in dum process thread
277     }
278    
279     bool
280     BasicClientUserAgent::process(int timeoutMs)
281     {
282     if(!mDumShutdown)
283     {
284     if(mDumShutdownRequested)
285     {
286     // unregister
287     if(mRegHandle.isValid())
288     {
289     mRegHandle->end();
290     }
291    
292     // End all calls - !slg! TODO
293    
294     mDum->shutdown(this);
295     mDumShutdownRequested = false;
296     }
297     mDum->process(timeoutMs);
298     return true;
299     }
300     return false;
301     }
302    
303     void
304     BasicClientUserAgent::addTransport(TransportType type, int port)
305     {
306     if(port == 0) return; // Transport disabled
307    
308     for (; port < port+10; ++port)
309     {
310     try
311     {
312     if (!mNoV4)
313     {
314     mStack.addTransport(type, port, V4, StunEnabled, Data::Empty, mTlsDomain);
315     return;
316     }
317    
318     if (mEnableV6)
319     {
320     mStack.addTransport(type, port, V6, StunEnabled, Data::Empty, mTlsDomain);
321     return;
322     }
323     }
324     catch (BaseException& e)
325     {
326     InfoLog (<< "Caught: " << e);
327     WarningLog (<< "Failed to add " << Tuple::toData(type) << " transport on " << port);
328     }
329     }
330     throw Transport::Exception("Port already in use", __FILE__, __LINE__);
331     }
332    
333     void
334     BasicClientUserAgent::post(Message* msg)
335     {
336     ConnectionTerminated* terminated = dynamic_cast<ConnectionTerminated*>(msg);
337     if (terminated)
338     {
339     InfoLog(<< "BasicClientUserAgent received connection terminated message for: " << terminated->getFlow());
340     delete msg;
341     return;
342     }
343     assert(false);
344     }
345    
346     void
347     BasicClientUserAgent::onDumCanBeDeleted()
348     {
349     mDumShutdown = true;
350     }
351    
352     ////////////////////////////////////////////////////////////////////////////////
353     // Registration Handler ////////////////////////////////////////////////////////
354     ////////////////////////////////////////////////////////////////////////////////
355     void
356     BasicClientUserAgent::onSuccess(ClientRegistrationHandle h, const SipMessage& msg)
357     {
358     InfoLog(<< "onSuccess(ClientRegistrationHandle): msg=" << msg.brief());
359     mRegHandle = h;
360     }
361    
362     void
363     BasicClientUserAgent::onFailure(ClientRegistrationHandle h, const SipMessage& msg)
364     {
365     InfoLog(<< "onFailure(ClientRegistrationHandle): msg=" << msg.brief());
366     mRegHandle = h;
367     }
368    
369     void
370     BasicClientUserAgent::onRemoved(ClientRegistrationHandle h, const SipMessage&msg)
371     {
372     InfoLog(<< "onRemoved(ClientRegistrationHandle): msg=" << msg.brief());
373     mRegHandle = h;
374     }
375    
376     int
377     BasicClientUserAgent::onRequestRetry(ClientRegistrationHandle h, int retryMinimum, const SipMessage& msg)
378     {
379     InfoLog(<< "onRequestRetry(ClientRegistrationHandle): msg=" << msg.brief());
380     mRegHandle = h;
381     return -1; // Let Profile retry setting take effect
382     }
383    
384    
385     ////////////////////////////////////////////////////////////////////////////////
386     // InviteSessionHandler ////////////////////////////////////////////////////////
387     ////////////////////////////////////////////////////////////////////////////////
388     void
389     BasicClientUserAgent::onNewSession(ClientInviteSessionHandle h, InviteSession::OfferAnswerType oat, const SipMessage& msg)
390     {
391     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onNewSession(h, oat, msg);
392     }
393    
394     void
395     BasicClientUserAgent::onNewSession(ServerInviteSessionHandle h, InviteSession::OfferAnswerType oat, const SipMessage& msg)
396     {
397     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onNewSession(h, oat, msg);
398     }
399    
400     void
401     BasicClientUserAgent::onFailure(ClientInviteSessionHandle h, const SipMessage& msg)
402     {
403     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onFailure(h, msg);
404     }
405    
406     void
407     BasicClientUserAgent::onEarlyMedia(ClientInviteSessionHandle h, const SipMessage& msg, const SdpContents& sdp)
408     {
409     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onEarlyMedia(h, msg, sdp);
410     }
411    
412     void
413     BasicClientUserAgent::onProvisional(ClientInviteSessionHandle h, const SipMessage& msg)
414     {
415     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onProvisional(h, msg);
416     }
417    
418     void
419     BasicClientUserAgent::onConnected(ClientInviteSessionHandle h, const SipMessage& msg)
420     {
421     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onConnected(h, msg);
422     }
423    
424     void
425     BasicClientUserAgent::onConnected(InviteSessionHandle h, const SipMessage& msg)
426     {
427     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onConnected(h, msg);
428     }
429    
430     void
431     BasicClientUserAgent::onStaleCallTimeout(ClientInviteSessionHandle h)
432     {
433     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onStaleCallTimeout(h);
434     }
435    
436     void
437     BasicClientUserAgent::onTerminated(InviteSessionHandle h, InviteSessionHandler::TerminatedReason reason, const SipMessage* msg)
438     {
439     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onTerminated(h, reason, msg);
440     }
441    
442     void
443     BasicClientUserAgent::onRedirected(ClientInviteSessionHandle h, const SipMessage& msg)
444     {
445     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onRedirected(h, msg);
446     }
447    
448     void
449     BasicClientUserAgent::onAnswer(InviteSessionHandle h, const SipMessage& msg, const SdpContents& sdp)
450     {
451     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onAnswer(h, msg, sdp);
452     }
453    
454     void
455     BasicClientUserAgent::onOffer(InviteSessionHandle h, const SipMessage& msg, const SdpContents& sdp)
456     {
457     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onOffer(h, msg, sdp);
458     }
459    
460     void
461     BasicClientUserAgent::onOfferRequired(InviteSessionHandle h, const SipMessage& msg)
462     {
463     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onOfferRequired(h, msg);
464     }
465    
466     void
467     BasicClientUserAgent::onOfferRejected(InviteSessionHandle h, const SipMessage* msg)
468     {
469     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onOfferRejected(h, msg);
470     }
471    
472     void
473     BasicClientUserAgent::onOfferRequestRejected(InviteSessionHandle h, const SipMessage& msg)
474     {
475     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onOfferRequestRejected(h, msg);
476     }
477    
478     void
479     BasicClientUserAgent::onRemoteSdpChanged(InviteSessionHandle h, const SipMessage& msg, const SdpContents& sdp)
480     {
481     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onRemoteSdpChanged(h, msg, sdp);
482     }
483    
484     void
485     BasicClientUserAgent::onInfo(InviteSessionHandle h, const SipMessage& msg)
486     {
487     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onInfo(h, msg);
488     }
489    
490     void
491     BasicClientUserAgent::onInfoSuccess(InviteSessionHandle h, const SipMessage& msg)
492     {
493     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onInfoSuccess(h, msg);
494     }
495    
496     void
497     BasicClientUserAgent::onInfoFailure(InviteSessionHandle h, const SipMessage& msg)
498     {
499     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onInfoFailure(h, msg);
500     }
501    
502     void
503     BasicClientUserAgent::onRefer(InviteSessionHandle h, ServerSubscriptionHandle ssh, const SipMessage& msg)
504     {
505     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onRefer(h, ssh, msg);
506     }
507    
508     void
509     BasicClientUserAgent::onReferAccepted(InviteSessionHandle h, ClientSubscriptionHandle csh, const SipMessage& msg)
510     {
511     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onReferAccepted(h, csh, msg);
512     }
513    
514     void
515     BasicClientUserAgent::onReferRejected(InviteSessionHandle h, const SipMessage& msg)
516     {
517     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onReferRejected(h, msg);
518     }
519    
520     void
521     BasicClientUserAgent::onReferNoSub(InviteSessionHandle h, const SipMessage& msg)
522     {
523     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onReferNoSub(h, msg);
524     }
525    
526     void
527     BasicClientUserAgent::onMessage(InviteSessionHandle h, const SipMessage& msg)
528     {
529     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onMessage(h, msg);
530     }
531    
532     void
533     BasicClientUserAgent::onMessageSuccess(InviteSessionHandle h, const SipMessage& msg)
534     {
535     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onMessageSuccess(h, msg);
536     }
537    
538     void
539     BasicClientUserAgent::onMessageFailure(InviteSessionHandle h, const SipMessage& msg)
540     {
541     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onMessageFailure(h, msg);
542     }
543    
544     void
545     BasicClientUserAgent::onForkDestroyed(ClientInviteSessionHandle h)
546     {
547     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onForkDestroyed(h);
548     }
549    
550     void
551     BasicClientUserAgent::onReadyToSend(InviteSessionHandle h, SipMessage& msg)
552     {
553     dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get())->onReadyToSend(h, msg);
554     }
555    
556    
557     ////////////////////////////////////////////////////////////////////////////////
558     // DialogSetHandler ///////////////////////////////////////////////////
559     ////////////////////////////////////////////////////////////////////////////////
560     void
561     BasicClientUserAgent::onTrying(AppDialogSetHandle h, const SipMessage& msg)
562     {
563     BasicClientCall *call = dynamic_cast<BasicClientCall *>(h.get());
564     if(call)
565     {
566     call->onTrying(h, msg);
567     }
568     else
569     {
570     InfoLog(<< "onTrying(AppDialogSetHandle): " << msg.brief());
571     }
572     }
573    
574     void
575     BasicClientUserAgent::onNonDialogCreatingProvisional(AppDialogSetHandle h, const SipMessage& msg)
576     {
577     BasicClientCall *call = dynamic_cast<BasicClientCall *>(h.get());
578     if(call)
579     {
580     call->onNonDialogCreatingProvisional(h, msg);
581     }
582     else
583     {
584     InfoLog(<< "onNonDialogCreatingProvisional(AppDialogSetHandle): " << msg.brief());
585     }
586     }
587    
588     ////////////////////////////////////////////////////////////////////////////////
589     // ClientSubscriptionHandler ///////////////////////////////////////////////////
590     ////////////////////////////////////////////////////////////////////////////////
591     void
592     BasicClientUserAgent::onUpdatePending(ClientSubscriptionHandle h, const SipMessage& msg, bool outOfOrder)
593     {
594     BasicClientCall* call = dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get());
595     if(call)
596     {
597     call->onUpdatePending(h, msg, outOfOrder);
598     return;
599     }
600     InfoLog(<< "onUpdatePending(ClientSubscriptionHandle): " << msg.brief());
601     }
602    
603     void
604     BasicClientUserAgent::onUpdateActive(ClientSubscriptionHandle h, const SipMessage& msg, bool outOfOrder)
605     {
606     BasicClientCall* call = dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get());
607     if(call)
608     {
609     call->onUpdateActive(h, msg, outOfOrder);
610     return;
611     }
612     InfoLog(<< "onUpdateActive(ClientSubscriptionHandle): " << msg.brief());
613     }
614    
615     void
616     BasicClientUserAgent::onUpdateExtension(ClientSubscriptionHandle h, const SipMessage& msg, bool outOfOrder)
617     {
618     BasicClientCall* call = dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get());
619     if(call)
620     {
621     call->onUpdateExtension(h, msg, outOfOrder);
622     return;
623     }
624     InfoLog(<< "onUpdateExtension(ClientSubscriptionHandle): " << msg.brief());
625     }
626    
627     void
628     BasicClientUserAgent::onNotifyNotReceived(ClientSubscriptionHandle h)
629     {
630     BasicClientCall* call = dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get());
631     if(call)
632     {
633     call->onNotifyNotReceived(h);
634     return;
635     }
636     WarningLog(<< "onNotifyNotReceived(ClientSubscriptionHandle)");
637     h->end();
638     }
639    
640     void
641     BasicClientUserAgent::onTerminated(ClientSubscriptionHandle h, const SipMessage* msg)
642     {
643     BasicClientCall* call = dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get());
644     if(call)
645     {
646     call->onTerminated(h, msg);
647     return;
648     }
649     if(msg)
650     {
651     InfoLog(<< "onTerminated(ClientSubscriptionHandle): msg=" << msg->brief());
652     }
653     else
654     {
655     InfoLog(<< "onTerminated(ClientSubscriptionHandle)");
656     }
657     }
658    
659     void
660     BasicClientUserAgent::onNewSubscription(ClientSubscriptionHandle h, const SipMessage& msg)
661     {
662     BasicClientCall* call = dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get());
663     if(call)
664     {
665     call->onNewSubscription(h, msg);
666     return;
667     }
668     InfoLog(<< "onNewSubscription(ClientSubscriptionHandle): msg=" << msg.brief());
669     }
670    
671     int
672     BasicClientUserAgent::onRequestRetry(ClientSubscriptionHandle h, int retrySeconds, const SipMessage& msg)
673     {
674     BasicClientCall* call = dynamic_cast<BasicClientCall *>(h->getAppDialogSet().get());
675     if(call)
676     {
677     return call->onRequestRetry(h, retrySeconds, msg);
678     }
679     InfoLog(<< "onRequestRetry(ClientSubscriptionHandle): msg=" << msg.brief());
680     return -1;
681     }
682    
683     ////////////////////////////////////////////////////////////////////////////////
684     // ServerSubscriptionHandler ///////////////////////////////////////////////////
685     ////////////////////////////////////////////////////////////////////////////////
686     void
687     BasicClientUserAgent::onNewSubscription(ServerSubscriptionHandle, const SipMessage& msg)
688     {
689     InfoLog(<< "onNewSubscription(ServerSubscriptionHandle): " << msg.brief());
690     }
691    
692     void
693     BasicClientUserAgent::onNewSubscriptionFromRefer(ServerSubscriptionHandle ss, const SipMessage& msg)
694     {
695     InfoLog(<< "onNewSubscriptionFromRefer(ServerSubscriptionHandle): " << msg.brief());
696     // Received an out-of-dialog refer request with implicit subscription
697     try
698     {
699     if(msg.exists(h_ReferTo))
700     {
701     // Check if TargetDialog header is present
702     if(msg.exists(h_TargetDialog))
703     {
704     pair<InviteSessionHandle, int> presult;
705     presult = mDum->findInviteSession(msg.header(h_TargetDialog));
706     if(!(presult.first == InviteSessionHandle::NotValid()))
707     {
708     BasicClientCall* callToRefer = (BasicClientCall*)presult.first->getAppDialogSet().get();
709    
710     callToRefer->onRefer(presult.first, ss, msg);
711     return;
712     }
713     }
714    
715     // We don't support ood refers that don't target a dialog - reject request
716     WarningLog (<< "onNewSubscriptionFromRefer(ServerSubscriptionHandle): Received ood refer (noSub) w/out a Target-Dialog: " << msg.brief());
717     ss->send(ss->reject(400));
718     }
719     else
720     {
721     WarningLog (<< "onNewSubscriptionFromRefer(ServerSubscriptionHandle): Received refer w/out a Refer-To: " << msg.brief());
722     ss->send(ss->reject(400));
723     }
724     }
725     catch(BaseException &e)
726     {
727     WarningLog(<< "onNewSubscriptionFromRefer(ServerSubscriptionHandle): exception " << e);
728     }
729     catch(...)
730     {
731     WarningLog(<< "onNewSubscriptionFromRefer(ServerSubscriptionHandle): unknown exception");
732     }
733     }
734    
735     void
736     BasicClientUserAgent::onRefresh(ServerSubscriptionHandle, const SipMessage& msg)
737     {
738     InfoLog(<< "onRefresh(ServerSubscriptionHandle): " << msg.brief());
739     }
740    
741     void
742     BasicClientUserAgent::onTerminated(ServerSubscriptionHandle)
743     {
744     InfoLog(<< "onTerminated(ServerSubscriptionHandle)");
745     }
746    
747     void
748     BasicClientUserAgent::onReadyToSend(ServerSubscriptionHandle, SipMessage&)
749     {
750     }
751    
752     void
753     BasicClientUserAgent::onNotifyRejected(ServerSubscriptionHandle, const SipMessage& msg)
754     {
755     WarningLog(<< "onNotifyRejected(ServerSubscriptionHandle): " << msg.brief());
756     }
757    
758     void
759     BasicClientUserAgent::onError(ServerSubscriptionHandle, const SipMessage& msg)
760     {
761     WarningLog(<< "onError(ServerSubscriptionHandle): " << msg.brief());
762     }
763    
764     void
765     BasicClientUserAgent::onExpiredByClient(ServerSubscriptionHandle, const SipMessage& sub, SipMessage& notify)
766     {
767     InfoLog(<< "onExpiredByClient(ServerSubscriptionHandle): " << notify.brief());
768     }
769    
770     void
771     BasicClientUserAgent::onExpired(ServerSubscriptionHandle, SipMessage& msg)
772     {
773     InfoLog(<< "onExpired(ServerSubscriptionHandle): " << msg.brief());
774     }
775    
776     bool
777     BasicClientUserAgent::hasDefaultExpires() const
778     {
779     return true;
780     }
781    
782     UInt32
783     BasicClientUserAgent::getDefaultExpires() const
784     {
785     return 60;
786     }
787    
788     ////////////////////////////////////////////////////////////////////////////////
789     // OutOfDialogHandler //////////////////////////////////////////////////////////
790     ////////////////////////////////////////////////////////////////////////////////
791     void
792     BasicClientUserAgent::onSuccess(ClientOutOfDialogReqHandle, const SipMessage& msg)
793     {
794     InfoLog(<< "onSuccess(ClientOutOfDialogReqHandle): " << msg.brief());
795     }
796    
797     void
798     BasicClientUserAgent::onFailure(ClientOutOfDialogReqHandle h, const SipMessage& msg)
799     {
800     WarningLog(<< "onFailure(ClientOutOfDialogReqHandle): " << msg.brief());
801     }
802    
803     void
804     BasicClientUserAgent::onReceivedRequest(ServerOutOfDialogReqHandle ood, const SipMessage& msg)
805     {
806     InfoLog(<< "onReceivedRequest(ServerOutOfDialogReqHandle): " << msg.brief());
807    
808     switch(msg.method())
809     {
810     case OPTIONS:
811     {
812     SharedPtr<SipMessage> optionsAnswer = ood->answerOptions();
813     ood->send(optionsAnswer);
814     break;
815     }
816     default:
817     ood->send(ood->reject(501 /* Not Implemented*/));
818     break;
819     }
820     }
821    
822     ////////////////////////////////////////////////////////////////////////////////
823     // RedirectHandler /////////////////////////////////////////////////////////////
824     ////////////////////////////////////////////////////////////////////////////////
825     void
826     BasicClientUserAgent::onRedirectReceived(AppDialogSetHandle h, const SipMessage& msg)
827     {
828     BasicClientCall* call = dynamic_cast<BasicClientCall *>(h.get());
829     if(call)
830     {
831     call->onRedirectReceived(h, msg);
832     }
833     else
834     {
835     InfoLog(<< "onRedirectReceived(AppDialogSetHandle): " << msg.brief());
836     }
837     }
838    
839     bool
840     BasicClientUserAgent::onTryingNextTarget(AppDialogSetHandle, const SipMessage& msg)
841     {
842     InfoLog(<< "onTryingNextTarget(AppDialogSetHandle): " << msg.brief());
843    
844     // Always allow redirection for now
845     return true;
846     }
847    
848    
849    
850    
851     /* ====================================================================
852    
853     Copyright (c) 2011, SIP Spectrum, Inc.
854     All rights reserved.
855    
856     Redistribution and use in source and binary forms, with or without
857     modification, are permitted provided that the following conditions are
858     met:
859    
860     1. Redistributions of source code must retain the above copyright
861     notice, this list of conditions and the following disclaimer.
862    
863     2. Redistributions in binary form must reproduce the above copyright
864     notice, this list of conditions and the following disclaimer in the
865     documentation and/or other materials provided with the distribution.
866    
867     3. Neither the name of SIP Spectrum nor the names of its contributors
868     may be used to endorse or promote products derived from this
869     software without specific prior written permission.
870    
871     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
872     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
873     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
874     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
875     OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
876     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
877     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
878     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
879     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
880     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
881     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
882    
883     ==================================================================== */
884    

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