XmlRpcGroupsServicesConnectorModule.cs 46 KB

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