diff options
author | Melanie | 2013-02-14 07:45:23 +0000 |
---|---|---|
committer | Melanie | 2013-02-14 07:45:23 +0000 |
commit | 9d55a2298d33c3b71a39908415cab18bbf3364b6 (patch) | |
tree | 7f00f6eaa9c9d63da3dbcd2dcf0f01b1ce049d6f /OpenSim/Region/OptionalModules/Scripting | |
parent | Merge branch 'master' into careminster (diff) | |
parent | Fix a very unlikely-to-occur NullReferenceException race condition in llPushO... (diff) | |
download | opensim-SC-9d55a2298d33c3b71a39908415cab18bbf3364b6.zip opensim-SC-9d55a2298d33c3b71a39908415cab18bbf3364b6.tar.gz opensim-SC-9d55a2298d33c3b71a39908415cab18bbf3364b6.tar.bz2 opensim-SC-9d55a2298d33c3b71a39908415cab18bbf3364b6.tar.xz |
Merge branch 'master' into careminster
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting')
3 files changed, 153 insertions, 13 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs index 3bad06c..ca3989a 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | |||
@@ -68,14 +68,11 @@ 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 | 71 | // add separators for quoted paths and array references |
72 | protected static Regex m_ParsePassOne = new Regex("{[^}]+}"); | 72 | protected static Regex m_ParsePassOne = new Regex("({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])"); |
73 | |||
74 | // add separators for array references | ||
75 | protected static Regex m_ParsePassTwo = new Regex("(\\[[0-9]+\\]|\\[\\+\\])"); | ||
76 | 73 | ||
77 | // add quotes to bare identifiers which are limited to alphabetic characters | 74 | // add quotes to bare identifiers which are limited to alphabetic characters |
78 | protected static Regex m_ParsePassThree = new Regex("\\.([a-zA-Z]+)"); | 75 | protected static Regex m_ParsePassThree = new Regex("(?<!{[^}]*)\\.([a-zA-Z]+)(?=\\.)"); |
79 | 76 | ||
80 | // remove extra separator characters | 77 | // remove extra separator characters |
81 | protected static Regex m_ParsePassFour = new Regex("\\.+"); | 78 | protected static Regex m_ParsePassFour = new Regex("\\.+"); |
@@ -84,7 +81,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
84 | protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)*$"); | 81 | protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)*$"); |
85 | 82 | ||
86 | // expression used to match path components | 83 | // expression used to match path components |
87 | protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)"); | 84 | protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])"); |
88 | 85 | ||
89 | // extract the internals of an array reference | 86 | // extract the internals of an array reference |
90 | protected static Regex m_SimpleArrayPattern = new Regex("\\[([0-9]+)\\]"); | 87 | protected static Regex m_SimpleArrayPattern = new Regex("\\[([0-9]+)\\]"); |
@@ -148,6 +145,34 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
148 | /// | 145 | /// |
149 | /// </summary> | 146 | /// </summary> |
150 | // ----------------------------------------------------------------- | 147 | // ----------------------------------------------------------------- |
148 | public JsonStoreNodeType PathType(string expr) | ||
149 | { | ||
150 | Stack<string> path; | ||
151 | if (! ParsePathExpression(expr,out path)) | ||
152 | return JsonStoreNodeType.Undefined; | ||
153 | |||
154 | OSD result = ProcessPathExpression(ValueStore,path); | ||
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 | |||
171 | // ----------------------------------------------------------------- | ||
172 | /// <summary> | ||
173 | /// | ||
174 | /// </summary> | ||
175 | // ----------------------------------------------------------------- | ||
151 | public bool TestPath(string expr, bool useJson) | 176 | public bool TestPath(string expr, bool useJson) |
152 | { | 177 | { |
153 | Stack<string> path; | 178 | Stack<string> path; |
@@ -170,6 +195,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
170 | /// | 195 | /// |
171 | /// </summary> | 196 | /// </summary> |
172 | // ----------------------------------------------------------------- | 197 | // ----------------------------------------------------------------- |
198 | public int ArrayLength(string expr) | ||
199 | { | ||
200 | Stack<string> path; | ||
201 | if (! ParsePathExpression(expr,out path)) | ||
202 | return -1; | ||
203 | |||
204 | OSD result = ProcessPathExpression(ValueStore,path); | ||
205 | if (result != null && result.Type == OSDType.Array) | ||
206 | { | ||
207 | OSDArray arr = result as OSDArray; | ||
208 | return arr.Count; | ||
209 | } | ||
210 | |||
211 | return -1; | ||
212 | } | ||
213 | |||
214 | // ----------------------------------------------------------------- | ||
215 | /// <summary> | ||
216 | /// | ||
217 | /// </summary> | ||
218 | // ----------------------------------------------------------------- | ||
173 | public bool GetValue(string expr, out string value, bool useJson) | 219 | public bool GetValue(string expr, out string value, bool useJson) |
174 | { | 220 | { |
175 | Stack<string> path; | 221 | Stack<string> path; |
@@ -465,11 +511,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
465 | // add front and rear separators | 511 | // add front and rear separators |
466 | expr = "." + expr + "."; | 512 | expr = "." + expr + "."; |
467 | 513 | ||
468 | // add separators for quoted exprs | 514 | // add separators for quoted exprs and array references |
469 | expr = m_ParsePassOne.Replace(expr,".$0.",-1,0); | 515 | expr = m_ParsePassOne.Replace(expr,".$1.",-1,0); |
470 | |||
471 | // add separators for array references | ||
472 | expr = m_ParsePassTwo.Replace(expr,".$0.",-1,0); | ||
473 | 516 | ||
474 | // add quotes to bare identifier | 517 | // add quotes to bare identifier |
475 | expr = m_ParsePassThree.Replace(expr,".{$1}",-1,0); | 518 | expr = m_ParsePassThree.Replace(expr,".{$1}",-1,0); |
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs index cc13661..eec86ef 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs | |||
@@ -270,6 +270,38 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
270 | /// | 270 | /// |
271 | /// </summary> | 271 | /// </summary> |
272 | // ----------------------------------------------------------------- | 272 | // ----------------------------------------------------------------- |
273 | public JsonStoreNodeType PathType(UUID storeID, string path) | ||
274 | { | ||
275 | if (! m_enabled) return JsonStoreNodeType.Undefined; | ||
276 | |||
277 | JsonStore map = null; | ||
278 | lock (m_JsonValueStore) | ||
279 | { | ||
280 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | ||
281 | { | ||
282 | m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); | ||
283 | return JsonStoreNodeType.Undefined; | ||
284 | } | ||
285 | } | ||
286 | |||
287 | try | ||
288 | { | ||
289 | lock (map) | ||
290 | return map.PathType(path); | ||
291 | } | ||
292 | catch (Exception e) | ||
293 | { | ||
294 | m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e); | ||
295 | } | ||
296 | |||
297 | return JsonStoreNodeType.Undefined; | ||
298 | } | ||
299 | |||
300 | // ----------------------------------------------------------------- | ||
301 | /// <summary> | ||
302 | /// | ||
303 | /// </summary> | ||
304 | // ----------------------------------------------------------------- | ||
273 | public bool TestPath(UUID storeID, string path, bool useJson) | 305 | public bool TestPath(UUID storeID, string path, bool useJson) |
274 | { | 306 | { |
275 | if (! m_enabled) return false; | 307 | if (! m_enabled) return false; |
@@ -375,6 +407,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
375 | /// | 407 | /// |
376 | /// </summary> | 408 | /// </summary> |
377 | // ----------------------------------------------------------------- | 409 | // ----------------------------------------------------------------- |
410 | public int ArrayLength(UUID storeID, string path) | ||
411 | { | ||
412 | if (! m_enabled) return -1; | ||
413 | |||
414 | JsonStore map = null; | ||
415 | lock (m_JsonValueStore) | ||
416 | { | ||
417 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | ||
418 | return -1; | ||
419 | } | ||
420 | |||
421 | try | ||
422 | { | ||
423 | lock (map) | ||
424 | { | ||
425 | return map.ArrayLength(path); | ||
426 | } | ||
427 | } | ||
428 | catch (Exception e) | ||
429 | { | ||
430 | m_log.Error("[JsonStore]: unable to retrieve value", e); | ||
431 | } | ||
432 | |||
433 | return -1; | ||
434 | } | ||
435 | |||
436 | // ----------------------------------------------------------------- | ||
437 | /// <summary> | ||
438 | /// | ||
439 | /// </summary> | ||
440 | // ----------------------------------------------------------------- | ||
378 | public bool GetValue(UUID storeID, string path, bool useJson, out string value) | 441 | public bool GetValue(UUID storeID, string path, bool useJson, out string value) |
379 | { | 442 | { |
380 | value = String.Empty; | 443 | value = String.Empty; |
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs index e436304..3955bff 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs | |||
@@ -167,7 +167,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
167 | try | 167 | try |
168 | { | 168 | { |
169 | m_comms.RegisterScriptInvocations(this); | 169 | m_comms.RegisterScriptInvocations(this); |
170 | 170 | m_comms.RegisterConstants(this); | |
171 | |||
171 | // m_comms.RegisterScriptInvocation(this, "JsonCreateStore"); | 172 | // m_comms.RegisterScriptInvocation(this, "JsonCreateStore"); |
172 | // m_comms.RegisterScriptInvocation(this, "JsonAttachObjectStore"); | 173 | // m_comms.RegisterScriptInvocation(this, "JsonAttachObjectStore"); |
173 | // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore"); | 174 | // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore"); |
@@ -214,6 +215,22 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
214 | 215 | ||
215 | #endregion | 216 | #endregion |
216 | 217 | ||
218 | #region ScriptConstantInteface | ||
219 | |||
220 | [ScriptConstant] | ||
221 | public static readonly int JSONTYPEUNDEF = (int)JsonStoreNodeType.Undefined; | ||
222 | |||
223 | [ScriptConstant] | ||
224 | public static readonly int JSONTYPEOBJECT = (int)JsonStoreNodeType.Object; | ||
225 | |||
226 | [ScriptConstant] | ||
227 | public static readonly int JSONTYPEARRAY = (int)JsonStoreNodeType.Array; | ||
228 | |||
229 | [ScriptConstant] | ||
230 | public static readonly int JSONTYPEVALUE = (int)JsonStoreNodeType.Value; | ||
231 | |||
232 | #endregion | ||
233 | |||
217 | #region ScriptInvocationInteface | 234 | #region ScriptInvocationInteface |
218 | // ----------------------------------------------------------------- | 235 | // ----------------------------------------------------------------- |
219 | /// <summary> | 236 | /// <summary> |
@@ -319,6 +336,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
319 | /// </summary> | 336 | /// </summary> |
320 | // ----------------------------------------------------------------- | 337 | // ----------------------------------------------------------------- |
321 | [ScriptInvocation] | 338 | [ScriptInvocation] |
339 | public int JsonPathType(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
340 | { | ||
341 | return (int)m_store.PathType(storeID,path); | ||
342 | } | ||
343 | |||
344 | [ScriptInvocation] | ||
322 | public int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path) | 345 | public int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path) |
323 | { | 346 | { |
324 | return m_store.TestPath(storeID,path,false) ? 1 : 0; | 347 | return m_store.TestPath(storeID,path,false) ? 1 : 0; |
@@ -364,6 +387,17 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
364 | /// </summary> | 387 | /// </summary> |
365 | // ----------------------------------------------------------------- | 388 | // ----------------------------------------------------------------- |
366 | [ScriptInvocation] | 389 | [ScriptInvocation] |
390 | public int JsonArrayLength(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
391 | { | ||
392 | return m_store.ArrayLength(storeID,path); | ||
393 | } | ||
394 | |||
395 | // ----------------------------------------------------------------- | ||
396 | /// <summary> | ||
397 | /// | ||
398 | /// </summary> | ||
399 | // ----------------------------------------------------------------- | ||
400 | [ScriptInvocation] | ||
367 | public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path) | 401 | public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path) |
368 | { | 402 | { |
369 | string value = String.Empty; | 403 | string value = String.Empty; |