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/llurlwhitelist.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 'linden/indra/newview/llurlwhitelist.cpp')
-rw-r--r-- | linden/indra/newview/llurlwhitelist.cpp | 222 |
1 files changed, 222 insertions, 0 deletions
diff --git a/linden/indra/newview/llurlwhitelist.cpp b/linden/indra/newview/llurlwhitelist.cpp new file mode 100644 index 0000000..8992146 --- /dev/null +++ b/linden/indra/newview/llurlwhitelist.cpp | |||
@@ -0,0 +1,222 @@ | |||
1 | /** | ||
2 | * @file llurlwhitelist.cpp | ||
3 | * @author Callum Prentice | ||
4 | * @brief maintains a "white list" of acceptable URLS that are stored on disk | ||
5 | * | ||
6 | * Copyright (c) 2005-2007, Linden Research, Inc. | ||
7 | * | ||
8 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
9 | * to you under the terms of the GNU General Public License, version 2.0 | ||
10 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
11 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
12 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
13 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
14 | * | ||
15 | * There are special exceptions to the terms and conditions of the GPL as | ||
16 | * it is applied to this Source Code. View the full text of the exception | ||
17 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
18 | * online at http://secondlife.com/developers/opensource/flossexception | ||
19 | * | ||
20 | * By copying, modifying or distributing this software, you acknowledge | ||
21 | * that you have read and understood your obligations described above, | ||
22 | * and agree to abide by those obligations. | ||
23 | * | ||
24 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
25 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
26 | * COMPLETENESS OR PERFORMANCE. | ||
27 | */ | ||
28 | |||
29 | #include "llviewerprecompiledheaders.h" | ||
30 | #include "llurlwhitelist.h" | ||
31 | |||
32 | #include <iostream> | ||
33 | #include <fstream> | ||
34 | |||
35 | LLUrlWhiteList* LLUrlWhiteList::sInstance = 0; | ||
36 | |||
37 | /////////////////////////////////////////////////////////////////////////////// | ||
38 | // | ||
39 | LLUrlWhiteList::LLUrlWhiteList () : | ||
40 | mLoaded ( false ), | ||
41 | mFilename ( "url_whitelist.ini" ), | ||
42 | mUrlList ( 0 ), | ||
43 | mUrlListIter ( 0 ) | ||
44 | { | ||
45 | } | ||
46 | |||
47 | /////////////////////////////////////////////////////////////////////////////// | ||
48 | // | ||
49 | LLUrlWhiteList::~LLUrlWhiteList () | ||
50 | { | ||
51 | } | ||
52 | |||
53 | /////////////////////////////////////////////////////////////////////////////// | ||
54 | |||
55 | //static | ||
56 | void LLUrlWhiteList::initClass () | ||
57 | { | ||
58 | if ( ! sInstance ) | ||
59 | { | ||
60 | sInstance = new LLUrlWhiteList (); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | //static | ||
65 | void LLUrlWhiteList::cleanupClass () | ||
66 | { | ||
67 | delete sInstance; | ||
68 | sInstance = NULL; | ||
69 | } | ||
70 | |||
71 | LLUrlWhiteList* LLUrlWhiteList::getInstance () | ||
72 | { | ||
73 | return sInstance; | ||
74 | } | ||
75 | |||
76 | /////////////////////////////////////////////////////////////////////////////// | ||
77 | // | ||
78 | bool LLUrlWhiteList::load () | ||
79 | { | ||
80 | // don't load if we're already loaded | ||
81 | if ( mLoaded ) | ||
82 | return ( true ); | ||
83 | |||
84 | // remove current entries before we load over them | ||
85 | clear (); | ||
86 | |||
87 | // build filename for each user | ||
88 | LLString resolvedFilename = gDirUtilp->getExpandedFilename ( LL_PATH_PER_SL_ACCOUNT, mFilename.c_str () ); | ||
89 | |||
90 | // open a file for reading | ||
91 | llifstream file ( resolvedFilename.c_str () ); | ||
92 | if ( file.is_open () ) | ||
93 | { | ||
94 | // add each line in the file to the list | ||
95 | std::string line; | ||
96 | while ( std::getline ( file, line ) ) | ||
97 | { | ||
98 | addItem ( line, false ); | ||
99 | }; | ||
100 | |||
101 | file.close (); | ||
102 | |||
103 | // flag as loaded | ||
104 | mLoaded = true; | ||
105 | |||
106 | return true; | ||
107 | }; | ||
108 | |||
109 | return false; | ||
110 | } | ||
111 | |||
112 | /////////////////////////////////////////////////////////////////////////////// | ||
113 | // | ||
114 | bool LLUrlWhiteList::save () | ||
115 | { | ||
116 | // build filename for each user | ||
117 | LLString resolvedFilename = gDirUtilp->getExpandedFilename ( LL_PATH_PER_SL_ACCOUNT, mFilename.c_str () ); | ||
118 | |||
119 | // open a file for writing | ||
120 | llofstream file ( resolvedFilename.c_str () ); | ||
121 | if ( file.is_open () ) | ||
122 | { | ||
123 | // for each entry we have | ||
124 | for ( LLStringListIter iter = mUrlList.begin (); iter != mUrlList.end (); ++iter ) | ||
125 | { | ||
126 | file << ( *iter ) << std::endl; | ||
127 | }; | ||
128 | |||
129 | file.close (); | ||
130 | |||
131 | return true; | ||
132 | }; | ||
133 | |||
134 | return false; | ||
135 | } | ||
136 | |||
137 | /////////////////////////////////////////////////////////////////////////////// | ||
138 | // | ||
139 | bool LLUrlWhiteList::clear () | ||
140 | { | ||
141 | mUrlList.clear (); | ||
142 | |||
143 | // invalidate iterator since we changed the contents | ||
144 | mUrlListIter = mUrlList.end (); | ||
145 | |||
146 | return true; | ||
147 | } | ||
148 | |||
149 | LLString url_cleanup(LLString pattern) | ||
150 | { | ||
151 | LLString::trim(pattern); | ||
152 | S32 length = pattern.length(); | ||
153 | S32 position = 0; | ||
154 | std::string::reverse_iterator it = pattern.rbegin(); | ||
155 | ++it; // skip last char, might be '/' | ||
156 | ++position; | ||
157 | for (; it < pattern.rend(); ++it) | ||
158 | { | ||
159 | char c = *it; | ||
160 | if (c == '/') | ||
161 | { | ||
162 | // found second to last '/' | ||
163 | S32 desired_length = length - position; | ||
164 | LLString::truncate(pattern, desired_length); | ||
165 | break; | ||
166 | } | ||
167 | ++position; | ||
168 | } | ||
169 | return pattern; | ||
170 | } | ||
171 | |||
172 | /////////////////////////////////////////////////////////////////////////////// | ||
173 | // | ||
174 | bool LLUrlWhiteList::addItem ( const LLString& itemIn, bool saveAfterAdd ) | ||
175 | { | ||
176 | LLString item = url_cleanup(itemIn); | ||
177 | |||
178 | mUrlList.insert ( mUrlList.end (), item ); | ||
179 | |||
180 | // use this when all you want to do is call addItem ( ... ) where necessary | ||
181 | if ( saveAfterAdd ) | ||
182 | save (); | ||
183 | |||
184 | return true; | ||
185 | } | ||
186 | |||
187 | /////////////////////////////////////////////////////////////////////////////// | ||
188 | // | ||
189 | bool LLUrlWhiteList::getFirst ( LLString& valueOut ) | ||
190 | { | ||
191 | if ( mUrlList.size () == 0 ) | ||
192 | return false; | ||
193 | |||
194 | mUrlListIter = mUrlList.begin (); | ||
195 | |||
196 | valueOut = * ( mUrlListIter ); | ||
197 | |||
198 | ++mUrlListIter; | ||
199 | |||
200 | return true; | ||
201 | } | ||
202 | |||
203 | /////////////////////////////////////////////////////////////////////////////// | ||
204 | // | ||
205 | bool LLUrlWhiteList::getNext ( LLString& valueOut ) | ||
206 | { | ||
207 | if ( mUrlListIter == mUrlList.end () ) | ||
208 | return false; | ||
209 | |||
210 | valueOut = * ( mUrlListIter ); | ||
211 | |||
212 | ++mUrlListIter; | ||
213 | |||
214 | return true; | ||
215 | } | ||
216 | |||
217 | /////////////////////////////////////////////////////////////////////////////// | ||
218 | // | ||
219 | bool LLUrlWhiteList::containsMatch ( const LLString& patternIn ) | ||
220 | { | ||
221 | return false; | ||
222 | } | ||