aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting/JsonStore
diff options
context:
space:
mode:
authorMelanie2013-02-10 00:17:14 +0000
committerMelanie2013-02-10 00:17:14 +0000
commit069e587841465d8d041164929e27fc891b66a64a (patch)
treec37a59b837bfbac696850a7af2b8f20c520141ba /OpenSim/Region/OptionalModules/Scripting/JsonStore
parentMerge branch 'master' into careminster (diff)
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-069e587841465d8d041164929e27fc891b66a64a.zip
opensim-SC-069e587841465d8d041164929e27fc891b66a64a.tar.gz
opensim-SC-069e587841465d8d041164929e27fc891b66a64a.tar.bz2
opensim-SC-069e587841465d8d041164929e27fc891b66a64a.tar.xz
Merge branch 'master' into careminster
Conflicts: OpenSim/Data/MySQL/MySQLSimulationData.cs OpenSim/Data/MySQL/Resources/RegionStore.migrations
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs99
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs12
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs7
3 files changed, 90 insertions, 28 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
index 088d0cd..3d715cc 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
@@ -81,7 +81,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
81 protected static Regex m_ParsePassFour = new Regex("\\.+"); 81 protected static Regex m_ParsePassFour = new Regex("\\.+");
82 82
83 // expression used to validate the full path, this is canonical representation 83 // expression used to validate the full path, this is canonical representation
84 protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)+$"); 84 protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)*$");
85 85
86 // expression used to match path components 86 // expression used to match path components
87 protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)"); 87 protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)");
@@ -107,9 +107,17 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
107 /// 107 ///
108 /// </summary> 108 /// </summary>
109 // ----------------------------------------------------------------- 109 // -----------------------------------------------------------------
110 public static string CanonicalPathExpression(string path) 110 public static bool CanonicalPathExpression(string ipath, out string opath)
111 { 111 {
112 return PathExpressionToKey(ParsePathExpression(path)); 112 Stack<string> path;
113 if (! ParsePathExpression(ipath,out path))
114 {
115 opath = "";
116 return false;
117 }
118
119 opath = PathExpressionToKey(path);
120 return true;
113 } 121 }
114 122
115 // ----------------------------------------------------------------- 123 // -----------------------------------------------------------------
@@ -139,13 +147,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
139 // ----------------------------------------------------------------- 147 // -----------------------------------------------------------------
140 public bool TestPath(string expr, bool useJson) 148 public bool TestPath(string expr, bool useJson)
141 { 149 {
142 Stack<string> path = ParsePathExpression(expr); 150 Stack<string> path;
151 if (! ParsePathExpression(expr,out path))
152 return false;
153
143 OSD result = ProcessPathExpression(ValueStore,path); 154 OSD result = ProcessPathExpression(ValueStore,path);
144 155
145 if (result == null) 156 if (result == null)
146 return false; 157 return false;
147 158
148 if (useJson || result.Type == OSDType.String) 159 if (useJson || OSDBaseType(result.Type))
149 return true; 160 return true;
150 161
151 return false; 162 return false;
@@ -158,7 +169,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
158 // ----------------------------------------------------------------- 169 // -----------------------------------------------------------------
159 public bool GetValue(string expr, out string value, bool useJson) 170 public bool GetValue(string expr, out string value, bool useJson)
160 { 171 {
161 Stack<string> path = ParsePathExpression(expr); 172 Stack<string> path;
173 if (! ParsePathExpression(expr,out path))
174 {
175 value = "";
176 return false;
177 }
178
162 OSD result = ProcessPathExpression(ValueStore,path); 179 OSD result = ProcessPathExpression(ValueStore,path);
163 return ConvertOutputValue(result,out value,useJson); 180 return ConvertOutputValue(result,out value,useJson);
164 } 181 }
@@ -192,7 +209,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
192 // ----------------------------------------------------------------- 209 // -----------------------------------------------------------------
193 public bool TakeValue(string expr, bool useJson, TakeValueCallback cback) 210 public bool TakeValue(string expr, bool useJson, TakeValueCallback cback)
194 { 211 {
195 Stack<string> path = ParsePathExpression(expr); 212 Stack<string> path;
213 if (! ParsePathExpression(expr,out path))
214 return false;
215
196 string pexpr = PathExpressionToKey(path); 216 string pexpr = PathExpressionToKey(path);
197 217
198 OSD result = ProcessPathExpression(ValueStore,path); 218 OSD result = ProcessPathExpression(ValueStore,path);
@@ -223,7 +243,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
223 // ----------------------------------------------------------------- 243 // -----------------------------------------------------------------
224 public bool ReadValue(string expr, bool useJson, TakeValueCallback cback) 244 public bool ReadValue(string expr, bool useJson, TakeValueCallback cback)
225 { 245 {
226 Stack<string> path = ParsePathExpression(expr); 246 Stack<string> path;
247 if (! ParsePathExpression(expr,out path))
248 return false;
249
227 string pexpr = PathExpressionToKey(path); 250 string pexpr = PathExpressionToKey(path);
228 251
229 OSD result = ProcessPathExpression(ValueStore,path); 252 OSD result = ProcessPathExpression(ValueStore,path);
@@ -253,7 +276,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
253 // ----------------------------------------------------------------- 276 // -----------------------------------------------------------------
254 protected bool SetValueFromExpression(string expr, OSD ovalue) 277 protected bool SetValueFromExpression(string expr, OSD ovalue)
255 { 278 {
256 Stack<string> path = ParsePathExpression(expr); 279 Stack<string> path;
280 if (! ParsePathExpression(expr,out path))
281 return false;
282
257 if (path.Count == 0) 283 if (path.Count == 0)
258 { 284 {
259 ValueStore = ovalue; 285 ValueStore = ovalue;
@@ -399,34 +425,36 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
399 /// use a stack because we process the path in inverse order later 425 /// use a stack because we process the path in inverse order later
400 /// </summary> 426 /// </summary>
401 // ----------------------------------------------------------------- 427 // -----------------------------------------------------------------
402 protected static Stack<string> ParsePathExpression(string path) 428 protected static bool ParsePathExpression(string expr, out Stack<string> path)
403 { 429 {
404 Stack<string> m_path = new Stack<string>(); 430 path = new Stack<string>();
405 431
406 // add front and rear separators 432 // add front and rear separators
407 path = "." + path + "."; 433 expr = "." + expr + ".";
408 434
409 // add separators for quoted paths 435 // add separators for quoted exprs
410 path = m_ParsePassOne.Replace(path,".$0.",-1,0); 436 expr = m_ParsePassOne.Replace(expr,".$0.",-1,0);
411 437
412 // add separators for array references 438 // add separators for array references
413 path = m_ParsePassTwo.Replace(path,".$0.",-1,0); 439 expr = m_ParsePassTwo.Replace(expr,".$0.",-1,0);
414 440
415 // add quotes to bare identifier 441 // add quotes to bare identifier
416 path = m_ParsePassThree.Replace(path,".{$1}",-1,0); 442 expr = m_ParsePassThree.Replace(expr,".{$1}",-1,0);
417 443
418 // remove extra separators 444 // remove extra separators
419 path = m_ParsePassFour.Replace(path,".",-1,0); 445 expr = m_ParsePassFour.Replace(expr,".",-1,0);
420 446
421 // validate the results (catches extra quote characters for example) 447 // validate the results (catches extra quote characters for example)
422 if (m_ValidatePath.IsMatch(path)) 448 if (m_ValidatePath.IsMatch(expr))
423 { 449 {
424 MatchCollection matches = m_PathComponent.Matches(path,0); 450 MatchCollection matches = m_PathComponent.Matches(expr,0);
425 foreach (Match match in matches) 451 foreach (Match match in matches)
426 m_path.Push(match.Groups[1].Value); 452 path.Push(match.Groups[1].Value);
453
454 return true;
427 } 455 }
428 456
429 return m_path; 457 return false;
430 } 458 }
431 459
432 // ----------------------------------------------------------------- 460 // -----------------------------------------------------------------
@@ -531,7 +559,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
531 return true; 559 return true;
532 } 560 }
533 561
534 if (result.Type == OSDType.String) 562 if (OSDBaseType(result.Type))
535 { 563 {
536 value = result.AsString(); 564 value = result.AsString();
537 return true; 565 return true;
@@ -562,6 +590,33 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
562 /// 590 ///
563 /// </summary> 591 /// </summary>
564 // ----------------------------------------------------------------- 592 // -----------------------------------------------------------------
593 protected static bool OSDBaseType(OSDType type)
594 {
595 // Should be the list of base types for which AsString() returns
596 // something useful
597 if (type == OSDType.Boolean)
598 return true;
599 if (type == OSDType.Integer)
600 return true;
601 if (type == OSDType.Real)
602 return true;
603 if (type == OSDType.String)
604 return true;
605 if (type == OSDType.UUID)
606 return true;
607 if (type == OSDType.Date)
608 return true;
609 if (type == OSDType.URI)
610 return true;
611
612 return false;
613 }
614
615 // -----------------------------------------------------------------
616 /// <summary>
617 ///
618 /// </summary>
619 // -----------------------------------------------------------------
565 protected static int ComputeSizeOf(OSD value) 620 protected static int ComputeSizeOf(OSD value)
566 { 621 {
567 string sval; 622 string sval;
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
index d75cd32..e436304 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
@@ -301,7 +301,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
301 [ScriptInvocation] 301 [ScriptInvocation]
302 public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist) 302 public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist)
303 { 303 {
304 return JsonStore.CanonicalPathExpression(ConvertList2Path(pathlist)); 304 string ipath = ConvertList2Path(pathlist);
305 string opath;
306
307 if (JsonStore.CanonicalPathExpression(ipath,out opath))
308 return opath;
309
310 // This won't parse if passed to the other routines as opposed to
311 // returning an empty string which is a valid path and would overwrite
312 // the entire store
313 return "**INVALID**";
305 } 314 }
306 315
307 // ----------------------------------------------------------------- 316 // -----------------------------------------------------------------
@@ -421,6 +430,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
421 // ----------------------------------------------------------------- 430 // -----------------------------------------------------------------
422 protected void GenerateRuntimeError(string msg) 431 protected void GenerateRuntimeError(string msg)
423 { 432 {
433 m_log.InfoFormat("[JsonStore] runtime error: {0}",msg);
424 throw new Exception("JsonStore Runtime Error: " + msg); 434 throw new Exception("JsonStore Runtime Error: " + msg);
425 } 435 }
426 436
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
index ca88d1a..af97ac7 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
@@ -144,8 +144,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
144 144
145 int dsrv = (int)InvokeOp("JsonDestroyStore", fakeStoreId); 145 int dsrv = (int)InvokeOp("JsonDestroyStore", fakeStoreId);
146 146
147 // XXX: Current returns 'true' even though no such store existed. Need to ask if this is best behaviour. 147 Assert.That(dsrv, Is.EqualTo(0));
148 Assert.That(dsrv, Is.EqualTo(1));
149 } 148 }
150 149
151 [Test] 150 [Test]
@@ -211,9 +210,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
211 210
212 // Test remove of non-existing value 211 // Test remove of non-existing value
213 int fakeValueRemove = (int)InvokeOp("JsonRemoveValue", storeId, "Hello"); 212 int fakeValueRemove = (int)InvokeOp("JsonRemoveValue", storeId, "Hello");
214 213 Assert.That(fakeValueRemove, Is.EqualTo(0));
215 // XXX: Is this the best response to removing a value that isn't there?
216 Assert.That(fakeValueRemove, Is.EqualTo(1));
217 214
218 // Test get from non-existing store 215 // Test get from non-existing store
219 UUID fakeStoreId = TestHelpers.ParseTail(0x500); 216 UUID fakeStoreId = TestHelpers.ParseTail(0x500);