diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs | 513 |
1 files changed, 513 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs b/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs new file mode 100644 index 0000000..49aa8ba --- /dev/null +++ b/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs | |||
@@ -0,0 +1,513 @@ | |||
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 | 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; | ||
316 | UserProfileProperties props = new UserProfileProperties(); | ||
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; | ||
341 | UserProfileProperties props = new UserProfileProperties(); | ||
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; | ||
368 | UserProfileProperties props = new UserProfileProperties(); | ||
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 | #region Utility | ||
437 | public bool AvatarImageAssetsRequest(OSDMap json, ref JsonRpcResponse response) | ||
438 | { | ||
439 | if(!json.ContainsKey("params")) | ||
440 | { | ||
441 | response.Error.Code = ErrorCode.ParseError; | ||
442 | m_log.DebugFormat ("Avatar Image Assets Request"); | ||
443 | return false; | ||
444 | } | ||
445 | |||
446 | OSDMap request = (OSDMap)json["params"]; | ||
447 | UUID avatarId = new UUID(request["avatarId"].AsString()); | ||
448 | |||
449 | OSDArray data = (OSDArray) Service.AvatarImageAssetsRequest(avatarId); | ||
450 | response.Result = data; | ||
451 | |||
452 | return true; | ||
453 | } | ||
454 | #endregion Utiltiy | ||
455 | |||
456 | #region UserData | ||
457 | public bool RequestUserAppData(OSDMap json, ref JsonRpcResponse response) | ||
458 | { | ||
459 | if(!json.ContainsKey("params")) | ||
460 | { | ||
461 | response.Error.Code = ErrorCode.ParseError; | ||
462 | response.Error.Message = "no parameters supplied"; | ||
463 | m_log.DebugFormat ("User Application Service URL Request: No Parameters!"); | ||
464 | return false; | ||
465 | } | ||
466 | |||
467 | string result = string.Empty; | ||
468 | UserAppData props = new UserAppData(); | ||
469 | object Props = (object)props; | ||
470 | OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]); | ||
471 | if(Service.RequestUserAppData(ref props, ref result)) | ||
472 | { | ||
473 | OSDMap res = new OSDMap(); | ||
474 | res["result"] = OSD.FromString("success"); | ||
475 | res["token"] = OSD.FromString (result); | ||
476 | response.Result = res; | ||
477 | |||
478 | return true; | ||
479 | } | ||
480 | |||
481 | response.Error.Code = ErrorCode.InternalError; | ||
482 | response.Error.Message = string.Format("{0}", result); | ||
483 | return false; | ||
484 | } | ||
485 | |||
486 | public bool UpdateUserAppData(OSDMap json, ref JsonRpcResponse response) | ||
487 | { | ||
488 | if(!json.ContainsKey("params")) | ||
489 | { | ||
490 | response.Error.Code = ErrorCode.ParseError; | ||
491 | response.Error.Message = "no parameters supplied"; | ||
492 | m_log.DebugFormat ("User App Data Update Request"); | ||
493 | return false; | ||
494 | } | ||
495 | |||
496 | string result = string.Empty; | ||
497 | UserAppData props = new UserAppData(); | ||
498 | object Props = (object)props; | ||
499 | OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]); | ||
500 | if(Service.SetUserAppData(props, ref result)) | ||
501 | { | ||
502 | response.Result = OSD.SerializeMembers(props); | ||
503 | return true; | ||
504 | } | ||
505 | |||
506 | response.Error.Code = ErrorCode.InternalError; | ||
507 | response.Error.Message = string.Format("{0}", result); | ||
508 | return false; | ||
509 | } | ||
510 | #endregion UserData | ||
511 | } | ||
512 | } | ||
513 | |||