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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27