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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3067 - (hide 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 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 jason 2577 }
205    
206 jason 2868 Dialog::~Dialog()
207     {
208 derek 2981 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 derek 3041 for(std::list<ServerSubscription*>::iterator it = mServerSubscriptions.begin();
216     it != mServerSubscriptions.end(); it++)
217     {
218     delete *it;
219     }
220 derek 2981 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 jason 2884 mDialogSet.mDialogs.erase(this->getId());
233 derek 2976 delete mAppDialog;
234     mDialogSet.possiblyDie();
235 jason 2868 }
236    
237 jason 2588 DialogId
238     Dialog::getId() const
239     {
240     return mId;
241     }
242    
243 davidb 2604 void
244 jason 2891 Dialog::cancel()
245     {
246 derek 3006 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 jason 2891 }
260    
261     void
262 davidb 2604 Dialog::dispatch(const SipMessage& msg)
263     {
264 derek 2990 InfoLog ( << "Dialog::dispatch: " << msg.brief());
265 jason 2614 if (msg.isRequest())
266 jason 2583 {
267 jason 2614 const SipMessage& request = msg;
268     switch (request.header(h_CSeq).method())
269 jason 2583 {
270 jason 2614 case INVITE: // new INVITE
271     if (mInviteSession == 0)
272     {
273 derek 2992 InfoLog ( << "Dialog::dispatch -- Created new server invite session" << msg.brief());
274 jason 2885 mInviteSession = makeServerInviteSession(request);
275 jason 2614 }
276     mInviteSession->dispatch(request);
277     break;
278 derek 2997 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 jason 2614 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 derek 3041 {
305     ServerSubscription* server = findMatchingServerSub(request);
306     if (server)
307 jason 2614 {
308 derek 3041 server->dispatch(request);
309 jason 2614 }
310 derek 3041 else
311     {
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 3058 // //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 derek 2991
390 derek 3058 // 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 derek 2991
429 derek 3058 // 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 derek 3058 break;
467 jason 2614 case REFER:
468     {
469 derek 3058 int code = response.header(h_StatusLine).statusCode();
470     if (code < 300)
471 jason 2612 {
472 derek 3058 // throw it away
473     return;
474     }
475 jason 2614 else
476     {
477 derek 3058 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 jason 2614 }
500     }
501 derek 3058 break;
502 jason 2614 case PUBLISH:
503 jason 2887 // !jf! could assert that no other usages exist
504 jason 2614 if (mClientPublication == 0)
505     {
506 jason 2885 mClientPublication = makeClientPublication(response);
507 jason 2614 }
508     mClientPublication->dispatch(response);
509     break;
510 jason 2584
511 jason 2614 case REGISTER:
512 jason 2887 // !jf! could assert that no other usages exist
513 jason 2614 if (mClientRegistration == 0)
514     {
515 jason 2885 mClientRegistration = makeClientRegistration(response);
516 jason 2614 }
517     mClientRegistration->dispatch(response);
518     break;
519 jason 2584
520 jason 2614 // unsolicited - not allowed but commonly implemented
521     // by large companies with a bridge as their logo
522     case NOTIFY:
523     case INFO:
524 jason 2612
525 jason 2614 default:
526     {
527     ClientOutOfDialogReq* req = findMatchingClientOutOfDialogReq(response);
528     if (req == 0)
529 jason 2612 {
530 jason 2885 req = makeClientOutOfDialogReq(response);
531 jason 2614 mClientOutOfDialogRequests.push_back(req);
532     }
533     req->dispatch(response);
534     break;
535 jason 2584 }
536 jason 2583 }
537     }
538 jason 2578 }
539    
540 derek 3041 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 jason 2612
554     ClientSubscription*
555     Dialog::findMatchingClientSub(const SipMessage& msg)
556 jason 2583 {
557 derek 2858 for (std::list<ClientSubscription*>::iterator i=mClientSubscriptions.begin();
558 jason 2612 i != mClientSubscriptions.end(); ++i)
559 jason 2583 {
560 jason 2614 if ((*i)->matches(msg))
561 jason 2612 {
562 jason 2614 return *i;
563 jason 2612 }
564     }
565 jason 2614 return 0;
566 jason 2612 }
567 jason 2585
568 jason 2614 ClientOutOfDialogReq*
569 jason 2612 Dialog::findMatchingClientOutOfDialogReq(const SipMessage& msg)
570     {
571 derek 2858 for (std::list<ClientOutOfDialogReq*>::iterator i=mClientOutOfDialogRequests.begin();
572 jason 2612 i != mClientOutOfDialogRequests.end(); ++i)
573     {
574 jason 2614 if ((*i)->matches(msg))
575 jason 2612 {
576 jason 2614 return *i;
577 jason 2612 }
578 jason 2583 }
579 jason 2614 return 0;
580 jason 2583 }
581    
582 jason 2612
583 jason 2941 InviteSessionHandle
584 derek 3041 Dialog::getInviteSession()
585 ken 2520 {
586 davidb 2603 if (mInviteSession)
587     {
588     return mInviteSession->getSessionHandle();
589     }
590     else
591     {
592 derek 3041 return InviteSessionHandle::NotValid();
593 davidb 2603 }
594 ken 2520 }
595    
596 jason 2941 std::vector<ClientSubscriptionHandle>
597 derek 3041 Dialog::findClientSubscriptions(const Data& event)
598 ken 2520 {
599 jason 2941 std::vector<ClientSubscriptionHandle> handles;
600 davidb 2603
601 derek 2858 for (std::list<ClientSubscription*>::const_iterator i = mClientSubscriptions.begin();
602 davidb 2603 i != mClientSubscriptions.end(); ++i)
603     {
604 derek 3041 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 davidb 2603 handles.push_back((*i)->getHandle());
638     }
639    
640     return handles;
641 ken 2520 }
642    
643 derek 3041 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 jason 2941 ClientRegistrationHandle
658 derek 3041 Dialog::getClientRegistration()
659 ken 2520 {
660 davidb 2603 if (mClientRegistration)
661     {
662     return mClientRegistration->getHandle();
663     }
664     else
665     {
666 derek 3041 return ClientRegistrationHandle::NotValid();
667 davidb 2603 }
668 ken 2520 }
669    
670 jason 2941 ServerRegistrationHandle
671 derek 3041 Dialog::getServerRegistration()
672 ken 2520 {
673 davidb 2603 if (mServerRegistration)
674     {
675     return mServerRegistration->getHandle();
676     }
677     else
678     {
679 derek 3041 return ServerRegistrationHandle::NotValid();
680 davidb 2603 }
681 ken 2520 }
682    
683 jason 2941 ClientPublicationHandle
684 derek 3041 Dialog::getClientPublication()
685 davidb 2604 {
686     if (mClientPublication)
687     {
688     return mClientPublication->getHandle();
689     }
690     else
691     {
692 derek 3041 return ClientPublicationHandle::NotValid();
693 davidb 2604 }
694     }
695 ken 2520
696 jason 2941 ServerPublicationHandle
697 derek 3041 Dialog::getServerPublication()
698 ken 2520 {
699 davidb 2604 if (mServerPublication)
700     {
701     return mServerPublication->getHandle();
702     }
703     else
704     {
705 derek 3041 return ServerPublicationHandle::NotValid();
706 davidb 2604 }
707 ken 2520 }
708 jason 2535
709 jason 2614 #if 0
710 jason 2941 ClientOutOfDialogReqHandle
711 davidb 2604 Dialog::findClientOutOfDialog()
712 jason 2539 {
713 jason 2614 if (mClientOutOfDialogRequests)
714 jason 2539 {
715 davidb 2604 return mClientOutOfDialogReq->getHandle();
716 jason 2577 }
717 davidb 2604 else
718 jason 2577 {
719 davidb 2604 throw BaseUsage::Exception("no such client out of dialog",
720     __FILE__, __LINE__);
721 jason 2577 }
722 davidb 2604 }
723 jason 2614 #endif
724 davidb 2604
725 jason 2941 ServerOutOfDialogReqHandle
726 derek 3041 Dialog::getServerOutOfDialog()
727 davidb 2604 {
728 jason 2614 if (mServerOutOfDialogRequest)
729 davidb 2604 {
730 jason 2614 return mServerOutOfDialogRequest->getHandle();
731 davidb 2604 }
732 jason 2577 else
733     {
734 derek 3041 return ServerOutOfDialogReqHandle::NotValid();
735 jason 2577 }
736 jason 2539 }
737    
738 davidb 2604 #if 0
739 jason 2539 void
740 jason 2535 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 jason 2612 #endif
767 jason 2539
768    
769 derek 2813 void
770     Dialog::makeRequest(SipMessage& request, MethodTypes method)
771     {
772     RequestLine rLine(method);
773    
774 derek 2817 rLine.uri() = mRemoteTarget.uri();
775 derek 2813
776     request.header(h_RequestLine) = rLine;
777 derek 2995 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 derek 2813
782     request.header(h_CallId) = mCallId;
783 derek 2997
784     request.remove(h_RecordRoutes); //!dcm! -- all of this is rather messy
785    
786 derek 2995 request.remove(h_Contacts);
787     request.header(h_Contacts).push_front(mLocalContact);
788 derek 2813 request.header(h_CSeq).method() = method;
789     request.header(h_MaxForwards).value() = 70;
790    
791 derek 2961 //must keep old via for cancel
792     if (method != CANCEL)
793     {
794 derek 3024 request.header(h_Routes) = mRouteSet;
795 derek 2992 request.remove(h_Vias);
796 derek 2961 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 derek 3024 //don't increment CSeq for ACK or CANCEL
805     if (method != ACK && method != CANCEL)
806 derek 2965 {
807     request.header(h_CSeq).sequence() = ++mLocalCSeq;
808     }
809 derek 2995 InfoLog ( << "Dialog::makeRequest: " << request );
810 derek 2813 }
811    
812 derek 2961 void
813     Dialog::makeCancel(SipMessage& request)
814     {
815     makeRequest(request, CANCEL);
816 derek 2813
817 derek 2961 //not allowed in a CANCEL
818     request.remove(h_Requires);
819     request.remove(h_ProxyRequires);
820 derek 3058 request.header(h_To).remove(p_tag);
821 derek 2961 }
822    
823 derek 2813 void
824 jason 2887 Dialog::makeResponse(SipMessage& response, const SipMessage& request, int code)
825 derek 2813 {
826     assert( code >= 100 );
827 derek 2992 if (code < 300 && code > 100)
828 derek 2813 {
829     assert(request.isRequest());
830     assert(request.header(h_RequestLine).getMethod() == INVITE ||
831 derek 2997 request.header(h_RequestLine).getMethod() == SUBSCRIBE ||
832 derek 3024 request.header(h_RequestLine).getMethod() == BYE ||
833     request.header(h_RequestLine).getMethod() == CANCEL);
834 derek 2813
835     assert (request.header(h_Contacts).size() == 1);
836 derek 2992 Helper::makeResponse(response, request, code, mLocalContact);
837 derek 2936 response.header(h_To).param(p_tag) = mId.getLocalTag();
838 derek 2813 }
839     else
840     {
841 derek 2817 Helper::makeResponse(response, request, code, mLocalContact);
842 derek 3006 response.header(h_To).param(p_tag) = mId.getLocalTag();
843    
844 derek 2813 }
845 derek 2992 InfoLog ( << "Dialog::makeResponse: " << response);
846 derek 2813 }
847    
848 jason 2885
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 jason 2941 //return mDum.createAppClientInviteSession(*this, *creator);
855     return new ClientInviteSession(mDum, *this, creator->getLastRequest(), creator->getInitialOffer());
856 jason 2885 }
857    
858     ClientRegistration*
859     Dialog::makeClientRegistration(const SipMessage& response)
860     {
861     BaseCreator* creator = mDialogSet.getCreator();
862     assert(creator);
863 jason 2941 return new ClientRegistration(mDum, *this, creator->getLastRequest());
864 jason 2885 }
865    
866     ClientPublication*
867     Dialog::makeClientPublication(const SipMessage& response)
868     {
869     BaseCreator* creator = mDialogSet.getCreator();
870     assert(creator);
871 jason 2941 return new ClientPublication(mDum, *this, creator->getLastRequest());
872 jason 2885 }
873    
874     ClientSubscription*
875 derek 3058 Dialog::makeClientSubscription(const SipMessage& request)
876 jason 2885 {
877 derek 3058 return new ClientSubscription(mDum, *this, request);
878 jason 2885 }
879    
880     ClientOutOfDialogReq*
881     Dialog::makeClientOutOfDialogReq(const SipMessage& response)
882     {
883     BaseCreator* creator = mDialogSet.getCreator();
884     assert(creator);
885 jason 2941 return new ClientOutOfDialogReq(mDum, *this, creator->getLastRequest());
886 jason 2885 }
887    
888     ServerInviteSession*
889     Dialog::makeServerInviteSession(const SipMessage& request)
890     {
891 jason 2941 return new ServerInviteSession(mDum, *this, request);
892 jason 2885 }
893    
894     ServerSubscription*
895     Dialog::makeServerSubscription(const SipMessage& request)
896     {
897 jason 2941 return new ServerSubscription(mDum, *this, request);
898 jason 2885 }
899    
900     ServerRegistration*
901     Dialog::makeServerRegistration(const SipMessage& request)
902     {
903 jason 2941 return new ServerRegistration(mDum, *this, request);
904 jason 2885 }
905    
906     ServerPublication*
907     Dialog::makeServerPublication(const SipMessage& request)
908     {
909 jason 2941 return new ServerPublication(mDum, *this, request);
910 jason 2885 }
911    
912     ServerOutOfDialogReq*
913     Dialog::makeServerOutOfDialog(const SipMessage& request)
914     {
915 jason 2941 return new ServerOutOfDialogReq(mDum, *this, request);
916 jason 2885 }
917    
918 davidb 2603 Dialog::Exception::Exception(const Data& msg, const Data& file, int line)
919     : BaseException(msg, file, line)
920 jason 2885 {
921     }
922 davidb 2603
923 jason 2853 void
924     Dialog::update(const SipMessage& msg)
925     {
926     }
927    
928     #if 0
929 derek 2839 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 jason 2853 #endif
941 derek 2839
942 derek 2858 void Dialog::possiblyDie()
943     {
944 derek 2981 if (!mDestroying)
945 derek 2858 {
946 derek 2981 if (mClientSubscriptions.empty() &&
947 derek 3041 mServerSubscriptions.empty() &&
948 derek 2981 mClientOutOfDialogRequests.empty() &&
949 derek 3041 !(mInviteSession ||
950 derek 2981 mClientRegistration ||
951     mServerRegistration ||
952     mClientPublication ||
953     mServerPublication ||
954     mServerOutOfDialogRequest))
955     {
956     delete this;
957     }
958     }
959 derek 2858 }
960 derek 2862
961 jason 2884 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