reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
UserProfile.cxx
Go to the documentation of this file.
1
4#include "rutil/Logger.hxx"
5#include "rutil/Inserter.hxx"
7
8#include <utility>
9
10using namespace resip;
11#define RESIPROCATE_SUBSYSTEM Subsystem::DUM
12
13const resip::NameAddr UserProfile::mAnonymous("\"Anonymous\" <sip:anonymous@anonymous.invalid>", true /* preCacheAor */);
14
16 mGruuEnabled(false),
17 mRegId(0),
18 mClientOutboundEnabled(false),
19 mDigestCacheUseLimit(0)
20{
21 //InfoLog (<< "************ UserProfile created (no base)!: " << *this);
22}
23
24UserProfile::UserProfile(std::shared_ptr<Profile> baseProfile) : Profile(baseProfile),
25 mGruuEnabled(false),
26 mRegId(0),
27 mClientOutboundEnabled(false),
28 mDigestCacheUseLimit(0)
29{
30 //InfoLog (<< "************ UserProfile created (with base)!: " << *this);
31}
32
34{
35 //InfoLog (<< "************ UserProfile destroyed!: " << *this);
36}
37
38std::shared_ptr<UserProfile>
40{
41 std::shared_ptr<UserProfile> anon(this->clone());
42 anon->setDefaultFrom(mAnonymous);
43 return anon;
44}
45
48{
49 return new UserProfile(*this);
50}
51
52bool
54{
55 return (mDefaultFrom.uri().getAor() == mAnonymous.uri().getAor());
56}
57
58void
60{
61 mDefaultFrom = from;
62}
63
66{
67 return mDefaultFrom;
68}
69
70void
72{
73 mServiceRoute = sRoute;
74}
75
78{
79 return mServiceRoute;
80}
81
82bool
84{
85 return !mInstanceId.empty();
86}
87
88void
90{
91 mInstanceId = id;
92}
93
94const Data&
96{
97 return mInstanceId;
98}
99
100void
101UserProfile::addGruu(const Data& aor, const NameAddr& contact)
102{
103}
104
105bool
106UserProfile::hasGruu(const Data& aor) const
107{
108 return false;
109}
110
111bool
112UserProfile::hasGruu(const Data& aor, const Data& instance) const
113{
114 return false;
115}
116
119{
120 resip_assert(0);
121 static NameAddr gruu;
122 return gruu;
123}
124
126UserProfile:: getGruu(const Data& aor, const NameAddr& contact)
127{
128 resip_assert(0);
129 static NameAddr gruu;
130 return gruu;
131}
132
133void
135{
136 mDigestCredentials.clear();
137}
138
139void
140UserProfile::setDigestCredential( const Data& realm, const Data& user, const Data& password, bool isPasswordA1Hash)
141{
142 DigestCredential cred(realm, user, password, isPasswordA1Hash);
143
144 DebugLog (<< "Adding credential: " << cred);
145 mDigestCredentials.erase(cred);
146 mDigestCredentials.insert(cred);
147}
148
152{
153 if(mDigestCredentials.empty())
154 {
155 // !jf! why not just throw here?
156 WarningLog(<< "No digest credentials available");
158 }
159
160 DigestCredentials::const_iterator it = mDigestCredentials.find(DigestCredential(realm));
161 if (it == mDigestCredentials.end())
162 {
163 DebugLog(<< "Didn't find credential for realm: " << realm << " " << *mDigestCredentials.begin());
164 return *mDigestCredentials.begin();
165 }
166 else
167 {
168 DebugLog(<< "Found credential for realm: " << *it << realm);
169 return *it;
170 }
171}
172
173UserProfile::DigestCredential::DigestCredential(const Data& r, const Data& u, const Data& pwd, bool pwdA1Hash) :
174 realm(r),
175 user(u),
176 password(pwd),
177 isPasswordA1Hash(pwdA1Hash)
178{
179}
180
182 realm(Data::Empty),
183 user(Data::Empty),
184 password(Data::Empty),
185 isPasswordA1Hash(false)
186{
187}
188
190 realm(pRealm),
191 user(Data::Empty),
192 password(Data::Empty),
193 isPasswordA1Hash(false)
194{
195}
196
197bool
199{
200 return realm < rhs.realm;
201}
202
204resip::operator<<(EncodeStream& strm, const UserProfile& profile)
205{
206 strm << "UserProfile: " << profile.mDefaultFrom << Inserter(profile.mDigestCredentials);
207 return strm;
208}
209
211resip::operator<<(EncodeStream& strm, const UserProfile::DigestCredential& cred)
212{
213 strm << "realm=" << cred.realm << " user=" << cred.user ;
214 return strm;
215}
216
217
218/* ====================================================================
219 * The Vovida Software License, Version 1.0
220 *
221 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
222 *
223 * Redistribution and use in source and binary forms, with or without
224 * modification, are permitted provided that the following conditions
225 * are met:
226 *
227 * 1. Redistributions of source code must retain the above copyright
228 * notice, this list of conditions and the following disclaimer.
229 *
230 * 2. Redistributions in binary form must reproduce the above copyright
231 * notice, this list of conditions and the following disclaimer in
232 * the documentation and/or other materials provided with the
233 * distribution.
234 *
235 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
236 * and "Vovida Open Communication Application Library (VOCAL)" must
237 * not be used to endorse or promote products derived from this
238 * software without prior written permission. For written
239 * permission, please contact vocal@vovida.org.
240 *
241 * 4. Products derived from this software may not be called "VOCAL", nor
242 * may "VOCAL" appear in their name, without prior written
243 * permission of Vovida Networks, Inc.
244 *
245 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
246 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
247 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
248 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
249 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
250 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
251 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
252 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
253 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
254 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
256 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
257 * DAMAGE.
258 *
259 * ====================================================================
260 *
261 * This software consists of voluntary contributions made by Vovida
262 * Networks, Inc. and many individuals on behalf of Vovida Networks,
263 * Inc. For more information on Vovida Networks, Inc., please see
264 * <http://www.vovida.org/>.
265 *
266 */
#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.
static const UserProfile::DigestCredential emptyDigestCredential
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
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Definition NameAddr.hxx:19
Data getAor() const
Definition Uri.cxx:1095
virtual NameAddr & getGruu(const Data &aor)
virtual NameAddrs & getServiceRoute() noexcept
virtual void setInstanceId(const Data &id)
virtual bool hasGruu(const Data &aor) const
virtual void setDigestCredential(const Data &realm, const Data &user, const Data &password, bool isPasswordA1Hash=false)
For the password you may either provide the plain text password (isPasswordA1Hash = false) or the Dig...
virtual bool hasInstanceId()
virtual const Data & getInstanceId() const noexcept
virtual const DigestCredential & getDigestCredential(const Data &realm)
virtual std::shared_ptr< UserProfile > getAnonymousUserProfile() const
virtual UserProfile * clone() const
virtual void setServiceRoute(const NameAddrs &sRoute)
virtual void clearDigestCredentials() noexcept
The following functions deal with clearing, setting and getting of digest credentals.
virtual void setDefaultFrom(const NameAddr &from)
virtual NameAddr & getDefaultFrom() noexcept
bool isAnonymous() const
virtual void addGruu(const Data &aor, const NameAddr &contact)
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
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
#define EncodeStream
bool operator<(const DigestCredential &rhs) const