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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2884 by jason, Sun May 30 19:55:02 2004 UTC revision 3026 by derek, Wed Jun 23 18:42:07 2004 UTC
# Line 1  Line 1 
 #include "resiprocate/SipMessage.hxx"  
1  #include "resiprocate/Contents.hxx"  #include "resiprocate/Contents.hxx"
2  #include "resiprocate/Helper.hxx"  #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/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  #include "resiprocate/os/Logger.hxx"  #include "resiprocate/os/Logger.hxx"
21    
 #include "BaseCreator.hxx"  
 #include "Dialog.hxx"  
 #include "DialogUsageManager.hxx"  
 #include "ClientOutOfDialogReq.hxx"  
   
22  #define RESIPROCATE_SUBSYSTEM Subsystem::DUM  #define RESIPROCATE_SUBSYSTEM Subsystem::DUM
23    
24  using namespace resip;  using namespace resip;
25  using namespace std;  using namespace std;
26    
 class ServerInviteSession;  
   
27  Dialog::Dialog(DialogUsageManager& dum, const SipMessage& msg, DialogSet& ds)  Dialog::Dialog(DialogUsageManager& dum, const SipMessage& msg, DialogSet& ds)
28     : mId(msg),     : mDum(dum),
      mDum(dum),  
29       mDialogSet(ds),       mDialogSet(ds),
30       mClientSubscriptions(),       mClientSubscriptions(),
31       mServerSubscription(0),       mServerSubscription(0),
# Line 29  Line 37 
37       mClientOutOfDialogRequests(),       mClientOutOfDialogRequests(),
38       mServerOutOfDialogRequest(0),       mServerOutOfDialogRequest(0),
39       mType(Fake),       mType(Fake),
      mLocalTag(),  
      mRemoteTag(),  
      mCallId(msg.header(h_CallID)),  
