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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27