aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/lluri.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcommon/lluri.cpp')
-rw-r--r--linden/indra/llcommon/lluri.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/linden/indra/llcommon/lluri.cpp b/linden/indra/llcommon/lluri.cpp
index c838b25..83de022 100644
--- a/linden/indra/llcommon/lluri.cpp
+++ b/linden/indra/llcommon/lluri.cpp
@@ -188,6 +188,55 @@ LLURI::LLURI(const std::string& escaped_str)
188 } 188 }
189} 189}
190 190
191static BOOL isDefault(const std::string& scheme, U16 port)
192{
193 if (scheme == "http")
194 return port == 80;
195 if (scheme == "https")
196 return port == 443;
197 if (scheme == "ftp")
198 return port == 21;
199
200 return FALSE;
201}
202
203LLURI::LLURI(const std::string& scheme,
204 const std::string& userName,
205 const std::string& password,
206 const std::string& hostName,
207 U16 port,
208 const std::string& escapedPath,
209 const std::string& escapedQuery)
210 : mScheme(scheme),
211 mEscapedPath(escapedPath),
212 mEscapedQuery(escapedQuery)
213{
214 std::ostringstream auth;
215 std::ostringstream opaque;
216
217 opaque << "//";
218
219 if (!userName.empty())
220 {
221 auth << escape(userName);
222 if (!password.empty())
223 {
224 auth << ':' << escape(password);
225 }
226 auth << '@';
227 }
228 auth << hostName;
229 if (!isDefault(scheme, port))
230 {
231 auth << ':' << port;
232 }
233 mEscapedAuthority = auth.str();
234
235 opaque << mEscapedAuthority << escapedPath << escapedQuery;
236
237 mEscapedOpaque = opaque.str();
238}
239
191LLURI::~LLURI() 240LLURI::~LLURI()
192{ 241{
193} 242}
@@ -447,6 +496,35 @@ std::string LLURI::hostName() const
447 return unescape(host); 496 return unescape(host);
448} 497}
449 498
499std::string LLURI::userName() const
500{
501 std::string user, userPass, host, port;
502 findAuthorityParts(mEscapedAuthority, userPass, host, port);
503 std::string::size_type pos = userPass.find(':');
504 if (pos != std::string::npos)
505 {
506 user = userPass.substr(0, pos);
507 }
508 return unescape(user);
509}
510
511std::string LLURI::password() const
512{
513 std::string pass, userPass, host, port;
514 findAuthorityParts(mEscapedAuthority, userPass, host, port);
515 std::string::size_type pos = userPass.find(':');
516 if (pos != std::string::npos)
517 {
518 pass = userPass.substr(pos + 1);
519 }
520 return unescape(pass);
521}
522
523BOOL LLURI::defaultPort() const
524{
525 return isDefault(mScheme, hostPort());
526}
527
450U16 LLURI::hostPort() const 528U16 LLURI::hostPort() const
451{ 529{
452 std::string user, host, port; 530 std::string user, host, port;