40       mRouteSet(),       mRouteSet(),
41       mLocalContact(),       mLocalContact(),
42       mLocalCSeq(0),       mLocalCSeq(0),
43       mRemoteCSeq(0),       mRemoteCSeq(0),
44       mRemoteTarget()       mId("INVALID", "INVALID", "INVALID"),
45         mRemoteTarget(),
46         mLocalNameAddr(),
47         mRemoteNameAddr(),
48         mCallId(msg.header(h_CallID)),
49         mDestroying(false)
50  {  {
51     assert(msg.isExternal());     assert(msg.isExternal());
52    
53      
54     if (msg.isRequest()) // UAS     if (msg.isRequest()) // UAS
55     {     {
56        const SipMessage& request = msg;        const SipMessage& request = msg;
# Line 59  Line 70 
70           default:           default:
71              mType = Fake;              mType = Fake;
72        }        }
73              if (request.exists(h_RecordRoutes))
74          {
75        mRouteSet = request.header(h_RecordRoutes); // !jf! is this right order        mRouteSet = request.header(h_RecordRoutes); // !jf! is this right order
76          }
77    
78        switch (request.header(h_CSeq).method())        switch (request.header(h_CSeq).method())
79        {        {
80           case INVITE:           case INVITE:
81           case SUBSCRIBE:           case SUBSCRIBE:
82           case REFER:           case REFER:
83                InfoLog ( << "UAS dialog ID creation, DS: " << ds.getId());            
84                mId = DialogId(ds.getId(), request.header(h_From).param(p_tag));
85                mRemoteNameAddr = request.header(h_From);
86                mLocalNameAddr = request.header(h_To);
87                mLocalNameAddr.param(p_tag) = mId.getLocalTag();
88              if (request.exists(h_Contacts) && request.header(h_Contacts).size() == 1)              if (request.exists(h_Contacts) && request.header(h_Contacts).size() == 1)
89              {              {
90                 const NameAddr& contact = request.header(h_Contacts).front();                 const NameAddr& contact = request.header(h_Contacts).front();
# Line 97  Line 115 
115        mRemoteCSeq = request.header(h_CSeq).sequence();        mRemoteCSeq = request.header(h_CSeq).sequence();
116        mLocalCSeq = 1;        mLocalCSeq = 1;
117                
118        if (request.header(h_From).exists(p_tag) ) // 2543 compat        InfoLog ( << "************** Created Dialog as UAS **************" );      
119        {        InfoLog ( << "mRemoteNameAddr: " << mRemoteNameAddr );
120           mRemoteTag = request.header(h_From).param(p_tag);          InfoLog ( << "mLocalNameAddr: " << mLocalNameAddr );
121        }        InfoLog ( << "mLocalContact: " << mLocalContact );
122        if ( request.header(h_To).exists(p_tag) )  // 2543 compat        InfoLog ( << "mRemoteTarget: " << mRemoteTarget );
       {  
          mLocalTag = request.header(h_To).param(p_tag);  
       }  
123     }     }
124     else if (msg.isResponse())     else if (msg.isResponse())
125     {     {
126          mId = DialogId(msg);      
127        const SipMessage& response = msg;        const SipMessage& response = msg;
128          mRemoteNameAddr = response.header(h_To);
129          mLocalNameAddr = response.header(h_From);
130    
131        switch (msg.header(h_CSeq).method())        switch (msg.header(h_CSeq).method())
132        {        {
# Line 135  Line 153 
153           case INVITE:           case INVITE:
154           case SUBSCRIBE:           case SUBSCRIBE:
155           case REFER:           case REFER:
156                if (response.header(h_StatusLine).statusCode() > 100 &&
157                    response.header(h_StatusLine).statusCode() < 300)
158                {
159                  
160              if (response.exists(h_Contacts) && response.header(h_Contacts).size() == 1)              if (response.exists(h_Contacts) && response.header(h_Contacts).size() == 1)
161              {              {
162                 const NameAddr& contact = response.header(h_Contacts).front();                 const NameAddr& contact = response.header(h_Contacts).front();
# Line 164  Line 186 
186           default:           default:
187              break;              break;
188        }        }
189          }
190    
191        mLocalCSeq = response.header(h_CSeq).sequence();        mLocalCSeq = response.header(h_CSeq).sequence();
192        mRemoteCSeq = 0;        mRemoteCSeq = 0;
193          InfoLog ( << "************** Created Dialog as UAC **************" );      
194          InfoLog ( << "mRemoteNameAddr: " << mRemoteNameAddr );
195          InfoLog ( << "mLocalNameAddr: " << mLocalNameAddr );
196          InfoLog ( << "mLocalContact: " << mLocalContact );
197          InfoLog ( << "mRemoteTarget: " << mRemoteTarget );
198    
199                
       if ( response.header(h_From).exists(p_tag) ) // 2543 compat  
       {  
          mLocalTag = response.header(h_From).param(p_tag);    
       }  
       if ( response.header(h_To).exists(p_tag) )  // 2543 compat  
       {  
          mRemoteTag = response.header(h_To).param(p_tag);  
       }  
200     }     }
201     mDialogSet.addDialog(this);     mDialogSet.addDialog(this);
202  }  }
203    
204  Dialog::~Dialog()  Dialog::~Dialog()
205  {  {
206       mDestroying = true;
207       //does removing an elemnt from a list invalidate iterators?
208       for(std::list<ClientSubscription*>::iterator it = mClientSubscriptions.begin();
209           it != mClientSubscriptions.end(); it++)
210       {
211          delete *it;
212       }
213       for(std::list<ClientOutOfDialogReq*>::iterator it = mClientOutOfDialogRequests.begin();
214           it != mClientOutOfDialogRequests.end(); it++)
215       {
216          delete *it;
217       }
218       delete mServerSubscription;
219       delete mInviteSession;
220       delete mClientRegistration;
221       delete mServerRegistration;
222       delete mClientPublication;
223       delete mServerPublication;
224       delete mServerOutOfDialogRequest;
225    
226     mDialogSet.mDialogs.erase(this->getId());     mDialogSet.mDialogs.erase(this->getId());
227       delete mAppDialog;
228       mDialogSet.possiblyDie();
229  }  }
230    
231  DialogId  DialogId
# Line 192  Line 235 
235  }  }
236    
237  void  void
238    Dialog::cancel()
239    {
240       if (mInviteSession)
241       {
242          mInviteSession->end();
243       }
244       else
245       {
246          if (mDialogSet.getCreator())
247          {
248             makeRequest(mDialogSet.getCreator()->getLastRequest(), CANCEL);
249             mDum.send(mDialogSet.getCreator()->getLastRequest());
250             delete this;
251          }
252       }
253    }
254    
255    void
256  Dialog::dispatch(const SipMessage& msg)  Dialog::dispatch(const SipMessage& msg)
257  {  {
258       InfoLog ( << "Dialog::dispatch: " << msg.brief());
259     if (msg.isRequest())     if (msg.isRequest())
260     {     {
261        const SipMessage& request = msg;        const SipMessage& request = msg;
# Line 202  Line 264 
264           case INVITE:  // new INVITE           case INVITE:  // new INVITE
265              if (mInviteSession == 0)              if (mInviteSession == 0)
266              {              {
267                 mInviteSession = mDum.makeServerInviteSession(*this, request);                 InfoLog ( << "Dialog::dispatch  --  Created new server invite session" << msg.brief());
268                   mInviteSession = makeServerInviteSession(request);
269              }              }
270              mInviteSession->dispatch(request);              mInviteSession->dispatch(request);
271              break;              break;
272                           case BYE:
273                if (mInviteSession == 0)
274                {
275                   InfoLog ( << "Spurious BYE" );
276                   return;              
277                }
278                else
279                {
280                   mInviteSession->dispatch(request);
281                }
282                break;
283           case ACK:           case ACK:
284           case CANCEL:           case CANCEL:
285              if (mInviteSession == 0)              if (mInviteSession == 0)
# Line 224  Line 297 
297           case REFER: //!jf! does this create a server subs?           case REFER: //!jf! does this create a server subs?
298              if (mServerSubscription == 0)              if (mServerSubscription == 0)
299              {              {
300                 mServerSubscription = mDum.makeServerSubscription(*this, request);                 mServerSubscription = makeServerSubscription(request);
301              }              }
302                                
303              mServerSubscription->dispatch(request);              mServerSubscription->dispatch(request);
# Line 243  Line 316 
316                    BaseCreator* creator = mDum.findCreator(mId);                    BaseCreator* creator = mDum.findCreator(mId);
317                    if (creator)                    if (creator)
318                    {                    {
319                       ClientSubscription* sub = mDum.makeClientSubscription(*this, request);                       ClientSubscription* sub = makeClientSubscription(request);
320                       mClientSubscriptions.push_back(sub);                       mClientSubscriptions.push_back(sub);
321                       sub->dispatch(request);                       sub->dispatch(request);
322                    }                    }
323                    else                    else
324                    {                    {
325                       std::auto_ptr<SipMessage> failure(Helper::makeResponse(request, 481));                       SipMessage failure;
326                       mDum.send(*failure);                       makeResponse(failure, request, 481);
327                         mDum.sendResponse(failure);
328                       return;                       return;
329                    }                    }
330                 }                 }
# Line 258  Line 332 
332              else // no to tag - unsolicited notify              else // no to tag - unsolicited notify
333              {              {
334                 assert(mServerOutOfDialogRequest == 0);                 assert(mServerOutOfDialogRequest == 0);
335                 mServerOutOfDialogRequest = mDum.makeServerOutOfDialog(*this, request);                 mServerOutOfDialogRequest = makeServerOutOfDialog(request);
336                 mServerOutOfDialogRequest->dispatch(request);                 mServerOutOfDialogRequest->dispatch(request);
337              }              }
338              break;              break;
# Line 266  Line 340 
340           case PUBLISH:           case PUBLISH:
341              if (mServerPublication == 0)              if (mServerPublication == 0)
342              {              {
343                 mServerPublication = mDum.makeServerPublication(*this, request);                 mServerPublication = makeServerPublication(request);
344              }              }
345              mServerPublication->dispatch(request);              mServerPublication->dispatch(request);
346              break;              break;
# Line 274  Line 348 
348           case REGISTER:           case REGISTER:
349              if (mServerRegistration == 0)              if (mServerRegistration == 0)
350              {              {
351                 mServerRegistration = mDum.makeServerRegistration(*this, request);                 mServerRegistration = makeServerRegistration(request);
352              }              }
353              mServerRegistration->dispatch(request);              mServerRegistration->dispatch(request);
354              break;              break;
355                                
356           default:           default:
357                InfoLog ( << "In Dialog::dispatch, default(ServerOutOfDialogRequest), msg: " << msg );            
358              // only can be one ServerOutOfDialogReq at a time              // only can be one ServerOutOfDialogReq at a time
359              assert(mServerOutOfDialogRequest == 0);              assert(mServerOutOfDialogRequest == 0);
360              mServerOutOfDialogRequest = mDum.makeServerOutOfDialog(*this, request);              mServerOutOfDialogRequest = makeServerOutOfDialog(request);
361              mServerOutOfDialogRequest->dispatch(request);              mServerOutOfDialogRequest->dispatch(request);
362              break;              break;
363        }        }
364     }     }
365     else if (msg.isResponse())     else if (msg.isResponse())
366     {     {
367    #if 0
368          //Auth related
369          if (mDum.mClientAuthManager && !mDialogSet.mCancelled)
370          {
371             if (mDialogSet.getCreator())
372             {
373                if ( mDum.mClientAuthManager->handle( mDialogSet.getCreator()->getLastRequest(), msg))
374                {
375                   InfoLog( << "about to retransmit request with digest credentials" );
376                   InfoLog( << mDialogSet.getCreator()->getLastRequest() );
377                  
378                   mDum.send(mDialogSet.getCreator()->getLastRequest());
379                   return;
380                }
381             }
382             else
383             {
384                SipMessage* lastRequest = 0;            
385                switch (msg.header(h_CSeq).method())
386                {
387                   case INVITE:
388                   case CANCEL:
389                   case REFER:
390                      if (mInviteSession == 0)
391                      {
392                         return;
393                      }
394                      else
395                      {
396                         lastRequest = &mInviteSession->mLastRequest;
397                      }
398                      break;              
399                   case REGISTER:
400                      if (mClientRegistration == 0)
401                      {
402                         return;
403                      }
404                      else
405                      {
406                         lastRequest = &mClientRegistration->mLastRequest;
407                      }
408                      break;              
409                   default:
410                      break;
411                }
412                if ( lastRequest && mDum.mClientAuthManager->handle( *lastRequest, msg ) )
413                {
414                   InfoLog( << "about to retransmit request with digest credentials" );
415                   InfoLog( << *lastRequest );
416                  
417                   mDum.send(*lastRequest);
418                   return;
419                }
420             }
421          }
422    #endif
423        const SipMessage& response = msg;        const SipMessage& response = msg;
424        // !jf! should this only be for 2xx responses?        // !jf! should this only be for 2xx responses? !jf! Propose no as an
425          // answer !dcm! what is he on?
426        switch (response.header(h_CSeq).method())        switch (response.header(h_CSeq).method())
427        {        {
428           case INVITE:           case INVITE:
429              if (mInviteSession == 0)              if (mInviteSession == 0)
430              {              {
431                 BaseCreator* creator = mDum.findCreator(mId);                 // #if!jf! don't think creator needs a dispatch
432                 assert (creator);                 //BaseCreator* creator = mDum.findCreator(mId);
433                 creator->dispatch(response);                 //assert (creator); // stray responses have been rejected already
434                 if (response.header(h_StatusLine).statusCode() != 100)                 //creator->dispatch(response);
435                 {                 // #endif!jf!
436                    mInviteSession = mDum.makeClientInviteSession(*this, response);                 InfoLog ( << "Dialog::dispatch  --  Created new client invite session" << msg.brief());
437    
438                   mInviteSession = makeClientInviteSession(response);
439                    mInviteSession->dispatch(response);                    mInviteSession->dispatch(response);
440                 }                 }
             }  
441              else              else
442              {              {
443                 mInviteSession->dispatch(response);                 mInviteSession->dispatch(response);
444              }              }
445              break;              break;
446                           case BYE:
447           case ACK:           case ACK:
448           case CANCEL:           case CANCEL:
449              if (mInviteSession != 0)              if (mInviteSession != 0)
# Line 330  Line 463 
463              }              }
464              else              else
465              {              {
466                 ClientSubscription* sub = mDum.makeClientSubscription(*this, response);                 ClientSubscription* sub = makeClientSubscription(response);
467                 mClientSubscriptions.push_back(sub);                 mClientSubscriptions.push_back(sub);
468                 sub->dispatch(response);                 sub->dispatch(response);
469              }              }
# Line 338  Line 471 
471           }           }
472                                
473           case PUBLISH:           case PUBLISH:
474                // !jf! could assert that no other usages exist
475              if (mClientPublication == 0)              if (mClientPublication == 0)
476              {              {
477                 mClientPublication = mDum.makeClientPublication(*this, response);                 mClientPublication = makeClientPublication(response);
478              }              }
479              mClientPublication->dispatch(response);              mClientPublication->dispatch(response);
480              break;              break;
481                                
482           case REGISTER:           case REGISTER:
483                // !jf! could assert that no other usages exist
484              if (mClientRegistration == 0)              if (mClientRegistration == 0)
485              {              {
486                 mClientRegistration = mDum.makeClientRegistration(*this, response);                 mClientRegistration = makeClientRegistration(response);
487              }              }
488              mClientRegistration->dispatch(response);              mClientRegistration->dispatch(response);
489              break;              break;
# Line 363  Line 498 
498              ClientOutOfDialogReq* req = findMatchingClientOutOfDialogReq(response);              ClientOutOfDialogReq* req = findMatchingClientOutOfDialogReq(response);
499              if (req == 0)              if (req == 0)
500              {              {
501                 req = mDum.makeClientOutOfDialogReq(*this, response);                 req = makeClientOutOfDialogReq(response);
502                 mClientOutOfDialogRequests.push_back(req);                 mClientOutOfDialogRequests.push_back(req);
503              }              }
504              req->dispatch(response);              req->dispatch(response);
# Line 374  Line 509 
509  }  }
510    
511    
512    
513    
514  ClientSubscription*  ClientSubscription*
515  Dialog::findMatchingClientSub(const SipMessage& msg)  Dialog::findMatchingClientSub(const SipMessage& msg)
516  {  {
# Line 403  Line 540 
540  }  }
541    
542    
543  InviteSession::Handle  InviteSessionHandle
544  Dialog::findInviteSession()  Dialog::findInviteSession()
545  {  {
546     if (mInviteSession)     if (mInviteSession)
# Line 417  Line 554 
554     }     }
555  }  }
556    
557  std::vector<ClientSubscription::Handle>  std::vector<ClientSubscriptionHandle>
558  Dialog::findClientSubscriptions()  Dialog::findClientSubscriptions()
559  {  {
560     std::vector<ClientSubscription::Handle> handles;     std::vector<ClientSubscriptionHandle> handles;
561        
562     for (std::list<ClientSubscription*>::const_iterator i = mClientSubscriptions.begin();     for (std::list<ClientSubscription*>::const_iterator i = mClientSubscriptions.begin();
563          i != mClientSubscriptions.end(); ++i)          i != mClientSubscriptions.end(); ++i)
# Line 431  Line 568 
568     return handles;     return handles;
569  }  }
570    
571  ClientRegistration::Handle  ClientRegistrationHandle
572  Dialog::findClientRegistration()  Dialog::findClientRegistration()
573  {  {
574     if (mClientRegistration)     if (mClientRegistration)
# Line 445  Line 582 
582     }     }
583  }  }
584    
585  ServerRegistration::Handle  ServerRegistrationHandle
586  Dialog::findServerRegistration()  Dialog::findServerRegistration()
587  {  {
588     if (mServerRegistration)     if (mServerRegistration)
# Line 459  Line 596 
596     }     }
597  }  }
598    
599  ClientPublication::Handle  ClientPublicationHandle
600  Dialog::findClientPublication()  Dialog::findClientPublication()
601  {  {
602     if (mClientPublication)     if (mClientPublication)
# Line 473  Line 610 
610     }     }
611  }  }
612    
613  ServerPublication::Handle  ServerPublicationHandle
614  Dialog::findServerPublication()  Dialog::findServerPublication()
615  {  {
616     if (mServerPublication)     if (mServerPublication)
# Line 488  Line 625 
625  }  }
626    
627  #if 0  #if 0
628  ClientOutOfDialogReq::Handle  ClientOutOfDialogReqHandle
629  Dialog::findClientOutOfDialog()  Dialog::findClientOutOfDialog()
630  {  {
631     if (mClientOutOfDialogRequests)     if (mClientOutOfDialogRequests)
# Line 503  Line 640 
640  }  }
641  #endif  #endif
642    
643  ServerOutOfDialogReq::Handle  ServerOutOfDialogReqHandle
644  Dialog::findServerOutOfDialog()  Dialog::findServerOutOfDialog()
645  {  {
646     if (mServerOutOfDialogRequest)     if (mServerOutOfDialogRequest)
# Line 556  Line 693 
693     rLine.uri() = mRemoteTarget.uri();     rLine.uri() = mRemoteTarget.uri();
694        
695     request.header(h_RequestLine) = rLine;     request.header(h_RequestLine) = rLine;
696     request.header(h_To) = mRemoteTarget;     request.header(h_To) = mRemoteNameAddr;  
697     request.header(h_To).param(p_tag) = mRemoteTag;  //   request.header(h_To).param(p_tag) = mId.getRemoteTag();
698     request.header(h_From) = mLocalContact;     request.header(h_From) = mLocalNameAddr;  
699     request.header(h_From).param(p_tag) = mLocalTag;  //   request.header(h_From).param(p_tag) = mId.getLocalTag();
700    
701     request.header(h_CallId) = mCallId;     request.header(h_CallId) = mCallId;
702     request.header(h_Routes) = mRouteSet;  
703       request.remove(h_RecordRoutes);  //!dcm! -- all of this is rather messy
704    
705       request.remove(h_Contacts);  
706     request.header(h_Contacts).push_front(mLocalContact);     request.header(h_Contacts).push_front(mLocalContact);
707     request.header(h_CSeq).method() = method;     request.header(h_CSeq).method() = method;
708     request.header(h_MaxForwards).value() = 70;     request.header(h_MaxForwards).value() = 70;
709    
710       //must keep old via for cancel
711       if (method != CANCEL)
712       {
713          request.header(h_Routes) = mRouteSet;
714          request.remove(h_Vias);      
715     Via via;     Via via;
716     via.param(p_branch); // will create the branch     via.param(p_branch); // will create the branch
717     request.header(h_Vias).push_front(via);     request.header(h_Vias).push_front(via);
718       }
719       else
720       {
721          assert(request.exists(h_Vias));
722       }
723       //don't increment CSeq for ACK or CANCEL
724       if (method != ACK && method != CANCEL)
725       {
726     request.header(h_CSeq).sequence() = ++mLocalCSeq;     request.header(h_CSeq).sequence() = ++mLocalCSeq;
727  }  }
728       InfoLog ( << "Dialog::makeRequest: " << request );
729    }
730    
731    void
732    Dialog::makeCancel(SipMessage& request)
733    {
734       makeRequest(request, CANCEL);  
735    
736       //not allowed in a CANCEL
737       request.remove(h_Requires);
738       request.remove(h_ProxyRequires);
739    }
740    
741  void  void
742  Dialog::makeResponse(const SipMessage& request, SipMessage& response, int code)  Dialog::makeResponse(SipMessage& response, const SipMessage& request, int code)
743  {  {
744     assert( code >= 100 );     assert( code >= 100 );
745     response.header(h_To).param(p_tag) = mLocalTag;     if (code < 300 && code > 100)
    if ( (code < 300) && (code > 100) )  
746     {     {
747        assert(request.isRequest());        assert(request.isRequest());
748        assert(request.header(h_RequestLine).getMethod() == INVITE ||        assert(request.header(h_RequestLine).getMethod() == INVITE ||
749               request.header(h_RequestLine).getMethod() == SUBSCRIBE);               request.header(h_RequestLine).getMethod() == SUBSCRIBE ||
750                 request.header(h_RequestLine).getMethod() == BYE ||
751                 request.header(h_RequestLine).getMethod() == CANCEL);
752                
753        assert (request.header(h_Contacts).size() == 1);        assert (request.header(h_Contacts).size() == 1);
754        response.header(h_To).param(p_tag) = mLocalTag;        Helper::makeResponse(response, request, code, mLocalContact);
755          response.header(h_To).param(p_tag) = mId.getLocalTag();
756       }
757       else
758       {
759          Helper::makeResponse(response, request, code, mLocalContact);
760          response.header(h_To).param(p_tag) = mId.getLocalTag();
761    
762       }
763       InfoLog ( << "Dialog::makeResponse: " << response);  
764    }
765    
       Helper::makeResponse(response, request, code);  
766    
767        if (!request.exists(h_Contacts) && request.header(h_Contacts).size() != 1)  ClientInviteSession*
768    Dialog::makeClientInviteSession(const SipMessage& response)
769        {        {
770           InfoLog (<< "Request doesn't have a contact header or more than one contact, so can't create dialog");     InviteSessionCreator* creator = dynamic_cast<InviteSessionCreator*>(mDialogSet.getCreator());
771           DebugLog (<< request);     assert(creator); // !jf! this maybe can assert by evil UAS
772           throw Exception("Invalid or missing contact header in request", __FILE__,__LINE__);     //return mDum.createAppClientInviteSession(*this, *creator);
773       return new ClientInviteSession(mDum, *this, creator->getLastRequest(), creator->getInitialOffer());
774        }        }
775    
776        assert (response.header(h_To).exists(p_tag));  ClientRegistration*
777    Dialog::makeClientRegistration(const SipMessage& response)
778    {
779       BaseCreator* creator = mDialogSet.getCreator();
780       assert(creator);
781       return new ClientRegistration(mDum, *this, creator->getLastRequest());
782     }     }
783     else  
784    ClientPublication*
785    Dialog::makeClientPublication(const SipMessage& response)
786     {     {
787        Helper::makeResponse(response, request, code, mLocalContact);     BaseCreator* creator = mDialogSet.getCreator();
788       assert(creator);
789       return new ClientPublication(mDum, *this, creator->getLastRequest());
790    }
791    
792    ClientSubscription*
793    Dialog::makeClientSubscription(const SipMessage& response)
794    {
795       BaseCreator* creator = mDialogSet.getCreator();
796       assert(creator);
797       return new ClientSubscription(mDum, *this, creator->getLastRequest());
798    }
799    
800    ClientOutOfDialogReq*
801    Dialog::makeClientOutOfDialogReq(const SipMessage& response)
802    {
803       BaseCreator* creator = mDialogSet.getCreator();
804       assert(creator);
805       return new ClientOutOfDialogReq(mDum, *this, creator->getLastRequest());
806    }
807    
808    ServerInviteSession*
809    Dialog::makeServerInviteSession(const SipMessage& request)
810    {
811       return new ServerInviteSession(mDum, *this, request);
812    }
813    
814    ServerSubscription*
815    Dialog::makeServerSubscription(const SipMessage& request)
816    {
817       return new ServerSubscription(mDum, *this, request);
818     }     }
819    
820    ServerRegistration*
821    Dialog::makeServerRegistration(const SipMessage& request)
822    {
823       return new ServerRegistration(mDum, *this, request);
824    }
825    
826    ServerPublication*
827    Dialog::makeServerPublication(const SipMessage& request)
828    {
829       return new ServerPublication(mDum, *this, request);
830    }
831    
832    ServerOutOfDialogReq*
833    Dialog::makeServerOutOfDialog(const SipMessage& request)
834    {
835       return new ServerOutOfDialogReq(mDum, *this, request);
836  }  }
837    
838  Dialog::Exception::Exception(const Data& msg, const Data& file, int line)  Dialog::Exception::Exception(const Data& msg, const Data& file, int line)
839     : BaseException(msg, file, line)     : BaseException(msg, file, line)
840  {}  {
841    }
842    
843  void  void
844  Dialog::update(const SipMessage& msg)  Dialog::update(const SipMessage& msg)
# Line 631  Line 861 
861    
862  void Dialog::possiblyDie()  void Dialog::possiblyDie()
863  {  {
864       if (!mDestroying)
865       {
866     if (mClientSubscriptions.empty() &&     if (mClientSubscriptions.empty() &&
867         mClientOutOfDialogRequests.empty() &&         mClientOutOfDialogRequests.empty() &&
868         !(mServerSubscription ||         !(mServerSubscription ||
# Line 644  Line 876 
876        delete this;        delete this;
877     }     }
878  }  }
879    }
880    
881  ostream&  ostream&
882  resip::operator<<(ostream& strm, const Dialog& dialog)  resip::operator<<(ostream& strm, const Dialog& dialog)

Legend:
Removed from v.2884  
changed lines
  Added in v.3026

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27