1
0

UserProfilesHandlers.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. OSDMap res = new OSDMap();
  116. res["result"] = OSD.FromString("success");
  117. response.Result = res;
  118. return true;
  119. }
  120. public bool ClassifiedInfoRequest(OSDMap json, ref JsonRpcResponse response)
  121. {
  122. if(!json.ContainsKey("params"))
  123. {
  124. response.Error.Code = ErrorCode.ParseError;
  125. response.Error.Message = "no parameters supplied";
  126. m_log.DebugFormat ("Classified Info Request");
  127. return false;
  128. }
  129. string result = string.Empty;
  130. UserClassifiedAdd ad = new UserClassifiedAdd();
  131. object Ad = (object)ad;
  132. OSD.DeserializeMembers(ref Ad, (OSDMap)json["params"]);
  133. if(Service.ClassifiedInfoRequest(ref ad, ref result))
  134. {
  135. response.Result = OSD.SerializeMembers(ad);
  136. return true;
  137. }
  138. response.Error.Code = ErrorCode.InternalError;
  139. response.Error.Message = string.Format("{0}", result);
  140. return false;
  141. }
  142. #endregion Classifieds
  143. #region Picks
  144. public bool AvatarPicksRequest(OSDMap json, ref JsonRpcResponse response)
  145. {
  146. if(!json.ContainsKey("params"))
  147. {
  148. response.Error.Code = ErrorCode.ParseError;
  149. m_log.DebugFormat ("Avatar Picks Request");
  150. return false;
  151. }
  152. OSDMap request = (OSDMap)json["params"];
  153. UUID creatorId = new UUID(request["creatorId"].AsString());
  154. OSDArray data = (OSDArray) Service.AvatarPicksRequest(creatorId);
  155. response.Result = data;
  156. return true;
  157. }
  158. public bool PickInfoRequest(OSDMap json, ref JsonRpcResponse response)
  159. {
  160. if(!json.ContainsKey("params"))
  161. {
  162. response.Error.Code = ErrorCode.ParseError;
  163. response.Error.Message = "no parameters supplied";
  164. m_log.DebugFormat ("Avatar Picks Info Request");
  165. return false;
  166. }
  167. string result = string.Empty;
  168. UserProfilePick pick = new UserProfilePick();
  169. object Pick = (object)pick;
  170. OSD.DeserializeMembers(ref Pick, (OSDMap)json["params"]);
  171. if(Service.PickInfoRequest(ref pick, ref result))
  172. {
  173. response.Result = OSD.SerializeMembers(pick);
  174. return true;
  175. }
  176. response.Error.Code = ErrorCode.InternalError;
  177. response.Error.Message = string.Format("{0}", result);
  178. return false;
  179. }
  180. public bool PicksUpdate(OSDMap json, ref JsonRpcResponse response)
  181. {
  182. if(!json.ContainsKey("params"))
  183. {
  184. response.Error.Code = ErrorCode.ParseError;
  185. response.Error.Message = "no parameters supplied";
  186. m_log.DebugFormat ("Avatar Picks Update Request");
  187. return false;
  188. }
  189. string result = string.Empty;
  190. UserProfilePick pick = new UserProfilePick();
  191. object Pick = (object)pick;
  192. OSD.DeserializeMembers(ref Pick, (OSDMap)json["params"]);
  193. if(Service.PicksUpdate(ref pick, ref result))
  194. {
  195. response.Result = OSD.SerializeMembers(pick);
  196. return true;
  197. }
  198. response.Error.Code = ErrorCode.InternalError;
  199. response.Error.Message = "unable to update pick";
  200. return false;
  201. }
  202. public bool PicksDelete(OSDMap json, ref JsonRpcResponse response)
  203. {
  204. if(!json.ContainsKey("params"))
  205. {
  206. response.Error.Code = ErrorCode.ParseError;
  207. m_log.DebugFormat ("Avatar Picks Delete Request");
  208. return false;
  209. }
  210. OSDMap request = (OSDMap)json["params"];
  211. UUID pickId = new UUID(request["pickId"].AsString());
  212. if(Service.PicksDelete(pickId))
  213. return true;
  214. response.Error.Code = ErrorCode.InternalError;
  215. response.Error.Message = "data error removing record";
  216. return false;
  217. }
  218. #endregion Picks
  219. #region Notes
  220. public bool AvatarNotesRequest(OSDMap json, ref JsonRpcResponse response)
  221. {
  222. if(!json.ContainsKey("params"))
  223. {
  224. response.Error.Code = ErrorCode.ParseError;
  225. response.Error.Message = "Params missing";
  226. m_log.DebugFormat ("Avatar Notes Request");
  227. return false;
  228. }
  229. string result = string.Empty;
  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. object Notes = (object) note;
  239. OSD.DeserializeMembers(ref Notes, (OSDMap)json["params"]);
  240. return true;
  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 Utility
  334. public bool AvatarImageAssetsRequest(OSDMap json, ref JsonRpcResponse response)
  335. {
  336. if(!json.ContainsKey("params"))
  337. {
  338. response.Error.Code = ErrorCode.ParseError;
  339. m_log.DebugFormat ("Avatar Image Assets Request");
  340. return false;
  341. }
  342. OSDMap request = (OSDMap)json["params"];
  343. UUID avatarId = new UUID(request["avatarId"].AsString());
  344. OSDArray data = (OSDArray) Service.AvatarImageAssetsRequest(avatarId);
  345. response.Result = data;
  346. return true;
  347. }
  348. #endregion Utiltiy
  349. #region UserData
  350. public bool RequestUserAppData(OSDMap json, ref JsonRpcResponse response)
  351. {
  352. if(!json.ContainsKey("params"))
  353. {
  354. response.Error.Code = ErrorCode.ParseError;
  355. response.Error.Message = "no parameters supplied";
  356. m_log.DebugFormat ("User Application Service URL Request: No Parameters!");
  357. return false;
  358. }
  359. string result = string.Empty;
  360. UserAppData props = new UserAppData();
  361. object Props = (object)props;
  362. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  363. if(Service.RequestUserAppData(ref props, ref result))
  364. {
  365. OSDMap res = new OSDMap();
  366. res["result"] = OSD.FromString("success");
  367. res["token"] = OSD.FromString (result);
  368. response.Result = res;
  369. return true;
  370. }
  371. response.Error.Code = ErrorCode.InternalError;
  372. response.Error.Message = string.Format("{0}", result);
  373. return false;
  374. }
  375. public bool UpdateUserAppData(OSDMap json, ref JsonRpcResponse response)
  376. {
  377. if(!json.ContainsKey("params"))
  378. {
  379. response.Error.Code = ErrorCode.ParseError;
  380. response.Error.Message = "no parameters supplied";
  381. m_log.DebugFormat ("User App Data Update Request");
  382. return false;
  383. }
  384. string result = string.Empty;
  385. UserAppData props = new UserAppData();
  386. object Props = (object)props;
  387. OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
  388. if(Service.SetUserAppData(props, ref result))
  389. {
  390. response.Result = OSD.SerializeMembers(props);
  391. return true;
  392. }
  393. response.Error.Code = ErrorCode.InternalError;
  394. response.Error.Message = string.Format("{0}", result);
  395. return false;
  396. }
  397. #endregion UserData
  398. }
  399. }