reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
UserAgentClientSubscription.cxx
Go to the documentation of this file.
1#include "UserAgent.hxx"
2#include "ReconSubsystem.hxx"
4
5#include <rutil/Log.hxx>
6#include <rutil/Logger.hxx>
9
10using namespace recon;
11using namespace resip;
12using namespace std;
13
14#define RESIPROCATE_SUBSYSTEM ReconSubsystem::RECON
15
17: AppDialogSet(dum),
18 mUserAgent(userAgent),
19 mSubscriptionHandle(handle),
20 mLastNotifyHash(0),
21 mEnded(false)
22{
23 mUserAgent.registerSubscription(this);
24}
25
30
33{
34 return mSubscriptionHandle;
35}
36
37void
39{
40 if(!mEnded)
41 {
42 mEnded = true;
44 }
45}
46
47void
48UserAgentClientSubscription::notifyReceived(const Data& notifyData)
49{
50 size_t hash = notifyData.hash();
51 if(hash != mLastNotifyHash) // only call callback if body changed from last time
52 {
53 mLastNotifyHash = hash;
54 mUserAgent.onSubscriptionNotify(mSubscriptionHandle, notifyData);
55 }
56}
57
59// ClientSubscriptionHandler ///////////////////////////////////////////////////
61void
63{
64 InfoLog(<< "onUpdatePending(ClientSubscriptionHandle): handle=" << mSubscriptionHandle << ", " << msg.brief());
65 h->acceptUpdate();
66 if(mEnded)
67 {
68 h->end();
69 }
70 else if(msg.getContents())
71 {
72 const Data& bodyData = msg.getContents()->getBodyData();
73 notifyReceived(bodyData);
74 }
75}
76
77void
79{
80 InfoLog(<< "onUpdateActive(ClientSubscriptionHandle): handle=" << mSubscriptionHandle << ", " << msg.brief());
81 h->acceptUpdate();
82 if(mEnded)
83 {
84 h->end();
85 }
86 else if(msg.getContents())
87 {
88 const Data& bodyData = msg.getContents()->getBodyData();
89 notifyReceived(bodyData);
90 }
91}
92
93void
95{
96 InfoLog(<< "onUpdateExtension(ClientSubscriptionHandle): handle=" << mSubscriptionHandle << ", " << msg.brief());
97 h->acceptUpdate();
98 if(mEnded)
99 {
100 h->end();
101 }
102 else if(msg.getContents())
103 {
104 const Data& bodyData = msg.getContents()->getBodyData();
105 notifyReceived(bodyData);
106 }
107}
108
109void
111{
112 unsigned int statusCode = 0;
113 if(msg)
114 {
115 if(msg->isResponse())
116 {
117 statusCode = msg->header(h_StatusLine).responseCode();
118 if (statusCode >= 300)
119 {
120 WarningLog(<< "onTerminated(ClientSubscriptionHandle): handle=" << mSubscriptionHandle << ", " << msg->brief());
121 }
122 else
123 {
124 InfoLog(<< "onTerminated(ClientSubscriptionHandle): handle=" << mSubscriptionHandle << ", " << msg->brief());
125 }
126 }
127 else
128 {
129 InfoLog(<< "onTerminated(ClientSubscriptionHandle): handle=" << mSubscriptionHandle << ", " << msg->brief());
130 if(msg->getContents())
131 {
132 notifyReceived(msg->getContents()->getBodyData());
133 }
134 }
135 }
136 else
137 {
138 WarningLog(<< "onTerminated(ClientSubscriptionHandle): handle=" << mSubscriptionHandle);
139 statusCode = 408; // timedout waiting for notify after subscribe
140 }
141 mUserAgent.onSubscriptionTerminated(mSubscriptionHandle, statusCode);
142}
143
144void
146{
147 InfoLog(<< "onNewSubscription(ClientSubscriptionHandle): handle=" << mSubscriptionHandle << ", " << msg.brief());
148 // Note: The notify here, will also be passed in an onUpdateXXXX callback, so no need to do anything with this callback
149}
150
151int
153{
154 return min(retryMinimum, mUserAgent.getUserAgentMasterProfile()->subscriptionRetryInterval());
155}
156
157
158/* ====================================================================
159
160 Copyright (c) 2023, SIP Spectrum, Inc. http://www.sipspectrum.com
161 Copyright (c) 2007-2008, Plantronics, Inc.
162 All rights reserved.
163
164 Redistribution and use in source and binary forms, with or without
165 modification, are permitted provided that the following conditions are
166 met:
167
168 1. Redistributions of source code must retain the above copyright
169 notice, this list of conditions and the following disclaimer.
170
171 2. Redistributions in binary form must reproduce the above copyright
172 notice, this list of conditions and the following disclaimer in the
173 documentation and/or other materials provided with the distribution.
174
175 3. Neither the name of Plantronics nor the names of its contributors
176 may be used to endorse or promote products derived from this
177 software without specific prior written permission.
178
179 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
180 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
182 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
183 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
184 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
185 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
186 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
187 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
188 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
189 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
190
191 ==================================================================== */
#define InfoLog(args_)
Definition Logger.hxx:131
#define WarningLog(args_)
Definition Logger.hxx:134
static const Data bodyData("Body")
virtual void onUpdateActive(resip::ClientSubscriptionHandle h, const resip::SipMessage &notify, bool outOfOrder)
UserAgentClientSubscription(UserAgent &userAgent, resip::DialogUsageManager &dum, unsigned int handle)
virtual void onNewSubscription(resip::ClientSubscriptionHandle h, const resip::SipMessage &notify)
virtual void onUpdatePending(resip::ClientSubscriptionHandle h, const resip::SipMessage &notify, bool outOfOrder)
virtual int onRequestRetry(resip::ClientSubscriptionHandle h, int retryMinimum, const resip::SipMessage &notify)
virtual void onTerminated(resip::ClientSubscriptionHandle h, const resip::SipMessage *notify)
virtual void onUpdateExtension(resip::ClientSubscriptionHandle, const resip::SipMessage &notify, bool outOfOrder)
This class is one of two main classes of concern to an application using the UserAgent library.
Definition UserAgent.hxx:56
virtual void onSubscriptionNotify(SubscriptionHandle handle, const resip::Data &notifyData)
Callback used when a subscription has received an event notification from the server.
void unregisterSubscription(UserAgentClientSubscription *)
std::shared_ptr< UserAgentMasterProfile > getUserAgentMasterProfile() const noexcept
void registerSubscription(UserAgentClientSubscription *)
virtual void onSubscriptionTerminated(SubscriptionHandle handle, unsigned int statusCode)
Callback used when a subscription is terminated.
virtual void end()
virtual Data getBodyData() const
Definition Contents.cxx:661
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
size_t hash() const
Creates a 32-bit hash based on the contents of this Data.
Definition Data.cxx:2355
virtual Brief brief() const
return a facet for brief encoding of message
Definition Message.cxx:16
Represents a SIP message.
Contents * getContents() const
Retrieves the body of 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.
unsigned int SubscriptionHandle
dcm! – add UnusedChecking(_enum) below;
StatusLineType h_StatusLine
Definition Headers.cxx:348