/[resiprocate]/branches/b-client-outbound-20110213/resip/dum/test/basicClientUserAgent.cxx
ViewVC logotype

Annotation of /branches/b-client-outbound-20110213/resip/dum/test/basicClientUserAgent.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9018 - (hide annotations) (download)
Wed Feb 16 22:40:07 2011 UTC (8 years, 11 months ago) by sgodin
File MIME type: text/plain
File size: 32893 byte(s)
-fixed bug in propagation of flowTerminated to all relevant DialogSets
 - stopped finding dialogsets once the flow key was cleared from the user profile
-fixed bug in propagation of flowTerminated notification to server and client subscription dialogs
 - iterator can become invalidated if flow terminated handler ends Subscription 
-added ability for basicClient to be dummy subscription server for basicClientTest event 
 (plain text bodies) - used for testing subscription recovery after flow failure
-added ability for basicClient to form a client subscription to a command line
 provided URI (typically this would be set to the AOR of another basicClient user)

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

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