reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ClientPagerMessage.cxx
Go to the documentation of this file.
1
2#if defined(HAVE_CONFIG_H)
3 #include "config.h"
4#endif
5
13#include "resip/dum/Dialog.hxx"
16#include "rutil/Logger.hxx"
18
19#ifdef USE_SSL
21#endif
22
23#include <utility>
24
25using namespace resip;
26
27#if(0)
28// for application behaves like ICQ
29app::onSendButtonClicked(im)
30{
31 disableSendButton();
32 mPageManager.page(im);
33}
34
35app::onSuccess(...)
36{
37 enableSendButton();
38}
39
40app::onFailure(...)
41{
42 reportFailueToUI();
43 enableSendButton();
44}
45
46// for application behaves like MSN
47app::onSendButtonClicked(im)
48{
49 mPageManager.page(im);
50}
51
52app::onSuccess(...)
53{
54 // most likely no-op
55}
56
57app::onFailure(...)
58{
59 reportFailueToUI();
60}
61
62// for application behaves like MSN but wants to limit number of pages queued.
63app::onSendButtonClicked(im)
64{
65 if(mPageManager.msgQueued() > 5 - 1)
66 {
67 disableSendButton();
68 }
69 mPageManager.page(im);
70}
71
72app::onSuccess(...)
73{
74 if(mPageManager.msgQueued() < 5)
75 {
76 enableSendButton();
77 }
78}
79
80app::onFailure(...)
81{
82 reportFailueToUI();
83 if(mPageManager.msgQueued() < 5)
84 {
85 enableSendButton();
86 }
87}
88#endif
89
90#define RESIPROCATE_SUBSYSTEM Subsystem::DUM
91
97
99 : NonDialogUsage(dum, dialogSet),
100 mRequest(dialogSet.getCreator()->getLastRequest()),
101 mEnded(false)
102{
103}
104
106{
107 this->clearMsgQueued();
108 mDialogSet.mClientPagerMessage = 0;
109}
110
113{
114 return *mRequest;
115}
116
117void
118ClientPagerMessage::page(std::unique_ptr<Contents> contents, DialogUsageManager::EncryptionLevel level)
119{
120 resip_assert(contents != nullptr);
121 bool do_page = mMsgQueue.empty();
122 Item item;
123 item.contents = contents.release();
124 item.encryptionLevel = level;
125 mMsgQueue.push_back(item);
126 if(do_page)
127 {
128 pageFirstMsgQueued();
129 }
130}
131
133{
134public:
136 std::unique_ptr<Contents> contents,
138 : mClientPagerMessageHandle(clientPagerMessageHandle),
139 mContents(std::move(contents)),
140 mLevel(level)
141 {
142 }
143
144 void executeCommand() override
145 {
146 if(mClientPagerMessageHandle.isValid())
147 {
148 mClientPagerMessageHandle->page(std::move(mContents), mLevel);
149 }
150 }
151
152 EncodeStream& encodeBrief(EncodeStream& strm) const override
153 {
154 return strm << "ClientPagerMessagePageCommand";
155 }
156
157private:
158 ClientPagerMessageHandle mClientPagerMessageHandle;
159 std::unique_ptr<Contents> mContents;
161};
162
163void
164ClientPagerMessage::pageCommand(std::unique_ptr<Contents> contents,
166{
167 mDum.post(new ClientPagerMessagePageCommand(getHandle(), std::move(contents), level));
168}
169
170// Use this API if the application has ongoing pending messages and it is using
171// getMessageRequest to modify the target routing information for messages (ie:
172// requestUri or Route headers). This will cause the current pending message to
173// be re-sent immediately using the new information that the application just set.
174// Any onSuccess or onFailure callbacks that might result from the active pending
175// message at the time this is called will be suppressed. Any messages queued
176// behind that message will be dispatched sequentially to the new target.
177void
179{
180 if (mMsgQueue.empty() == false)
181 {
182 // Note: calling this will cause mRequest->header(h_CSeq) to get a new value
183 // and the responses to the currently pending MESSAGE will be ignored
184 pageFirstMsgQueued();
185 }
186}
187
188void
190{
192
193 ClientPagerMessageHandler* handler = mDum.mClientPagerMessageHandler;
194 resip_assert(handler);
195
196 const int code = msg.header(h_StatusLine).statusCode();
197
198 DebugLog ( << "ClientPagerMessageReq::dispatch(msg)" << msg.brief());
199 {
200 if (code < 200)
201 {
202 DebugLog ( << "ClientPagerMessageReq::dispatch - encountered provisional response" << msg.brief() );
203 }
204 else if (code < 300)
205 {
206 // if cseq doesn't match last message paged then someone must have called newTargetInfoSet
207 // we want to suppress the onSuccess callback and logic, since we re-sent this first queued
208 // item to a new target
209 if (msg.header(h_CSeq).sequence() == mRequest->header(h_CSeq).sequence())
210 {
211 if (mMsgQueue.empty() == false)
212 {
213 delete mMsgQueue.front().contents;
214 mMsgQueue.pop_front();
215 if (mMsgQueue.empty() == false)
216 {
217 this->pageFirstMsgQueued();
218 }
219 }
220 handler->onSuccess(getHandle(), msg);
221 }
222 }
223 else
224 {
225 // if cseq doesn't match last message paged then someone must have called newTargetInfoSet
226 // we want to suppress the onFailure callback and logic, since we re-sent this first queued
227 // item to a new target
228 if (msg.header(h_CSeq).sequence() == mRequest->header(h_CSeq).sequence())
229 {
230 if (!mMsgQueue.empty())
231 {
232 // if cseq doesn't match first queued element - someone must have called newTargetInfoSet
233 // we want to suppress the onFailure callback and logic, since we re-sent this first queued item to a new target
234 SipMessage errResponse;
235 MsgQueue::iterator contents;
236 for (contents = mMsgQueue.begin(); contents != mMsgQueue.end(); ++contents)
237 {
238 Contents* p = contents->contents;
239 WarningLog(<< "Paging failed " << *p);
240 Helper::makeResponse(errResponse, *mRequest, code);
241 handler->onFailure(getHandle(), errResponse, std::unique_ptr<Contents>(p));
242 contents->contents = 0;
243 }
244 mMsgQueue.clear();
245 }
246 else
247 {
248 handler->onFailure(getHandle(), msg, mRequest->releaseContents());
249 }
250 }
251 }
252 }
253}
254
255void
259
260void
262{
263 if(!mEnded)
264 {
265 mEnded = true;
266 mDum.destroy(this);
267 }
268}
269
271{
272public:
274 : mClientPagerMessage(clientPagerMessage)
275 {
276 }
277
278 void executeCommand() override
279 {
280 mClientPagerMessage.end();
281 }
282
283 EncodeStream& encodeBrief(EncodeStream& strm) const override
284 {
285 return strm << "ClientPagerMessageEndCommand";
286 }
287private:
288 ClientPagerMessage& mClientPagerMessage;
289};
290
291void
296
297size_t
299{
300 return mMsgQueue.size();
301}
302
303void
304ClientPagerMessage::pageFirstMsgQueued()
305{
306 resip_assert(mMsgQueue.empty() == false);
307 mRequest->header(h_CSeq).sequence()++;
308 mRequest->setContents(mMsgQueue.front().contents);
309 DumHelper::setOutgoingEncryptionLevel(*mRequest, mMsgQueue.front().encryptionLevel);
310 DebugLog(<< "ClientPagerMessage::pageFirstMsgQueued: " << *mRequest);
311 mDum.send(mRequest);
312}
313
314void
315ClientPagerMessage::clearMsgQueued()
316{
317 MsgQueue::iterator contents;
318 for(contents = mMsgQueue.begin(); contents != mMsgQueue.end(); ++contents)
319 {
320 Contents* p = contents->contents;
321 delete p;
322 }
323 mMsgQueue.clear();
324}
325
327ClientPagerMessage::dump(EncodeStream& strm) const
328{
329 strm << "ClientPagerMessage queued: " << mMsgQueue.size();
330 return strm;
331}
332
333
334
335/* ====================================================================
336 * The Vovida Software License, Version 1.0
337 *
338 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
339 *
340 * Redistribution and use in source and binary forms, with or without
341 * modification, are permitted provided that the following conditions
342 * are met:
343 *
344 * 1. Redistributions of source code must retain the above copyright
345 * notice, this list of conditions and the following disclaimer.
346 *
347 * 2. Redistributions in binary form must reproduce the above copyright
348 * notice, this list of conditions and the following disclaimer in
349 * the documentation and/or other materials provided with the
350
351 * distribution.
352 *
353 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
354 * and "Vovida Open Communication Application Library (VOCAL)" must
355 * not be used to endorse or promote products derived from this
356 * software without prior written permission. For written
357 * permission, please contact vocal@vovida.org.
358 *
359 * 4. Products derived from this software may not be called "VOCAL", nor
360 * may "VOCAL" appear in their name, without prior written
361 * permission of Vovida Networks, Inc.
362 *
363 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
364 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
365 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
366 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
367 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
368 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
369 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
370 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
371 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
372 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
373 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
374 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
375 * DAMAGE.
376 *
377 * ====================================================================
378 *
379 * This software consists of voluntary contributions made by Vovida
380 * Networks, Inc. and many individuals on behalf of Vovida Networks,
381 * Inc. For more information on Vovida Networks, Inc., please see
382 * <http://www.vovida.org/>.
383 *
384 */
#define DebugLog(args_)
Definition Logger.hxx:128
#define WarningLog(args_)
Definition Logger.hxx:134
#define resip_assert(x)
This file needs to work for both C and C++ code.
EncodeStream & encodeBrief(EncodeStream &strm) const override
output a brief description to stream
ClientPagerMessageEndCommand(ClientPagerMessage &clientPagerMessage)
EncodeStream & encodeBrief(EncodeStream &strm) const override
output a brief description to stream
ClientPagerMessagePageCommand(const ClientPagerMessageHandle &clientPagerMessageHandle, std::unique_ptr< Contents > contents, DialogUsageManager::EncryptionLevel level)
BaseUsageHandle getBaseHandle() const
Definition BaseUsage.cxx:36
DialogUsageManager & mDum
Definition BaseUsage.hxx:43
virtual void onSuccess(ClientPagerMessageHandle, const SipMessage &status)=0
virtual void onFailure(ClientPagerMessageHandle, const SipMessage &status, std::unique_ptr< Contents > contents)=0
kh!
virtual void endCommand()
Provide asynchronous method access by using command.
ClientPagerMessage(DialogUsageManager &dum, DialogSet &dialogSet)
EncodeStream & dump(EncodeStream &strm) const override
ClientPagerMessageHandle getHandle()
virtual void pageCommand(std::unique_ptr< Contents > contents, DialogUsageManager::EncryptionLevel level=DialogUsageManager::None)
void dispatch(const SipMessage &msg) override
SipMessage & getMessageRequest() noexcept
kh!
virtual void page(std::unique_ptr< Contents > contents, DialogUsageManager::EncryptionLevel level=DialogUsageManager::None)
kh!
Base class for all SIP body types.
Definition Contents.hxx:51
void send(std::shared_ptr< SipMessage > request)
static void setOutgoingEncryptionLevel(SipMessage &message, DialogUsageManager::EncryptionLevel level)
Definition DumHelper.cxx:11
static void makeResponse(SipMessage &response, const SipMessage &request, int responseCode, const Data &reason=Data::Empty, const Data &hostname=Data::Empty, const Data &warning=Data::Empty)
Make a response to a provided request.
Definition Helper.cxx:412
virtual Brief brief() const
return a facet for brief encoding of message
Definition Message.cxx:16
Represents a SIP message.
const RequestLine & header(const RequestLineType &l) const
Returns the RequestLine. This is only valid for request messages.
bool isResponse() const
Returns true if message is a response, false otherwise.
void post(Message *msg)
Posts a Message to this TransactionUser's fifo.
dcm! – add UnusedChecking(_enum) below;
StatusLineType h_StatusLine
Definition Headers.cxx:348
Handle< ClientPagerMessage > ClientPagerMessageHandle
Definition Handles.hxx:34
#define EncodeStream