aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
diff options
context:
space:
mode:
authorMelanie2013-04-28 19:03:39 +0200
committerMelanie2013-04-28 19:03:39 +0200
commit4275d7a839d7380ee50aeadc38a31dd467bd891e (patch)
tree1e589fc3b448b580d1cc25b52215ef5ce2d7ae78 /OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
parentMerge branch 'ubitwork' of ssh://3dhosting.de/var/git/careminster into ubitwork (diff)
parentController module for dynamic floaters (WIP) (diff)
downloadopensim-SC_OLD-4275d7a839d7380ee50aeadc38a31dd467bd891e.zip
opensim-SC_OLD-4275d7a839d7380ee50aeadc38a31dd467bd891e.tar.gz
opensim-SC_OLD-4275d7a839d7380ee50aeadc38a31dd467bd891e.tar.bz2
opensim-SC_OLD-4275d7a839d7380ee50aeadc38a31dd467bd891e.tar.xz
Merge branch 'avination-current' of ssh://3dhosting.de/var/git/careminster into avination-current
Conflicts: bin/Regions/Regions.ini.example
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs307
1 files changed, 228 insertions, 79 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
index 0c175ca..1bb5aee 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
@@ -39,8 +39,10 @@ using OpenMetaverse.StructuredData;
39using OpenSim.Framework; 39using OpenSim.Framework;
40using OpenSim.Region.Framework.Interfaces; 40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes; 41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.Framework.Scenes.Scripting;
42using System.Collections.Generic; 43using System.Collections.Generic;
43using System.Text.RegularExpressions; 44using System.Text.RegularExpressions;
45using PermissionMask = OpenSim.Framework.PermissionMask;
44 46
45namespace OpenSim.Region.OptionalModules.Scripting.JsonStore 47namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
46{ 48{
@@ -92,12 +94,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
92 } 94 }
93 catch (Exception e) 95 catch (Exception e)
94 { 96 {
95 m_log.ErrorFormat("[JsonStoreScripts] initialization error: {0}",e.Message); 97 m_log.ErrorFormat("[JsonStoreScripts]: initialization error: {0}", e.Message);
96 return; 98 return;
97 } 99 }
98 100
99 if (m_enabled) 101 if (m_enabled)
100 m_log.DebugFormat("[JsonStoreScripts] module is enabled"); 102 m_log.DebugFormat("[JsonStoreScripts]: module is enabled");
101 } 103 }
102 104
103 // ----------------------------------------------------------------- 105 // -----------------------------------------------------------------
@@ -150,7 +152,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
150 m_comms = m_scene.RequestModuleInterface<IScriptModuleComms>(); 152 m_comms = m_scene.RequestModuleInterface<IScriptModuleComms>();
151 if (m_comms == null) 153 if (m_comms == null)
152 { 154 {
153 m_log.ErrorFormat("[JsonStoreScripts] ScriptModuleComms interface not defined"); 155 m_log.ErrorFormat("[JsonStoreScripts]: ScriptModuleComms interface not defined");
154 m_enabled = false; 156 m_enabled = false;
155 return; 157 return;
156 } 158 }
@@ -158,40 +160,20 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
158 m_store = m_scene.RequestModuleInterface<IJsonStoreModule>(); 160 m_store = m_scene.RequestModuleInterface<IJsonStoreModule>();
159 if (m_store == null) 161 if (m_store == null)
160 { 162 {
161 m_log.ErrorFormat("[JsonStoreScripts] JsonModule interface not defined"); 163 m_log.ErrorFormat("[JsonStoreScripts]: JsonModule interface not defined");
162 m_enabled = false; 164 m_enabled = false;
163 return; 165 return;
164 } 166 }
165 167
166 try 168 try
167 { 169 {
168 m_comms.RegisterScriptInvocation(this,"JsonCreateStore"); 170 m_comms.RegisterScriptInvocations(this);
169 m_comms.RegisterScriptInvocation(this,"JsonDestroyStore"); 171 m_comms.RegisterConstants(this);
170
171 m_comms.RegisterScriptInvocation(this,"JsonReadNotecard");
172 m_comms.RegisterScriptInvocation(this,"JsonWriteNotecard");
173
174 m_comms.RegisterScriptInvocation(this,"JsonTestPath");
175 m_comms.RegisterScriptInvocation(this,"JsonTestPathJson");
176
177 m_comms.RegisterScriptInvocation(this,"JsonGetValue");
178 m_comms.RegisterScriptInvocation(this,"JsonGetValueJson");
179
180 m_comms.RegisterScriptInvocation(this,"JsonTakeValue");
181 m_comms.RegisterScriptInvocation(this,"JsonTakeValueJson");
182
183 m_comms.RegisterScriptInvocation(this,"JsonReadValue");
184 m_comms.RegisterScriptInvocation(this,"JsonReadValueJson");
185
186 m_comms.RegisterScriptInvocation(this,"JsonSetValue");
187 m_comms.RegisterScriptInvocation(this,"JsonSetValueJson");
188
189 m_comms.RegisterScriptInvocation(this,"JsonRemoveValue");
190 } 172 }
191 catch (Exception e) 173 catch (Exception e)
192 { 174 {
193 // See http://opensimulator.org/mantis/view.php?id=5971 for more information 175 // See http://opensimulator.org/mantis/view.php?id=5971 for more information
194 m_log.WarnFormat("[JsonStroreScripts] script method registration failed; {0}",e.Message); 176 m_log.WarnFormat("[JsonStoreScripts]: script method registration failed; {0}", e.Message);
195 m_enabled = false; 177 m_enabled = false;
196 } 178 }
197 } 179 }
@@ -208,23 +190,61 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
208 190
209#endregion 191#endregion
210 192
193#region ScriptConstantsInterface
194
195 [ScriptConstant]
196 public static readonly int JSON_NODETYPE_UNDEF = (int)JsonStoreNodeType.Undefined;
197
198 [ScriptConstant]
199 public static readonly int JSON_NODETYPE_OBJECT = (int)JsonStoreNodeType.Object;
200
201 [ScriptConstant]
202 public static readonly int JSON_NODETYPE_ARRAY = (int)JsonStoreNodeType.Array;
203
204 [ScriptConstant]
205 public static readonly int JSON_NODETYPE_VALUE = (int)JsonStoreNodeType.Value;
206
207 [ScriptConstant]
208 public static readonly int JSON_VALUETYPE_UNDEF = (int)JsonStoreValueType.Undefined;
209
210 [ScriptConstant]
211 public static readonly int JSON_VALUETYPE_BOOLEAN = (int)JsonStoreValueType.Boolean;
212
213 [ScriptConstant]
214 public static readonly int JSON_VALUETYPE_INTEGER = (int)JsonStoreValueType.Integer;
215
216 [ScriptConstant]
217 public static readonly int JSON_VALUETYPE_FLOAT = (int)JsonStoreValueType.Float;
218
219 [ScriptConstant]
220 public static readonly int JSON_VALUETYPE_STRING = (int)JsonStoreValueType.String;
221
222
223#endregion
224
211#region ScriptInvocationInteface 225#region ScriptInvocationInteface
212 // ----------------------------------------------------------------- 226 // -----------------------------------------------------------------
213 /// <summary> 227 /// <summary>
214 /// 228 ///
215 /// </summary> 229 /// </summary>
216 // ----------------------------------------------------------------- 230 // -----------------------------------------------------------------
217 protected void GenerateRuntimeError(string msg) 231 [ScriptInvocation]
232 public UUID JsonAttachObjectStore(UUID hostID, UUID scriptID)
218 { 233 {
219 throw new Exception("JsonStore Runtime Error: " + msg); 234 UUID uuid = UUID.Zero;
235 if (! m_store.AttachObjectStore(hostID))
236 GenerateRuntimeError("Failed to create Json store");
237
238 return hostID;
220 } 239 }
221 240
222 // ----------------------------------------------------------------- 241 // -----------------------------------------------------------------
223 /// <summary> 242 /// <summary>
224 /// 243 ///
225 /// </summary> 244 /// </summary>
226 // ----------------------------------------------------------------- 245 // -----------------------------------------------------------------
227 protected UUID JsonCreateStore(UUID hostID, UUID scriptID, string value) 246 [ScriptInvocation]
247 public UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
228 { 248 {
229 UUID uuid = UUID.Zero; 249 UUID uuid = UUID.Zero;
230 if (! m_store.CreateStore(value, ref uuid)) 250 if (! m_store.CreateStore(value, ref uuid))
@@ -238,7 +258,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
238 /// 258 ///
239 /// </summary> 259 /// </summary>
240 // ----------------------------------------------------------------- 260 // -----------------------------------------------------------------
241 protected int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID) 261 [ScriptInvocation]
262 public int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID)
242 { 263 {
243 return m_store.DestroyStore(storeID) ? 1 : 0; 264 return m_store.DestroyStore(storeID) ? 1 : 0;
244 } 265 }
@@ -248,10 +269,22 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
248 /// 269 ///
249 /// </summary> 270 /// </summary>
250 // ----------------------------------------------------------------- 271 // -----------------------------------------------------------------
251 protected UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) 272 [ScriptInvocation]
273 public int JsonTestStore(UUID hostID, UUID scriptID, UUID storeID)
274 {
275 return m_store.TestStore(storeID) ? 1 : 0;
276 }
277
278 // -----------------------------------------------------------------
279 /// <summary>
280 ///
281 /// </summary>
282 // -----------------------------------------------------------------
283 [ScriptInvocation]
284 public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier)
252 { 285 {
253 UUID reqID = UUID.Random(); 286 UUID reqID = UUID.Random();
254 Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); }); 287 Util.FireAndForget(o => DoJsonReadNotecard(reqID, hostID, scriptID, storeID, path, notecardIdentifier));
255 return reqID; 288 return reqID;
256 } 289 }
257 290
@@ -260,7 +293,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
260 /// 293 ///
261 /// </summary> 294 /// </summary>
262 // ----------------------------------------------------------------- 295 // -----------------------------------------------------------------
263 protected UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name) 296 [ScriptInvocation]
297 public UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name)
264 { 298 {
265 UUID reqID = UUID.Random(); 299 UUID reqID = UUID.Random();
266 Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); }); 300 Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); });
@@ -272,14 +306,41 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
272 /// 306 ///
273 /// </summary> 307 /// </summary>
274 // ----------------------------------------------------------------- 308 // -----------------------------------------------------------------
275 protected int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path) 309 [ScriptInvocation]
310 public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist)
276 { 311 {
277 return m_store.TestPath(storeID,path,false) ? 1 : 0; 312 string ipath = ConvertList2Path(pathlist);
313 string opath;
314
315 if (JsonStore.CanonicalPathExpression(ipath,out opath))
316 return opath;
317
318 // This won't parse if passed to the other routines as opposed to
319 // returning an empty string which is a valid path and would overwrite
320 // the entire store
321 return "**INVALID**";
322 }
323
324 // -----------------------------------------------------------------
325 /// <summary>
326 ///
327 /// </summary>
328 // -----------------------------------------------------------------
329 [ScriptInvocation]
330 public int JsonGetNodeType(UUID hostID, UUID scriptID, UUID storeID, string path)
331 {
332 return (int)m_store.GetNodeType(storeID,path);
278 } 333 }
279 334
280 protected int JsonTestPathJson(UUID hostID, UUID scriptID, UUID storeID, string path) 335 // -----------------------------------------------------------------
336 /// <summary>
337 ///
338 /// </summary>
339 // -----------------------------------------------------------------
340 [ScriptInvocation]
341 public int JsonGetValueType(UUID hostID, UUID scriptID, UUID storeID, string path)
281 { 342 {
282 return m_store.TestPath(storeID,path,true) ? 1 : 0; 343 return (int)m_store.GetValueType(storeID,path);
283 } 344 }
284 345
285 // ----------------------------------------------------------------- 346 // -----------------------------------------------------------------
@@ -287,12 +348,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
287 /// 348 ///
288 /// </summary> 349 /// </summary>
289 // ----------------------------------------------------------------- 350 // -----------------------------------------------------------------
290 protected int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value) 351 [ScriptInvocation]
352 public int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
291 { 353 {
292 return m_store.SetValue(storeID,path,value,false) ? 1 : 0; 354 return m_store.SetValue(storeID,path,value,false) ? 1 : 0;
293 } 355 }
294 356
295 protected int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value) 357 [ScriptInvocation]
358 public int JsonSetJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
296 { 359 {
297 return m_store.SetValue(storeID,path,value,true) ? 1 : 0; 360 return m_store.SetValue(storeID,path,value,true) ? 1 : 0;
298 } 361 }
@@ -302,7 +365,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
302 /// 365 ///
303 /// </summary> 366 /// </summary>
304 // ----------------------------------------------------------------- 367 // -----------------------------------------------------------------
305 protected int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path) 368 [ScriptInvocation]
369 public int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path)
306 { 370 {
307 return m_store.RemoveValue(storeID,path) ? 1 : 0; 371 return m_store.RemoveValue(storeID,path) ? 1 : 0;
308 } 372 }
@@ -312,14 +376,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
312 /// 376 ///
313 /// </summary> 377 /// </summary>
314 // ----------------------------------------------------------------- 378 // -----------------------------------------------------------------
315 protected string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path) 379 [ScriptInvocation]
380 public int JsonGetArrayLength(UUID hostID, UUID scriptID, UUID storeID, string path)
381 {
382 return m_store.GetArrayLength(storeID,path);
383 }
384
385 // -----------------------------------------------------------------
386 /// <summary>
387 ///
388 /// </summary>
389 // -----------------------------------------------------------------
390 [ScriptInvocation]
391 public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
316 { 392 {
317 string value = String.Empty; 393 string value = String.Empty;
318 m_store.GetValue(storeID,path,false,out value); 394 m_store.GetValue(storeID,path,false,out value);
319 return value; 395 return value;
320 } 396 }
321 397
322 protected string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 398 [ScriptInvocation]
399 public string JsonGetJson(UUID hostID, UUID scriptID, UUID storeID, string path)
323 { 400 {
324 string value = String.Empty; 401 string value = String.Empty;
325 m_store.GetValue(storeID,path,true, out value); 402 m_store.GetValue(storeID,path,true, out value);
@@ -331,80 +408,105 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
331 /// 408 ///
332 /// </summary> 409 /// </summary>
333 // ----------------------------------------------------------------- 410 // -----------------------------------------------------------------
334 protected UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path) 411 [ScriptInvocation]
412 public UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path)
335 { 413 {
336 UUID reqID = UUID.Random(); 414 UUID reqID = UUID.Random();
337 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); }); 415 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); });
338 return reqID; 416 return reqID;
339 } 417 }
340 418
341 protected UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 419 [ScriptInvocation]
420 public UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
342 { 421 {
343 UUID reqID = UUID.Random(); 422 UUID reqID = UUID.Random();
344 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); }); 423 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); });
345 return reqID; 424 return reqID;
346 } 425 }
347 426
348 private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
349 {
350 try
351 {
352 m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
353 return;
354 }
355 catch (Exception e)
356 {
357 m_log.InfoFormat("[JsonStoreScripts] unable to retrieve value; {0}",e.ToString());
358 }
359
360 DispatchValue(scriptID,reqID,String.Empty);
361 }
362
363
364 // ----------------------------------------------------------------- 427 // -----------------------------------------------------------------
365 /// <summary> 428 /// <summary>
366 /// 429 ///
367 /// </summary> 430 /// </summary>
368 // ----------------------------------------------------------------- 431 // -----------------------------------------------------------------
369 protected UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path) 432 [ScriptInvocation]
433 public UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path)
370 { 434 {
371 UUID reqID = UUID.Random(); 435 UUID reqID = UUID.Random();
372 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); }); 436 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); });
373 return reqID; 437 return reqID;
374 } 438 }
375 439
376 protected UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 440 [ScriptInvocation]
441 public UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
377 { 442 {
378 UUID reqID = UUID.Random(); 443 UUID reqID = UUID.Random();
379 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); }); 444 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); });
380 return reqID; 445 return reqID;
381 } 446 }
382 447
383 private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson) 448#endregion
449
450 // -----------------------------------------------------------------
451 /// <summary>
452 ///
453 /// </summary>
454 // -----------------------------------------------------------------
455 protected void GenerateRuntimeError(string msg)
456 {
457 m_log.InfoFormat("[JsonStore] runtime error: {0}",msg);
458 throw new Exception("JsonStore Runtime Error: " + msg);
459 }
460
461 // -----------------------------------------------------------------
462 /// <summary>
463 ///
464 /// </summary>
465 // -----------------------------------------------------------------
466 protected void DispatchValue(UUID scriptID, UUID reqID, string value)
467 {
468 m_comms.DispatchReply(scriptID,1,value,reqID.ToString());
469 }
470
471 // -----------------------------------------------------------------
472 /// <summary>
473 ///
474 /// </summary>
475 // -----------------------------------------------------------------
476 private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
384 { 477 {
385 try 478 try
386 { 479 {
387 m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); }); 480 m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
388 return; 481 return;
389 } 482 }
390 catch (Exception e) 483 catch (Exception e)
391 { 484 {
392 m_log.InfoFormat("[JsonStoreScripts] unable to retrieve value; {0}",e.ToString()); 485 m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
393 } 486 }
394 487
395 DispatchValue(scriptID,reqID,String.Empty); 488 DispatchValue(scriptID,reqID,String.Empty);
396 } 489 }
397 490
398#endregion
399 491
400 // ----------------------------------------------------------------- 492 // -----------------------------------------------------------------
401 /// <summary> 493 /// <summary>
402 /// 494 ///
403 /// </summary> 495 /// </summary>
404 // ----------------------------------------------------------------- 496 // -----------------------------------------------------------------
405 protected void DispatchValue(UUID scriptID, UUID reqID, string value) 497 private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
406 { 498 {
407 m_comms.DispatchReply(scriptID,1,value,reqID.ToString()); 499 try
500 {
501 m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
502 return;
503 }
504 catch (Exception e)
505 {
506 m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
507 }
508
509 DispatchValue(scriptID,reqID,String.Empty);
408 } 510 }
409 511
410 // ----------------------------------------------------------------- 512 // -----------------------------------------------------------------
@@ -412,31 +514,40 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
412 /// 514 ///
413 /// </summary> 515 /// </summary>
414 // ----------------------------------------------------------------- 516 // -----------------------------------------------------------------
415 private void DoJsonReadNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) 517 private void DoJsonReadNotecard(
518 UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier)
416 { 519 {
520 UUID assetID;
521
522 if (!UUID.TryParse(notecardIdentifier, out assetID))
523 {
524 SceneObjectPart part = m_scene.GetSceneObjectPart(hostID);
525 assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard);
526 }
527
417 AssetBase a = m_scene.AssetService.Get(assetID.ToString()); 528 AssetBase a = m_scene.AssetService.Get(assetID.ToString());
418 if (a == null) 529 if (a == null)
419 GenerateRuntimeError(String.Format("Unable to find notecard asset {0}",assetID)); 530 GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID));
420 531
421 if (a.Type != (sbyte)AssetType.Notecard) 532 if (a.Type != (sbyte)AssetType.Notecard)
422 GenerateRuntimeError(String.Format("Invalid notecard asset {0}",assetID)); 533 GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID));
423 534
424 m_log.DebugFormat("[JsonStoreScripts] read notecard in context {0}",storeID); 535 m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}",storeID);
425 536
426 try 537 try
427 { 538 {
428 string jsondata = SLUtil.ParseNotecardToString(Encoding.UTF8.GetString(a.Data)); 539 string jsondata = SLUtil.ParseNotecardToString(Encoding.UTF8.GetString(a.Data));
429 int result = m_store.SetValue(storeID, path, jsondata,true) ? 1 : 0; 540 int result = m_store.SetValue(storeID, path, jsondata,true) ? 1 : 0;
430 m_comms.DispatchReply(scriptID,result, "", reqID.ToString()); 541 m_comms.DispatchReply(scriptID, result, "", reqID.ToString());
431 return; 542 return;
432 } 543 }
433 catch (Exception e) 544 catch (Exception e)
434 { 545 {
435 m_log.WarnFormat("[JsonStoreScripts] Json parsing failed; {0}",e.Message); 546 m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message);
436 } 547 }
437 548
438 GenerateRuntimeError(String.Format("Json parsing failed for {0}",assetID.ToString())); 549 GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID));
439 m_comms.DispatchReply(scriptID,0,"",reqID.ToString()); 550 m_comms.DispatchReply(scriptID, 0, "", reqID.ToString());
440 } 551 }
441 552
442 // ----------------------------------------------------------------- 553 // -----------------------------------------------------------------
@@ -494,5 +605,43 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
494 605
495 m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString()); 606 m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString());
496 } 607 }
608
609 // -----------------------------------------------------------------
610 /// <summary>
611 /// Convert a list of values that are path components to a single string path
612 /// </summary>
613 // -----------------------------------------------------------------
614 protected static Regex m_ArrayPattern = new Regex("^([0-9]+|\\+)$");
615 private string ConvertList2Path(object[] pathlist)
616 {
617 string path = "";
618 for (int i = 0; i < pathlist.Length; i++)
619 {
620 string token = "";
621
622 if (pathlist[i] is string)
623 {
624 token = pathlist[i].ToString();
625
626 // Check to see if this is a bare number which would not be a valid
627 // identifier otherwise
628 if (m_ArrayPattern.IsMatch(token))
629 token = '[' + token + ']';
630 }
631 else if (pathlist[i] is int)
632 {
633 token = "[" + pathlist[i].ToString() + "]";
634 }
635 else
636 {
637 token = "." + pathlist[i].ToString() + ".";
638 }
639
640 path += token + ".";
641 }
642
643 return path;
644 }
645
497 } 646 }
498} 647}