GridServerPostHandler.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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 Nini.Config;
  28. using log4net;
  29. using System;
  30. using System.Reflection;
  31. using System.IO;
  32. using System.Net;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Xml;
  36. using System.Xml.Serialization;
  37. using System.Collections.Generic;
  38. using OpenSim.Server.Base;
  39. using OpenSim.Services.Interfaces;
  40. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  41. using OpenSim.Framework;
  42. using OpenSim.Framework.ServiceAuth;
  43. using OpenSim.Framework.Servers.HttpServer;
  44. using OpenMetaverse;
  45. namespace OpenSim.Server.Handlers.Grid
  46. {
  47. public class GridServerPostHandler : BaseStreamHandler
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. #pragma warning disable 414
  51. private static string LogHeader = "[GRID HANDLER]";
  52. #pragma warning restore 414
  53. private IGridService m_GridService;
  54. public GridServerPostHandler(IGridService service, IServiceAuth auth) :
  55. base("POST", "/grid", auth)
  56. {
  57. m_GridService = service;
  58. }
  59. protected override byte[] ProcessRequest(string path, Stream requestData,
  60. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  61. {
  62. StreamReader sr = new StreamReader(requestData);
  63. string body = sr.ReadToEnd();
  64. sr.Close();
  65. body = body.Trim();
  66. //m_log.DebugFormat("[XXX]: query String: {0}", body);
  67. try
  68. {
  69. Dictionary<string, object> request =
  70. ServerUtils.ParseQueryString(body);
  71. if (!request.ContainsKey("METHOD"))
  72. return FailureResult();
  73. string method = request["METHOD"].ToString();
  74. switch (method)
  75. {
  76. case "register":
  77. return Register(request);
  78. case "deregister":
  79. return Deregister(request);
  80. case "get_neighbours":
  81. return GetNeighbours(request);
  82. case "get_region_by_uuid":
  83. return GetRegionByUUID(request);
  84. case "get_region_by_position":
  85. return GetRegionByPosition(request);
  86. case "get_region_by_name":
  87. return GetRegionByName(request);
  88. case "get_regions_by_name":
  89. return GetRegionsByName(request);
  90. case "get_region_range":
  91. return GetRegionRange(request);
  92. case "get_default_regions":
  93. return GetDefaultRegions(request);
  94. case "get_default_hypergrid_regions":
  95. return GetDefaultHypergridRegions(request);
  96. case "get_fallback_regions":
  97. return GetFallbackRegions(request);
  98. case "get_hyperlinks":
  99. return GetHyperlinks(request);
  100. case "get_region_flags":
  101. return GetRegionFlags(request);
  102. case "get_grid_extra_features":
  103. return GetGridExtraFeatures(request);
  104. }
  105. m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method);
  106. }
  107. catch (Exception e)
  108. {
  109. m_log.ErrorFormat("[GRID HANDLER]: Exception {0} {1}", e.Message, e.StackTrace);
  110. }
  111. return FailureResult();
  112. }
  113. #region Method-specific handlers
  114. byte[] Register(Dictionary<string, object> request)
  115. {
  116. UUID scopeID = UUID.Zero;
  117. if (request.ContainsKey("SCOPEID"))
  118. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  119. else
  120. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
  121. int versionNumberMin = 0, versionNumberMax = 0;
  122. if (request.ContainsKey("VERSIONMIN"))
  123. Int32.TryParse(request["VERSIONMIN"].ToString(), out versionNumberMin);
  124. else
  125. m_log.WarnFormat("[GRID HANDLER]: no minimum protocol version in request to register region");
  126. if (request.ContainsKey("VERSIONMAX"))
  127. Int32.TryParse(request["VERSIONMAX"].ToString(), out versionNumberMax);
  128. else
  129. m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region");
  130. // Check the protocol version
  131. // This is how it works:
  132. // Example 1:
  133. // Client: [0 0]
  134. // Server: [1 1]
  135. // ==> fail
  136. // Example 2:
  137. // Client: [1 1]
  138. // Server: [0 0]
  139. // ==> fail
  140. // Example 3:
  141. // Client: [0 1]
  142. // Server: [1 1]
  143. // ==> success
  144. // Example 4:
  145. // Client: [1 1]
  146. // Server: [0 1]
  147. // ==> success
  148. if ((versionNumberMin > ProtocolVersions.ServerProtocolVersionMax || versionNumberMax < ProtocolVersions.ServerProtocolVersionMin))
  149. {
  150. // Can't do, there is no overlap in the acceptable ranges
  151. return FailureResult();
  152. }
  153. Dictionary<string, object> rinfoData = new Dictionary<string, object>();
  154. GridRegion rinfo = null;
  155. try
  156. {
  157. foreach (KeyValuePair<string, object> kvp in request)
  158. rinfoData[kvp.Key] = kvp.Value.ToString();
  159. rinfo = new GridRegion(rinfoData);
  160. }
  161. catch (Exception e)
  162. {
  163. m_log.DebugFormat("[GRID HANDLER]: exception unpacking region data: {0}", e);
  164. }
  165. string result = "Error communicating with grid service";
  166. if (rinfo != null)
  167. result = m_GridService.RegisterRegion(scopeID, rinfo);
  168. if (result == String.Empty)
  169. return SuccessResult();
  170. else
  171. return FailureResult(result);
  172. }
  173. byte[] Deregister(Dictionary<string, object> request)
  174. {
  175. UUID regionID = UUID.Zero;
  176. if (request.ContainsKey("REGIONID"))
  177. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  178. else
  179. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region");
  180. bool result = m_GridService.DeregisterRegion(regionID);
  181. if (result)
  182. return SuccessResult();
  183. else
  184. return FailureResult();
  185. }
  186. byte[] GetNeighbours(Dictionary<string, object> request)
  187. {
  188. UUID scopeID = UUID.Zero;
  189. if (request.ContainsKey("SCOPEID"))
  190. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  191. else
  192. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
  193. UUID regionID = UUID.Zero;
  194. if (request.ContainsKey("REGIONID"))
  195. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  196. else
  197. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
  198. List<GridRegion> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
  199. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  200. Dictionary<string, object> result = new Dictionary<string, object>();
  201. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  202. result["result"] = "null";
  203. else
  204. {
  205. int i = 0;
  206. foreach (GridRegion rinfo in rinfos)
  207. {
  208. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  209. result["region" + i] = rinfoDict;
  210. i++;
  211. }
  212. }
  213. string xmlString = ServerUtils.BuildXmlResponse(result);
  214. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  215. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  216. }
  217. byte[] GetRegionByUUID(Dictionary<string, object> request)
  218. {
  219. UUID scopeID = UUID.Zero;
  220. if (request.ContainsKey("SCOPEID"))
  221. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  222. else
  223. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
  224. UUID regionID = UUID.Zero;
  225. if (request.ContainsKey("REGIONID"))
  226. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  227. else
  228. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
  229. GridRegion rinfo = m_GridService.GetRegionByUUID(scopeID, regionID);
  230. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  231. Dictionary<string, object> result = new Dictionary<string, object>();
  232. if (rinfo == null)
  233. result["result"] = "null";
  234. else
  235. result["result"] = rinfo.ToKeyValuePairs();
  236. string xmlString = ServerUtils.BuildXmlResponse(result);
  237. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  238. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  239. }
  240. byte[] GetRegionByPosition(Dictionary<string, object> request)
  241. {
  242. UUID scopeID = UUID.Zero;
  243. if (request.ContainsKey("SCOPEID"))
  244. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  245. else
  246. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position");
  247. int x = 0, y = 0;
  248. if (request.ContainsKey("X"))
  249. Int32.TryParse(request["X"].ToString(), out x);
  250. else
  251. m_log.WarnFormat("[GRID HANDLER]: no X in request to get region by position");
  252. if (request.ContainsKey("Y"))
  253. Int32.TryParse(request["Y"].ToString(), out y);
  254. else
  255. m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position");
  256. // m_log.DebugFormat("{0} GetRegionByPosition: loc=<{1},{2}>", LogHeader, x, y);
  257. GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
  258. Dictionary<string, object> result = new Dictionary<string, object>();
  259. if (rinfo == null)
  260. result["result"] = "null";
  261. else
  262. result["result"] = rinfo.ToKeyValuePairs();
  263. string xmlString = ServerUtils.BuildXmlResponse(result);
  264. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  265. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  266. }
  267. byte[] GetRegionByName(Dictionary<string, object> request)
  268. {
  269. UUID scopeID = UUID.Zero;
  270. if (request.ContainsKey("SCOPEID"))
  271. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  272. else
  273. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by name");
  274. string regionName = string.Empty;
  275. if (request.ContainsKey("NAME"))
  276. regionName = request["NAME"].ToString();
  277. else
  278. m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name");
  279. GridRegion rinfo = m_GridService.GetRegionByName(scopeID, regionName);
  280. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  281. Dictionary<string, object> result = new Dictionary<string, object>();
  282. if (rinfo == null)
  283. result["result"] = "null";
  284. else
  285. result["result"] = rinfo.ToKeyValuePairs();
  286. string xmlString = ServerUtils.BuildXmlResponse(result);
  287. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  288. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  289. }
  290. byte[] GetRegionsByName(Dictionary<string, object> request)
  291. {
  292. UUID scopeID = UUID.Zero;
  293. if (request.ContainsKey("SCOPEID"))
  294. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  295. else
  296. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get regions by name");
  297. string regionName = string.Empty;
  298. if (request.ContainsKey("NAME"))
  299. regionName = request["NAME"].ToString();
  300. else
  301. m_log.WarnFormat("[GRID HANDLER]: no NAME in request to get regions by name");
  302. int max = 0;
  303. if (request.ContainsKey("MAX"))
  304. Int32.TryParse(request["MAX"].ToString(), out max);
  305. else
  306. m_log.WarnFormat("[GRID HANDLER]: no MAX in request to get regions by name");
  307. List<GridRegion> rinfos = m_GridService.GetRegionsByName(scopeID, regionName, max);
  308. //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
  309. Dictionary<string, object> result = new Dictionary<string, object>();
  310. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  311. result["result"] = "null";
  312. else
  313. {
  314. int i = 0;
  315. foreach (GridRegion rinfo in rinfos)
  316. {
  317. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  318. result["region" + i] = rinfoDict;
  319. i++;
  320. }
  321. }
  322. string xmlString = ServerUtils.BuildXmlResponse(result);
  323. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  324. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  325. }
  326. byte[] GetRegionRange(Dictionary<string, object> request)
  327. {
  328. //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
  329. UUID scopeID = UUID.Zero;
  330. if (request.ContainsKey("SCOPEID"))
  331. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  332. else
  333. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
  334. int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
  335. if (request.ContainsKey("XMIN"))
  336. Int32.TryParse(request["XMIN"].ToString(), out xmin);
  337. else
  338. m_log.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range");
  339. if (request.ContainsKey("XMAX"))
  340. Int32.TryParse(request["XMAX"].ToString(), out xmax);
  341. else
  342. m_log.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range");
  343. if (request.ContainsKey("YMIN"))
  344. Int32.TryParse(request["YMIN"].ToString(), out ymin);
  345. else
  346. m_log.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range");
  347. if (request.ContainsKey("YMAX"))
  348. Int32.TryParse(request["YMAX"].ToString(), out ymax);
  349. else
  350. m_log.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range");
  351. List<GridRegion> rinfos = m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
  352. Dictionary<string, object> result = new Dictionary<string, object>();
  353. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  354. result["result"] = "null";
  355. else
  356. {
  357. int i = 0;
  358. foreach (GridRegion rinfo in rinfos)
  359. {
  360. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  361. result["region" + i] = rinfoDict;
  362. i++;
  363. }
  364. }
  365. string xmlString = ServerUtils.BuildXmlResponse(result);
  366. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  367. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  368. }
  369. byte[] GetDefaultRegions(Dictionary<string, object> request)
  370. {
  371. //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions");
  372. UUID scopeID = UUID.Zero;
  373. if (request.ContainsKey("SCOPEID"))
  374. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  375. else
  376. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
  377. List<GridRegion> rinfos = m_GridService.GetDefaultRegions(scopeID);
  378. Dictionary<string, object> result = new Dictionary<string, object>();
  379. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  380. result["result"] = "null";
  381. else
  382. {
  383. int i = 0;
  384. foreach (GridRegion rinfo in rinfos)
  385. {
  386. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  387. result["region" + i] = rinfoDict;
  388. i++;
  389. }
  390. }
  391. string xmlString = ServerUtils.BuildXmlResponse(result);
  392. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  393. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  394. }
  395. byte[] GetDefaultHypergridRegions(Dictionary<string, object> request)
  396. {
  397. //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions");
  398. UUID scopeID = UUID.Zero;
  399. if (request.ContainsKey("SCOPEID"))
  400. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  401. else
  402. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
  403. List<GridRegion> rinfos = m_GridService.GetDefaultHypergridRegions(scopeID);
  404. Dictionary<string, object> result = new Dictionary<string, object>();
  405. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  406. result["result"] = "null";
  407. else
  408. {
  409. int i = 0;
  410. foreach (GridRegion rinfo in rinfos)
  411. {
  412. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  413. result["region" + i] = rinfoDict;
  414. i++;
  415. }
  416. }
  417. string xmlString = ServerUtils.BuildXmlResponse(result);
  418. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  419. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  420. }
  421. byte[] GetFallbackRegions(Dictionary<string, object> request)
  422. {
  423. //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
  424. UUID scopeID = UUID.Zero;
  425. if (request.ContainsKey("SCOPEID"))
  426. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  427. else
  428. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get fallback regions");
  429. int x = 0, y = 0;
  430. if (request.ContainsKey("X"))
  431. Int32.TryParse(request["X"].ToString(), out x);
  432. else
  433. m_log.WarnFormat("[GRID HANDLER]: no X in request to get fallback regions");
  434. if (request.ContainsKey("Y"))
  435. Int32.TryParse(request["Y"].ToString(), out y);
  436. else
  437. m_log.WarnFormat("[GRID HANDLER]: no Y in request to get fallback regions");
  438. List<GridRegion> rinfos = m_GridService.GetFallbackRegions(scopeID, x, y);
  439. Dictionary<string, object> result = new Dictionary<string, object>();
  440. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  441. result["result"] = "null";
  442. else
  443. {
  444. int i = 0;
  445. foreach (GridRegion rinfo in rinfos)
  446. {
  447. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  448. result["region" + i] = rinfoDict;
  449. i++;
  450. }
  451. }
  452. string xmlString = ServerUtils.BuildXmlResponse(result);
  453. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  454. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  455. }
  456. byte[] GetHyperlinks(Dictionary<string, object> request)
  457. {
  458. //m_log.DebugFormat("[GRID HANDLER]: GetHyperlinks");
  459. UUID scopeID = UUID.Zero;
  460. if (request.ContainsKey("SCOPEID"))
  461. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  462. else
  463. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get linked regions");
  464. List<GridRegion> rinfos = m_GridService.GetHyperlinks(scopeID);
  465. Dictionary<string, object> result = new Dictionary<string, object>();
  466. if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
  467. result["result"] = "null";
  468. else
  469. {
  470. int i = 0;
  471. foreach (GridRegion rinfo in rinfos)
  472. {
  473. Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
  474. result["region" + i] = rinfoDict;
  475. i++;
  476. }
  477. }
  478. string xmlString = ServerUtils.BuildXmlResponse(result);
  479. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  480. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  481. }
  482. byte[] GetRegionFlags(Dictionary<string, object> request)
  483. {
  484. UUID scopeID = UUID.Zero;
  485. if (request.ContainsKey("SCOPEID"))
  486. UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
  487. else
  488. m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get RegionFlags");
  489. UUID regionID = UUID.Zero;
  490. if (request.ContainsKey("REGIONID"))
  491. UUID.TryParse(request["REGIONID"].ToString(), out regionID);
  492. else
  493. m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get RegionFlags");
  494. int flags = m_GridService.GetRegionFlags(scopeID, regionID);
  495. // m_log.DebugFormat("[GRID HANDLER]: flags for region {0}: {1}", regionID, flags);
  496. Dictionary<string, object> result = new Dictionary<string, object>();
  497. result["result"] = flags.ToString();
  498. string xmlString = ServerUtils.BuildXmlResponse(result);
  499. //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
  500. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  501. }
  502. byte[] GetGridExtraFeatures(Dictionary<string, object> request)
  503. {
  504. Dictionary<string, object> result = new Dictionary<string, object> ();
  505. Dictionary<string, object> extraFeatures = m_GridService.GetExtraFeatures ();
  506. foreach (string key in extraFeatures.Keys)
  507. {
  508. result [key] = extraFeatures [key];
  509. }
  510. string xmlString = ServerUtils.BuildXmlResponse(result);
  511. return Util.UTF8NoBomEncoding.GetBytes(xmlString);
  512. }
  513. #endregion
  514. #region Misc
  515. private byte[] SuccessResult()
  516. {
  517. XmlDocument doc = new XmlDocument();
  518. XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
  519. "", "");
  520. doc.AppendChild(xmlnode);
  521. XmlElement rootElement = doc.CreateElement("", "ServerResponse",
  522. "");
  523. doc.AppendChild(rootElement);
  524. XmlElement result = doc.CreateElement("", "Result", "");
  525. result.AppendChild(doc.CreateTextNode("Success"));
  526. rootElement.AppendChild(result);
  527. return Util.DocToBytes(doc);
  528. }
  529. private byte[] FailureResult()
  530. {
  531. return FailureResult(String.Empty);
  532. }
  533. private byte[] FailureResult(string msg)
  534. {
  535. XmlDocument doc = new XmlDocument();
  536. XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
  537. "", "");
  538. doc.AppendChild(xmlnode);
  539. XmlElement rootElement = doc.CreateElement("", "ServerResponse",
  540. "");
  541. doc.AppendChild(rootElement);
  542. XmlElement result = doc.CreateElement("", "Result", "");
  543. result.AppendChild(doc.CreateTextNode("Failure"));
  544. rootElement.AppendChild(result);
  545. XmlElement message = doc.CreateElement("", "Message", "");
  546. message.AppendChild(doc.CreateTextNode(msg));
  547. rootElement.AppendChild(message);
  548. return Util.DocToBytes(doc);
  549. }
  550. #endregion
  551. }
  552. }