/[resiprocate]/main/resip/dum/Dialog.cxx
ViewVC logotype

Annotation of /main/resip/dum/Dialog.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3081 - (hide annotations) (download)
Thu Jul 8 22:52:03 2004 UTC (15 years, 5 months ago) by derek
Original Path: main/sip/resiprocate/dum/Dialog.cxx
File size: 27582 byte(s)
reverted 100 handling change that was causing usage leak
changed some logging from Info to Debug
1 davidb 2603 #include "resiprocate/Contents.hxx"
2 jason 2614 #include "resiprocate/Helper.hxx"
3 jason 2885 #include "resiprocate/SipMessage.hxx"
4 derek 2943 #include "resiprocate/dum/AppDialog.hxx"
5 jason 2885 #include "resiprocate/dum/BaseCreator.hxx"
6 derek 2991 #include "resiprocate/dum/ClientAuthManager.hxx"
7 jason 2941 #include "resiprocate/dum/ClientInviteSession.hxx"
8 jason 2885 #include "resiprocate/dum/ClientOutOfDialogReq.hxx"
9 jason 2941 #include "resiprocate/dum/ClientRegistration.hxx"
10     #include "resiprocate/dum/ClientSubscription.hxx"
11 jason 2885 #include "resiprocate/dum/Dialog.hxx"
12     #include "resiprocate/dum/DialogUsageManager.hxx"
13     #include "resiprocate/dum/InviteSessionCreator.hxx"
14 derek 3058 #include "resiprocate/dum/InviteSessionHandler.hxx"
15 jason 2941 #include "resiprocate/dum/ServerInviteSession.hxx"
16     #include "resiprocate/dum/ServerOutOfDialogReq.hxx"
17     #include "resiprocate/dum/ServerRegistration.hxx"
18     #include "resiprocate/dum/ServerSubscription.hxx"
19     #include "resiprocate/dum/ClientPublication.hxx"
20     #include "resiprocate/dum/ServerPublication.hxx"
21 davidb 2603 #include "resiprocate/os/Logger.hxx"
22    
23     #define RESIPROCATE_SUBSYSTEM Subsystem::DUM
24    
25 ken 2520 using namespace resip;
26     using namespace std;
27    
28 derek 2867 Dialog::Dialog(DialogUsageManager& dum, const SipMessage& msg, DialogSet& ds)
29 derek 2995 : mDum(dum),
30 derek 2867 mDialogSet(ds),
31 jason 2588 mClientSubscriptions(),
32 derek 3041 mServerSubscriptions(),
33 jason 2588 mInviteSession(0),
34     mClientRegistration(0),
35     mServerRegistration(0),
36     mClientPublication(0),
37     mServerPublication(0),
38 jason 2614 mClientOutOfDialogRequests(),
39     mServerOutOfDialogRequest(0),
40 jason 2588 mType(Fake),
41     mRouteSet(),
42 jason 2611 mLocalContact(),
43 jason 2577 mLocalCSeq(0),
44     mRemoteCSeq(0),
45 derek 2995 mId("INVALID", "INVALID", "INVALID"),
46 derek 2981 mRemoteTarget(),
47 derek 2995 mLocalNameAddr(),
48     mRemoteNameAddr(),
49     mCallId(msg.header(h_CallID)),
50 derek 2981 mDestroying(false)
51 jason 2577 {
52 davidb 2603 assert(msg.isExternal());
53 jason 2577
54 derek 2936
55 jason 2577 if (msg.isRequest()) // UAS
56     {
57     const SipMessage& request = msg;
58    
59     switch (request.header(h_CSeq).method())
60     {
61     case INVITE:
62 jason 2611 mType = Invitation;
63     break;
64    
65 davidb 2603 case SUBSCRIBE:
66 jason 2611 case REFER:
67     case NOTIFY:
68 derek 3041 //!dcm! -- event header check
69 jason 2611 mType = Subscription;
70     break;
71    
72     default:
73     mType = Fake;
74     }
75 derek 3024 if (request.exists(h_RecordRoutes))
76     {
77     mRouteSet = request.header(h_RecordRoutes); // !jf! is this right order
78     }
79 jason 2611
80     switch (request.header(h_CSeq).method())
81     {
82     case INVITE:
83     case SUBSCRIBE:
84     case REFER:
85 derek 2995 InfoLog ( << "UAS dialog ID creation, DS: " << ds.getId());
86     mId = DialogId(ds.getId(), request.header(h_From).param(p_tag));
87     mRemoteNameAddr = request.header(h_From);
88     mLocalNameAddr = request.header(h_To);
89     mLocalNameAddr.param(p_tag) = mId.getLocalTag();
90 jason 2577 if (request.exists(h_Contacts) && request.header(h_Contacts).size() == 1)
91     {
92 davidb 2603 const NameAddr& contact = request.header(h_Contacts).front();
93 jason 2577 if (isEqualNoCase(contact.uri().scheme(), Symbols::Sips) ||
94     isEqualNoCase(contact.uri().scheme(), Symbols::Sip))
95     {
96 jason 2611 mLocalContact = NameAddr(request.header(h_RequestLine).uri()); // update later when send a request
97 jason 2577 mRemoteTarget = contact;
98     }
99     else
100     {
101 davidb 2603 InfoLog(<< "Got an INVITE or SUBSCRIBE with invalid scheme");
102     DebugLog(<< request);
103 jason 2611 throw Exception("Invalid scheme in request", __FILE__, __LINE__);
104 jason 2577 }
105     }
106     else
107     {
108     InfoLog (<< "Got an INVITE or SUBSCRIBE that doesn't have exactly one contact");
109     DebugLog (<< request);
110 jason 2611 throw Exception("Too many (or no contact) contacts in request", __FILE__, __LINE__);
111 jason 2577 }
112     break;
113 davidb 2603 default:
114     break;
115 jason 2577 }
116    
117     mRemoteCSeq = request.header(h_CSeq).sequence();
118 jason 2611 mLocalCSeq = 1;
119 derek 2995
120     InfoLog ( << "************** Created Dialog as UAS **************" );
121     InfoLog ( << "mRemoteNameAddr: " << mRemoteNameAddr );
122     InfoLog ( << "mLocalNameAddr: " << mLocalNameAddr );
123     InfoLog ( << "mLocalContact: " << mLocalContact );
124     InfoLog ( << "mRemoteTarget: " << mRemoteTarget );
125 jason 2577 }
126     else if (msg.isResponse())
127     {
128 derek 2995 mId = DialogId(msg);
129 jason 2577 const SipMessage& response = msg;
130 derek 2995 mRemoteNameAddr = response.header(h_To);
131     mLocalNameAddr = response.header(h_From);
132 jason 2611
133     switch (msg.header(h_CSeq).method())
134     {
135     case INVITE:
136     mType = Invitation;
137     break;
138    
139     case SUBSCRIBE:
140     case REFER:
141     mType = Subscription;
142     break;
143    
144     default:
145     mType = Fake;
146     }
147    
148 jason 2577 if (response.exists(h_RecordRoutes))
149     {
150     mRouteSet = response.header(h_RecordRoutes).reverse();
151     }
152    
153     switch (response.header(h_CSeq).method())
154     {
155     case INVITE:
156 davidb 2603 case SUBSCRIBE:
157 jason 2611 case REFER:
158 derek 2983 if (response.header(h_StatusLine).statusCode() > 100 &&
159     response.header(h_StatusLine).statusCode() < 300)
160 jason 2577 {
161 derek 2983
162     if (response.exists(h_Contacts) && response.header(h_Contacts).size() == 1)
163 jason 2577 {
164 derek 2983 const NameAddr& contact = response.header(h_Contacts).front();
165     if (isEqualNoCase(contact.uri().scheme(), Symbols::Sips) ||
166     isEqualNoCase(contact.uri().scheme(), Symbols::Sip))
167     {
168     BaseCreator* creator = mDum.findCreator(mId);
169     assert(creator);// !jf! throw or something here
170 jason 2612
171 derek 2983 mLocalContact = creator->getLastRequest().header(h_Contacts).front();
172     mRemoteTarget = contact;
173     }
174     else
175     {
176     InfoLog (<< "Got an INVITE or SUBSCRIBE with invalid scheme");
177     DebugLog (<< response);
178     throw Exception("Bad scheme in contact in response", __FILE__, __LINE__);
179     }
180 jason 2577 }
181     else
182     {
183 derek 2983 InfoLog (<< "Got an INVITE or SUBSCRIBE that doesn't have exactly one contact");
184 jason 2577 DebugLog (<< response);
185 derek 2983 throw Exception("Too many contacts (or no contact) in response", __FILE__, __LINE__);
186 jason 2577 }
187 derek 2983 break;
188     default:
189     break;
190 jason 2577 }
191     }
192 derek 2983
193 jason 2577 mLocalCSeq = response.header(h_CSeq).sequence();
194 jason 2611 mRemoteCSeq = 0;
195 derek 2995 InfoLog ( << "************** Created Dialog as UAC **************" );
196     InfoLog ( << "mRemoteNameAddr: " << mRemoteNameAddr );
197     InfoLog ( << "mLocalNameAddr: " << mLocalNameAddr );
198     InfoLog ( << "mLocalContact: " << mLocalContact );
199     InfoLog ( << "mRemoteTarget: " << mRemoteTarget );
200    
201 jason 2611
202 jason 2577 }
203 derek 2867 mDialogSet.addDialog(this);
204 derek 3081 DebugLog ( <<"Dialog::Dialog " << mId);
205 jason 2577 }
206    
207 jason 2868 Dialog::~Dialog()
208     {
209 derek 3081 DebugLog ( <<"Dialog::~Dialog() ");
210    
211 derek 2981 mDestroying = true;
212     //does removing an elemnt from a list invalidate iterators?
213     for(std::list<ClientSubscription*>::iterator it = mClientSubscriptions.begin();
214     it != mClientSubscriptions.end(); it++)
215     {
216     delete *it;
217     }
218 derek 3041 for(std::list<ServerSubscription*>::iterator it = mServerSubscriptions.begin();
219     it != mServerSubscriptions.end(); it++)
220     {
221     delete *it;
222     }
223 derek 2981 for(std::list<ClientOutOfDialogReq*>::iterator it = mClientOutOfDialogRequests.begin();
224     it != mClientOutOfDialogRequests.end(); it++)
225     {
226     delete *it;
227     }
228     delete mInviteSession;
229     delete mClientRegistration;
230     delete mServerRegistration;
231     delete mClientPublication;
232     delete mServerPublication;
233     delete mServerOutOfDialogRequest;
234    
235 jason 2884 mDialogSet.mDialogs.erase(this->getId());
236 derek 2976 delete mAppDialog;
237     mDialogSet.possiblyDie();
238 jason 2868 }
239    
240 jason 2588 DialogId
241     Dialog::getId() const
242     {
243     return mId;
244     }
245    
246 davidb 2604 void
247 jason 2891 Dialog::cancel()
248     {
249 derek 3006 if (mInviteSession)
250     {
251     mInviteSession->end();
252     }
253     else
254     {
255     if (mDialogSet.getCreator())
256     {
257     makeRequest(mDialogSet.getCreator()->getLastRequest(), CANCEL);
258     mDum.send(mDialogSet.getCreator()->getLastRequest());
259     delete this;
260     }
261     }
262 jason 2891 }
263    
264     void
265 davidb 2604 Dialog::dispatch(const SipMessage& msg)
266     {
267 derek 2990 InfoLog ( << "Dialog::dispatch: " << msg.brief());
268 jason 2614 if (msg.isRequest())
269 jason 2583 {
270 jason 2614 const SipMessage& request = msg;
271     switch (request.header(h_CSeq).method())
272 jason 2583 {
273 jason 2614 case INVITE: // new INVITE
274     if (mInviteSession == 0)
275     {
276 derek 2992 InfoLog ( << "Dialog::dispatch -- Created new server invite session" << msg.brief());
277 jason 2885 mInviteSession = makeServerInviteSession(request);
278 jason 2614 }
279     mInviteSession->dispatch(request);
280     break;
281 derek 2997 case BYE:
282     if (mInviteSession == 0)
283     {
284     InfoLog ( << "Spurious BYE" );
285     return;
286     }
287     else
288     {
289     mInviteSession->dispatch(request);
290     }
291     break;
292 jason 2614 case ACK:
293     case CANCEL:
294     if (mInviteSession == 0)
295     {
296     InfoLog (<< "Drop stray ACK or CANCEL in dialog on the floor");
297     DebugLog (<< request);
298     }
299     else
300     {
301     mInviteSession->dispatch(request);
302     }
303     break;
304    
305     case SUBSCRIBE:
306     case REFER: //!jf! does this create a server subs?
307 derek 3041 {
308     ServerSubscription* server = findMatchingServerSub(request);
309     if (server)
310 jason 2614 {
311 derek 3041 server->dispatch(request);
312 jason 2614 }
313 derek 3041 else
314     {
315     server = makeServerSubscription(request);
316     mServerSubscriptions.push_back(server);
317     server->dispatch(request);
318     }
319     }
320     break;
321 jason 2614 case NOTIFY:
322     if (request.header(h_To).exists(p_tag))
323     {
324     ClientSubscription* client = findMatchingClientSub(request);
325     if (client)
326 jason 2612 {
327 jason 2614 client->dispatch(request);
328 jason 2612 }
329     else
330     {
331 jason 2614 BaseCreator* creator = mDum.findCreator(mId);
332     if (creator)
333 jason 2612 {
334 jason 2885 ClientSubscription* sub = makeClientSubscription(request);
335 jason 2614 mClientSubscriptions.push_back(sub);
336     sub->dispatch(request);
337 jason 2612 }
338     else
339     {
340 jason 2887 SipMessage failure;
341     makeResponse(failure, request, 481);
342     mDum.sendResponse(failure);
343 jason 2614 return;
344 jason 2612 }
345     }
346 jason 2614 }
347     else // no to tag - unsolicited notify
348     {
349     assert(mServerOutOfDialogRequest == 0);
350 jason 2885 mServerOutOfDialogRequest = makeServerOutOfDialog(request);
351 jason 2614 mServerOutOfDialogRequest->dispatch(request);
352     }
353     break;
354 jason 2583
355 jason 2614 case PUBLISH:
356     if (mServerPublication == 0)
357     {
358 jason 2885 mServerPublication = makeServerPublication(request);
359 jason 2614 }
360     mServerPublication->dispatch(request);
361     break;
362 jason 2612
363 jason 2614 case REGISTER:
364     if (mServerRegistration == 0)
365     {
366 jason 2885 mServerRegistration = makeServerRegistration(request);
367 jason 2614 }
368     mServerRegistration->dispatch(request);
369     break;
370 jason 2584
371 jason 2614 default:
372 derek 2997 InfoLog ( << "In Dialog::dispatch, default(ServerOutOfDialogRequest), msg: " << msg );
373 jason 2614 // only can be one ServerOutOfDialogReq at a time
374     assert(mServerOutOfDialogRequest == 0);
375 jason 2885 mServerOutOfDialogRequest = makeServerOutOfDialog(request);
376 jason 2614 mServerOutOfDialogRequest->dispatch(request);
377     break;
378 jason 2583 }
379 jason 2614 }
380     else if (msg.isResponse())
381     {
382 derek 3026 #if 0
383 derek 3058 // //Auth related
384     // if (mDum.mClientAuthManager && !mDialogSet.mCancelled)
385     // {
386     // if (mDialogSet.getCreator())
387     // {
388     // if ( mDum.mClientAuthManager->handle( mDialogSet.getCreator()->getLastRequest(), msg))
389     // {
390     // InfoLog( << "about to retransmit request with digest credentials" );
391     // InfoLog( << mDialogSet.getCreator()->getLastRequest() );
392 derek 2991
393 derek 3058 // mDum.send(mDialogSet.getCreator()->getLastRequest());
394     // return;
395     // }
396     // }
397     // else
398     // {
399     // SipMessage* lastRequest = 0;
400     // switch (msg.header(h_CSeq).method())
401     // {
402     // case INVITE:
403     // case CANCEL:
404     // case REFER:
405     // if (mInviteSession == 0)
406     // {
407     // return;
408     // }
409     // else
410     // {
411     // lastRequest = &mInviteSession->mLastRequest;
412     // }
413     // break;
414     // case REGISTER:
415     // if (mClientRegistration == 0)
416     // {
417     // return;
418     // }
419     // else
420     // {
421     // lastRequest = &mClientRegistration->mLastRequest;
422     // }
423     // break;
424     // default:
425     // break;
426     // }
427     // if ( lastRequest && mDum.mClientAuthManager->handle( *lastRequest, msg ) )
428     // {
429     // InfoLog( << "about to retransmit request with digest credentials" );
430     // InfoLog( << *lastRequest );
431 derek 2991
432 derek 3058 // mDum.send(*lastRequest);
433     // return;
434     // }
435     // }
436     // }
437 derek 3026 #endif
438 jason 2614 const SipMessage& response = msg;
439 jason 2885 // !jf! should this only be for 2xx responses? !jf! Propose no as an
440     // answer !dcm! what is he on?
441 jason 2614 switch (response.header(h_CSeq).method())
442 jason 2583 {
443 jason 2614 case INVITE:
444     if (mInviteSession == 0)
445     {
446 jason 2885 // #if!jf! don't think creator needs a dispatch
447     //BaseCreator* creator = mDum.findCreator(mId);
448     //assert (creator); // stray responses have been rejected already
449     //creator->dispatch(response);
450     // #endif!jf!
451 derek 2992 InfoLog ( << "Dialog::dispatch -- Created new client invite session" << msg.brief());
452    
453 jason 2885 mInviteSession = makeClientInviteSession(response);
454     mInviteSession->dispatch(response);
455 jason 2614 }
456     else
457     {
458     mInviteSession->dispatch(response);
459     }
460     break;
461 derek 2997 case BYE:
462 jason 2614 case ACK:
463     case CANCEL:
464     if (mInviteSession != 0)
465     {
466     mInviteSession->dispatch(response);
467     }
468     // else drop on the floor
469 derek 3058 break;
470 jason 2614 case REFER:
471     {
472 derek 3058 int code = response.header(h_StatusLine).statusCode();
473     if (code < 300)
474 jason 2612 {
475 derek 3058 // throw it away
476     return;
477     }
478 jason 2614 else
479     {
480 derek 3058 if (mInviteSession && mDum.mInviteSessionHandler)
481     {
482     mDum.mInviteSessionHandler->onReferRejected(mInviteSession->getSessionHandle(), response);
483     }
484     }
485     }
486     break;
487     case SUBSCRIBE:
488     {
489     int code = response.header(h_StatusLine).statusCode();
490     if (code < 300)
491     {
492     // throw it away
493     return;
494     }
495     else
496     {
497     ClientSubscription* client = findMatchingClientSub(response);
498     if (client)
499     {
500     client->dispatch(response);
501     }
502 jason 2614 }
503     }
504 derek 3058 break;
505 jason 2614 case PUBLISH:
506 jason 2887 // !jf! could assert that no other usages exist
507 jason 2614 if (mClientPublication == 0)
508     {
509 jason 2885 mClientPublication = makeClientPublication(response);
510 jason 2614 }
511     mClientPublication->dispatch(response);
512     break;
513 jason 2584
514 jason 2614 case REGISTER:
515 jason 2887 // !jf! could assert that no other usages exist
516 jason 2614 if (mClientRegistration == 0)
517     {
518 jason 2885 mClientRegistration = makeClientRegistration(response);
519 jason 2614 }
520     mClientRegistration->dispatch(response);
521     break;
522 jason 2584
523 jason 2614 // unsolicited - not allowed but commonly implemented
524     // by large companies with a bridge as their logo
525     case NOTIFY:
526     case INFO:
527 jason 2612
528 jason 2614 default:
529     {
530     ClientOutOfDialogReq* req = findMatchingClientOutOfDialogReq(response);
531     if (req == 0)
532 jason 2612 {
533 jason 2885 req = makeClientOutOfDialogReq(response);
534 jason 2614 mClientOutOfDialogRequests.push_back(req);
535     }
536     req->dispatch(response);
537     break;
538 jason 2584 }
539 jason 2583 }
540     }
541 jason 2578 }
542    
543 derek 3041 ServerSubscription*
544     Dialog::findMatchingServerSub(const SipMessage& msg)
545     {
546     for (std::list<ServerSubscription*>::iterator i=mServerSubscriptions.begin();
547     i != mServerSubscriptions.end(); ++i)
548     {
549     if ((*i)->matches(msg))
550     {
551     return *i;
552     }
553     }
554     return 0;
555     }
556 jason 2612
557     ClientSubscription*
558     Dialog::findMatchingClientSub(const SipMessage& msg)
559 jason 2583 {
560 derek 2858 for (std::list<ClientSubscription*>::iterator i=mClientSubscriptions.begin();
561 jason 2612 i != mClientSubscriptions.end(); ++i)
562 jason 2583 {
563 jason 2614 if ((*i)->matches(msg))
564 jason 2612 {
565 jason 2614 return *i;
566 jason 2612 }
567     }
568 jason 2614 return 0;
569 jason 2612 }
570 jason 2585
571 jason 2614 ClientOutOfDialogReq*
572 jason 2612 Dialog::findMatchingClientOutOfDialogReq(const SipMessage& msg)
573     {
574 derek 2858 for (std::list<ClientOutOfDialogReq*>::iterator i=mClientOutOfDialogRequests.begin();
575 jason 2612 i != mClientOutOfDialogRequests.end(); ++i)
576     {
577 jason 2614 if ((*i)->matches(msg))
578 jason 2612 {
579 jason 2614 return *i;
580 jason 2612 }
581 jason 2583 }
582 jason 2614 return 0;
583 jason 2583 }
584    
585 jason 2612
586 jason 2941 InviteSessionHandle
587 derek 3041 Dialog::getInviteSession()
588 ken 2520 {
589 davidb 2603 if (mInviteSession)
590     {
591     return mInviteSession->getSessionHandle();
592     }
593     else
594     {
595 derek 3041 return InviteSessionHandle::NotValid();
596 davidb 2603 }
597 ken 2520 }
598    
599 jason 2941 std::vector<ClientSubscriptionHandle>
600 derek 3041 Dialog::findClientSubscriptions(const Data& event)
601 ken 2520 {
602 jason 2941 std::vector<ClientSubscriptionHandle> handles;
603 davidb 2603
604 derek 2858 for (std::list<ClientSubscription*>::const_iterator i = mClientSubscriptions.begin();
605 davidb 2603 i != mClientSubscriptions.end(); ++i)
606     {
607 derek 3041 if ( (*i)->getEventType() == event)
608     {
609     handles.push_back((*i)->getHandle());
610     }
611     }
612     return handles;
613     }
614    
615     std::vector<ServerSubscriptionHandle>
616     Dialog::findServerSubscriptions(const Data& event)
617     {
618     std::vector<ServerSubscriptionHandle> handles;
619    
620     for (std::list<ServerSubscription*>::const_iterator i = mServerSubscriptions.begin();
621     i != mServerSubscriptions.end(); ++i)
622     {
623     if ( (*i)->getEventType() == event)
624     {
625     handles.push_back((*i)->getHandle());
626     }
627     }
628     return handles;
629     }
630    
631    
632     std::vector<ClientSubscriptionHandle>
633     Dialog::getClientSubscriptions()
634     {
635     std::vector<ClientSubscriptionHandle> handles;
636    
637     for (std::list<ClientSubscription*>::const_iterator i = mClientSubscriptions.begin();
638     i != mClientSubscriptions.end(); ++i)
639     {
640 davidb 2603 handles.push_back((*i)->getHandle());
641     }
642    
643     return handles;
644 ken 2520 }
645    
646 derek 3041 std::vector<ServerSubscriptionHandle>
647     Dialog::getServerSubscriptions()
648     {
649     std::vector<ServerSubscriptionHandle> handles;
650    
651     for (std::list<ServerSubscription*>::const_iterator i = mServerSubscriptions.begin();
652     i != mServerSubscriptions.end(); ++i)
653     {
654     handles.push_back((*i)->getHandle());
655     }
656    
657     return handles;
658     }
659    
660 jason 2941 ClientRegistrationHandle
661 derek 3041 Dialog::getClientRegistration()
662 ken 2520 {
663 davidb 2603 if (mClientRegistration)
664     {
665     return mClientRegistration->getHandle();
666     }
667     else
668     {
669 derek 3041 return ClientRegistrationHandle::NotValid();
670 davidb 2603 }
671 ken 2520 }
672    
673 jason 2941 ServerRegistrationHandle
674 derek 3041 Dialog::getServerRegistration()
675 ken 2520 {
676 davidb 2603 if (mServerRegistration)
677     {
678     return mServerRegistration->getHandle();
679     }
680     else
681     {
682 derek 3041 return ServerRegistrationHandle::NotValid();
683 davidb 2603 }
684 ken 2520 }
685    
686 jason 2941 ClientPublicationHandle
687 derek 3041 Dialog::getClientPublication()
688 davidb 2604 {
689     if (mClientPublication)
690     {
691     return mClientPublication->getHandle();
692     }
693     else
694     {
695 derek 3041 return ClientPublicationHandle::NotValid();
696 davidb 2604 }
697     }
698 ken 2520
699 jason 2941 ServerPublicationHandle
700 derek 3041 Dialog::getServerPublication()
701 ken 2520 {
702 davidb 2604 if (mServerPublication)
703     {
704     return mServerPublication->getHandle();
705     }
706     else
707     {
708 derek 3041 return ServerPublicationHandle::NotValid();
709 davidb 2604 }
710 ken 2520 }
711 jason 2535
712 jason 2614 #if 0
713 jason 2941 ClientOutOfDialogReqHandle
714 davidb 2604 Dialog::findClientOutOfDialog()
715 jason 2539 {
716 jason 2614 if (mClientOutOfDialogRequests)
717 jason 2539 {
718 davidb 2604 return mClientOutOfDialogReq->getHandle();
719 jason 2577 }
720 davidb 2604 else
721 jason 2577 {
722 davidb 2604 throw BaseUsage::Exception("no such client out of dialog",
723     __FILE__, __LINE__);
724 jason 2577 }
725 davidb 2604 }
726 jason 2614 #endif
727 davidb 2604
728 jason 2941 ServerOutOfDialogReqHandle
729 derek 3041 Dialog::getServerOutOfDialog()
730 davidb 2604 {
731 jason 2614 if (mServerOutOfDialogRequest)
732 davidb 2604 {
733 jason 2614 return mServerOutOfDialogRequest->getHandle();
734 davidb 2604 }
735 jason 2577 else
736     {
737 derek 3041 return ServerOutOfDialogReqHandle::NotValid();
738 jason 2577 }
739 jason 2539 }
740    
741 davidb 2604 #if 0
742 jason 2539 void
743 jason 2535 Dialog::processNotify(const SipMessage& notify)
744     {
745     if (notify.isRequest())
746     {
747     if (findSubscriptions().empty())
748     {
749     SubscriptionCreator* creator = dynamic_cast<SubscriptionCreator*>(DialogSetId(notify).getCreator());
750     if (creator)
751     {
752     creator->makeNewSubscription(notify);
753     }
754     }
755     else
756     {
757     for (std::list<BaseUsage*>::iterator i=mUsages.begin(); i!=mUsages.end(); i++)
758     {
759     ClientSubscription* sub = dynamic_cast<ClientSubscription*>(*i);
760     if (sub && sub->matches(notify))
761     {
762     sub->process(notify);
763     break;
764     }
765     }
766     }
767     }
768     }
769 jason 2612 #endif
770 jason 2539
771    
772 derek 2813 void
773     Dialog::makeRequest(SipMessage& request, MethodTypes method)
774     {
775     RequestLine rLine(method);
776    
777 derek 2817 rLine.uri() = mRemoteTarget.uri();
778 derek 2813
779     request.header(h_RequestLine) = rLine;
780 derek 2995 request.header(h_To) = mRemoteNameAddr;
781     // request.header(h_To).param(p_tag) = mId.getRemoteTag();
782     request.header(h_From) = mLocalNameAddr;
783     // request.header(h_From).param(p_tag) = mId.getLocalTag();
784 derek 2813
785     request.header(h_CallId) = mCallId;
786 derek 2997
787     request.remove(h_RecordRoutes); //!dcm! -- all of this is rather messy
788    
789 derek 2995 request.remove(h_Contacts);
790     request.header(h_Contacts).push_front(mLocalContact);
791 derek 2813 request.header(h_CSeq).method() = method;
792     request.header(h_MaxForwards).value() = 70;
793    
794 derek 2961 //must keep old via for cancel
795     if (method != CANCEL)
796     {
797 derek 3024 request.header(h_Routes) = mRouteSet;
798 derek 2992 request.remove(h_Vias);
799 derek 2961 Via via;
800     via.param(p_branch); // will create the branch
801     request.header(h_Vias).push_front(via);
802     }
803     else
804     {
805     assert(request.exists(h_Vias));
806     }
807 derek 3024 //don't increment CSeq for ACK or CANCEL
808     if (method != ACK && method != CANCEL)
809 derek 2965 {
810     request.header(h_CSeq).sequence() = ++mLocalCSeq;
811     }
812 derek 2995 InfoLog ( << "Dialog::makeRequest: " << request );
813 derek 2813 }
814    
815 derek 2961 void
816     Dialog::makeCancel(SipMessage& request)
817     {
818     makeRequest(request, CANCEL);
819 derek 2813
820 derek 2961 //not allowed in a CANCEL
821     request.remove(h_Requires);
822     request.remove(h_ProxyRequires);
823 derek 3058 request.header(h_To).remove(p_tag);
824 derek 2961 }
825    
826 derek 2813 void
827 jason 2887 Dialog::makeResponse(SipMessage& response, const SipMessage& request, int code)
828 derek 2813 {
829     assert( code >= 100 );
830 derek 2992 if (code < 300 && code > 100)
831 derek 2813 {
832     assert(request.isRequest());
833     assert(request.header(h_RequestLine).getMethod() == INVITE ||
834 derek 2997 request.header(h_RequestLine).getMethod() == SUBSCRIBE ||
835 derek 3024 request.header(h_RequestLine).getMethod() == BYE ||
836     request.header(h_RequestLine).getMethod() == CANCEL);
837 derek 2813
838 sgodin 3068 assert (request.header(h_RequestLine).getMethod() == CANCEL || // Contact header is not required for Requests that do not form a dialog
839     request.header(h_RequestLine).getMethod() == BYE ||
840     request.header(h_Contacts).size() == 1);
841 derek 2992 Helper::makeResponse(response, request, code, mLocalContact);
842 derek 2936 response.header(h_To).param(p_tag) = mId.getLocalTag();
843 derek 2813 }
844     else
845     {
846 derek 2817 Helper::makeResponse(response, request, code, mLocalContact);
847 derek 3006 response.header(h_To).param(p_tag) = mId.getLocalTag();
848    
849 derek 2813 }
850 derek 2992 InfoLog ( << "Dialog::makeResponse: " << response);
851 derek 2813 }
852    
853 jason 2885
854     ClientInviteSession*
855     Dialog::makeClientInviteSession(const SipMessage& response)
856     {
857     InviteSessionCreator* creator = dynamic_cast<InviteSessionCreator*>(mDialogSet.getCreator());
858     assert(creator); // !jf! this maybe can assert by evil UAS
859 jason 2941 //return mDum.createAppClientInviteSession(*this, *creator);
860     return new ClientInviteSession(mDum, *this, creator->getLastRequest(), creator->getInitialOffer());
861 jason 2885 }
862    
863     ClientRegistration*
864     Dialog::makeClientRegistration(const SipMessage& response)
865     {
866     BaseCreator* creator = mDialogSet.getCreator();
867     assert(creator);
868 jason 2941 return new ClientRegistration(mDum, *this, creator->getLastRequest());
869 jason 2885 }
870    
871     ClientPublication*
872     Dialog::makeClientPublication(const SipMessage& response)
873     {
874     BaseCreator* creator = mDialogSet.getCreator();
875     assert(creator);
876 jason 2941 return new ClientPublication(mDum, *this, creator->getLastRequest());
877 jason 2885 }
878    
879     ClientSubscription*
880 derek 3058 Dialog::makeClientSubscription(const SipMessage& request)
881 jason 2885 {
882 derek 3058 return new ClientSubscription(mDum, *this, request);
883 jason 2885 }
884    
885     ClientOutOfDialogReq*
886     Dialog::makeClientOutOfDialogReq(const SipMessage& response)
887     {
888     BaseCreator* creator = mDialogSet.getCreator();
889     assert(creator);
890 jason 2941 return new ClientOutOfDialogReq(mDum, *this, creator->getLastRequest());
891 jason 2885 }
892    
893     ServerInviteSession*
894     Dialog::makeServerInviteSession(const SipMessage& request)
895     {
896 jason 2941 return new ServerInviteSession(mDum, *this, request);
897 jason 2885 }
898    
899     ServerSubscription*
900     Dialog::makeServerSubscription(const SipMessage& request)
901     {
902 jason 2941 return new ServerSubscription(mDum, *this, request);
903 jason 2885 }
904    
905     ServerRegistration*
906     Dialog::makeServerRegistration(const SipMessage& request)
907     {
908 jason 2941 return new ServerRegistration(mDum, *this, request);
909 jason 2885 }
910    
911     ServerPublication*
912     Dialog::makeServerPublication(const SipMessage& request)
913     {
914 jason 2941 return new ServerPublication(mDum, *this, request);
915 jason 2885 }
916    
917     ServerOutOfDialogReq*
918     Dialog::makeServerOutOfDialog(const SipMessage& request)
919     {
920 jason 2941 return new ServerOutOfDialogReq(mDum, *this, request);
921 jason 2885 }
922    
923 davidb 2603 Dialog::Exception::Exception(const Data& msg, const Data& file, int line)
924     : BaseException(msg, file, line)
925 jason 2885 {
926     }
927 davidb 2603
928 jason 2853 void
929     Dialog::update(const SipMessage& msg)
930     {
931     }
932    
933     #if 0
934 derek 2839 void
935     Dialog::setLocalContact(const NameAddr& localContact)
936     {
937     mLocalContact = localContact;
938     }
939    
940     void
941     Dialog::setRemoteTarget(const NameAddr& remoteTarget)
942     {
943     mRemoteTarget = remoteTarget;
944     }
945 jason 2853 #endif
946 derek 2839
947 derek 2858 void Dialog::possiblyDie()
948     {
949 derek 2981 if (!mDestroying)
950 derek 2858 {
951 derek 2981 if (mClientSubscriptions.empty() &&
952 derek 3041 mServerSubscriptions.empty() &&
953 derek 2981 mClientOutOfDialogRequests.empty() &&
954 derek 3041 !(mInviteSession ||
955 derek 2981 mClientRegistration ||
956     mServerRegistration ||
957     mClientPublication ||
958     mServerPublication ||
959     mServerOutOfDialogRequest))
960     {
961     delete this;
962     }
963     }
964 derek 2858 }
965 derek 2862
966 jason 2884 ostream&
967     resip::operator<<(ostream& strm, const Dialog& dialog)
968     {
969    
970     return strm;
971     }
972    

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27