diff options
Diffstat (limited to 'OpenSim/Framework/SLUtil.cs')
-rw-r--r-- | OpenSim/Framework/SLUtil.cs | 380 |
1 files changed, 380 insertions, 0 deletions
diff --git a/OpenSim/Framework/SLUtil.cs b/OpenSim/Framework/SLUtil.cs new file mode 100644 index 0000000..a489806 --- /dev/null +++ b/OpenSim/Framework/SLUtil.cs | |||
@@ -0,0 +1,380 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using OpenMetaverse; | ||
33 | |||
34 | namespace OpenSim.Framework | ||
35 | { | ||
36 | public static class SLUtil | ||
37 | { | ||
38 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
39 | |||
40 | #region SL / file extension / content-type conversions | ||
41 | |||
42 | public static string SLAssetTypeToContentType(int assetType) | ||
43 | { | ||
44 | switch ((AssetType)assetType) | ||
45 | { | ||
46 | case AssetType.Texture: | ||
47 | return "image/x-j2c"; | ||
48 | case AssetType.Sound: | ||
49 | return "application/ogg"; | ||
50 | case AssetType.CallingCard: | ||
51 | return "application/vnd.ll.callingcard"; | ||
52 | case AssetType.Landmark: | ||
53 | return "application/vnd.ll.landmark"; | ||
54 | case AssetType.Clothing: | ||
55 | return "application/vnd.ll.clothing"; | ||
56 | case AssetType.Object: | ||
57 | return "application/vnd.ll.primitive"; | ||
58 | case AssetType.Notecard: | ||
59 | return "application/vnd.ll.notecard"; | ||
60 | case AssetType.Folder: | ||
61 | return "application/vnd.ll.folder"; | ||
62 | case AssetType.RootFolder: | ||
63 | return "application/vnd.ll.rootfolder"; | ||
64 | case AssetType.LSLText: | ||
65 | return "application/vnd.ll.lsltext"; | ||
66 | case AssetType.LSLBytecode: | ||
67 | return "application/vnd.ll.lslbyte"; | ||
68 | case AssetType.TextureTGA: | ||
69 | case AssetType.ImageTGA: | ||
70 | return "image/tga"; | ||
71 | case AssetType.Bodypart: | ||
72 | return "application/vnd.ll.bodypart"; | ||
73 | case AssetType.TrashFolder: | ||
74 | return "application/vnd.ll.trashfolder"; | ||
75 | case AssetType.SnapshotFolder: | ||
76 | return "application/vnd.ll.snapshotfolder"; | ||
77 | case AssetType.LostAndFoundFolder: | ||
78 | return "application/vnd.ll.lostandfoundfolder"; | ||
79 | case AssetType.SoundWAV: | ||
80 | return "audio/x-wav"; | ||
81 | case AssetType.ImageJPEG: | ||
82 | return "image/jpeg"; | ||
83 | case AssetType.Animation: | ||
84 | return "application/vnd.ll.animation"; | ||
85 | case AssetType.Gesture: | ||
86 | return "application/vnd.ll.gesture"; | ||
87 | case AssetType.Simstate: | ||
88 | return "application/x-metaverse-simstate"; | ||
89 | case AssetType.FavoriteFolder: | ||
90 | return "application/vnd.ll.favoritefolder"; | ||
91 | case AssetType.Link: | ||
92 | return "application/vnd.ll.link"; | ||
93 | case AssetType.LinkFolder: | ||
94 | return "application/vnd.ll.linkfolder"; | ||
95 | case AssetType.CurrentOutfitFolder: | ||
96 | return "application/vnd.ll.currentoutfitfolder"; | ||
97 | case AssetType.OutfitFolder: | ||
98 | return "application/vnd.ll.outfitfolder"; | ||
99 | case AssetType.MyOutfitsFolder: | ||
100 | return "application/vnd.ll.myoutfitsfolder"; | ||
101 | case AssetType.InboxFolder: | ||
102 | return "application/vnd.ll.inboxfolder"; | ||
103 | case AssetType.Unknown: | ||
104 | default: | ||
105 | return "application/octet-stream"; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | public static string SLInvTypeToContentType(int invType) | ||
110 | { | ||
111 | switch ((InventoryType)invType) | ||
112 | { | ||
113 | case InventoryType.Animation: | ||
114 | return "application/vnd.ll.animation"; | ||
115 | case InventoryType.CallingCard: | ||
116 | return "application/vnd.ll.callingcard"; | ||
117 | case InventoryType.Folder: | ||
118 | return "application/vnd.ll.folder"; | ||
119 | case InventoryType.Gesture: | ||
120 | return "application/vnd.ll.gesture"; | ||
121 | case InventoryType.Landmark: | ||
122 | return "application/vnd.ll.landmark"; | ||
123 | case InventoryType.LSL: | ||
124 | return "application/vnd.ll.lsltext"; | ||
125 | case InventoryType.Notecard: | ||
126 | return "application/vnd.ll.notecard"; | ||
127 | case InventoryType.Attachment: | ||
128 | case InventoryType.Object: | ||
129 | return "application/vnd.ll.primitive"; | ||
130 | case InventoryType.Sound: | ||
131 | return "application/ogg"; | ||
132 | case InventoryType.Snapshot: | ||
133 | case InventoryType.Texture: | ||
134 | return "image/x-j2c"; | ||
135 | case InventoryType.Wearable: | ||
136 | return "application/vnd.ll.clothing"; | ||
137 | default: | ||
138 | return "application/octet-stream"; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | public static sbyte ContentTypeToSLAssetType(string contentType) | ||
143 | { | ||
144 | switch (contentType) | ||
145 | { | ||
146 | case "image/x-j2c": | ||
147 | case "image/jp2": | ||
148 | return (sbyte)AssetType.Texture; | ||
149 | case "application/ogg": | ||
150 | return (sbyte)AssetType.Sound; | ||
151 | case "application/vnd.ll.callingcard": | ||
152 | case "application/x-metaverse-callingcard": | ||
153 | return (sbyte)AssetType.CallingCard; | ||
154 | case "application/vnd.ll.landmark": | ||
155 | case "application/x-metaverse-landmark": | ||
156 | return (sbyte)AssetType.Landmark; | ||
157 | case "application/vnd.ll.clothing": | ||
158 | case "application/x-metaverse-clothing": | ||
159 | return (sbyte)AssetType.Clothing; | ||
160 | case "application/vnd.ll.primitive": | ||
161 | case "application/x-metaverse-primitive": | ||
162 | return (sbyte)AssetType.Object; | ||
163 | case "application/vnd.ll.notecard": | ||
164 | case "application/x-metaverse-notecard": | ||
165 | return (sbyte)AssetType.Notecard; | ||
166 | case "application/vnd.ll.folder": | ||
167 | return (sbyte)AssetType.Folder; | ||
168 | case "application/vnd.ll.rootfolder": | ||
169 | return (sbyte)AssetType.RootFolder; | ||
170 | case "application/vnd.ll.lsltext": | ||
171 | case "application/x-metaverse-lsl": | ||
172 | return (sbyte)AssetType.LSLText; | ||
173 | case "application/vnd.ll.lslbyte": | ||
174 | case "application/x-metaverse-lso": | ||
175 | return (sbyte)AssetType.LSLBytecode; | ||
176 | case "image/tga": | ||
177 | // Note that AssetType.TextureTGA will be converted to AssetType.ImageTGA | ||
178 | return (sbyte)AssetType.ImageTGA; | ||
179 | case "application/vnd.ll.bodypart": | ||
180 | case "application/x-metaverse-bodypart": | ||
181 | return (sbyte)AssetType.Bodypart; | ||
182 | case "application/vnd.ll.trashfolder": | ||
183 | return (sbyte)AssetType.TrashFolder; | ||
184 | case "application/vnd.ll.snapshotfolder": | ||
185 | return (sbyte)AssetType.SnapshotFolder; | ||
186 | case "application/vnd.ll.lostandfoundfolder": | ||
187 | return (sbyte)AssetType.LostAndFoundFolder; | ||
188 | case "audio/x-wav": | ||
189 | return (sbyte)AssetType.SoundWAV; | ||
190 | case "image/jpeg": | ||
191 | return (sbyte)AssetType.ImageJPEG; | ||
192 | case "application/vnd.ll.animation": | ||
193 | case "application/x-metaverse-animation": | ||
194 | return (sbyte)AssetType.Animation; | ||
195 | case "application/vnd.ll.gesture": | ||
196 | case "application/x-metaverse-gesture": | ||
197 | return (sbyte)AssetType.Gesture; | ||
198 | case "application/x-metaverse-simstate": | ||
199 | return (sbyte)AssetType.Simstate; | ||
200 | case "application/vnd.ll.favoritefolder": | ||
201 | return (sbyte)AssetType.FavoriteFolder; | ||
202 | case "application/vnd.ll.link": | ||
203 | return (sbyte)AssetType.Link; | ||
204 | case "application/vnd.ll.linkfolder": | ||
205 | return (sbyte)AssetType.LinkFolder; | ||
206 | case "application/vnd.ll.currentoutfitfolder": | ||
207 | return (sbyte)AssetType.CurrentOutfitFolder; | ||
208 | case "application/vnd.ll.outfitfolder": | ||
209 | return (sbyte)AssetType.OutfitFolder; | ||
210 | case "application/vnd.ll.myoutfitsfolder": | ||
211 | return (sbyte)AssetType.MyOutfitsFolder; | ||
212 | case "application/vnd.ll.inboxfolder": | ||
213 | return (sbyte)AssetType.InboxFolder; | ||
214 | case "application/octet-stream": | ||
215 | default: | ||
216 | return (sbyte)AssetType.Unknown; | ||
217 | } | ||
218 | } | ||
219 | |||
220 | public static sbyte ContentTypeToSLInvType(string contentType) | ||
221 | { | ||
222 | switch (contentType) | ||
223 | { | ||
224 | case "image/x-j2c": | ||
225 | case "image/jp2": | ||
226 | case "image/tga": | ||
227 | case "image/jpeg": | ||
228 | return (sbyte)InventoryType.Texture; | ||
229 | case "application/ogg": | ||
230 | case "audio/x-wav": | ||
231 | return (sbyte)InventoryType.Sound; | ||
232 | case "application/vnd.ll.callingcard": | ||
233 | case "application/x-metaverse-callingcard": | ||
234 | return (sbyte)InventoryType.CallingCard; | ||
235 | case "application/vnd.ll.landmark": | ||
236 | case "application/x-metaverse-landmark": | ||
237 | return (sbyte)InventoryType.Landmark; | ||
238 | case "application/vnd.ll.clothing": | ||
239 | case "application/x-metaverse-clothing": | ||
240 | case "application/vnd.ll.bodypart": | ||
241 | case "application/x-metaverse-bodypart": | ||
242 | return (sbyte)InventoryType.Wearable; | ||
243 | case "application/vnd.ll.primitive": | ||
244 | case "application/x-metaverse-primitive": | ||
245 | return (sbyte)InventoryType.Object; | ||
246 | case "application/vnd.ll.notecard": | ||
247 | case "application/x-metaverse-notecard": | ||
248 | return (sbyte)InventoryType.Notecard; | ||
249 | case "application/vnd.ll.folder": | ||
250 | return (sbyte)InventoryType.Folder; | ||
251 | case "application/vnd.ll.rootfolder": | ||
252 | return (sbyte)InventoryType.RootCategory; | ||
253 | case "application/vnd.ll.lsltext": | ||
254 | case "application/x-metaverse-lsl": | ||
255 | case "application/vnd.ll.lslbyte": | ||
256 | case "application/x-metaverse-lso": | ||
257 | return (sbyte)InventoryType.LSL; | ||
258 | case "application/vnd.ll.trashfolder": | ||
259 | case "application/vnd.ll.snapshotfolder": | ||
260 | case "application/vnd.ll.lostandfoundfolder": | ||
261 | return (sbyte)InventoryType.Folder; | ||
262 | case "application/vnd.ll.animation": | ||
263 | case "application/x-metaverse-animation": | ||
264 | return (sbyte)InventoryType.Animation; | ||
265 | case "application/vnd.ll.gesture": | ||
266 | case "application/x-metaverse-gesture": | ||
267 | return (sbyte)InventoryType.Gesture; | ||
268 | case "application/x-metaverse-simstate": | ||
269 | return (sbyte)InventoryType.Snapshot; | ||
270 | case "application/octet-stream": | ||
271 | default: | ||
272 | return (sbyte)InventoryType.Unknown; | ||
273 | } | ||
274 | } | ||
275 | |||
276 | #endregion SL / file extension / content-type conversions | ||
277 | |||
278 | /// <summary> | ||
279 | /// Parse a notecard in Linden format to a string of ordinary text. | ||
280 | /// </summary> | ||
281 | /// <param name="rawInput"></param> | ||
282 | /// <returns></returns> | ||
283 | public static string ParseNotecardToString(string rawInput) | ||
284 | { | ||
285 | string[] output = ParseNotecardToList(rawInput).ToArray(); | ||
286 | |||
287 | // foreach (string line in output) | ||
288 | // m_log.DebugFormat("[PARSE NOTECARD]: ParseNotecardToString got line {0}", line); | ||
289 | |||
290 | return string.Join("\n", output); | ||
291 | } | ||
292 | |||
293 | /// <summary> | ||
294 | /// Parse a notecard in Linden format to a list of ordinary lines. | ||
295 | /// </summary> | ||
296 | /// <param name="rawInput"></param> | ||
297 | /// <returns></returns> | ||
298 | public static List<string> ParseNotecardToList(string rawInput) | ||
299 | { | ||
300 | string[] input = rawInput.Replace("\r", "").Split('\n'); | ||
301 | int idx = 0; | ||
302 | int level = 0; | ||
303 | List<string> output = new List<string>(); | ||
304 | string[] words; | ||
305 | |||
306 | while (idx < input.Length) | ||
307 | { | ||
308 | if (input[idx] == "{") | ||
309 | { | ||
310 | level++; | ||
311 | idx++; | ||
312 | continue; | ||
313 | } | ||
314 | |||
315 | if (input[idx]== "}") | ||
316 | { | ||
317 | level--; | ||
318 | idx++; | ||
319 | continue; | ||
320 | } | ||
321 | |||
322 | switch (level) | ||
323 | { | ||
324 | case 0: | ||
325 | words = input[idx].Split(' '); // Linden text ver | ||
326 | // Notecards are created *really* empty. Treat that as "no text" (just like after saving an empty notecard) | ||
327 | if (words.Length < 3) | ||
328 | return output; | ||
329 | |||
330 | int version = int.Parse(words[3]); | ||
331 | if (version != 2) | ||
332 | return output; | ||
333 | break; | ||
334 | case 1: | ||
335 | words = input[idx].Split(' '); | ||
336 | if (words[0] == "LLEmbeddedItems") | ||
337 | break; | ||
338 | if (words[0] == "Text") | ||
339 | { | ||
340 | int len = int.Parse(words[2]); | ||
341 | idx++; | ||
342 | |||
343 | int count = -1; | ||
344 | |||
345 | while (count < len) | ||
346 | { | ||
347 | // int l = input[idx].Length; | ||
348 | string ln = input[idx]; | ||
349 | |||
350 | int need = len-count-1; | ||
351 | if (ln.Length > need) | ||
352 | ln = ln.Substring(0, need); | ||
353 | |||
354 | // m_log.DebugFormat("[PARSE NOTECARD]: Adding line {0}", ln); | ||
355 | output.Add(ln); | ||
356 | count += ln.Length + 1; | ||
357 | idx++; | ||
358 | } | ||
359 | |||
360 | return output; | ||
361 | } | ||
362 | break; | ||
363 | case 2: | ||
364 | words = input[idx].Split(' '); // count | ||
365 | if (words[0] == "count") | ||
366 | { | ||
367 | int c = int.Parse(words[1]); | ||
368 | if (c > 0) | ||
369 | return output; | ||
370 | break; | ||
371 | } | ||
372 | break; | ||
373 | } | ||
374 | idx++; | ||
375 | } | ||
376 | |||
377 | return output; | ||
378 | } | ||
379 | } | ||
380 | } \ No newline at end of file | ||