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

Contents of /main/resip/dum/InviteSession.hxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8217 - (show annotations) (download)
Wed Aug 27 14:25:17 2008 UTC (11 years, 5 months ago) by sgodin
File MIME type: text/plain
File size: 17811 byte(s)
-add an accessor to InviteSession to get the remote contact header - remoteTarget
1 #if !defined(RESIP_INVITESESSION_HXX)
2 #define RESIP_INVITESESSION_HXX
3
4 #include "resip/stack/SipMessage.hxx"
5 #include "resip/stack/SdpContents.hxx"
6 #include "resip/dum/DialogUsage.hxx"
7 #include "resip/dum/DialogUsageManager.hxx"
8
9 #include <map>
10 #include <queue>
11
12 namespace resip
13 {
14
15 class SdpContents;
16
17 /** Base class for class ClientInviteSession and class ServerInviteSession.
18 Implements common attributes and behavior (i.e.t post connected) of the two
19 classes.
20 */
21 class InviteSession : public DialogUsage
22 {
23 public:
24 /** Called to set the offer that will be used in the next message that
25 sends an offer. If possible, this will synchronously send the
26 appropriate request or response. In some cases, the UAS might have to
27 call accept in order to cause the message to be sent. */
28 virtual void provideOffer(const SdpContents& offer);
29 virtual void provideOffer(const SdpContents& offer, DialogUsageManager::EncryptionLevel level, const SdpContents* alternative);
30
31 /** Similar to provideOffer - called to set the answer to be signalled to
32 the peer. May result in message being sent synchronously depending on
33 the state. */
34 virtual void provideAnswer(const SdpContents& answer);
35
36 /** Called to request that the far end provide an offer. This will cause a
37 reinvite with no sdp to be sent. */
38 virtual void requestOffer();
39
40 typedef enum
41 {
42 None, // means no Offer or Answer (may have SDP)
43 Offer,
44 Answer
45 } OfferAnswerType;
46
47 // WARNING: Do not change this list without appropriately adjusting the
48 // EndReasons array in InviteSession.cxx
49 enum EndReason
50 {
51 NotSpecified=0,
52 UserHangup,
53 AppRejectedSdp,
54 IllegalNegotiation,
55 AckNotReceived,
56 SessionExpired,
57 StaleReInvite,
58 ENDREASON_MAX
59 };
60
61 /** Makes the specific dialog end. Will send a BYE (not a CANCEL) */
62 virtual void end(EndReason reason);
63 virtual void end(); // reason == NotSpecified ; same as above - required for BaseUsage pure virtual
64
65 /** Rejects an offer at the SIP level. Can also be used to
66 send a 488 to a reINVITE or UPDATE */
67 virtual void reject(int statusCode, WarningCategory *warning = 0);
68
69 /** will send a reINVITE (current sdp) or UPDATE with new Contact header */
70 virtual void targetRefresh(const NameAddr& localUri);
71
72 // Following methods are for sending requests within a dialog
73
74 /** sends a refer request */
75 virtual void refer(const NameAddr& referTo, bool referSub = true);
76 virtual void refer(const NameAddr& referTo, std::auto_ptr<resip::Contents> contents, bool referSub = true);
77
78 /** sends a refer request with a replaces header */
79 virtual void refer(const NameAddr& referTo, InviteSessionHandle sessionToReplace, bool referSub = true);
80
81 /** sends an info request */
82 virtual void info(const Contents& contents);
83
84 /** sends a message request
85
86 @warning From RFC3428 - The authors recognize that there may be valid reasons to
87 send MESSAGE requests in the context of a dialog. For
88 example, one participant in a voice session may wish to
89 send an IM to another participant, and associate that IM
90 with the session. But implementations SHOULD NOT create
91 dialogs for the primary purpose of associating MESSAGE
92 requests with one another.
93 */
94 virtual void message(const Contents& contents);
95
96 /** accepts an INFO or MESSAGE request with a 2xx and an optional contents */
97 virtual void acceptNIT(int statusCode = 200, const Contents * contents = 0);
98
99 /** rejects an INFO or MESSAGE request with an error status code */
100 virtual void rejectNIT(int statusCode = 488);
101
102 /**
103 * Provide asynchronous method access by using command
104 */
105 virtual void provideOfferCommand(const SdpContents& offer);
106 virtual void provideOfferCommand(const SdpContents& offer, DialogUsageManager::EncryptionLevel level, const SdpContents* alternative);
107 virtual void provideAnswerCommand(const SdpContents& answer);
108 /** Asynchronously makes the specific dialog end. Will send a BYE (not a CANCEL) */
109 virtual void endCommand(EndReason reason = NotSpecified);
110 /** Asynchronously rejects an offer at the SIP level. Can also be used to
111 send a 488 to a reINVITE or UPDATE */
112 virtual void rejectCommand(int statusCode, WarningCategory *warning = 0);
113 virtual void referCommand(const NameAddr& referTo, bool referSub = true);
114 virtual void referCommand(const NameAddr& referTo, InviteSessionHandle sessionToReplace, bool referSub = true);
115 virtual void infoCommand(const Contents& contents);
116 virtual void messageCommand(const Contents& contents);
117 /** Asynchronously accepts an INFO or MESSAGE request with a 2xx and an optional contents */
118 virtual void acceptNITCommand(int statusCode = 200, const Contents * contents = 0);
119 /** Asynchronously rejects an INFO or MESSAGE request with an error status code */
120 virtual void rejectNITCommand(int statusCode = 488);
121
122 virtual void acceptReferNoSub(int statusCode = 200);
123 virtual void rejectReferNoSub(int responseCode);
124
125 // Convenience methods for accessing attributes of a dialog.
126 const NameAddr& myAddr() const;
127 const NameAddr& peerAddr() const;
128 const NameAddr& remoteTarget() const;
129 bool hasLocalSdp() const;
130 const SdpContents& getLocalSdp() const;
131 bool hasRemoteSdp() const;
132 const SdpContents& getRemoteSdp() const;
133 bool hasProposedRemoteSdp() const;
134 const SdpContents& getProposedRemoteSdp() const;
135 const Data& getDialogId() const;
136
137 bool isConnected() const;
138 bool isTerminated() const;
139 bool isEarly() const; // UAC Early states
140 bool isAccepted() const; // UAS States after accept is called
141
142 Tokens& getPeerSupportedMethods() { return mPeerSupportedMethods; }
143 Tokens& getPeerSupportedOptionTags() { return mPeerSupportedOptionTags; }
144 Mimes& getPeerSupportedMimeTypes() { return mPeerSupportedMimeTypes; }
145 Tokens& getPeerSupportedEncodings() { return mPeerSupportedEncodings; }
146 Tokens& getPeerSupportedLanguages() { return mPeerSupportedLanguages; }
147 Tokens& getPeerAllowedEvents() { return mPeerAllowedEvents; }
148 Data& getPeerUserAgent() { return mPeerUserAgent; }
149 NameAddrs& getPeerPAssertedIdentities() { return mPeerPAssertedIdentities; }
150
151 virtual EncodeStream& dump(EncodeStream& strm) const;
152 InviteSessionHandle getSessionHandle();
153
154 protected:
155
156 typedef enum
157 {
158 Undefined, // Not used
159 Connected,
160 SentUpdate, // Sent an UPDATE
161 SentUpdateGlare, // got a 491
162 SentReinvite, // Sent a reINVITE
163 SentReinviteGlare, // Got a 491
164 SentReinviteNoOffer, // Sent a reINVITE with no offer (requestOffer)
165 SentReinviteAnswered, // Sent a reINVITE no offer and received a 200-offer
166 SentReinviteNoOfferGlare, // Got a 491
167 ReceivedUpdate, // Received an UPDATE
168 ReceivedReinvite, // Received a reINVITE
169 ReceivedReinviteNoOffer, // Received a reINVITE with no offer
170 ReceivedReinviteSentOffer, // Sent a 200 to a reINVITE with no offer
171 Answered,
172 WaitingToOffer,
173 WaitingToRequestOffer,
174 WaitingToTerminate, // Waiting for 2xx response before sending BYE
175 WaitingToHangup, // Waiting for ACK before sending BYE
176 Terminated, // Ended. waiting to delete
177
178 UAC_Start,
179 UAC_Early,
180 UAC_EarlyWithOffer,
181 UAC_EarlyWithAnswer,
182 UAC_Answered,
183 UAC_SentUpdateEarly,
184 UAC_SentUpdateEarlyGlare,
185 UAC_ReceivedUpdateEarly,
186 UAC_SentAnswer,
187 UAC_QueuedUpdate,
188 UAC_Cancelled,
189
190 UAS_Start,
191 UAS_Offer,
192 UAS_OfferProvidedAnswer,
193 UAS_EarlyOffer,
194 UAS_EarlyProvidedAnswer,
195
196 UAS_NoOffer,
197 UAS_ProvidedOffer,
198 UAS_EarlyNoOffer,
199 UAS_EarlyProvidedOffer,
200 UAS_Accepted,
201 UAS_WaitingToOffer,
202 UAS_WaitingToRequestOffer,
203
204 UAS_AcceptedWaitingAnswer,
205 UAS_ReceivedOfferReliable,
206 UAS_NoOfferReliable,
207 UAS_FirstSentOfferReliable,
208 UAS_FirstSentAnswerReliable,
209 UAS_NegotiatedReliable,
210 UAS_SentUpdate,
211 UAS_SentUpdateAccepted,
212 UAS_ReceivedUpdate,
213 UAS_ReceivedUpdateWaitingAnswer,
214 UAS_WaitingToTerminate,
215 UAS_WaitingToHangup
216 } State;
217
218 typedef enum
219 {
220 OnRedirect, // 3xx
221 OnGeneralFailure, // 481 or 408
222 OnInvite, // UAS
223 OnInviteOffer,// UAS
224 OnInviteReliableOffer, // UAS
225 OnInviteReliable, // UAS
226 OnCancel, // UAS
227 OnBye,
228 On200Bye,
229 On1xx, // UAC
230 On1xxEarly, // UAC
231 On1xxOffer, // UAC
232 On1xxAnswer, // UAC
233 On2xx,
234 On2xxOffer,
235 On2xxAnswer,
236 On422Invite,
237 On487Invite,
238 On491Invite,
239 OnInviteFailure,
240 OnAck,
241 OnAckAnswer,
242 On200Cancel, // UAC
243 OnCancelFailure, // UAC
244 OnUpdate,
245 OnUpdateOffer,
246 OnUpdateRejected,
247 On422Update,
248 On491Update,
249 On200Update,
250 OnPrack, // UAS
251 On200Prack, // UAC
252 Unknown
253 } Event;
254
255 typedef enum
256 {
257 NitComplete,
258 NitProceeding
259 } NitState;
260
261 InviteSession(DialogUsageManager& dum, Dialog& dialog);
262 virtual ~InviteSession();
263 virtual void dialogDestroyed(const SipMessage& msg);
264 virtual void onReadyToSend(SipMessage& msg);
265
266 virtual void dispatch(const SipMessage& msg);
267 virtual void dispatch(const DumTimeout& timer);
268
269 // Utility methods (one for each State)
270 void dispatchConnected(const SipMessage& msg);
271 void dispatchSentUpdate(const SipMessage& msg);
272 void dispatchSentReinvite(const SipMessage& msg);
273 void dispatchSentReinviteNoOffer(const SipMessage& msg);
274 void dispatchSentReinviteAnswered(const SipMessage& msg);
275 void dispatchGlare(const SipMessage& msg);
276 void dispatchReinviteNoOfferGlare(const SipMessage& msg);
277 void dispatchReceivedUpdateOrReinvite(const SipMessage& msg);
278 void dispatchReceivedReinviteSentOffer(const SipMessage& msg);
279 void dispatchAnswered(const SipMessage& msg);
280 void dispatchWaitingToOffer(const SipMessage& msg);
281 void dispatchWaitingToRequestOffer(const SipMessage& msg);
282 void dispatchWaitingToTerminate(const SipMessage& msg);
283 void dispatchWaitingToHangup(const SipMessage& msg);
284 void dispatchTerminated(const SipMessage& msg);
285 void dispatchBye(const SipMessage& msg);
286 void dispatchInfo(const SipMessage& msg);
287
288 void startRetransmit200Timer();
289 void start491Timer();
290 void startStaleReInviteTimer();
291
292 void setSessionTimerHeaders(SipMessage& msg);
293 void sessionRefresh();
294 void setSessionTimerPreferences();
295 void startSessionTimer();
296 void handleSessionTimerResponse(const SipMessage& msg);
297 void handleSessionTimerRequest(SipMessage &response, const SipMessage& request);
298
299 static Data toData(State state);
300 void transition(State target);
301
302 std::auto_ptr<SdpContents> getSdp(const SipMessage& msg);
303 bool isReliable(const SipMessage& msg);
304 static std::auto_ptr<SdpContents> makeSdp(const SdpContents& sdp);
305 static std::auto_ptr<Contents> makeSdp(const SdpContents& sdp, const SdpContents* alternative);
306 static void setSdp(SipMessage& msg, const SdpContents& sdp, const SdpContents* alternative = 0);
307 static void setSdp(SipMessage& msg, const Contents* sdp);
308 void provideProposedOffer();
309
310 void storePeerCapabilities(const SipMessage& msg);
311 bool updateMethodSupported() const;
312
313 void sendAck(const SdpContents *sdp=0);
314 void sendBye();
315
316 DialogUsageManager::EncryptionLevel getEncryptionLevel(const SipMessage& msg);
317 void setCurrentLocalSdp(const SipMessage& msg);
318 void referNoSub(const SipMessage& msg);
319
320 Tokens mPeerSupportedMethods;
321 Tokens mPeerSupportedOptionTags;
322 Mimes mPeerSupportedMimeTypes;
323 Tokens mPeerSupportedEncodings;
324 Tokens mPeerSupportedLanguages;
325 Tokens mPeerAllowedEvents;
326 Data mPeerUserAgent;
327 NameAddrs mPeerPAssertedIdentities;
328
329 Event toEvent(const SipMessage& msg, const SdpContents* sdp);
330
331 State mState;
332 NitState mNitState;
333
334 std::auto_ptr<SdpContents> mCurrentLocalSdp;
335 std::auto_ptr<Contents> mProposedLocalSdp;
336
337 std::auto_ptr<SdpContents> mCurrentRemoteSdp;
338 std::auto_ptr<SdpContents> mProposedRemoteSdp;
339
340 SharedPtr<SipMessage> mLastLocalSessionModification; // last UPDATE or reINVITE sent
341 SharedPtr<SipMessage> mLastRemoteSessionModification; // last UPDATE or reINVITE received
342 SharedPtr<SipMessage> mInvite200; // 200 OK for reINVITE for retransmissions
343 SharedPtr<SipMessage> mLastNitResponse; //
344 //?dcm? -- ptr, delete when not needed?
345
346 SipMessage mLastReferNoSubRequest;
347
348 unsigned long mCurrentRetransmit200;
349 unsigned int mStaleReInviteTimerSeq;
350
351 // Session Timer settings
352 UInt32 mSessionInterval;
353 UInt32 mMinSE;
354 bool mSessionRefresher;
355 unsigned int mSessionTimerSeq;
356 bool mSessionRefreshReInvite;
357
358 class QueuedNIT
359 {
360 public:
361 QueuedNIT(SharedPtr<SipMessage> NIT, bool referSub=false)
362 : mNIT(NIT), mReferSubscription(referSub) {}
363 SharedPtr<SipMessage>& getNIT() { return mNIT; }
364 bool referSubscription() { return mReferSubscription; }
365 private:
366 SharedPtr<SipMessage> mNIT;
367 bool mReferSubscription;
368 };
369 std::queue<QueuedNIT*> mNITQueue;
370 void nitComplete();
371 bool mReferSub;
372
373 DialogUsageManager::EncryptionLevel mCurrentEncryptionLevel;
374 DialogUsageManager::EncryptionLevel mProposedEncryptionLevel; // UPDATE or RE-INVITE
375
376 EndReason mEndReason;
377
378 // Used to respond to 2xx retransmissions.
379 typedef HashMap<Data, SharedPtr<SipMessage> > AckMap;
380 AckMap mAcks;
381
382 private:
383 friend class Dialog;
384 friend class DialogUsageManager;
385
386 // disabled
387 InviteSession(const InviteSession&);
388 InviteSession& operator=(const InviteSession&);
389
390 // Utility methods for handling particular methods
391 void dispatchOthers(const SipMessage& msg);
392 void dispatchUnhandledInvite(const SipMessage& msg);
393 void dispatchPrack(const SipMessage& msg);
394 void dispatchCancel(const SipMessage& msg);
395 void dispatchMessage(const SipMessage& msg);
396 };
397
398 }
399
400 #endif
401
402 /* ====================================================================
403 * The Vovida Software License, Version 1.0
404 *
405 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
406 *
407 * Redistribution and use in source and binary forms, with or without
408 * modification, are permitted provided that the following conditions
409 * are met:
410 *
411 * 1. Redistributions of source code must retain the above copyright
412 * notice, this list of conditions and the following disclaimer.
413 *
414 * 2. Redistributions in binary form must reproduce the above copyright
415 * notice, this list of conditions and the following disclaimer in
416 * the documentation and/or other materials provided with the
417 * distribution.
418 *
419 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
420 * and "Vovida Open Communication Application Library (VOCAL)" must
421 * not be used to endorse or promote products derived from this
422 * software without prior written permission. For written
423 * permission, please contact vocal@vovida.org.
424 *
425 * 4. Products derived from this software may not be called "VOCAL", nor
426 * may "VOCAL" appear in their name, without prior written
427 * permission of Vovida Networks, Inc.
428 *
429 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
430 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
431 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
432 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
433 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
434 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
435 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
436 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
437 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
438 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
439 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
440 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
441 * DAMAGE.
442 *
443 * ====================================================================
444 *
445 * This software consists of voluntary contributions made by Vovida
446 * Networks, Inc. and many individuals on behalf of Vovida Networks,
447 * Inc. For more information on Vovida Networks, Inc., please see
448 * <http://www.vovida.org/>.
449 *
450 */
451
452
453
454

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27