1
0

UserProfilesHandlers.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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. OSD tmpParams;
  86. if(!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
  87. {
  88. response.Error.Code = ErrorCode.ParseError;
  89. response.Error.Message = "Error parsing classified update request";
  90. m_log.DebugFormat ("Classified Update Request");
  91. return false;
  92. }
  93. string result = string.Empty;
  94. UserClassifiedAdd ad = new UserClassifiedAdd();
  95. object Ad = ad;
  96. OSD.DeserializeMembers(ref Ad, (OSDMap)tmpParams);
  97. //If no maturity bits are set, set PG maturity bit. This works
  98. // around a viewer bug. It simplifies the ability to search ads
  99. // based on maturity level. 0x4e is bits 1 (old viewers mature), 2 (pg), 3 (Mature) and 6 (Adult).
  100. if ((ad.Flags & 0x4e) == 0)
  101. ad.Flags |= 0x04;
  102. if (Service.ClassifiedUpdate(ad, ref result))
  103. {
  104. response.Result = OSD.SerializeMembers(ad);
  105. return true;
  106. }
  107. response.Error.Code = ErrorCode.InternalError;
  108. response.Error.Message = string.Format("{0}", result);
  109. return false;
  110. }
  111. public bool ClassifiedDelete(OSDMap json, ref JsonRpcResponse response)
  112. {
  113. if(!json.ContainsKey("params"))
  114. {
  115. response.Error.Code = ErrorCode.ParseError;
  116. m_log.DebugFormat ("Classified Delete Request");
  117. return false;
  118. }
  119. OSDMap request = (OSDMap)json["params"];
  120. UUID classifiedId = new UUID(request["classifiedId"].AsString());
  121. if (Service.ClassifiedDelete(classifiedId))
  122. return true;
  123. response.Error.Code = ErrorCode.InternalError;
  124. response.Error.Message = "data error removing record";
  125. return false;
  126. }
  127. public bool ClassifiedInfoRequest(OSDMap json, ref JsonRpcResponse response)
  128. {
  129. OSD tmpParams;
  130. if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
  131. {
  132. response.Error.Code = ErrorCode.ParseError;
  133. response.Error.Message = "no parameters supplied";
  134. m_log.DebugFormat ("Classified Info Request");
  135. return false;
  136. }
  137. string result = string.Empty;
  138. UserClassifiedAdd ad = new UserClassifiedAdd();
  139. object Ad = (object)ad;
  140. OSD.DeserializeMembers(ref Ad, (OSDMap)tmpParams);
  141. if(Service.ClassifiedInfoRequest(ref ad, ref result))
  142. {
  143. //If no maturity bits are set, set PG maturity bit. This works
  144. // around a viewer bug. It simplifies the ability to search ads
  145. // based on maturity level. 0x4e is bits 1 (old viewers mature), 2 (pg), 3 (Mature) and 6 (Adult).
  146. if ((ad.Flags & 0x4e) == 0)
  147. ad.Flags |= 0x04;
  148. response.Result = OSD.SerializeMembers(ad);
  149. return true;
  150. }
  151. response.Error.Code = ErrorCode.InternalError;
  152. response.Error.Message = string.Format("{0}", result);
  153. return false;
  154. }
  155. #endregion Classifieds
  156. #region Picks
  157. public bool AvatarPicksRequest(OSDMap json, ref JsonRpcResponse response)
  158. {
  159. OSD tmpParams;
  160. if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
  161. {
  162. response.Error.Code = ErrorCode.ParseError;
  163. m_log.DebugFormat ("Avatar Picks Request");
  164. return false;
  165. }
  166. OSDMap request = (OSDMap)tmpParams;
  167. UUID creatorId = new UUID(request["creatorId"].AsString());
  168. OSDArray data = (OSDArray) Service.AvatarPicksRequest(creatorId);
  169. response.Result = data;
  170. return true;
  171. }
  172. public bool PickInfoRequest(OSDMap json, ref JsonRpcResponse response)
  173. {
  174. OSD tmpParams;
  175. if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
  176. {
  177. response.Error.Code = ErrorCode.ParseError;
  178. response.Error.Message = "no parameters supplied";
  179. m_log.DebugFormat ("Avatar Picks Info Request");
  180. return false;
  181. }
  182. string result = string.Empty;
  183. UserProfilePick pick = new UserProfilePick();
  184. object Pick = (object)pick;
  185. OSD.DeserializeMembers(ref Pick, (OSDMap)tmpParams);
  186. if(Service.PickInfoRequest(ref pick, ref result))
  187. {
  188. response.Result = OSD.SerializeMembers(pick);
  189. return true;
  190. }
  191. response.Error.Code = ErrorCode.InternalError;
  192. response.Error.Message = string.Format("{0}", result);
  193. return false;
  194. }
  195. public bool PicksUpdate(OSDMap json, ref JsonRpcResponse response)
  196. {
  197. OSD tmpParams;
  198. if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
  199. {
  200. response.Error.Code = ErrorCode.ParseError;
  201. response.Error.Message = "no parameters supplied";
  202. m_log.DebugFormat ("Avatar Picks Update Request");
  203. return false;
  204. }
  205. string result = string.Empty;
  206. UserProfilePick pick = new UserProfilePick();
  207. object Pick = (object)pick;
  208. OSD.DeserializeMembers(ref Pick, (OSDMap)tmpParams);
  209. if(Service.PicksUpdate(ref pick, ref result))
  210. {
  211. response.Result = OSD.SerializeMembers(pick);
  212. return true;
  213. }
  214. response.Error.Code = ErrorCode.InternalError;
  215. response.Error.Message = "unable to update pick";
  216. return false;
  217. }
  218. public bool PicksDelete(OSDMap json, ref JsonRpcResponse response)
  219. {
  220. OSD tmpParams;
  221. if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
  222. {
  223. response.Error.Code = ErrorCode.ParseError;
  224. m_log.DebugFormat ("Avatar Picks Delete Request");
  225. return false;
  226. }
  227. OSDMap request = tmpParams as OSDMap;
  228. UUID pickId = new UUID(request["pickId"].AsString());
  229. if(Service.PicksDelete(pickId))
  230. return true;
  231. response.Error.Code = ErrorCode.InternalError;
  232. response.Error.Message = "data error removing record";
  233. return false;
  234. }
  235. #endregion Picks
  236. #region Notes
  237. public bool AvatarNotesRequest(OSDMap json, ref JsonRpcResponse response)
  238. {
  239. OSD tmpParams;
  240. if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
  241. {
  242. response.Error.Code = ErrorCode.ParseError;
  243. response.Error.Message = "Params missing";
  244. m_log.DebugFormat ("Avatar Notes Request");
  245. return false;
  246. }
  247. UserProfileNotes note = new UserProfileNotes();
  248. object Note = (object)note;
  249. OSD.DeserializeMembers(ref Note, (OSDMap)tmpParams);
  250. if(Service.AvatarNotesRequest(ref note))
  251. {
  252. response.Result = OSD.SerializeMembers(note);
  253. return true;
  254. }
  255. response.Error.Code = ErrorCode.InternalError;
  256. response.Error.Message = "Error reading notes";
  257. return false;
  258. }
  259. public bool NotesUpdate(OSDMap json, ref JsonRpcResponse response)
  260. {
  261. OSD tmpParams;
  262. if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
  263. {
  264. response.Error.Code = ErrorCode.ParseError;
  265. response.Error.Message = "No parameters";
  266. m_log.DebugFormat ("Avatar Notes Update Request");
  267. return false;
  268. }
  269. string result = string.Empty;
  270. UserProfileNotes note = new UserProfileNotes();
  271. object Notes = (object) note;
  272. OSD.DeserializeMembers(ref Notes, (OSDMap)tmpParams);
  273. if(Service.NotesUpdate(ref note, ref result))
  274. {
  275. response.Result = OSD.SerializeMembers(note);
  276. return true;
  277. }
  278. return true;
  279. }
  280. #endregion Notes
  281. #region Profile Properties
  282. public bool AvatarPropertiesRequest(OSDMap json, ref JsonRpcResponse response)
  283. {
  284. if(!json.ContainsKey("params"))
  285. {
  286. response.Error.Code = ErrorCode.ParseError;
  287. response.Error.Message = "no parameters supplied";
  288. m_log.DebugFormat ("Avatar Properties Request");
  289. return false;
  290. }
  291. string result = string.Empty;
  292. UserProfileProperties props = new UserProfileProperties();
  293. object Props = (object)props;
  294. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  295. if(Service.AvatarPropertiesRequest(ref props, ref result))
  296. {
  297. response.Result = OSD.SerializeMembers(props);
  298. return true;
  299. }
  300. response.Error.Code = ErrorCode.InternalError;
  301. response.Error.Message = string.Format("{0}", result);
  302. return false;
  303. }
  304. public bool AvatarPropertiesUpdate(OSDMap json, ref JsonRpcResponse response)
  305. {
  306. if(!json.ContainsKey("params"))
  307. {
  308. response.Error.Code = ErrorCode.ParseError;
  309. response.Error.Message = "no parameters supplied";
  310. m_log.DebugFormat ("Avatar Properties Update Request");
  311. return false;
  312. }
  313. string result = string.Empty;
  314. UserProfileProperties props = new UserProfileProperties();
  315. object Props = (object)props;
  316. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  317. if(Service.AvatarPropertiesUpdate(ref props, ref result))
  318. {
  319. response.Result = OSD.SerializeMembers(props);
  320. return true;
  321. }
  322. response.Error.Code = ErrorCode.InternalError;
  323. response.Error.Message = string.Format("{0}", result);
  324. return false;
  325. }
  326. #endregion Profile Properties
  327. #region Interests
  328. public bool AvatarInterestsUpdate(OSDMap json, ref JsonRpcResponse response)
  329. {
  330. if(!json.ContainsKey("params"))
  331. {
  332. response.Error.Code = ErrorCode.ParseError;
  333. response.Error.Message = "no parameters supplied";
  334. m_log.DebugFormat ("Avatar Interests Update Request");
  335. return false;
  336. }
  337. string result = string.Empty;
  338. UserProfileProperties props = new UserProfileProperties();
  339. object Props = (object)props;
  340. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  341. if(Service.AvatarInterestsUpdate(props, ref result))
  342. {
  343. response.Result = OSD.SerializeMembers(props);
  344. return true;
  345. }
  346. response.Error.Code = ErrorCode.InternalError;
  347. response.Error.Message = string.Format("{0}", result);
  348. return false;
  349. }
  350. #endregion Interests
  351. #region User Preferences
  352. public bool UserPreferencesRequest(OSDMap json, ref JsonRpcResponse response)
  353. {
  354. if(!json.ContainsKey("params"))
  355. {
  356. response.Error.Code = ErrorCode.ParseError;
  357. m_log.DebugFormat ("User Preferences Request");
  358. return false;
  359. }
  360. string result = string.Empty;
  361. UserPreferences prefs = new UserPreferences();
  362. object Prefs = (object)prefs;
  363. OSD.DeserializeMembers(ref Prefs, (OSDMap)json["params"]);
  364. if(Service.UserPreferencesRequest(ref prefs, ref result))
  365. {
  366. response.Result = OSD.SerializeMembers(prefs);
  367. return true;
  368. }
  369. response.Error.Code = ErrorCode.InternalError;
  370. response.Error.Message = string.Format("{0}", result);
  371. // m_log.InfoFormat("[PROFILES]: User preferences request error - {0}", response.Error.Message);
  372. return false;
  373. }
  374. public bool UserPreferenecesUpdate(OSDMap json, ref JsonRpcResponse response)
  375. {
  376. if(!json.ContainsKey("params"))
  377. {
  378. response.Error.Code = ErrorCode.ParseError;
  379. response.Error.Message = "no parameters supplied";
  380. m_log.DebugFormat ("User Preferences Update Request");
  381. return false;
  382. }
  383. string result = string.Empty;
  384. UserPreferences prefs = new UserPreferences();
  385. object Prefs = (object)prefs;
  386. OSD.DeserializeMembers(ref Prefs, (OSDMap)json["params"]);
  387. if(Service.UserPreferencesUpdate(ref prefs, ref result))
  388. {
  389. response.Result = OSD.SerializeMembers(prefs);
  390. return true;
  391. }
  392. response.Error.Code = ErrorCode.InternalError;
  393. response.Error.Message = string.Format("{0}", result);
  394. m_log.InfoFormat("[PROFILES]: User preferences update error - {0}", response.Error.Message);
  395. return false;
  396. }
  397. #endregion User Preferences
  398. #region Utility
  399. public bool AvatarImageAssetsRequest(OSDMap json, ref JsonRpcResponse response)
  400. {
  401. if(!json.ContainsKey("params"))
  402. {
  403. response.Error.Code = ErrorCode.ParseError;
  404. m_log.DebugFormat ("Avatar Image Assets Request");
  405. return false;
  406. }
  407. OSDMap request = (OSDMap)json["params"];
  408. UUID avatarId = new UUID(request["avatarId"].AsString());
  409. OSDArray data = (OSDArray) Service.AvatarImageAssetsRequest(avatarId);
  410. response.Result = data;
  411. return true;
  412. }
  413. #endregion Utiltiy
  414. #region UserData
  415. public bool RequestUserAppData(OSDMap json, ref JsonRpcResponse response)
  416. {
  417. if(!json.ContainsKey("params"))
  418. {
  419. response.Error.Code = ErrorCode.ParseError;
  420. response.Error.Message = "no parameters supplied";
  421. m_log.DebugFormat ("User Application Service URL Request: No Parameters!");
  422. return false;
  423. }
  424. string result = string.Empty;
  425. UserAppData props = new UserAppData();
  426. object Props = (object)props;
  427. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  428. if(Service.RequestUserAppData(ref props, ref result))
  429. {
  430. OSDMap res = new OSDMap();
  431. res["result"] = OSD.FromString("success");
  432. res["token"] = OSD.FromString (result);
  433. response.Result = res;
  434. return true;
  435. }
  436. response.Error.Code = ErrorCode.InternalError;
  437. response.Error.Message = string.Format("{0}", result);
  438. return false;
  439. }
  440. public bool UpdateUserAppData(OSDMap json, ref JsonRpcResponse response)
  441. {
  442. if(!json.ContainsKey("params"))
  443. {
  444. response.Error.Code = ErrorCode.ParseError;
  445. response.Error.Message = "no parameters supplied";
  446. m_log.DebugFormat ("User App Data Update Request");
  447. return false;
  448. }
  449. string result = string.Empty;
  450. UserAppData props = new UserAppData();
  451. object Props = (object)props;
  452. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  453. if(Service.SetUserAppData(props, ref result))
  454. {
  455. response.Result = OSD.SerializeMembers(props);
  456. return true;
  457. }
  458. response.Error.Code = ErrorCode.InternalError;
  459. response.Error.Message = string.Format("{0}", result);
  460. return false;
  461. }
  462. #endregion UserData
  463. }
  464. }