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

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

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

revision 5012 by sgodin, Wed Jun 29 12:36:04 2005 UTC revision 5068 by daniel, Fri Jul 15 17:14:51 2005 UTC
# Line 1  Line 1 
1  #include "resiprocate/MultipartMixedContents.hxx"  #include "resiprocate/MultipartMixedContents.hxx"
2    #include "resiprocate/MultipartAlternativeContents.hxx"
3  #include "resiprocate/SdpContents.hxx"  #include "resiprocate/SdpContents.hxx"
4  #include "resiprocate/SipMessage.hxx"  #include "resiprocate/SipMessage.hxx"
5  #include "resiprocate/Helper.hxx"  #include "resiprocate/Helper.hxx"
# Line 40  Line 41 
41       mMinSE(90),       mMinSE(90),
42       mSessionRefresher(false),       mSessionRefresher(false),
43       mSessionTimerSeq(0),       mSessionTimerSeq(0),
44       mSentRefer(false)       mSentRefer(false),
45         mCurrentEncryptionLevel(DialogUsageManager::None),
46         mProposedEncryptionLevel(DialogUsageManager::None)
47  {  {
48     DebugLog ( << "^^^ InviteSession::InviteSession " << this);     DebugLog ( << "^^^ InviteSession::InviteSession " << this);
49     assert(mDum.mInviteSessionHandler);     assert(mDum.mInviteSessionHandler);
# Line 209  Line 212 
212  }  }
213    
214  void  void
215  InviteSession::provideOffer(const SdpContents& offer)  InviteSession::provideOffer(const SdpContents& offer,
216                                DialogUsageManager::EncryptionLevel level,
217                                const SdpContents* alternative)
218  {  {
219     switch (mState)     switch (mState)
220     {     {
# Line 229  Line 234 
234           setSessionTimerHeaders(mLastSessionModification);           setSessionTimerHeaders(mLastSessionModification);
235    
236           InfoLog (<< "Sending " << mLastSessionModification.brief());           InfoLog (<< "Sending " << mLastSessionModification.brief());
237           InviteSession::setSdp(mLastSessionModification, offer);           InviteSession::setSdp(mLastSessionModification, offer, alternative);
238           mProposedLocalSdp = InviteSession::makeSdp(offer);           mProposedLocalSdp = InviteSession::makeSdp(offer, alternative);
239           mDialog.send(mLastSessionModification);           mProposedEncryptionLevel = level;
240             mDialog.send(mLastSessionModification, mProposedEncryptionLevel);
241           break;           break;
242    
243        case Answered:        case Answered:
244           // queue the offer to be sent after the ACK is received           // queue the offer to be sent after the ACK is received
245           transition(WaitingToOffer);           transition(WaitingToOffer);
246           mProposedLocalSdp = InviteSession::makeSdp(offer);           mProposedEncryptionLevel = level;
247             mProposedLocalSdp = InviteSession::makeSdp(offer, alternative);
248           break;           break;
249    
250        // ?slg? Can we handle all of the states listed in isConnected() ???        // ?slg? Can we handle all of the states listed in isConnected() ???
# Line 248  Line 255 
255  }  }
256    
257  void  void
258    InviteSession::provideOffer(const SdpContents& offer)
259    {
260       return provideOffer(offer, mCurrentEncryptionLevel, 0);
261    }
262    
263    void
264  InviteSession::provideAnswer(const SdpContents& answer)  InviteSession::provideAnswer(const SdpContents& answer)
265  {  {
266     switch (mState)     switch (mState)
# Line 256  Line 269 
269           transition(Connected);           transition(Connected);
270           mDialog.makeResponse(mInvite200, mLastSessionModification, 200);           mDialog.makeResponse(mInvite200, mLastSessionModification, 200);
271           handleSessionTimerRequest(mInvite200, mLastSessionModification);           handleSessionTimerRequest(mInvite200, mLastSessionModification);
272           InviteSession::setSdp(mInvite200, answer);           InviteSession::setSdp(mInvite200, answer, 0);
273           mCurrentLocalSdp = InviteSession::makeSdp(answer);           mCurrentLocalSdp = InviteSession::makeSdp(answer);
274           mCurrentRemoteSdp = mProposedRemoteSdp;           mCurrentRemoteSdp = mProposedRemoteSdp;
275           InfoLog (<< "Sending " << mInvite200.brief());           InfoLog (<< "Sending " << mInvite200.brief());
276           mDialog.send(mInvite200);           mDialog.send(mInvite200, mCurrentEncryptionLevel);
277           startRetransmit200Timer();           startRetransmit200Timer();
278           break;           break;
279    
# Line 271  Line 284 
284           SipMessage response;           SipMessage response;
285           mDialog.makeResponse(response, mLastSessionModification, 200);           mDialog.makeResponse(response, mLastSessionModification, 200);
286           handleSessionTimerRequest(response, mLastSessionModification);           handleSessionTimerRequest(response, mLastSessionModification);
287           InviteSession::setSdp(response, answer);           InviteSession::setSdp(response, answer, 0);
288           mCurrentLocalSdp = InviteSession::makeSdp(answer);           mCurrentLocalSdp = InviteSession::makeSdp(answer);
289           mCurrentRemoteSdp = mProposedRemoteSdp;           mCurrentRemoteSdp = mProposedRemoteSdp;
290           InfoLog (<< "Sending " << response.brief());           InfoLog (<< "Sending " << response.brief());
291           mDialog.send(response);           mDialog.send(response, mCurrentEncryptionLevel);
292           break;           break;
293        }        }
294    
# Line 464  Line 477 
477           mDialog.makeRequest(info, INFO);           mDialog.makeRequest(info, INFO);
478           // !jf! handle multipart here           // !jf! handle multipart here
479           info.setContents(&contents);           info.setContents(&contents);
480           mDialog.send(info);           mDialog.send(info, mCurrentEncryptionLevel);
481        }        }
482        else        else
483        {        {
# Line 532  Line 545 
545        if (mCurrentRetransmit200)        if (mCurrentRetransmit200)
546        {        {
547           InfoLog (<< "Retransmitting: " << endl << mInvite200);           InfoLog (<< "Retransmitting: " << endl << mInvite200);
548           mDialog.send(mInvite200);           mDialog.send(mInvite200, DialogUsageManager::None);
549           mCurrentRetransmit200 *= 2;           mCurrentRetransmit200 *= 2;
550           mDum.addTimerMs(DumTimeout::Retransmit200, resipMin(Timer::T2, mCurrentRetransmit200), getBaseHandle(),  timeout.seq());           mDum.addTimerMs(DumTimeout::Retransmit200, resipMin(Timer::T2, mCurrentRetransmit200), getBaseHandle(),  timeout.seq());
551        }        }
# Line 563  Line 576 
576           transition(SentUpdate);           transition(SentUpdate);
577    
578           InfoLog (<< "Retransmitting the UPDATE (glare condition timer)");           InfoLog (<< "Retransmitting the UPDATE (glare condition timer)");
579           mDialog.send(mLastSessionModification);           mDialog.send(mLastSessionModification, DialogUsageManager::None);
580        }        }
581        else if (mState == SentReinviteGlare)        else if (mState == SentReinviteGlare)
582        {        {
583           transition(SentReinvite);           transition(SentReinvite);
584    
585           InfoLog (<< "Retransmitting the reINVITE (glare condition timer)");           InfoLog (<< "Retransmitting the reINVITE (glare condition timer)");
586           mDialog.send(mLastSessionModification);           mDialog.send(mLastSessionModification, DialogUsageManager::None);
587        }        }
588     }     }
589     else if (timeout.type() == DumTimeout::SessionExpiration)     else if (timeout.type() == DumTimeout::SessionExpiration)
# Line 594  Line 607 
607     }     }
608  }  }
609    
   
