reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
NonDialogUsage.cxx
Go to the documentation of this file.
6#include "rutil/Logger.hxx"
7#include "rutil/Inserter.hxx"
8
9#include <utility>
10
11#define RESIPROCATE_SUBSYSTEM Subsystem::DUM
12
13using namespace resip;
14
15NonDialogUsage::Exception::Exception(const Data& msg, const Data& file, const int line)
16 : BaseException(msg, file, line)
17{
18}
19
20const char*
22{
23 return "NonDialogUsage::Exception";
24}
25
27 BaseUsage(dum),
28 mDialogSet(dialogSet)
29{
30}
31
33{
34 mDialogSet.possiblyDie();
35}
36
39{
40 return mDialogSet.mAppDialogSet->getHandle();
41}
42
43std::shared_ptr<UserProfile>
45{
46 return mDialogSet.mUserProfile;
47}
48
49void
51{
52 // Only touch the single empty Contact created by Helper::makeResponse -
53 // anything else was put there by the application. An empty host is what
54 // the TransportSelector fills in with the address of the outgoing transport.
55 if (!response.exists(h_Contacts) ||
56 response.header(h_Contacts).size() != 1 ||
57 !response.header(h_Contacts).front().uri().host().empty())
58 {
59 return;
60 }
61
62 const std::shared_ptr<UserProfile> profile = getUserProfile();
63 NameAddr& contact = response.header(h_Contacts).front();
64 if (profile->hasUserAgentCapabilities())
65 {
66 contact = profile->getUserAgentCapabilities();
67 }
68 if (!profile->isAnonymous() && profile->hasPublicGruu())
69 {
70 contact.uri() = profile->getPublicGruu();
71 }
72 else if (profile->isAnonymous() && profile->hasTempGruu())
73 {
74 contact.uri() = profile->getTempGruu();
75 }
76 else
77 {
78 if (profile->hasOverrideHostAndPort())
79 {
80 contact.uri() = profile->getOverrideHostAndPort();
81 }
82 // See Dialog.cxx for why the user part is only copied from sip:, sips:
83 // and tel: URIs.
84 if (request.header(h_RequestLine).uri().user().empty())
85 {
86 if (request.header(h_To).uri().isUserRelevant())
87 {
88 contact.uri().user() = request.header(h_To).uri().user();
89 }
90 }
91 else if (request.header(h_RequestLine).uri().isUserRelevant())
92 {
93 contact.uri().user() = request.header(h_RequestLine).uri().user();
94 }
95 const Data& instanceId = profile->getInstanceId();
96 if (!contact.uri().exists(p_gr) && !instanceId.empty())
97 {
98 contact.param(p_Instance) = instanceId;
99 }
100 }
101 if (profile->clientOutboundEnabled())
102 {
103 // Add ;ob parm to non-register requests - RFC5626 pg17
104 contact.uri().param(p_ob);
105 }
106}
107
108void
109NonDialogUsage::send(std::shared_ptr<SipMessage> msg)
110{
111 const NameAddrs& sRoute = getUserProfile()->getServiceRoute();
112
113 // Clear the routes if there was previously a service_route. Otherwise
114 // keep the route in case there exists custom routes
115
116 if (!sRoute.empty())
117 {
118 if (msg->header(h_RequestLine).method() == REGISTER)
119 {
120 const NameAddrs emptyRoute;
121 msg->remove(h_Routes);
122 getUserProfile()->setServiceRoute(emptyRoute);
123 }
124 else
125 {
126 InfoLog(<< "Applying service route: " << Inserter(getUserProfile()->getServiceRoute()) << " to " << msg->brief());
127 msg->header(h_Routes) = sRoute;
128 }
129 }
130
131 mDum.send(msg);
132}
133
135{
136public:
137 NonDialogUsageSendCommand(NonDialogUsage& usage, std::shared_ptr<SipMessage> msg)
138 : mNonDialogUsage(usage),
139 mMessage(msg)
140 {
141 }
142
143 void executeCommand() override
144 {
145 mNonDialogUsage.send(mMessage);
146 }
147
148 EncodeStream& encodeBrief(EncodeStream& strm) const override
149 {
150 return strm << "NonDialogUsageSendCommand";
151 }
152private:
153 NonDialogUsage& mNonDialogUsage;
154 std::shared_ptr<SipMessage> mMessage;
155};
156
157void
158NonDialogUsage::sendCommand(std::shared_ptr<SipMessage> message)
159{
160 mDum.post(new NonDialogUsageSendCommand(*this, message));
161}
162
163/* ====================================================================
164 * The Vovida Software License, Version 1.0
165 *
166 * Copyright (c) 2026 SIP Spectrum, Inc. http://www.sipspectrum.com
167 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
168 *
169 * Redistribution and use in source and binary forms, with or without
170 * modification, are permitted provided that the following conditions
171 * are met:
172 *
173 * 1. Redistributions of source code must retain the above copyright
174 * notice, this list of conditions and the following disclaimer.
175 *
176 * 2. Redistributions in binary form must reproduce the above copyright
177 * notice, this list of conditions and the following disclaimer in
178 * the documentation and/or other materials provided with the
179
180 * distribution.
181 *
182 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
183 * and "Vovida Open Communication Application Library (VOCAL)" must
184 * not be used to endorse or promote products derived from this
185 * software without prior written permission. For written
186 * permission, please contact vocal@vovida.org.
187 *
188 * 4. Products derived from this software may not be called "VOCAL", nor
189 * may "VOCAL" appear in their name, without prior written
190 * permission of Vovida Networks, Inc.
191 *
192 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
193 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
194 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
195 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
196 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
197 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
198 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
199 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
200 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
201 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
202 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
203 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
204 * DAMAGE.
205 *
206 * ====================================================================
207 *
208 * This software consists of voluntary contributions made by Vovida
209 * Networks, Inc. and many individuals on behalf of Vovida Networks,
210 * Inc. For more information on Vovida Networks, Inc., please see
211 * <http://www.vovida.org/>.
212 *
213 */
#define InfoLog(args_)
Definition Logger.hxx:131
static void usage(void)
Definition adig.c:755
NonDialogUsageSendCommand(NonDialogUsage &usage, std::shared_ptr< SipMessage > msg)
EncodeStream & encodeBrief(EncodeStream &strm) const override
output a brief description to stream
AppDialogSetHandle getHandle()
The abstract base-class for all exceptions thrown by resip code.
DialogUsageManager & mDum
Definition BaseUsage.hxx:43
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
bool empty() const noexcept
Checks whether the Data is empty.
Definition Data.hxx:591
void send(std::shared_ptr< SipMessage > request)
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Definition NameAddr.hxx:19
const Data & param(const ExtensionParameter &param) const
Const accessor for non-natively-supported parameter types.
Exception(const Data &msg, const Data &file, int line)
const char * name() const noexcept override
void applyLocalContact(SipMessage &response, const SipMessage &request) const
NonDialogUsage(DialogUsageManager &dum, DialogSet &dialogSet)
virtual void send(std::shared_ptr< SipMessage > msg)
std::shared_ptr< UserProfile > getUserProfile() const noexcept
virtual void sendCommand(std::shared_ptr< SipMessage > msg)
AppDialogSetHandle getAppDialogSet() const
bool empty() const
return true or false indicating whether the mParsers vector is empty or not
const Uri & uri() const
Represents a SIP message.
const RequestLine & header(const RequestLineType &l) const
Returns the RequestLine. This is only valid for request messages.
bool exists(const HeaderBase &headerType) const
Returns true if the given header field is present, false otherwise.
void post(Message *msg)
Posts a Message to this TransactionUser's fifo.
bool isUserRelevant() const
Checks if this URI's scheme has sip:/sips:/tel: user-part semantics, i.e.
Definition Uri.cxx:528
bool exists(const Param< Uri > &paramType) const
Definition Uri.cxx:1701
Data & user()
Definition Uri.hxx:42
Data & host()
Definition Uri.hxx:40
const Data & param(const ExtensionParameter &param) const
Const accessor for non-natively-supported parameter types.
dcm! – add UnusedChecking(_enum) below;
InserterClass< T > Inserter(const T &t)
Templatized function to construct an instance of InserterClass for a container to be inserted.
Definition Inserter.hxx:312
RequestLineType h_RequestLine
Definition Headers.cxx:347
#define EncodeStream