UrlModule.cs 27 KB

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