reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
SipConfigParse.cxx
Go to the documentation of this file.
1
3#ifdef USE_SSL
5#endif
7
8using namespace resip;
9using namespace std;
10
11#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
12
13namespace resip
14{
15
19
23
24bool
26{
27 Data lowerName(name); lowerName.lowercase();
28 ConfigValuesMap::iterator it = mConfigValues.find(lowerName);
29 if(it != mConfigValues.end())
30 {
31 try
32 {
33 if(!it->second.empty())
34 {
35 NameAddr tempNameAddr(it->second);
36 value = tempNameAddr.uri();
37 return true;
38 }
39 else
40 {
41 value = Uri(); // return an empty Uri
42 return true;
43 }
44 }
45 catch(resip::BaseException& e)
46 {
47 // Try adding sip: to value to see if it will be valid
48 try
49 {
50 NameAddr tempNameAddr(Data("sip:" + it->second));
51 value = tempNameAddr.uri();
52 return true;
53 }
55 {
56 cerr << "Invalid Uri setting: " << name << " = " << it->second << ": " << e << endl;
57 return false;
58 }
59 }
60 }
61 // Not found
62 return false;
63}
64
66SipConfigParse::getConfigUri(const resip::Data& name, const resip::Uri& defaultValue, bool useDefaultIfEmpty)
67{
68 Uri ret(defaultValue);
69 if(getConfigValue(name, ret) && ret.host().empty() && useDefaultIfEmpty)
70 {
71 return defaultValue;
72 }
73 return ret;
74}
75
76bool
78{
79 Data lowerName(name); lowerName.lowercase();
80 ConfigValuesMap::iterator it = mConfigValues.find(lowerName);
81 if(it != mConfigValues.end())
82 {
83 try
84 {
85 if(!it->second.empty())
86 {
87 NameAddr tempuri(it->second);
88 value = tempuri;
89 return true;
90 }
91 else
92 {
93 value = NameAddr();
94 return true;
95 }
96 }
97 catch(resip::BaseException& e)
98 {
99 cerr << "Invalid uri format: " << e << endl;
100 return false;
101 }
102 }
103 // Not found
104 return false;
105}
106
108SipConfigParse::getConfigNameAddr(const resip::Data& name, const resip::NameAddr& defaultValue, bool useDefaultIfEmpty)
109{
110 resip::NameAddr ret(defaultValue);
111 if(getConfigValue(name, ret) && ret.uri().host().empty() && useDefaultIfEmpty)
112 {
113 return defaultValue;
114 }
115 return ret;
116}
117
118bool
120{
121 Data lowerName(name); lowerName.lowercase();
122 ConfigValuesMap::iterator it = mConfigValues.find(lowerName);
123 if(it != mConfigValues.end())
124 {
125#ifdef USE_SSL
126 value = Security::parseSSLType(it->second);
127#else
128 value = SecurityTypes::NoSSL;
129#endif
130 }
131 return false;
132}
133
136{
137 SecurityTypes::SSLType ret = defaultValue;
138 getConfigValue(name, ret);
139 return ret;
140}
141
142bool
144{
145 Data lowerName(name); lowerName.lowercase();
146 ConfigValuesMap::iterator it = mConfigValues.find(lowerName);
147 if(it != mConfigValues.end())
148 {
149 if(isEqualNoCase(it->second, "Optional"))
150 {
152 }
153 else if(isEqualNoCase(it->second, "Mandatory"))
154 {
156 }
157 else if(isEqualNoCase(it->second, "None"))
158 {
159 value = SecurityTypes::None;
160 }
161 else
162 {
163 Data exceptionString("Unknown TLS client verification mode found in " + name + " setting: " + it->second);
164 throw Exception(exceptionString, __FILE__, __LINE__);
165 }
166 return true;
167 }
168 return false;
169}
170
178
179}
180
181/* ====================================================================
182 *
183 * Copyright 2016 Daniel Pocock http://danielpocock.com All rights reserved.
184 *
185 * Redistribution and use in source and binary forms, with or without
186 * modification, are permitted provided that the following conditions
187 * are met:
188 *
189 * 1. Redistributions of source code must retain the above copyright
190 * notice, this list of conditions and the following disclaimer.
191 *
192 * 2. Redistributions in binary form must reproduce the above copyright
193 * notice, this list of conditions and the following disclaimer in
194 * the documentation and/or other materials provided with the
195 * distribution.
196 *
197 * 3. Neither the name of the author(s) nor the names of any contributors
198 * may be used to endorse or promote products derived from this software
199 * without specific prior written permission.
200 *
201 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
202 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
203 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
204 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
205 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
206 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
207 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
208 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
209 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
210 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
211 * SUCH DAMAGE.
212 *
213 * ====================================================================
214 *
215 *
216 */
217
The abstract base-class for all exceptions thrown by resip code.
static SecurityTypes::SSLType parseSSLType(const Data &typeName)
Converts a string containing an SSL type name to the corresponding enum value.
ConfigValuesMap mConfigValues
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
Data & lowercase()
Converts this Data to lowercase.
Definition Data.cxx:1635
size_type find(const Data &match, size_type start=0) const
Finds a specified sequence of bytes in this Data.
Definition Data.cxx:1947
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Definition NameAddr.hxx:19
resip::Uri getConfigUri(const resip::Data &name, const resip::Uri &defaultValue, bool useDefaultIfEmpty=false)
SecurityTypes::TlsClientVerificationMode getConfigClientVerificationMode(const resip::Data &name, SecurityTypes::TlsClientVerificationMode defaultValue)
SecurityTypes::SSLType getConfigSSLType(const resip::Data &name, SecurityTypes::SSLType defaultValue)
bool getConfigValue(const resip::Data &name, resip::Uri &value)
resip::NameAddr getConfigNameAddr(const resip::Data &name, const resip::NameAddr &defaultValue, bool useDefaultIfEmpty=false)
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
Data & host()
Definition Uri.hxx:40
SSLType
Note: Before adding to the SSLType enum, please see the comments about mTlsCtx in resip/stack/ssl/Sec...
dcm! – add UnusedChecking(_enum) below;
bool isEqualNoCase(const Data &left, const Data &right)
Definition Data.hxx:1116