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/llinventory/llnotecard.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/llinventory/llnotecard.cpp')
-rw-r--r-- | linden/indra/llinventory/llnotecard.cpp | 305 |
1 files changed, 305 insertions, 0 deletions
diff --git a/linden/indra/llinventory/llnotecard.cpp b/linden/indra/llinventory/llnotecard.cpp new file mode 100644 index 0000000..5f48f0e --- /dev/null +++ b/linden/indra/llinventory/llnotecard.cpp | |||
@@ -0,0 +1,305 @@ | |||
1 | /** | ||
2 | * @file llnotecard.cpp | ||
3 | * @brief LLNotecard class definition | ||
4 | * | ||
5 | * Copyright (c) 2006-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 "linden_common.h" | ||
29 | #include "llinventory.h" | ||
30 | #include "llnotecard.h" | ||
31 | #include "llstreamtools.h" | ||
32 | |||
33 | LLNotecard::LLNotecard(U32 max_text) | ||
34 | : mMaxText(max_text) | ||
35 | { | ||
36 | } | ||
37 | |||
38 | LLNotecard::~LLNotecard() | ||
39 | { | ||
40 | } | ||
41 | |||
42 | bool LLNotecard::importEmbeddedItemsStream(std::istream& str) | ||
43 | { | ||
44 | // Version 1 format: | ||
45 | // LLEmbeddedItems version 1 | ||
46 | // { | ||
47 | // count <number of entries being used and not deleted> | ||
48 | // { | ||
49 | // ext char index <index> | ||
50 | // <InventoryItem chunk> | ||
51 | // } | ||
52 | // } | ||
53 | |||
54 | S32 i; | ||
55 | S32 count = 0; | ||
56 | |||
57 | str >> std::ws >> "LLEmbeddedItems version" >> mEmbeddedVersion >> "\n"; | ||
58 | if (str.fail()) | ||
59 | { | ||
60 | llwarns << "Invalid Linden text file header" << llendl; | ||
61 | goto import_file_failed; | ||
62 | } | ||
63 | |||
64 | if( 1 != mEmbeddedVersion ) | ||
65 | { | ||
66 | llwarns << "Invalid LLEmbeddedItems version: " << mEmbeddedVersion << llendl; | ||
67 | goto import_file_failed; | ||
68 | } | ||
69 | |||
70 | str >> std::ws >> "{\n"; | ||
71 | if(str.fail()) | ||
72 | { | ||
73 | llwarns << "Invalid Linden text file format: missing {" << llendl; | ||
74 | goto import_file_failed; | ||
75 | } | ||
76 | |||
77 | str >> std::ws >> "count " >> count >> "\n"; | ||
78 | if(str.fail()) | ||
79 | { | ||
80 | llwarns << "Invalid LLEmbeddedItems count" << llendl; | ||
81 | goto import_file_failed; | ||
82 | } | ||
83 | |||
84 | if((count < 0)) | ||
85 | { | ||
86 | llwarns << "Invalid LLEmbeddedItems count value: " << count << llendl; | ||
87 | goto import_file_failed; | ||
88 | } | ||
89 | |||
90 | for(i = 0; i < count; i++) | ||
91 | { | ||
92 | str >> std::ws >> "{\n"; | ||
93 | if(str.fail()) | ||
94 | { | ||
95 | llwarns << "Invalid LLEmbeddedItems file format: missing {" << llendl; | ||
96 | goto import_file_failed; | ||
97 | } | ||
98 | |||
99 | U32 index = 0; | ||
100 | str >> std::ws >> "ext char index " >> index >> "\n"; | ||
101 | if(str.fail()) | ||
102 | { | ||
103 | llwarns << "Invalid LLEmbeddedItems file format: missing ext char index" << llendl; | ||
104 | goto import_file_failed; | ||
105 | } | ||
106 | |||
107 | if( (index < 0) ) | ||
108 | { | ||
109 | llwarns << "Invalid LLEmbeddedItems file format: invalid ext char index: " << index << llendl; | ||
110 | goto import_file_failed; | ||
111 | } | ||
112 | |||
113 | str >> std::ws >> "inv_item\t0\n"; | ||
114 | if(str.fail()) | ||
115 | { | ||
116 | llwarns << "Invalid LLEmbeddedItems file format: missing inv_item" << llendl; | ||
117 | goto import_file_failed; | ||
118 | } | ||
119 | |||
120 | LLPointer<LLInventoryItem> item = new LLInventoryItem; | ||
121 | if (!item->importLegacyStream(str)) | ||
122 | { | ||
123 | llinfos << "notecard import failed" << llendl; | ||
124 | goto import_file_failed; | ||
125 | } | ||
126 | mItems.push_back(item); | ||
127 | |||
128 | str >> std::ws >> "}\n"; | ||
129 | if(str.fail()) | ||
130 | { | ||
131 | llwarns << "Invalid LLEmbeddedItems file format: missing }" << llendl; | ||
132 | goto import_file_failed; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | str >> std::ws >> "}\n"; | ||
137 | if(str.fail()) | ||
138 | { | ||
139 | llwarns << "Invalid LLEmbeddedItems file format: missing }" << llendl; | ||
140 | goto import_file_failed; | ||
141 | } | ||
142 | |||
143 | return true; | ||
144 | |||
145 | import_file_failed: | ||
146 | return false; | ||
147 | } | ||
148 | |||
149 | bool LLNotecard::importStream(std::istream& str) | ||
150 | { | ||
151 | // Version 1 format: | ||
152 | // Linden text version 1 | ||
153 | // { | ||
154 | // <EmbeddedItemList chunk> | ||
155 | // Text length | ||
156 | // <ASCII text; 0x80 | index = embedded item> | ||
157 | // } | ||
158 | |||
159 | // Version 2 format: (NOTE: Imports identically to version 1) | ||
160 | // Linden text version 2 | ||
161 | // { | ||
162 | // <EmbeddedItemList chunk> | ||
163 | // Text length | ||
164 | // <UTF8 text; FIRST_EMBEDDED_CHAR + index = embedded item> | ||
165 | // } | ||
166 | |||
167 | str >> std::ws >> "Linden text version " >> mVersion >> "\n"; | ||
168 | if(str.fail()) | ||
169 | { | ||
170 | llwarns << "Invalid Linden text file header " << llendl; | ||
171 | return FALSE; | ||
172 | } | ||
173 | |||
174 | if( 1 != mVersion && 2 != mVersion) | ||
175 | { | ||
176 | llwarns << "Invalid Linden text file version: " << mVersion << llendl; | ||
177 | return FALSE; | ||
178 | } | ||
179 | |||
180 | str >> std::ws >> "{\n"; | ||
181 | if(str.fail()) | ||
182 | { | ||
183 | llwarns << "Invalid Linden text file format" << llendl; | ||
184 | return FALSE; | ||
185 | } | ||
186 | |||
187 | if(!importEmbeddedItemsStream(str)) | ||
188 | { | ||
189 | return FALSE; | ||
190 | } | ||
191 | |||
192 | char line_buf[STD_STRING_BUF_SIZE]; | ||
193 | str.getline(line_buf, STD_STRING_BUF_SIZE); | ||
194 | if(str.fail()) | ||
195 | { | ||
196 | llwarns << "Invalid Linden text length field" << llendl; | ||
197 | return FALSE; | ||
198 | } | ||
199 | line_buf[STD_STRING_STR_LEN] = '\0'; | ||
200 | |||
201 | U32 text_len = 0; | ||
202 | if( 1 != sscanf(line_buf, "Text length %d", &text_len) ) | ||
203 | { | ||
204 | llwarns << "Invalid Linden text length field" << llendl; | ||
205 | return FALSE; | ||
206 | } | ||
207 | |||
208 | if(text_len > mMaxText) | ||
209 | { | ||
210 | llwarns << "Invalid Linden text length: " << text_len << llendl; | ||
211 | return FALSE; | ||
212 | } | ||
213 | |||
214 | BOOL success = TRUE; | ||
215 | |||
216 | char* text = new char[text_len + 1]; | ||
217 | fullread(str, text, text_len); | ||
218 | if(str.fail()) | ||
219 | { | ||
220 | llwarns << "Invalid Linden text: text shorter than text length: " << text_len << llendl; | ||
221 | success = FALSE; | ||
222 | } | ||
223 | text[text_len] = '\0'; | ||
224 | |||
225 | if(success) | ||
226 | { | ||
227 | // Actually set the text | ||
228 | mText = text; | ||
229 | } | ||
230 | |||
231 | delete[] text; | ||
232 | |||
233 | return success; | ||
234 | } | ||
235 | |||
236 | //////////////////////////////////////////////////////////////////////////// | ||
237 | |||
238 | bool LLNotecard::exportEmbeddedItemsStream( std::ostream& out_stream ) | ||
239 | { | ||
240 | out_stream << "LLEmbeddedItems version 1\n"; | ||
241 | out_stream << "{\n"; | ||
242 | |||
243 | out_stream << llformat("count %d\n", mItems.size() ); | ||
244 | |||
245 | S32 idx = 0; | ||
246 | for (std::vector<LLPointer<LLInventoryItem> >::iterator iter = mItems.begin(); | ||
247 | iter != mItems.end(); ++iter) | ||
248 | { | ||
249 | LLInventoryItem* item = *iter; | ||
250 | if (item) | ||
251 | { | ||
252 | out_stream << "{\n"; | ||
253 | out_stream << llformat("ext char index %d\n", idx ); | ||
254 | if( !item->exportLegacyStream( out_stream ) ) | ||
255 | { | ||
256 | return FALSE; | ||
257 | } | ||
258 | out_stream << "}\n"; | ||
259 | } | ||
260 | ++idx; | ||
261 | } | ||
262 | |||
263 | out_stream << "}\n"; | ||
264 | |||
265 | return TRUE; | ||
266 | } | ||
267 | |||
268 | bool LLNotecard::exportStream( std::ostream& out_stream ) | ||
269 | { | ||
270 | out_stream << "Linden text version 2\n"; | ||
271 | out_stream << "{\n"; | ||
272 | |||
273 | if( !exportEmbeddedItemsStream( out_stream ) ) | ||
274 | { | ||
275 | return FALSE; | ||
276 | } | ||
277 | |||
278 | out_stream << llformat("Text length %d\n", mText.length() ); | ||
279 | out_stream << mText; | ||
280 | out_stream << "}\n"; | ||
281 | |||
282 | return TRUE; | ||
283 | } | ||
284 | |||
285 | //////////////////////////////////////////////////////////////////////////// | ||
286 | |||
287 | const std::vector<LLPointer<LLInventoryItem> >& LLNotecard::getItems() const | ||
288 | { | ||
289 | return mItems; | ||
290 | } | ||
291 | |||
292 | LLString& LLNotecard::getText() | ||
293 | { | ||
294 | return mText; | ||
295 | } | ||
296 | |||
297 | void LLNotecard::setItems(const std::vector<LLPointer<LLInventoryItem> >& items) | ||
298 | { | ||
299 | mItems = items; | ||
300 | } | ||
301 | |||
302 | void LLNotecard::setText(const LLString& text) | ||
303 | { | ||
304 | mText = text; | ||
305 | } | ||