Annotation of /trunk/indra/newview/llurlsimstring.cpp
Parent Directory
|
Revision Log
Revision 138 - (view) (download)
| 1 : | mjm | 135 | /** |
| 2 : | * @file llurlsimstring.cpp (was 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 : | mjm | 137 | * Copyright (c) 2006-2010, Linden Research, Inc. |
| 9 : | mjm | 135 | * |
| 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://secondlifegrid.net/programs/open_source/licensing/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 | ||
| 22 : | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 23 : | * | ||
| 24 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 25 : | * that you have read and understood your obligations described above, | ||
| 26 : | * and agree to abide by those obligations. | ||
| 27 : | * | ||
| 28 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 29 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 30 : | * COMPLETENESS OR PERFORMANCE. | ||
| 31 : | * $/LicenseInfo$ | ||
| 32 : | */ | ||
| 33 : | |||
| 34 : | #include "llviewerprecompiledheaders.h" | ||
| 35 : | |||
| 36 : | #include "llurlsimstring.h" | ||
| 37 : | |||
| 38 : | #include "llpanellogin.h" | ||
| 39 : | #include "llviewercontrol.h" | ||
| 40 : | |||
| 41 : | #include "curl/curl.h" | ||
| 42 : | |||
| 43 : | //static | ||
| 44 : | LLURLSimString LLURLSimString::sInstance; | ||
| 45 : | std::string LLURLSimString::sLocationStringHome("My Home"); | ||
| 46 : | std::string LLURLSimString::sLocationStringLast("My Last Location"); | ||
| 47 : | |||
| 48 : | // "secondlife://simname/x/y/z" -> "simname/x/y/z" | ||
| 49 : | // (actually .*//foo -> foo) | ||
| 50 : | // static | ||
| 51 : | void LLURLSimString::setString(const std::string& sim_string) | ||
| 52 : | { | ||
| 53 : | sInstance.mSimString.clear(); | ||
| 54 : | sInstance.mSimName.clear(); | ||
| 55 : | sInstance.mParseState = NOT_PARSED; | ||
| 56 : | //MK | ||
| 57 : | mjm | 138 | if (gSavedSettings.getBOOL("RestrainedLove")) |
| 58 : | mjm | 135 | { |
| 59 : | return; | ||
| 60 : | } | ||
| 61 : | //mk | ||
| 62 : | if (sim_string == sLocationStringHome) | ||
| 63 : | { | ||
| 64 : | gSavedSettings.setBOOL("LoginLastLocation", FALSE); | ||
| 65 : | } | ||
| 66 : | else if (sim_string == sLocationStringLast) | ||
| 67 : | { | ||
| 68 : | gSavedSettings.setBOOL("LoginLastLocation", TRUE); | ||
| 69 : | } | ||
| 70 : | else | ||
| 71 : | { | ||
| 72 : | char* curlstr = curl_unescape(sim_string.c_str(), sim_string.size()); | ||
| 73 : | std::string tstring = std::string(curlstr); | ||
| 74 : | curl_free(curlstr); | ||
| 75 : | std::string::size_type idx = tstring.find("//"); | ||
| 76 : | idx = (idx == std::string::npos) ? 0 : idx+2; | ||
| 77 : | sInstance.mSimString = tstring.substr(idx); | ||
| 78 : | } | ||
| 79 : | } | ||
| 80 : | |||
| 81 : | // "/100" -> 100 | ||
| 82 : | // static | ||
| 83 : | std::string::size_type LLURLSimString::parseGridIdx(const std::string& in_string, | ||
| 84 : | std::string::size_type idx0, | ||
| 85 : | std::string::size_type* res) | ||
| 86 : | { | ||
| 87 : | if (idx0 == std::string::npos || in_string[idx0] != '/') | ||
| 88 : | { | ||
| 89 : | return std::string::npos; // parse error | ||
| 90 : | } | ||
| 91 : | idx0++; | ||
| 92 : | std::string::size_type idx1 = in_string.find_first_of('/', idx0); | ||
| 93 : | std::string::size_type len = (idx1 == std::string::npos) ? std::string::npos : idx1-idx0; | ||
| 94 : | std::string tstring = in_string.substr(idx0,len); | ||
| 95 : | if (!tstring.empty()) | ||
| 96 : | { | ||
| 97 : | std::string::size_type val = atoi(tstring.c_str()); | ||
| 98 : | *res = val; | ||
| 99 : | } | ||
| 100 : | return idx1; | ||
| 101 : | } | ||
| 102 : | |||
| 103 : | // "simname/x/y/z" -> mSimName = simname, mX = x, mY = y, mZ = z | ||
| 104 : | // static | ||
| 105 : | bool LLURLSimString::parse() | ||
| 106 : | { | ||
| 107 : | if (sInstance.mParseState == NOT_SET) | ||
| 108 : | { | ||
| 109 : | return false; | ||
| 110 : | } | ||
| 111 : | if (sInstance.mParseState == NOT_PARSED) | ||
| 112 : | { | ||
| 113 : | if (parse(sInstance.mSimString, | ||
| 114 : | &sInstance.mSimName, | ||
| 115 : | &sInstance.mX, | ||
| 116 : | &sInstance.mY, | ||
| 117 : | &sInstance.mZ)) | ||
| 118 : | { | ||
| 119 : | sInstance.mParseState = PARSE_OK; | ||
| 120 : | } | ||
| 121 : | else | ||
| 122 : | { | ||
| 123 : | sInstance.mParseState = PARSE_FAIL; | ||
| 124 : | } | ||
| 125 : | } | ||
| 126 : | return (sInstance.mParseState == PARSE_OK); | ||
| 127 : | } | ||
| 128 : | |||
| 129 : | // static | ||
| 130 : | bool LLURLSimString::parse(const std::string& sim_string, | ||
| 131 : | std::string *region_name, | ||
| 132 : | S32 *x, S32 *y, S32 *z) | ||
| 133 : | { | ||
| 134 : | // strip any bogus initial '/' | ||
| 135 : | std::string::size_type idx0 = sim_string.find_first_not_of('/'); | ||
| 136 : | if (idx0 == std::string::npos) idx0 = 0; | ||
| 137 : | |||
| 138 : | std::string::size_type idx1 = sim_string.find_first_of('/', idx0); | ||
| 139 : | std::string::size_type len = (idx1 == std::string::npos) ? std::string::npos : idx1-idx0; | ||
| 140 : | std::string tstring = sim_string.substr(idx0,len); | ||
| 141 : | *region_name = unescapeRegionName(tstring); | ||
| 142 : | if (!region_name->empty()) | ||
| 143 : | { | ||
| 144 : | // return position data if found. otherwise leave passed-in values alone. (DEV-18380) -MG | ||
| 145 : | if (idx1 != std::string::npos) | ||
| 146 : | { | ||
| 147 : | std::string::size_type xs = *x, ys = *y, zs = *z; | ||
| 148 : | idx1 = parseGridIdx(sim_string, idx1, &xs); | ||
| 149 : | idx1 = parseGridIdx(sim_string, idx1, &ys); | ||
| 150 : | idx1 = parseGridIdx(sim_string, idx1, &zs); | ||
| 151 : | *x = xs; | ||
| 152 : | *y = ys; | ||
| 153 : | *z = zs; | ||
| 154 : | } | ||
| 155 : | |||
| 156 : | return true; | ||
| 157 : | } | ||
| 158 : | else | ||
| 159 : | { | ||
| 160 : | return false; | ||
| 161 : | } | ||
| 162 : | } | ||
| 163 : | |||
| 164 : | // static | ||
| 165 : | std::string LLURLSimString::getURL() | ||
| 166 : | { | ||
| 167 : | std::string url; | ||
| 168 : | if (sInstance.mParseState == PARSE_OK) | ||
| 169 : | { | ||
| 170 : | url = llformat("secondlife://%s/%d/%d/%d/", | ||
| 171 : | sInstance.mSimName.c_str(), | ||
| 172 : | sInstance.mX, | ||
| 173 : | sInstance.mY, | ||
| 174 : | sInstance.mZ); | ||
| 175 : | } | ||
| 176 : | return url; | ||
| 177 : | } | ||
| 178 : | |||
| 179 : | // static | ||
| 180 : | std::string LLURLSimString::unescapeRegionName(std::string region_name) | ||
| 181 : | { | ||
| 182 : | std::string result; | ||
| 183 : | char* curlstr = curl_unescape(region_name.c_str(), region_name.size()); | ||
| 184 : | result = std::string(curlstr); | ||
| 185 : | curl_free(curlstr); | ||
| 186 : | return result; | ||
| 187 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

