aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/OptionalModules/Scripting
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs391
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreCommands.cs195
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs200
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs482
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs900
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs19
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs1
9 files changed, 2013 insertions, 179 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
index 34894ba..c38bb3e 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
@@ -49,7 +49,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
49 private static readonly ILog m_log = 49 private static readonly ILog m_log =
50 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 51
52 private OSD m_ValueStore; 52 protected virtual OSD ValueStore { get; set; }
53 53
54 protected class TakeValueCallbackClass 54 protected class TakeValueCallbackClass
55 { 55 {
@@ -68,42 +68,141 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
68 protected List<TakeValueCallbackClass> m_TakeStore; 68 protected List<TakeValueCallbackClass> m_TakeStore;
69 protected List<TakeValueCallbackClass> m_ReadStore; 69 protected List<TakeValueCallbackClass> m_ReadStore;
70 70
71 // add separators for quoted paths and array references
72 protected static Regex m_ParsePassOne = new Regex("({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])");
71 73
74 // add quotes to bare identifiers which are limited to alphabetic characters
75 protected static Regex m_ParsePassThree = new Regex("(?<!{[^}]*)\\.([a-zA-Z]+)(?=\\.)");
76
77 // remove extra separator characters
78 protected static Regex m_ParsePassFour = new Regex("\\.+");
79
80 // expression used to validate the full path, this is canonical representation
81 protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)*$");
82
83 // expression used to match path components
84 protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])");
85
86 // extract the internals of an array reference
87 protected static Regex m_SimpleArrayPattern = new Regex("^\\[([0-9]+)\\]$");
88 protected static Regex m_ArrayPattern = new Regex("^\\[([0-9]+|\\+)\\]$");
89
90 // extract the internals of a has reference
91 protected static Regex m_HashPattern = new Regex("^{([^}]+)}$");
92
93 // -----------------------------------------------------------------
94 /// <summary>
95 /// This is a simple estimator for the size of the stored data, it
96 /// is not precise, but should be close enough to implement reasonable
97 /// limits on the storage space used
98 /// </summary>
99 // -----------------------------------------------------------------
100 public int StringSpace { get; set; }
101
72 // ----------------------------------------------------------------- 102 // -----------------------------------------------------------------
73 /// <summary> 103 /// <summary>
74 /// 104 ///
75 /// </summary> 105 /// </summary>
76 // ----------------------------------------------------------------- 106 // -----------------------------------------------------------------
77 public JsonStore() : this("") {} 107 public static bool CanonicalPathExpression(string ipath, out string opath)
108 {
109 Stack<string> path;
110 if (! ParsePathExpression(ipath,out path))
111 {
112 opath = "";
113 return false;
114 }
115
116 opath = PathExpressionToKey(path);
117 return true;
118 }
78 119
79 public JsonStore(string value) 120 // -----------------------------------------------------------------
121 /// <summary>
122 ///
123 /// </summary>
124 // -----------------------------------------------------------------
125 public JsonStore()
80 { 126 {
127 StringSpace = 0;
81 m_TakeStore = new List<TakeValueCallbackClass>(); 128 m_TakeStore = new List<TakeValueCallbackClass>();
82 m_ReadStore = new List<TakeValueCallbackClass>(); 129 m_ReadStore = new List<TakeValueCallbackClass>();
83 130 }
131
132 public JsonStore(string value) : this()
133 {
134 // This is going to throw an exception if the value is not
135 // a valid JSON chunk. Calling routines should catch the
136 // exception and handle it appropriately
84 if (String.IsNullOrEmpty(value)) 137 if (String.IsNullOrEmpty(value))
85 m_ValueStore = new OSDMap(); 138 ValueStore = new OSDMap();
86 else 139 else
87 m_ValueStore = OSDParser.DeserializeJson(value); 140 ValueStore = OSDParser.DeserializeJson(value);
88 } 141 }
142
143 // -----------------------------------------------------------------
144 /// <summary>
145 ///
146 /// </summary>
147 // -----------------------------------------------------------------
148 public JsonStoreNodeType GetNodeType(string expr)
149 {
150 Stack<string> path;
151 if (! ParsePathExpression(expr,out path))
152 return JsonStoreNodeType.Undefined;
153
154 OSD result = ProcessPathExpression(ValueStore,path);
89 155
156 if (result == null)
157 return JsonStoreNodeType.Undefined;
158
159 if (result is OSDMap)
160 return JsonStoreNodeType.Object;
161
162 if (result is OSDArray)
163 return JsonStoreNodeType.Array;
164
165 if (OSDBaseType(result.Type))
166 return JsonStoreNodeType.Value;
167
168 return JsonStoreNodeType.Undefined;
169 }
170
90 // ----------------------------------------------------------------- 171 // -----------------------------------------------------------------
91 /// <summary> 172 /// <summary>
92 /// 173 ///
93 /// </summary> 174 /// </summary>
94 // ----------------------------------------------------------------- 175 // -----------------------------------------------------------------
95 public bool TestPath(string expr, bool useJson) 176 public JsonStoreValueType GetValueType(string expr)
96 { 177 {
97 Stack<string> path = ParsePathExpression(expr); 178 Stack<string> path;
98 OSD result = ProcessPathExpression(m_ValueStore,path); 179 if (! ParsePathExpression(expr,out path))
180 return JsonStoreValueType.Undefined;
181
182 OSD result = ProcessPathExpression(ValueStore,path);
99 183
100 if (result == null) 184 if (result == null)
101 return false; 185 return JsonStoreValueType.Undefined;
102 186
103 if (useJson || result.Type == OSDType.String) 187 if (result is OSDMap)
104 return true; 188 return JsonStoreValueType.Undefined;
105 189
106 return false; 190 if (result is OSDArray)
191 return JsonStoreValueType.Undefined;
192
193 if (result is OSDBoolean)
194 return JsonStoreValueType.Boolean;
195
196 if (result is OSDInteger)
197 return JsonStoreValueType.Integer;
198
199 if (result is OSDReal)
200 return JsonStoreValueType.Float;
201
202 if (result is OSDString)
203 return JsonStoreValueType.String;
204
205 return JsonStoreValueType.Undefined;
107 } 206 }
108 207
109 // ----------------------------------------------------------------- 208 // -----------------------------------------------------------------
@@ -111,10 +210,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
111 /// 210 ///
112 /// </summary> 211 /// </summary>
113 // ----------------------------------------------------------------- 212 // -----------------------------------------------------------------
213 public int ArrayLength(string expr)
214 {
215 Stack<string> path;
216 if (! ParsePathExpression(expr,out path))
217 return -1;
218
219 OSD result = ProcessPathExpression(ValueStore,path);
220 if (result != null && result.Type == OSDType.Array)
221 {
222 OSDArray arr = result as OSDArray;
223 return arr.Count;
224 }
225
226 return -1;
227 }
228
229 // -----------------------------------------------------------------
230 /// <summary>
231 ///
232 /// </summary>
233 // -----------------------------------------------------------------
114 public bool GetValue(string expr, out string value, bool useJson) 234 public bool GetValue(string expr, out string value, bool useJson)
115 { 235 {
116 Stack<string> path = ParsePathExpression(expr); 236 Stack<string> path;
117 OSD result = ProcessPathExpression(m_ValueStore,path); 237 if (! ParsePathExpression(expr,out path))
238 {
239 value = "";
240 return false;
241 }
242
243 OSD result = ProcessPathExpression(ValueStore,path);
118 return ConvertOutputValue(result,out value,useJson); 244 return ConvertOutputValue(result,out value,useJson);
119 } 245 }
120 246
@@ -136,7 +262,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
136 // ----------------------------------------------------------------- 262 // -----------------------------------------------------------------
137 public bool SetValue(string expr, string value, bool useJson) 263 public bool SetValue(string expr, string value, bool useJson)
138 { 264 {
139 OSD ovalue = useJson ? OSDParser.DeserializeJson(value) : new OSDString(value); 265 OSD ovalue;
266
267 // One note of caution... if you use an empty string in the
268 // structure it will be assumed to be a default value and will
269 // not be seialized in the json
270
271 if (useJson)
272 {
273 // There doesn't appear to be a good way to determine if the
274 // value is valid Json other than to let the parser crash
275 try
276 {
277 ovalue = OSDParser.DeserializeJson(value);
278 }
279 catch (Exception)
280 {
281 if (value.StartsWith("'") && value.EndsWith("'"))
282 {
283 ovalue = new OSDString(value.Substring(1,value.Length - 2));
284 }
285 else
286 {
287 return false;
288 }
289 }
290 }
291 else
292 {
293 ovalue = new OSDString(value);
294 }
295
140 return SetValueFromExpression(expr,ovalue); 296 return SetValueFromExpression(expr,ovalue);
141 } 297 }
142 298
@@ -147,10 +303,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
147 // ----------------------------------------------------------------- 303 // -----------------------------------------------------------------
148 public bool TakeValue(string expr, bool useJson, TakeValueCallback cback) 304 public bool TakeValue(string expr, bool useJson, TakeValueCallback cback)
149 { 305 {
150 Stack<string> path = ParsePathExpression(expr); 306 Stack<string> path;
307 if (! ParsePathExpression(expr,out path))
308 return false;
309
151 string pexpr = PathExpressionToKey(path); 310 string pexpr = PathExpressionToKey(path);
152 311
153 OSD result = ProcessPathExpression(m_ValueStore,path); 312 OSD result = ProcessPathExpression(ValueStore,path);
154 if (result == null) 313 if (result == null)
155 { 314 {
156 m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); 315 m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback));
@@ -178,10 +337,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
178 // ----------------------------------------------------------------- 337 // -----------------------------------------------------------------
179 public bool ReadValue(string expr, bool useJson, TakeValueCallback cback) 338 public bool ReadValue(string expr, bool useJson, TakeValueCallback cback)
180 { 339 {
181 Stack<string> path = ParsePathExpression(expr); 340 Stack<string> path;
341 if (! ParsePathExpression(expr,out path))
342 return false;
343
182 string pexpr = PathExpressionToKey(path); 344 string pexpr = PathExpressionToKey(path);
183 345
184 OSD result = ProcessPathExpression(m_ValueStore,path); 346 OSD result = ProcessPathExpression(ValueStore,path);
185 if (result == null) 347 if (result == null)
186 { 348 {
187 m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); 349 m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback));
@@ -208,25 +370,30 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
208 // ----------------------------------------------------------------- 370 // -----------------------------------------------------------------
209 protected bool SetValueFromExpression(string expr, OSD ovalue) 371 protected bool SetValueFromExpression(string expr, OSD ovalue)
210 { 372 {
211 Stack<string> path = ParsePathExpression(expr); 373 Stack<string> path;
374 if (! ParsePathExpression(expr,out path))
375 return false;
376
212 if (path.Count == 0) 377 if (path.Count == 0)
213 { 378 {
214 m_ValueStore = ovalue; 379 ValueStore = ovalue;
380 StringSpace = 0;
215 return true; 381 return true;
216 } 382 }
217 383
384 // pkey will be the final element in the path, we pull it out here to make sure
385 // that the assignment works correctly
218 string pkey = path.Pop(); 386 string pkey = path.Pop();
219 string pexpr = PathExpressionToKey(path); 387 string pexpr = PathExpressionToKey(path);
220 if (pexpr != "") 388 if (pexpr != "")
221 pexpr += "."; 389 pexpr += ".";
222 390
223 OSD result = ProcessPathExpression(m_ValueStore,path); 391 OSD result = ProcessPathExpression(ValueStore,path);
224 if (result == null) 392 if (result == null)
225 return false; 393 return false;
226 394
227 Regex aPattern = new Regex("\\[([0-9]+|\\+)\\]"); 395 // Check pkey, the last element in the path, for and extract array references
228 MatchCollection amatches = aPattern.Matches(pkey,0); 396 MatchCollection amatches = m_ArrayPattern.Matches(pkey,0);
229
230 if (amatches.Count > 0) 397 if (amatches.Count > 0)
231 { 398 {
232 if (result.Type != OSDType.Array) 399 if (result.Type != OSDType.Array)
@@ -242,8 +409,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
242 { 409 {
243 string npkey = String.Format("[{0}]",amap.Count); 410 string npkey = String.Format("[{0}]",amap.Count);
244 411
245 amap.Add(ovalue); 412 if (ovalue != null)
246 InvokeNextCallback(pexpr + npkey); 413 {
414 StringSpace += ComputeSizeOf(ovalue);
415
416 amap.Add(ovalue);
417 InvokeNextCallback(pexpr + npkey);
418 }
247 return true; 419 return true;
248 } 420 }
249 421
@@ -251,9 +423,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
251 if (0 <= aval && aval < amap.Count) 423 if (0 <= aval && aval < amap.Count)
252 { 424 {
253 if (ovalue == null) 425 if (ovalue == null)
426 {
427 StringSpace -= ComputeSizeOf(amap[aval]);
254 amap.RemoveAt(aval); 428 amap.RemoveAt(aval);
429 }
255 else 430 else
256 { 431 {
432 StringSpace -= ComputeSizeOf(amap[aval]);
433 StringSpace += ComputeSizeOf(ovalue);
257 amap[aval] = ovalue; 434 amap[aval] = ovalue;
258 InvokeNextCallback(pexpr + pkey); 435 InvokeNextCallback(pexpr + pkey);
259 } 436 }
@@ -263,9 +440,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
263 return false; 440 return false;
264 } 441 }
265 442
266 Regex hPattern = new Regex("{([^}]+)}"); 443 // Check for and extract hash references
267 MatchCollection hmatches = hPattern.Matches(pkey,0); 444 MatchCollection hmatches = m_HashPattern.Matches(pkey,0);
268
269 if (hmatches.Count > 0) 445 if (hmatches.Count > 0)
270 { 446 {
271 Match match = hmatches[0]; 447 Match match = hmatches[0];
@@ -274,16 +450,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
274 450
275 if (result is OSDMap) 451 if (result is OSDMap)
276 { 452 {
453 // this is the assignment case
277 OSDMap hmap = result as OSDMap; 454 OSDMap hmap = result as OSDMap;
278 if (ovalue != null) 455 if (ovalue != null)
279 { 456 {
457 StringSpace -= ComputeSizeOf(hmap[hkey]);
458 StringSpace += ComputeSizeOf(ovalue);
459
280 hmap[hkey] = ovalue; 460 hmap[hkey] = ovalue;
281 InvokeNextCallback(pexpr + pkey); 461 InvokeNextCallback(pexpr + pkey);
462 return true;
282 } 463 }
283 else if (hmap.ContainsKey(hkey)) 464
465 // this is the remove case
466 if (hmap.ContainsKey(hkey))
467 {
468 StringSpace -= ComputeSizeOf(hmap[hkey]);
284 hmap.Remove(hkey); 469 hmap.Remove(hkey);
285 470 return true;
286 return true; 471 }
472
473 return false;
287 } 474 }
288 475
289 return false; 476 return false;
@@ -332,39 +519,33 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
332 /// use a stack because we process the path in inverse order later 519 /// use a stack because we process the path in inverse order later
333 /// </summary> 520 /// </summary>
334 // ----------------------------------------------------------------- 521 // -----------------------------------------------------------------
335 protected static Stack<string> ParsePathExpression(string path) 522 protected static bool ParsePathExpression(string expr, out Stack<string> path)
336 { 523 {
337 Stack<string> m_path = new Stack<string>(); 524 path = new Stack<string>();
338 525
339 // add front and rear separators 526 // add front and rear separators
340 path = "." + path + "."; 527 expr = "." + expr + ".";
341 528
342 // add separators for quoted paths 529 // add separators for quoted exprs and array references
343 Regex pass1 = new Regex("{[^}]+}"); 530 expr = m_ParsePassOne.Replace(expr,".$1.",-1,0);
344 path = pass1.Replace(path,".$0.",-1,0);
345
346 // add separators for array references
347 Regex pass2 = new Regex("(\\[[0-9]+\\]|\\[\\+\\])");
348 path = pass2.Replace(path,".$0.",-1,0);
349 531
350 // add quotes to bare identifier 532 // add quotes to bare identifier
351 Regex pass3 = new Regex("\\.([a-zA-Z]+)"); 533 expr = m_ParsePassThree.Replace(expr,".{$1}",-1,0);
352 path = pass3.Replace(path,".{$1}",-1,0);
353 534
354 // remove extra separators 535 // remove extra separators
355 Regex pass4 = new Regex("\\.+"); 536 expr = m_ParsePassFour.Replace(expr,".",-1,0);
356 path = pass4.Replace(path,".",-1,0);
357 537
358 Regex validate = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)+$"); 538 // validate the results (catches extra quote characters for example)
359 if (validate.IsMatch(path)) 539 if (m_ValidatePath.IsMatch(expr))
360 { 540 {
361 Regex parser = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)"); 541 MatchCollection matches = m_PathComponent.Matches(expr,0);
362 MatchCollection matches = parser.Matches(path,0);
363 foreach (Match match in matches) 542 foreach (Match match in matches)
364 m_path.Push(match.Groups[1].Value); 543 path.Push(match.Groups[1].Value);
544
545 return true;
365 } 546 }
366 547
367 return m_path; 548 return false;
368 } 549 }
369 550
370 // ----------------------------------------------------------------- 551 // -----------------------------------------------------------------
@@ -385,9 +566,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
385 return null; 566 return null;
386 567
387 // ---------- Check for an array index ---------- 568 // ---------- Check for an array index ----------
388 Regex aPattern = new Regex("\\[([0-9]+)\\]"); 569 MatchCollection amatches = m_SimpleArrayPattern.Matches(pkey,0);
389 MatchCollection amatches = aPattern.Matches(pkey,0); 570
390
391 if (amatches.Count > 0) 571 if (amatches.Count > 0)
392 { 572 {
393 if (rmap.Type != OSDType.Array) 573 if (rmap.Type != OSDType.Array)
@@ -410,9 +590,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
410 } 590 }
411 591
412 // ---------- Check for a hash index ---------- 592 // ---------- Check for a hash index ----------
413 Regex hPattern = new Regex("{([^}]+)}"); 593 MatchCollection hmatches = m_HashPattern.Matches(pkey,0);
414 MatchCollection hmatches = hPattern.Matches(pkey,0); 594
415
416 if (hmatches.Count > 0) 595 if (hmatches.Count > 0)
417 { 596 {
418 if (rmap.Type != OSDType.Map) 597 if (rmap.Type != OSDType.Map)
@@ -456,14 +635,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
456 // The path pointed to an intermediate hash structure 635 // The path pointed to an intermediate hash structure
457 if (result.Type == OSDType.Map) 636 if (result.Type == OSDType.Map)
458 { 637 {
459 value = OSDParser.SerializeJsonString(result as OSDMap); 638 value = OSDParser.SerializeJsonString(result as OSDMap,true);
460 return true; 639 return true;
461 } 640 }
462 641
463 // The path pointed to an intermediate hash structure 642 // The path pointed to an intermediate hash structure
464 if (result.Type == OSDType.Array) 643 if (result.Type == OSDType.Array)
465 { 644 {
466 value = OSDParser.SerializeJsonString(result as OSDArray); 645 value = OSDParser.SerializeJsonString(result as OSDArray,true);
467 return true; 646 return true;
468 } 647 }
469 648
@@ -471,7 +650,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
471 return true; 650 return true;
472 } 651 }
473 652
474 if (result.Type == OSDType.String) 653 if (OSDBaseType(result.Type))
475 { 654 {
476 value = result.AsString(); 655 value = result.AsString();
477 return true; 656 return true;
@@ -496,5 +675,91 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
496 675
497 return pkey; 676 return pkey;
498 } 677 }
678
679 // -----------------------------------------------------------------
680 /// <summary>
681 ///
682 /// </summary>
683 // -----------------------------------------------------------------
684 protected static bool OSDBaseType(OSDType type)
685 {
686 // Should be the list of base types for which AsString() returns
687 // something useful
688 if (type == OSDType.Boolean)
689 return true;
690 if (type == OSDType.Integer)
691 return true;
692 if (type == OSDType.Real)
693 return true;
694 if (type == OSDType.String)
695 return true;
696 if (type == OSDType.UUID)
697 return true;
698 if (type == OSDType.Date)
699 return true;
700 if (type == OSDType.URI)
701 return true;
702
703 return false;
704 }
705
706 // -----------------------------------------------------------------
707 /// <summary>
708 ///
709 /// </summary>
710 // -----------------------------------------------------------------
711 protected static int ComputeSizeOf(OSD value)
712 {
713 string sval;
714
715 if (ConvertOutputValue(value,out sval,true))
716 return sval.Length;
717
718 return 0;
719 }
720 }
721
722 // -----------------------------------------------------------------
723 /// <summary>
724 /// </summary>
725 // -----------------------------------------------------------------
726 public class JsonObjectStore : JsonStore
727 {
728 private static readonly ILog m_log =
729 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
730
731 private Scene m_scene;
732 private UUID m_objectID;
733
734 protected override OSD ValueStore
735 {
736 get
737 {
738 SceneObjectPart sop = m_scene.GetSceneObjectPart(m_objectID);
739 if (sop == null)
740 {
741 // This is bad
742 return null;
743 }
744
745 return sop.DynAttrs.TopLevelMap;
746 }
747
748 // cannot set the top level
749 set
750 {
751 m_log.InfoFormat("[JsonStore] cannot set top level value in object store");
752 }
753 }
754
755 public JsonObjectStore(Scene scene, UUID oid) : base()
756 {
757 m_scene = scene;
758 m_objectID = oid;
759
760 // the size limit is imposed on whatever is already in the store
761 StringSpace = ComputeSizeOf(ValueStore);
762 }
499 } 763 }
764
500} 765}
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreCommands.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreCommands.cs
new file mode 100644
index 0000000..d4b19dd
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreCommands.cs
@@ -0,0 +1,195 @@
1/*
2 * Copyright (c) Contributors
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 OpenSim 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 */
27using Mono.Addins;
28
29using System;
30using System.Reflection;
31using System.Threading;
32using System.Text;
33using System.Net;
34using System.Net.Sockets;
35using log4net;
36using Nini.Config;
37using OpenMetaverse;
38using OpenMetaverse.StructuredData;
39using OpenSim.Framework;
40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes;
42using System.Collections.Generic;
43using System.Text.RegularExpressions;
44
45namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
46{
47 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreCommandsModule")]
48
49 public class JsonStoreCommandsModule : INonSharedRegionModule
50 {
51 private static readonly ILog m_log =
52 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53
54 private IConfig m_config = null;
55 private bool m_enabled = false;
56
57 private Scene m_scene = null;
58 //private IJsonStoreModule m_store;
59 private JsonStoreModule m_store;
60
61#region Region Module interface
62
63 // -----------------------------------------------------------------
64 /// <summary>
65 /// Name of this shared module is it's class name
66 /// </summary>
67 // -----------------------------------------------------------------
68 public string Name
69 {
70 get { return this.GetType().Name; }
71 }
72
73 // -----------------------------------------------------------------
74 /// <summary>
75 /// Initialise this shared module
76 /// </summary>
77 /// <param name="scene">this region is getting initialised</param>
78 /// <param name="source">nini config, we are not using this</param>
79 // -----------------------------------------------------------------
80 public void Initialise(IConfigSource config)
81 {
82 try
83 {
84 if ((m_config = config.Configs["JsonStore"]) == null)
85 {
86 // There is no configuration, the module is disabled
87 // m_log.InfoFormat("[JsonStore] no configuration info");
88 return;
89 }
90
91 m_enabled = m_config.GetBoolean("Enabled", m_enabled);
92 }
93 catch (Exception e)
94 {
95 m_log.Error("[JsonStore]: initialization error: {0}", e);
96 return;
97 }
98
99 if (m_enabled)
100 m_log.DebugFormat("[JsonStore]: module is enabled");
101 }
102
103 // -----------------------------------------------------------------
104 /// <summary>
105 /// everything is loaded, perform post load configuration
106 /// </summary>
107 // -----------------------------------------------------------------
108 public void PostInitialise()
109 {
110 }
111
112 // -----------------------------------------------------------------
113 /// <summary>
114 /// Nothing to do on close
115 /// </summary>
116 // -----------------------------------------------------------------
117 public void Close()
118 {
119 }
120
121 // -----------------------------------------------------------------
122 /// <summary>
123 /// </summary>
124 // -----------------------------------------------------------------
125 public void AddRegion(Scene scene)
126 {
127 if (m_enabled)
128 {
129 m_scene = scene;
130
131 }
132 }
133
134 // -----------------------------------------------------------------
135 /// <summary>
136 /// </summary>
137 // -----------------------------------------------------------------
138 public void RemoveRegion(Scene scene)
139 {
140 // need to remove all references to the scene in the subscription
141 // list to enable full garbage collection of the scene object
142 }
143
144 // -----------------------------------------------------------------
145 /// <summary>
146 /// Called when all modules have been added for a region. This is
147 /// where we hook up events
148 /// </summary>
149 // -----------------------------------------------------------------
150 public void RegionLoaded(Scene scene)
151 {
152 if (m_enabled)
153 {
154 m_scene = scene;
155
156 m_store = (JsonStoreModule) m_scene.RequestModuleInterface<IJsonStoreModule>();
157 if (m_store == null)
158 {
159 m_log.ErrorFormat("[JsonStoreCommands]: JsonModule interface not defined");
160 m_enabled = false;
161 return;
162 }
163
164 scene.AddCommand("JsonStore", this, "jsonstore stats", "jsonstore stats",
165 "Display statistics about the state of the JsonStore module", "",
166 CmdStats);
167 }
168 }
169
170 /// -----------------------------------------------------------------
171 /// <summary>
172 /// </summary>
173 // -----------------------------------------------------------------
174 public Type ReplaceableInterface
175 {
176 get { return null; }
177 }
178
179#endregion
180
181#region Commands
182
183 private void CmdStats(string module, string[] cmd)
184 {
185 if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
186 return;
187
188 JsonStoreStats stats = m_store.GetStoreStats();
189 MainConsole.Instance.OutputFormat("{0}\t{1}",m_scene.RegionInfo.RegionName,stats.StoreCount);
190 }
191
192#endregion
193
194 }
195}
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
index e68764a..26044f0 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
@@ -42,7 +42,6 @@ using OpenSim.Region.Framework.Scenes;
42using System.Collections.Generic; 42using System.Collections.Generic;
43using System.Text.RegularExpressions; 43using System.Text.RegularExpressions;
44 44
45
46namespace OpenSim.Region.OptionalModules.Scripting.JsonStore 45namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
47{ 46{
48 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreModule")] 47 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreModule")]
@@ -54,9 +53,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
54 53
55 private IConfig m_config = null; 54 private IConfig m_config = null;
56 private bool m_enabled = false; 55 private bool m_enabled = false;
56 private bool m_enableObjectStore = false;
57 private int m_maxStringSpace = Int32.MaxValue;
58
57 private Scene m_scene = null; 59 private Scene m_scene = null;
58 60
59 private Dictionary<UUID,JsonStore> m_JsonValueStore; 61 private Dictionary<UUID,JsonStore> m_JsonValueStore;
62
60 private UUID m_sharedStore; 63 private UUID m_sharedStore;
61 64
62#region Region Module interface 65#region Region Module interface
@@ -90,15 +93,19 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
90 } 93 }
91 94
92 m_enabled = m_config.GetBoolean("Enabled", m_enabled); 95 m_enabled = m_config.GetBoolean("Enabled", m_enabled);
96 m_enableObjectStore = m_config.GetBoolean("EnableObjectStore", m_enableObjectStore);
97 m_maxStringSpace = m_config.GetInt("MaxStringSpace", m_maxStringSpace);
98 if (m_maxStringSpace == 0)
99 m_maxStringSpace = Int32.MaxValue;
93 } 100 }
94 catch (Exception e) 101 catch (Exception e)
95 { 102 {
96 m_log.ErrorFormat("[JsonStore] initialization error: {0}",e.Message); 103 m_log.Error("[JsonStore]: initialization error: {0}", e);
97 return; 104 return;
98 } 105 }
99 106
100 if (m_enabled) 107 if (m_enabled)
101 m_log.DebugFormat("[JsonStore] module is enabled"); 108 m_log.DebugFormat("[JsonStore]: module is enabled");
102 } 109 }
103 110
104 // ----------------------------------------------------------------- 111 // -----------------------------------------------------------------
@@ -133,6 +140,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
133 m_sharedStore = UUID.Zero; 140 m_sharedStore = UUID.Zero;
134 m_JsonValueStore = new Dictionary<UUID,JsonStore>(); 141 m_JsonValueStore = new Dictionary<UUID,JsonStore>();
135 m_JsonValueStore.Add(m_sharedStore,new JsonStore("")); 142 m_JsonValueStore.Add(m_sharedStore,new JsonStore(""));
143
144 scene.EventManager.OnObjectBeingRemovedFromScene += EventManagerOnObjectBeingRemovedFromScene;
136 } 145 }
137 } 146 }
138 147
@@ -142,6 +151,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
142 // ----------------------------------------------------------------- 151 // -----------------------------------------------------------------
143 public void RemoveRegion(Scene scene) 152 public void RemoveRegion(Scene scene)
144 { 153 {
154 scene.EventManager.OnObjectBeingRemovedFromScene -= EventManagerOnObjectBeingRemovedFromScene;
155
145 // need to remove all references to the scene in the subscription 156 // need to remove all references to the scene in the subscription
146 // list to enable full garbage collection of the scene object 157 // list to enable full garbage collection of the scene object
147 } 158 }
@@ -154,7 +165,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
154 // ----------------------------------------------------------------- 165 // -----------------------------------------------------------------
155 public void RegionLoaded(Scene scene) 166 public void RegionLoaded(Scene scene)
156 { 167 {
157 if (m_enabled) {} 168 if (m_enabled)
169 {
170 }
158 } 171 }
159 172
160 /// ----------------------------------------------------------------- 173 /// -----------------------------------------------------------------
@@ -168,8 +181,68 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
168 181
169#endregion 182#endregion
170 183
184#region SceneEvents
185 // -----------------------------------------------------------------
186 /// <summary>
187 ///
188 /// </summary>
189 // -----------------------------------------------------------------
190 public void EventManagerOnObjectBeingRemovedFromScene(SceneObjectGroup obj)
191 {
192 obj.ForEachPart(delegate(SceneObjectPart sop) { DestroyStore(sop.UUID); } );
193 }
194
195#endregion
196
171#region ScriptInvocationInteface 197#region ScriptInvocationInteface
172 198
199
200 // -----------------------------------------------------------------
201 /// <summary>
202 ///
203 /// </summary>
204 // -----------------------------------------------------------------
205 public JsonStoreStats GetStoreStats()
206 {
207 JsonStoreStats stats;
208
209 lock (m_JsonValueStore)
210 {
211 stats.StoreCount = m_JsonValueStore.Count;
212 }
213
214 return stats;
215 }
216
217 // -----------------------------------------------------------------
218 /// <summary>
219 ///
220 /// </summary>
221 // -----------------------------------------------------------------
222 public bool AttachObjectStore(UUID objectID)
223 {
224 if (! m_enabled) return false;
225 if (! m_enableObjectStore) return false;
226
227 SceneObjectPart sop = m_scene.GetSceneObjectPart(objectID);
228 if (sop == null)
229 {
230 m_log.ErrorFormat("[JsonStore] unable to attach to unknown object; {0}", objectID);
231 return false;
232 }
233
234 lock (m_JsonValueStore)
235 {
236 if (m_JsonValueStore.ContainsKey(objectID))
237 return true;
238
239 JsonStore map = new JsonObjectStore(m_scene,objectID);
240 m_JsonValueStore.Add(objectID,map);
241 }
242
243 return true;
244 }
245
173 // ----------------------------------------------------------------- 246 // -----------------------------------------------------------------
174 /// <summary> 247 /// <summary>
175 /// 248 ///
@@ -189,9 +262,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
189 { 262 {
190 map = new JsonStore(value); 263 map = new JsonStore(value);
191 } 264 }
192 catch (Exception e) 265 catch (Exception)
193 { 266 {
194 m_log.InfoFormat("[JsonStore] Unable to initialize store from {0}; {1}",value,e.Message); 267 m_log.ErrorFormat("[JsonStore]: Unable to initialize store from {0}", value);
195 return false; 268 return false;
196 } 269 }
197 270
@@ -211,9 +284,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
211 if (! m_enabled) return false; 284 if (! m_enabled) return false;
212 285
213 lock (m_JsonValueStore) 286 lock (m_JsonValueStore)
214 m_JsonValueStore.Remove(storeID); 287 return m_JsonValueStore.Remove(storeID);
215
216 return true;
217 } 288 }
218 289
219 // ----------------------------------------------------------------- 290 // -----------------------------------------------------------------
@@ -221,31 +292,76 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
221 /// 292 ///
222 /// </summary> 293 /// </summary>
223 // ----------------------------------------------------------------- 294 // -----------------------------------------------------------------
224 public bool TestPath(UUID storeID, string path, bool useJson) 295 public bool TestStore(UUID storeID)
225 { 296 {
226 if (! m_enabled) return false; 297 if (! m_enabled) return false;
227 298
299 lock (m_JsonValueStore)
300 return m_JsonValueStore.ContainsKey(storeID);
301 }
302
303 // -----------------------------------------------------------------
304 /// <summary>
305 ///
306 /// </summary>
307 // -----------------------------------------------------------------
308 public JsonStoreNodeType GetNodeType(UUID storeID, string path)
309 {
310 if (! m_enabled) return JsonStoreNodeType.Undefined;
311
228 JsonStore map = null; 312 JsonStore map = null;
229 lock (m_JsonValueStore) 313 lock (m_JsonValueStore)
230 { 314 {
231 if (! m_JsonValueStore.TryGetValue(storeID,out map)) 315 if (! m_JsonValueStore.TryGetValue(storeID,out map))
232 { 316 {
233 m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); 317 m_log.InfoFormat("[JsonStore] Missing store {0}",storeID);
234 return false; 318 return JsonStoreNodeType.Undefined;
235 } 319 }
236 } 320 }
237 321
238 try 322 try
239 { 323 {
240 lock (map) 324 lock (map)
241 return map.TestPath(path,useJson); 325 return map.GetNodeType(path);
242 } 326 }
243 catch (Exception e) 327 catch (Exception e)
244 { 328 {
245 m_log.InfoFormat("[JsonStore] Path test failed for {0} in {1}; {2}",path,storeID,e.Message); 329 m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e);
246 } 330 }
247 331
248 return false; 332 return JsonStoreNodeType.Undefined;
333 }
334
335 // -----------------------------------------------------------------
336 /// <summary>
337 ///
338 /// </summary>
339 // -----------------------------------------------------------------
340 public JsonStoreValueType GetValueType(UUID storeID, string path)
341 {
342 if (! m_enabled) return JsonStoreValueType.Undefined;
343
344 JsonStore map = null;
345 lock (m_JsonValueStore)
346 {
347 if (! m_JsonValueStore.TryGetValue(storeID,out map))
348 {
349 m_log.InfoFormat("[JsonStore] Missing store {0}",storeID);
350 return JsonStoreValueType.Undefined;
351 }
352 }
353
354 try
355 {
356 lock (map)
357 return map.GetValueType(path);
358 }
359 catch (Exception e)
360 {
361 m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e);
362 }
363
364 return JsonStoreValueType.Undefined;
249 } 365 }
250 366
251 // ----------------------------------------------------------------- 367 // -----------------------------------------------------------------
@@ -270,12 +386,20 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
270 try 386 try
271 { 387 {
272 lock (map) 388 lock (map)
273 if (map.SetValue(path,value,useJson)) 389 {
274 return true; 390 if (map.StringSpace > m_maxStringSpace)
391 {
392 m_log.WarnFormat("[JsonStore] {0} exceeded string size; {1} bytes used of {2} limit",
393 storeID,map.StringSpace,m_maxStringSpace);
394 return false;
395 }
396
397 return map.SetValue(path,value,useJson);
398 }
275 } 399 }
276 catch (Exception e) 400 catch (Exception e)
277 { 401 {
278 m_log.InfoFormat("[JsonStore] Unable to assign {0} to {1} in {2}; {3}",value,path,storeID,e.Message); 402 m_log.Error(string.Format("[JsonStore]: Unable to assign {0} to {1} in {2}", value, path, storeID), e);
279 } 403 }
280 404
281 return false; 405 return false;
@@ -303,12 +427,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
303 try 427 try
304 { 428 {
305 lock (map) 429 lock (map)
306 if (map.RemoveValue(path)) 430 return map.RemoveValue(path);
307 return true;
308 } 431 }
309 catch (Exception e) 432 catch (Exception e)
310 { 433 {
311 m_log.InfoFormat("[JsonStore] Unable to remove {0} in {1}; {2}",path,storeID,e.Message); 434 m_log.Error(string.Format("[JsonStore]: Unable to remove {0} in {1}", path, storeID), e);
312 } 435 }
313 436
314 return false; 437 return false;
@@ -319,6 +442,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
319 /// 442 ///
320 /// </summary> 443 /// </summary>
321 // ----------------------------------------------------------------- 444 // -----------------------------------------------------------------
445 public int GetArrayLength(UUID storeID, string path)
446 {
447 if (! m_enabled) return -1;
448
449 JsonStore map = null;
450 lock (m_JsonValueStore)
451 {
452 if (! m_JsonValueStore.TryGetValue(storeID,out map))
453 return -1;
454 }
455
456 try
457 {
458 lock (map)
459 {
460 return map.ArrayLength(path);
461 }
462 }
463 catch (Exception e)
464 {
465 m_log.Error("[JsonStore]: unable to retrieve value", e);
466 }
467
468 return -1;
469 }
470
471 // -----------------------------------------------------------------
472 /// <summary>
473 ///
474 /// </summary>
475 // -----------------------------------------------------------------
322 public bool GetValue(UUID storeID, string path, bool useJson, out string value) 476 public bool GetValue(UUID storeID, string path, bool useJson, out string value)
323 { 477 {
324 value = String.Empty; 478 value = String.Empty;
@@ -341,7 +495,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
341 } 495 }
342 catch (Exception e) 496 catch (Exception e)
343 { 497 {
344 m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.Message); 498 m_log.Error("[JsonStore]: unable to retrieve value", e);
345 } 499 }
346 500
347 return false; 501 return false;
@@ -380,7 +534,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
380 } 534 }
381 catch (Exception e) 535 catch (Exception e)
382 { 536 {
383 m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString()); 537 m_log.Error("[JsonStore] unable to retrieve value", e);
384 } 538 }
385 539
386 cback(String.Empty); 540 cback(String.Empty);
@@ -419,7 +573,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
419 } 573 }
420 catch (Exception e) 574 catch (Exception e)
421 { 575 {
422 m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString()); 576 m_log.Error("[JsonStore]: unable to retrieve value", e);
423 } 577 }
424 578
425 cback(String.Empty); 579 cback(String.Empty);
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
index 0c175ca..edf51a2 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{
@@ -57,7 +59,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
57 59
58 private IScriptModuleComms m_comms; 60 private IScriptModuleComms m_comms;
59 private IJsonStoreModule m_store; 61 private IJsonStoreModule m_store;
60 62
63 private Dictionary<UUID,HashSet<UUID>> m_scriptStores = new Dictionary<UUID,HashSet<UUID>>();
64
61#region Region Module interface 65#region Region Module interface
62 66
63 // ----------------------------------------------------------------- 67 // -----------------------------------------------------------------
@@ -92,12 +96,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
92 } 96 }
93 catch (Exception e) 97 catch (Exception e)
94 { 98 {
95 m_log.ErrorFormat("[JsonStoreScripts] initialization error: {0}",e.Message); 99 m_log.ErrorFormat("[JsonStoreScripts]: initialization error: {0}", e.Message);
96 return; 100 return;
97 } 101 }
98 102
99 if (m_enabled) 103 if (m_enabled)
100 m_log.DebugFormat("[JsonStoreScripts] module is enabled"); 104 m_log.DebugFormat("[JsonStoreScripts]: module is enabled");
101 } 105 }
102 106
103 // ----------------------------------------------------------------- 107 // -----------------------------------------------------------------
@@ -124,6 +128,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
124 // ----------------------------------------------------------------- 128 // -----------------------------------------------------------------
125 public void AddRegion(Scene scene) 129 public void AddRegion(Scene scene)
126 { 130 {
131 scene.EventManager.OnScriptReset += HandleScriptReset;
132 scene.EventManager.OnRemoveScript += HandleScriptReset;
127 } 133 }
128 134
129 // ----------------------------------------------------------------- 135 // -----------------------------------------------------------------
@@ -132,12 +138,34 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
132 // ----------------------------------------------------------------- 138 // -----------------------------------------------------------------
133 public void RemoveRegion(Scene scene) 139 public void RemoveRegion(Scene scene)
134 { 140 {
141 scene.EventManager.OnScriptReset -= HandleScriptReset;
142 scene.EventManager.OnRemoveScript -= HandleScriptReset;
143
135 // need to remove all references to the scene in the subscription 144 // need to remove all references to the scene in the subscription
136 // list to enable full garbage collection of the scene object 145 // list to enable full garbage collection of the scene object
137 } 146 }
138 147
139 // ----------------------------------------------------------------- 148 // -----------------------------------------------------------------
140 /// <summary> 149 /// <summary>
150 /// </summary>
151 // -----------------------------------------------------------------
152 private void HandleScriptReset(uint localID, UUID itemID)
153 {
154 HashSet<UUID> stores;
155
156 lock (m_scriptStores)
157 {
158 if (! m_scriptStores.TryGetValue(itemID, out stores))
159 return;
160 m_scriptStores.Remove(itemID);
161 }
162
163 foreach (UUID id in stores)
164 m_store.DestroyStore(id);
165 }
166
167 // -----------------------------------------------------------------
168 /// <summary>
141 /// Called when all modules have been added for a region. This is 169 /// Called when all modules have been added for a region. This is
142 /// where we hook up events 170 /// where we hook up events
143 /// </summary> 171 /// </summary>
@@ -150,7 +178,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
150 m_comms = m_scene.RequestModuleInterface<IScriptModuleComms>(); 178 m_comms = m_scene.RequestModuleInterface<IScriptModuleComms>();
151 if (m_comms == null) 179 if (m_comms == null)
152 { 180 {
153 m_log.ErrorFormat("[JsonStoreScripts] ScriptModuleComms interface not defined"); 181 m_log.ErrorFormat("[JsonStoreScripts]: ScriptModuleComms interface not defined");
154 m_enabled = false; 182 m_enabled = false;
155 return; 183 return;
156 } 184 }
@@ -158,40 +186,20 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
158 m_store = m_scene.RequestModuleInterface<IJsonStoreModule>(); 186 m_store = m_scene.RequestModuleInterface<IJsonStoreModule>();
159 if (m_store == null) 187 if (m_store == null)
160 { 188 {
161 m_log.ErrorFormat("[JsonStoreScripts] JsonModule interface not defined"); 189 m_log.ErrorFormat("[JsonStoreScripts]: JsonModule interface not defined");
162 m_enabled = false; 190 m_enabled = false;
163 return; 191 return;
164 } 192 }
165 193
166 try 194 try
167 { 195 {
168 m_comms.RegisterScriptInvocation(this,"JsonCreateStore"); 196 m_comms.RegisterScriptInvocations(this);
169 m_comms.RegisterScriptInvocation(this,"JsonDestroyStore"); 197 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 } 198 }
191 catch (Exception e) 199 catch (Exception e)
192 { 200 {
193 // See http://opensimulator.org/mantis/view.php?id=5971 for more information 201 // See http://opensimulator.org/mantis/view.php?id=5971 for more information
194 m_log.WarnFormat("[JsonStroreScripts] script method registration failed; {0}",e.Message); 202 m_log.WarnFormat("[JsonStoreScripts]: script method registration failed; {0}", e.Message);
195 m_enabled = false; 203 m_enabled = false;
196 } 204 }
197 } 205 }
@@ -208,28 +216,73 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
208 216
209#endregion 217#endregion
210 218
219#region ScriptConstantsInterface
220
221 [ScriptConstant]
222 public static readonly int JSON_NODETYPE_UNDEF = (int)JsonStoreNodeType.Undefined;
223
224 [ScriptConstant]
225 public static readonly int JSON_NODETYPE_OBJECT = (int)JsonStoreNodeType.Object;
226
227 [ScriptConstant]
228 public static readonly int JSON_NODETYPE_ARRAY = (int)JsonStoreNodeType.Array;
229
230 [ScriptConstant]
231 public static readonly int JSON_NODETYPE_VALUE = (int)JsonStoreNodeType.Value;
232
233 [ScriptConstant]
234 public static readonly int JSON_VALUETYPE_UNDEF = (int)JsonStoreValueType.Undefined;
235
236 [ScriptConstant]
237 public static readonly int JSON_VALUETYPE_BOOLEAN = (int)JsonStoreValueType.Boolean;
238
239 [ScriptConstant]
240 public static readonly int JSON_VALUETYPE_INTEGER = (int)JsonStoreValueType.Integer;
241
242 [ScriptConstant]
243 public static readonly int JSON_VALUETYPE_FLOAT = (int)JsonStoreValueType.Float;
244
245 [ScriptConstant]
246 public static readonly int JSON_VALUETYPE_STRING = (int)JsonStoreValueType.String;
247
248
249#endregion
250
211#region ScriptInvocationInteface 251#region ScriptInvocationInteface
212 // ----------------------------------------------------------------- 252 // -----------------------------------------------------------------
213 /// <summary> 253 /// <summary>
214 /// 254 ///
215 /// </summary> 255 /// </summary>
216 // ----------------------------------------------------------------- 256 // -----------------------------------------------------------------
217 protected void GenerateRuntimeError(string msg) 257 [ScriptInvocation]
258 public UUID JsonAttachObjectStore(UUID hostID, UUID scriptID)
218 { 259 {
219 throw new Exception("JsonStore Runtime Error: " + msg); 260 UUID uuid = UUID.Zero;
261 if (! m_store.AttachObjectStore(hostID))
262 GenerateRuntimeError("Failed to create Json store");
263
264 return hostID;
220 } 265 }
221 266
222 // ----------------------------------------------------------------- 267 // -----------------------------------------------------------------
223 /// <summary> 268 /// <summary>
224 /// 269 ///
225 /// </summary> 270 /// </summary>
226 // ----------------------------------------------------------------- 271 // -----------------------------------------------------------------
227 protected UUID JsonCreateStore(UUID hostID, UUID scriptID, string value) 272 [ScriptInvocation]
273 public UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
228 { 274 {
229 UUID uuid = UUID.Zero; 275 UUID uuid = UUID.Zero;
230 if (! m_store.CreateStore(value, ref uuid)) 276 if (! m_store.CreateStore(value, ref uuid))
231 GenerateRuntimeError("Failed to create Json store"); 277 GenerateRuntimeError("Failed to create Json store");
232 278
279 lock (m_scriptStores)
280 {
281 if (! m_scriptStores.ContainsKey(scriptID))
282 m_scriptStores[scriptID] = new HashSet<UUID>();
283
284 m_scriptStores[scriptID].Add(uuid);
285 }
233 return uuid; 286 return uuid;
234 } 287 }
235 288
@@ -238,8 +291,15 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
238 /// 291 ///
239 /// </summary> 292 /// </summary>
240 // ----------------------------------------------------------------- 293 // -----------------------------------------------------------------
241 protected int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID) 294 [ScriptInvocation]
295 public int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID)
242 { 296 {
297 lock(m_scriptStores)
298 {
299 if (m_scriptStores.ContainsKey(scriptID))
300 m_scriptStores[scriptID].Remove(storeID);
301 }
302
243 return m_store.DestroyStore(storeID) ? 1 : 0; 303 return m_store.DestroyStore(storeID) ? 1 : 0;
244 } 304 }
245 305
@@ -248,10 +308,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
248 /// 308 ///
249 /// </summary> 309 /// </summary>
250 // ----------------------------------------------------------------- 310 // -----------------------------------------------------------------
251 protected UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) 311 [ScriptInvocation]
312 public int JsonTestStore(UUID hostID, UUID scriptID, UUID storeID)
313 {
314 return m_store.TestStore(storeID) ? 1 : 0;
315 }
316
317 // -----------------------------------------------------------------
318 /// <summary>
319 ///
320 /// </summary>
321 // -----------------------------------------------------------------
322 [ScriptInvocation]
323 public UUID JsonRezAtRoot(UUID hostID, UUID scriptID, string item, Vector3 pos, Vector3 vel, Quaternion rot, string param)
324 {
325 UUID reqID = UUID.Random();
326 Util.FireAndForget(
327 o => DoJsonRezObject(hostID, scriptID, reqID, item, pos, vel, rot, param), null, "JsonStoreScriptModule.DoJsonRezObject");
328 return reqID;
329 }
330
331 // -----------------------------------------------------------------
332 /// <summary>
333 ///
334 /// </summary>
335 // -----------------------------------------------------------------
336 [ScriptInvocation]
337 public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier)
252 { 338 {
253 UUID reqID = UUID.Random(); 339 UUID reqID = UUID.Random();
254 Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); }); 340 Util.FireAndForget(
341 o => DoJsonReadNotecard(reqID, hostID, scriptID, storeID, path, notecardIdentifier), null, "JsonStoreScriptModule.JsonReadNotecard");
255 return reqID; 342 return reqID;
256 } 343 }
257 344
@@ -260,10 +347,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
260 /// 347 ///
261 /// </summary> 348 /// </summary>
262 // ----------------------------------------------------------------- 349 // -----------------------------------------------------------------
263 protected UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name) 350 [ScriptInvocation]
351 public UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name)
264 { 352 {
265 UUID reqID = UUID.Random(); 353 UUID reqID = UUID.Random();
266 Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); }); 354 Util.FireAndForget(
355 o => DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name), null, "JsonStoreScriptModule.DoJsonWriteNotecard");
267 return reqID; 356 return reqID;
268 } 357 }
269 358
@@ -272,14 +361,41 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
272 /// 361 ///
273 /// </summary> 362 /// </summary>
274 // ----------------------------------------------------------------- 363 // -----------------------------------------------------------------
275 protected int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path) 364 [ScriptInvocation]
365 public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist)
366 {
367 string ipath = ConvertList2Path(pathlist);
368 string opath;
369
370 if (JsonStore.CanonicalPathExpression(ipath,out opath))
371 return opath;
372
373 // This won't parse if passed to the other routines as opposed to
374 // returning an empty string which is a valid path and would overwrite
375 // the entire store
376 return "**INVALID**";
377 }
378
379 // -----------------------------------------------------------------
380 /// <summary>
381 ///
382 /// </summary>
383 // -----------------------------------------------------------------
384 [ScriptInvocation]
385 public int JsonGetNodeType(UUID hostID, UUID scriptID, UUID storeID, string path)
276 { 386 {
277 return m_store.TestPath(storeID,path,false) ? 1 : 0; 387 return (int)m_store.GetNodeType(storeID,path);
278 } 388 }
279 389
280 protected int JsonTestPathJson(UUID hostID, UUID scriptID, UUID storeID, string path) 390 // -----------------------------------------------------------------
391 /// <summary>
392 ///
393 /// </summary>
394 // -----------------------------------------------------------------
395 [ScriptInvocation]
396 public int JsonGetValueType(UUID hostID, UUID scriptID, UUID storeID, string path)
281 { 397 {
282 return m_store.TestPath(storeID,path,true) ? 1 : 0; 398 return (int)m_store.GetValueType(storeID,path);
283 } 399 }
284 400
285 // ----------------------------------------------------------------- 401 // -----------------------------------------------------------------
@@ -287,12 +403,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
287 /// 403 ///
288 /// </summary> 404 /// </summary>
289 // ----------------------------------------------------------------- 405 // -----------------------------------------------------------------
290 protected int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value) 406 [ScriptInvocation]
407 public int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
291 { 408 {
292 return m_store.SetValue(storeID,path,value,false) ? 1 : 0; 409 return m_store.SetValue(storeID,path,value,false) ? 1 : 0;
293 } 410 }
294 411
295 protected int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value) 412 [ScriptInvocation]
413 public int JsonSetJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
296 { 414 {
297 return m_store.SetValue(storeID,path,value,true) ? 1 : 0; 415 return m_store.SetValue(storeID,path,value,true) ? 1 : 0;
298 } 416 }
@@ -302,7 +420,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
302 /// 420 ///
303 /// </summary> 421 /// </summary>
304 // ----------------------------------------------------------------- 422 // -----------------------------------------------------------------
305 protected int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path) 423 [ScriptInvocation]
424 public int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path)
306 { 425 {
307 return m_store.RemoveValue(storeID,path) ? 1 : 0; 426 return m_store.RemoveValue(storeID,path) ? 1 : 0;
308 } 427 }
@@ -312,14 +431,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
312 /// 431 ///
313 /// </summary> 432 /// </summary>
314 // ----------------------------------------------------------------- 433 // -----------------------------------------------------------------
315 protected string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path) 434 [ScriptInvocation]
435 public int JsonGetArrayLength(UUID hostID, UUID scriptID, UUID storeID, string path)
436 {
437 return m_store.GetArrayLength(storeID,path);
438 }
439
440 // -----------------------------------------------------------------
441 /// <summary>
442 ///
443 /// </summary>
444 // -----------------------------------------------------------------
445 [ScriptInvocation]
446 public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
316 { 447 {
317 string value = String.Empty; 448 string value = String.Empty;
318 m_store.GetValue(storeID,path,false,out value); 449 m_store.GetValue(storeID,path,false,out value);
319 return value; 450 return value;
320 } 451 }
321 452
322 protected string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 453 [ScriptInvocation]
454 public string JsonGetJson(UUID hostID, UUID scriptID, UUID storeID, string path)
323 { 455 {
324 string value = String.Empty; 456 string value = String.Empty;
325 m_store.GetValue(storeID,path,true, out value); 457 m_store.GetValue(storeID,path,true, out value);
@@ -331,80 +463,109 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
331 /// 463 ///
332 /// </summary> 464 /// </summary>
333 // ----------------------------------------------------------------- 465 // -----------------------------------------------------------------
334 protected UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path) 466 [ScriptInvocation]
467 public UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path)
335 { 468 {
336 UUID reqID = UUID.Random(); 469 UUID reqID = UUID.Random();
337 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); }); 470 Util.FireAndForget(
471 o => DoJsonTakeValue(scriptID,reqID,storeID,path,false), null, "JsonStoreScriptModule.DoJsonTakeValue");
338 return reqID; 472 return reqID;
339 } 473 }
340 474
341 protected UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 475 [ScriptInvocation]
476 public UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
342 { 477 {
343 UUID reqID = UUID.Random(); 478 UUID reqID = UUID.Random();
344 Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); }); 479 Util.FireAndForget(
480 o => DoJsonTakeValue(scriptID,reqID,storeID,path,true), null, "JsonStoreScriptModule.DoJsonTakeValueJson");
345 return reqID; 481 return reqID;
346 } 482 }
347 483
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 // ----------------------------------------------------------------- 484 // -----------------------------------------------------------------
365 /// <summary> 485 /// <summary>
366 /// 486 ///
367 /// </summary> 487 /// </summary>
368 // ----------------------------------------------------------------- 488 // -----------------------------------------------------------------
369 protected UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path) 489 [ScriptInvocation]
490 public UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path)
370 { 491 {
371 UUID reqID = UUID.Random(); 492 UUID reqID = UUID.Random();
372 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); }); 493 Util.FireAndForget(
494 o => DoJsonReadValue(scriptID,reqID,storeID,path,false), null, "JsonStoreScriptModule.DoJsonReadValue");
373 return reqID; 495 return reqID;
374 } 496 }
375 497
376 protected UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 498 [ScriptInvocation]
499 public UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
377 { 500 {
378 UUID reqID = UUID.Random(); 501 UUID reqID = UUID.Random();
379 Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); }); 502 Util.FireAndForget(
503 o => DoJsonReadValue(scriptID,reqID,storeID,path,true), null, "JsonStoreScriptModule.DoJsonReadValueJson");
380 return reqID; 504 return reqID;
381 } 505 }
382 506
383 private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson) 507#endregion
508
509 // -----------------------------------------------------------------
510 /// <summary>
511 ///
512 /// </summary>
513 // -----------------------------------------------------------------
514 protected void GenerateRuntimeError(string msg)
515 {
516 m_log.InfoFormat("[JsonStore] runtime error: {0}",msg);
517 throw new Exception("JsonStore Runtime Error: " + msg);
518 }
519
520 // -----------------------------------------------------------------
521 /// <summary>
522 ///
523 /// </summary>
524 // -----------------------------------------------------------------
525 protected void DispatchValue(UUID scriptID, UUID reqID, string value)
526 {
527 m_comms.DispatchReply(scriptID,1,value,reqID.ToString());
528 }
529
530 // -----------------------------------------------------------------
531 /// <summary>
532 ///
533 /// </summary>
534 // -----------------------------------------------------------------
535 private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
384 { 536 {
385 try 537 try
386 { 538 {
387 m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); }); 539 m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
388 return; 540 return;
389 } 541 }
390 catch (Exception e) 542 catch (Exception e)
391 { 543 {
392 m_log.InfoFormat("[JsonStoreScripts] unable to retrieve value; {0}",e.ToString()); 544 m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
393 } 545 }
394 546
395 DispatchValue(scriptID,reqID,String.Empty); 547 DispatchValue(scriptID,reqID,String.Empty);
396 } 548 }
397 549
398#endregion
399 550
400 // ----------------------------------------------------------------- 551 // -----------------------------------------------------------------
401 /// <summary> 552 /// <summary>
402 /// 553 ///
403 /// </summary> 554 /// </summary>
404 // ----------------------------------------------------------------- 555 // -----------------------------------------------------------------
405 protected void DispatchValue(UUID scriptID, UUID reqID, string value) 556 private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
406 { 557 {
407 m_comms.DispatchReply(scriptID,1,value,reqID.ToString()); 558 try
559 {
560 m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
561 return;
562 }
563 catch (Exception e)
564 {
565 m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
566 }
567
568 DispatchValue(scriptID,reqID,String.Empty);
408 } 569 }
409 570
410 // ----------------------------------------------------------------- 571 // -----------------------------------------------------------------
@@ -412,31 +573,44 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
412 /// 573 ///
413 /// </summary> 574 /// </summary>
414 // ----------------------------------------------------------------- 575 // -----------------------------------------------------------------
415 private void DoJsonReadNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) 576 private void DoJsonReadNotecard(
577 UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier)
416 { 578 {
579 UUID assetID;
580
581 if (!UUID.TryParse(notecardIdentifier, out assetID))
582 {
583 SceneObjectPart part = m_scene.GetSceneObjectPart(hostID);
584 assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard);
585 }
586
417 AssetBase a = m_scene.AssetService.Get(assetID.ToString()); 587 AssetBase a = m_scene.AssetService.Get(assetID.ToString());
418 if (a == null) 588 if (a == null)
419 GenerateRuntimeError(String.Format("Unable to find notecard asset {0}",assetID)); 589 GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID));
420 590
421 if (a.Type != (sbyte)AssetType.Notecard) 591 if (a.Type != (sbyte)AssetType.Notecard)
422 GenerateRuntimeError(String.Format("Invalid notecard asset {0}",assetID)); 592 GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID));
423 593
424 m_log.DebugFormat("[JsonStoreScripts] read notecard in context {0}",storeID); 594 m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}",storeID);
425 595
426 try 596 try
427 { 597 {
428 string jsondata = SLUtil.ParseNotecardToString(Encoding.UTF8.GetString(a.Data)); 598 string jsondata = SLUtil.ParseNotecardToString(a.Data);
429 int result = m_store.SetValue(storeID, path, jsondata,true) ? 1 : 0; 599 int result = m_store.SetValue(storeID, path, jsondata,true) ? 1 : 0;
430 m_comms.DispatchReply(scriptID,result, "", reqID.ToString()); 600 m_comms.DispatchReply(scriptID, result, "", reqID.ToString());
431 return; 601 return;
432 } 602 }
603 catch(SLUtil.NotANotecardFormatException e)
604 {
605 m_log.WarnFormat("[JsonStoreScripts]: Notecard parsing failed; assetId {0} at line number {1}", assetID.ToString(), e.lineNumber);
606 }
433 catch (Exception e) 607 catch (Exception e)
434 { 608 {
435 m_log.WarnFormat("[JsonStoreScripts] Json parsing failed; {0}",e.Message); 609 m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message);
436 } 610 }
437 611
438 GenerateRuntimeError(String.Format("Json parsing failed for {0}",assetID.ToString())); 612 GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID));
439 m_comms.DispatchReply(scriptID,0,"",reqID.ToString()); 613 m_comms.DispatchReply(scriptID, 0, "", reqID.ToString());
440 } 614 }
441 615
442 // ----------------------------------------------------------------- 616 // -----------------------------------------------------------------
@@ -494,5 +668,141 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
494 668
495 m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString()); 669 m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString());
496 } 670 }
671
672 // -----------------------------------------------------------------
673 /// <summary>
674 /// Convert a list of values that are path components to a single string path
675 /// </summary>
676 // -----------------------------------------------------------------
677 protected static Regex m_ArrayPattern = new Regex("^([0-9]+|\\+)$");
678 private string ConvertList2Path(object[] pathlist)
679 {
680 string path = "";
681 for (int i = 0; i < pathlist.Length; i++)
682 {
683 string token = "";
684
685 if (pathlist[i] is string)
686 {
687 token = pathlist[i].ToString();
688
689 // Check to see if this is a bare number which would not be a valid
690 // identifier otherwise
691 if (m_ArrayPattern.IsMatch(token))
692 token = '[' + token + ']';
693 }
694 else if (pathlist[i] is int)
695 {
696 token = "[" + pathlist[i].ToString() + "]";
697 }
698 else
699 {
700 token = "." + pathlist[i].ToString() + ".";
701 }
702
703 path += token + ".";
704 }
705
706 return path;
707 }
708
709 // -----------------------------------------------------------------
710 /// <summary>
711 ///
712 /// </summary>
713 // -----------------------------------------------------------------
714 private void DoJsonRezObject(UUID hostID, UUID scriptID, UUID reqID, string name, Vector3 pos, Vector3 vel, Quaternion rot, string param)
715 {
716 if (Double.IsNaN(rot.X) || Double.IsNaN(rot.Y) || Double.IsNaN(rot.Z) || Double.IsNaN(rot.W))
717 {
718 GenerateRuntimeError("Invalid rez rotation");
719 return;
720 }
721
722 SceneObjectGroup host = m_scene.GetSceneObjectGroup(hostID);
723 if (host == null)
724 {
725 GenerateRuntimeError(String.Format("Unable to find rezzing host '{0}'",hostID));
726 return;
727 }
728
729 // hpos = host.RootPart.GetWorldPosition()
730 // float dist = (float)llVecDist(hpos, pos);
731 // if (dist > m_ScriptDistanceFactor * 10.0f)
732 // return;
733
734 TaskInventoryItem item = host.RootPart.Inventory.GetInventoryItem(name);
735 if (item == null)
736 {
737 GenerateRuntimeError(String.Format("Unable to find object to rez '{0}'",name));
738 return;
739 }
740
741 if (item.InvType != (int)InventoryType.Object)
742 {
743 GenerateRuntimeError("Can't create requested object; object is missing from database");
744 return;
745 }
746
747 List<SceneObjectGroup> objlist;
748 List<Vector3> veclist;
749
750 bool success = host.RootPart.Inventory.GetRezReadySceneObjects(item, out objlist, out veclist);
751 if (! success)
752 {
753 GenerateRuntimeError("Failed to create object");
754 return;
755 }
756
757 int totalPrims = 0;
758 foreach (SceneObjectGroup group in objlist)
759 totalPrims += group.PrimCount;
760
761 if (! m_scene.Permissions.CanRezObject(totalPrims, item.OwnerID, pos))
762 {
763 GenerateRuntimeError("Not allowed to create the object");
764 return;
765 }
766
767 if (! m_scene.Permissions.BypassPermissions())
768 {
769 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
770 host.RootPart.Inventory.RemoveInventoryItem(item.ItemID);
771 }
772
773 for (int i = 0; i < objlist.Count; i++)
774 {
775 SceneObjectGroup group = objlist[i];
776 Vector3 curpos = pos + veclist[i];
777
778 if (group.IsAttachment == false && group.RootPart.Shape.State != 0)
779 {
780 group.RootPart.AttachedPos = group.AbsolutePosition;
781 group.RootPart.Shape.LastAttachPoint = (byte)group.AttachmentPoint;
782 }
783
784 group.FromPartID = host.RootPart.UUID;
785 m_scene.AddNewSceneObject(group, true, curpos, rot, vel);
786
787 UUID storeID = group.UUID;
788 if (! m_store.CreateStore(param, ref storeID))
789 {
790 GenerateRuntimeError("Unable to create jsonstore for new object");
791 continue;
792 }
793
794 // We can only call this after adding the scene object, since the scene object references the scene
795 // to find out if scripts should be activated at all.
796 group.RootPart.SetDieAtEdge(true);
797 group.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 3);
798 group.ResumeScripts();
799
800 group.ScheduleGroupForFullUpdate();
801
802 // send the reply back to the host object, use the integer param to indicate the number
803 // of remaining objects
804 m_comms.DispatchReply(scriptID, objlist.Count-i-1, group.RootPart.UUID.ToString(), reqID.ToString());
805 }
806 }
497 } 807 }
498} 808}
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
new file mode 100644
index 0000000..99a7076
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
@@ -0,0 +1,900 @@
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 System.Text;
32using log4net;
33using Nini.Config;
34using NUnit.Framework;
35using OpenMetaverse;
36using OpenSim.Framework;
37using OpenSim.Region.CoreModules.Scripting.ScriptModuleComms;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Region.ScriptEngine.Shared;
40using OpenSim.Region.ScriptEngine.Shared.Api;
41using OpenSim.Services.Interfaces;
42using OpenSim.Tests.Common;
43
44namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
45{
46 /// <summary>
47 /// Tests for inventory functions in LSL
48 /// </summary>
49 [TestFixture]
50 public class JsonStoreScriptModuleTests : OpenSimTestCase
51 {
52 private Scene m_scene;
53 private MockScriptEngine m_engine;
54 private ScriptModuleCommsModule m_smcm;
55 private JsonStoreScriptModule m_jssm;
56
57 [TestFixtureSetUp]
58 public void FixtureInit()
59 {
60 // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
61 Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
62 }
63
64 [TestFixtureTearDown]
65 public void TearDown()
66 {
67 // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
68 // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
69 // tests really shouldn't).
70 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
71 }
72
73 [SetUp]
74 public override void SetUp()
75 {
76 base.SetUp();
77
78 IConfigSource configSource = new IniConfigSource();
79 IConfig jsonStoreConfig = configSource.AddConfig("JsonStore");
80 jsonStoreConfig.Set("Enabled", "true");
81
82 m_engine = new MockScriptEngine();
83 m_smcm = new ScriptModuleCommsModule();
84 JsonStoreModule jsm = new JsonStoreModule();
85 m_jssm = new JsonStoreScriptModule();
86
87 m_scene = new SceneHelpers().SetupScene();
88 SceneHelpers.SetupSceneModules(m_scene, configSource, m_engine, m_smcm, jsm, m_jssm);
89
90 try
91 {
92 m_smcm.RegisterScriptInvocation(this, "DummyTestMethod");
93 }
94 catch (ArgumentException)
95 {
96 Assert.Ignore("Ignoring test since running on .NET 3.5 or earlier.");
97 }
98
99 // XXX: Unfortunately, ICommsModule currently has no way of deregistering methods.
100 }
101
102 private object InvokeOp(string name, params object[] args)
103 {
104 return InvokeOpOnHost(name, UUID.Zero, args);
105 }
106
107 private object InvokeOpOnHost(string name, UUID hostId, params object[] args)
108 {
109 return m_smcm.InvokeOperation(hostId, UUID.Zero, name, args);
110 }
111
112 [Test]
113 public void TestJsonCreateStore()
114 {
115 TestHelpers.InMethod();
116// TestHelpers.EnableLogging();
117
118 // Test blank store
119 {
120 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
121 Assert.That(storeId, Is.Not.EqualTo(UUID.Zero));
122 }
123
124 // Test single element store
125 {
126 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }");
127 Assert.That(storeId, Is.Not.EqualTo(UUID.Zero));
128 }
129
130 // Test with an integer value
131 {
132 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 42.15 }");
133 Assert.That(storeId, Is.Not.EqualTo(UUID.Zero));
134
135 string value = (string)InvokeOp("JsonGetValue", storeId, "Hello");
136 Assert.That(value, Is.EqualTo("42.15"));
137 }
138
139 // Test with an array as the root node
140 {
141 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "[ 'one', 'two', 'three' ]");
142 Assert.That(storeId, Is.Not.EqualTo(UUID.Zero));
143
144 string value = (string)InvokeOp("JsonGetValue", storeId, "[1]");
145 Assert.That(value, Is.EqualTo("two"));
146 }
147 }
148
149 [Test]
150 public void TestJsonDestroyStore()
151 {
152 TestHelpers.InMethod();
153// TestHelpers.EnableLogging();
154
155 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }");
156 int dsrv = (int)InvokeOp("JsonDestroyStore", storeId);
157
158 Assert.That(dsrv, Is.EqualTo(1));
159
160 int tprv = (int)InvokeOp("JsonGetNodeType", storeId, "Hello");
161 Assert.That(tprv, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF));
162 }
163
164 [Test]
165 public void TestJsonDestroyStoreNotExists()
166 {
167 TestHelpers.InMethod();
168// TestHelpers.EnableLogging();
169
170 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
171
172 int dsrv = (int)InvokeOp("JsonDestroyStore", fakeStoreId);
173
174 Assert.That(dsrv, Is.EqualTo(0));
175 }
176
177 [Test]
178 public void TestJsonGetValue()
179 {
180 TestHelpers.InMethod();
181// TestHelpers.EnableLogging();
182
183 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'Two' } }");
184
185 {
186 string value = (string)InvokeOp("JsonGetValue", storeId, "Hello.World");
187 Assert.That(value, Is.EqualTo("Two"));
188 }
189
190 // Test get of path section instead of leaf
191 {
192 string value = (string)InvokeOp("JsonGetValue", storeId, "Hello");
193 Assert.That(value, Is.EqualTo(""));
194 }
195
196 // Test get of non-existing value
197 {
198 string fakeValueGet = (string)InvokeOp("JsonGetValue", storeId, "foo");
199 Assert.That(fakeValueGet, Is.EqualTo(""));
200 }
201
202 // Test get from non-existing store
203 {
204 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
205 string fakeStoreValueGet = (string)InvokeOp("JsonGetValue", fakeStoreId, "Hello");
206 Assert.That(fakeStoreValueGet, Is.EqualTo(""));
207 }
208 }
209
210 [Test]
211 public void TestJsonGetJson()
212 {
213 TestHelpers.InMethod();
214// TestHelpers.EnableLogging();
215
216 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'Two' } }");
217
218 {
219 string value = (string)InvokeOp("JsonGetJson", storeId, "Hello.World");
220 Assert.That(value, Is.EqualTo("'Two'"));
221 }
222
223 // Test get of path section instead of leaf
224 {
225 string value = (string)InvokeOp("JsonGetJson", storeId, "Hello");
226 Assert.That(value, Is.EqualTo("{\"World\":\"Two\"}"));
227 }
228
229 // Test get of non-existing value
230 {
231 string fakeValueGet = (string)InvokeOp("JsonGetJson", storeId, "foo");
232 Assert.That(fakeValueGet, Is.EqualTo(""));
233 }
234
235 // Test get from non-existing store
236 {
237 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
238 string fakeStoreValueGet = (string)InvokeOp("JsonGetJson", fakeStoreId, "Hello");
239 Assert.That(fakeStoreValueGet, Is.EqualTo(""));
240 }
241 }
242
243// [Test]
244// public void TestJsonTakeValue()
245// {
246// TestHelpers.InMethod();
247//// TestHelpers.EnableLogging();
248//
249// UUID storeId
250// = (UUID)m_smcm.InvokeOperation(
251// UUID.Zero, UUID.Zero, "JsonCreateStore", new object[] { "{ 'Hello' : 'World' }" });
252//
253// string value
254// = (string)m_smcm.InvokeOperation(
255// UUID.Zero, UUID.Zero, "JsonTakeValue", new object[] { storeId, "Hello" });
256//
257// Assert.That(value, Is.EqualTo("World"));
258//
259// string value2
260// = (string)m_smcm.InvokeOperation(
261// UUID.Zero, UUID.Zero, "JsonGetValue", new object[] { storeId, "Hello" });
262//
263// Assert.That(value, Is.Null);
264// }
265
266 [Test]
267 public void TestJsonRemoveValue()
268 {
269 TestHelpers.InMethod();
270// TestHelpers.EnableLogging();
271
272 // Test remove of node in object pointing to a string
273 {
274 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }");
275
276 int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello");
277 Assert.That(returnValue, Is.EqualTo(1));
278
279 int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello");
280 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF));
281
282 string returnValue2 = (string)InvokeOp("JsonGetValue", storeId, "Hello");
283 Assert.That(returnValue2, Is.EqualTo(""));
284 }
285
286 // Test remove of node in object pointing to another object
287 {
288 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'Wally' } }");
289
290 int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello");
291 Assert.That(returnValue, Is.EqualTo(1));
292
293 int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello");
294 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF));
295
296 string returnValue2 = (string)InvokeOp("JsonGetJson", storeId, "Hello");
297 Assert.That(returnValue2, Is.EqualTo(""));
298 }
299
300 // Test remove of node in an array
301 {
302 UUID storeId
303 = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : [ 'value1', 'value2' ] }");
304
305 int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello[0]");
306 Assert.That(returnValue, Is.EqualTo(1));
307
308 int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello[0]");
309 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE));
310
311 result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello[1]");
312 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF));
313
314 string stringReturnValue = (string)InvokeOp("JsonGetValue", storeId, "Hello[0]");
315 Assert.That(stringReturnValue, Is.EqualTo("value2"));
316
317 stringReturnValue = (string)InvokeOp("JsonGetJson", storeId, "Hello[1]");
318 Assert.That(stringReturnValue, Is.EqualTo(""));
319 }
320
321 // Test remove of non-existing value
322 {
323 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }");
324
325 int fakeValueRemove = (int)InvokeOp("JsonRemoveValue", storeId, "Cheese");
326 Assert.That(fakeValueRemove, Is.EqualTo(0));
327 }
328
329 {
330 // Test get from non-existing store
331 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
332 int fakeStoreValueRemove = (int)InvokeOp("JsonRemoveValue", fakeStoreId, "Hello");
333 Assert.That(fakeStoreValueRemove, Is.EqualTo(0));
334 }
335 }
336
337// [Test]
338// public void TestJsonTestPath()
339// {
340// TestHelpers.InMethod();
341//// TestHelpers.EnableLogging();
342//
343// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'One' } }");
344//
345// {
346// int result = (int)InvokeOp("JsonTestPath", storeId, "Hello.World");
347// Assert.That(result, Is.EqualTo(1));
348// }
349//
350// // Test for path which does not resolve to a value.
351// {
352// int result = (int)InvokeOp("JsonTestPath", storeId, "Hello");
353// Assert.That(result, Is.EqualTo(0));
354// }
355//
356// {
357// int result2 = (int)InvokeOp("JsonTestPath", storeId, "foo");
358// Assert.That(result2, Is.EqualTo(0));
359// }
360//
361// // Test with fake store
362// {
363// UUID fakeStoreId = TestHelpers.ParseTail(0x500);
364// int fakeStoreValueRemove = (int)InvokeOp("JsonTestPath", fakeStoreId, "Hello");
365// Assert.That(fakeStoreValueRemove, Is.EqualTo(0));
366// }
367// }
368
369// [Test]
370// public void TestJsonTestPathJson()
371// {
372// TestHelpers.InMethod();
373//// TestHelpers.EnableLogging();
374//
375// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'One' } }");
376//
377// {
378// int result = (int)InvokeOp("JsonTestPathJson", storeId, "Hello.World");
379// Assert.That(result, Is.EqualTo(1));
380// }
381//
382// // Test for path which does not resolve to a value.
383// {
384// int result = (int)InvokeOp("JsonTestPathJson", storeId, "Hello");
385// Assert.That(result, Is.EqualTo(1));
386// }
387//
388// {
389// int result2 = (int)InvokeOp("JsonTestPathJson", storeId, "foo");
390// Assert.That(result2, Is.EqualTo(0));
391// }
392//
393// // Test with fake store
394// {
395// UUID fakeStoreId = TestHelpers.ParseTail(0x500);
396// int fakeStoreValueRemove = (int)InvokeOp("JsonTestPathJson", fakeStoreId, "Hello");
397// Assert.That(fakeStoreValueRemove, Is.EqualTo(0));
398// }
399// }
400
401 [Test]
402 public void TestJsonGetArrayLength()
403 {
404 TestHelpers.InMethod();
405// TestHelpers.EnableLogging();
406
407 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : [ 'one', 2 ] } }");
408
409 {
410 int result = (int)InvokeOp("JsonGetArrayLength", storeId, "Hello.World");
411 Assert.That(result, Is.EqualTo(2));
412 }
413
414 // Test path which is not an array
415 {
416 int result = (int)InvokeOp("JsonGetArrayLength", storeId, "Hello");
417 Assert.That(result, Is.EqualTo(-1));
418 }
419
420 // Test fake path
421 {
422 int result = (int)InvokeOp("JsonGetArrayLength", storeId, "foo");
423 Assert.That(result, Is.EqualTo(-1));
424 }
425
426 // Test fake store
427 {
428 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
429 int result = (int)InvokeOp("JsonGetArrayLength", fakeStoreId, "Hello.World");
430 Assert.That(result, Is.EqualTo(-1));
431 }
432 }
433
434 [Test]
435 public void TestJsonGetNodeType()
436 {
437 TestHelpers.InMethod();
438// TestHelpers.EnableLogging();
439
440 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : [ 'one', 2 ] } }");
441
442 {
443 int result = (int)InvokeOp("JsonGetNodeType", storeId, ".");
444 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_OBJECT));
445 }
446
447 {
448 int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello");
449 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_OBJECT));
450 }
451
452 {
453 int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World");
454 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_ARRAY));
455 }
456
457 {
458 int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World[0]");
459 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE));
460 }
461
462 {
463 int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World[1]");
464 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE));
465 }
466
467 // Test for non-existent path
468 {
469 int result = (int)InvokeOp("JsonGetNodeType", storeId, "foo");
470 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF));
471 }
472
473 // Test for non-existent store
474 {
475 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
476 int result = (int)InvokeOp("JsonGetNodeType", fakeStoreId, ".");
477 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF));
478 }
479 }
480
481 [Test]
482 public void TestJsonList2Path()
483 {
484 TestHelpers.InMethod();
485// TestHelpers.EnableLogging();
486
487 // Invoking these methods directly since I just couldn't get comms module invocation to work for some reason
488 // - some confusion with the methods that take a params object[] invocation.
489 {
490 string result = m_jssm.JsonList2Path(UUID.Zero, UUID.Zero, new object[] { "foo" });
491 Assert.That(result, Is.EqualTo("{foo}"));
492 }
493
494 {
495 string result = m_jssm.JsonList2Path(UUID.Zero, UUID.Zero, new object[] { "foo", "bar" });
496 Assert.That(result, Is.EqualTo("{foo}.{bar}"));
497 }
498
499 {
500 string result = m_jssm.JsonList2Path(UUID.Zero, UUID.Zero, new object[] { "foo", 1, "bar" });
501 Assert.That(result, Is.EqualTo("{foo}.[1].{bar}"));
502 }
503 }
504
505 [Test]
506 public void TestJsonSetValue()
507 {
508 TestHelpers.InMethod();
509// TestHelpers.EnableLogging();
510
511 {
512 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
513
514 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun", "Times");
515 Assert.That(result, Is.EqualTo(1));
516
517 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun");
518 Assert.That(value, Is.EqualTo("Times"));
519 }
520
521 // Test setting a key containing periods with delineation
522 {
523 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
524
525 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun.Circus}", "Times");
526 Assert.That(result, Is.EqualTo(1));
527
528 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun.Circus}");
529 Assert.That(value, Is.EqualTo("Times"));
530 }
531
532 // *** Test [] ***
533
534 // Test setting a key containing unbalanced ] without delineation. Expecting failure
535 {
536 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
537
538 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun]Circus", "Times");
539 Assert.That(result, Is.EqualTo(0));
540
541 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun]Circus");
542 Assert.That(value, Is.EqualTo(""));
543 }
544
545 // Test setting a key containing unbalanced [ without delineation. Expecting failure
546 {
547 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
548
549 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun[Circus", "Times");
550 Assert.That(result, Is.EqualTo(0));
551
552 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun[Circus");
553 Assert.That(value, Is.EqualTo(""));
554 }
555
556 // Test setting a key containing unbalanced [] without delineation. Expecting failure
557 {
558 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
559
560 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun[]Circus", "Times");
561 Assert.That(result, Is.EqualTo(0));
562
563 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun[]Circus");
564 Assert.That(value, Is.EqualTo(""));
565 }
566
567 // Test setting a key containing unbalanced ] with delineation
568 {
569 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
570
571 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun]Circus}", "Times");
572 Assert.That(result, Is.EqualTo(1));
573
574 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun]Circus}");
575 Assert.That(value, Is.EqualTo("Times"));
576 }
577
578 // Test setting a key containing unbalanced [ with delineation
579 {
580 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
581
582 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun[Circus}", "Times");
583 Assert.That(result, Is.EqualTo(1));
584
585 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun[Circus}");
586 Assert.That(value, Is.EqualTo("Times"));
587 }
588
589 // Test setting a key containing empty balanced [] with delineation
590 {
591 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
592
593 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun[]Circus}", "Times");
594 Assert.That(result, Is.EqualTo(1));
595
596 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun[]Circus}");
597 Assert.That(value, Is.EqualTo("Times"));
598 }
599
600// // Commented out as this currently unexpectedly fails.
601// // Test setting a key containing brackets around an integer with delineation
602// {
603// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
604//
605// int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun[0]Circus}", "Times");
606// Assert.That(result, Is.EqualTo(1));
607//
608// string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun[0]Circus}");
609// Assert.That(value, Is.EqualTo("Times"));
610// }
611
612 // *** Test {} ***
613
614 // Test setting a key containing unbalanced } without delineation. Expecting failure (?)
615 {
616 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
617
618 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun}Circus", "Times");
619 Assert.That(result, Is.EqualTo(0));
620
621 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun}Circus");
622 Assert.That(value, Is.EqualTo(""));
623 }
624
625 // Test setting a key containing unbalanced { without delineation. Expecting failure (?)
626 {
627 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
628
629 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun{Circus", "Times");
630 Assert.That(result, Is.EqualTo(0));
631
632 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun}Circus");
633 Assert.That(value, Is.EqualTo(""));
634 }
635
636// // Commented out as this currently unexpectedly fails.
637// // Test setting a key containing unbalanced }
638// {
639// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
640//
641// int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun}Circus}", "Times");
642// Assert.That(result, Is.EqualTo(0));
643// }
644
645 // Test setting a key containing unbalanced { with delineation
646 {
647 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
648
649 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun{Circus}", "Times");
650 Assert.That(result, Is.EqualTo(1));
651
652 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun{Circus}");
653 Assert.That(value, Is.EqualTo("Times"));
654 }
655
656 // Test setting a key containing balanced {} with delineation. This should fail.
657 {
658 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
659
660 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun{Filled}Circus}", "Times");
661 Assert.That(result, Is.EqualTo(0));
662
663 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun{Filled}Circus}");
664 Assert.That(value, Is.EqualTo(""));
665 }
666
667 // Test setting to location that does not exist. This should fail.
668 {
669 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
670
671 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun.Circus", "Times");
672 Assert.That(result, Is.EqualTo(0));
673
674 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun.Circus");
675 Assert.That(value, Is.EqualTo(""));
676 }
677
678 // Test with fake store
679 {
680 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
681 int fakeStoreValueSet = (int)InvokeOp("JsonSetValue", fakeStoreId, "Hello", "World");
682 Assert.That(fakeStoreValueSet, Is.EqualTo(0));
683 }
684 }
685
686 [Test]
687 public void TestJsonSetJson()
688 {
689 TestHelpers.InMethod();
690// TestHelpers.EnableLogging();
691
692 // Single quoted token case
693 {
694 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }");
695
696 int result = (int)InvokeOp("JsonSetJson", storeId, "Fun", "'Times'");
697 Assert.That(result, Is.EqualTo(1));
698
699 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun");
700 Assert.That(value, Is.EqualTo("Times"));
701 }
702
703 // Sub-tree case
704 {
705 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }");
706
707 int result = (int)InvokeOp("JsonSetJson", storeId, "Fun", "{ 'Filled' : 'Times' }");
708 Assert.That(result, Is.EqualTo(1));
709
710 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun.Filled");
711 Assert.That(value, Is.EqualTo("Times"));
712 }
713
714 // If setting single strings in JsonSetValueJson, these must be single quoted tokens, not bare strings.
715 {
716 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }");
717
718 int result = (int)InvokeOp("JsonSetJson", storeId, "Fun", "Times");
719 Assert.That(result, Is.EqualTo(0));
720
721 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun");
722 Assert.That(value, Is.EqualTo(""));
723 }
724
725 // Test setting to location that does not exist. This should fail.
726 {
727 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }");
728
729 int result = (int)InvokeOp("JsonSetJson", storeId, "Fun.Circus", "'Times'");
730 Assert.That(result, Is.EqualTo(0));
731
732 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun.Circus");
733 Assert.That(value, Is.EqualTo(""));
734 }
735
736 // Test with fake store
737 {
738 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
739 int fakeStoreValueSet = (int)InvokeOp("JsonSetJson", fakeStoreId, "Hello", "'World'");
740 Assert.That(fakeStoreValueSet, Is.EqualTo(0));
741 }
742 }
743
744 /// <summary>
745 /// Test for writing json to a notecard
746 /// </summary>
747 /// <remarks>
748 /// TODO: Really needs to test correct receipt of the link_message event. Could do this by directly fetching
749 /// it via the MockScriptEngine or perhaps by a dummy script instance.
750 /// </remarks>
751 [Test]
752 public void TestJsonWriteNotecard()
753 {
754 TestHelpers.InMethod();
755// TestHelpers.EnableLogging();
756
757 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, TestHelpers.ParseTail(0x1));
758 m_scene.AddSceneObject(so);
759
760 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello':'World' }");
761
762 {
763 string notecardName = "nc1";
764
765 // Write notecard
766 UUID writeNotecardRequestId = (UUID)InvokeOpOnHost("JsonWriteNotecard", so.UUID, storeId, "", notecardName);
767 Assert.That(writeNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
768
769 TaskInventoryItem nc1Item = so.RootPart.Inventory.GetInventoryItem(notecardName);
770 Assert.That(nc1Item, Is.Not.Null);
771
772 // TODO: Should independently check the contents.
773 }
774
775 // TODO: Write partial test
776
777 {
778 // Try to write notecard for a bad path
779 // In this case we do get a request id but no notecard is written.
780 string badPathNotecardName = "badPathNotecardName";
781
782 UUID writeNotecardBadPathRequestId
783 = (UUID)InvokeOpOnHost("JsonWriteNotecard", so.UUID, storeId, "flibble", badPathNotecardName);
784 Assert.That(writeNotecardBadPathRequestId, Is.Not.EqualTo(UUID.Zero));
785
786 TaskInventoryItem badPathItem = so.RootPart.Inventory.GetInventoryItem(badPathNotecardName);
787 Assert.That(badPathItem, Is.Null);
788 }
789
790 {
791 // Test with fake store
792 // In this case we do get a request id but no notecard is written.
793 string fakeStoreNotecardName = "fakeStoreNotecardName";
794
795 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
796 UUID fakeStoreWriteNotecardValue
797 = (UUID)InvokeOpOnHost("JsonWriteNotecard", so.UUID, fakeStoreId, "", fakeStoreNotecardName);
798 Assert.That(fakeStoreWriteNotecardValue, Is.Not.EqualTo(UUID.Zero));
799
800 TaskInventoryItem fakeStoreItem = so.RootPart.Inventory.GetInventoryItem(fakeStoreNotecardName);
801 Assert.That(fakeStoreItem, Is.Null);
802 }
803 }
804
805 /// <summary>
806 /// Test for reading json from a notecard
807 /// </summary>
808 /// <remarks>
809 /// TODO: Really needs to test correct receipt of the link_message event. Could do this by directly fetching
810 /// it via the MockScriptEngine or perhaps by a dummy script instance.
811 /// </remarks>
812 [Test]
813 public void TestJsonReadNotecard()
814 {
815 TestHelpers.InMethod();
816// TestHelpers.EnableLogging();
817
818 string notecardName = "nc1";
819
820 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, TestHelpers.ParseTail(0x1));
821 m_scene.AddSceneObject(so);
822
823 UUID creatingStoreId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello':'World' }");
824
825 // Write notecard
826 InvokeOpOnHost("JsonWriteNotecard", so.UUID, creatingStoreId, "", notecardName);
827
828 {
829 // Read notecard
830 UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{}");
831 UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "", notecardName);
832 Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
833
834 string value = (string)InvokeOp("JsonGetValue", receivingStoreId, "Hello");
835 Assert.That(value, Is.EqualTo("World"));
836 }
837
838 {
839 // Read notecard to new single component path
840 UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{}");
841 UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "make", notecardName);
842 Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
843
844 string value = (string)InvokeOp("JsonGetValue", receivingStoreId, "Hello");
845 Assert.That(value, Is.EqualTo(""));
846
847 value = (string)InvokeOp("JsonGetValue", receivingStoreId, "make.Hello");
848 Assert.That(value, Is.EqualTo("World"));
849 }
850
851 {
852 // Read notecard to new multi-component path. This should not work.
853 UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{}");
854 UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "make.it", notecardName);
855 Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
856
857 string value = (string)InvokeOp("JsonGetValue", receivingStoreId, "Hello");
858 Assert.That(value, Is.EqualTo(""));
859
860 value = (string)InvokeOp("JsonGetValue", receivingStoreId, "make.it.Hello");
861 Assert.That(value, Is.EqualTo(""));
862 }
863
864 {
865 // Read notecard to existing multi-component path. This should work
866 UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{ 'make' : { 'it' : 'so' } }");
867 UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "make.it", notecardName);
868 Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
869
870 string value = (string)InvokeOp("JsonGetValue", receivingStoreId, "Hello");
871 Assert.That(value, Is.EqualTo(""));
872
873 value = (string)InvokeOp("JsonGetValue", receivingStoreId, "make.it.Hello");
874 Assert.That(value, Is.EqualTo("World"));
875 }
876
877 {
878 // Read notecard to invalid path. This should not work.
879 UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{ 'make' : { 'it' : 'so' } }");
880 UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "/", notecardName);
881 Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
882
883 string value = (string)InvokeOp("JsonGetValue", receivingStoreId, "Hello");
884 Assert.That(value, Is.EqualTo(""));
885 }
886
887 {
888 // Try read notecard to fake store.
889 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
890 UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, fakeStoreId, "", notecardName);
891 Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
892
893 string value = (string)InvokeOp("JsonGetValue", fakeStoreId, "Hello");
894 Assert.That(value, Is.EqualTo(""));
895 }
896 }
897
898 public object DummyTestMethod(object o1, object o2, object o3, object o4, object o5) { return null; }
899 }
900}
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs
index 6fb28e2..4bafe2f 100644
--- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs
@@ -180,6 +180,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
180 /// * Internet 180 /// * Internet
181 /// * Everything 181 /// * Everything
182 /// </remarks> 182 /// </remarks>
183#pragma warning disable 0618
183 public static AppDomain CreateRestrictedDomain(string permissionSetName, string appDomainName) 184 public static AppDomain CreateRestrictedDomain(string permissionSetName, string appDomainName)
184 { 185 {
185 if (permissionSetName == null) 186 if (permissionSetName == null)
@@ -240,6 +241,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
240 241
241 return restrictedDomain; 242 return restrictedDomain;
242 } 243 }
244#pragma warning restore 0618
243 245
244 246
245 void EventManager_OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource) 247 void EventManager_OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource)
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs
index 5ed1514..47b9c09 100644
--- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs
@@ -34,7 +34,7 @@ using OpenSim.Framework;
34using OpenSim.Region.Framework.Interfaces; 34using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes; 35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Region.OptionalModules.Scripting.Minimodule.Object; 36using OpenSim.Region.OptionalModules.Scripting.Minimodule.Object;
37using OpenSim.Region.Physics.Manager; 37using OpenSim.Region.PhysicsModules.SharedBase;
38using PrimType=OpenSim.Region.OptionalModules.Scripting.Minimodule.Object.PrimType; 38using PrimType=OpenSim.Region.OptionalModules.Scripting.Minimodule.Object.PrimType;
39using SculptType=OpenSim.Region.OptionalModules.Scripting.Minimodule.Object.SculptType; 39using SculptType=OpenSim.Region.OptionalModules.Scripting.Minimodule.Object.SculptType;
40 40
diff --git a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
index c550c44..870c0bb 100644
--- a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
@@ -105,7 +105,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady
105 m_scene.LoginLock = true; 105 m_scene.LoginLock = true;
106 m_scene.EventManager.OnEmptyScriptCompileQueue += OnEmptyScriptCompileQueue; 106 m_scene.EventManager.OnEmptyScriptCompileQueue += OnEmptyScriptCompileQueue;
107 107
108 m_log.InfoFormat("[RegionReady]: Region {0} - LOGINS DISABLED DURING INITIALIZATION.", m_scene.Name); 108 // This should always show up to the user but should not trigger warn/errors as these messages are
109 // expected and are not simulator problems. Ideally, there would be a status level in log4net but
110 // failing that, we will print out to console instead.
111 MainConsole.Instance.OutputFormat("Region {0} - LOGINS DISABLED DURING INITIALIZATION.", m_scene.Name);
109 112
110 if (m_uri != string.Empty) 113 if (m_uri != string.Empty)
111 { 114 {
@@ -169,7 +172,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady
169 c.Channel = m_channelNotify; 172 c.Channel = m_channelNotify;
170 c.Message += numScriptsFailed.ToString() + "," + message; 173 c.Message += numScriptsFailed.ToString() + "," + message;
171 c.Type = ChatTypeEnum.Region; 174 c.Type = ChatTypeEnum.Region;
172 c.Position = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 30); 175 if (m_scene != null)
176 c.Position = new Vector3((m_scene.RegionInfo.RegionSizeX * 0.5f), (m_scene.RegionInfo.RegionSizeY * 0.5f), 30);
177 else
178 c.Position = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 30);
173 c.Sender = null; 179 c.Sender = null;
174 c.SenderUUID = UUID.Zero; 180 c.SenderUUID = UUID.Zero;
175 c.Scene = m_scene; 181 c.Scene = m_scene;
@@ -215,8 +221,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady
215 // m_log.InfoFormat("[RegionReady]: Logins enabled for {0}, Oar {1}", 221 // m_log.InfoFormat("[RegionReady]: Logins enabled for {0}, Oar {1}",
216 // m_scene.RegionInfo.RegionName, m_oarFileLoading.ToString()); 222 // m_scene.RegionInfo.RegionName, m_oarFileLoading.ToString());
217 223
218 m_log.InfoFormat( 224 // Putting this out to console to make it eye-catching for people who are running OpenSimulator
219 "[RegionReady]: INITIALIZATION COMPLETE FOR {0} - LOGINS ENABLED", m_scene.Name); 225 // without info log messages enabled. Making this a warning is arguably misleading since it isn't a
226 // warning, and monitor scripts looking for warn/error/fatal messages will received false positives.
227 // Arguably, log4net needs a status log level (like Apache).
228 MainConsole.Instance.OutputFormat("INITIALIZATION COMPLETE FOR {0} - LOGINS ENABLED", m_scene.Name);
220 } 229 }
221 230
222 m_scene.SceneGridService.InformNeighborsThatRegionisUp( 231 m_scene.SceneGridService.InformNeighborsThatRegionisUp(
@@ -297,7 +306,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady
297 finally 306 finally
298 { 307 {
299 if (os != null) 308 if (os != null)
300 os.Close(); 309 os.Dispose();
301 } 310 }
302 } 311 }
303 } 312 }
diff --git a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs
index 709d389..744d1e3 100644
--- a/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/XmlRpcRouterModule/XmlRpcGridRouterModule.cs
@@ -35,7 +35,6 @@ using OpenMetaverse;
35using Mono.Addins; 35using Mono.Addins;
36 36
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Framework.Communications;
39using OpenSim.Framework.Servers; 38using OpenSim.Framework.Servers;
40using OpenSim.Framework.Servers.HttpServer; 39using OpenSim.Framework.Servers.HttpServer;
41using OpenSim.Framework.Client; 40using OpenSim.Framework.Client;