GroupsServiceRobustConnector.cs 34 KB

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