|
reSIProcate/DialogUsageManager
9694
|
00001 #if !defined(RESIP_INVITESESSION_HXX) 00002 #define RESIP_INVITESESSION_HXX 00003 00004 #include "resip/stack/SipMessage.hxx" 00005 #include "resip/stack/Contents.hxx" 00006 #include "resip/dum/DialogUsage.hxx" 00007 #include "resip/dum/DialogUsageManager.hxx" 00008 00009 #include <map> 00010 #include <queue> 00011 00012 namespace resip 00013 { 00014 00015 class Contents; 00016 class SdpContents; 00017 00022 class InviteSession : public DialogUsage 00023 { 00024 public: 00029 virtual void provideOffer(const Contents& offer); 00030 virtual void provideOffer(const Contents& offer, DialogUsageManager::EncryptionLevel level, const Contents* alternative); 00031 00035 virtual void provideAnswer(const Contents& answer); 00036 00039 virtual void requestOffer(); 00040 00041 typedef enum 00042 { 00043 None, // means no Offer or Answer (may have body) 00044 Offer, 00045 Answer 00046 } OfferAnswerType; 00047 00048 // WARNING: Do not change this list without appropriately adjusting the 00049 // EndReasons array in InviteSession.cxx 00050 enum EndReason 00051 { 00052 NotSpecified=0, 00053 UserHangup, 00054 AppRejectedSdp, 00055 IllegalNegotiation, 00056 AckNotReceived, 00057 SessionExpired, 00058 StaleReInvite, 00059 ENDREASON_MAX, // Maximum used by the global array in InviteSession.cxx 00060 UserSpecified // User-specified reason - doesn't use the array in InviteSession.cxx 00061 }; 00062 00064 virtual void end(const Data& userReason); 00065 virtual void end(EndReason reason); 00066 virtual void end(); // reason == NotSpecified ; same as above - required for BaseUsage pure virtual 00067 00070 virtual void reject(int statusCode, WarningCategory *warning = 0); 00071 00073 virtual void targetRefresh(const NameAddr& localUri); 00074 00075 // Following methods are for sending requests within a dialog 00076 00078 virtual void refer(const NameAddr& referTo, bool referSub = true); 00079 virtual void refer(const NameAddr& referTo, std::auto_ptr<resip::Contents> contents, bool referSub = true); 00080 00082 virtual void refer(const NameAddr& referTo, InviteSessionHandle sessionToReplace, bool referSub = true); 00083 virtual void refer(const NameAddr& referTo, InviteSessionHandle sessionToReplace, std::auto_ptr<resip::Contents> contents, bool referSub = true); 00084 virtual void refer(const NameAddr& referTo, const CallId& replaces, bool referSub = true); 00085 virtual void refer(const NameAddr& referTo, const CallId& replaces, std::auto_ptr<resip::Contents> contents, bool referSub = true); 00086 00088 virtual void info(const Contents& contents); 00089 00100 virtual void message(const Contents& contents); 00101 00103 virtual void acceptNIT(int statusCode = 200, const Contents * contents = 0); 00104 00106 virtual void rejectNIT(int statusCode = 488); 00107 00112 const SharedPtr<SipMessage> getLastSentNITRequest() const; 00113 00117 virtual void provideOfferCommand(const Contents& offer); 00118 virtual void provideOfferCommand(const Contents& offer, DialogUsageManager::EncryptionLevel level, const Contents* alternative); 00119 virtual void provideAnswerCommand(const Contents& answer); 00121 virtual void endCommand(EndReason reason = NotSpecified); 00124 virtual void rejectCommand(int statusCode, WarningCategory *warning = 0); 00125 virtual void referCommand(const NameAddr& referTo, bool referSub = true); 00126 virtual void referCommand(const NameAddr& referTo, InviteSessionHandle sessionToReplace, bool referSub = true); 00127 virtual void infoCommand(const Contents& contents); 00128 virtual void messageCommand(const Contents& contents); 00130 virtual void acceptNITCommand(int statusCode = 200, const Contents * contents = 0); 00132 virtual void rejectNITCommand(int statusCode = 488); 00133 00134 virtual void acceptReferNoSub(int statusCode = 200); 00135 virtual void rejectReferNoSub(int responseCode); 00136 00137 bool hasLocalOfferAnswer() const; 00138 const Contents& getLocalOfferAnswer() const; 00139 bool hasRemoteOfferAnswer() const; 00140 const Contents& getRemoteOfferAnswer() const; 00141 bool hasProposedRemoteOfferAnswer() const; 00142 const Contents& getProposedRemoteOfferAnswer() const; 00143 00144 // Note: The following fn's are for backwards compatibility and are only valid to call 00145 // if the InviteSessionHandler is not in Generic mode (ie. 00146 // InviteSessionHandler::isGenericOfferAnswer is false) 00147 bool hasLocalSdp() const; 00148 const SdpContents& getLocalSdp() const; 00149 bool hasRemoteSdp() const; 00150 const SdpContents& getRemoteSdp() const; 00151 bool hasProposedRemoteSdp() const; 00152 const SdpContents& getProposedRemoteSdp() const; 00153 00154 bool isConnected() const; 00155 bool isTerminated() const; 00156 bool isEarly() const; // UAC Early states 00157 bool isAccepted() const; // UAS States after accept is called 00158 00159 Tokens& getPeerSupportedMethods() { return mPeerSupportedMethods; } 00160 Tokens& getPeerSupportedOptionTags() { return mPeerSupportedOptionTags; } 00161 Mimes& getPeerSupportedMimeTypes() { return mPeerSupportedMimeTypes; } 00162 Tokens& getPeerSupportedEncodings() { return mPeerSupportedEncodings; } 00163 Tokens& getPeerSupportedLanguages() { return mPeerSupportedLanguages; } 00164 Tokens& getPeerAllowedEvents() { return mPeerAllowedEvents; } 00165 Data& getPeerUserAgent() { return mPeerUserAgent; } 00166 NameAddrs& getPeerPAssertedIdentities() { return mPeerPAssertedIdentities; } 00167 00168 virtual EncodeStream& dump(EncodeStream& strm) const; 00169 InviteSessionHandle getSessionHandle(); 00170 00171 protected: 00172 00173 typedef enum 00174 { 00175 Undefined, // Not used 00176 Connected, 00177 SentUpdate, // Sent an UPDATE 00178 SentUpdateGlare, // got a 491 00179 SentReinvite, // Sent a reINVITE 00180 SentReinviteGlare, // Got a 491 00181 SentReinviteNoOffer, // Sent a reINVITE with no offer (requestOffer) 00182 SentReinviteAnswered, // Sent a reINVITE no offer and received a 200-offer 00183 SentReinviteNoOfferGlare, // Got a 491 00184 ReceivedUpdate, // Received an UPDATE 00185 ReceivedReinvite, // Received a reINVITE 00186 ReceivedReinviteNoOffer, // Received a reINVITE with no offer 00187 ReceivedReinviteSentOffer, // Sent a 200 to a reINVITE with no offer 00188 Answered, 00189 WaitingToOffer, 00190 WaitingToRequestOffer, 00191 WaitingToTerminate, // Waiting for 2xx response before sending BYE 00192 WaitingToHangup, // Waiting for ACK before sending BYE 00193 Terminated, // Ended. waiting to delete 00194 00195 UAC_Start, 00196 UAC_Early, 00197 UAC_EarlyWithOffer, 00198 UAC_EarlyWithAnswer, 00199 UAC_Answered, 00200 UAC_SentUpdateEarly, 00201 UAC_SentUpdateEarlyGlare, 00202 UAC_ReceivedUpdateEarly, 00203 UAC_SentAnswer, 00204 UAC_QueuedUpdate, 00205 UAC_Cancelled, 00206 00207 UAS_Start, 00208 UAS_Offer, 00209 UAS_OfferProvidedAnswer, 00210 UAS_EarlyOffer, 00211 UAS_EarlyProvidedAnswer, 00212 00213 UAS_NoOffer, 00214 UAS_ProvidedOffer, 00215 UAS_EarlyNoOffer, 00216 UAS_EarlyProvidedOffer, 00217 UAS_Accepted, 00218 UAS_WaitingToOffer, 00219 UAS_WaitingToRequestOffer, 00220 00221 UAS_AcceptedWaitingAnswer, 00222 UAS_ReceivedOfferReliable, 00223 UAS_NoOfferReliable, 00224 UAS_FirstSentOfferReliable, 00225 UAS_FirstSentAnswerReliable, 00226 UAS_NegotiatedReliable, 00227 UAS_SentUpdate, 00228 UAS_SentUpdateAccepted, 00229 UAS_ReceivedUpdate, 00230 UAS_ReceivedUpdateWaitingAnswer, 00231 UAS_WaitingToTerminate, 00232 UAS_WaitingToHangup 00233 } State; 00234 00235 typedef enum 00236 { 00237 OnRedirect, // 3xx 00238 OnGeneralFailure, // 481 or 408 00239 OnInvite, // UAS 00240 OnInviteOffer,// UAS 00241 OnInviteReliableOffer, // UAS 00242 OnInviteReliable, // UAS 00243 OnCancel, // UAS 00244 OnBye, 00245 On200Bye, 00246 On1xx, // UAC 00247 On1xxEarly, // UAC 00248 On1xxOffer, // UAC 00249 On1xxAnswer, // UAC 00250 On2xx, 00251 On2xxOffer, 00252 On2xxAnswer, 00253 On422Invite, 00254 On487Invite, 00255 On491Invite, 00256 OnInviteFailure, 00257 OnAck, 00258 OnAckAnswer, 00259 On200Cancel, // UAC 00260 OnCancelFailure, // UAC 00261 OnUpdate, 00262 OnUpdateOffer, 00263 OnUpdateRejected, 00264 On422Update, 00265 On491Update, 00266 On200Update, 00267 OnPrack, // UAS 00268 On200Prack, // UAC 00269 Unknown 00270 } Event; 00271 00272 typedef enum 00273 { 00274 NitComplete, 00275 NitProceeding 00276 } NitState; 00277 00278 InviteSession(DialogUsageManager& dum, Dialog& dialog); 00279 virtual ~InviteSession(); 00280 virtual void dialogDestroyed(const SipMessage& msg); 00281 virtual void onReadyToSend(SipMessage& msg); 00282 virtual void flowTerminated(); 00283 00284 virtual void dispatch(const SipMessage& msg); 00285 virtual void dispatch(const DumTimeout& timer); 00286 00287 // Utility methods (one for each State) 00288 void dispatchConnected(const SipMessage& msg); 00289 void dispatchSentUpdate(const SipMessage& msg); 00290 void dispatchSentReinvite(const SipMessage& msg); 00291 void dispatchSentReinviteNoOffer(const SipMessage& msg); 00292 void dispatchSentReinviteAnswered(const SipMessage& msg); 00293 void dispatchGlare(const SipMessage& msg); 00294 void dispatchReinviteNoOfferGlare(const SipMessage& msg); 00295 void dispatchReceivedUpdateOrReinvite(const SipMessage& msg); 00296 void dispatchReceivedReinviteSentOffer(const SipMessage& msg); 00297 void dispatchAnswered(const SipMessage& msg); 00298 void dispatchWaitingToOffer(const SipMessage& msg); 00299 void dispatchWaitingToRequestOffer(const SipMessage& msg); 00300 void dispatchWaitingToTerminate(const SipMessage& msg); 00301 void dispatchWaitingToHangup(const SipMessage& msg); 00302 void dispatchTerminated(const SipMessage& msg); 00303 void dispatchBye(const SipMessage& msg); 00304 void dispatchInfo(const SipMessage& msg); 00305 void dispatchMessage(const SipMessage& msg); 00306 00307 void startRetransmit200Timer(); 00308 void start491Timer(); 00309 void startStaleReInviteTimer(); 00310 00311 void setSessionTimerHeaders(SipMessage& msg); 00312 void sessionRefresh(); 00313 void setSessionTimerPreferences(); 00314 void startSessionTimer(); 00315 void handleSessionTimerResponse(const SipMessage& msg); 00316 void handleSessionTimerRequest(SipMessage &response, const SipMessage& request); 00317 00318 static Data toData(State state); 00319 void transition(State target); 00320 00321 std::auto_ptr<Contents> getOfferAnswer(const SipMessage& msg); 00322 bool isReliable(const SipMessage& msg); 00323 static std::auto_ptr<Contents> makeOfferAnswer(const Contents& offerAnswer); 00324 static std::auto_ptr<Contents> makeOfferAnswer(const Contents& offerAnswer, const Contents* alternative); 00325 static void setOfferAnswer(SipMessage& msg, const Contents& offerAnswer, const Contents* alternative = 0); 00326 static void setOfferAnswer(SipMessage& msg, const Contents* offerAnswer); 00327 void provideProposedOffer(); 00328 00329 void storePeerCapabilities(const SipMessage& msg); 00330 bool updateMethodSupported() const; 00331 00332 void sendAck(const Contents *answer=0); 00333 SharedPtr<SipMessage> sendBye(); 00334 00335 const Data& getEndReasonString(InviteSession::EndReason reason); 00336 00337 DialogUsageManager::EncryptionLevel getEncryptionLevel(const SipMessage& msg); 00338 void setCurrentLocalOfferAnswer(const SipMessage& msg); 00339 void referNoSub(const SipMessage& msg); 00340 00341 Tokens mPeerSupportedMethods; 00342 Tokens mPeerSupportedOptionTags; 00343 Mimes mPeerSupportedMimeTypes; 00344 Tokens mPeerSupportedEncodings; 00345 Tokens mPeerSupportedLanguages; 00346 Tokens mPeerAllowedEvents; 00347 Data mPeerUserAgent; 00348 NameAddrs mPeerPAssertedIdentities; 00349 00350 Event toEvent(const SipMessage& msg, const Contents* offeranswer); 00351 00352 State mState; 00353 NitState mNitState; 00354 NitState mServerNitState; 00355 00356 std::auto_ptr<Contents> mCurrentLocalOfferAnswer; 00357 std::auto_ptr<Contents> mProposedLocalOfferAnswer; 00358 00359 std::auto_ptr<Contents> mCurrentRemoteOfferAnswer; 00360 std::auto_ptr<Contents> mProposedRemoteOfferAnswer; 00361 00362 SharedPtr<SipMessage> mLastLocalSessionModification; // last UPDATE or reINVITE sent 00363 SharedPtr<SipMessage> mLastRemoteSessionModification; // last UPDATE or reINVITE received 00364 SharedPtr<SipMessage> mInvite200; // 200 OK for reINVITE for retransmissions 00365 SharedPtr<SipMessage> mLastNitResponse; // 00366 //?dcm? -- ptr, delete when not needed? 00367 00368 SipMessage mLastReferNoSubRequest; 00369 00370 unsigned long mCurrentRetransmit200; 00371 unsigned int mStaleReInviteTimerSeq; 00372 00373 // Session Timer settings 00374 UInt32 mSessionInterval; 00375 UInt32 mMinSE; 00376 bool mSessionRefresher; 00377 unsigned int mSessionTimerSeq; 00378 bool mSessionRefreshReInvite; 00379 00380 class QueuedNIT 00381 { 00382 public: 00383 QueuedNIT(SharedPtr<SipMessage> NIT, bool referSub=false) 00384 : mNIT(NIT), mReferSubscription(referSub) {} 00385 SharedPtr<SipMessage>& getNIT() { return mNIT; } 00386 bool referSubscription() { return mReferSubscription; } 00387 private: 00388 SharedPtr<SipMessage> mNIT; 00389 bool mReferSubscription; 00390 }; 00391 std::queue<QueuedNIT*> mNITQueue; 00392 void nitComplete(); 00393 bool mReferSub; 00394 SharedPtr<SipMessage> mLastSentNITRequest; 00395 00396 DialogUsageManager::EncryptionLevel mCurrentEncryptionLevel; 00397 DialogUsageManager::EncryptionLevel mProposedEncryptionLevel; // UPDATE or RE-INVITE 00398 00399 EndReason mEndReason; 00400 00401 // Used when a user-specified EndReason is needed 00402 Data mUserEndReason; 00403 00404 // Used to respond to 2xx retransmissions. 00405 typedef HashMap<Data, SharedPtr<SipMessage> > AckMap; 00406 AckMap mAcks; 00407 00408 private: 00409 friend class Dialog; 00410 friend class DialogUsageManager; 00411 00412 // disabled 00413 InviteSession(const InviteSession&); 00414 InviteSession& operator=(const InviteSession&); 00415 00416 // Utility methods for handling particular methods 00417 void dispatchOthers(const SipMessage& msg); 00418 void dispatchUnhandledInvite(const SipMessage& msg); 00419 void dispatchPrack(const SipMessage& msg); 00420 void dispatchCancel(const SipMessage& msg); 00421 }; 00422 00423 } 00424 00425 #endif 00426 00427 /* ==================================================================== 00428 * The Vovida Software License, Version 1.0 00429 * 00430 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00431 * 00432 * Redistribution and use in source and binary forms, with or without 00433 * modification, are permitted provided that the following conditions 00434 * are met: 00435 * 00436 * 1. Redistributions of source code must retain the above copyright 00437 * notice, this list of conditions and the following disclaimer. 00438 * 00439 * 2. Redistributions in binary form must reproduce the above copyright 00440 * notice, this list of conditions and the following disclaimer in 00441 * the documentation and/or other materials provided with the 00442 * distribution. 00443 * 00444 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00445 * and "Vovida Open Communication Application Library (VOCAL)" must 00446 * not be used to endorse or promote products derived from this 00447 * software without prior written permission. For written 00448 * permission, please contact vocal@vovida.org. 00449 * 00450 * 4. Products derived from this software may not be called "VOCAL", nor 00451 * may "VOCAL" appear in their name, without prior written 00452 * permission of Vovida Networks, Inc. 00453 * 00454 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00455 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00456 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00457 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00458 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00459 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00460 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00461 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00462 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00463 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00464 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00465 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00466 * DAMAGE. 00467 * 00468 * ==================================================================== 00469 * 00470 * This software consists of voluntary contributions made by Vovida 00471 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00472 * Inc. For more information on Vovida Networks, Inc., please see 00473 * <http://www.vovida.org/>. 00474 * 00475 */ 00476 00477 00478 00479
1.7.5.1