1
0

UserProfilesHandlers.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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. using System;
  28. using System.Reflection;
  29. using OpenMetaverse;
  30. using OpenMetaverse.StructuredData;
  31. using log4net;
  32. using OpenSim.Services.Interfaces;
  33. using OpenSim.Framework.Servers.HttpServer;
  34. using OpenSim.Framework;
  35. namespace OpenSim.Server.Handlers
  36. {
  37. public class UserProfilesHandlers
  38. {
  39. public UserProfilesHandlers ()
  40. {
  41. }
  42. }
  43. public class JsonRpcProfileHandlers
  44. {
  45. static readonly ILog m_log =
  46. LogManager.GetLogger(
  47. MethodBase.GetCurrentMethod().DeclaringType);
  48. public IUserProfilesService Service
  49. {
  50. get; private set;
  51. }
  52. public JsonRpcProfileHandlers(IUserProfilesService service)
  53. {
  54. Service = service;
  55. }
  56. #region Classifieds
  57. /// <summary>
  58. /// Request avatar's classified ads.
  59. /// </summary>
  60. /// <returns>
  61. /// An array containing all the calassified uuid and it's name created by the creator id
  62. /// </returns>
  63. /// <param name='json'>
  64. /// Our parameters are in the OSDMap json["params"]
  65. /// </param>
  66. /// <param name='response'>
  67. /// If set to <c>true</c> response.
  68. /// </param>
  69. public bool AvatarClassifiedsRequest(OSDMap json, ref JsonRpcResponse response)
  70. {
  71. if(!json.ContainsKey("params"))
  72. {
  73. response.Error.Code = ErrorCode.ParseError;
  74. m_log.DebugFormat ("Classified Request");
  75. return false;
  76. }
  77. OSDMap request = (OSDMap)json["params"];
  78. UUID creatorId = new UUID(request["creatorId"].AsString());
  79. OSDArray data = (OSDArray) Service.AvatarClassifiedsRequest(creatorId);
  80. response.Result = data;
  81. return true;
  82. }
  83. public bool ClassifiedUpdate(OSDMap json, ref JsonRpcResponse response)
  84. {
  85. if(!json.ContainsKey("params"))
  86. {
  87. response.Error.Code = ErrorCode.ParseError;
  88. response.Error.Message = "Error parsing classified update request";
  89. m_log.DebugFormat ("Classified Update Request");
  90. return false;
  91. }
  92. string result = string.Empty;
  93. UserClassifiedAdd ad = new UserClassifiedAdd();
  94. object Ad = (object)ad;
  95. OSD.DeserializeMembers(ref Ad, (OSDMap)json["params"]);
  96. if(Service.ClassifiedUpdate(ad, ref result))
  97. {
  98. response.Result = OSD.SerializeMembers(ad);
  99. return true;
  100. }
  101. response.Error.Code = ErrorCode.InternalError;
  102. response.Error.Message = string.Format("{0}", result);
  103. return false;
  104. }
  105. public bool ClassifiedDelete(OSDMap json, ref JsonRpcResponse response)
  106. {
  107. if(!json.ContainsKey("params"))
  108. {
  109. response.Error.Code = ErrorCode.ParseError;
  110. m_log.DebugFormat ("Classified Delete Request");
  111. return false;
  112. }
  113. OSDMap request = (OSDMap)json["params"];
  114. UUID classifiedId = new UUID(request["classifiedId"].AsString());
  115. if (Service.ClassifiedDelete(classifiedId))
  116. return true;
  117. response.Error.Code = ErrorCode.InternalError;
  118. response.Error.Message = "data error removing record";
  119. return false;
  120. }
  121. public bool ClassifiedInfoRequest(OSDMap json, ref JsonRpcResponse response)
  122. {
  123. if(!json.ContainsKey("params"))
  124. {
  125. response.Error.Code = ErrorCode.ParseError;
  126. response.Error.Message = "no parameters supplied";
  127. m_log.DebugFormat ("Classified Info Request");
  128. return false;
  129. }
  130. string result = string.Empty;
  131. UserClassifiedAdd ad = new UserClassifiedAdd();
  132. object Ad = (object)ad;
  133. OSD.DeserializeMembers(ref Ad, (OSDMap)json["params"]);
  134. if(Service.ClassifiedInfoRequest(ref ad, ref result))
  135. {
  136. response.Result = OSD.SerializeMembers(ad);
  137. return true;
  138. }
  139. response.Error.Code = ErrorCode.InternalError;
  140. response.Error.Message = string.Format("{0}", result);
  141. return false;
  142. }
  143. #endregion Classifieds
  144. #region Picks
  145. public bool AvatarPicksRequest(OSDMap json, ref JsonRpcResponse response)
  146. {
  147. if(!json.ContainsKey("params"))
  148. {
  149. response.Error.Code = ErrorCode.ParseError;
  150. m_log.DebugFormat ("Avatar Picks Request");
  151. return false;
  152. }
  153. OSDMap request = (OSDMap)json["params"];
  154. UUID creatorId = new UUID(request["creatorId"].AsString());
  155. OSDArray data = (OSDArray) Service.AvatarPicksRequest(creatorId);
  156. response.Result = data;
  157. return true;
  158. }
  159. public bool PickInfoRequest(OSDMap json, ref JsonRpcResponse response)
  160. {
  161. if(!json.ContainsKey("params"))
  162. {
  163. response.Error.Code = ErrorCode.ParseError;
  164. response.Error.Message = "no parameters supplied";
  165. m_log.DebugFormat ("Avatar Picks Info Request");
  166. return false;
  167. }
  168. string result = string.Empty;
  169. UserProfilePick pick = new UserProfilePick();
  170. object Pick = (object)pick;
  171. OSD.DeserializeMembers(ref Pick, (OSDMap)json["params"]);
  172. if(Service.PickInfoRequest(ref pick, ref result))
  173. {
  174. response.Result = OSD.SerializeMembers(pick);
  175. return true;
  176. }
  177. response.Error.Code = ErrorCode.InternalError;
  178. response.Error.Message = string.Format("{0}", result);
  179. return false;
  180. }
  181. public bool PicksUpdate(OSDMap json, ref JsonRpcResponse response)
  182. {
  183. if(!json.ContainsKey("params"))
  184. {
  185. response.Error.Code = ErrorCode.ParseError;
  186. response.Error.Message = "no parameters supplied";
  187. m_log.DebugFormat ("Avatar Picks Update Request");
  188. return false;
  189. }
  190. string result = string.Empty;
  191. UserProfilePick pick = new UserProfilePick();
  192. object Pick = (object)pick;
  193. OSD.DeserializeMembers(ref Pick, (OSDMap)json["params"]);
  194. if(Service.PicksUpdate(ref pick, ref result))
  195. {
  196. response.Result = OSD.SerializeMembers(pick);
  197. return true;
  198. }
  199. response.Error.Code = ErrorCode.InternalError;
  200. response.Error.Message = "unable to update pick";
  201. return false;
  202. }
  203. public bool PicksDelete(OSDMap json, ref JsonRpcResponse response)
  204. {
  205. if(!json.ContainsKey("params"))
  206. {
  207. response.Error.Code = ErrorCode.ParseError;
  208. m_log.DebugFormat ("Avatar Picks Delete Request");
  209. return false;
  210. }
  211. OSDMap request = (OSDMap)json["params"];
  212. UUID pickId = new UUID(request["pickId"].AsString());
  213. if(Service.PicksDelete(pickId))
  214. return true;
  215. response.Error.Code = ErrorCode.InternalError;
  216. response.Error.Message = "data error removing record";
  217. return false;
  218. }
  219. #endregion Picks
  220. #region Notes
  221. public bool AvatarNotesRequest(OSDMap json, ref JsonRpcResponse response)
  222. {
  223. if(!json.ContainsKey("params"))
  224. {
  225. response.Error.Code = ErrorCode.ParseError;
  226. response.Error.Message = "Params missing";
  227. m_log.DebugFormat ("Avatar Notes Request");
  228. return false;
  229. }
  230. UserProfileNotes note = new UserProfileNotes();
  231. object Note = (object)note;
  232. OSD.DeserializeMembers(ref Note, (OSDMap)json["params"]);
  233. if(Service.AvatarNotesRequest(ref note))
  234. {
  235. response.Result = OSD.SerializeMembers(note);
  236. return true;
  237. }
  238. response.Error.Code = ErrorCode.InternalError;
  239. response.Error.Message = "Error reading notes";
  240. return false;
  241. }
  242. public bool NotesUpdate(OSDMap json, ref JsonRpcResponse response)
  243. {
  244. if(!json.ContainsKey("params"))
  245. {
  246. response.Error.Code = ErrorCode.ParseError;
  247. response.Error.Message = "No parameters";
  248. m_log.DebugFormat ("Avatar Notes Update Request");
  249. return false;
  250. }
  251. string result = string.Empty;
  252. UserProfileNotes note = new UserProfileNotes();
  253. object Notes = (object) note;
  254. OSD.DeserializeMembers(ref Notes, (OSDMap)json["params"]);
  255. if(Service.NotesUpdate(ref note, ref result))
  256. {
  257. response.Result = OSD.SerializeMembers(note);
  258. return true;
  259. }
  260. return true;
  261. }
  262. #endregion Notes
  263. #region Profile Properties
  264. public bool AvatarPropertiesRequest(OSDMap json, ref JsonRpcResponse response)
  265. {
  266. if(!json.ContainsKey("params"))
  267. {
  268. response.Error.Code = ErrorCode.ParseError;
  269. response.Error.Message = "no parameters supplied";
  270. m_log.DebugFormat ("Avatar Properties Request");
  271. return false;
  272. }
  273. string result = string.Empty;
  274. UserProfileProperties props = new UserProfileProperties();
  275. object Props = (object)props;
  276. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  277. if(Service.AvatarPropertiesRequest(ref props, ref result))
  278. {
  279. response.Result = OSD.SerializeMembers(props);
  280. return true;
  281. }
  282. response.Error.Code = ErrorCode.InternalError;
  283. response.Error.Message = string.Format("{0}", result);
  284. return false;
  285. }
  286. public bool AvatarPropertiesUpdate(OSDMap json, ref JsonRpcResponse response)
  287. {
  288. if(!json.ContainsKey("params"))
  289. {
  290. response.Error.Code = ErrorCode.ParseError;
  291. response.Error.Message = "no parameters supplied";
  292. m_log.DebugFormat ("Avatar Properties Update Request");
  293. return false;
  294. }
  295. string result = string.Empty;
  296. UserProfileProperties props = new UserProfileProperties();
  297. object Props = (object)props;
  298. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  299. if(Service.AvatarPropertiesUpdate(ref props, ref result))
  300. {
  301. response.Result = OSD.SerializeMembers(props);
  302. return true;
  303. }
  304. response.Error.Code = ErrorCode.InternalError;
  305. response.Error.Message = string.Format("{0}", result);
  306. return false;
  307. }
  308. #endregion Profile Properties
  309. #region Interests
  310. public bool AvatarInterestsUpdate(OSDMap json, ref JsonRpcResponse response)
  311. {
  312. if(!json.ContainsKey("params"))
  313. {
  314. response.Error.Code = ErrorCode.ParseError;
  315. response.Error.Message = "no parameters supplied";
  316. m_log.DebugFormat ("Avatar Interests Update Request");
  317. return false;
  318. }
  319. string result = string.Empty;
  320. UserProfileProperties props = new UserProfileProperties();
  321. object Props = (object)props;
  322. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  323. if(Service.AvatarInterestsUpdate(props, ref result))
  324. {
  325. response.Result = OSD.SerializeMembers(props);
  326. return true;
  327. }
  328. response.Error.Code = ErrorCode.InternalError;
  329. response.Error.Message = string.Format("{0}", result);
  330. return false;
  331. }
  332. #endregion Interests
  333. #region User Preferences
  334. public bool UserPreferencesRequest(OSDMap json, ref JsonRpcResponse response)
  335. {
  336. if(!json.ContainsKey("params"))
  337. {
  338. response.Error.Code = ErrorCode.ParseError;
  339. m_log.DebugFormat ("User Preferences Request");
  340. return false;
  341. }
  342. string result = string.Empty;
  343. UserPreferences prefs = new UserPreferences();
  344. object Prefs = (object)prefs;
  345. OSD.DeserializeMembers(ref Prefs, (OSDMap)json["params"]);
  346. if(Service.UserPreferencesRequest(ref prefs, ref result))
  347. {
  348. response.Result = OSD.SerializeMembers(prefs);
  349. return true;
  350. }
  351. response.Error.Code = ErrorCode.InternalError;
  352. response.Error.Message = string.Format("{0}", result);
  353. // m_log.InfoFormat("[PROFILES]: User preferences request error - {0}", response.Error.Message);
  354. return false;
  355. }
  356. public bool UserPreferenecesUpdate(OSDMap json, ref JsonRpcResponse response)
  357. {
  358. if(!json.ContainsKey("params"))
  359. {
  360. response.Error.Code = ErrorCode.ParseError;
  361. response.Error.Message = "no parameters supplied";
  362. m_log.DebugFormat ("User Preferences Update Request");
  363. return false;
  364. }
  365. string result = string.Empty;
  366. UserPreferences prefs = new UserPreferences();
  367. object Prefs = (object)prefs;
  368. OSD.DeserializeMembers(ref Prefs, (OSDMap)json["params"]);
  369. if(Service.UserPreferencesUpdate(ref prefs, ref result))
  370. {
  371. response.Result = OSD.SerializeMembers(prefs);
  372. return true;
  373. }
  374. response.Error.Code = ErrorCode.InternalError;
  375. response.Error.Message = string.Format("{0}", result);
  376. m_log.InfoFormat("[PROFILES]: User preferences update error - {0}", response.Error.Message);
  377. return false;
  378. }
  379. #endregion User Preferences
  380. #region Utility
  381. public bool AvatarImageAssetsRequest(OSDMap json, ref JsonRpcResponse response)
  382. {
  383. if(!json.ContainsKey("params"))
  384. {
  385. response.Error.Code = ErrorCode.ParseError;
  386. m_log.DebugFormat ("Avatar Image Assets Request");
  387. return false;
  388. }
  389. OSDMap request = (OSDMap)json["params"];
  390. UUID avatarId = new UUID(request["avatarId"].AsString());
  391. OSDArray data = (OSDArray) Service.AvatarImageAssetsRequest(avatarId);
  392. response.Result = data;
  393. return true;
  394. }
  395. #endregion Utiltiy
  396. #region UserData
  397. public bool RequestUserAppData(OSDMap json, ref JsonRpcResponse response)
  398. {
  399. if(!json.ContainsKey("params"))
  400. {
  401. response.Error.Code = ErrorCode.ParseError;
  402. response.Error.Message = "no parameters supplied";
  403. m_log.DebugFormat ("User Application Service URL Request: No Parameters!");
  404. return false;
  405. }
  406. string result = string.Empty;
  407. UserAppData props = new UserAppData();
  408. object Props = (object)props;
  409. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  410. if(Service.RequestUserAppData(ref props, ref result))
  411. {
  412. OSDMap res = new OSDMap();
  413. res["result"] = OSD.FromString("success");
  414. res["token"] = OSD.FromString (result);
  415. response.Result = res;
  416. return true;
  417. }
  418. response.Error.Code = ErrorCode.InternalError;
  419. response.Error.Message = string.Format("{0}", result);
  420. return false;
  421. }
  422. public bool UpdateUserAppData(OSDMap json, ref JsonRpcResponse response)
  423. {
  424. if(!json.ContainsKey("params"))
  425. {
  426. response.Error.Code = ErrorCode.ParseError;
  427. response.Error.Message = "no parameters supplied";
  428. m_log.DebugFormat ("User App Data Update Request");
  429. return false;
  430. }
  431. string result = string.Empty;
  432. UserAppData props = new UserAppData();
  433. object Props = (object)props;
  434. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  435. if(Service.SetUserAppData(props, ref result))
  436. {
  437. response.Result = OSD.SerializeMembers(props);
  438. return true;
  439. }
  440. response.Error.Code = ErrorCode.InternalError;
  441. response.Error.Message = string.Format("{0}", result);
  442. return false;
  443. }
  444. #endregion UserData
  445. }
  446. }