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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2941 - (show annotations) (download)
Mon Jun 7 00:44:01 2004 UTC (15 years, 6 months ago) by jason
Original Path: main/sip/resiprocate/dum/InviteSession.cxx
File size: 9617 byte(s)
refactored Handle code
streamlined header includes

1 #include "resiprocate/SipMessage.hxx"
2 #include "resiprocate/SdpContents.hxx"
3 #include "resiprocate/dum/Dialog.hxx"
4 #include "resiprocate/dum/DialogUsageManager.hxx"
5 #include "resiprocate/dum/InviteSession.hxx"
6 #include "resiprocate/dum/InviteSessionHandler.hxx"
7 #include "resiprocate/os/Logger.hxx"
8
9 #define RESIPROCATE_SUBSYSTEM Subsystem::DUM
10
11 using namespace resip;
12
13 InviteSession::InviteSession(DialogUsageManager& dum, Dialog& dialog)
14 : BaseUsage(dum, dialog),
15 mOfferState(Nothing),
16 mCurrentLocalSdp(0),
17 mCurrentRemoteSdp(0),
18 mProposedLocalSdp(0),
19 mProposedRemoteSdp(0)
20 {
21 assert(mDum.mInviteSessionHandler);
22 }
23
24 InviteSession::~InviteSession()
25 {
26 mDialog.mInviteSession = 0;
27 }
28
29 void
30 InviteSession::setOffer(const SdpContents* sdp)
31 {
32 //mProposedLocalSdp = sdp;
33 }
34
35 void
36 InviteSession::setAnswer(const SdpContents* sdp)
37 {
38 //mProposedLocalSdp = 0;
39 //mCurrentLocalSdp = sdp;
40 }
41
42 const SdpContents*
43 InviteSession::getLocalSdp()
44 {
45 return mCurrentLocalSdp;
46 }
47
48 const SdpContents*
49 InviteSession::getRemoteSdp()
50 {
51 return mCurrentRemoteSdp;
52 }
53
54 InviteSessionHandle
55 InviteSession::getSessionHandle()
56 {
57 return InviteSessionHandle(mDum, getBaseHandle().getId());
58 }
59
60 void
61 InviteSession::dispatch(const SipMessage& msg)
62 {
63 std::pair<OfferAnswerType, const SdpContents*> offans;
64 offans = InviteSession::getOfferOrAnswer(msg);
65
66 // reINVITE
67 if (msg.isRequest())
68 {
69 switch(msg.header(h_RequestLine).method())
70 {
71 case INVITE:
72 mDialog.update(msg);
73 mDum.mInviteSessionHandler->onDialogModified(getSessionHandle(), msg);
74
75 if (offans.first != None)
76 {
77 InviteSession::incomingSdp(msg, offans.second);
78 }
79 break;
80
81 case BYE:
82 end();
83 break;
84
85 case UPDATE:
86 assert(0);
87 break;
88
89 case INFO:
90 mDum.mInviteSessionHandler->onInfo(getSessionHandle(), msg);
91 break;
92
93 case REFER:
94 assert(0); // !jf!
95 mDum.mInviteSessionHandler->onRefer(getSessionHandle(), msg);
96 break;
97
98 default:
99 InfoLog (<< "Ignoring request in an INVITE dialog: " << msg.brief());
100 break;
101 }
102 }
103 }
104
105
106 SipMessage&
107 InviteSession::end()
108 {
109 //assert(mState == Connected);
110
111 #if 0
112 // no way for the application to modify the BYE yet
113 SipMessage bye;
114 mDialog.makeBye(bye);
115 copyAuthorizations(bye);
116 //mDum.send(bye);
117 #endif
118 return mLastRequest;
119 }
120
121 // If sdp==0, it means the last offer failed
122 void
123 InviteSession::incomingSdp(const SipMessage& msg, const SdpContents* sdp)
124 {
125 switch (mOfferState)
126 {
127 case Nothing:
128 assert(mCurrentLocalSdp == 0);
129 assert(mCurrentRemoteSdp == 0);
130 mProposedRemoteSdp = static_cast<SdpContents*>(sdp->clone());
131 mOfferState = Offerred;
132 mDum.mInviteSessionHandler->onOffer(getSessionHandle(), msg, sdp);
133 break;
134
135 case Offerred:
136 mCurrentLocalSdp = mProposedLocalSdp;
137 mCurrentRemoteSdp = static_cast<SdpContents*>(sdp->clone());
138 mProposedLocalSdp = 0;
139 mProposedRemoteSdp = 0;
140 mOfferState = Answered;
141 mDum.mInviteSessionHandler->onAnswer(getSessionHandle(), msg, sdp);
142 break;
143
144 case Answered:
145 assert(mProposedLocalSdp == 0);
146 assert(mProposedRemoteSdp == 0);
147 mProposedRemoteSdp = static_cast<SdpContents*>(sdp->clone());
148 mOfferState = CounterOfferred;
149 mDum.mInviteSessionHandler->onOffer(getSessionHandle(), msg, sdp);
150 break;
151
152
153 case CounterOfferred:
154 assert(mCurrentLocalSdp);
155 assert(mCurrentRemoteSdp);
156 mOfferState = Answered;
157 if (sdp)
158 {
159 mCurrentLocalSdp = mProposedLocalSdp;
160 mCurrentRemoteSdp = static_cast<SdpContents*>(sdp->clone());
161 mDum.mInviteSessionHandler->onAnswer(getSessionHandle(), msg, sdp);
162 }
163 else
164 {
165 mProposedLocalSdp = 0;
166 mProposedRemoteSdp = 0;
167 // !jf! is this right?
168 mDum.mInviteSessionHandler->onOfferRejected(getSessionHandle(), msg);
169 }
170 break;
171 }
172 }
173
174 void
175 InviteSession::sendSdp(const SdpContents* sdp)
176 {
177 switch (mOfferState)
178 {
179 case Nothing:
180 assert(mCurrentLocalSdp == 0);
181 assert(mCurrentRemoteSdp == 0);
182 mProposedLocalSdp = static_cast<SdpContents*>(sdp->clone());
183 mOfferState = Offerred;
184 break;
185
186 case Offerred:
187 mCurrentLocalSdp = static_cast<SdpContents*>(sdp->clone());
188 mCurrentRemoteSdp = mProposedRemoteSdp;
189 mProposedLocalSdp = 0;
190 mProposedRemoteSdp = 0;
191 mOfferState = Answered;
192 break;
193
194 case Answered:
195 assert(mProposedLocalSdp == 0);
196 assert(mProposedRemoteSdp == 0);
197 mProposedLocalSdp = static_cast<SdpContents*>(sdp->clone());
198 mOfferState = CounterOfferred;
199 break;
200
201
202 case CounterOfferred:
203 assert(mCurrentLocalSdp);
204 assert(mCurrentRemoteSdp);
205 if (sdp)
206 {
207 mCurrentLocalSdp = static_cast<SdpContents*>(sdp->clone());
208 mCurrentRemoteSdp = mProposedRemoteSdp;
209 }
210 else
211 {
212 mProposedLocalSdp = 0;
213 mProposedRemoteSdp = 0;
214 }
215 mOfferState = Answered;
216 break;
217 }
218 }
219
220 std::pair<InviteSession::OfferAnswerType, const SdpContents*>
221 InviteSession::getOfferOrAnswer(const SipMessage& msg) const
222 {
223 std::pair<InviteSession::OfferAnswerType, const SdpContents*> ret;
224 ret.first = None;
225
226 const SdpContents* contents = dynamic_cast<const SdpContents*>(msg.getContents());
227 if (contents)
228 {
229 static Token c100rel(Symbols::C100rel);
230 if (msg.isRequest() ||
231 msg.exists(h_Supporteds) && msg.header(h_Supporteds).find(c100rel))
232 {
233 switch (mOfferState)
234 {
235 case None:
236 ret.first = Offer;
237 ret.second = contents;
238 break;
239
240 case Offerred:
241 ret.first = Answer;
242 ret.second = contents;
243 break;
244
245 case Answered:
246 ret.first = Offer;
247 ret.second = contents;
248 break;
249
250 case CounterOfferred:
251 ret.first = Answer;
252 ret.second = contents;
253 break;
254 }
255 }
256 }
257 return ret;
258 }
259
260 void
261 InviteSession::copyAuthorizations(SipMessage& request)
262 {
263 #if 0
264 if (mLastRequest.exists(h_ProxyAuthorizations))
265 {
266 // should make the next auth (change nextNonce)
267 request.header(h_ProxyAuthorizations) = mLastRequest.header(h_ProxyAuthorizations);
268 }
269 if (mLastRequest.exists(h_ProxyAuthorizations))
270 {
271 // should make the next auth (change nextNonce)
272 request.header(h_ProxyAuthorizations) = mLastRequest.header(h_ProxyAuthorizations);
273 }
274 #endif
275 }
276
277
278 void InviteSession::makeAck(const SipMessage& response2xx)
279 {
280 }
281
282 /* ====================================================================
283 * The Vovida Software License, Version 1.0
284 *
285 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
286 *
287 * Redistribution and use in source and binary forms, with or without
288 * modification, are permitted provided that the following conditions
289 * are met:
290 *
291 * 1. Redistributions of source code must retain the above copyright
292 * notice, this list of conditions and the following disclaimer.
293 *
294 * 2. Redistributions in binary form must reproduce the above copyright
295 * notice, this list of conditions and the following disclaimer in
296 * the documentation and/or other materials provided with the
297
298 * distribution.
299 *
300 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
301 * and "Vovida Open Communication Application Library (VOCAL)" must
302 * not be used to endorse or promote products derived from this
303 * software without prior written permission. For written
304 * permission, please contact vocal@vovida.org.
305 *
306 * 4. Products derived from this software may not be called "VOCAL", nor
307 * may "VOCAL" appear in their name, without prior written
308 * permission of Vovida Networks, Inc.
309 *
310 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
311 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
312 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
313 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
314 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
315 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
316 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
317 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
318 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
319 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
320 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
321 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
322 * DAMAGE.
323 *
324 * ====================================================================
325 *
326 * This software consists of voluntary contributions made by Vovida
327 * Networks, Inc. and many individuals on behalf of Vovida Networks,
328 * Inc. For more information on Vovida Networks, Inc., please see
329 * <http://www.vovida.org/>.
330 *
331 */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27