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