clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
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 System.Text; |
||
31 | using System.Xml; |
||
32 | using System.Collections.Generic; |
||
33 | using System.IO; |
||
34 | using Nini.Config; |
||
35 | using OpenSim.Framework; |
||
36 | using OpenSim.Server.Base; |
||
37 | using OpenSim.Services.Interfaces; |
||
38 | using OpenSim.Framework.Servers.HttpServer; |
||
39 | using OpenSim.Server.Handlers.Base; |
||
40 | using log4net; |
||
41 | using OpenMetaverse; |
||
42 | |||
43 | namespace OpenSim.Groups |
||
44 | { |
||
45 | public class GroupsServiceRobustConnector : ServiceConnector |
||
46 | { |
||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
48 | |||
49 | private GroupsService m_GroupsService; |
||
50 | private string m_ConfigName = "Groups"; |
||
51 | |||
52 | public GroupsServiceRobustConnector(IConfigSource config, IHttpServer server, string configName) : |
||
53 | base(config, server, configName) |
||
54 | { |
||
55 | if (configName != String.Empty) |
||
56 | m_ConfigName = configName; |
||
57 | |||
58 | m_log.DebugFormat("[Groups.RobustConnector]: Starting with config name {0}", m_ConfigName); |
||
59 | |||
60 | m_GroupsService = new GroupsService(config); |
||
61 | |||
62 | server.AddStreamHandler(new GroupsServicePostHandler(m_GroupsService)); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | public class GroupsServicePostHandler : BaseStreamHandler |
||
67 | { |
||
68 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
69 | |||
70 | private GroupsService m_GroupsService; |
||
71 | |||
72 | public GroupsServicePostHandler(GroupsService service) : |
||
73 | base("POST", "/groups") |
||
74 | { |
||
75 | m_GroupsService = service; |
||
76 | } |
||
77 | |||
78 | protected override byte[] ProcessRequest(string path, Stream requestData, |
||
79 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
||
80 | { |
||
81 | StreamReader sr = new StreamReader(requestData); |
||
82 | string body = sr.ReadToEnd(); |
||
83 | sr.Close(); |
||
84 | body = body.Trim(); |
||
85 | |||
86 | //m_log.DebugFormat("[XXX]: query String: {0}", body); |
||
87 | |||
88 | try |
||
89 | { |
||
90 | Dictionary<string, object> request = |
||
91 | ServerUtils.ParseQueryString(body); |
||
92 | |||
93 | if (!request.ContainsKey("METHOD")) |
||
94 | return FailureResult(); |
||
95 | |||
96 | string method = request["METHOD"].ToString(); |
||
97 | request.Remove("METHOD"); |
||
98 | |||
99 | m_log.DebugFormat("[Groups.Handler]: {0}", method); |
||
100 | switch (method) |
||
101 | { |
||
102 | case "PUTGROUP": |
||
103 | return HandleAddOrUpdateGroup(request); |
||
104 | case "GETGROUP": |
||
105 | return HandleGetGroup(request); |
||
106 | case "ADDAGENTTOGROUP": |
||
107 | return HandleAddAgentToGroup(request); |
||
108 | case "REMOVEAGENTFROMGROUP": |
||
109 | return HandleRemoveAgentFromGroup(request); |
||
110 | case "GETMEMBERSHIP": |
||
111 | return HandleGetMembership(request); |
||
112 | case "GETGROUPMEMBERS": |
||
113 | return HandleGetGroupMembers(request); |
||
114 | case "PUTROLE": |
||
115 | return HandlePutRole(request); |
||
116 | case "REMOVEROLE": |
||
117 | return HandleRemoveRole(request); |
||
118 | case "GETGROUPROLES": |
||
119 | return HandleGetGroupRoles(request); |
||
120 | case "GETROLEMEMBERS": |
||
121 | return HandleGetRoleMembers(request); |
||
122 | case "AGENTROLE": |
||
123 | return HandleAgentRole(request); |
||
124 | case "GETAGENTROLES": |
||
125 | return HandleGetAgentRoles(request); |
||
126 | case "SETACTIVE": |
||
127 | return HandleSetActive(request); |
||
128 | case "UPDATEMEMBERSHIP": |
||
129 | return HandleUpdateMembership(request); |
||
130 | case "INVITE": |
||
131 | return HandleInvite(request); |
||
132 | case "ADDNOTICE": |
||
133 | return HandleAddNotice(request); |
||
134 | case "GETNOTICES": |
||
135 | return HandleGetNotices(request); |
||
136 | case "FINDGROUPS": |
||
137 | return HandleFindGroups(request); |
||
138 | } |
||
139 | m_log.DebugFormat("[GROUPS HANDLER]: unknown method request: {0}", method); |
||
140 | } |
||
141 | catch (Exception e) |
||
142 | { |
||
143 | m_log.DebugFormat("[GROUPS HANDLER]: Exception {0}", e.StackTrace); |
||
144 | } |
||
145 | |||
146 | return FailureResult(); |
||
147 | } |
||
148 | |||
149 | byte[] HandleAddOrUpdateGroup(Dictionary<string, object> request) |
||
150 | { |
||
151 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
152 | |||
153 | ExtendedGroupRecord grec = GroupsDataUtils.GroupRecord(request); |
||
154 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("OP")) |
||
155 | NullResult(result, "Bad network data"); |
||
156 | |||
157 | else |
||
158 | { |
||
159 | string RequestingAgentID = request["RequestingAgentID"].ToString(); |
||
160 | string reason = string.Empty; |
||
161 | string op = request["OP"].ToString(); |
||
162 | if (op == "ADD") |
||
163 | { |
||
164 | grec.GroupID = m_GroupsService.CreateGroup(RequestingAgentID, grec.GroupName, grec.Charter, grec.ShowInList, grec.GroupPicture, grec.MembershipFee, |
||
165 | grec.OpenEnrollment, grec.AllowPublish, grec.MaturePublish, grec.FounderID, out reason); |
||
166 | |||
167 | } |
||
168 | else if (op == "UPDATE") |
||
169 | { |
||
170 | m_GroupsService.UpdateGroup(RequestingAgentID, grec.GroupID, grec.Charter, grec.ShowInList, grec.GroupPicture, grec.MembershipFee, |
||
171 | grec.OpenEnrollment, grec.AllowPublish, grec.MaturePublish); |
||
172 | |||
173 | } |
||
174 | |||
175 | if (grec.GroupID != UUID.Zero) |
||
176 | { |
||
177 | grec = m_GroupsService.GetGroupRecord(RequestingAgentID, grec.GroupID); |
||
178 | if (grec == null) |
||
179 | NullResult(result, "Internal Error"); |
||
180 | else |
||
181 | result["RESULT"] = GroupsDataUtils.GroupRecord(grec); |
||
182 | } |
||
183 | else |
||
184 | NullResult(result, reason); |
||
185 | } |
||
186 | |||
187 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
188 | |||
189 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
190 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
191 | } |
||
192 | |||
193 | byte[] HandleGetGroup(Dictionary<string, object> request) |
||
194 | { |
||
195 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
196 | |||
197 | if (!request.ContainsKey("RequestingAgentID")) |
||
198 | NullResult(result, "Bad network data"); |
||
199 | else |
||
200 | { |
||
201 | string RequestingAgentID = request["RequestingAgentID"].ToString(); |
||
202 | ExtendedGroupRecord grec = null; |
||
203 | if (request.ContainsKey("GroupID")) |
||
204 | { |
||
205 | UUID groupID = new UUID(request["GroupID"].ToString()); |
||
206 | grec = m_GroupsService.GetGroupRecord(RequestingAgentID, groupID); |
||
207 | } |
||
208 | else if (request.ContainsKey("Name")) |
||
209 | { |
||
210 | string name = request["Name"].ToString(); |
||
211 | grec = m_GroupsService.GetGroupRecord(RequestingAgentID, name); |
||
212 | } |
||
213 | |||
214 | if (grec == null) |
||
215 | NullResult(result, "Group not found"); |
||
216 | else |
||
217 | result["RESULT"] = GroupsDataUtils.GroupRecord(grec); |
||
218 | } |
||
219 | |||
220 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
221 | |||
222 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
223 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
224 | } |
||
225 | |||
226 | byte[] HandleAddAgentToGroup(Dictionary<string, object> request) |
||
227 | { |
||
228 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
229 | |||
230 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID") || |
||
231 | !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID")) |
||
232 | NullResult(result, "Bad network data"); |
||
233 | else |
||
234 | { |
||
235 | UUID groupID = new UUID(request["GroupID"].ToString()); |
||
236 | UUID roleID = new UUID(request["RoleID"].ToString()); |
||
237 | string agentID = request["AgentID"].ToString(); |
||
238 | string requestingAgentID = request["RequestingAgentID"].ToString(); |
||
239 | string token = string.Empty; |
||
240 | string reason = string.Empty; |
||
241 | |||
242 | if (request.ContainsKey("AccessToken")) |
||
243 | token = request["AccessToken"].ToString(); |
||
244 | |||
245 | if (!m_GroupsService.AddAgentToGroup(requestingAgentID, agentID, groupID, roleID, token, out reason)) |
||
246 | NullResult(result, reason); |
||
247 | else |
||
248 | { |
||
249 | GroupMembershipData membership = m_GroupsService.GetAgentGroupMembership(requestingAgentID, agentID, groupID); |
||
250 | if (membership == null) |
||
251 | NullResult(result, "Internal error"); |
||
252 | else |
||
253 | result["RESULT"] = GroupsDataUtils.GroupMembershipData((ExtendedGroupMembershipData)membership); |
||
254 | } |
||
255 | } |
||
256 | |||
257 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
258 | |||
259 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
260 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
261 | } |
||
262 | |||
263 | byte[] HandleRemoveAgentFromGroup(Dictionary<string, object> request) |
||
264 | { |
||
265 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
266 | |||
267 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID") || !request.ContainsKey("GroupID")) |
||
268 | NullResult(result, "Bad network data"); |
||
269 | else |
||
270 | { |
||
271 | UUID groupID = new UUID(request["GroupID"].ToString()); |
||
272 | string agentID = request["AgentID"].ToString(); |
||
273 | string requestingAgentID = request["RequestingAgentID"].ToString(); |
||
274 | |||
275 | m_GroupsService.RemoveAgentFromGroup(requestingAgentID, agentID, groupID); |
||
276 | } |
||
277 | |||
278 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
279 | result["RESULT"] = "true"; |
||
280 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); |
||
281 | } |
||
282 | |||
283 | byte[] HandleGetMembership(Dictionary<string, object> request) |
||
284 | { |
||
285 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
286 | |||
287 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID")) |
||
288 | NullResult(result, "Bad network data"); |
||
289 | else |
||
290 | { |
||
291 | string agentID = request["AgentID"].ToString(); |
||
292 | UUID groupID = UUID.Zero; |
||
293 | if (request.ContainsKey("GroupID")) |
||
294 | groupID = new UUID(request["GroupID"].ToString()); |
||
295 | string requestingAgentID = request["RequestingAgentID"].ToString(); |
||
296 | bool all = request.ContainsKey("ALL"); |
||
297 | |||
298 | if (!all) |
||
299 | { |
||
300 | ExtendedGroupMembershipData membership = null; |
||
301 | if (groupID == UUID.Zero) |
||
302 | { |
||
303 | membership = m_GroupsService.GetAgentActiveMembership(requestingAgentID, agentID); |
||
304 | } |
||
305 | else |
||
306 | { |
||
307 | membership = m_GroupsService.GetAgentGroupMembership(requestingAgentID, agentID, groupID); |
||
308 | } |
||
309 | |||
310 | if (membership == null) |
||
311 | NullResult(result, "No such membership"); |
||
312 | else |
||
313 | result["RESULT"] = GroupsDataUtils.GroupMembershipData(membership); |
||
314 | } |
||
315 | else |
||
316 | { |
||
317 | List<GroupMembershipData> memberships = m_GroupsService.GetAgentGroupMemberships(requestingAgentID, agentID); |
||
318 | if (memberships == null || (memberships != null && memberships.Count == 0)) |
||
319 | { |
||
320 | NullResult(result, "No memberships"); |
||
321 | } |
||
322 | else |
||
323 | { |
||
324 | Dictionary<string, object> dict = new Dictionary<string, object>(); |
||
325 | int i = 0; |
||
326 | foreach (GroupMembershipData m in memberships) |
||
327 | dict["m-" + i++] = GroupsDataUtils.GroupMembershipData((ExtendedGroupMembershipData)m); |
||
328 | |||
329 | result["RESULT"] = dict; |
||
330 | } |
||
331 | } |
||
332 | } |
||
333 | |||
334 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
335 | |||
336 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
337 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
338 | } |
||
339 | |||
340 | byte[] HandleGetGroupMembers(Dictionary<string, object> request) |
||
341 | { |
||
342 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
343 | |||
344 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID")) |
||
345 | NullResult(result, "Bad network data"); |
||
346 | else |
||
347 | { |
||
348 | UUID groupID = new UUID(request["GroupID"].ToString()); |
||
349 | string requestingAgentID = request["RequestingAgentID"].ToString(); |
||
350 | |||
351 | List<ExtendedGroupMembersData> members = m_GroupsService.GetGroupMembers(requestingAgentID, groupID); |
||
352 | if (members == null || (members != null && members.Count == 0)) |
||
353 | { |
||
354 | NullResult(result, "No members"); |
||
355 | } |
||
356 | else |
||
357 | { |
||
358 | Dictionary<string, object> dict = new Dictionary<string, object>(); |
||
359 | int i = 0; |
||
360 | foreach (ExtendedGroupMembersData m in members) |
||
361 | { |
||
362 | dict["m-" + i++] = GroupsDataUtils.GroupMembersData(m); |
||
363 | } |
||
364 | |||
365 | result["RESULT"] = dict; |
||
366 | } |
||
367 | } |
||
368 | |||
369 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
370 | |||
371 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
372 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
373 | } |
||
374 | |||
375 | byte[] HandlePutRole(Dictionary<string, object> request) |
||
376 | { |
||
377 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
378 | |||
379 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID") || |
||
380 | !request.ContainsKey("Name") || !request.ContainsKey("Description") || !request.ContainsKey("Title") || |
||
381 | !request.ContainsKey("Powers") || !request.ContainsKey("OP")) |
||
382 | NullResult(result, "Bad network data"); |
||
383 | |||
384 | else |
||
385 | { |
||
386 | string op = request["OP"].ToString(); |
||
387 | string reason = string.Empty; |
||
388 | |||
389 | bool success = false; |
||
390 | if (op == "ADD") |
||
391 | success = m_GroupsService.AddGroupRole(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()), |
||
392 | new UUID(request["RoleID"].ToString()), request["Name"].ToString(), request["Description"].ToString(), |
||
393 | request["Title"].ToString(), UInt64.Parse(request["Powers"].ToString()), out reason); |
||
394 | |||
395 | else if (op == "UPDATE") |
||
396 | success = m_GroupsService.UpdateGroupRole(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()), |
||
397 | new UUID(request["RoleID"].ToString()), request["Name"].ToString(), request["Description"].ToString(), |
||
398 | request["Title"].ToString(), UInt64.Parse(request["Powers"].ToString())); |
||
399 | |||
400 | result["RESULT"] = success.ToString(); |
||
401 | } |
||
402 | |||
403 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
404 | |||
405 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
406 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
407 | } |
||
408 | |||
409 | byte[] HandleRemoveRole(Dictionary<string, object> request) |
||
410 | { |
||
411 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
412 | |||
413 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID")) |
||
414 | NullResult(result, "Bad network data"); |
||
415 | |||
416 | else |
||
417 | { |
||
418 | m_GroupsService.RemoveGroupRole(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()), |
||
419 | new UUID(request["RoleID"].ToString())); |
||
420 | result["RESULT"] = "true"; |
||
421 | } |
||
422 | |||
423 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
424 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); |
||
425 | } |
||
426 | |||
427 | byte[] HandleGetGroupRoles(Dictionary<string, object> request) |
||
428 | { |
||
429 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
430 | |||
431 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID")) |
||
432 | NullResult(result, "Bad network data"); |
||
433 | else |
||
434 | { |
||
435 | UUID groupID = new UUID(request["GroupID"].ToString()); |
||
436 | string requestingAgentID = request["RequestingAgentID"].ToString(); |
||
437 | |||
438 | List<GroupRolesData> roles = m_GroupsService.GetGroupRoles(requestingAgentID, groupID); |
||
439 | if (roles == null || (roles != null && roles.Count == 0)) |
||
440 | { |
||
441 | NullResult(result, "No members"); |
||
442 | } |
||
443 | else |
||
444 | { |
||
445 | Dictionary<string, object> dict = new Dictionary<string, object>(); |
||
446 | int i = 0; |
||
447 | foreach (GroupRolesData r in roles) |
||
448 | dict["r-" + i++] = GroupsDataUtils.GroupRolesData(r); |
||
449 | |||
450 | result["RESULT"] = dict; |
||
451 | } |
||
452 | } |
||
453 | |||
454 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
455 | |||
456 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
457 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
458 | } |
||
459 | |||
460 | byte[] HandleGetRoleMembers(Dictionary<string, object> request) |
||
461 | { |
||
462 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
463 | |||
464 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID")) |
||
465 | NullResult(result, "Bad network data"); |
||
466 | else |
||
467 | { |
||
468 | UUID groupID = new UUID(request["GroupID"].ToString()); |
||
469 | string requestingAgentID = request["RequestingAgentID"].ToString(); |
||
470 | |||
471 | List<ExtendedGroupRoleMembersData> rmembers = m_GroupsService.GetGroupRoleMembers(requestingAgentID, groupID); |
||
472 | if (rmembers == null || (rmembers != null && rmembers.Count == 0)) |
||
473 | { |
||
474 | NullResult(result, "No members"); |
||
475 | } |
||
476 | else |
||
477 | { |
||
478 | Dictionary<string, object> dict = new Dictionary<string, object>(); |
||
479 | int i = 0; |
||
480 | foreach (ExtendedGroupRoleMembersData rm in rmembers) |
||
481 | dict["rm-" + i++] = GroupsDataUtils.GroupRoleMembersData(rm); |
||
482 | |||
483 | result["RESULT"] = dict; |
||
484 | } |
||
485 | } |
||
486 | |||
487 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
488 | |||
489 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
490 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
491 | } |
||
492 | |||
493 | byte[] HandleAgentRole(Dictionary<string, object> request) |
||
494 | { |
||
495 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
496 | |||
497 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID") || |
||
498 | !request.ContainsKey("AgentID") || !request.ContainsKey("OP")) |
||
499 | NullResult(result, "Bad network data"); |
||
500 | |||
501 | else |
||
502 | { |
||
503 | string op = request["OP"].ToString(); |
||
504 | |||
505 | bool success = false; |
||
506 | if (op == "ADD") |
||
507 | success = m_GroupsService.AddAgentToGroupRole(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(), |
||
508 | new UUID(request["GroupID"].ToString()), new UUID(request["RoleID"].ToString())); |
||
509 | |||
510 | else if (op == "DELETE") |
||
511 | success = m_GroupsService.RemoveAgentFromGroupRole(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(), |
||
512 | new UUID(request["GroupID"].ToString()), new UUID(request["RoleID"].ToString())); |
||
513 | |||
514 | result["RESULT"] = success.ToString(); |
||
515 | } |
||
516 | |||
517 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
518 | |||
519 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
520 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
521 | } |
||
522 | |||
523 | byte[] HandleGetAgentRoles(Dictionary<string, object> request) |
||
524 | { |
||
525 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
526 | |||
527 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("AgentID")) |
||
528 | NullResult(result, "Bad network data"); |
||
529 | else |
||
530 | { |
||
531 | UUID groupID = new UUID(request["GroupID"].ToString()); |
||
532 | string agentID = request["AgentID"].ToString(); |
||
533 | string requestingAgentID = request["RequestingAgentID"].ToString(); |
||
534 | |||
535 | List<GroupRolesData> roles = m_GroupsService.GetAgentGroupRoles(requestingAgentID, agentID, groupID); |
||
536 | if (roles == null || (roles != null && roles.Count == 0)) |
||
537 | { |
||
538 | NullResult(result, "No members"); |
||
539 | } |
||
540 | else |
||
541 | { |
||
542 | Dictionary<string, object> dict = new Dictionary<string, object>(); |
||
543 | int i = 0; |
||
544 | foreach (GroupRolesData r in roles) |
||
545 | dict["r-" + i++] = GroupsDataUtils.GroupRolesData(r); |
||
546 | |||
547 | result["RESULT"] = dict; |
||
548 | } |
||
549 | } |
||
550 | |||
551 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
552 | |||
553 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
554 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
555 | } |
||
556 | |||
557 | byte[] HandleSetActive(Dictionary<string, object> request) |
||
558 | { |
||
559 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
560 | |||
561 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || |
||
562 | !request.ContainsKey("AgentID") || !request.ContainsKey("OP")) |
||
563 | { |
||
564 | NullResult(result, "Bad network data"); |
||
565 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
566 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
567 | } |
||
568 | else |
||
569 | { |
||
570 | string op = request["OP"].ToString(); |
||
571 | |||
572 | if (op == "GROUP") |
||
573 | { |
||
574 | ExtendedGroupMembershipData group = m_GroupsService.SetAgentActiveGroup(request["RequestingAgentID"].ToString(), |
||
575 | request["AgentID"].ToString(), new UUID(request["GroupID"].ToString())); |
||
576 | |||
577 | if (group == null) |
||
578 | NullResult(result, "Internal error"); |
||
579 | else |
||
580 | result["RESULT"] = GroupsDataUtils.GroupMembershipData(group); |
||
581 | |||
582 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
583 | |||
584 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
585 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
586 | |||
587 | } |
||
588 | else if (op == "ROLE" && request.ContainsKey("RoleID")) |
||
589 | { |
||
590 | m_GroupsService.SetAgentActiveGroupRole(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(), |
||
591 | new UUID(request["GroupID"].ToString()), new UUID(request["RoleID"].ToString())); |
||
592 | result["RESULT"] = "true"; |
||
593 | } |
||
594 | |||
595 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); |
||
596 | } |
||
597 | |||
598 | } |
||
599 | |||
600 | byte[] HandleUpdateMembership(Dictionary<string, object> request) |
||
601 | { |
||
602 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
603 | |||
604 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID") || !request.ContainsKey("GroupID") || |
||
605 | !request.ContainsKey("AcceptNotices") || !request.ContainsKey("ListInProfile")) |
||
606 | NullResult(result, "Bad network data"); |
||
607 | |||
608 | else |
||
609 | { |
||
610 | m_GroupsService.UpdateMembership(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(), new UUID(request["GroupID"].ToString()), |
||
611 | bool.Parse(request["AcceptNotices"].ToString()), bool.Parse(request["ListInProfile"].ToString())); |
||
612 | |||
613 | result["RESULT"] = "true"; |
||
614 | } |
||
615 | |||
616 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
617 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); |
||
618 | } |
||
619 | |||
620 | byte[] HandleInvite(Dictionary<string, object> request) |
||
621 | { |
||
622 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
623 | |||
624 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("InviteID")) |
||
625 | { |
||
626 | NullResult(result, "Bad network data"); |
||
627 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
628 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
629 | } |
||
630 | else |
||
631 | { |
||
632 | string op = request["OP"].ToString(); |
||
633 | |||
634 | if (op == "ADD" && request.ContainsKey("GroupID") && request.ContainsKey("RoleID") && request.ContainsKey("AgentID")) |
||
635 | { |
||
636 | bool success = m_GroupsService.AddAgentToGroupInvite(request["RequestingAgentID"].ToString(), |
||
637 | new UUID(request["InviteID"].ToString()), new UUID(request["GroupID"].ToString()), |
||
638 | new UUID(request["RoleID"].ToString()), request["AgentID"].ToString()); |
||
639 | |||
640 | result["RESULT"] = success.ToString(); |
||
641 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); |
||
642 | |||
643 | } |
||
644 | else if (op == "DELETE") |
||
645 | { |
||
646 | m_GroupsService.RemoveAgentToGroupInvite(request["RequestingAgentID"].ToString(), new UUID(request["InviteID"].ToString())); |
||
647 | result["RESULT"] = "true"; |
||
648 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); |
||
649 | } |
||
650 | else if (op == "GET") |
||
651 | { |
||
652 | GroupInviteInfo invite = m_GroupsService.GetAgentToGroupInvite(request["RequestingAgentID"].ToString(), |
||
653 | new UUID(request["InviteID"].ToString())); |
||
654 | |||
655 | result["RESULT"] = GroupsDataUtils.GroupInviteInfo(invite); |
||
656 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); |
||
657 | } |
||
658 | |||
659 | NullResult(result, "Bad OP in request"); |
||
660 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); |
||
661 | } |
||
662 | |||
663 | } |
||
664 | |||
665 | byte[] HandleAddNotice(Dictionary<string, object> request) |
||
666 | { |
||
667 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
668 | |||
669 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("NoticeID") || |
||
670 | !request.ContainsKey("FromName") || !request.ContainsKey("Subject") || !request.ContainsKey("Message") || |
||
671 | !request.ContainsKey("HasAttachment")) |
||
672 | NullResult(result, "Bad network data"); |
||
673 | |||
674 | else |
||
675 | { |
||
676 | |||
677 | bool hasAtt = bool.Parse(request["HasAttachment"].ToString()); |
||
678 | byte attType = 0; |
||
679 | string attName = string.Empty; |
||
680 | string attOwner = string.Empty; |
||
681 | UUID attItem = UUID.Zero; |
||
682 | if (request.ContainsKey("AttachmentType")) |
||
683 | attType = byte.Parse(request["AttachmentType"].ToString()); |
||
684 | if (request.ContainsKey("AttachmentName")) |
||
685 | attName = request["AttachmentName"].ToString(); |
||
686 | if (request.ContainsKey("AttachmentItemID")) |
||
687 | attItem = new UUID(request["AttachmentItemID"].ToString()); |
||
688 | if (request.ContainsKey("AttachmentOwnerID")) |
||
689 | attOwner = request["AttachmentOwnerID"].ToString(); |
||
690 | |||
691 | bool success = m_GroupsService.AddGroupNotice(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()), |
||
692 | new UUID(request["NoticeID"].ToString()), request["FromName"].ToString(), request["Subject"].ToString(), |
||
693 | request["Message"].ToString(), hasAtt, attType, attName, attItem, attOwner); |
||
694 | |||
695 | result["RESULT"] = success.ToString(); |
||
696 | } |
||
697 | |||
698 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
699 | |||
700 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
||
701 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
702 | } |
||
703 | |||
704 | byte[] HandleGetNotices(Dictionary<string, object> request) |
||
705 | { |
||
706 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
707 | |||
708 | if (!request.ContainsKey("RequestingAgentID")) |
||
709 | NullResult(result, "Bad network data"); |
||
710 | |||
711 | else if (request.ContainsKey("NoticeID")) // just one |
||
712 | { |
||
713 | GroupNoticeInfo notice = m_GroupsService.GetGroupNotice(request["RequestingAgentID"].ToString(), new UUID(request["NoticeID"].ToString())); |
||
714 | |||
715 | if (notice == null) |
||
716 | NullResult(result, "NO such notice"); |
||
717 | else |
||
718 | result["RESULT"] = GroupsDataUtils.GroupNoticeInfo(notice); |
||
719 | |||
720 | } |
||
721 | else if (request.ContainsKey("GroupID")) // all notices for group |
||
722 | { |
||
723 | List<ExtendedGroupNoticeData> notices = m_GroupsService.GetGroupNotices(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString())); |
||
724 | |||
725 | if (notices == null || (notices != null && notices.Count == 0)) |
||
726 | NullResult(result, "No notices"); |
||
727 | else |
||
728 | { |
||
729 | Dictionary<string, object> dict = new Dictionary<string, object>(); |
||
730 | int i = 0; |
||
731 | foreach (ExtendedGroupNoticeData n in notices) |
||
732 | dict["n-" + i++] = GroupsDataUtils.GroupNoticeData(n); |
||
733 | |||
734 | result["RESULT"] = dict; |
||
735 | } |
||
736 | |||
737 | } |
||
738 | else |
||
739 | NullResult(result, "Bad OP in request"); |
||
740 | |||
741 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
742 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
743 | } |
||
744 | |||
745 | byte[] HandleFindGroups(Dictionary<string, object> request) |
||
746 | { |
||
747 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
748 | |||
749 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("Query")) |
||
750 | NullResult(result, "Bad network data"); |
||
751 | |||
752 | List<DirGroupsReplyData> hits = m_GroupsService.FindGroups(request["RequestingAgentID"].ToString(), request["Query"].ToString()); |
||
753 | |||
754 | if (hits == null || (hits != null && hits.Count == 0)) |
||
755 | NullResult(result, "No hits"); |
||
756 | else |
||
757 | { |
||
758 | Dictionary<string, object> dict = new Dictionary<string, object>(); |
||
759 | int i = 0; |
||
760 | foreach (DirGroupsReplyData n in hits) |
||
761 | dict["n-" + i++] = GroupsDataUtils.DirGroupsReplyData(n); |
||
762 | |||
763 | result["RESULT"] = dict; |
||
764 | } |
||
765 | |||
766 | |||
767 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
768 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
769 | } |
||
770 | |||
771 | |||
772 | #region Helpers |
||
773 | |||
774 | private void NullResult(Dictionary<string, object> result, string reason) |
||
775 | { |
||
776 | result["RESULT"] = "NULL"; |
||
777 | result["REASON"] = reason; |
||
778 | } |
||
779 | |||
780 | private byte[] FailureResult() |
||
781 | { |
||
782 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
783 | NullResult(result, "Unknown method"); |
||
784 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
785 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
786 | } |
||
787 | #endregion |
||
788 | } |
||
789 | } |