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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27