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