aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llurlsimstring.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llurlsimstring.cpp171
1 files changed, 171 insertions, 0 deletions
diff --git a/linden/indra/newview/llurlsimstring.cpp b/linden/indra/newview/llurlsimstring.cpp
new file mode 100644
index 0000000..efa3c5a
--- /dev/null
+++ b/linden/indra/newview/llurlsimstring.cpp
@@ -0,0 +1,171 @@
1/**
2 * @file llsimurlstring.cpp
3 * @brief Handles "SLURL fragments" like Ahern/123/45 for
4 * startup processing, login screen, prefs, etc.
5 *
6 * $LicenseInfo:firstyear=2006&license=viewergpl$
7 *
8 * Copyright (c) 2006-2007, Linden Research, Inc.
9 *
10 * Second Life Viewer Source Code
11 * The source code in this file ("Source Code") is provided by Linden Lab
12 * to you under the terms of the GNU General Public License, version 2.0
13 * ("GPL"), unless you have obtained a separate licensing agreement
14 * ("Other License"), formally executed by you and Linden Lab. Terms of
15 * the GPL can be found in doc/GPL-license.txt in this distribution, or
16 * online at http://secondlife.com/developers/opensource/gplv2
17 *
18 * There are special exceptions to the terms and conditions of the GPL as
19 * it is applied to this Source Code. View the full text of the exception
20 * in the file doc/FLOSS-exception.txt in this software distribution, or
21 * online at http://secondlife.com/developers/opensource/flossexception
22 *
23 * By copying, modifying or distributing this software, you acknowledge
24 * that you have read and understood your obligations described above,
25 * and agree to abide by those obligations.
26 *
27 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
28 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
29 * COMPLETENESS OR PERFORMANCE.
30 * $/LicenseInfo$
31 */
32
33#include "llviewerprecompiledheaders.h"
34
35#include "llurlsimstring.h"
36
37#include "llpanellogin.h"
38#include "llviewercontrol.h"
39
40#include "curl/curl.h"
41
42//static
43LLURLSimString LLURLSimString::sInstance;
44LLString LLURLSimString::sLocationStringHome("My Home");
45LLString LLURLSimString::sLocationStringLast("My Last Location");
46
47// "secondlife://simname/x/y/z" -> "simname/x/y/z"
48// (actually .*//foo -> foo)
49// static
50void LLURLSimString::setString(const LLString& sim_string)
51{
52 sInstance.mSimString.clear();
53 sInstance.mSimName.clear();
54 sInstance.mParseState = NOT_PARSED;
55 if (sim_string == sLocationStringHome)
56 {
57 gSavedSettings.setBOOL("LoginLastLocation", FALSE);
58 }
59 else if (sim_string == sLocationStringLast)
60 {
61 gSavedSettings.setBOOL("LoginLastLocation", TRUE);
62 }
63 else
64 {
65 char* curlstr = curl_unescape(sim_string.c_str(), sim_string.size());
66 LLString tstring = LLString(curlstr);
67 curl_free(curlstr);
68 std::string::size_type idx = tstring.find("//");
69 idx = (idx == LLString::npos) ? 0 : idx+2;
70 sInstance.mSimString = tstring.substr(idx);
71 }
72 LLPanelLogin::refreshLocation( false ); // in case LLPanelLogin is visible
73}
74
75// "/100" -> 100
76// static
77S32 LLURLSimString::parseGridIdx(const LLString& in_string, S32 idx0, S32* res, S32 max)
78{
79 if (idx0 == INT_MAX || in_string[idx0] != '/')
80 {
81 return INT_MAX; // parse error
82 }
83 idx0++;
84 LLString::size_type idx1 = in_string.find_first_of('/', idx0);
85 LLString::size_type len = (idx1 == LLString::npos) ? LLString::npos : idx1-idx0;
86 LLString tstring = in_string.substr(idx0,len);
87 if (!tstring.empty())
88 {
89 S32 val = atoi(tstring.c_str());
90 *res = llclamp(val,0,max);
91 }
92 return idx1;
93}
94
95// "simname/x/y/z" -> mSimName = simname, mX = x, mY = y, mZ = z
96// static
97bool LLURLSimString::parse()
98{
99 if (sInstance.mParseState == NOT_SET)
100 {
101 return false;
102 }
103 if (sInstance.mParseState == NOT_PARSED)
104 {
105 if (parse(sInstance.mSimString,
106 &sInstance.mSimName,
107 &sInstance.mX,
108 &sInstance.mY,
109 &sInstance.mZ))
110 {
111 sInstance.mParseState = PARSE_OK;
112 }
113 else
114 {
115 sInstance.mParseState = PARSE_FAIL;
116 }
117 }
118 return (sInstance.mParseState == PARSE_OK);
119}
120
121// static
122bool LLURLSimString::parse(const LLString& sim_string, std::string *region_name, S32 *x, S32 *y, S32 *z)
123{
124 // strip any bogus initial '/'
125 LLString::size_type idx0 = sim_string.find_first_not_of('/');
126 if (idx0 == std::string::npos) idx0 = 0;
127
128 LLString::size_type idx1 = sim_string.find_first_of('/', idx0);
129 LLString::size_type len = (idx1 == std::string::npos) ? std::string::npos : idx1-idx0;
130 LLString tstring = sim_string.substr(idx0,len);
131 *region_name = unescapeRegionName(tstring);
132 if (!region_name->empty())
133 {
134 if (idx1 != std::string::npos)
135 {
136 idx1 = parseGridIdx(sim_string, idx1, x, 255);
137 idx1 = parseGridIdx(sim_string, idx1, y, 255);
138 idx1 = parseGridIdx(sim_string, idx1, z, 1000);
139 }
140 return true;
141 }
142 else
143 {
144 return false;
145 }
146}
147
148// static
149std::string LLURLSimString::getURL()
150{
151 std::string url;
152 if (sInstance.mParseState == PARSE_OK)
153 {
154 url = llformat("secondlife://%s/%d/%d/%d/",
155 sInstance.mSimName.c_str(),
156 sInstance.mX,
157 sInstance.mY,
158 sInstance.mZ);
159 }
160 return url;
161}
162
163// static
164std::string LLURLSimString::unescapeRegionName(std::string region_name)
165{
166 std::string result;
167 char* curlstr = curl_unescape(region_name.c_str(), region_name.size());
168 result = std::string(curlstr);
169 curl_free(curlstr);
170 return result;
171}