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