1 |
derek |
3138 |
#include "resiprocate/SdpContents.hxx" |
2 |
jason |
2725 |
#include "resiprocate/SipMessage.hxx" |
3 |
|
|
#include "resiprocate/dum/Dialog.hxx" |
4 |
|
|
#include "resiprocate/dum/DialogUsageManager.hxx" |
5 |
|
|
#include "resiprocate/dum/InviteSession.hxx" |
6 |
jason |
2846 |
#include "resiprocate/dum/InviteSessionHandler.hxx" |
7 |
derek |
3138 |
#include "resiprocate/dum/Profile.hxx" |
8 |
derek |
2961 |
#include "resiprocate/dum/UsageUseException.hxx" |
9 |
jason |
2856 |
#include "resiprocate/os/Logger.hxx" |
10 |
jason |
2555 |
|
11 |
derek |
3094 |
#if defined(WIN32) && defined(_DEBUG) &&defined(LEAK_CHECK)// Used for tracking down memory leaks in Visual Studio |
12 |
derek |
3092 |
#define _CRTDBG_MAP_ALLOC |
13 |
|
|
#include <stdlib.h> |
14 |
|
|
#include <crtdbg.h> |
15 |
|
|
#define new new( _NORMAL_BLOCK, __FILE__, __LINE__) |
16 |
|
|
#endif // defined(WIN32) && defined(_DEBUG) |
17 |
sgodin |
3091 |
|
18 |
derek |
3092 |
|
19 |
jason |
2856 |
#define RESIPROCATE_SUBSYSTEM Subsystem::DUM |
20 |
jason |
2846 |
|
21 |
davidb |
2603 |
using namespace resip; |
22 |
|
|
|
23 |
derek |
2990 |
unsigned long |
24 |
|
|
InviteSession::T1 = 500; |
25 |
|
|
|
26 |
|
|
unsigned long |
27 |
|
|
InviteSession::T2 = 8 * T1; |
28 |
|
|
|
29 |
|
|
unsigned long |
30 |
|
|
InviteSession::TimerH = 64 * T1; |
31 |
|
|
|
32 |
derek |
2976 |
InviteSession::InviteSession(DialogUsageManager& dum, Dialog& dialog, State initialState) |
33 |
derek |
3089 |
: DialogUsage(dum, dialog), |
34 |
derek |
2976 |
mState(initialState), |
35 |
jason |
2846 |
mOfferState(Nothing), |
36 |
jason |
2725 |
mCurrentLocalSdp(0), |
37 |
|
|
mCurrentRemoteSdp(0), |
38 |
|
|
mProposedLocalSdp(0), |
39 |
derek |
2965 |
mProposedRemoteSdp(0), |
40 |
derek |
2990 |
mNextOfferOrAnswerSdp(0), |
41 |
derek |
3138 |
mCurrentRetransmit200(0), |
42 |
|
|
mDestroyer(this) |
43 |
jason |
2555 |
{ |
44 |
derek |
3006 |
InfoLog ( << "^^^ InviteSession::InviteSession " << this); |
45 |
jason |
2846 |
assert(mDum.mInviteSessionHandler); |
46 |
jason |
2555 |
} |
47 |
|
|
|
48 |
derek |
2858 |
InviteSession::~InviteSession() |
49 |
|
|
{ |
50 |
derek |
3006 |
InfoLog ( << "^^^ InviteSession::~InviteSession " << this); |
51 |
derek |
2965 |
delete mCurrentLocalSdp; |
52 |
|
|
delete mCurrentRemoteSdp; |
53 |
|
|
delete mProposedLocalSdp; |
54 |
|
|
delete mProposedRemoteSdp; |
55 |
|
|
delete mNextOfferOrAnswerSdp; |
56 |
derek |
2858 |
mDialog.mInviteSession = 0; |
57 |
|
|
} |
58 |
jason |
2846 |
|
59 |
derek |
3064 |
SipMessage& |
60 |
|
|
InviteSession::modifySession() |
61 |
|
|
{ |
62 |
|
|
if (mNextOfferOrAnswerSdp == 0 || mState != Connected) |
63 |
|
|
{ |
64 |
|
|
throw new UsageUseException("Must be in the connected state and have propsed an offer to call modifySession", |
65 |
|
|
__FILE__, __LINE__); |
66 |
|
|
} |
67 |
|
|
mState = ReInviting; |
68 |
|
|
mDialog.makeRequest(mLastRequest, INVITE); |
69 |
|
|
return mLastRequest; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
|
73 |
|
|
SipMessage& |
74 |
|
|
InviteSession::acceptOffer(int statusCode) |
75 |
|
|
{ |
76 |
|
|
if (mNextOfferOrAnswerSdp == 0 || mState != ReInviting) |
77 |
|
|
{ |
78 |
|
|
throw new UsageUseException("Must be in the ReInviting state and have propsed an answer to call answerModifySession", |
79 |
|
|
__FILE__, __LINE__); |
80 |
|
|
} |
81 |
|
|
mState = AcceptingReInvite; |
82 |
derek |
3089 |
mDialog.makeResponse(mFinalResponse, mLastRequest, statusCode); |
83 |
|
|
return mFinalResponse; |
84 |
derek |
3064 |
} |
85 |
|
|
|
86 |
jason |
2866 |
void |
87 |
|
|
InviteSession::setOffer(const SdpContents* sdp) |
88 |
|
|
{ |
89 |
derek |
2965 |
if (mProposedRemoteSdp) |
90 |
|
|
{ |
91 |
|
|
throw UsageUseException("Cannot set an offer with an oustanding remote offer", __FILE__, __LINE__); |
92 |
|
|
} |
93 |
sgodin |
3091 |
assert(mNextOfferOrAnswerSdp == 0); |
94 |
derek |
2965 |
mNextOfferOrAnswerSdp = static_cast<SdpContents*>(sdp->clone()); |
95 |
jason |
2866 |
} |
96 |
|
|
|
97 |
|
|
void |
98 |
|
|
InviteSession::setAnswer(const SdpContents* sdp) |
99 |
|
|
{ |
100 |
derek |
2965 |
if (mProposedLocalSdp ) |
101 |
|
|
{ |
102 |
|
|
throw UsageUseException("Cannot set an answer with an oustanding offer", __FILE__, __LINE__); |
103 |
|
|
} |
104 |
sgodin |
3091 |
assert(mNextOfferOrAnswerSdp == 0); |
105 |
derek |
2965 |
mNextOfferOrAnswerSdp = static_cast<SdpContents*>(sdp->clone()); |
106 |
jason |
2866 |
} |
107 |
|
|
|
108 |
jason |
2555 |
const SdpContents* |
109 |
|
|
InviteSession::getLocalSdp() |
110 |
|
|
{ |
111 |
jason |
2725 |
return mCurrentLocalSdp; |
112 |
jason |
2555 |
} |
113 |
|
|
|
114 |
|
|
const SdpContents* |
115 |
|
|
InviteSession::getRemoteSdp() |
116 |
|
|
{ |
117 |
jason |
2725 |
return mCurrentRemoteSdp; |
118 |
jason |
2555 |
} |
119 |
davidb |
2575 |
|
120 |
jason |
2941 |
InviteSessionHandle |
121 |
|
|
InviteSession::getSessionHandle() |
122 |
|
|
{ |
123 |
|
|
return InviteSessionHandle(mDum, getBaseHandle().getId()); |
124 |
|
|
} |
125 |
|
|
|
126 |
derek |
2990 |
|
127 |
jason |
2856 |
void |
128 |
derek |
2990 |
InviteSession::dispatch(const DumTimeout& timeout) |
129 |
|
|
{ |
130 |
derek |
3138 |
Destroyer::Guard guard(mDestroyer); |
131 |
derek |
3064 |
if (timeout.type() == DumTimeout::Retransmit200 && (mState == Accepting || mState == AcceptingReInvite )) |
132 |
derek |
2990 |
{ |
133 |
derek |
3001 |
mDum.send(mFinalResponse); |
134 |
derek |
3079 |
mDum.addTimerMs(DumTimeout::Retransmit200, resipMin(T2, mCurrentRetransmit200*2), getBaseHandle(), 0); |
135 |
derek |
2990 |
} |
136 |
|
|
else if (timeout.type() == DumTimeout::WaitForAck && mState != Connected) |
137 |
|
|
{ |
138 |
|
|
mDialog.makeResponse(mLastResponse, mLastRequest, 408); |
139 |
|
|
mDum.mInviteSessionHandler->onTerminated(getSessionHandle(), mLastResponse); |
140 |
derek |
3138 |
guard.destroy(); |
141 |
derek |
2990 |
} |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
void |
145 |
jason |
2856 |
InviteSession::dispatch(const SipMessage& msg) |
146 |
|
|
{ |
147 |
derek |
3138 |
Destroyer::Guard guard(mDestroyer); |
148 |
jason |
2856 |
std::pair<OfferAnswerType, const SdpContents*> offans; |
149 |
|
|
offans = InviteSession::getOfferOrAnswer(msg); |
150 |
|
|
|
151 |
derek |
2961 |
switch(mState) |
152 |
jason |
2856 |
{ |
153 |
derek |
2961 |
case Terminated: |
154 |
derek |
2978 |
//!dcm! -- 481 behaviour here, should pretty much die on anything |
155 |
derek |
2997 |
//eventually 200 to BYE could be handled further out |
156 |
|
|
if (msg.isResponse()) |
157 |
derek |
2961 |
{ |
158 |
derek |
2997 |
int code = msg.header(h_StatusLine).statusCode(); |
159 |
|
|
if ((code == 200 && msg.header(h_CSeq).method() == BYE) || code > 399) |
160 |
|
|
{ |
161 |
|
|
mDum.mInviteSessionHandler->onTerminated(getSessionHandle(), msg); |
162 |
derek |
3138 |
guard.destroy(); |
163 |
derek |
3006 |
return; |
164 |
derek |
2997 |
} |
165 |
derek |
2961 |
} |
166 |
derek |
3138 |
else |
167 |
|
|
{ |
168 |
|
|
//make a function to do this & the occurences of this in DialogUsageManager |
169 |
|
|
SipMessage failure; |
170 |
|
|
mDum.makeResponse(failure, msg, 481); |
171 |
|
|
failure.header(h_AcceptLanguages) = mDum.mProfile->getSupportedLanguages(); |
172 |
|
|
mDum.sendResponse(failure); |
173 |
|
|
} |
174 |
derek |
2961 |
break; |
175 |
|
|
case Connected: |
176 |
|
|
if (msg.isRequest()) |
177 |
|
|
{ |
178 |
|
|
switch(msg.header(h_RequestLine).method()) |
179 |
|
|
{ |
180 |
sgodin |
3091 |
// reINVITE |
181 |
derek |
2961 |
case INVITE: |
182 |
derek |
3089 |
mState = ReInviting; |
183 |
derek |
2961 |
mDialog.update(msg); |
184 |
sgodin |
3071 |
mLastRequest = msg; // !slg! |
185 |
derek |
2961 |
mDum.mInviteSessionHandler->onDialogModified(getSessionHandle(), msg); |
186 |
|
|
if (offans.first != None) |
187 |
|
|
{ |
188 |
derek |
2976 |
incomingSdp(msg, offans.second); |
189 |
derek |
2961 |
} |
190 |
|
|
break; |
191 |
jason |
2856 |
|
192 |
derek |
2961 |
case BYE: |
193 |
derek |
2978 |
mState = Terminated; |
194 |
|
|
mDum.mInviteSessionHandler->onTerminated(getSessionHandle(), msg); |
195 |
|
|
mDialog.makeResponse(mLastResponse, msg, 200); |
196 |
|
|
send(mLastResponse); |
197 |
derek |
2961 |
break; |
198 |
jason |
2856 |
|
199 |
derek |
2961 |
case UPDATE: |
200 |
|
|
assert(0); |
201 |
|
|
break; |
202 |
jason |
2856 |
|
203 |
derek |
2961 |
case INFO: |
204 |
|
|
mDum.mInviteSessionHandler->onInfo(getSessionHandle(), msg); |
205 |
|
|
break; |
206 |
jason |
2856 |
|
207 |
derek |
2961 |
case REFER: |
208 |
derek |
3101 |
//handled in Dialog |
209 |
|
|
assert(0); |
210 |
derek |
2961 |
break; |
211 |
jason |
2856 |
|
212 |
derek |
2961 |
default: |
213 |
|
|
InfoLog (<< "Ignoring request in an INVITE dialog: " << msg.brief()); |
214 |
|
|
break; |
215 |
|
|
} |
216 |
derek |
3006 |
} |
217 |
|
|
else |
218 |
|
|
{ |
219 |
|
|
//!dcm! -- need to change this logic for when we don't have an ACK yet |
220 |
|
|
if ( msg.header(h_StatusLine).statusCode() == 200) |
221 |
|
|
{ |
222 |
|
|
//retransmist ack |
223 |
|
|
mDum.send(mAck); |
224 |
|
|
} |
225 |
|
|
} |
226 |
derek |
3064 |
break; |
227 |
|
|
case ReInviting: |
228 |
derek |
3089 |
if (msg.isResponse() && msg.header(h_CSeq).method() == INVITE |
229 |
|
|
&& msg.header(h_StatusLine).statusCode() == 200) |
230 |
derek |
3064 |
{ |
231 |
derek |
3089 |
mState = Connected; |
232 |
derek |
3064 |
send(ackConnection()); |
233 |
derek |
3089 |
if (offans.first != None) |
234 |
|
|
{ |
235 |
|
|
incomingSdp(msg, offans.second); |
236 |
|
|
} |
237 |
derek |
3064 |
} |
238 |
|
|
else |
239 |
|
|
{ |
240 |
|
|
ErrLog ( << "Spurious message sent to UAS " << msg ); |
241 |
|
|
return; |
242 |
|
|
} |
243 |
|
|
break; |
244 |
derek |
2976 |
case Accepting: |
245 |
|
|
if (msg.isRequest() && msg.header(h_RequestLine).method() == ACK) |
246 |
|
|
{ |
247 |
|
|
mState = Connected; |
248 |
|
|
mDum.mInviteSessionHandler->onConnected(getSessionHandle(), msg); |
249 |
|
|
if (offans.first != None) |
250 |
|
|
{ |
251 |
|
|
InviteSession::incomingSdp(msg, offans.second); |
252 |
|
|
} |
253 |
|
|
} |
254 |
|
|
else |
255 |
|
|
{ |
256 |
derek |
2997 |
ErrLog ( << "Spurious message sent to UAS " << msg ); |
257 |
|
|
return; |
258 |
derek |
2976 |
} |
259 |
|
|
break; |
260 |
derek |
3064 |
case AcceptingReInvite: |
261 |
|
|
if (msg.isRequest() && msg.header(h_RequestLine).method() == ACK) |
262 |
|
|
{ |
263 |
|
|
mState = Connected; |
264 |
|
|
//this shouldn't happen, but it may be allowed(DUM API doesn't |
265 |
|
|
//support this for re-invite) |
266 |
|
|
if (offans.first != None) |
267 |
|
|
{ |
268 |
|
|
InviteSession::incomingSdp(msg, offans.second); |
269 |
|
|
} |
270 |
|
|
} |
271 |
|
|
else |
272 |
|
|
{ |
273 |
|
|
ErrLog ( << "Spurious message sent to UAS " << msg ); |
274 |
|
|
return; |
275 |
|
|
} |
276 |
|
|
break; |
277 |
|
|
|
278 |
|
|
|
279 |
derek |
2961 |
default: |
280 |
derek |
3024 |
DebugLog ( << "Throwing away strange message: " << msg ); |
281 |
|
|
//throw message away |
282 |
|
|
// assert(0); //all other cases should be handled in base classes |
283 |
|
|
|
284 |
jason |
2856 |
} |
285 |
|
|
} |
286 |
|
|
|
287 |
derek |
2955 |
SipMessage& |
288 |
derek |
3039 |
InviteSession::makeRefer(const NameAddr& referTo) |
289 |
derek |
2955 |
{ |
290 |
derek |
3058 |
mDialog.makeRequest(mLastRequest, REFER); |
291 |
|
|
mLastRequest.header(h_ReferTo) = referTo; |
292 |
|
|
return mLastRequest; |
293 |
derek |
2955 |
} |
294 |
jason |
2856 |
|
295 |
derek |
3112 |
SipMessage& |
296 |
|
|
InviteSession::makeRefer(const NameAddr& referTo, InviteSessionHandle sessionToReplace) |
297 |
|
|
{ |
298 |
|
|
if (!sessionToReplace.isValid()) |
299 |
|
|
{ |
300 |
|
|
throw new UsageUseException("Attempted to make a refer w/ and invalid replacement target", __FILE__, __LINE__); |
301 |
|
|
} |
302 |
|
|
|
303 |
|
|
mDialog.makeRequest(mLastRequest, REFER); |
304 |
|
|
mLastRequest.header(h_ReferTo) = referTo; |
305 |
|
|
CallId replaces; |
306 |
|
|
DialogId id = sessionToReplace->mDialog.getId(); |
307 |
|
|
replaces.value() = id.getCallId(); |
308 |
|
|
replaces.param(p_toTag) = id.getRemoteTag(); |
309 |
|
|
replaces.param(p_fromTag) = id.getLocalTag(); |
310 |
|
|
|
311 |
|
|
mLastRequest.header(h_ReferTo).uri().embedded().header(h_Replaces) = replaces; |
312 |
|
|
return mLastRequest; |
313 |
|
|
} |
314 |
|
|
|
315 |
jason |
2809 |
SipMessage& |
316 |
jason |
2621 |
InviteSession::end() |
317 |
|
|
{ |
318 |
derek |
3006 |
InfoLog ( << "InviteSession::end, state: " << mState); |
319 |
derek |
2961 |
switch (mState) |
320 |
|
|
{ |
321 |
|
|
case Terminated: |
322 |
derek |
2965 |
throw UsageUseException("Cannot end a session that has already been cancelled.", __FILE__, __LINE__); |
323 |
derek |
2961 |
break; |
324 |
|
|
case Connected: |
325 |
derek |
3006 |
case Accepting: |
326 |
|
|
InfoLog ( << "InviteSession::end, connected or Accepting" ); |
327 |
derek |
2961 |
mDialog.makeRequest(mLastRequest, BYE); |
328 |
derek |
2985 |
//new transaction |
329 |
|
|
assert(mLastRequest.header(h_Vias).size() == 1); |
330 |
derek |
3079 |
// mLastRequest.header(h_Vias).front().param(p_branch).reset(); |
331 |
derek |
2961 |
mState = Terminated; |
332 |
|
|
return mLastRequest; |
333 |
|
|
break; |
334 |
|
|
default: |
335 |
|
|
assert(0); // out of states |
336 |
|
|
} |
337 |
derek |
2981 |
throw UsageUseException("Programmer error", __FILE__, __LINE__); //make VC++ happy |
338 |
jason |
2621 |
} |
339 |
|
|
|
340 |
jason |
2809 |
// If sdp==0, it means the last offer failed |
341 |
derek |
2965 |
// !dcm! -- eventually handle confused UA's that send offers/answers at |
342 |
|
|
// inappropriate times, probably with a different callback |
343 |
jason |
2846 |
void |
344 |
|
|
InviteSession::incomingSdp(const SipMessage& msg, const SdpContents* sdp) |
345 |
jason |
2809 |
{ |
346 |
|
|
switch (mOfferState) |
347 |
|
|
{ |
348 |
jason |
2846 |
case Nothing: |
349 |
jason |
2809 |
assert(mCurrentLocalSdp == 0); |
350 |
|
|
assert(mCurrentRemoteSdp == 0); |
351 |
sgodin |
3091 |
assert(mProposedLocalSdp == 0); |
352 |
|
|
assert(mProposedRemoteSdp == 0); |
353 |
jason |
2846 |
mProposedRemoteSdp = static_cast<SdpContents*>(sdp->clone()); |
354 |
jason |
2809 |
mOfferState = Offerred; |
355 |
jason |
2846 |
mDum.mInviteSessionHandler->onOffer(getSessionHandle(), msg, sdp); |
356 |
jason |
2809 |
break; |
357 |
|
|
|
358 |
|
|
case Offerred: |
359 |
sgodin |
3091 |
assert(mCurrentLocalSdp == 0); |
360 |
|
|
assert(mCurrentRemoteSdp == 0); |
361 |
jason |
2809 |
mCurrentLocalSdp = mProposedLocalSdp; |
362 |
jason |
2846 |
mCurrentRemoteSdp = static_cast<SdpContents*>(sdp->clone()); |
363 |
sgodin |
3091 |
delete mProposedRemoteSdp; |
364 |
jason |
2809 |
mProposedLocalSdp = 0; |
365 |
|
|
mProposedRemoteSdp = 0; |
366 |
|
|
mOfferState = Answered; |
367 |
jason |
2846 |
mDum.mInviteSessionHandler->onAnswer(getSessionHandle(), msg, sdp); |
368 |
jason |
2809 |
break; |
369 |
|
|
|
370 |
|
|
case Answered: |
371 |
|
|
assert(mProposedLocalSdp == 0); |
372 |
|
|
assert(mProposedRemoteSdp == 0); |
373 |
jason |
2846 |
mProposedRemoteSdp = static_cast<SdpContents*>(sdp->clone()); |
374 |
jason |
2809 |
mOfferState = CounterOfferred; |
375 |
jason |
2846 |
mDum.mInviteSessionHandler->onOffer(getSessionHandle(), msg, sdp); |
376 |
jason |
2809 |
break; |
377 |
derek |
2965 |
|
378 |
jason |
2809 |
case CounterOfferred: |
379 |
|
|
assert(mCurrentLocalSdp); |
380 |
|
|
assert(mCurrentRemoteSdp); |
381 |
jason |
2846 |
mOfferState = Answered; |
382 |
sgodin |
3071 |
if (sdp) // !slg! There currenlty doesn't seem to be anyone calling this with sdp == 0 |
383 |
jason |
2809 |
{ |
384 |
derek |
2965 |
delete mCurrentLocalSdp; |
385 |
|
|
delete mCurrentRemoteSdp; |
386 |
jason |
2809 |
mCurrentLocalSdp = mProposedLocalSdp; |
387 |
jason |
2846 |
mCurrentRemoteSdp = static_cast<SdpContents*>(sdp->clone()); |
388 |
sgodin |
3091 |
delete mProposedRemoteSdp; |
389 |
derek |
2965 |
mProposedLocalSdp = 0; |
390 |
|
|
mProposedRemoteSdp = 0; |
391 |
|
|
mOfferState = Answered; |
392 |
jason |
2846 |
mDum.mInviteSessionHandler->onAnswer(getSessionHandle(), msg, sdp); |
393 |
jason |
2809 |
} |
394 |
|
|
else |
395 |
|
|
{ |
396 |
sgodin |
3091 |
delete mProposedLocalSdp; |
397 |
|
|
delete mProposedRemoteSdp; |
398 |
jason |
2809 |
mProposedLocalSdp = 0; |
399 |
|
|
mProposedRemoteSdp = 0; |
400 |
jason |
2846 |
// !jf! is this right? |
401 |
|
|
mDum.mInviteSessionHandler->onOfferRejected(getSessionHandle(), msg); |
402 |
jason |
2809 |
} |
403 |
|
|
break; |
404 |
|
|
} |
405 |
|
|
} |
406 |
|
|
|
407 |
derek |
2965 |
void |
408 |
|
|
InviteSession::send(SipMessage& msg) |
409 |
|
|
{ |
410 |
derek |
3138 |
Destroyer::Guard guard(mDestroyer); |
411 |
derek |
2965 |
if (msg.isRequest()) |
412 |
|
|
{ |
413 |
|
|
//unless the message is an ACK(in which case it is mAck) |
414 |
|
|
//strip out the SDP after sending |
415 |
derek |
3089 |
switch(msg.header(h_RequestLine).getMethod()) |
416 |
|
|
{ |
417 |
|
|
case INVITE: |
418 |
|
|
case UPDATE: |
419 |
|
|
if (mNextOfferOrAnswerSdp) |
420 |
|
|
{ |
421 |
sgodin |
3091 |
msg.setContents(mNextOfferOrAnswerSdp); |
422 |
derek |
3089 |
sendSdp(mNextOfferOrAnswerSdp); |
423 |
|
|
mNextOfferOrAnswerSdp = 0; |
424 |
|
|
} |
425 |
|
|
break; |
426 |
|
|
default: |
427 |
|
|
break; |
428 |
|
|
} |
429 |
|
|
|
430 |
derek |
2965 |
if (msg.header(h_RequestLine).getMethod() == ACK) |
431 |
|
|
{ |
432 |
|
|
mDum.send(msg); |
433 |
|
|
} |
434 |
|
|
else |
435 |
|
|
{ |
436 |
|
|
mDum.send(msg); |
437 |
|
|
msg.releaseContents(); |
438 |
|
|
} |
439 |
|
|
} |
440 |
|
|
else |
441 |
|
|
{ |
442 |
|
|
int code = msg.header(h_StatusLine).statusCode(); |
443 |
|
|
//!dcm! -- probably kill this object earlier, handle 200 to bye in |
444 |
|
|
//DialogUsageManager...very soon |
445 |
|
|
if (msg.header(h_CSeq).method() == BYE && code == 200) //!dcm! -- not 2xx? |
446 |
|
|
|
447 |
|
|
{ |
448 |
|
|
mState = Terminated; |
449 |
|
|
mDum.send(msg); |
450 |
sgodin |
3140 |
//mDum.mInviteSessionHandler->onTerminated(getSessionHandle(), msg); // This is actually called when recieving the BYE message so that the BYE message can be passed to onTerminated |
451 |
derek |
3138 |
guard.destroy(); |
452 |
derek |
2965 |
} |
453 |
derek |
2978 |
else if (code >= 200 && code < 300 && msg.header(h_CSeq).method() == INVITE) |
454 |
derek |
2965 |
{ |
455 |
derek |
2978 |
assert(&msg == &mFinalResponse); |
456 |
derek |
2990 |
mCurrentRetransmit200 = T1; |
457 |
derek |
3079 |
mDum.addTimerMs(DumTimeout::Retransmit200, mCurrentRetransmit200, getBaseHandle(), 0); |
458 |
|
|
mDum.addTimerMs(DumTimeout::WaitForAck, TimerH, getBaseHandle(), 0); |
459 |
derek |
2990 |
|
460 |
|
|
//!dcm! -- this should be mFinalResponse...maybe assign here in |
461 |
derek |
2965 |
//case the user wants to be very strange |
462 |
|
|
if (mNextOfferOrAnswerSdp) |
463 |
|
|
{ |
464 |
sgodin |
3091 |
msg.setContents(mNextOfferOrAnswerSdp); |
465 |
derek |
2965 |
sendSdp(mNextOfferOrAnswerSdp); |
466 |
derek |
2997 |
mNextOfferOrAnswerSdp = 0; |
467 |
derek |
2978 |
} |
468 |
|
|
mDum.send(msg); |
469 |
|
|
} |
470 |
|
|
else |
471 |
|
|
{ |
472 |
|
|
mDum.send(msg); |
473 |
|
|
msg.releaseContents(); |
474 |
|
|
} |
475 |
derek |
2965 |
} |
476 |
|
|
} |
477 |
|
|
|
478 |
jason |
2621 |
void |
479 |
derek |
2965 |
InviteSession::sendSdp(SdpContents* sdp) |
480 |
jason |
2809 |
{ |
481 |
|
|
switch (mOfferState) |
482 |
|
|
{ |
483 |
jason |
2846 |
case Nothing: |
484 |
jason |
2809 |
assert(mCurrentLocalSdp == 0); |
485 |
|
|
assert(mCurrentRemoteSdp == 0); |
486 |
derek |
2965 |
mProposedLocalSdp = sdp; |
487 |
jason |
2809 |
mOfferState = Offerred; |
488 |
|
|
break; |
489 |
|
|
|
490 |
|
|
case Offerred: |
491 |
sgodin |
3091 |
assert(mCurrentLocalSdp == 0); |
492 |
|
|
assert(mCurrentRemoteSdp == 0); |
493 |
derek |
2965 |
mCurrentLocalSdp = sdp; |
494 |
jason |
2809 |
mCurrentRemoteSdp = mProposedRemoteSdp; |
495 |
sgodin |
3091 |
delete mProposedLocalSdp; |
496 |
jason |
2809 |
mProposedLocalSdp = 0; |
497 |
|
|
mProposedRemoteSdp = 0; |
498 |
|
|
mOfferState = Answered; |
499 |
|
|
break; |
500 |
|
|
|
501 |
|
|
case Answered: |
502 |
|
|
assert(mProposedLocalSdp == 0); |
503 |
|
|
assert(mProposedRemoteSdp == 0); |
504 |
derek |
2965 |
mProposedLocalSdp = sdp; |
505 |
jason |
2809 |
mOfferState = CounterOfferred; |
506 |
|
|
break; |
507 |
|
|
|
508 |
|
|
case CounterOfferred: |
509 |
|
|
assert(mCurrentLocalSdp); |
510 |
|
|
assert(mCurrentRemoteSdp); |
511 |
sgodin |
3071 |
if (sdp) // !slg! There currenlty doesn't seem to be anyone calling this with sdp == 0 |
512 |
jason |
2809 |
{ |
513 |
derek |
3064 |
delete mCurrentLocalSdp; |
514 |
|
|
delete mCurrentRemoteSdp; |
515 |
sgodin |
3091 |
mCurrentLocalSdp = sdp; |
516 |
jason |
2809 |
mCurrentRemoteSdp = mProposedRemoteSdp; |
517 |
sgodin |
3091 |
delete mProposedLocalSdp; |
518 |
|
|
mProposedLocalSdp = 0; |
519 |
|
|
mProposedRemoteSdp = 0; |
520 |
jason |
2809 |
} |
521 |
sgodin |
3091 |
else |
522 |
|
|
{ |
523 |
|
|
delete mProposedLocalSdp; |
524 |
|
|
delete mProposedRemoteSdp; |
525 |
|
|
mProposedLocalSdp = 0; |
526 |
|
|
mProposedRemoteSdp = 0; |
527 |
|
|
} |
528 |
jason |
2809 |
mOfferState = Answered; |
529 |
|
|
break; |
530 |
|
|
} |
531 |
|
|
} |
532 |
|
|
|
533 |
jason |
2846 |
std::pair<InviteSession::OfferAnswerType, const SdpContents*> |
534 |
|
|
InviteSession::getOfferOrAnswer(const SipMessage& msg) const |
535 |
|
|
{ |
536 |
|
|
std::pair<InviteSession::OfferAnswerType, const SdpContents*> ret; |
537 |
|
|
ret.first = None; |
538 |
|
|
|
539 |
|
|
const SdpContents* contents = dynamic_cast<const SdpContents*>(msg.getContents()); |
540 |
|
|
if (contents) |
541 |
|
|
{ |
542 |
|
|
static Token c100rel(Symbols::C100rel); |
543 |
derek |
2976 |
if (msg.isRequest() || msg.header(h_StatusLine).responseCode() == 200 || |
544 |
jason |
2846 |
msg.exists(h_Supporteds) && msg.header(h_Supporteds).find(c100rel)) |
545 |
|
|
{ |
546 |
|
|
switch (mOfferState) |
547 |
|
|
{ |
548 |
|
|
case None: |
549 |
|
|
ret.first = Offer; |
550 |
|
|
ret.second = contents; |
551 |
|
|
break; |
552 |
|
|
|
553 |
|
|
case Offerred: |
554 |
|
|
ret.first = Answer; |
555 |
|
|
ret.second = contents; |
556 |
|
|
break; |
557 |
|
|
|
558 |
|
|
case Answered: |
559 |
|
|
ret.first = Offer; |
560 |
|
|
ret.second = contents; |
561 |
|
|
break; |
562 |
|
|
|
563 |
|
|
case CounterOfferred: |
564 |
|
|
ret.first = Answer; |
565 |
|
|
ret.second = contents; |
566 |
|
|
break; |
567 |
|
|
} |
568 |
|
|
} |
569 |
|
|
} |
570 |
|
|
return ret; |
571 |
|
|
} |
572 |
|
|
|
573 |
jason |
2809 |
void |
574 |
jason |
2621 |
InviteSession::copyAuthorizations(SipMessage& request) |
575 |
|
|
{ |
576 |
jason |
2725 |
#if 0 |
577 |
jason |
2621 |
if (mLastRequest.exists(h_ProxyAuthorizations)) |
578 |
|
|
{ |
579 |
|
|
// should make the next auth (change nextNonce) |
580 |
|
|
request.header(h_ProxyAuthorizations) = mLastRequest.header(h_ProxyAuthorizations); |
581 |
|
|
} |
582 |
|
|
if (mLastRequest.exists(h_ProxyAuthorizations)) |
583 |
|
|
{ |
584 |
|
|
// should make the next auth (change nextNonce) |
585 |
|
|
request.header(h_ProxyAuthorizations) = mLastRequest.header(h_ProxyAuthorizations); |
586 |
|
|
} |
587 |
jason |
2725 |
#endif |
588 |
jason |
2621 |
} |
589 |
|
|
|
590 |
derek |
2955 |
SipMessage& |
591 |
derek |
2965 |
InviteSession::rejectOffer(int statusCode) |
592 |
|
|
{ |
593 |
derek |
3101 |
if (statusCode < 400) |
594 |
|
|
{ |
595 |
|
|
throw new UsageUseException("Must reject with a 4xx", __FILE__, __LINE__); |
596 |
|
|
} |
597 |
derek |
3069 |
//sdp state change here--go to initial state? |
598 |
derek |
2976 |
mDialog.makeResponse(mLastResponse, mLastRequest, statusCode); |
599 |
|
|
return mLastResponse; |
600 |
derek |
2965 |
} |
601 |
|
|
|
602 |
|
|
SipMessage& |
603 |
derek |
2955 |
InviteSession::targetRefresh(const NameAddr& localUri) |
604 |
|
|
{ |
605 |
|
|
assert(0); |
606 |
derek |
2981 |
return mLastRequest; |
607 |
derek |
2955 |
} |
608 |
davidb |
2576 |
|
609 |
derek |
2981 |
SipMessage& |
610 |
|
|
InviteSession::ackConnection() |
611 |
|
|
{ |
612 |
|
|
//if not a reinvite, and a pending offer exists, throw |
613 |
|
|
makeAck(); |
614 |
derek |
2985 |
//new transaction |
615 |
|
|
assert(mAck.header(h_Vias).size() == 1); |
616 |
derek |
3079 |
// mAck.header(h_Vias).front().param(p_branch).reset(); |
617 |
derek |
2981 |
return mAck; |
618 |
|
|
} |
619 |
|
|
|
620 |
derek |
2955 |
void |
621 |
derek |
2965 |
InviteSession::makeAck() |
622 |
derek |
2849 |
{ |
623 |
derek |
2965 |
mAck = mLastRequest; |
624 |
derek |
2992 |
|
625 |
|
|
InfoLog ( << "InviteSession::makeAck:before: " << mAck ); |
626 |
|
|
|
627 |
derek |
2965 |
mDialog.makeRequest(mAck, ACK); |
628 |
|
|
if (mNextOfferOrAnswerSdp) |
629 |
|
|
{ |
630 |
sgodin |
3091 |
mAck.setContents(mNextOfferOrAnswerSdp); |
631 |
derek |
2965 |
sendSdp(mNextOfferOrAnswerSdp); |
632 |
derek |
2997 |
mNextOfferOrAnswerSdp = 0; |
633 |
derek |
2992 |
} |
634 |
|
|
|
635 |
|
|
InfoLog ( << "InviteSession::makeAck:after: " << mAck ); |
636 |
derek |
2849 |
} |
637 |
|
|
|
638 |
davidb |
2575 |
/* ==================================================================== |
639 |
|
|
* The Vovida Software License, Version 1.0 |
640 |
|
|
* |
641 |
|
|
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. |
642 |
|
|
* |
643 |
|
|
* Redistribution and use in source and binary forms, with or without |
644 |
|
|
* modification, are permitted provided that the following conditions |
645 |
|
|
* are met: |
646 |
|
|
* |
647 |
|
|
* 1. Redistributions of source code must retain the above copyright |
648 |
|
|
* notice, this list of conditions and the following disclaimer. |
649 |
|
|
* |
650 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
651 |
|
|
* notice, this list of conditions and the following disclaimer in |
652 |
|
|
* the documentation and/or other materials provided with the |
653 |
|
|
|
654 |
|
|
* distribution. |
655 |
|
|
* |
656 |
|
|
* 3. The names "VOCAL", "Vovida Open Communication Application Library", |
657 |
|
|
* and "Vovida Open Communication Application Library (VOCAL)" must |
658 |
|
|
* not be used to endorse or promote products derived from this |
659 |
|
|
* software without prior written permission. For written |
660 |
|
|
* permission, please contact vocal@vovida.org. |
661 |
|
|
* |
662 |
|
|
* 4. Products derived from this software may not be called "VOCAL", nor |
663 |
|
|
* may "VOCAL" appear in their name, without prior written |
664 |
|
|
* permission of Vovida Networks, Inc. |
665 |
|
|
* |
666 |
|
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
667 |
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
668 |
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND |
669 |
|
|
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA |
670 |
|
|
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES |
671 |
|
|
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, |
672 |
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
673 |
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
674 |
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
675 |
|
|
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
676 |
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
677 |
|
|
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
678 |
|
|
* DAMAGE. |
679 |
|
|
* |
680 |
|
|
* ==================================================================== |
681 |
|
|
* |
682 |
|
|
* This software consists of voluntary contributions made by Vovida |
683 |
|
|
* Networks, Inc. and many individuals on behalf of Vovida Networks, |
684 |
|
|
* Inc. For more information on Vovida Networks, Inc., please see |
685 |
|
|
* <http://www.vovida.org/>. |
686 |
|
|
* |
687 |
|
|
*/ |