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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9956 - (show annotations) (download)
Sat Jan 26 02:05:35 2013 UTC (6 years, 9 months ago) by fjoanis
File MIME type: text/plain
File size: 9053 byte(s)
- Ensured that all DUM usages/sessions DumCommandAdapter commands are using handles rather than references when saving the usage/session they apply to.
 - This fixes potential crashes in the case where a DumCommandAdapter would be enqueued onto the stack's queue while a usage terminating message is sitting in the queue.
 - The effect in that case would be that the saved reference to the usage would become invalid and this could cause a crash.
- Also fixed an issue with InviteSession::*NITCommand() where DumCommandAdapter commands would end up being recursively queued onto the stack.

1
2 #if defined(HAVE_CONFIG_H)
3 #include "config.h"
4 #endif
5
6 #include "resip/stack/SipMessage.hxx"
7 #include "resip/stack/MethodTypes.hxx"
8 #include "resip/stack/TransactionUser.hxx"
9 #include "resip/dum/PagerMessageCreator.hxx"
10 #include "resip/dum/DialogUsageManager.hxx"
11 #include "resip/dum/ClientPagerMessage.hxx"
12 #include "resip/dum/PagerMessageHandler.hxx"
13 #include "resip/dum/Dialog.hxx"
14 #include "resip/dum/UsageUseException.hxx"
15 #include "resip/dum/DumHelper.hxx"
16 #include "rutil/Logger.hxx"
17 #include "resip/stack/Helper.hxx"
18
19 #ifdef USE_SSL
20 #include "resip/stack/ssl/Security.hxx"
21 #endif
22
23 using namespace resip;
24
25 #if(0)
26 // for appcliation behaves like ICQ
27 app::onSendButtonClicked(im)
28 {
29 disableSendButton();
30 mPageManager.page(im);
31 }
32
33 app::onSuccess(...)
34 {
35 enableSendButton();
36 }
37
38 app::onFailure(...)
39 {
40 reportFailueToUI();
41 enableSendButton();
42 }
43
44 // for application behaves like MSN
45 app::onSendButtonClicked(im)
46 {
47 mPageManager.page(im);
48 }
49
50 app::onSuccess(...)
51 {
52 // most likely no-op
53 }
54
55 app::onFailure(...)
56 {
57 reportFailueToUI();
58 }
59
60 // for application behaves like MSN but wants to limit number of pages queued.
61 app::onSendButtonClicked(im)
62 {
63 if(mPageManager.msgQueued() > 5 - 1)
64 {
65 disableSendButton();
66 }
67 mPageManager.page(im);
68 }
69
70 app::onSuccess(...)
71 {
72 if(mPageManager.msgQueued() < 5)
73 {
74 enableSendButton();
75 }
76 }
77
78 app::onFailure(...)
79 {
80 reportFailueToUI();
81 if(mPageManager.msgQueued() < 5)
82 {
83 enableSendButton();
84 }
85 }
86 #endif
87
88 #define RESIPROCATE_SUBSYSTEM Subsystem::DUM
89
90 ClientPagerMessageHandle
91 ClientPagerMessage::getHandle()
92 {
93 return ClientPagerMessageHandle(mDum, getBaseHandle().getId());
94 }
95
96 ClientPagerMessage::ClientPagerMessage(DialogUsageManager& dum, DialogSet& dialogSet)
97 : NonDialogUsage(dum, dialogSet),
98 mRequest(dialogSet.getCreator()->getLastRequest()),
99 mEnded(false)
100 {
101 }
102
103 ClientPagerMessage::~ClientPagerMessage()
104 {
105 this->clearMsgQueued();
106 mDialogSet.mClientPagerMessage = 0;
107 }
108
109 SipMessage&
110 ClientPagerMessage::getMessageRequest()
111 {
112 return *mRequest;
113 }
114
115 void
116 ClientPagerMessage::page(std::auto_ptr<Contents> contents,
117 DialogUsageManager::EncryptionLevel level)
118 {
119 assert(contents.get() != 0);
120 bool do_page = mMsgQueue.empty();
121 Item item;
122 item.contents = contents.release();
123 item.encryptionLevel = level;
124 mMsgQueue.push_back(item);
125 if(do_page)
126 {
127 this->pageFirstMsgQueued();
128 }
129 }
130
131 class ClientPagerMessagePageCommand : public DumCommandAdapter
132 {
133 public:
134 ClientPagerMessagePageCommand(const ClientPagerMessageHandle& clientPagerMessageHandle,
135 std::auto_ptr<Contents> contents,
136 DialogUsageManager::EncryptionLevel level)
137 : mClientPagerMessageHandle(clientPagerMessageHandle),
138 mContents(contents),
139 mLevel(level)
140 {
141
142 }
143
144 virtual void executeCommand()
145 {
146 if(mClientPagerMessageHandle.isValid())
147 {
148 mClientPagerMessageHandle->page(mContents, mLevel);
149 }
150 }
151
152 virtual EncodeStream& encodeBrief(EncodeStream& strm) const
153 {
154 return strm << "ClientPagerMessagePageCommand";
155 }
156 private:
157 ClientPagerMessageHandle mClientPagerMessageHandle;
158 std::auto_ptr<Contents> mContents;
159 DialogUsageManager::EncryptionLevel mLevel;
160 };
161
162 void
163 ClientPagerMessage::pageCommand(std::auto_ptr<Contents> contents,
164 DialogUsageManager::EncryptionLevel level)
165 {
166 mDum.post(new ClientPagerMessagePageCommand(getHandle(), contents, level));
167 }
168
169 void
170 ClientPagerMessage::dispatch(const SipMessage& msg)
171 {
172 assert(msg.isResponse());
173
174 ClientPagerMessageHandler* handler = mDum.mClientPagerMessageHandler;
175 assert(handler);
176
177 int code = msg.header(h_StatusLine).statusCode();
178
179 DebugLog ( << "ClientPagerMessageReq::dispatch(msg)" << msg.brief() );
180 {
181 if (code < 200)
182 {
183 DebugLog ( << "ClientPagerMessageReq::dispatch - encountered provisional response" << msg.brief() );
184 }
185 else if (code < 300)
186 {
187 if(mMsgQueue.empty() == false)
188 {
189 delete mMsgQueue.front().contents;
190 mMsgQueue.pop_front();
191 if(mMsgQueue.empty() == false)
192 {
193 this->pageFirstMsgQueued();
194 }
195 }
196 handler->onSuccess(getHandle(), msg);
197 }
198 else
199 {
200 if(!mMsgQueue.empty())
201 {
202 SipMessage errResponse;
203 MsgQueue::iterator contents;
204 for(contents = mMsgQueue.begin(); contents != mMsgQueue.end(); ++contents)
205 {
206 Contents* p = contents->contents;
207 WarningLog ( << "Paging failed " << *p );
208 Helper::makeResponse(errResponse, *mRequest, code);
209 handler->onFailure(getHandle(), errResponse, std::auto_ptr<Contents>(p));
210 contents->contents = 0;
211 }
212 mMsgQueue.clear();
213 }
214 else
215 {
216 handler->onFailure(getHandle(), msg, std::auto_ptr<Contents>(mRequest->releaseContents()));
217 }
218 }
219 }
220 }
221
222 void
223 ClientPagerMessage::dispatch(const DumTimeout& timer)
224 {
225 }
226
227 void
228 ClientPagerMessage::end()
229 {
230 if(!mEnded)
231 {
232 mEnded = true;
233 mDum.destroy(this);
234 }
235 }
236
237 class ClientPagerMessageEndCommand : public DumCommandAdapter
238 {
239 public:
240 ClientPagerMessageEndCommand(ClientPagerMessage& clientPagerMessage)
241 : mClientPagerMessage(clientPagerMessage)
242 {
243 }
244
245 virtual void executeCommand()
246 {
247 mClientPagerMessage.end();
248 }
249
250 virtual EncodeStream& encodeBrief(EncodeStream& strm) const
251 {
252 return strm << "ClientPagerMessageEndCommand";
253 }
254 private:
255 ClientPagerMessage& mClientPagerMessage;
256 };
257
258 void
259 ClientPagerMessage::endCommand()
260 {
261 mDum.post(new ClientPagerMessageEndCommand(*this));
262 }
263
264 size_t
265 ClientPagerMessage::msgQueued () const
266 {
267 return mMsgQueue.size();
268 }
269
270 void
271 ClientPagerMessage::pageFirstMsgQueued ()
272 {
273 assert(mMsgQueue.empty() == false);
274 mRequest->header(h_CSeq).sequence()++;
275 mRequest->setContents(mMsgQueue.front().contents);
276 DumHelper::setOutgoingEncryptionLevel(*mRequest, mMsgQueue.front().encryptionLevel);
277 DebugLog(<< "ClientPagerMessage::pageFirstMsgQueued: " << *mRequest);
278 mDum.send(mRequest);
279 }
280
281 void
282 ClientPagerMessage::clearMsgQueued ()
283 {
284 MsgQueue::iterator contents;
285 for(contents = mMsgQueue.begin(); contents != mMsgQueue.end(); ++contents)
286 {
287 Contents* p = contents->contents;
288 delete p;
289 }
290 mMsgQueue.clear();
291 }
292
293 EncodeStream&
294 ClientPagerMessage::dump(EncodeStream& strm) const
295 {
296 strm << "ClientPagerMessage queued: " << mMsgQueue.size();
297 return strm;
298 }
299
300
301
302 /* ====================================================================
303 * The Vovida Software License, Version 1.0
304 *
305 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
306 *
307 * Redistribution and use in source and binary forms, with or without
308 * modification, are permitted provided that the following conditions
309 * are met:
310 *
311 * 1. Redistributions of source code must retain the above copyright
312 * notice, this list of conditions and the following disclaimer.
313 *
314 * 2. Redistributions in binary form must reproduce the above copyright
315 * notice, this list of conditions and the following disclaimer in
316 * the documentation and/or other materials provided with the
317
318 * distribution.
319 *
320 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
321 * and "Vovida Open Communication Application Library (VOCAL)" must
322 * not be used to endorse or promote products derived from this
323 * software without prior written permission. For written
324 * permission, please contact vocal@vovida.org.
325 *
326 * 4. Products derived from this software may not be called "VOCAL", nor
327 * may "VOCAL" appear in their name, without prior written
328 * permission of Vovida Networks, Inc.
329 *
330 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
331 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
332 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
333 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
334 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
335 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
336 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
337 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
338 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
339 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
340 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
341 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
342 * DAMAGE.
343 *
344 * ====================================================================
345 *
346 * This software consists of voluntary contributions made by Vovida
347 * Networks, Inc. and many individuals on behalf of Vovida Networks,
348 * Inc. For more information on Vovida Networks, Inc., please see
349 * <http://www.vovida.org/>.
350 *
351 */

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