XmlRpcGroupsServicesConnectorModule.cs 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  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.Collections;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using System.Text;
  32. using Nwc.XmlRpc;
  33. using log4net;
  34. using Mono.Addins;
  35. using Nini.Config;
  36. using OpenMetaverse;
  37. using OpenMetaverse.StructuredData;
  38. using OpenSim.Framework;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Services.Interfaces;
  41. namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
  42. {
  43. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XmlRpcGroupsServicesConnectorModule")]
  44. public class XmlRpcGroupsServicesConnectorModule : ISharedRegionModule, IGroupsServicesConnector
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. private bool m_debugEnabled = false;
  48. public const GroupPowers DefaultEveryonePowers
  49. = GroupPowers.AllowSetHome
  50. | GroupPowers.Accountable
  51. | GroupPowers.JoinChat
  52. | GroupPowers.AllowVoiceChat
  53. | GroupPowers.ReceiveNotices
  54. | GroupPowers.StartProposal
  55. | GroupPowers.VoteOnProposal;
  56. // Would this be cleaner as (GroupPowers)ulong.MaxValue?
  57. public const GroupPowers DefaultOwnerPowers
  58. = GroupPowers.Accountable
  59. | GroupPowers.AllowEditLand
  60. | GroupPowers.AllowFly
  61. | GroupPowers.AllowLandmark
  62. | GroupPowers.AllowRez
  63. | GroupPowers.AllowSetHome
  64. | GroupPowers.AllowVoiceChat
  65. | GroupPowers.AssignMember
  66. | GroupPowers.AssignMemberLimited
  67. | GroupPowers.ChangeActions
  68. | GroupPowers.ChangeIdentity
  69. | GroupPowers.ChangeMedia
  70. | GroupPowers.ChangeOptions
  71. | GroupPowers.CreateRole
  72. | GroupPowers.DeedObject
  73. | GroupPowers.DeleteRole
  74. | GroupPowers.Eject
  75. | GroupPowers.FindPlaces
  76. | GroupPowers.Invite
  77. | GroupPowers.JoinChat
  78. | GroupPowers.LandChangeIdentity
  79. | GroupPowers.LandDeed
  80. | GroupPowers.LandDivideJoin
  81. | GroupPowers.LandEdit
  82. | GroupPowers.AllowEnvironment
  83. | GroupPowers.LandEjectAndFreeze
  84. | GroupPowers.LandGardening
  85. | GroupPowers.LandManageAllowed
  86. | GroupPowers.LandManageBanned
  87. | GroupPowers.LandManagePasses
  88. | GroupPowers.LandOptions
  89. | GroupPowers.LandRelease
  90. | GroupPowers.LandSetSale
  91. | GroupPowers.ModerateChat
  92. | GroupPowers.ObjectManipulate
  93. | GroupPowers.ObjectSetForSale
  94. | GroupPowers.ReceiveNotices
  95. | GroupPowers.RemoveMember
  96. | GroupPowers.ReturnGroupOwned
  97. | GroupPowers.ReturnGroupSet
  98. | GroupPowers.ReturnNonGroup
  99. | GroupPowers.RoleProperties
  100. | GroupPowers.SendNotices
  101. | GroupPowers.SetLandingPoint
  102. | GroupPowers.StartProposal
  103. | GroupPowers.VoteOnProposal;
  104. private bool m_connectorEnabled = false;
  105. private string m_groupsServerURI = string.Empty;
  106. private bool m_disableKeepAlive = true;
  107. private string m_groupReadKey = string.Empty;
  108. private string m_groupWriteKey = string.Empty;
  109. private IUserAccountService m_accountService = null;
  110. private ExpiringCache<string, XmlRpcResponse> m_memoryCache;
  111. private int m_cacheTimeout = 30;
  112. // Used to track which agents are have dropped from a group chat session
  113. // Should be reset per agent, on logon
  114. // TODO: move this to Flotsam XmlRpc Service
  115. // SessionID, List<AgentID>
  116. private Dictionary<UUID, List<UUID>> m_groupsAgentsDroppedFromChatSession = new Dictionary<UUID, List<UUID>>();
  117. private Dictionary<UUID, List<UUID>> m_groupsAgentsInvitedToChatSession = new Dictionary<UUID, List<UUID>>();
  118. #region Region Module interfaceBase Members
  119. public string Name
  120. {
  121. get { return "XmlRpcGroupsServicesConnector"; }
  122. }
  123. // this module is not intended to be replaced, but there should only be 1 of them.
  124. public Type ReplaceableInterface
  125. {
  126. get { return null; }
  127. }
  128. public void Initialise(IConfigSource config)
  129. {
  130. IConfig groupsConfig = config.Configs["Groups"];
  131. if (groupsConfig == null)
  132. {
  133. // Do not run this module by default.
  134. return;
  135. }
  136. else
  137. {
  138. // if groups aren't enabled, we're not needed.
  139. // if we're not specified as the connector to use, then we're not wanted
  140. if ((groupsConfig.GetBoolean("Enabled", false) == false)
  141. || (groupsConfig.GetString("ServicesConnectorModule", "XmlRpcGroupsServicesConnector") != Name))
  142. {
  143. m_connectorEnabled = false;
  144. return;
  145. }
  146. m_log.DebugFormat("[XMLRPC-GROUPS-CONNECTOR]: Initializing {0}", this.Name);
  147. m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty);
  148. if (string.IsNullOrEmpty(m_groupsServerURI))
  149. {
  150. m_log.ErrorFormat("Please specify a valid URL for GroupsServerURI in OpenSim.ini, [Groups]");
  151. m_connectorEnabled = false;
  152. return;
  153. }
  154. m_disableKeepAlive = groupsConfig.GetBoolean("XmlRpcDisableKeepAlive", true);
  155. m_groupReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty);
  156. m_groupWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty);
  157. m_cacheTimeout = groupsConfig.GetInt("GroupsCacheTimeout", 30);
  158. if (m_cacheTimeout == 0)
  159. {
  160. m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Disabled.");
  161. }
  162. else
  163. {
  164. m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Timeout set to {0}.", m_cacheTimeout);
  165. }
  166. m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", false);
  167. // If we got all the config options we need, lets start'er'up
  168. m_memoryCache = new ExpiringCache<string, XmlRpcResponse>();
  169. m_connectorEnabled = true;
  170. }
  171. }
  172. public void Close()
  173. {
  174. }
  175. public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene)
  176. {
  177. if (m_connectorEnabled)
  178. {
  179. if (m_accountService == null)
  180. {
  181. m_accountService = scene.UserAccountService;
  182. }
  183. scene.RegisterModuleInterface<IGroupsServicesConnector>(this);
  184. }
  185. }
  186. public void RemoveRegion(OpenSim.Region.Framework.Scenes.Scene scene)
  187. {
  188. if (scene.RequestModuleInterface<IGroupsServicesConnector>() == this)
  189. {
  190. scene.UnregisterModuleInterface<IGroupsServicesConnector>(this);
  191. }
  192. }
  193. public void RegionLoaded(OpenSim.Region.Framework.Scenes.Scene scene)
  194. {
  195. // TODO: May want to consider listenning for Agent Connections so we can pre-cache group info
  196. // scene.EventManager.OnNewClient += OnNewClient;
  197. }
  198. #endregion
  199. #region ISharedRegionModule Members
  200. public void PostInitialise()
  201. {
  202. // NoOp
  203. }
  204. #endregion
  205. #region IGroupsServicesConnector Members
  206. /// <summary>
  207. /// Create a Group, including Everyone and Owners Role, place FounderID in both groups, select Owner as selected role, and newly created group as agent's active role.
  208. /// </summary>
  209. public UUID CreateGroup(UUID requestingAgentID, string name, string charter, bool showInList, UUID insigniaID,
  210. int membershipFee, bool openEnrollment, bool allowPublish,
  211. bool maturePublish, UUID founderID)
  212. {
  213. UUID GroupID = UUID.Random();
  214. UUID OwnerRoleID = UUID.Random();
  215. Hashtable param = new Hashtable();
  216. param["GroupID"] = GroupID.ToString();
  217. param["Name"] = name;
  218. param["Charter"] = charter;
  219. param["ShowInList"] = showInList == true ? 1 : 0;
  220. param["InsigniaID"] = insigniaID.ToString();
  221. param["MembershipFee"] = membershipFee;
  222. param["OpenEnrollment"] = openEnrollment == true ? 1 : 0;
  223. param["AllowPublish"] = allowPublish == true ? 1 : 0;
  224. param["MaturePublish"] = maturePublish == true ? 1 : 0;
  225. param["FounderID"] = founderID.ToString();
  226. param["EveryonePowers"] = ((ulong)DefaultEveryonePowers).ToString();
  227. param["OwnerRoleID"] = OwnerRoleID.ToString();
  228. param["OwnersPowers"] = ((ulong)DefaultOwnerPowers).ToString();
  229. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.createGroup", param);
  230. if (respData.Contains("error"))
  231. {
  232. // UUID is not nullable
  233. return UUID.Zero;
  234. }
  235. return UUID.Parse((string)respData["GroupID"]);
  236. }
  237. public void UpdateGroup(UUID requestingAgentID, UUID groupID, string charter, bool showInList,
  238. UUID insigniaID, int membershipFee, bool openEnrollment,
  239. bool allowPublish, bool maturePublish)
  240. {
  241. Hashtable param = new Hashtable();
  242. param["GroupID"] = groupID.ToString();
  243. param["Charter"] = charter;
  244. param["ShowInList"] = showInList == true ? 1 : 0;
  245. param["InsigniaID"] = insigniaID.ToString();
  246. param["MembershipFee"] = membershipFee;
  247. param["OpenEnrollment"] = openEnrollment == true ? 1 : 0;
  248. param["AllowPublish"] = allowPublish == true ? 1 : 0;
  249. param["MaturePublish"] = maturePublish == true ? 1 : 0;
  250. XmlRpcCall(requestingAgentID, "groups.updateGroup", param);
  251. }
  252. public void AddGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID, string name, string description,
  253. string title, ulong powers)
  254. {
  255. Hashtable param = new Hashtable();
  256. param["GroupID"] = groupID.ToString();
  257. param["RoleID"] = roleID.ToString();
  258. param["Name"] = name;
  259. param["Description"] = description;
  260. param["Title"] = title;
  261. param["Powers"] = powers.ToString();
  262. XmlRpcCall(requestingAgentID, "groups.addRoleToGroup", param);
  263. }
  264. public void RemoveGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID)
  265. {
  266. Hashtable param = new Hashtable();
  267. param["GroupID"] = groupID.ToString();
  268. param["RoleID"] = roleID.ToString();
  269. XmlRpcCall(requestingAgentID, "groups.removeRoleFromGroup", param);
  270. }
  271. public void UpdateGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID, string name, string description,
  272. string title, ulong powers)
  273. {
  274. Hashtable param = new Hashtable();
  275. param["GroupID"] = groupID.ToString();
  276. param["RoleID"] = roleID.ToString();
  277. if (name != null)
  278. {
  279. param["Name"] = name;
  280. }
  281. if (description != null)
  282. {
  283. param["Description"] = description;
  284. }
  285. if (title != null)
  286. {
  287. param["Title"] = title;
  288. }
  289. param["Powers"] = powers.ToString();
  290. XmlRpcCall(requestingAgentID, "groups.updateGroupRole", param);
  291. }
  292. public GroupRecord GetGroupRecord(UUID requestingAgentID, UUID GroupID, string GroupName)
  293. {
  294. Hashtable param = new Hashtable();
  295. if (GroupID != UUID.Zero)
  296. {
  297. param["GroupID"] = GroupID.ToString();
  298. }
  299. if (!string.IsNullOrEmpty(GroupName))
  300. {
  301. param["Name"] = GroupName.ToString();
  302. }
  303. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroup", param);
  304. if (respData.Contains("error"))
  305. {
  306. return null;
  307. }
  308. return GroupProfileHashtableToGroupRecord(respData);
  309. }
  310. public GroupProfileData GetMemberGroupProfile(UUID requestingAgentID, UUID GroupID, UUID AgentID)
  311. {
  312. Hashtable param = new Hashtable();
  313. param["GroupID"] = GroupID.ToString();
  314. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroup", param);
  315. if (respData.Contains("error"))
  316. {
  317. // GroupProfileData is not nullable
  318. return new GroupProfileData();
  319. }
  320. GroupMembershipData MemberInfo = GetAgentGroupMembership(requestingAgentID, AgentID, GroupID);
  321. GroupProfileData MemberGroupProfile = GroupProfileHashtableToGroupProfileData(respData);
  322. if(MemberInfo != null)
  323. {
  324. MemberGroupProfile.MemberTitle = MemberInfo.GroupTitle;
  325. MemberGroupProfile.PowersMask = MemberInfo.GroupPowers;
  326. }
  327. return MemberGroupProfile;
  328. }
  329. public void SetAgentActiveGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  330. {
  331. Hashtable param = new Hashtable();
  332. param["AgentID"] = AgentID.ToString();
  333. param["GroupID"] = GroupID.ToString();
  334. XmlRpcCall(requestingAgentID, "groups.setAgentActiveGroup", param);
  335. }
  336. public void SetAgentActiveGroupRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  337. {
  338. Hashtable param = new Hashtable();
  339. param["AgentID"] = AgentID.ToString();
  340. param["GroupID"] = GroupID.ToString();
  341. param["SelectedRoleID"] = RoleID.ToString();
  342. XmlRpcCall(requestingAgentID, "groups.setAgentGroupInfo", param);
  343. }
  344. public void SetAgentGroupInfo(UUID requestingAgentID, UUID AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
  345. {
  346. Hashtable param = new Hashtable();
  347. param["AgentID"] = AgentID.ToString();
  348. param["GroupID"] = GroupID.ToString();
  349. param["AcceptNotices"] = AcceptNotices ? "1" : "0";
  350. param["ListInProfile"] = ListInProfile ? "1" : "0";
  351. XmlRpcCall(requestingAgentID, "groups.setAgentGroupInfo", param);
  352. }
  353. public void AddAgentToGroupInvite(UUID requestingAgentID, UUID inviteID, UUID groupID, UUID roleID, UUID agentID)
  354. {
  355. Hashtable param = new Hashtable();
  356. param["InviteID"] = inviteID.ToString();
  357. param["AgentID"] = agentID.ToString();
  358. param["RoleID"] = roleID.ToString();
  359. param["GroupID"] = groupID.ToString();
  360. XmlRpcCall(requestingAgentID, "groups.addAgentToGroupInvite", param);
  361. }
  362. public GroupInviteInfo GetAgentToGroupInvite(UUID requestingAgentID, UUID inviteID)
  363. {
  364. Hashtable param = new Hashtable();
  365. param["InviteID"] = inviteID.ToString();
  366. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getAgentToGroupInvite", param);
  367. if (respData.Contains("error"))
  368. {
  369. return null;
  370. }
  371. GroupInviteInfo inviteInfo = new GroupInviteInfo();
  372. inviteInfo.InviteID = inviteID;
  373. inviteInfo.GroupID = UUID.Parse((string)respData["GroupID"]);
  374. inviteInfo.RoleID = UUID.Parse((string)respData["RoleID"]);
  375. inviteInfo.AgentID = UUID.Parse((string)respData["AgentID"]);
  376. return inviteInfo;
  377. }
  378. public void RemoveAgentToGroupInvite(UUID requestingAgentID, UUID inviteID)
  379. {
  380. Hashtable param = new Hashtable();
  381. param["InviteID"] = inviteID.ToString();
  382. XmlRpcCall(requestingAgentID, "groups.removeAgentToGroupInvite", param);
  383. }
  384. public void AddAgentToGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  385. {
  386. Hashtable param = new Hashtable();
  387. param["AgentID"] = AgentID.ToString();
  388. param["GroupID"] = GroupID.ToString();
  389. param["RoleID"] = RoleID.ToString();
  390. XmlRpcCall(requestingAgentID, "groups.addAgentToGroup", param);
  391. }
  392. public void RemoveAgentFromGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  393. {
  394. Hashtable param = new Hashtable();
  395. param["AgentID"] = AgentID.ToString();
  396. param["GroupID"] = GroupID.ToString();
  397. XmlRpcCall(requestingAgentID, "groups.removeAgentFromGroup", param);
  398. }
  399. public void AddAgentToGroupRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  400. {
  401. Hashtable param = new Hashtable();
  402. param["AgentID"] = AgentID.ToString();
  403. param["GroupID"] = GroupID.ToString();
  404. param["RoleID"] = RoleID.ToString();
  405. XmlRpcCall(requestingAgentID, "groups.addAgentToGroupRole", param);
  406. }
  407. public void RemoveAgentFromGroupRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  408. {
  409. Hashtable param = new Hashtable();
  410. param["AgentID"] = AgentID.ToString();
  411. param["GroupID"] = GroupID.ToString();
  412. param["RoleID"] = RoleID.ToString();
  413. XmlRpcCall(requestingAgentID, "groups.removeAgentFromGroupRole", param);
  414. }
  415. public List<DirGroupsReplyData> FindGroups(UUID requestingAgentID, string search)
  416. {
  417. Hashtable param = new Hashtable();
  418. param["Search"] = search;
  419. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.findGroups", param);
  420. List<DirGroupsReplyData> findings = new List<DirGroupsReplyData>();
  421. if (!respData.Contains("error"))
  422. {
  423. Hashtable results = (Hashtable)respData["results"];
  424. foreach (Hashtable groupFind in results.Values)
  425. {
  426. DirGroupsReplyData data = new DirGroupsReplyData();
  427. data.groupID = new UUID((string)groupFind["GroupID"]); ;
  428. data.groupName = (string)groupFind["Name"];
  429. data.members = int.Parse((string)groupFind["Members"]);
  430. // data.searchOrder = order;
  431. findings.Add(data);
  432. }
  433. }
  434. return findings;
  435. }
  436. public GroupMembershipData GetAgentGroupMembership(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  437. {
  438. Hashtable param = new Hashtable();
  439. param["AgentID"] = AgentID.ToString();
  440. param["GroupID"] = GroupID.ToString();
  441. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getAgentGroupMembership", param);
  442. if (respData.Contains("error"))
  443. {
  444. return null;
  445. }
  446. GroupMembershipData data = HashTableToGroupMembershipData(respData);
  447. return data;
  448. }
  449. public GroupMembershipData GetAgentActiveMembership(UUID requestingAgentID, UUID AgentID)
  450. {
  451. Hashtable param = new Hashtable();
  452. param["AgentID"] = AgentID.ToString();
  453. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getAgentActiveMembership", param);
  454. if (respData.Contains("error"))
  455. {
  456. return null;
  457. }
  458. return HashTableToGroupMembershipData(respData);
  459. }
  460. public List<GroupMembershipData> GetAgentGroupMemberships(UUID requestingAgentID, UUID AgentID)
  461. {
  462. Hashtable param = new Hashtable();
  463. param["AgentID"] = AgentID.ToString();
  464. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getAgentGroupMemberships", param);
  465. List<GroupMembershipData> memberships = new List<GroupMembershipData>();
  466. if (!respData.Contains("error"))
  467. {
  468. foreach (object membership in respData.Values)
  469. {
  470. memberships.Add(HashTableToGroupMembershipData((Hashtable)membership));
  471. }
  472. }
  473. return memberships;
  474. }
  475. public List<GroupRolesData> GetAgentGroupRoles(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  476. {
  477. Hashtable param = new Hashtable();
  478. param["AgentID"] = AgentID.ToString();
  479. param["GroupID"] = GroupID.ToString();
  480. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getAgentRoles", param);
  481. List<GroupRolesData> Roles = new List<GroupRolesData>();
  482. if (respData.Contains("error"))
  483. {
  484. return Roles;
  485. }
  486. foreach (Hashtable role in respData.Values)
  487. {
  488. GroupRolesData data = new GroupRolesData();
  489. data.RoleID = new UUID((string)role["RoleID"]);
  490. data.Name = (string)role["Name"];
  491. data.Description = (string)role["Description"];
  492. data.Powers = ulong.Parse((string)role["Powers"]);
  493. data.Title = (string)role["Title"];
  494. Roles.Add(data);
  495. }
  496. return Roles;
  497. }
  498. public List<GroupRolesData> GetGroupRoles(UUID requestingAgentID, UUID GroupID)
  499. {
  500. Hashtable param = new Hashtable();
  501. param["GroupID"] = GroupID.ToString();
  502. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupRoles", param);
  503. List<GroupRolesData> Roles = new List<GroupRolesData>();
  504. if (respData.Contains("error"))
  505. {
  506. return Roles;
  507. }
  508. foreach (Hashtable role in respData.Values)
  509. {
  510. GroupRolesData data = new GroupRolesData();
  511. data.Description = (string)role["Description"];
  512. data.Members = int.Parse((string)role["Members"]);
  513. data.Name = (string)role["Name"];
  514. data.Powers = ulong.Parse((string)role["Powers"]);
  515. data.RoleID = new UUID((string)role["RoleID"]);
  516. data.Title = (string)role["Title"];
  517. Roles.Add(data);
  518. }
  519. return Roles;
  520. }
  521. public List<GroupMembersData> GetGroupMembers(UUID requestingAgentID, UUID GroupID)
  522. {
  523. Hashtable param = new Hashtable();
  524. param["GroupID"] = GroupID.ToString();
  525. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupMembers", param);
  526. List<GroupMembersData> members = new List<GroupMembersData>();
  527. if (respData.Contains("error"))
  528. {
  529. return members;
  530. }
  531. foreach (Hashtable membership in respData.Values)
  532. {
  533. GroupMembersData data = new GroupMembersData();
  534. data.AcceptNotices = ((string)membership["AcceptNotices"]) == "1";
  535. data.AgentID = new UUID((string)membership["AgentID"]);
  536. data.Contribution = int.Parse((string)membership["Contribution"]);
  537. data.IsOwner = ((string)membership["IsOwner"]) == "1";
  538. data.ListInProfile = ((string)membership["ListInProfile"]) == "1";
  539. data.AgentPowers = ulong.Parse((string)membership["AgentPowers"]);
  540. data.Title = (string)membership["Title"];
  541. if(membership.ContainsKey("OnlineStatus"))
  542. data.OnlineStatus = (string)membership["OnlineStatus"];
  543. members.Add(data);
  544. }
  545. return members;
  546. }
  547. public List<GroupRoleMembersData> GetGroupRoleMembers(UUID requestingAgentID, UUID GroupID)
  548. {
  549. Hashtable param = new Hashtable();
  550. param["GroupID"] = GroupID.ToString();
  551. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupRoleMembers", param);
  552. List<GroupRoleMembersData> members = new List<GroupRoleMembersData>();
  553. if (!respData.Contains("error"))
  554. {
  555. foreach (Hashtable membership in respData.Values)
  556. {
  557. GroupRoleMembersData data = new GroupRoleMembersData();
  558. data.MemberID = new UUID((string)membership["AgentID"]);
  559. data.RoleID = new UUID((string)membership["RoleID"]);
  560. members.Add(data);
  561. }
  562. }
  563. return members;
  564. }
  565. public List<GroupNoticeData> GetGroupNotices(UUID requestingAgentID, UUID GroupID)
  566. {
  567. Hashtable param = new Hashtable();
  568. param["GroupID"] = GroupID.ToString();
  569. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupNotices", param);
  570. List<GroupNoticeData> values = new List<GroupNoticeData>();
  571. if (!respData.Contains("error"))
  572. {
  573. foreach (Hashtable value in respData.Values)
  574. {
  575. GroupNoticeData data = new GroupNoticeData();
  576. data.NoticeID = UUID.Parse((string)value["NoticeID"]);
  577. data.Timestamp = uint.Parse((string)value["Timestamp"]);
  578. data.FromName = (string)value["FromName"];
  579. data.Subject = (string)value["Subject"];
  580. data.HasAttachment = false;
  581. data.AssetType = 0;
  582. values.Add(data);
  583. }
  584. }
  585. return values;
  586. }
  587. public GroupNoticeInfo GetGroupNotice(UUID requestingAgentID, UUID noticeID)
  588. {
  589. Hashtable param = new Hashtable();
  590. param["NoticeID"] = noticeID.ToString();
  591. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupNotice", param);
  592. if (respData.Contains("error"))
  593. {
  594. return null;
  595. }
  596. GroupNoticeInfo data = new GroupNoticeInfo();
  597. data.GroupID = UUID.Parse((string)respData["GroupID"]);
  598. data.Message = (string)respData["Message"];
  599. data.BinaryBucket = Utils.HexStringToBytes((string)respData["BinaryBucket"], true);
  600. data.noticeData.NoticeID = UUID.Parse((string)respData["NoticeID"]);
  601. data.noticeData.Timestamp = uint.Parse((string)respData["Timestamp"]);
  602. data.noticeData.FromName = (string)respData["FromName"];
  603. data.noticeData.Subject = (string)respData["Subject"];
  604. data.noticeData.HasAttachment = false;
  605. data.noticeData.AssetType = 0;
  606. if (data.Message == null)
  607. {
  608. data.Message = string.Empty;
  609. }
  610. return data;
  611. }
  612. public void AddGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket)
  613. {
  614. string binBucket = OpenMetaverse.Utils.BytesToHexString(binaryBucket, "");
  615. Hashtable param = new Hashtable();
  616. param["GroupID"] = groupID.ToString();
  617. param["NoticeID"] = noticeID.ToString();
  618. param["FromName"] = fromName;
  619. param["Subject"] = subject;
  620. param["Message"] = message;
  621. param["BinaryBucket"] = binBucket;
  622. param["TimeStamp"] = ((uint)Util.UnixTimeSinceEpoch()).ToString();
  623. XmlRpcCall(requestingAgentID, "groups.addGroupNotice", param);
  624. }
  625. #endregion
  626. #region GroupSessionTracking
  627. public void ResetAgentGroupChatSessions(UUID agentID)
  628. {
  629. foreach (List<UUID> agentList in m_groupsAgentsDroppedFromChatSession.Values)
  630. {
  631. agentList.Remove(agentID);
  632. }
  633. }
  634. public bool hasAgentBeenInvitedToGroupChatSession(UUID agentID, UUID groupID)
  635. {
  636. // If we're tracking this group, and we can find them in the tracking, then they've been invited
  637. return m_groupsAgentsInvitedToChatSession.ContainsKey(groupID)
  638. && m_groupsAgentsInvitedToChatSession[groupID].Contains(agentID);
  639. }
  640. public bool hasAgentDroppedGroupChatSession(UUID agentID, UUID groupID)
  641. {
  642. // If we're tracking drops for this group,
  643. // and we find them, well... then they've dropped
  644. return m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID)
  645. && m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID);
  646. }
  647. public void AgentDroppedFromGroupChatSession(UUID agentID, UUID groupID)
  648. {
  649. if (m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID))
  650. {
  651. if (m_groupsAgentsInvitedToChatSession[groupID].Contains(agentID))
  652. m_groupsAgentsInvitedToChatSession[groupID].Remove(agentID);
  653. // If not in dropped list, add
  654. if (!m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID))
  655. m_groupsAgentsDroppedFromChatSession[groupID].Add(agentID);
  656. }
  657. }
  658. public void AgentInvitedToGroupChatSession(UUID agentID, UUID groupID)
  659. {
  660. // Add Session Status if it doesn't exist for this session
  661. CreateGroupChatSessionTracking(groupID);
  662. // If nessesary, remove from dropped list
  663. if (m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID))
  664. m_groupsAgentsDroppedFromChatSession[groupID].Remove(agentID);
  665. if (!m_groupsAgentsInvitedToChatSession[groupID].Contains(agentID))
  666. m_groupsAgentsInvitedToChatSession[groupID].Add(agentID);
  667. }
  668. private void CreateGroupChatSessionTracking(UUID groupID)
  669. {
  670. if (!m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID))
  671. {
  672. m_groupsAgentsDroppedFromChatSession.Add(groupID, new List<UUID>());
  673. m_groupsAgentsInvitedToChatSession.Add(groupID, new List<UUID>());
  674. }
  675. }
  676. #endregion
  677. #region XmlRpcHashtableMarshalling
  678. private GroupProfileData GroupProfileHashtableToGroupProfileData(Hashtable groupProfile)
  679. {
  680. GroupProfileData group = new GroupProfileData();
  681. group.GroupID = UUID.Parse((string)groupProfile["GroupID"]);
  682. group.Name = (string)groupProfile["Name"];
  683. if (groupProfile["Charter"] != null)
  684. {
  685. group.Charter = (string)groupProfile["Charter"];
  686. }
  687. group.ShowInList = ((string)groupProfile["ShowInList"]) == "1";
  688. group.InsigniaID = UUID.Parse((string)groupProfile["InsigniaID"]);
  689. group.MembershipFee = int.Parse((string)groupProfile["MembershipFee"]);
  690. group.OpenEnrollment = ((string)groupProfile["OpenEnrollment"]) == "1";
  691. group.AllowPublish = ((string)groupProfile["AllowPublish"]) == "1";
  692. group.MaturePublish = ((string)groupProfile["MaturePublish"]) == "1";
  693. group.FounderID = UUID.Parse((string)groupProfile["FounderID"]);
  694. group.OwnerRole = UUID.Parse((string)groupProfile["OwnerRoleID"]);
  695. group.GroupMembershipCount = int.Parse((string)groupProfile["GroupMembershipCount"]);
  696. group.GroupRolesCount = int.Parse((string)groupProfile["GroupRolesCount"]);
  697. return group;
  698. }
  699. private GroupRecord GroupProfileHashtableToGroupRecord(Hashtable groupProfile)
  700. {
  701. GroupRecord group = new GroupRecord();
  702. group.GroupID = UUID.Parse((string)groupProfile["GroupID"]);
  703. group.GroupName = groupProfile["Name"].ToString();
  704. if (groupProfile["Charter"] != null)
  705. {
  706. group.Charter = (string)groupProfile["Charter"];
  707. }
  708. group.ShowInList = ((string)groupProfile["ShowInList"]) == "1";
  709. group.GroupPicture = UUID.Parse((string)groupProfile["InsigniaID"]);
  710. group.MembershipFee = int.Parse((string)groupProfile["MembershipFee"]);
  711. group.OpenEnrollment = ((string)groupProfile["OpenEnrollment"]) == "1";
  712. group.AllowPublish = ((string)groupProfile["AllowPublish"]) == "1";
  713. group.MaturePublish = ((string)groupProfile["MaturePublish"]) == "1";
  714. group.FounderID = UUID.Parse((string)groupProfile["FounderID"]);
  715. group.OwnerRoleID = UUID.Parse((string)groupProfile["OwnerRoleID"]);
  716. return group;
  717. }
  718. private static GroupMembershipData HashTableToGroupMembershipData(Hashtable respData)
  719. {
  720. GroupMembershipData data = new GroupMembershipData();
  721. data.AcceptNotices = ((string)respData["AcceptNotices"] == "1");
  722. data.Contribution = int.Parse((string)respData["Contribution"]);
  723. data.ListInProfile = ((string)respData["ListInProfile"] == "1");
  724. data.ActiveRole = new UUID((string)respData["SelectedRoleID"]);
  725. data.GroupTitle = (string)respData["Title"];
  726. data.GroupPowers = ulong.Parse((string)respData["GroupPowers"]);
  727. // Is this group the agent's active group
  728. data.GroupID = new UUID((string)respData["GroupID"]);
  729. UUID ActiveGroup = new UUID((string)respData["ActiveGroupID"]);
  730. data.Active = data.GroupID.Equals(ActiveGroup);
  731. data.AllowPublish = ((string)respData["AllowPublish"] == "1");
  732. if (respData["Charter"] != null)
  733. {
  734. data.Charter = (string)respData["Charter"];
  735. }
  736. data.FounderID = new UUID((string)respData["FounderID"]);
  737. data.GroupID = new UUID((string)respData["GroupID"]);
  738. data.GroupName = (string)respData["GroupName"];
  739. data.GroupPicture = new UUID((string)respData["InsigniaID"]);
  740. data.MaturePublish = ((string)respData["MaturePublish"] == "1");
  741. data.MembershipFee = int.Parse((string)respData["MembershipFee"]);
  742. data.OpenEnrollment = ((string)respData["OpenEnrollment"] == "1");
  743. data.ShowInList = ((string)respData["ShowInList"] == "1");
  744. return data;
  745. }
  746. #endregion
  747. /// <summary>
  748. /// Encapsulate the XmlRpc call to standardize security and error handling.
  749. /// </summary>
  750. private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param)
  751. {
  752. XmlRpcResponse resp = null;
  753. string CacheKey = null;
  754. // Only bother with the cache if it isn't disabled.
  755. if (m_cacheTimeout > 0)
  756. {
  757. if (!function.StartsWith("groups.get"))
  758. {
  759. // Any and all updates cause the cache to clear
  760. m_memoryCache.Clear();
  761. }
  762. else
  763. {
  764. StringBuilder sb = new StringBuilder(requestingAgentID + function);
  765. foreach (object key in param.Keys)
  766. {
  767. if (param[key] != null)
  768. {
  769. sb.AppendFormat(",{0}:{1}", key.ToString(), param[key].ToString());
  770. }
  771. }
  772. CacheKey = sb.ToString();
  773. m_memoryCache.TryGetValue(CacheKey, out resp);
  774. }
  775. }
  776. if (resp == null)
  777. {
  778. if (m_debugEnabled)
  779. m_log.DebugFormat("[XMLRPC-GROUPS-CONNECTOR]: Cache miss for key {0}", CacheKey);
  780. string UserService;
  781. UUID SessionID;
  782. GetClientGroupRequestID(requestingAgentID, out UserService, out SessionID);
  783. param.Add("RequestingAgentID", requestingAgentID.ToString());
  784. param.Add("RequestingAgentUserService", UserService);
  785. param.Add("RequestingSessionID", SessionID.ToString());
  786. param.Add("ReadKey", m_groupReadKey);
  787. param.Add("WriteKey", m_groupWriteKey);
  788. IList parameters = new ArrayList();
  789. parameters.Add(param);
  790. ConfigurableKeepAliveXmlRpcRequest req;
  791. req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive);
  792. try
  793. {
  794. resp = req.Send(m_groupsServerURI);
  795. }
  796. catch (Exception e)
  797. {
  798. m_log.ErrorFormat(
  799. "[XMLRPC-GROUPS-CONNECTOR]: An error has occured while attempting to access the XmlRpcGroups server method {0} at {1}: {2}",
  800. function, m_groupsServerURI, e.Message);
  801. if(m_debugEnabled)
  802. {
  803. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0}", e.StackTrace);
  804. foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
  805. {
  806. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} ", ResponseLine);
  807. }
  808. foreach (string key in param.Keys)
  809. {
  810. m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", key, param[key].ToString());
  811. }
  812. }
  813. if ((m_cacheTimeout > 0) && (CacheKey != null))
  814. {
  815. m_memoryCache.AddOrUpdate(CacheKey, resp, 10.0);
  816. }
  817. Hashtable respData = new Hashtable();
  818. respData.Add("error", e.ToString());
  819. return respData;
  820. }
  821. if ((m_cacheTimeout > 0) && (CacheKey != null))
  822. {
  823. m_memoryCache.AddOrUpdate(CacheKey, resp, 10.0);
  824. }
  825. }
  826. if (resp.Value is Hashtable)
  827. {
  828. Hashtable respData = (Hashtable)resp.Value;
  829. if (respData.Contains("error") && !respData.Contains("succeed"))
  830. {
  831. LogRespDataToConsoleError(requestingAgentID, function, param, respData);
  832. }
  833. return respData;
  834. }
  835. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: The XmlRpc server returned a {1} instead of a hashtable for {0}", function, resp.Value.GetType().ToString());
  836. if (resp.Value is ArrayList)
  837. {
  838. ArrayList al = (ArrayList)resp.Value;
  839. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Contains {0} elements", al.Count);
  840. foreach (object o in al)
  841. {
  842. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", o.GetType().ToString(), o.ToString());
  843. }
  844. }
  845. else
  846. {
  847. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Function returned: {0}", resp.Value.ToString());
  848. }
  849. Hashtable error = new Hashtable();
  850. error.Add("error", "invalid return value");
  851. return error;
  852. }
  853. private void LogRespDataToConsoleError(UUID requestingAgentID, string function, Hashtable param, Hashtable respData)
  854. {
  855. m_log.ErrorFormat(
  856. "[XMLRPC-GROUPS-CONNECTOR]: Error when calling {0} for {1} with params {2}. Response params are {3}",
  857. function, requestingAgentID, Util.PrettyFormatToSingleLine(param), Util.PrettyFormatToSingleLine(respData));
  858. }
  859. /// <summary>
  860. /// Group Request Tokens are an attempt to allow the groups service to authenticate
  861. /// requests.
  862. /// TODO: This broke after the big grid refactor, either find a better way, or discard this
  863. /// </summary>
  864. /// <param name="client"></param>
  865. /// <returns></returns>
  866. private void GetClientGroupRequestID(UUID AgentID, out string UserServiceURL, out UUID SessionID)
  867. {
  868. UserServiceURL = "";
  869. SessionID = UUID.Zero;
  870. // Need to rework this based on changes to User Services
  871. /*
  872. UserAccount userAccount = m_accountService.GetUserAccount(UUID.Zero,AgentID);
  873. if (userAccount == null)
  874. {
  875. // This should be impossible. If I've been passed a reference to a client
  876. // that client should be registered with the UserService. So something
  877. // is horribly wrong somewhere.
  878. m_log.WarnFormat("[GROUPS]: Could not find a UserServiceURL for {0}", AgentID);
  879. }
  880. else if (userProfile is ForeignUserProfileData)
  881. {
  882. // They aren't from around here
  883. ForeignUserProfileData fupd = (ForeignUserProfileData)userProfile;
  884. UserServiceURL = fupd.UserServerURI;
  885. SessionID = fupd.CurrentAgent.SessionID;
  886. }
  887. else
  888. {
  889. // They're a local user, use this:
  890. UserServiceURL = m_commManager.NetworkServersInfo.UserURL;
  891. SessionID = userProfile.CurrentAgent.SessionID;
  892. }
  893. */
  894. }
  895. }
  896. }
  897. namespace Nwc.XmlRpc
  898. {
  899. using System;
  900. using System.Collections;
  901. using System.IO;
  902. using System.Xml;
  903. using System.Net;
  904. using System.Text;
  905. using System.Reflection;
  906. /// <summary>Class supporting the request side of an XML-RPC transaction.</summary>
  907. public class ConfigurableKeepAliveXmlRpcRequest : XmlRpcRequest
  908. {
  909. private XmlRpcRequestSerializer _serializer = new XmlRpcRequestSerializer();
  910. private XmlRpcResponseDeserializer _deserializer = new XmlRpcResponseDeserializer();
  911. private bool _disableKeepAlive = true;
  912. public string RequestResponse = String.Empty;
  913. /// <summary>Instantiate an <c>XmlRpcRequest</c> for a specified method and parameters.</summary>
  914. /// <param name="methodName"><c>String</c> designating the <i>object.method</i> on the server the request
  915. /// should be directed to.</param>
  916. /// <param name="parameters"><c>ArrayList</c> of XML-RPC type parameters to invoke the request with.</param>
  917. public ConfigurableKeepAliveXmlRpcRequest(String methodName, IList parameters, bool disableKeepAlive)
  918. {
  919. MethodName = methodName;
  920. _params = parameters;
  921. _disableKeepAlive = disableKeepAlive;
  922. }
  923. /// <summary>Send the request to the server.</summary>
  924. /// <param name="url"><c>String</c> The url of the XML-RPC server.</param>
  925. /// <returns><c>XmlRpcResponse</c> The response generated.</returns>
  926. public XmlRpcResponse Send(String url)
  927. {
  928. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  929. if (request == null)
  930. throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR,
  931. XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url);
  932. request.Method = "POST";
  933. request.ContentType = "text/xml";
  934. request.AllowWriteStreamBuffering = true;
  935. request.KeepAlive = !_disableKeepAlive;
  936. request.Timeout = 30000;
  937. using (Stream stream = request.GetRequestStream())
  938. {
  939. using (XmlTextWriter xml = new XmlTextWriter(stream, Encoding.ASCII))
  940. {
  941. _serializer.Serialize(xml, this);
  942. xml.Flush();
  943. }
  944. }
  945. XmlRpcResponse resp;
  946. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  947. {
  948. using (Stream s = response.GetResponseStream())
  949. {
  950. using (StreamReader input = new StreamReader(s))
  951. {
  952. string inputXml = input.ReadToEnd();
  953. try
  954. {
  955. resp = (XmlRpcResponse)_deserializer.Deserialize(inputXml);
  956. }
  957. catch (Exception e)
  958. {
  959. RequestResponse = inputXml;
  960. throw e;
  961. }
  962. }
  963. }
  964. }
  965. return resp;
  966. }
  967. }
  968. }