Annotation of /trunk/linden/indra/newview/llurl.cpp
Parent Directory
|
Revision Log
Revision 61 - (view) (download)
| 1 : | mjm | 57 | /** |
| 2 : | * @file llurl.cpp | ||
| 3 : | * @brief Text url class | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2001&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | * Copyright (c) 2001-2008, Linden Research, Inc. | ||
| 8 : | * | ||
| 9 : | * Second Life Viewer Source Code | ||
| 10 : | * The source code in this file ("Source Code") is provided by Linden Lab | ||
| 11 : | * to you under the terms of the GNU General Public License, version 2.0 | ||
| 12 : | * ("GPL"), unless you have obtained a separate licensing agreement | ||
| 13 : | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
| 14 : | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
| 15 : | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
| 16 : | * | ||
| 17 : | * There are special exceptions to the terms and conditions of the GPL as | ||
| 18 : | * it is applied to this Source Code. View the full text of the exception | ||
| 19 : | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
| 20 : | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 21 : | * | ||
| 22 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 23 : | * that you have read and understood your obligations described above, | ||
| 24 : | * and agree to abide by those obligations. | ||
| 25 : | * | ||
| 26 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 27 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 28 : | * COMPLETENESS OR PERFORMANCE. | ||
| 29 : | * $/LicenseInfo$ | ||
| 30 : | */ | ||
| 31 : | |||
| 32 : | #include "llviewerprecompiledheaders.h" | ||
| 33 : | #include "llurl.h" | ||
| 34 : | #include "llerror.h" | ||
| 35 : | |||
| 36 : | LLURL::LLURL() | ||
| 37 : | { | ||
| 38 : | init(""); | ||
| 39 : | } | ||
| 40 : | |||
| 41 : | LLURL::LLURL(const LLURL &url) | ||
| 42 : | { | ||
| 43 : | if (this != &url) | ||
| 44 : | { | ||
| 45 : | init(url.getFQURL()); | ||
| 46 : | } | ||
| 47 : | else | ||
| 48 : | { | ||
| 49 : | init(""); | ||
| 50 : | } | ||
| 51 : | } | ||
| 52 : | |||
| 53 : | LLURL::LLURL(const char * url) | ||
| 54 : | { | ||
| 55 : | init(url); | ||
| 56 : | } | ||
| 57 : | |||
| 58 : | LLURL::~LLURL() | ||
| 59 : | { | ||
| 60 : | cleanup(); | ||
| 61 : | } | ||
| 62 : | |||
| 63 : | void LLURL::init(const char * url) | ||
| 64 : | { | ||
| 65 : | mURI[0] = '\0'; | ||
| 66 : | mAuthority[0] = '\0'; | ||
| 67 : | mPath[0] = '\0'; | ||
| 68 : | mFilename[0] = '\0'; | ||
| 69 : | mExtension[0] = '\0'; | ||
| 70 : | mTag[0] = '\0'; | ||
| 71 : | |||
| 72 : | char url_copy[MAX_STRING]; /* Flawfinder: ignore */ | ||
| 73 : | |||
| 74 : | strncpy (url_copy,url, MAX_STRING -1); /* Flawfinder: ignore */ | ||
| 75 : | url_copy[MAX_STRING -1] = '\0'; | ||
| 76 : | |||
| 77 : | char *parse; | ||
| 78 : | char *leftover_url = url_copy; | ||
| 79 : | S32 span = 0; | ||
| 80 : | |||
| 81 : | // copy and lop off tag | ||
| 82 : | if ((parse = strchr(url_copy,'#'))) | ||
| 83 : | { | ||
| 84 : | strncpy(mTag,parse+1, LL_MAX_PATH -1); /* Flawfinder: ignore */ | ||
| 85 : | mTag[LL_MAX_PATH -1] = '\0'; | ||
| 86 : | *parse = '\0'; | ||
| 87 : | } | ||
| 88 : | |||
| 89 : | // copy out URI if it exists, update leftover_url | ||
| 90 : | if ((parse = strchr(url_copy,':'))) | ||
| 91 : | { | ||
| 92 : | *parse = '\0'; | ||
| 93 : | strncpy(mURI,leftover_url, LL_MAX_PATH -1); /* Flawfinder: ignore */ | ||
| 94 : | mURI[LL_MAX_PATH -1] = '\0'; | ||
| 95 : | leftover_url = parse + 1; | ||
| 96 : | } | ||
| 97 : | |||
| 98 : | // copy out authority if it exists, update leftover_url | ||
| 99 : | if ((leftover_url[0] == '/') && (leftover_url[1] == '/')) | ||
| 100 : | { | ||
| 101 : | leftover_url += 2; // skip the "//" | ||
| 102 : | |||
| 103 : | span = strcspn(leftover_url, "/"); | ||
| 104 : | strncat(mAuthority,leftover_url,span); /* Flawfinder: ignore */ | ||
| 105 : | leftover_url += span; | ||
| 106 : | } | ||
| 107 : | |||
| 108 : | if ((parse = strrchr(leftover_url,'.'))) | ||
| 109 : | { | ||
| 110 : | // copy and lop off extension | ||
| 111 : | strncpy(mExtension,parse+1, LL_MAX_PATH -1); /* Flawfinder: ignore */ | ||
| 112 : | mExtension[LL_MAX_PATH -1] = '\0'; | ||
| 113 : | *parse = '\0'; | ||
| 114 : | } | ||
| 115 : | |||
| 116 : | if ((parse = strrchr(leftover_url,'/'))) | ||
| 117 : | { | ||
| 118 : | parse++; | ||
| 119 : | } | ||
| 120 : | else | ||
| 121 : | { | ||
| 122 : | parse = leftover_url; | ||
| 123 : | } | ||
| 124 : | |||
| 125 : | // copy and lop off filename | ||
| 126 : | strncpy(mFilename,parse, LL_MAX_PATH -1);/* Flawfinder: ignore */ | ||
| 127 : | mFilename[LL_MAX_PATH -1] = '\0'; | ||
| 128 : | *parse = '\0'; | ||
| 129 : | |||
| 130 : | // what's left should be the path | ||
| 131 : | strncpy(mPath,leftover_url, LL_MAX_PATH -1); /* Flawfinder: ignore */ | ||
| 132 : | mPath[LL_MAX_PATH -1] = '\0'; | ||
| 133 : | |||
| 134 : | // llinfos << url << " decomposed into: " << llendl; | ||
| 135 : | // llinfos << " URI : <" << mURI << ">" << llendl; | ||
| 136 : | // llinfos << " Auth: <" << mAuthority << ">" << llendl; | ||
| 137 : | // llinfos << " Path: <" << mPath << ">" << llendl; | ||
| 138 : | // llinfos << " File: <" << mFilename << ">" << llendl; | ||
| 139 : | // llinfos << " Ext : <" << mExtension << ">" << llendl; | ||
| 140 : | // llinfos << " Tag : <" << mTag << ">" << llendl; | ||
| 141 : | } | ||
| 142 : | |||
| 143 : | void LLURL::cleanup() | ||
| 144 : | { | ||
| 145 : | } | ||
| 146 : | |||
| 147 : | // Copy assignment | ||
| 148 : | LLURL &LLURL::operator=(const LLURL &rhs) | ||
| 149 : | { | ||
| 150 : | if (this != &rhs) | ||
| 151 : | { | ||
| 152 : | this->init(rhs.getFQURL()); | ||
| 153 : | } | ||
| 154 : | |||
| 155 : | return *this; | ||
| 156 : | } | ||
| 157 : | |||
| 158 : | // Compare | ||
| 159 : | bool LLURL::operator==(const LLURL &rhs) const | ||
| 160 : | { | ||
| 161 : | if ((strcmp(mURI, rhs.mURI)) | ||
| 162 : | || (strcmp(mAuthority, rhs.mAuthority)) | ||
| 163 : | || (strcmp(mPath, rhs.mPath)) | ||
| 164 : | || (strcmp(mFilename, rhs.mFilename)) | ||
| 165 : | || (strcmp(mExtension, rhs.mExtension)) | ||
| 166 : | || (strcmp(mTag, rhs.mTag)) | ||
| 167 : | ) | ||
| 168 : | { | ||
| 169 : | return FALSE; | ||
| 170 : | } | ||
| 171 : | return TRUE; | ||
| 172 : | } | ||
| 173 : | |||
| 174 : | bool LLURL::operator!=(const LLURL& rhs) const | ||
| 175 : | { | ||
| 176 : | return !(*this == rhs); | ||
| 177 : | } | ||
| 178 : | |||
| 179 : | const char * LLURL::getFQURL() const | ||
| 180 : | { | ||
| 181 : | char fqurl[LL_MAX_PATH]; /* Flawfinder: ignore */ | ||
| 182 : | |||
| 183 : | fqurl[0] = '\0'; | ||
| 184 : | |||
| 185 : | if (mURI[0]) | ||
| 186 : | { | ||
| 187 : | strncat(fqurl,mURI, LL_MAX_PATH - strlen(fqurl) -1); /* Flawfinder: ignore */ | ||
| 188 : | strcat(fqurl,":"); /* Flawfinder: ignore */ | ||
| 189 : | if (mAuthority[0]) | ||
| 190 : | { | ||
| 191 : | strcat(fqurl,"//"); /* Flawfinder: ignore */ | ||
| 192 : | } | ||
| 193 : | } | ||
| 194 : | |||
| 195 : | if (mAuthority[0]) | ||
| 196 : | { | ||
| 197 : | strncat(fqurl,mAuthority, LL_MAX_PATH - strlen(fqurl) -1); /* Flawfinder: ignore */ | ||
| 198 : | } | ||
| 199 : | |||
| 200 : | strncat(fqurl,mPath, LL_MAX_PATH - strlen(fqurl) -1); /* Flawfinder: ignore */ | ||
| 201 : | |||
| 202 : | strncat(fqurl,mFilename, LL_MAX_PATH - strlen(fqurl) -1); /* Flawfinder: ignore */ | ||
| 203 : | |||
| 204 : | if (mExtension[0]) | ||
| 205 : | { | ||
| 206 : | strcat(fqurl,"."); /* Flawfinder: ignore */ | ||
| 207 : | strncat(fqurl,mExtension, LL_MAX_PATH - strlen(fqurl) -1); /* Flawfinder: ignore */ | ||
| 208 : | } | ||
| 209 : | |||
| 210 : | if (mTag[0]) | ||
| 211 : | { | ||
| 212 : | strcat(fqurl,"#"); /* Flawfinder: ignore */ | ||
| 213 : | strncat(fqurl,mTag, LL_MAX_PATH - strlen(fqurl) -1); /* Flawfinder: ignore */ | ||
| 214 : | } | ||
| 215 : | |||
| 216 : | strncpy(LLURL::sReturnString,fqurl, LL_MAX_PATH -1); /* Flawfinder: ignore */ | ||
| 217 : | LLURL::sReturnString[LL_MAX_PATH -1] = '\0'; | ||
| 218 : | |||
| 219 : | return(LLURL::sReturnString); | ||
| 220 : | } | ||
| 221 : | |||
| 222 : | |||
| 223 : | const char* LLURL::updateRelativePath(const LLURL &url) | ||
| 224 : | { | ||
| 225 : | char new_path[LL_MAX_PATH]; /* Flawfinder: ignore */ | ||
| 226 : | char tmp_path[LL_MAX_PATH]; /* Flawfinder: ignore */ | ||
| 227 : | |||
| 228 : | char *parse; | ||
| 229 : | |||
| 230 : | if (mPath[0] != '/') | ||
| 231 : | { | ||
| 232 : | //start with existing path | ||
| 233 : | strncpy (new_path,url.mPath, LL_MAX_PATH -1); /* Flawfinder: ignore */ | ||
| 234 : | new_path[LL_MAX_PATH -1] = '\0'; | ||
| 235 : | strncpy (tmp_path,mPath, LL_MAX_PATH -1); /* Flawfinder: ignore */ | ||
| 236 : | tmp_path[LL_MAX_PATH -1] = '\0'; | ||
| 237 : | |||
| 238 : | parse = strtok(tmp_path,"/"); | ||
| 239 : | while (parse) | ||
| 240 : | { | ||
| 241 : | if (!strcmp(parse,".")) | ||
| 242 : | { | ||
| 243 : | // skip this, it's meaningless | ||
| 244 : | } | ||
| 245 : | else if (!strcmp(parse,"..")) | ||
| 246 : | { | ||
| 247 : | if ((parse = strrchr(new_path, '/'))) | ||
| 248 : | { | ||
| 249 : | *parse = '\0'; | ||
| 250 : | if ((parse = strrchr(new_path, '/'))) | ||
| 251 : | { | ||
| 252 : | *(parse+1) = '\0'; | ||
| 253 : | } | ||
| 254 : | else | ||
| 255 : | { | ||
| 256 : | new_path[0] = '\0'; | ||
| 257 : | } | ||
| 258 : | } | ||
| 259 : | else | ||
| 260 : | { | ||
| 261 : | strcat(new_path,"../"); /* Flawfinder: ignore */ | ||
| 262 : | } | ||
| 263 : | |||
| 264 : | } | ||
| 265 : | else | ||
| 266 : | { | ||
| 267 : | strncat(new_path,parse, LL_MAX_PATH - strlen(new_path) -1 ); /* Flawfinder: ignore */ | ||
| 268 : | strcat(new_path,"/"); /* Flawfinder: ignore */ | ||
| 269 : | } | ||
| 270 : | parse = strtok(NULL,"/"); | ||
| 271 : | } | ||
| 272 : | strncpy(mPath,new_path, LL_MAX_PATH -1); /* Flawfinder: ignore */ | ||
| 273 : | mPath[LL_MAX_PATH -1] = '\0'; | ||
| 274 : | } | ||
| 275 : | return mPath; | ||
| 276 : | } | ||
| 277 : | |||
| 278 : | const char * LLURL::getFullPath() | ||
| 279 : | { | ||
| 280 : | strncpy(LLURL::sReturnString,mPath, LL_MAX_PATH -1); /* Flawfinder: ignore */ | ||
| 281 : | LLURL::sReturnString[LL_MAX_PATH -1] = '\0'; | ||
| 282 : | strncat(LLURL::sReturnString,mFilename, LL_MAX_PATH - strlen(LLURL::sReturnString) -1); /* Flawfinder: ignore */ | ||
| 283 : | strcat(LLURL::sReturnString,"."); /* Flawfinder: ignore */ | ||
| 284 : | strncat(LLURL::sReturnString,mExtension, LL_MAX_PATH - strlen(LLURL::sReturnString) -1); /* Flawfinder: ignore */ | ||
| 285 : | return(sReturnString); | ||
| 286 : | } | ||
| 287 : | |||
| 288 : | |||
| 289 : | char LLURL::sReturnString[LL_MAX_PATH] = ""; |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

