29 using System.Collections.Generic;
31 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Framework.ServiceAuth;
36 using OpenSim.Server.Base;
42 namespace OpenSim.Groups
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 private string m_ServerURI;
50 private object m_Lock =
new object();
54 IConfig groupsConfig = config.Configs[
"Groups"];
55 string url = groupsConfig.GetString(
"GroupsServerURI", string.Empty);
56 if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
57 throw new Exception(
string.Format(
"[Groups.RemoteConnector]: Malformed groups server URL {0}. Fix it or disable the Groups feature.", url));
60 if (!m_ServerURI.EndsWith(
"/"))
64 string authType = Util.GetConfigVarFromSections<
string>(config,
"AuthType",
new string[] {
"Network",
"Groups" },
"None");
68 case "BasicHttpAuthentication":
74 m_log.DebugFormat(
"[Groups.RemoteConnector]: Groups server at {0}, authentication {1}",
75 m_ServerURI, (m_Auth == null ?
"None" : m_Auth.GetType().ToString()));
78 public ExtendedGroupRecord CreateGroup(
string RequestingAgentID,
string name,
string charter,
bool showInList, UUID insigniaID,
int membershipFee,
bool openEnrollment,
79 bool allowPublish,
bool maturePublish, UUID founderID, out
string reason)
81 reason = string.Empty;
84 rec.AllowPublish = allowPublish;
85 rec.Charter = charter;
86 rec.FounderID = founderID;
88 rec.GroupPicture = insigniaID;
89 rec.MaturePublish = maturePublish;
90 rec.MembershipFee = membershipFee;
91 rec.OpenEnrollment = openEnrollment;
92 rec.ShowInList = showInList;
94 Dictionary<string, object> sendData = GroupsDataUtils.GroupRecord(rec);
95 sendData[
"RequestingAgentID"] = RequestingAgentID;
96 sendData[
"OP"] =
"ADD";
97 Dictionary<string, object> ret = MakeRequest(
"PUTGROUP", sendData);
102 if (ret[
"RESULT"].ToString() ==
"NULL")
104 reason = ret[
"REASON"].ToString();
108 return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret[
"RESULT"]);
112 public ExtendedGroupRecord UpdateGroup(
string RequestingAgentID, UUID groupID,
string charter,
bool showInList, UUID insigniaID,
int membershipFee,
bool openEnrollment,
bool allowPublish,
bool maturePublish)
115 rec.AllowPublish = allowPublish;
116 rec.Charter = charter;
117 rec.GroupPicture = insigniaID;
118 rec.MaturePublish = maturePublish;
119 rec.GroupID = groupID;
120 rec.MembershipFee = membershipFee;
121 rec.OpenEnrollment = openEnrollment;
122 rec.ShowInList = showInList;
124 Dictionary<string, object> sendData = GroupsDataUtils.GroupRecord(rec);
125 sendData[
"RequestingAgentID"] = RequestingAgentID;
126 sendData[
"OP"] =
"UPDATE";
127 Dictionary<string, object> ret = MakeRequest(
"PUTGROUP", sendData);
129 if (ret == null || (ret != null && (!ret.ContainsKey(
"RESULT") || ret[
"RESULT"].ToString() ==
"NULL")))
132 return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret[
"RESULT"]);
137 if (GroupID == UUID.Zero && (GroupName == null || (GroupName != null && GroupName ==
string.Empty)))
140 Dictionary<string, object> sendData =
new Dictionary<string, object>();
141 if (GroupID != UUID.Zero)
142 sendData[
"GroupID"] = GroupID.ToString();
143 if (!
string.IsNullOrEmpty(GroupName))
146 sendData[
"RequestingAgentID"] = RequestingAgentID;
148 Dictionary<string, object> ret = MakeRequest(
"GETGROUP", sendData);
150 if (ret == null || (ret != null && (!ret.ContainsKey(
"RESULT") || ret[
"RESULT"].ToString() ==
"NULL")))
153 return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret[
"RESULT"]);
156 public List<DirGroupsReplyData>
FindGroups(
string RequestingAgentID,
string query)
158 List<DirGroupsReplyData> hits =
new List<DirGroupsReplyData>();
159 if (
string.IsNullOrEmpty(query))
162 Dictionary<string, object> sendData =
new Dictionary<string, object>();
163 sendData[
"Query"] = query;
164 sendData[
"RequestingAgentID"] = RequestingAgentID;
166 Dictionary<string, object> ret = MakeRequest(
"FINDGROUPS", sendData);
171 if (!ret.ContainsKey(
"RESULT"))
174 if (ret[
"RESULT"].ToString() ==
"NULL")
177 foreach (
object v
in ((Dictionary<string, object>)ret[
"RESULT"]).Values)
179 DirGroupsReplyData m = GroupsDataUtils.DirGroupsReplyData((Dictionary<string, object>)v);
188 reason = string.Empty;
190 Dictionary<string, object> sendData =
new Dictionary<string,object>();
191 sendData[
"AgentID"] = AgentID;
192 sendData[
"GroupID"] = GroupID.ToString();
193 sendData[
"RoleID"] = RoleID.ToString();
194 sendData[
"RequestingAgentID"] = RequestingAgentID;
195 sendData[
"AccessToken"] = token;
196 Dictionary<string, object> ret = MakeRequest(
"ADDAGENTTOGROUP", sendData);
201 if (!ret.ContainsKey(
"RESULT"))
204 if (ret[
"RESULT"].ToString() ==
"NULL")
206 reason = ret[
"REASON"].ToString();
210 return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret[
"RESULT"]);
216 Dictionary<string, object> sendData =
new Dictionary<string, object>();
217 sendData[
"AgentID"] = AgentID;
218 sendData[
"GroupID"] = GroupID.ToString();
219 sendData[
"RequestingAgentID"] = RequestingAgentID;
220 MakeRequest(
"REMOVEAGENTFROMGROUP", sendData);
225 Dictionary<string, object> sendData =
new Dictionary<string, object>();
226 sendData[
"AgentID"] = AgentID;
227 if (GroupID != UUID.Zero)
228 sendData[
"GroupID"] = GroupID.ToString();
229 sendData[
"RequestingAgentID"] = RequestingAgentID;
230 Dictionary<string, object> ret = MakeRequest(
"GETMEMBERSHIP", sendData);
235 if (!ret.ContainsKey(
"RESULT"))
238 if (ret[
"RESULT"].ToString() ==
"NULL")
241 return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret[
"RESULT"]);
244 public List<GroupMembershipData>
GetMemberships(
string RequestingAgentID,
string AgentID)
246 List<GroupMembershipData> memberships =
new List<GroupMembershipData>();
248 Dictionary<string, object> sendData =
new Dictionary<string, object>();
249 sendData[
"AgentID"] = AgentID;
250 sendData[
"ALL"] =
"true";
251 sendData[
"RequestingAgentID"] = RequestingAgentID;
252 Dictionary<string, object> ret = MakeRequest(
"GETMEMBERSHIP", sendData);
257 if (!ret.ContainsKey(
"RESULT"))
260 if (ret[
"RESULT"].ToString() ==
"NULL")
263 foreach (
object v
in ((Dictionary<string, object>)ret[
"RESULT"]).Values)
265 GroupMembershipData m = GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)v);
272 public List<ExtendedGroupMembersData>
GetGroupMembers(
string RequestingAgentID, UUID GroupID)
274 List<ExtendedGroupMembersData> members =
new List<ExtendedGroupMembersData>();
276 Dictionary<string, object> sendData =
new Dictionary<string, object>();
277 sendData[
"GroupID"] = GroupID.ToString();
278 sendData[
"RequestingAgentID"] = RequestingAgentID;
280 Dictionary<string, object> ret = MakeRequest(
"GETGROUPMEMBERS", sendData);
285 if (!ret.ContainsKey(
"RESULT"))
288 if (ret[
"RESULT"].ToString() ==
"NULL")
291 foreach (
object v
in ((Dictionary<string, object>)ret[
"RESULT"]).Values)
300 public bool AddGroupRole(
string RequestingAgentID, UUID groupID, UUID roleID,
string name,
string description,
string title, ulong powers, out
string reason)
302 reason = string.Empty;
304 Dictionary<string, object> sendData =
new Dictionary<string, object>();
305 sendData[
"GroupID"] = groupID.ToString();
306 sendData[
"RoleID"] = roleID.ToString();
307 sendData[
"Name"] = GroupsDataUtils.Sanitize(name);
308 sendData[
"Description"] = GroupsDataUtils.Sanitize(description);
309 sendData[
"Title"] = GroupsDataUtils.Sanitize(title);
310 sendData[
"Powers"] = powers.ToString();
311 sendData[
"RequestingAgentID"] = RequestingAgentID;
312 sendData[
"OP"] =
"ADD";
313 Dictionary<string, object> ret = MakeRequest(
"PUTROLE", sendData);
318 if (!ret.ContainsKey(
"RESULT"))
321 if (ret[
"RESULT"].ToString().ToLower() !=
"true")
323 reason = ret[
"REASON"].ToString();
330 public bool UpdateGroupRole(
string RequestingAgentID, UUID groupID, UUID roleID,
string name,
string description,
string title, ulong powers)
332 Dictionary<string, object> sendData =
new Dictionary<string, object>();
333 sendData[
"GroupID"] = groupID.ToString();
334 sendData[
"RoleID"] = roleID.ToString();
335 sendData[
"Name"] = GroupsDataUtils.Sanitize(name);
336 sendData[
"Description"] = GroupsDataUtils.Sanitize(description);
337 sendData[
"Title"] = GroupsDataUtils.Sanitize(title);
338 sendData[
"Powers"] = powers.ToString();
339 sendData[
"RequestingAgentID"] = RequestingAgentID;
340 sendData[
"OP"] =
"UPDATE";
341 Dictionary<string, object> ret = MakeRequest(
"PUTROLE", sendData);
346 if (!ret.ContainsKey(
"RESULT"))
349 if (ret[
"RESULT"].ToString().ToLower() !=
"true")
357 Dictionary<string, object> sendData =
new Dictionary<string, object>();
358 sendData[
"GroupID"] = groupID.ToString();
359 sendData[
"RoleID"] = roleID.ToString();
360 sendData[
"RequestingAgentID"] = RequestingAgentID;
361 MakeRequest(
"REMOVEROLE", sendData);
364 public List<GroupRolesData>
GetGroupRoles(
string RequestingAgentID, UUID GroupID)
366 List<GroupRolesData> roles =
new List<GroupRolesData>();
368 Dictionary<string, object> sendData =
new Dictionary<string, object>();
369 sendData[
"GroupID"] = GroupID.ToString();
370 sendData[
"RequestingAgentID"] = RequestingAgentID;
371 Dictionary<string, object> ret = MakeRequest(
"GETGROUPROLES", sendData);
376 if (!ret.ContainsKey(
"RESULT"))
379 if (ret[
"RESULT"].ToString() ==
"NULL")
382 foreach (
object v
in ((Dictionary<string, object>)ret[
"RESULT"]).Values)
384 GroupRolesData m = GroupsDataUtils.GroupRolesData((Dictionary<string, object>)v);
393 List<ExtendedGroupRoleMembersData> rmembers =
new List<ExtendedGroupRoleMembersData>();
395 Dictionary<string, object> sendData =
new Dictionary<string, object>();
396 sendData[
"GroupID"] = GroupID.ToString();
397 sendData[
"RequestingAgentID"] = RequestingAgentID;
398 Dictionary<string, object> ret = MakeRequest(
"GETROLEMEMBERS", sendData);
403 if (!ret.ContainsKey(
"RESULT"))
406 if (ret[
"RESULT"].ToString() ==
"NULL")
409 foreach (
object v
in ((Dictionary<string, object>)ret[
"RESULT"]).Values)
420 Dictionary<string, object> sendData =
new Dictionary<string, object>();
421 sendData[
"AgentID"] = AgentID.ToString();
422 sendData[
"GroupID"] = GroupID.ToString();
423 sendData[
"RoleID"] = RoleID.ToString();
424 sendData[
"RequestingAgentID"] = RequestingAgentID;
425 sendData[
"OP"] =
"ADD";
427 Dictionary<string, object> ret = MakeRequest(
"AGENTROLE", sendData);
432 if (!ret.ContainsKey(
"RESULT"))
435 if (ret[
"RESULT"].ToString().ToLower() !=
"true")
443 Dictionary<string, object> sendData =
new Dictionary<string, object>();
444 sendData[
"AgentID"] = AgentID.ToString();
445 sendData[
"GroupID"] = GroupID.ToString();
446 sendData[
"RoleID"] = RoleID.ToString();
447 sendData[
"RequestingAgentID"] = RequestingAgentID;
448 sendData[
"OP"] =
"DELETE";
450 Dictionary<string, object> ret = MakeRequest(
"AGENTROLE", sendData);
455 if (!ret.ContainsKey(
"RESULT"))
458 if (ret[
"RESULT"].ToString().ToLower() !=
"true")
464 public List<GroupRolesData>
GetAgentGroupRoles(
string RequestingAgentID,
string AgentID, UUID GroupID)
466 List<GroupRolesData> roles =
new List<GroupRolesData>();
468 Dictionary<string, object> sendData =
new Dictionary<string, object>();
469 sendData[
"AgentID"] = AgentID.ToString();
470 sendData[
"GroupID"] = GroupID.ToString();
471 sendData[
"RequestingAgentID"] = RequestingAgentID;
472 Dictionary<string, object> ret = MakeRequest(
"GETAGENTROLES", sendData);
477 if (!ret.ContainsKey(
"RESULT"))
480 if (ret[
"RESULT"].ToString() ==
"NULL")
483 foreach (
object v
in ((Dictionary<string, object>)ret[
"RESULT"]).Values)
485 GroupRolesData m = GroupsDataUtils.GroupRolesData((Dictionary<string, object>)v);
494 Dictionary<string, object> sendData =
new Dictionary<string, object>();
495 sendData[
"AgentID"] = AgentID.ToString();
496 sendData[
"GroupID"] = GroupID.ToString();
497 sendData[
"RequestingAgentID"] = RequestingAgentID;
498 sendData[
"OP"] =
"GROUP";
500 Dictionary<string, object> ret = MakeRequest(
"SETACTIVE", sendData);
505 if (!ret.ContainsKey(
"RESULT"))
508 if (ret[
"RESULT"].ToString() ==
"NULL")
511 return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret[
"RESULT"]);
516 Dictionary<string, object> sendData =
new Dictionary<string, object>();
517 sendData[
"AgentID"] = AgentID.ToString();
518 sendData[
"GroupID"] = GroupID.ToString();
519 sendData[
"RoleID"] = RoleID.ToString();
520 sendData[
"RequestingAgentID"] = RequestingAgentID;
521 sendData[
"OP"] =
"ROLE";
523 MakeRequest(
"SETACTIVE", sendData);
526 public void UpdateMembership(
string RequestingAgentID,
string AgentID, UUID GroupID,
bool AcceptNotices,
bool ListInProfile)
528 Dictionary<string, object> sendData =
new Dictionary<string, object>();
529 sendData[
"AgentID"] = AgentID.ToString();
530 sendData[
"GroupID"] = GroupID.ToString();
531 sendData[
"AcceptNotices"] = AcceptNotices.ToString();
532 sendData[
"ListInProfile"] = ListInProfile.ToString();
533 sendData[
"RequestingAgentID"] = RequestingAgentID;
534 MakeRequest(
"UPDATEMEMBERSHIP", sendData);
537 public bool AddAgentToGroupInvite(
string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID,
string agentID)
539 Dictionary<string, object> sendData =
new Dictionary<string, object>();
540 sendData[
"InviteID"] = inviteID.ToString();
541 sendData[
"GroupID"] = groupID.ToString();
542 sendData[
"RoleID"] = roleID.ToString();
543 sendData[
"AgentID"] = agentID.ToString();
544 sendData[
"RequestingAgentID"] = RequestingAgentID;
545 sendData[
"OP"] =
"ADD";
547 Dictionary<string, object> ret = MakeRequest(
"INVITE", sendData);
552 if (!ret.ContainsKey(
"RESULT"))
555 if (ret[
"RESULT"].ToString().ToLower() !=
"true")
563 Dictionary<string, object> sendData =
new Dictionary<string, object>();
564 sendData[
"InviteID"] = inviteID.ToString();
565 sendData[
"RequestingAgentID"] = RequestingAgentID;
566 sendData[
"OP"] =
"GET";
568 Dictionary<string, object> ret = MakeRequest(
"INVITE", sendData);
573 if (!ret.ContainsKey(
"RESULT"))
576 if (ret[
"RESULT"].ToString() ==
"NULL")
579 return GroupsDataUtils.GroupInviteInfo((Dictionary<string, object>)ret[
"RESULT"]);
584 Dictionary<string, object> sendData =
new Dictionary<string, object>();
585 sendData[
"InviteID"] = inviteID.ToString();
586 sendData[
"RequestingAgentID"] = RequestingAgentID;
587 sendData[
"OP"] =
"DELETE";
589 MakeRequest(
"INVITE", sendData);
592 public bool AddGroupNotice(
string RequestingAgentID, UUID groupID, UUID noticeID,
string fromName,
string subject,
string message,
593 bool hasAttachment, byte attType,
string attName, UUID attItemID,
string attOwnerID)
595 Dictionary<string, object> sendData =
new Dictionary<string, object>();
596 sendData[
"GroupID"] = groupID.ToString();
597 sendData[
"NoticeID"] = noticeID.ToString();
598 sendData[
"FromName"] = GroupsDataUtils.Sanitize(fromName);
599 sendData[
"Subject"] = GroupsDataUtils.Sanitize(subject);
600 sendData[
"Message"] = GroupsDataUtils.Sanitize(message);
601 sendData[
"HasAttachment"] = hasAttachment.ToString();
604 sendData[
"AttachmentType"] = attType.ToString();
605 sendData[
"AttachmentName"] = attName.ToString();
606 sendData[
"AttachmentItemID"] = attItemID.ToString();
607 sendData[
"AttachmentOwnerID"] = attOwnerID;
609 sendData[
"RequestingAgentID"] = RequestingAgentID;
611 Dictionary<string, object> ret = MakeRequest(
"ADDNOTICE", sendData);
616 if (!ret.ContainsKey(
"RESULT"))
619 if (ret[
"RESULT"].ToString().ToLower() !=
"true")
627 Dictionary<string, object> sendData =
new Dictionary<string, object>();
628 sendData[
"NoticeID"] = noticeID.ToString();
629 sendData[
"RequestingAgentID"] = RequestingAgentID;
631 Dictionary<string, object> ret = MakeRequest(
"GETNOTICES", sendData);
636 if (!ret.ContainsKey(
"RESULT"))
639 if (ret[
"RESULT"].ToString() ==
"NULL")
642 return GroupsDataUtils.GroupNoticeInfo((Dictionary<string, object>)ret[
"RESULT"]);
645 public List<ExtendedGroupNoticeData>
GetGroupNotices(
string RequestingAgentID, UUID GroupID)
647 List<ExtendedGroupNoticeData> notices =
new List<ExtendedGroupNoticeData>();
649 Dictionary<string, object> sendData =
new Dictionary<string, object>();
650 sendData[
"GroupID"] = GroupID.ToString();
651 sendData[
"RequestingAgentID"] = RequestingAgentID;
652 Dictionary<string, object> ret = MakeRequest(
"GETNOTICES", sendData);
657 if (!ret.ContainsKey(
"RESULT"))
660 if (ret[
"RESULT"].ToString() ==
"NULL")
663 foreach (
object v
in ((Dictionary<string, object>)ret[
"RESULT"]).Values)
674 private Dictionary<string, object> MakeRequest(
string method, Dictionary<string, object> sendData)
676 sendData[
"METHOD"] = method;
678 string reply = string.Empty;
680 reply = SynchronousRestFormsRequester.MakeRequest("POST",
681 m_ServerURI + "groups",
682 ServerUtils.BuildQueryString(sendData),
685 if (reply ==
string.Empty)
688 Dictionary<
string,
object> replyData = ServerUtils.ParseXmlResponse(
bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID)
List< GroupRolesData > GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID)
ExtendedGroupRecord UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
GroupMembershipData SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID)
bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason)
List< DirGroupsReplyData > FindGroups(string RequestingAgentID, string query)
bool RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
ExtendedGroupRecord CreateGroup(string RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish, UUID founderID, out string reason)
bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers)
List< ExtendedGroupMembersData > GetGroupMembers(string RequestingAgentID, UUID GroupID)
List< ExtendedGroupRoleMembersData > GetGroupRoleMembers(string RequestingAgentID, UUID GroupID)
List< GroupRolesData > GetGroupRoles(string RequestingAgentID, UUID GroupID)
GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID)
bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID)
GroupMembershipData AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason)
bool AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID)
static string Sanitize(string s)
ExtendedGroupMembershipData GetMembership(string RequestingAgentID, string AgentID, UUID GroupID)
ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName)
void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
List< GroupMembershipData > GetMemberships(string RequestingAgentID, string AgentID)
GroupsServiceRemoteConnector(IConfigSource config)
List< ExtendedGroupNoticeData > GetGroupNotices(string RequestingAgentID, UUID GroupID)
void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID)