aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMic Bowman2013-02-08 22:43:15 -0800
committerMic Bowman2013-02-08 22:43:15 -0800
commit7bb82c8f2ed987410342c1367dde24b695593eec (patch)
tree545fe97d94054748a4042df16230e3e9ca3e5bd5 /OpenSim
parentBroaden the internal OSD type checks to parse JSON that has (diff)
downloadopensim-SC_OLD-7bb82c8f2ed987410342c1367dde24b695593eec.zip
opensim-SC_OLD-7bb82c8f2ed987410342c1367dde24b695593eec.tar.gz
opensim-SC_OLD-7bb82c8f2ed987410342c1367dde24b695593eec.tar.bz2
opensim-SC_OLD-7bb82c8f2ed987410342c1367dde24b695593eec.tar.xz
Make JsonStore path parsing more robust. Should fix the
invalid path problem.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs68
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs12
2 files changed, 59 insertions, 21 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
index 5c89717..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,7 +147,10 @@ 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)
@@ -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 // -----------------------------------------------------------------
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