UrlModule.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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.Threading;
  29. using System.Collections.Generic;
  30. using System.Collections;
  31. using System.Reflection;
  32. using log4net;
  33. using Mono.Addins;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Servers;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
  42. {
  43. public class UrlData
  44. {
  45. public UUID hostID;
  46. public UUID itemID;
  47. public IScriptModule engine;
  48. public string url;
  49. public UUID urlcode;
  50. public Dictionary<UUID, RequestData> requests;
  51. public bool isSsl;
  52. public Scene scene;
  53. public bool allowXss;
  54. }
  55. public class RequestData
  56. {
  57. public UUID requestID;
  58. public Dictionary<string, string> headers;
  59. public string body;
  60. public int responseCode;
  61. public string responseBody;
  62. public string responseType = "text/plain";
  63. //public ManualResetEvent ev;
  64. public bool requestDone;
  65. public int startTime;
  66. public bool responseSent;
  67. public string uri;
  68. public bool allowResponseType = false;
  69. public UUID hostID;
  70. public Scene scene;
  71. }
  72. /// <summary>
  73. /// This module provides external URLs for in-world scripts.
  74. /// </summary>
  75. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UrlModule")]
  76. public class UrlModule : ISharedRegionModule, IUrlModule
  77. {
  78. private static readonly ILog m_log =
  79. LogManager.GetLogger(
  80. MethodBase.GetCurrentMethod().DeclaringType);
  81. private Dictionary<UUID, UrlData> m_RequestMap =
  82. new Dictionary<UUID, UrlData>();
  83. private Dictionary<string, UrlData> m_UrlMap =
  84. new Dictionary<string, UrlData>();
  85. private uint m_HttpsPort = 0;
  86. private IHttpServer m_HttpServer = null;
  87. private IHttpServer m_HttpsServer = null;
  88. public string ExternalHostNameForLSL { get; private set; }
  89. /// <summary>
  90. /// The default maximum number of urls
  91. /// </summary>
  92. public const int DefaultTotalUrls = 15000;
  93. /// <summary>
  94. /// Maximum number of external urls that can be set up by this module.
  95. /// </summary>
  96. public int TotalUrls { get; set; }
  97. public Type ReplaceableInterface
  98. {
  99. get { return null; }
  100. }
  101. public string Name
  102. {
  103. get { return "UrlModule"; }
  104. }
  105. public void Initialise(IConfigSource config)
  106. {
  107. IConfig networkConfig = config.Configs["Network"];
  108. if (networkConfig != null)
  109. {
  110. ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", null);
  111. bool ssl_enabled = config.Configs["Network"].GetBoolean("https_listener", false);
  112. if (ssl_enabled)
  113. m_HttpsPort = (uint)config.Configs["Network"].GetInt("https_port", (int)m_HttpsPort);
  114. }
  115. if (ExternalHostNameForLSL == null)
  116. ExternalHostNameForLSL = System.Environment.MachineName;
  117. IConfig llFunctionsConfig = config.Configs["LL-Functions"];
  118. if (llFunctionsConfig != null)
  119. TotalUrls = llFunctionsConfig.GetInt("max_external_urls_per_simulator", DefaultTotalUrls);
  120. else
  121. TotalUrls = DefaultTotalUrls;
  122. }
  123. public void PostInitialise()
  124. {
  125. }
  126. public void AddRegion(Scene scene)
  127. {
  128. if (m_HttpServer == null)
  129. {
  130. // There can only be one
  131. //
  132. m_HttpServer = MainServer.Instance;
  133. //
  134. // We can use the https if it is enabled
  135. if (m_HttpsPort > 0)
  136. {
  137. m_HttpsServer = MainServer.GetHttpServer(m_HttpsPort);
  138. }
  139. }
  140. scene.RegisterModuleInterface<IUrlModule>(this);
  141. scene.EventManager.OnScriptReset += OnScriptReset;
  142. }
  143. public void RegionLoaded(Scene scene)
  144. {
  145. IScriptModule[] scriptModules = scene.RequestModuleInterfaces<IScriptModule>();
  146. foreach (IScriptModule scriptModule in scriptModules)
  147. {
  148. scriptModule.OnScriptRemoved += ScriptRemoved;
  149. scriptModule.OnObjectRemoved += ObjectRemoved;
  150. }
  151. }
  152. public void RemoveRegion(Scene scene)
  153. {
  154. // Drop references to that scene
  155. foreach (KeyValuePair<string, UrlData> kvp in m_UrlMap)
  156. {
  157. if (kvp.Value.scene == scene)
  158. kvp.Value.scene = null;
  159. }
  160. foreach (KeyValuePair<UUID, UrlData> kvp in m_RequestMap)
  161. {
  162. if (kvp.Value.scene == scene)
  163. kvp.Value.scene = null;
  164. }
  165. }
  166. public void Close()
  167. {
  168. }
  169. public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID, Hashtable options)
  170. {
  171. UUID urlcode = UUID.Random();
  172. lock (m_UrlMap)
  173. {
  174. if (m_UrlMap.Count >= TotalUrls)
  175. {
  176. engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
  177. return urlcode;
  178. }
  179. string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/";
  180. UrlData urlData = new UrlData();
  181. urlData.hostID = host.UUID;
  182. urlData.itemID = itemID;
  183. urlData.engine = engine;
  184. urlData.url = url;
  185. urlData.urlcode = urlcode;
  186. urlData.isSsl = false;
  187. urlData.requests = new Dictionary<UUID, RequestData>();
  188. urlData.scene = host.ParentGroup.Scene;
  189. urlData.allowXss = false;
  190. if (options != null && options["allowXss"] != null)
  191. urlData.allowXss = true;
  192. m_UrlMap[url] = urlData;
  193. string uri = "/lslhttp/" + urlcode.ToString() + "/";
  194. PollServiceEventArgs args
  195. = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000);
  196. args.Type = PollServiceEventArgs.EventType.LslHttp;
  197. m_HttpServer.AddPollServiceHTTPHandler(uri, args);
  198. // m_log.DebugFormat(
  199. // "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}",
  200. // uri, itemID, host.Name, host.LocalId);
  201. engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
  202. }
  203. return urlcode;
  204. }
  205. public UUID RequestSecureURL(IScriptModule engine, SceneObjectPart host, UUID itemID, Hashtable options)
  206. {
  207. UUID urlcode = UUID.Random();
  208. if (m_HttpsServer == null)
  209. {
  210. engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
  211. return urlcode;
  212. }
  213. lock (m_UrlMap)
  214. {
  215. if (m_UrlMap.Count >= TotalUrls)
  216. {
  217. engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
  218. return urlcode;
  219. }
  220. string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/";
  221. UrlData urlData = new UrlData();
  222. urlData.hostID = host.UUID;
  223. urlData.itemID = itemID;
  224. urlData.engine = engine;
  225. urlData.url = url;
  226. urlData.urlcode = urlcode;
  227. urlData.isSsl = true;
  228. urlData.requests = new Dictionary<UUID, RequestData>();
  229. urlData.allowXss = false;
  230. if (options != null && options["allowXss"] != null)
  231. urlData.allowXss = true;
  232. m_UrlMap[url] = urlData;
  233. string uri = "/lslhttps/" + urlcode.ToString() + "/";
  234. PollServiceEventArgs args
  235. = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000);
  236. args.Type = PollServiceEventArgs.EventType.LslHttp;
  237. m_HttpsServer.AddPollServiceHTTPHandler(uri, args);
  238. // m_log.DebugFormat(
  239. // "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}",
  240. // uri, itemID, host.Name, host.LocalId);
  241. engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
  242. }
  243. return urlcode;
  244. }
  245. public void ReleaseURL(string url)
  246. {
  247. lock (m_UrlMap)
  248. {
  249. UrlData data;
  250. if (!m_UrlMap.TryGetValue(url, out data))
  251. {
  252. return;
  253. }
  254. lock (m_RequestMap)
  255. {
  256. foreach (UUID req in data.requests.Keys)
  257. m_RequestMap.Remove(req);
  258. }
  259. // m_log.DebugFormat(
  260. // "[URL MODULE]: Releasing url {0} for {1} in {2}",
  261. // url, data.itemID, data.hostID);
  262. RemoveUrl(data);
  263. m_UrlMap.Remove(url);
  264. }
  265. }
  266. public void HttpContentType(UUID request, string type)
  267. {
  268. lock (m_UrlMap)
  269. {
  270. if (m_RequestMap.ContainsKey(request))
  271. {
  272. UrlData urlData = m_RequestMap[request];
  273. urlData.requests[request].responseType = type;
  274. }
  275. else
  276. {
  277. m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString());
  278. }
  279. }
  280. }
  281. public void HttpResponse(UUID request, int status, string body)
  282. {
  283. lock (m_RequestMap)
  284. {
  285. if (m_RequestMap.ContainsKey(request))
  286. {
  287. UrlData urlData = m_RequestMap[request];
  288. if (!urlData.requests[request].responseSent)
  289. {
  290. string responseBody = body;
  291. // If we have no OpenID from built-in browser, disable this
  292. if (!urlData.requests[request].allowResponseType)
  293. urlData.requests[request].responseType = "text/plain";
  294. if (urlData.requests[request].responseType.Equals("text/plain"))
  295. {
  296. string value;
  297. if (urlData.requests[request].headers.TryGetValue("user-agent", out value))
  298. {
  299. if (value != null && value.IndexOf("MSIE") >= 0)
  300. {
  301. // wrap the html escaped response if the target client is IE
  302. // It ignores "text/plain" if the body is html
  303. responseBody = "<html>" + System.Web.HttpUtility.HtmlEncode(body) + "</html>";
  304. }
  305. }
  306. }
  307. urlData.requests[request].responseCode = status;
  308. urlData.requests[request].responseBody = responseBody;
  309. //urlData.requests[request].ev.Set();
  310. urlData.requests[request].requestDone = true;
  311. urlData.requests[request].responseSent = true;
  312. }
  313. }
  314. else
  315. {
  316. m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString());
  317. }
  318. }
  319. }
  320. public string GetHttpHeader(UUID requestId, string header)
  321. {
  322. lock (m_RequestMap)
  323. {
  324. if (m_RequestMap.ContainsKey(requestId))
  325. {
  326. UrlData urlData = m_RequestMap[requestId];
  327. string value;
  328. if (urlData.requests[requestId].headers.TryGetValue(header, out value))
  329. return value;
  330. }
  331. else
  332. {
  333. m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId);
  334. }
  335. }
  336. return String.Empty;
  337. }
  338. public int GetFreeUrls()
  339. {
  340. lock (m_UrlMap)
  341. return TotalUrls - m_UrlMap.Count;
  342. }
  343. public void ScriptRemoved(UUID itemID)
  344. {
  345. // m_log.DebugFormat("[URL MODULE]: Removing script {0}", itemID);
  346. lock (m_UrlMap)
  347. {
  348. List<string> removeURLs = new List<string>();
  349. foreach (KeyValuePair<string, UrlData> url in m_UrlMap)
  350. {
  351. if (url.Value.itemID == itemID)
  352. {
  353. RemoveUrl(url.Value);
  354. removeURLs.Add(url.Key);
  355. lock (m_RequestMap)
  356. {
  357. foreach (UUID req in url.Value.requests.Keys)
  358. m_RequestMap.Remove(req);
  359. }
  360. }
  361. }
  362. foreach (string urlname in removeURLs)
  363. m_UrlMap.Remove(urlname);
  364. }
  365. }
  366. public void ObjectRemoved(UUID objectID)
  367. {
  368. lock (m_UrlMap)
  369. {
  370. List<string> removeURLs = new List<string>();
  371. foreach (KeyValuePair<string, UrlData> url in m_UrlMap)
  372. {
  373. if (url.Value.hostID == objectID)
  374. {
  375. RemoveUrl(url.Value);
  376. removeURLs.Add(url.Key);
  377. lock (m_RequestMap)
  378. {
  379. foreach (UUID req in url.Value.requests.Keys)
  380. m_RequestMap.Remove(req);
  381. }
  382. }
  383. }
  384. foreach (string urlname in removeURLs)
  385. m_UrlMap.Remove(urlname);
  386. }
  387. }
  388. private void RemoveUrl(UrlData data)
  389. {
  390. if (data.isSsl)
  391. m_HttpsServer.RemoveHTTPHandler("", "/lslhttps/"+data.urlcode.ToString()+"/");
  392. else
  393. m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/");
  394. }
  395. private Hashtable NoEvents(UUID requestID, UUID sessionID)
  396. {
  397. Hashtable response = new Hashtable();
  398. UrlData url;
  399. int startTime = 0;
  400. lock (m_RequestMap)
  401. {
  402. if (!m_RequestMap.ContainsKey(requestID))
  403. return response;
  404. url = m_RequestMap[requestID];
  405. startTime = url.requests[requestID].startTime;
  406. }
  407. if (System.Environment.TickCount - startTime > 25000)
  408. {
  409. response["int_response_code"] = 500;
  410. response["str_response_string"] = "Script timeout";
  411. response["content_type"] = "text/plain";
  412. response["keepalive"] = false;
  413. response["reusecontext"] = false;
  414. //remove from map
  415. lock (url.requests)
  416. {
  417. url.requests.Remove(requestID);
  418. }
  419. lock (m_RequestMap)
  420. {
  421. m_RequestMap.Remove(requestID);
  422. }
  423. return response;
  424. }
  425. return response;
  426. }
  427. private bool HasEvents(UUID requestID, UUID sessionID)
  428. {
  429. UrlData url=null;
  430. lock (m_RequestMap)
  431. {
  432. if (!m_RequestMap.ContainsKey(requestID))
  433. {
  434. return false;
  435. }
  436. url = m_RequestMap[requestID];
  437. }
  438. lock (url.requests)
  439. {
  440. if (!url.requests.ContainsKey(requestID))
  441. {
  442. return false;
  443. }
  444. else
  445. {
  446. if (System.Environment.TickCount - url.requests[requestID].startTime > 25000)
  447. {
  448. return true;
  449. }
  450. if (url.requests[requestID].requestDone)
  451. return true;
  452. else
  453. return false;
  454. }
  455. }
  456. }
  457. private Hashtable GetEvents(UUID requestID, UUID sessionID)
  458. {
  459. UrlData url = null;
  460. RequestData requestData = null;
  461. lock (m_RequestMap)
  462. {
  463. if (!m_RequestMap.ContainsKey(requestID))
  464. return NoEvents(requestID,sessionID);
  465. url = m_RequestMap[requestID];
  466. }
  467. lock (url.requests)
  468. {
  469. requestData = url.requests[requestID];
  470. }
  471. if (!requestData.requestDone)
  472. return NoEvents(requestID,sessionID);
  473. Hashtable response = new Hashtable();
  474. if (System.Environment.TickCount - requestData.startTime > 25000)
  475. {
  476. response["int_response_code"] = 500;
  477. response["str_response_string"] = "Script timeout";
  478. response["content_type"] = "text/plain";
  479. response["keepalive"] = false;
  480. response["reusecontext"] = false;
  481. return response;
  482. }
  483. //put response
  484. response["int_response_code"] = requestData.responseCode;
  485. response["str_response_string"] = requestData.responseBody;
  486. response["content_type"] = requestData.responseType;
  487. response["keepalive"] = false;
  488. response["reusecontext"] = false;
  489. if (url.allowXss)
  490. response["access_control_allow_origin"] = "*";
  491. //remove from map
  492. lock (url.requests)
  493. {
  494. url.requests.Remove(requestID);
  495. }
  496. lock (m_RequestMap)
  497. {
  498. m_RequestMap.Remove(requestID);
  499. }
  500. return response;
  501. }
  502. public void HttpRequestHandler(UUID requestID, Hashtable request)
  503. {
  504. lock (request)
  505. {
  506. string uri = request["uri"].ToString();
  507. bool is_ssl = uri.Contains("lslhttps");
  508. try
  509. {
  510. Hashtable headers = (Hashtable)request["headers"];
  511. // string uri_full = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/";
  512. int pos1 = uri.IndexOf("/");// /lslhttp
  513. int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/
  514. int pos3 = uri.IndexOf("/", pos2 + 1); // /lslhttp/urlcode
  515. string uri_tmp = uri.Substring(0, pos3 + 1);
  516. //HTTP server code doesn't provide us with QueryStrings
  517. string pathInfo;
  518. string queryString;
  519. queryString = "";
  520. pathInfo = uri.Substring(pos3);
  521. UrlData url = null;
  522. string urlkey;
  523. if (!is_ssl)
  524. urlkey = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp;
  525. //m_UrlMap[];
  526. else
  527. urlkey = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp;
  528. if (m_UrlMap.ContainsKey(urlkey))
  529. {
  530. url = m_UrlMap[urlkey];
  531. }
  532. else
  533. {
  534. //m_log.Warn("[HttpRequestHandler]: http-in request failed; no such url: "+urlkey.ToString());
  535. return;
  536. }
  537. //for llGetHttpHeader support we need to store original URI here
  538. //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
  539. //as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader
  540. RequestData requestData = new RequestData();
  541. requestData.requestID = requestID;
  542. requestData.requestDone = false;
  543. requestData.startTime = System.Environment.TickCount;
  544. requestData.uri = uri;
  545. requestData.hostID = url.hostID;
  546. requestData.scene = url.scene;
  547. if (requestData.headers == null)
  548. requestData.headers = new Dictionary<string, string>();
  549. foreach (DictionaryEntry header in headers)
  550. {
  551. string key = (string)header.Key;
  552. string value = (string)header.Value;
  553. requestData.headers.Add(key, value);
  554. if (key == "cookie")
  555. {
  556. string[] parts = value.Split(new char[] {'='});
  557. if (parts[0] == "agni_sl_session_id" && parts.Length > 1)
  558. {
  559. string cookie = Uri.UnescapeDataString(parts[1]);
  560. string[] crumbs = cookie.Split(new char[] {':'});
  561. UUID owner;
  562. if (crumbs.Length == 2 && UUID.TryParse(crumbs[0], out owner))
  563. {
  564. if (crumbs[1].Length == 32)
  565. {
  566. Scene scene = requestData.scene;
  567. if (scene != null)
  568. {
  569. SceneObjectPart host = scene.GetSceneObjectPart(requestData.hostID);
  570. if (host != null)
  571. {
  572. if (host.OwnerID == owner)
  573. requestData.allowResponseType = true;
  574. }
  575. }
  576. }
  577. }
  578. }
  579. }
  580. }
  581. foreach (DictionaryEntry de in request)
  582. {
  583. if (de.Key.ToString() == "querystringkeys")
  584. {
  585. System.String[] keys = (System.String[])de.Value;
  586. foreach (String key in keys)
  587. {
  588. if (request.ContainsKey(key))
  589. {
  590. string val = (String)request[key];
  591. if (key != "")
  592. {
  593. queryString = queryString + key + "=" + val + "&";
  594. }
  595. else
  596. {
  597. queryString = queryString + val + "&";
  598. }
  599. }
  600. }
  601. if (queryString.Length > 1)
  602. queryString = queryString.Substring(0, queryString.Length - 1);
  603. }
  604. }
  605. //if this machine is behind DNAT/port forwarding, currently this is being
  606. //set to address of port forwarding router
  607. requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"];
  608. requestData.headers["x-path-info"] = pathInfo;
  609. requestData.headers["x-query-string"] = queryString;
  610. requestData.headers["x-script-url"] = url.url;
  611. //requestData.ev = new ManualResetEvent(false);
  612. lock (url.requests)
  613. {
  614. url.requests.Add(requestID, requestData);
  615. }
  616. lock (m_RequestMap)
  617. {
  618. //add to request map
  619. m_RequestMap.Add(requestID, url);
  620. }
  621. url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() });
  622. //send initial response?
  623. // Hashtable response = new Hashtable();
  624. return;
  625. }
  626. catch (Exception we)
  627. {
  628. //Hashtable response = new Hashtable();
  629. m_log.Warn("[HttpRequestHandler]: http-in request failed");
  630. m_log.Warn(we.Message);
  631. m_log.Warn(we.StackTrace);
  632. }
  633. }
  634. }
  635. private void OnScriptReset(uint localID, UUID itemID)
  636. {
  637. ScriptRemoved(itemID);
  638. }
  639. }
  640. }