aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Addons/Groups/Hypergrid/HGGroupsServiceRobustConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Addons/Groups/Hypergrid/HGGroupsServiceRobustConnector.cs')
-rw-r--r--OpenSim/Addons/Groups/Hypergrid/HGGroupsServiceRobustConnector.cs443
1 files changed, 443 insertions, 0 deletions
diff --git a/OpenSim/Addons/Groups/Hypergrid/HGGroupsServiceRobustConnector.cs b/OpenSim/Addons/Groups/Hypergrid/HGGroupsServiceRobustConnector.cs
new file mode 100644
index 0000000..92dd85c
--- /dev/null
+++ b/OpenSim/Addons/Groups/Hypergrid/HGGroupsServiceRobustConnector.cs
@@ -0,0 +1,443 @@
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
28using System;
29using System.Reflection;
30using System.Text;
31using System.Xml;
32using System.Collections.Generic;
33using System.IO;
34using Nini.Config;
35using OpenSim.Framework;
36using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces;
38using OpenSim.Framework.Servers.HttpServer;
39using OpenSim.Server.Handlers.Base;
40using log4net;
41using OpenMetaverse;
42
43namespace OpenSim.Groups
44{
45 public class HGGroupsServiceRobustConnector : ServiceConnector
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private HGGroupsService m_GroupsService;
50 private string m_HomeURI = string.Empty;
51 private string m_ConfigName = "Groups";
52
53 // Called by Robust shell
54 public HGGroupsServiceRobustConnector(IConfigSource config, IHttpServer server, string configName) :
55 this(config, server, configName, null, null)
56 {
57 }
58
59 // Called by the sim-bound module
60 public HGGroupsServiceRobustConnector(IConfigSource config, IHttpServer server, string configName, IOfflineIMService im, IUserAccountService users) :
61 base(config, server, configName)
62 {
63 if (configName != String.Empty)
64 m_ConfigName = configName;
65
66 m_log.DebugFormat("[Groups.RobustHGConnector]: Starting with config name {0}", m_ConfigName);
67
68 IConfig cnf = config.Configs[m_ConfigName];
69 if (cnf == null)
70 throw new Exception(String.Format("[Groups.RobustHGConnector]: {0} section does not exist", m_ConfigName));
71
72 string homeURI = cnf.GetString("HomeURI", string.Empty);
73 if (homeURI == string.Empty)
74 throw new Exception(String.Format("[Groups.RobustHGConnector]: please provide the HomeURI in section {0}", m_ConfigName));
75
76 if (im == null)
77 {
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));
81
82 Object[] args = new Object[] { config };
83 im = ServerUtils.LoadPlugin<IOfflineIMService>(imDll, args);
84 }
85
86 if (users == null)
87 {
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));
91
92 Object[] args = new Object[] { config };
93 users = ServerUtils.LoadPlugin<IUserAccountService>(usersDll, args);
94 }
95
96 m_GroupsService = new HGGroupsService(config, im, users, homeURI);
97
98 server.AddStreamHandler(new HGGroupsServicePostHandler(m_GroupsService));
99 }
100
101 }
102
103 public class HGGroupsServicePostHandler : BaseStreamHandler
104 {
105 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
106
107 private HGGroupsService m_GroupsService;
108
109 public HGGroupsServicePostHandler(HGGroupsService service) :
110 base("POST", "/hg-groups")
111 {
112 m_GroupsService = service;
113 }
114
115 public override byte[] Handle(string path, Stream requestData,
116 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
117 {
118 StreamReader sr = new StreamReader(requestData);
119 string body = sr.ReadToEnd();
120 sr.Close();
121 body = body.Trim();
122
123 //m_log.DebugFormat("[XXX]: query String: {0}", body);
124
125 try
126 {
127 Dictionary<string, object> request =
128 ServerUtils.ParseQueryString(body);
129
130 if (!request.ContainsKey("METHOD"))
131 return FailureResult();
132
133 string method = request["METHOD"].ToString();
134 request.Remove("METHOD");
135
136 m_log.DebugFormat("[Groups.RobustHGConnector]: {0}", method);
137 switch (method)
138 {
139 case "POSTGROUP":
140 return HandleAddGroupProxy(request);
141 case "REMOVEAGENTFROMGROUP":
142 return HandleRemoveAgentFromGroup(request);
143 case "GETGROUP":
144 return HandleGetGroup(request);
145 case "ADDNOTICE":
146 return HandleAddNotice(request);
147 case "VERIFYNOTICE":
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);
155
156 }
157 m_log.DebugFormat("[Groups.RobustHGConnector]: unknown method request: {0}", method);
158 }
159 catch (Exception e)
160 {
161 m_log.DebugFormat("[Groups.RobustHGConnector]: Exception {0}", e.StackTrace);
162 }
163
164 return FailureResult();
165 }
166
167 byte[] HandleAddGroupProxy(Dictionary<string, object> request)
168 {
169 Dictionary<string, object> result = new Dictionary<string, object>();
170
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");
175
176 else
177 {
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();
186
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();
191 }
192
193 string xmlString = ServerUtils.BuildXmlResponse(result);
194
195 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
196 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
197 }
198
199 byte[] HandleRemoveAgentFromGroup(Dictionary<string, object> request)
200 {
201 Dictionary<string, object> result = new Dictionary<string, object>();
202
203 if (!request.ContainsKey("AccessToken") || !request.ContainsKey("AgentID") ||
204 !request.ContainsKey("GroupID"))
205 NullResult(result, "Bad network data");
206 else
207 {
208 UUID groupID = new UUID(request["GroupID"].ToString());
209 string agentID = request["AgentID"].ToString();
210 string token = request["AccessToken"].ToString();
211 string reason = string.Empty;
212
213 m_GroupsService.RemoveAgentFromGroup(agentID, agentID, groupID, token);
214 }
215
216 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
217 result["RESULT"] = "true";
218 return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result));
219 }
220
221 byte[] HandleGetGroup(Dictionary<string, object> request)
222 {
223 Dictionary<string, object> result = new Dictionary<string, object>();
224
225 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AccessToken"))
226 NullResult(result, "Bad network data");
227 else
228 {
229 string RequestingAgentID = request["RequestingAgentID"].ToString();
230 string token = request["AccessToken"].ToString();
231
232 UUID groupID = UUID.Zero;
233 string groupName = string.Empty;
234
235 if (request.ContainsKey("GroupID"))
236 groupID = new UUID(request["GroupID"].ToString());
237 if (request.ContainsKey("Name"))
238 groupName = request["Name"].ToString();
239
240 ExtendedGroupRecord grec = m_GroupsService.GetGroupRecord(RequestingAgentID, groupID, groupName, token);
241 if (grec == null)
242 NullResult(result, "Group not found");
243 else
244 result["RESULT"] = GroupsDataUtils.GroupRecord(grec);
245 }
246
247 string xmlString = ServerUtils.BuildXmlResponse(result);
248
249 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
250 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
251 }
252
253 byte[] HandleGetGroupMembers(Dictionary<string, object> request)
254 {
255 Dictionary<string, object> result = new Dictionary<string, object>();
256
257 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("AccessToken"))
258 NullResult(result, "Bad network data");
259 else
260 {
261 UUID groupID = new UUID(request["GroupID"].ToString());
262 string requestingAgentID = request["RequestingAgentID"].ToString();
263 string token = request["AccessToken"].ToString();
264
265 List<ExtendedGroupMembersData> members = m_GroupsService.GetGroupMembers(requestingAgentID, groupID, token);
266 if (members == null || (members != null && members.Count == 0))
267 {
268 NullResult(result, "No members");
269 }
270 else
271 {
272 Dictionary<string, object> dict = new Dictionary<string, object>();
273 int i = 0;
274 foreach (ExtendedGroupMembersData m in members)
275 {
276 dict["m-" + i++] = GroupsDataUtils.GroupMembersData(m);
277 }
278
279 result["RESULT"] = dict;
280 }
281 }
282
283 string xmlString = ServerUtils.BuildXmlResponse(result);
284
285 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
286 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
287 }
288
289 byte[] HandleGetGroupRoles(Dictionary<string, object> request)
290 {
291 Dictionary<string, object> result = new Dictionary<string, object>();
292
293 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("AccessToken"))
294 NullResult(result, "Bad network data");
295 else
296 {
297 UUID groupID = new UUID(request["GroupID"].ToString());
298 string requestingAgentID = request["RequestingAgentID"].ToString();
299 string token = request["AccessToken"].ToString();
300
301 List<GroupRolesData> roles = m_GroupsService.GetGroupRoles(requestingAgentID, groupID, token);
302 if (roles == null || (roles != null && roles.Count == 0))
303 {
304 NullResult(result, "No members");
305 }
306 else
307 {
308 Dictionary<string, object> dict = new Dictionary<string, object>();
309 int i = 0;
310 foreach (GroupRolesData r in roles)
311 dict["r-" + i++] = GroupsDataUtils.GroupRolesData(r);
312
313 result["RESULT"] = dict;
314 }
315 }
316
317 string xmlString = ServerUtils.BuildXmlResponse(result);
318
319 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
320 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
321 }
322
323 byte[] HandleGetRoleMembers(Dictionary<string, object> request)
324 {
325 Dictionary<string, object> result = new Dictionary<string, object>();
326
327 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("AccessToken"))
328 NullResult(result, "Bad network data");
329 else
330 {
331 UUID groupID = new UUID(request["GroupID"].ToString());
332 string requestingAgentID = request["RequestingAgentID"].ToString();
333 string token = request["AccessToken"].ToString();
334
335 List<ExtendedGroupRoleMembersData> rmembers = m_GroupsService.GetGroupRoleMembers(requestingAgentID, groupID, token);
336 if (rmembers == null || (rmembers != null && rmembers.Count == 0))
337 {
338 NullResult(result, "No members");
339 }
340 else
341 {
342 Dictionary<string, object> dict = new Dictionary<string, object>();
343 int i = 0;
344 foreach (ExtendedGroupRoleMembersData rm in rmembers)
345 dict["rm-" + i++] = GroupsDataUtils.GroupRoleMembersData(rm);
346
347 result["RESULT"] = dict;
348 }
349 }
350
351 string xmlString = ServerUtils.BuildXmlResponse(result);
352
353 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
354 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
355 }
356
357 byte[] HandleAddNotice(Dictionary<string, object> request)
358 {
359 Dictionary<string, object> result = new Dictionary<string, object>();
360
361 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("NoticeID") ||
362 !request.ContainsKey("FromName") || !request.ContainsKey("Subject") || !request.ContainsKey("Message") ||
363 !request.ContainsKey("HasAttachment"))
364 NullResult(result, "Bad network data");
365
366 else
367 {
368
369 bool hasAtt = bool.Parse(request["HasAttachment"].ToString());
370 byte attType = 0;
371 string attName = string.Empty;
372 string attOwner = string.Empty;
373 UUID attItem = UUID.Zero;
374 if (request.ContainsKey("AttachmentType"))
375 attType = byte.Parse(request["AttachmentType"].ToString());
376 if (request.ContainsKey("AttachmentName"))
377 attName = request["AttachmentType"].ToString();
378 if (request.ContainsKey("AttachmentItemID"))
379 attItem = new UUID(request["AttachmentItemID"].ToString());
380 if (request.ContainsKey("AttachmentOwnerID"))
381 attOwner = request["AttachmentOwnerID"].ToString();
382
383 bool success = m_GroupsService.AddNotice(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()),
384 new UUID(request["NoticeID"].ToString()), request["FromName"].ToString(), request["Subject"].ToString(),
385 request["Message"].ToString(), hasAtt, attType, attName, attItem, attOwner);
386
387 result["RESULT"] = success.ToString();
388 }
389
390 string xmlString = ServerUtils.BuildXmlResponse(result);
391
392 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
393 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
394 }
395
396 byte[] HandleVerifyNotice(Dictionary<string, object> request)
397 {
398 Dictionary<string, object> result = new Dictionary<string, object>();
399
400 if (!request.ContainsKey("NoticeID") || !request.ContainsKey("GroupID"))
401 NullResult(result, "Bad network data");
402
403 else
404 {
405 UUID noticeID = new UUID(request["NoticeID"].ToString());
406 UUID groupID = new UUID(request["GroupID"].ToString());
407
408 bool success = m_GroupsService.VerifyNotice(noticeID, groupID);
409 //m_log.DebugFormat("[XXX]: VerifyNotice returned {0}", success);
410 result["RESULT"] = success.ToString();
411 }
412
413 string xmlString = ServerUtils.BuildXmlResponse(result);
414
415 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
416 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
417 }
418
419 //
420 //
421 //
422 //
423 //
424
425 #region Helpers
426
427 private void NullResult(Dictionary<string, object> result, string reason)
428 {
429 result["RESULT"] = "NULL";
430 result["REASON"] = reason;
431 }
432
433 private byte[] FailureResult()
434 {
435 Dictionary<string, object> result = new Dictionary<string, object>();
436 NullResult(result, "Unknown method");
437 string xmlString = ServerUtils.BuildXmlResponse(result);
438 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
439 }
440
441 #endregion
442 }
443}