clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 {
41 public UserProfilesHandlers ()
42 {
43 }
44 }
45  
46 public class JsonRpcProfileHandlers
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  
57 public JsonRpcProfileHandlers(IUserProfilesService service)
58 {
59 Service = service;
60 }
61  
62 #region Classifieds
63 /// <summary>
64 /// Request avatar's classified ads.
65 /// </summary>
66 /// <returns>
67 /// An array containing all the calassified uuid and it's name created by the creator id
68 /// </returns>
69 /// <param name='json'>
70 /// Our parameters are in the OSDMap json["params"]
71 /// </param>
72 /// <param name='response'>
73 /// If set to <c>true</c> response.
74 /// </param>
75 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;
105 UserClassifiedAdd ad = new UserClassifiedAdd();
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;
150 UserClassifiedAdd ad = new UserClassifiedAdd();
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 string result = string.Empty;
268 UserProfileNotes note = new UserProfileNotes();
269 object Note = (object)note;
270 OSD.DeserializeMembers(ref Note, (OSDMap)json["params"]);
271 if(Service.AvatarNotesRequest(ref note))
272 {
273 response.Result = OSD.SerializeMembers(note);
274 return true;
275 }
276  
277 response.Error.Code = ErrorCode.InternalError;
278 response.Error.Message = "Error reading notes";
279 return false;
280 }
281  
282 public bool NotesUpdate(OSDMap json, ref JsonRpcResponse response)
283 {
284 if(!json.ContainsKey("params"))
285 {
286 response.Error.Code = ErrorCode.ParseError;
287 response.Error.Message = "No parameters";
288 m_log.DebugFormat ("Avatar Notes Update Request");
289 return false;
290 }
291  
292 string result = string.Empty;
293 UserProfileNotes note = new UserProfileNotes();
294 object Notes = (object) note;
295 OSD.DeserializeMembers(ref Notes, (OSDMap)json["params"]);
296 if(Service.NotesUpdate(ref note, ref result))
297 {
298 response.Result = OSD.SerializeMembers(note);
299 return true;
300 }
301 return true;
302 }
303 #endregion Notes
304  
305 #region Profile Properties
306 public bool AvatarPropertiesRequest(OSDMap json, ref JsonRpcResponse response)
307 {
308 if(!json.ContainsKey("params"))
309 {
310 response.Error.Code = ErrorCode.ParseError;
311 response.Error.Message = "no parameters supplied";
312 m_log.DebugFormat ("Avatar Properties Request");
313 return false;
314 }
315  
316 string result = string.Empty;
317 UserProfileProperties props = new UserProfileProperties();
318 object Props = (object)props;
319 OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
320 if(Service.AvatarPropertiesRequest(ref props, ref result))
321 {
322 response.Result = OSD.SerializeMembers(props);
323 return true;
324 }
325  
326 response.Error.Code = ErrorCode.InternalError;
327 response.Error.Message = string.Format("{0}", result);
328 return false;
329 }
330  
331 public bool AvatarPropertiesUpdate(OSDMap json, ref JsonRpcResponse response)
332 {
333 if(!json.ContainsKey("params"))
334 {
335 response.Error.Code = ErrorCode.ParseError;
336 response.Error.Message = "no parameters supplied";
337 m_log.DebugFormat ("Avatar Properties Update Request");
338 return false;
339 }
340  
341 string result = string.Empty;
342 UserProfileProperties props = new UserProfileProperties();
343 object Props = (object)props;
344 OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
345 if(Service.AvatarPropertiesUpdate(ref props, ref result))
346 {
347 response.Result = OSD.SerializeMembers(props);
348 return true;
349 }
350  
351 response.Error.Code = ErrorCode.InternalError;
352 response.Error.Message = string.Format("{0}", result);
353 return false;
354 }
355 #endregion Profile Properties
356  
357 #region Interests
358 public bool AvatarInterestsUpdate(OSDMap json, ref JsonRpcResponse response)
359 {
360 if(!json.ContainsKey("params"))
361 {
362 response.Error.Code = ErrorCode.ParseError;
363 response.Error.Message = "no parameters supplied";
364 m_log.DebugFormat ("Avatar Interests Update Request");
365 return false;
366 }
367  
368 string result = string.Empty;
369 UserProfileProperties props = new UserProfileProperties();
370 object Props = (object)props;
371 OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
372 if(Service.AvatarInterestsUpdate(props, ref result))
373 {
374 response.Result = OSD.SerializeMembers(props);
375 return true;
376 }
377  
378 response.Error.Code = ErrorCode.InternalError;
379 response.Error.Message = string.Format("{0}", result);
380 return false;
381 }
382 #endregion Interests
383  
384 #region User Preferences
385 public bool UserPreferencesRequest(OSDMap json, ref JsonRpcResponse response)
386 {
387 if(!json.ContainsKey("params"))
388 {
389 response.Error.Code = ErrorCode.ParseError;
390 m_log.DebugFormat ("User Preferences Request");
391 return false;
392 }
393  
394 string result = string.Empty;
395 UserPreferences prefs = new UserPreferences();
396 object Prefs = (object)prefs;
397 OSD.DeserializeMembers(ref Prefs, (OSDMap)json["params"]);
398 if(Service.UserPreferencesRequest(ref prefs, ref result))
399 {
400 response.Result = OSD.SerializeMembers(prefs);
401 return true;
402 }
403  
404 response.Error.Code = ErrorCode.InternalError;
405 response.Error.Message = string.Format("{0}", result);
406 m_log.InfoFormat("[PROFILES]: User preferences request error - {0}", response.Error.Message);
407 return false;
408 }
409  
410 public bool UserPreferenecesUpdate(OSDMap json, ref JsonRpcResponse response)
411 {
412 if(!json.ContainsKey("params"))
413 {
414 response.Error.Code = ErrorCode.ParseError;
415 response.Error.Message = "no parameters supplied";
416 m_log.DebugFormat ("User Preferences Update Request");
417 return false;
418 }
419  
420 string result = string.Empty;
421 UserPreferences prefs = new UserPreferences();
422 object Prefs = (object)prefs;
423 OSD.DeserializeMembers(ref Prefs, (OSDMap)json["params"]);
424 if(Service.UserPreferencesUpdate(ref prefs, ref result))
425 {
426 response.Result = OSD.SerializeMembers(prefs);
427 return true;
428 }
429  
430 response.Error.Code = ErrorCode.InternalError;
431 response.Error.Message = string.Format("{0}", result);
432 m_log.InfoFormat("[PROFILES]: User preferences update error - {0}", response.Error.Message);
433 return false;
434 }
435 #endregion User Preferences
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