aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/SLUtil.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/SLUtil.cs')
-rw-r--r--OpenSim/Framework/SLUtil.cs347
1 files changed, 347 insertions, 0 deletions
diff --git a/OpenSim/Framework/SLUtil.cs b/OpenSim/Framework/SLUtil.cs
new file mode 100644
index 0000000..f6d6a7c
--- /dev/null
+++ b/OpenSim/Framework/SLUtil.cs
@@ -0,0 +1,347 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using log4net;
32using OpenMetaverse;
33
34namespace 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 sbyte ContentTypeToSLAssetType(string contentType)
110 {
111 switch (contentType)
112 {
113 case "image/x-j2c":
114 case "image/jp2":
115 return (sbyte)AssetType.Texture;
116 case "application/ogg":
117 return (sbyte)AssetType.Sound;
118 case "application/vnd.ll.callingcard":
119 case "application/x-metaverse-callingcard":
120 return (sbyte)AssetType.CallingCard;
121 case "application/vnd.ll.landmark":
122 case "application/x-metaverse-landmark":
123 return (sbyte)AssetType.Landmark;
124 case "application/vnd.ll.clothing":
125 case "application/x-metaverse-clothing":
126 return (sbyte)AssetType.Clothing;
127 case "application/vnd.ll.primitive":
128 case "application/x-metaverse-primitive":
129 return (sbyte)AssetType.Object;
130 case "application/vnd.ll.notecard":
131 case "application/x-metaverse-notecard":
132 return (sbyte)AssetType.Notecard;
133 case "application/vnd.ll.folder":
134 return (sbyte)AssetType.Folder;
135 case "application/vnd.ll.rootfolder":
136 return (sbyte)AssetType.RootFolder;
137 case "application/vnd.ll.lsltext":
138 case "application/x-metaverse-lsl":
139 return (sbyte)AssetType.LSLText;
140 case "application/vnd.ll.lslbyte":
141 case "application/x-metaverse-lso":
142 return (sbyte)AssetType.LSLBytecode;
143 case "image/tga":
144 // Note that AssetType.TextureTGA will be converted to AssetType.ImageTGA
145 return (sbyte)AssetType.ImageTGA;
146 case "application/vnd.ll.bodypart":
147 case "application/x-metaverse-bodypart":
148 return (sbyte)AssetType.Bodypart;
149 case "application/vnd.ll.trashfolder":
150 return (sbyte)AssetType.TrashFolder;
151 case "application/vnd.ll.snapshotfolder":
152 return (sbyte)AssetType.SnapshotFolder;
153 case "application/vnd.ll.lostandfoundfolder":
154 return (sbyte)AssetType.LostAndFoundFolder;
155 case "audio/x-wav":
156 return (sbyte)AssetType.SoundWAV;
157 case "image/jpeg":
158 return (sbyte)AssetType.ImageJPEG;
159 case "application/vnd.ll.animation":
160 case "application/x-metaverse-animation":
161 return (sbyte)AssetType.Animation;
162 case "application/vnd.ll.gesture":
163 case "application/x-metaverse-gesture":
164 return (sbyte)AssetType.Gesture;
165 case "application/x-metaverse-simstate":
166 return (sbyte)AssetType.Simstate;
167 case "application/vnd.ll.favoritefolder":
168 return (sbyte)AssetType.FavoriteFolder;
169 case "application/vnd.ll.link":
170 return (sbyte)AssetType.Link;
171 case "application/vnd.ll.linkfolder":
172 return (sbyte)AssetType.LinkFolder;
173 case "application/vnd.ll.currentoutfitfolder":
174 return (sbyte)AssetType.CurrentOutfitFolder;
175 case "application/vnd.ll.outfitfolder":
176 return (sbyte)AssetType.OutfitFolder;
177 case "application/vnd.ll.myoutfitsfolder":
178 return (sbyte)AssetType.MyOutfitsFolder;
179 case "application/vnd.ll.inboxfolder":
180 return (sbyte)AssetType.InboxFolder;
181 case "application/octet-stream":
182 default:
183 return (sbyte)AssetType.Unknown;
184 }
185 }
186
187 public static sbyte ContentTypeToSLInvType(string contentType)
188 {
189 switch (contentType)
190 {
191 case "image/x-j2c":
192 case "image/jp2":
193 case "image/tga":
194 case "image/jpeg":
195 return (sbyte)InventoryType.Texture;
196 case "application/ogg":
197 case "audio/x-wav":
198 return (sbyte)InventoryType.Sound;
199 case "application/vnd.ll.callingcard":
200 case "application/x-metaverse-callingcard":
201 return (sbyte)InventoryType.CallingCard;
202 case "application/vnd.ll.landmark":
203 case "application/x-metaverse-landmark":
204 return (sbyte)InventoryType.Landmark;
205 case "application/vnd.ll.clothing":
206 case "application/x-metaverse-clothing":
207 case "application/vnd.ll.bodypart":
208 case "application/x-metaverse-bodypart":
209 return (sbyte)InventoryType.Wearable;
210 case "application/vnd.ll.primitive":
211 case "application/x-metaverse-primitive":
212 return (sbyte)InventoryType.Object;
213 case "application/vnd.ll.notecard":
214 case "application/x-metaverse-notecard":
215 return (sbyte)InventoryType.Notecard;
216 case "application/vnd.ll.folder":
217 return (sbyte)InventoryType.Folder;
218 case "application/vnd.ll.rootfolder":
219 return (sbyte)InventoryType.RootCategory;
220 case "application/vnd.ll.lsltext":
221 case "application/x-metaverse-lsl":
222 case "application/vnd.ll.lslbyte":
223 case "application/x-metaverse-lso":
224 return (sbyte)InventoryType.LSL;
225 case "application/vnd.ll.trashfolder":
226 case "application/vnd.ll.snapshotfolder":
227 case "application/vnd.ll.lostandfoundfolder":
228 return (sbyte)InventoryType.Folder;
229 case "application/vnd.ll.animation":
230 case "application/x-metaverse-animation":
231 return (sbyte)InventoryType.Animation;
232 case "application/vnd.ll.gesture":
233 case "application/x-metaverse-gesture":
234 return (sbyte)InventoryType.Gesture;
235 case "application/x-metaverse-simstate":
236 return (sbyte)InventoryType.Snapshot;
237 case "application/octet-stream":
238 default:
239 return (sbyte)InventoryType.Unknown;
240 }
241 }
242
243 #endregion SL / file extension / content-type conversions
244
245 /// <summary>
246 /// Parse a notecard in Linden format to a string of ordinary text.
247 /// </summary>
248 /// <param name="rawInput"></param>
249 /// <returns></returns>
250 public static string ParseNotecardToString(string rawInput)
251 {
252 string[] output = ParseNotecardToList(rawInput).ToArray();
253
254// foreach (string line in output)
255// m_log.DebugFormat("[PARSE NOTECARD]: ParseNotecardToString got line {0}", line);
256
257 return string.Join("\n", output);
258 }
259
260 /// <summary>
261 /// Parse a notecard in Linden format to a list of ordinary lines.
262 /// </summary>
263 /// <param name="rawInput"></param>
264 /// <returns></returns>
265 public static List<string> ParseNotecardToList(string rawInput)
266 {
267 string[] input = rawInput.Replace("\r", "").Split('\n');
268 int idx = 0;
269 int level = 0;
270 List<string> output = new List<string>();
271 string[] words;
272
273 while (idx < input.Length)
274 {
275 if (input[idx] == "{")
276 {
277 level++;
278 idx++;
279 continue;
280 }
281
282 if (input[idx]== "}")
283 {
284 level--;
285 idx++;
286 continue;
287 }
288
289 switch (level)
290 {
291 case 0:
292 words = input[idx].Split(' '); // Linden text ver
293 // Notecards are created *really* empty. Treat that as "no text" (just like after saving an empty notecard)
294 if (words.Length < 3)
295 return output;
296
297 int version = int.Parse(words[3]);
298 if (version != 2)
299 return output;
300 break;
301 case 1:
302 words = input[idx].Split(' ');
303 if (words[0] == "LLEmbeddedItems")
304 break;
305 if (words[0] == "Text")
306 {
307 int len = int.Parse(words[2]);
308 idx++;
309
310 int count = -1;
311
312 while (count < len)
313 {
314 // int l = input[idx].Length;
315 string ln = input[idx];
316
317 int need = len-count-1;
318 if (ln.Length > need)
319 ln = ln.Substring(0, need);
320
321// m_log.DebugFormat("[PARSE NOTECARD]: Adding line {0}", ln);
322 output.Add(ln);
323 count += ln.Length + 1;
324 idx++;
325 }
326
327 return output;
328 }
329 break;
330 case 2:
331 words = input[idx].Split(' '); // count
332 if (words[0] == "count")
333 {
334 int c = int.Parse(words[1]);
335 if (c > 0)
336 return output;
337 break;
338 }
339 break;
340 }
341 idx++;
342 }
343
344 return output;
345 }
346 }
347} \ No newline at end of file