29 using System.Reflection;
32 using System.Collections.Generic;
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;
43 namespace OpenSim.Groups
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 private string m_ConfigName =
"Groups";
54 this(config, server, configName, null, null)
60 base(config, server, configName)
62 if (configName != String.Empty)
63 m_ConfigName = configName;
65 m_log.DebugFormat(
"[Groups.RobustHGConnector]: Starting with config name {0}", m_ConfigName);
67 string homeURI = Util.GetConfigVarFromSections<
string>(config,
"HomeURI",
68 new string[] {
"Startup",
"Hypergrid", m_ConfigName}, string.Empty);
69 if (homeURI ==
string.Empty)
70 throw new Exception(String.Format(
"[Groups.RobustHGConnector]: please provide the HomeURI [Startup] or in section {0}", m_ConfigName));
72 IConfig cnf = config.Configs[m_ConfigName];
74 throw new Exception(String.Format(
"[Groups.RobustHGConnector]: {0} section does not exist", m_ConfigName));
78 string imDll = cnf.GetString(
"OfflineIMService", string.Empty);
79 if (imDll ==
string.Empty)
80 throw new Exception(String.Format(
"[Groups.RobustHGConnector]: please provide OfflineIMService in section {0}", m_ConfigName));
82 Object[] args =
new Object[] { config };
88 string usersDll = cnf.GetString(
"UserAccountService", string.Empty);
89 if (usersDll ==
string.Empty)
90 throw new Exception(String.Format(
"[Groups.RobustHGConnector]: please provide UserAccountService in section {0}", m_ConfigName));
92 Object[] args =
new Object[] { config };
105 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
110 base(
"POST",
"/hg-groups")
112 m_GroupsService = service;
118 StreamReader sr =
new StreamReader(requestData);
119 string body = sr.ReadToEnd();
127 Dictionary<string, object> request =
128 ServerUtils.ParseQueryString(body);
130 if (!request.ContainsKey(
"METHOD"))
131 return FailureResult();
133 string method = request[
"METHOD"].ToString();
134 request.Remove(
"METHOD");
136 m_log.DebugFormat(
"[Groups.RobustHGConnector]: {0}", method);
140 return HandleAddGroupProxy(request);
141 case "REMOVEAGENTFROMGROUP":
142 return HandleRemoveAgentFromGroup(request);
144 return HandleGetGroup(request);
146 return HandleAddNotice(request);
148 return HandleVerifyNotice(request);
149 case "GETGROUPMEMBERS":
150 return HandleGetGroupMembers(request);
151 case "GETGROUPROLES":
152 return HandleGetGroupRoles(request);
153 case "GETROLEMEMBERS":
154 return HandleGetRoleMembers(request);
157 m_log.DebugFormat(
"[Groups.RobustHGConnector]: unknown method request: {0}", method);
161 m_log.Error(string.Format(
"[Groups.RobustHGConnector]: Exception {0} ", e.Message), e);
164 return FailureResult();
167 byte[] HandleAddGroupProxy(Dictionary<string, object> request)
169 Dictionary<string, object> result =
new Dictionary<string, object>();
171 if (!request.ContainsKey(
"RequestingAgentID") || !request.ContainsKey(
"GroupID")
172 || !request.ContainsKey(
"AgentID")
173 || !request.ContainsKey(
"AccessToken") || !request.ContainsKey(
"Location"))
174 NullResult(result,
"Bad network data");
178 string RequestingAgentID = request[
"RequestingAgentID"].ToString();
179 string agentID = request[
"AgentID"].ToString();
180 UUID groupID =
new UUID(request[
"GroupID"].ToString());
181 string accessToken = request[
"AccessToken"].ToString();
182 string location = request[
"Location"].ToString();
183 string name = string.Empty;
184 if (request.ContainsKey(
"Name"))
185 name = request[
"Name"].ToString();
187 string reason = string.Empty;
188 bool success = m_GroupsService.CreateGroupProxy(RequestingAgentID, agentID, accessToken, groupID, location, name, out reason);
189 result[
"REASON"] = reason;
190 result[
"RESULT"] = success.ToString();
193 string xmlString = ServerUtils.BuildXmlResponse(result);
196 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
199 byte[] HandleRemoveAgentFromGroup(Dictionary<string, object> request)
201 Dictionary<string, object> result =
new Dictionary<string, object>();
203 if (!request.ContainsKey(
"AccessToken") || !request.ContainsKey(
"AgentID") ||
204 !request.ContainsKey(
"GroupID"))
205 NullResult(result,
"Bad network data");
208 UUID groupID =
new UUID(request[
"GroupID"].ToString());
209 string agentID = request[
"AgentID"].ToString();
210 string token = request[
"AccessToken"].ToString();
212 if (!m_GroupsService.RemoveAgentFromGroup(agentID, agentID, groupID, token))
213 NullResult(result,
"Internal error");
215 result[
"RESULT"] =
"true";
219 return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result));
222 byte[] HandleGetGroup(Dictionary<string, object> request)
224 Dictionary<string, object> result =
new Dictionary<string, object>();
226 if (!request.ContainsKey(
"RequestingAgentID") || !request.ContainsKey(
"AccessToken"))
227 NullResult(result,
"Bad network data");
230 string RequestingAgentID = request[
"RequestingAgentID"].ToString();
231 string token = request[
"AccessToken"].ToString();
233 UUID groupID = UUID.Zero;
234 string groupName = string.Empty;
236 if (request.ContainsKey(
"GroupID"))
237 groupID =
new UUID(request[
"GroupID"].ToString());
238 if (request.ContainsKey(
"Name"))
239 groupName = request[
"Name"].ToString();
241 ExtendedGroupRecord grec = m_GroupsService.GetGroupRecord(RequestingAgentID, groupID, groupName, token);
243 NullResult(result,
"Group not found");
245 result[
"RESULT"] = GroupsDataUtils.GroupRecord(grec);
248 string xmlString = ServerUtils.BuildXmlResponse(result);
251 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
254 byte[] HandleGetGroupMembers(Dictionary<string, object> request)
256 Dictionary<string, object> result =
new Dictionary<string, object>();
258 if (!request.ContainsKey(
"RequestingAgentID") || !request.ContainsKey(
"GroupID") || !request.ContainsKey(
"AccessToken"))
259 NullResult(result,
"Bad network data");
262 UUID groupID =
new UUID(request[
"GroupID"].ToString());
263 string requestingAgentID = request[
"RequestingAgentID"].ToString();
264 string token = request[
"AccessToken"].ToString();
266 List<ExtendedGroupMembersData> members = m_GroupsService.GetGroupMembers(requestingAgentID, groupID, token);
267 if (members == null || (members != null && members.Count == 0))
269 NullResult(result,
"No members");
273 Dictionary<string, object> dict =
new Dictionary<string, object>();
275 foreach (ExtendedGroupMembersData m
in members)
277 dict[
"m-" + i++] = GroupsDataUtils.GroupMembersData(m);
280 result[
"RESULT"] = dict;
284 string xmlString = ServerUtils.BuildXmlResponse(result);
287 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
290 byte[] HandleGetGroupRoles(Dictionary<string, object> request)
292 Dictionary<string, object> result =
new Dictionary<string, object>();
294 if (!request.ContainsKey(
"RequestingAgentID") || !request.ContainsKey(
"GroupID") || !request.ContainsKey(
"AccessToken"))
295 NullResult(result,
"Bad network data");
298 UUID groupID =
new UUID(request[
"GroupID"].ToString());
299 string requestingAgentID = request[
"RequestingAgentID"].ToString();
300 string token = request[
"AccessToken"].ToString();
302 List<GroupRolesData> roles = m_GroupsService.GetGroupRoles(requestingAgentID, groupID, token);
303 if (roles == null || (roles != null && roles.Count == 0))
305 NullResult(result,
"No members");
309 Dictionary<string, object> dict =
new Dictionary<string, object>();
312 dict[
"r-" + i++] = GroupsDataUtils.GroupRolesData(r);
314 result[
"RESULT"] = dict;
318 string xmlString = ServerUtils.BuildXmlResponse(result);
321 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
324 byte[] HandleGetRoleMembers(Dictionary<string, object> request)
326 Dictionary<string, object> result =
new Dictionary<string, object>();
328 if (!request.ContainsKey(
"RequestingAgentID") || !request.ContainsKey(
"GroupID") || !request.ContainsKey(
"AccessToken"))
329 NullResult(result,
"Bad network data");
332 UUID groupID =
new UUID(request[
"GroupID"].ToString());
333 string requestingAgentID = request[
"RequestingAgentID"].ToString();
334 string token = request[
"AccessToken"].ToString();
336 List<ExtendedGroupRoleMembersData> rmembers = m_GroupsService.GetGroupRoleMembers(requestingAgentID, groupID, token);
337 if (rmembers == null || (rmembers != null && rmembers.Count == 0))
339 NullResult(result,
"No members");
343 Dictionary<string, object> dict =
new Dictionary<string, object>();
345 foreach (ExtendedGroupRoleMembersData rm
in rmembers)
346 dict[
"rm-" + i++] = GroupsDataUtils.GroupRoleMembersData(rm);
348 result[
"RESULT"] = dict;
352 string xmlString = ServerUtils.BuildXmlResponse(result);
355 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
358 byte[] HandleAddNotice(Dictionary<string, object> request)
360 Dictionary<string, object> result =
new Dictionary<string, object>();
362 if (!request.ContainsKey(
"RequestingAgentID") || !request.ContainsKey(
"GroupID") || !request.ContainsKey(
"NoticeID") ||
363 !request.ContainsKey(
"FromName") || !request.ContainsKey(
"Subject") || !request.ContainsKey(
"Message") ||
364 !request.ContainsKey(
"HasAttachment"))
365 NullResult(result,
"Bad network data");
370 bool hasAtt = bool.Parse(request[
"HasAttachment"].ToString());
372 string attName = string.Empty;
373 string attOwner = string.Empty;
374 UUID attItem = UUID.Zero;
375 if (request.ContainsKey(
"AttachmentType"))
376 attType = byte.Parse(request[
"AttachmentType"].ToString());
377 if (request.ContainsKey(
"AttachmentName"))
378 attName = request[
"AttachmentType"].ToString();
379 if (request.ContainsKey(
"AttachmentItemID"))
380 attItem =
new UUID(request[
"AttachmentItemID"].ToString());
381 if (request.ContainsKey(
"AttachmentOwnerID"))
382 attOwner = request[
"AttachmentOwnerID"].ToString();
384 bool success = m_GroupsService.AddNotice(request[
"RequestingAgentID"].ToString(),
new UUID(request[
"GroupID"].ToString()),
385 new UUID(request[
"NoticeID"].ToString()), request[
"FromName"].ToString(), request[
"Subject"].ToString(),
386 request[
"Message"].ToString(), hasAtt, attType, attName, attItem, attOwner);
388 result[
"RESULT"] = success.ToString();
391 string xmlString = ServerUtils.BuildXmlResponse(result);
394 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
397 byte[] HandleVerifyNotice(Dictionary<string, object> request)
399 Dictionary<string, object> result =
new Dictionary<string, object>();
401 if (!request.ContainsKey(
"NoticeID") || !request.ContainsKey(
"GroupID"))
402 NullResult(result,
"Bad network data");
406 UUID noticeID =
new UUID(request[
"NoticeID"].ToString());
407 UUID groupID =
new UUID(request[
"GroupID"].ToString());
409 bool success = m_GroupsService.VerifyNotice(noticeID, groupID);
411 result[
"RESULT"] = success.ToString();
414 string xmlString = ServerUtils.BuildXmlResponse(result);
417 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
428 private void NullResult(Dictionary<string, object> result,
string reason)
430 result[
"RESULT"] =
"NULL";
431 result[
"REASON"] = reason;
434 private byte[] FailureResult()
436 Dictionary<string, object> result =
new Dictionary<string, object>();
437 NullResult(result,
"Unknown method");
438 string xmlString = ServerUtils.BuildXmlResponse(result);
439 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
Base streamed request handler.
HGGroupsServiceRobustConnector(IConfigSource config, IHttpServer server, string configName, IOfflineIMService im, IUserAccountService users)
HGGroupsServiceRobustConnector(IConfigSource config, IHttpServer server, string configName)
override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
HGGroupsServicePostHandler(HGGroupsService service)