610  void  void
611  InviteSession::dispatchConnected(const SipMessage& msg)  InviteSession::dispatchConnected(const SipMessage& msg)
612  {  {
# Line 615  Line 627 
627        case OnInviteReliableOffer:        case OnInviteReliableOffer:
628           mLastSessionModification = msg;           mLastSessionModification = msg;
629           transition(ReceivedReinvite);           transition(ReceivedReinvite);
630             mCurrentEncryptionLevel = getEncryptionLevel(msg);
631           //handler->onDialogModified(getSessionHandle(), Offer, msg);           //handler->onDialogModified(getSessionHandle(), Offer, msg);
632           handler->onOffer(getSessionHandle(), msg, *sdp);           handler->onOffer(getSessionHandle(), msg, *sdp);
633           break;           break;
# Line 634  Line 647 
647           //  Find out if it's an UPDATE requiring state change.           //  Find out if it's an UPDATE requiring state change.
648           //  See rfc3311 5.2, 4th paragraph.           //  See rfc3311 5.2, 4th paragraph.
649           mLastSessionModification = msg;           mLastSessionModification = msg;
650             mCurrentEncryptionLevel = getEncryptionLevel(msg);
651           handler->onOffer(getSessionHandle(), msg, *sdp);           handler->onOffer(getSessionHandle(), msg, *sdp);
652           break;           break;
653    
# Line 664  Line 678 
678     }     }
679  }  }
680    
   
   
681  void  void
682  InviteSession::dispatchSentUpdate(const SipMessage& msg)  InviteSession::dispatchSentUpdate(const SipMessage& msg)
683  {  {
# Line 693  Line 705 
705           handleSessionTimerResponse(msg);           handleSessionTimerResponse(msg);
706           if (sdp.get())           if (sdp.get())
707           {           {
708              mCurrentLocalSdp = mProposedLocalSdp;              mCurrentEncryptionLevel = getEncryptionLevel(msg);
709                setCurrentLocalSdp(msg);
710              mCurrentRemoteSdp = InviteSession::makeSdp(*sdp);              mCurrentRemoteSdp = InviteSession::makeSdp(*sdp);
711              handler->onAnswer(getSessionHandle(), msg, *sdp);              handler->onAnswer(getSessionHandle(), msg, *sdp);
712           }           }
# Line 702  Line 715 
715              // If we sent an offer in the Update Request and no answer is received              // If we sent an offer in the Update Request and no answer is received
716              handler->onIllegalNegotiation(getSessionHandle(), msg);              handler->onIllegalNegotiation(getSessionHandle(), msg);
717              mProposedLocalSdp.release();              mProposedLocalSdp.release();
718                mProposedEncryptionLevel = DialogUsageManager::None;
719           }           }
720           break;           break;
721    
# Line 710  Line 724 
724           start491Timer();           start491Timer();
725           break;           break;
726    
727        case On422Update:        case On422Update: // session timer
728           if(msg.exists(h_MinSE))           if(msg.exists(h_MinSE))
729           {           {
730              // Change interval to min from 422 response              // Change interval to min from 422 response
# Line 724  Line 738 
738              // ?slg? callback?              // ?slg? callback?
739              transition(Connected);              transition(Connected);
740              mProposedLocalSdp.release();              mProposedLocalSdp.release();
741                mProposedEncryptionLevel = DialogUsageManager::None;
742           }           }
743           break;           break;
744    
745        case OnUpdateRejected:        case OnUpdateRejected:
746           // !jf! - callback?           // !jf! - callback?
747           mProposedLocalSdp.release();           mProposedLocalSdp.release();
748             mProposedEncryptionLevel = DialogUsageManager::None;
749           transition(Connected);           transition(Connected);
750           break;           break;
751    
# Line 776  Line 792 
792        {        {
793           transition(Connected);           transition(Connected);
794           handleSessionTimerResponse(msg);           handleSessionTimerResponse(msg);
795           mCurrentLocalSdp = mProposedLocalSdp;           setCurrentLocalSdp(msg);
796           mCurrentRemoteSdp = InviteSession::makeSdp(*sdp);           mCurrentRemoteSdp = InviteSession::makeSdp(*sdp);
797             mCurrentEncryptionLevel = getEncryptionLevel(msg);
798           // !jf! I need to potentially include an answer in the ACK here           // !jf! I need to potentially include an answer in the ACK here
799           sendAck();           sendAck();
800           handler->onAnswer(getSessionHandle(), msg, *sdp);           handler->onAnswer(getSessionHandle(), msg, *sdp);
# Line 794  Line 811 
811           handleSessionTimerResponse(msg);           handleSessionTimerResponse(msg);
812           handler->onIllegalNegotiation(getSessionHandle(), msg);           handler->onIllegalNegotiation(getSessionHandle(), msg);
813           mProposedLocalSdp.release();           mProposedLocalSdp.release();
814             mProposedEncryptionLevel = DialogUsageManager::None;
815           break;           break;
816    
817        case On422Invite:        case On422Invite:
# Line 810  Line 828 
828              // ?slg? callback?              // ?slg? callback?
829              transition(Connected);              transition(Connected);
830              mProposedLocalSdp.release();              mProposedLocalSdp.release();
831                mProposedEncryptionLevel = DialogUsageManager::None;
832           }           }
833           break;           break;
834    
# Line 898  Line 917 
917  {  {
918     if (msg.isRequest() && msg.header(h_RequestLine).method() == ACK)     if (msg.isRequest() && msg.header(h_RequestLine).method() == ACK)
919     {     {
920    
921          assert(mProposedLocalSdp.get());
922        mCurrentRetransmit200 = 0; // stop the 200 retransmit timer        mCurrentRetransmit200 = 0; // stop the 200 retransmit timer
923        provideOffer(*mProposedLocalSdp);        if (dynamic_cast<MultipartAlternativeContents*>(mProposedLocalSdp.get()))
924          {
925             provideOffer( *(dynamic_cast<SdpContents*>((dynamic_cast<MultipartAlternativeContents*>(mProposedLocalSdp.get()))->parts().back())),
926                           mProposedEncryptionLevel,
927                           dynamic_cast<SdpContents*>((dynamic_cast<MultipartAlternativeContents*>(mProposedLocalSdp.get()))->parts().front()));
928          }
929          else
930          {
931             provideOffer(*(dynamic_cast<SdpContents*>(mProposedLocalSdp.get())), mProposedEncryptionLevel, 0);
932          }
933     }     }
934     else     else
935     {     {
# Line 1168  Line 1198 
1198     {     {
1199        transition(SentReinvite);        transition(SentReinvite);
1200        mDialog.makeRequest(mLastSessionModification, INVITE);        mDialog.makeRequest(mLastSessionModification, INVITE);
1201        InviteSession::setSdp(mLastSessionModification, *mCurrentLocalSdp);        InviteSession::setSdp(mLastSessionModification, mCurrentLocalSdp.get());
1202        mProposedLocalSdp = InviteSession::makeSdp(*mCurrentLocalSdp);        mProposedLocalSdp = InviteSession::makeSdp(*mCurrentLocalSdp.get(), 0);
1203     }     }
1204     setSessionTimerHeaders(mLastSessionModification);     setSessionTimerHeaders(mLastSessionModification);
1205    
1206     InfoLog (<< "sessionRefresh: Sending " << mLastSessionModification.brief());     InfoLog (<< "sessionRefresh: Sending " << mLastSessionModification.brief());
1207     mDialog.send(mLastSessionModification);     mDialog.send(mLastSessionModification, mCurrentEncryptionLevel);
1208  }  }
1209    
1210  void  void
# Line 1472  Line 1502 
1502     return std::auto_ptr<SdpContents>(static_cast<SdpContents*>(sdp.clone()));     return std::auto_ptr<SdpContents>(static_cast<SdpContents*>(sdp.clone()));
1503  }  }
1504    
1505    auto_ptr<Contents>
1506    InviteSession::makeSdp(const SdpContents& sdp,
1507                           const SdpContents* alternative)
1508    {
1509       if (alternative)
1510       {
1511          MultipartAlternativeContents* mac = new MultipartAlternativeContents;
1512          mac->parts().push_back(alternative->clone());
1513          mac->parts().push_back(sdp.clone());
1514          return auto_ptr<Contents>(mac);
1515       }
1516       else
1517       {
1518          return auto_ptr<Contents>(sdp.clone());
1519       }
1520    }
1521    
1522  void  void
1523  InviteSession::setSdp(SipMessage& msg, const SdpContents& sdp)  InviteSession::setSdp(SipMessage& msg, const SdpContents& sdp, const SdpContents* alternative)
1524  {  {
1525     // !jf! should deal with multipart here     // !jf! should deal with multipart here
1526    
1527     // This will clone the sdp since the InviteSession also wants to keep its own     // This will clone the sdp since the InviteSession also wants to keep its own
1528     // copy of the sdp around for the application to access     // copy of the sdp around for the application to access
1529       if (alternative)
1530       {
1531          MultipartAlternativeContents* mac = new MultipartAlternativeContents;
1532          mac->parts().push_back(alternative->clone());
1533          mac->parts().push_back(sdp.clone());
1534          msg.setContents(auto_ptr<Contents>(mac));
1535       }
1536       else
1537       {
1538     msg.setContents(&sdp);     msg.setContents(&sdp);
1539  }  }
1540    }
1541    
1542    void
1543    InviteSession::setSdp(SipMessage& msg, const Contents* sdp)
1544    {
1545       assert(sdp);
1546       msg.setContents(sdp);
1547    }
1548    
1549  InviteSession::Event  InviteSession::Event
1550  InviteSession::toEvent(const SipMessage& msg, const SdpContents* sdp)  InviteSession::toEvent(const SipMessage& msg, const SdpContents* sdp)
# Line 1690  Line 1754 
1754     mDialog.send(bye);     mDialog.send(bye);
1755  }  }
1756    
1757    DialogUsageManager::EncryptionLevel InviteSession::getEncryptionLevel(const SipMessage& msg)
1758    {
1759       DialogUsageManager::EncryptionLevel level = DialogUsageManager::None;
1760       const SecurityAttributes* secAttr = msg.getSecurityAttributes();
1761       if (secAttr)
1762       {
1763          SignatureStatus sig = secAttr->getSignatureStatus();
1764          bool sign = (SignatureTrusted == sig || SignatureCATrusted == sig || SignatureSelfSigned == sig);
1765          bool encrypted = secAttr->isEncrypted();
1766          if (encrypted && sign ) level = DialogUsageManager::SignAndEncrypt;
1767          else if (encrypted) level = DialogUsageManager::Encrypt;
1768          else if (sign) level = DialogUsageManager::Sign;
1769       }
1770       return level;
1771    }
1772    
1773    void InviteSession::setCurrentLocalSdp(const SipMessage& msg)
1774    {
1775       assert(mProposedLocalSdp.get());
1776       if (dynamic_cast<MultipartAlternativeContents*>(mProposedLocalSdp.get()))
1777       {
1778          if (DialogUsageManager::Encrypt == getEncryptionLevel(msg) || DialogUsageManager::SignAndEncrypt == getEncryptionLevel(msg))
1779          {
1780             mCurrentLocalSdp = auto_ptr<SdpContents>(static_cast<SdpContents*>((dynamic_cast<MultipartAlternativeContents*>(mProposedLocalSdp.get()))->parts().back()->clone()));
1781          }
1782          else
1783          {
1784             mCurrentLocalSdp = auto_ptr<SdpContents>(static_cast<SdpContents*>((dynamic_cast<MultipartAlternativeContents*>(mProposedLocalSdp.get()))->parts().front()->clone()));
1785          }
1786       }
1787       else
1788       {
1789          mCurrentLocalSdp = auto_ptr<SdpContents>(static_cast<SdpContents*>(mProposedLocalSdp.get()->clone()));
1790       }
1791       mProposedLocalSdp.release();
1792    }
1793    
1794    
1795  /* ====================================================================  /* ====================================================================
1796   * The Vovida Software License, Version 1.0   * The Vovida Software License, Version 1.0

Legend:
Removed from v.5012  
changed lines
  Added in v.5068

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27