JsonStoreScriptModule.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. */
  27. using Mono.Addins;
  28. using System;
  29. using System.Reflection;
  30. using System.Threading;
  31. using System.Text;
  32. using System.Net;
  33. using System.Net.Sockets;
  34. using log4net;
  35. using Nini.Config;
  36. using OpenMetaverse;
  37. using OpenMetaverse.StructuredData;
  38. using OpenSim.Framework;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. using OpenSim.Region.Framework.Scenes.Scripting;
  42. using System.Collections.Generic;
  43. using System.Text.RegularExpressions;
  44. using PermissionMask = OpenSim.Framework.PermissionMask;
  45. namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
  46. {
  47. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreScriptModule")]
  48. public class JsonStoreScriptModule : INonSharedRegionModule
  49. {
  50. private static readonly ILog m_log =
  51. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  52. private IConfig m_config = null;
  53. private bool m_enabled = false;
  54. private Scene m_scene = null;
  55. private IScriptModuleComms m_comms;
  56. private IJsonStoreModule m_store;
  57. private Dictionary<UUID,HashSet<UUID>> m_scriptStores = new Dictionary<UUID,HashSet<UUID>>();
  58. #region Region Module interface
  59. // -----------------------------------------------------------------
  60. /// <summary>
  61. /// Name of this shared module is it's class name
  62. /// </summary>
  63. // -----------------------------------------------------------------
  64. public string Name
  65. {
  66. get { return this.GetType().Name; }
  67. }
  68. // -----------------------------------------------------------------
  69. /// <summary>
  70. /// Initialise this shared module
  71. /// </summary>
  72. /// <param name="scene">this region is getting initialised</param>
  73. /// <param name="source">nini config, we are not using this</param>
  74. // -----------------------------------------------------------------
  75. public void Initialise(IConfigSource config)
  76. {
  77. try
  78. {
  79. if ((m_config = config.Configs["JsonStore"]) == null)
  80. {
  81. // There is no configuration, the module is disabled
  82. // m_log.InfoFormat("[JsonStoreScripts] no configuration info");
  83. return;
  84. }
  85. m_enabled = m_config.GetBoolean("Enabled", m_enabled);
  86. }
  87. catch (Exception e)
  88. {
  89. m_log.ErrorFormat("[JsonStoreScripts]: initialization error: {0}", e.Message);
  90. return;
  91. }
  92. if (m_enabled)
  93. m_log.DebugFormat("[JsonStoreScripts]: module is enabled");
  94. }
  95. // -----------------------------------------------------------------
  96. /// <summary>
  97. /// everything is loaded, perform post load configuration
  98. /// </summary>
  99. // -----------------------------------------------------------------
  100. public void PostInitialise()
  101. {
  102. }
  103. // -----------------------------------------------------------------
  104. /// <summary>
  105. /// Nothing to do on close
  106. /// </summary>
  107. // -----------------------------------------------------------------
  108. public void Close()
  109. {
  110. }
  111. // -----------------------------------------------------------------
  112. /// <summary>
  113. /// </summary>
  114. // -----------------------------------------------------------------
  115. public void AddRegion(Scene scene)
  116. {
  117. scene.EventManager.OnScriptReset += HandleScriptReset;
  118. scene.EventManager.OnRemoveScript += HandleScriptReset;
  119. }
  120. // -----------------------------------------------------------------
  121. /// <summary>
  122. /// </summary>
  123. // -----------------------------------------------------------------
  124. public void RemoveRegion(Scene scene)
  125. {
  126. scene.EventManager.OnScriptReset -= HandleScriptReset;
  127. scene.EventManager.OnRemoveScript -= HandleScriptReset;
  128. // need to remove all references to the scene in the subscription
  129. // list to enable full garbage collection of the scene object
  130. }
  131. // -----------------------------------------------------------------
  132. /// <summary>
  133. /// </summary>
  134. // -----------------------------------------------------------------
  135. private void HandleScriptReset(uint localID, UUID itemID)
  136. {
  137. HashSet<UUID> stores;
  138. lock (m_scriptStores)
  139. {
  140. if (! m_scriptStores.TryGetValue(itemID, out stores))
  141. return;
  142. m_scriptStores.Remove(itemID);
  143. }
  144. foreach (UUID id in stores)
  145. m_store.DestroyStore(id);
  146. }
  147. // -----------------------------------------------------------------
  148. /// <summary>
  149. /// Called when all modules have been added for a region. This is
  150. /// where we hook up events
  151. /// </summary>
  152. // -----------------------------------------------------------------
  153. public void RegionLoaded(Scene scene)
  154. {
  155. if (m_enabled)
  156. {
  157. m_scene = scene;
  158. m_comms = m_scene.RequestModuleInterface<IScriptModuleComms>();
  159. if (m_comms == null)
  160. {
  161. m_log.ErrorFormat("[JsonStoreScripts]: ScriptModuleComms interface not defined");
  162. m_enabled = false;
  163. return;
  164. }
  165. m_store = m_scene.RequestModuleInterface<IJsonStoreModule>();
  166. if (m_store == null)
  167. {
  168. m_log.ErrorFormat("[JsonStoreScripts]: JsonModule interface not defined");
  169. m_enabled = false;
  170. return;
  171. }
  172. try
  173. {
  174. m_comms.RegisterScriptInvocations(this);
  175. m_comms.RegisterConstants(this);
  176. }
  177. catch (Exception e)
  178. {
  179. // See http://opensimulator.org/mantis/view.php?id=5971 for more information
  180. m_log.WarnFormat("[JsonStoreScripts]: script method registration failed; {0}", e.Message);
  181. m_enabled = false;
  182. }
  183. }
  184. }
  185. /// -----------------------------------------------------------------
  186. /// <summary>
  187. /// </summary>
  188. // -----------------------------------------------------------------
  189. public Type ReplaceableInterface
  190. {
  191. get { return null; }
  192. }
  193. #endregion
  194. #region ScriptConstantsInterface
  195. [ScriptConstant]
  196. public static readonly int JSON_NODETYPE_UNDEF = (int)JsonStoreNodeType.Undefined;
  197. [ScriptConstant]
  198. public static readonly int JSON_NODETYPE_OBJECT = (int)JsonStoreNodeType.Object;
  199. [ScriptConstant]
  200. public static readonly int JSON_NODETYPE_ARRAY = (int)JsonStoreNodeType.Array;
  201. [ScriptConstant]
  202. public static readonly int JSON_NODETYPE_VALUE = (int)JsonStoreNodeType.Value;
  203. [ScriptConstant]
  204. public static readonly int JSON_VALUETYPE_UNDEF = (int)JsonStoreValueType.Undefined;
  205. [ScriptConstant]
  206. public static readonly int JSON_VALUETYPE_BOOLEAN = (int)JsonStoreValueType.Boolean;
  207. [ScriptConstant]
  208. public static readonly int JSON_VALUETYPE_INTEGER = (int)JsonStoreValueType.Integer;
  209. [ScriptConstant]
  210. public static readonly int JSON_VALUETYPE_FLOAT = (int)JsonStoreValueType.Float;
  211. [ScriptConstant]
  212. public static readonly int JSON_VALUETYPE_STRING = (int)JsonStoreValueType.String;
  213. #endregion
  214. #region ScriptInvocationInteface
  215. // -----------------------------------------------------------------
  216. /// <summary>
  217. ///
  218. /// </summary>
  219. // -----------------------------------------------------------------
  220. [ScriptInvocation]
  221. public UUID JsonAttachObjectStore(UUID hostID, UUID scriptID)
  222. {
  223. UUID uuid = UUID.Zero;
  224. if (! m_store.AttachObjectStore(hostID))
  225. GenerateRuntimeError("Failed to create Json store");
  226. return hostID;
  227. }
  228. // -----------------------------------------------------------------
  229. /// <summary>
  230. ///
  231. /// </summary>
  232. // -----------------------------------------------------------------
  233. [ScriptInvocation]
  234. public UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
  235. {
  236. UUID uuid = UUID.Zero;
  237. if (! m_store.CreateStore(value, ref uuid))
  238. GenerateRuntimeError("Failed to create Json store");
  239. lock (m_scriptStores)
  240. {
  241. if (! m_scriptStores.ContainsKey(scriptID))
  242. m_scriptStores[scriptID] = new HashSet<UUID>();
  243. m_scriptStores[scriptID].Add(uuid);
  244. }
  245. return uuid;
  246. }
  247. // -----------------------------------------------------------------
  248. /// <summary>
  249. ///
  250. /// </summary>
  251. // -----------------------------------------------------------------
  252. [ScriptInvocation]
  253. public int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID)
  254. {
  255. lock(m_scriptStores)
  256. {
  257. if (m_scriptStores.ContainsKey(scriptID))
  258. m_scriptStores[scriptID].Remove(storeID);
  259. }
  260. return m_store.DestroyStore(storeID) ? 1 : 0;
  261. }
  262. // -----------------------------------------------------------------
  263. /// <summary>
  264. ///
  265. /// </summary>
  266. // -----------------------------------------------------------------
  267. [ScriptInvocation]
  268. public int JsonTestStore(UUID hostID, UUID scriptID, UUID storeID)
  269. {
  270. return m_store.TestStore(storeID) ? 1 : 0;
  271. }
  272. // -----------------------------------------------------------------
  273. /// <summary>
  274. ///
  275. /// </summary>
  276. // -----------------------------------------------------------------
  277. [ScriptInvocation]
  278. public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier)
  279. {
  280. UUID reqID = UUID.Random();
  281. Util.FireAndForget(o => DoJsonReadNotecard(reqID, hostID, scriptID, storeID, path, notecardIdentifier));
  282. return reqID;
  283. }
  284. // -----------------------------------------------------------------
  285. /// <summary>
  286. ///
  287. /// </summary>
  288. // -----------------------------------------------------------------
  289. [ScriptInvocation]
  290. public UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name)
  291. {
  292. UUID reqID = UUID.Random();
  293. Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); });
  294. return reqID;
  295. }
  296. // -----------------------------------------------------------------
  297. /// <summary>
  298. ///
  299. /// </summary>
  300. // -----------------------------------------------------------------
  301. [ScriptInvocation]
  302. public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist)
  303. {
  304. string ipath = ConvertList2Path(pathlist);
  305. string opath;
  306. if (JsonStore.CanonicalPathExpression(ipath,out opath))
  307. return opath;
  308. // This won't parse if passed to the other routines as opposed to
  309. // returning an empty string which is a valid path and would overwrite
  310. // the entire store
  311. return "**INVALID**";
  312. }
  313. // -----------------------------------------------------------------
  314. /// <summary>
  315. ///
  316. /// </summary>
  317. // -----------------------------------------------------------------
  318. [ScriptInvocation]
  319. public int JsonGetNodeType(UUID hostID, UUID scriptID, UUID storeID, string path)
  320. {
  321. return (int)m_store.GetNodeType(storeID,path);
  322. }
  323. // -----------------------------------------------------------------
  324. /// <summary>
  325. ///
  326. /// </summary>
  327. // -----------------------------------------------------------------
  328. [ScriptInvocation]
  329. public int JsonGetValueType(UUID hostID, UUID scriptID, UUID storeID, string path)
  330. {
  331. return (int)m_store.GetValueType(storeID,path);
  332. }
  333. // -----------------------------------------------------------------
  334. /// <summary>
  335. ///
  336. /// </summary>
  337. // -----------------------------------------------------------------
  338. [ScriptInvocation]
  339. public int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
  340. {
  341. return m_store.SetValue(storeID,path,value,false) ? 1 : 0;
  342. }
  343. [ScriptInvocation]
  344. public int JsonSetJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
  345. {
  346. return m_store.SetValue(storeID,path,value,true) ? 1 : 0;
  347. }
  348. // -----------------------------------------------------------------
  349. /// <summary>
  350. ///
  351. /// </summary>
  352. // -----------------------------------------------------------------
  353. [ScriptInvocation]
  354. public int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path)
  355. {
  356. return m_store.RemoveValue(storeID,path) ? 1 : 0;
  357. }
  358. // -----------------------------------------------------------------
  359. /// <summary>
  360. ///
  361. /// </summary>
  362. // -----------------------------------------------------------------
  363. [ScriptInvocation]
  364. public int JsonGetArrayLength(UUID hostID, UUID scriptID, UUID storeID, string path)
  365. {
  366. return m_store.GetArrayLength(storeID,path);
  367. }
  368. // -----------------------------------------------------------------
  369. /// <summary>
  370. ///
  371. /// </summary>
  372. // -----------------------------------------------------------------
  373. [ScriptInvocation]
  374. public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
  375. {
  376. string value = String.Empty;
  377. m_store.GetValue(storeID,path,false,out value);
  378. return value;
  379. }
  380. [ScriptInvocation]
  381. public string JsonGetJson(UUID hostID, UUID scriptID, UUID storeID, string path)
  382. {
  383. string value = String.Empty;
  384. m_store.GetValue(storeID,path,true, out value);
  385. return value;
  386. }
  387. // -----------------------------------------------------------------
  388. /// <summary>
  389. ///
  390. /// </summary>
  391. // -----------------------------------------------------------------
  392. [ScriptInvocation]
  393. public UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path)
  394. {
  395. UUID reqID = UUID.Random();
  396. Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); });
  397. return reqID;
  398. }
  399. [ScriptInvocation]
  400. public UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
  401. {
  402. UUID reqID = UUID.Random();
  403. Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); });
  404. return reqID;
  405. }
  406. // -----------------------------------------------------------------
  407. /// <summary>
  408. ///
  409. /// </summary>
  410. // -----------------------------------------------------------------
  411. [ScriptInvocation]
  412. public UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path)
  413. {
  414. UUID reqID = UUID.Random();
  415. Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); });
  416. return reqID;
  417. }
  418. [ScriptInvocation]
  419. public UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
  420. {
  421. UUID reqID = UUID.Random();
  422. Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); });
  423. return reqID;
  424. }
  425. #endregion
  426. // -----------------------------------------------------------------
  427. /// <summary>
  428. ///
  429. /// </summary>
  430. // -----------------------------------------------------------------
  431. protected void GenerateRuntimeError(string msg)
  432. {
  433. m_log.InfoFormat("[JsonStore] runtime error: {0}",msg);
  434. throw new Exception("JsonStore Runtime Error: " + msg);
  435. }
  436. // -----------------------------------------------------------------
  437. /// <summary>
  438. ///
  439. /// </summary>
  440. // -----------------------------------------------------------------
  441. protected void DispatchValue(UUID scriptID, UUID reqID, string value)
  442. {
  443. m_comms.DispatchReply(scriptID,1,value,reqID.ToString());
  444. }
  445. // -----------------------------------------------------------------
  446. /// <summary>
  447. ///
  448. /// </summary>
  449. // -----------------------------------------------------------------
  450. private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
  451. {
  452. try
  453. {
  454. m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
  455. return;
  456. }
  457. catch (Exception e)
  458. {
  459. m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
  460. }
  461. DispatchValue(scriptID,reqID,String.Empty);
  462. }
  463. // -----------------------------------------------------------------
  464. /// <summary>
  465. ///
  466. /// </summary>
  467. // -----------------------------------------------------------------
  468. private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
  469. {
  470. try
  471. {
  472. m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
  473. return;
  474. }
  475. catch (Exception e)
  476. {
  477. m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
  478. }
  479. DispatchValue(scriptID,reqID,String.Empty);
  480. }
  481. // -----------------------------------------------------------------
  482. /// <summary>
  483. ///
  484. /// </summary>
  485. // -----------------------------------------------------------------
  486. private void DoJsonReadNotecard(
  487. UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier)
  488. {
  489. UUID assetID;
  490. if (!UUID.TryParse(notecardIdentifier, out assetID))
  491. {
  492. SceneObjectPart part = m_scene.GetSceneObjectPart(hostID);
  493. assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard);
  494. }
  495. AssetBase a = m_scene.AssetService.Get(assetID.ToString());
  496. if (a == null)
  497. GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID));
  498. if (a.Type != (sbyte)AssetType.Notecard)
  499. GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID));
  500. m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}",storeID);
  501. try
  502. {
  503. string jsondata = SLUtil.ParseNotecardToString(Encoding.UTF8.GetString(a.Data));
  504. int result = m_store.SetValue(storeID, path, jsondata,true) ? 1 : 0;
  505. m_comms.DispatchReply(scriptID, result, "", reqID.ToString());
  506. return;
  507. }
  508. catch (Exception e)
  509. {
  510. m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message);
  511. }
  512. GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID));
  513. m_comms.DispatchReply(scriptID, 0, "", reqID.ToString());
  514. }
  515. // -----------------------------------------------------------------
  516. /// <summary>
  517. ///
  518. /// </summary>
  519. // -----------------------------------------------------------------
  520. private void DoJsonWriteNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string name)
  521. {
  522. string data;
  523. if (! m_store.GetValue(storeID,path,true, out data))
  524. {
  525. m_comms.DispatchReply(scriptID,0,UUID.Zero.ToString(),reqID.ToString());
  526. return;
  527. }
  528. SceneObjectPart host = m_scene.GetSceneObjectPart(hostID);
  529. // Create new asset
  530. UUID assetID = UUID.Random();
  531. AssetBase asset = new AssetBase(assetID, name, (sbyte)AssetType.Notecard, host.OwnerID.ToString());
  532. asset.Description = "Json store";
  533. int textLength = data.Length;
  534. data = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
  535. + textLength.ToString() + "\n" + data + "}\n";
  536. asset.Data = Util.UTF8.GetBytes(data);
  537. m_scene.AssetService.Store(asset);
  538. // Create Task Entry
  539. TaskInventoryItem taskItem = new TaskInventoryItem();
  540. taskItem.ResetIDs(host.UUID);
  541. taskItem.ParentID = host.UUID;
  542. taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
  543. taskItem.Name = asset.Name;
  544. taskItem.Description = asset.Description;
  545. taskItem.Type = (int)AssetType.Notecard;
  546. taskItem.InvType = (int)InventoryType.Notecard;
  547. taskItem.OwnerID = host.OwnerID;
  548. taskItem.CreatorID = host.OwnerID;
  549. taskItem.BasePermissions = (uint)PermissionMask.All;
  550. taskItem.CurrentPermissions = (uint)PermissionMask.All;
  551. taskItem.EveryonePermissions = 0;
  552. taskItem.NextPermissions = (uint)PermissionMask.All;
  553. taskItem.GroupID = host.GroupID;
  554. taskItem.GroupPermissions = 0;
  555. taskItem.Flags = 0;
  556. taskItem.PermsGranter = UUID.Zero;
  557. taskItem.PermsMask = 0;
  558. taskItem.AssetID = asset.FullID;
  559. host.Inventory.AddInventoryItem(taskItem, false);
  560. m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString());
  561. }
  562. // -----------------------------------------------------------------
  563. /// <summary>
  564. /// Convert a list of values that are path components to a single string path
  565. /// </summary>
  566. // -----------------------------------------------------------------
  567. protected static Regex m_ArrayPattern = new Regex("^([0-9]+|\\+)$");
  568. private string ConvertList2Path(object[] pathlist)
  569. {
  570. string path = "";
  571. for (int i = 0; i < pathlist.Length; i++)
  572. {
  573. string token = "";
  574. if (pathlist[i] is string)
  575. {
  576. token = pathlist[i].ToString();
  577. // Check to see if this is a bare number which would not be a valid
  578. // identifier otherwise
  579. if (m_ArrayPattern.IsMatch(token))
  580. token = '[' + token + ']';
  581. }
  582. else if (pathlist[i] is int)
  583. {
  584. token = "[" + pathlist[i].ToString() + "]";
  585. }
  586. else
  587. {
  588. token = "." + pathlist[i].ToString() + ".";
  589. }
  590. path += token + ".";
  591. }
  592. return path;
  593. }
  594. }
  595. }