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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27