diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs | 96 |
1 files changed, 62 insertions, 34 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs index a654477..99a3122 100644 --- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs | |||
@@ -117,20 +117,21 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
117 | /// </summary> | 117 | /// </summary> |
118 | private Dictionary<string, UrlData> m_UrlMap = new Dictionary<string, UrlData>(); | 118 | private Dictionary<string, UrlData> m_UrlMap = new Dictionary<string, UrlData>(); |
119 | 119 | ||
120 | /// <summary> | 120 | private uint m_HttpsPort = 0; |
121 | /// Maximum number of external urls that can be set up by this module. | ||
122 | /// </summary> | ||
123 | private int m_TotalUrls = 100; | ||
124 | |||
125 | private uint https_port = 0; | ||
126 | private IHttpServer m_HttpServer = null; | 121 | private IHttpServer m_HttpServer = null; |
127 | private IHttpServer m_HttpsServer = null; | 122 | private IHttpServer m_HttpsServer = null; |
128 | 123 | ||
129 | private string m_ExternalHostNameForLSL = ""; | 124 | public string ExternalHostNameForLSL { get; private set; } |
130 | public string ExternalHostNameForLSL | 125 | |
131 | { | 126 | /// <summary> |
132 | get { return m_ExternalHostNameForLSL; } | 127 | /// The default maximum number of urls |
133 | } | 128 | /// </summary> |
129 | public const int DefaultTotalUrls = 100; | ||
130 | |||
131 | /// <summary> | ||
132 | /// Maximum number of external urls that can be set up by this module. | ||
133 | /// </summary> | ||
134 | public int TotalUrls { get; set; } | ||
134 | 135 | ||
135 | public Type ReplaceableInterface | 136 | public Type ReplaceableInterface |
136 | { | 137 | { |
@@ -144,16 +145,27 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
144 | 145 | ||
145 | public void Initialise(IConfigSource config) | 146 | public void Initialise(IConfigSource config) |
146 | { | 147 | { |
147 | m_ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", System.Environment.MachineName); | 148 | IConfig networkConfig = config.Configs["Network"]; |
148 | bool ssl_enabled = config.Configs["Network"].GetBoolean("https_listener",false); | 149 | |
150 | if (networkConfig != null) | ||
151 | { | ||
152 | ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", null); | ||
153 | |||
154 | bool ssl_enabled = config.Configs["Network"].GetBoolean("https_listener", false); | ||
155 | |||
156 | if (ssl_enabled) | ||
157 | m_HttpsPort = (uint)config.Configs["Network"].GetInt("https_port", (int)m_HttpsPort); | ||
158 | } | ||
149 | 159 | ||
150 | if (ssl_enabled) | 160 | if (ExternalHostNameForLSL == null) |
151 | https_port = (uint) config.Configs["Network"].GetInt("https_port",0); | 161 | ExternalHostNameForLSL = System.Environment.MachineName; |
152 | 162 | ||
153 | IConfig llFunctionsConfig = config.Configs["LL-Functions"]; | 163 | IConfig llFunctionsConfig = config.Configs["LL-Functions"]; |
154 | 164 | ||
155 | if (llFunctionsConfig != null) | 165 | if (llFunctionsConfig != null) |
156 | m_TotalUrls = llFunctionsConfig.GetInt("max_external_urls_per_simulator", m_TotalUrls); | 166 | TotalUrls = llFunctionsConfig.GetInt("max_external_urls_per_simulator", DefaultTotalUrls); |
167 | else | ||
168 | TotalUrls = DefaultTotalUrls; | ||
157 | } | 169 | } |
158 | 170 | ||
159 | public void PostInitialise() | 171 | public void PostInitialise() |
@@ -169,9 +181,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
169 | m_HttpServer = MainServer.Instance; | 181 | m_HttpServer = MainServer.Instance; |
170 | // | 182 | // |
171 | // We can use the https if it is enabled | 183 | // We can use the https if it is enabled |
172 | if (https_port > 0) | 184 | if (m_HttpsPort > 0) |
173 | { | 185 | { |
174 | m_HttpsServer = MainServer.GetHttpServer(https_port); | 186 | m_HttpsServer = MainServer.GetHttpServer(m_HttpsPort); |
175 | } | 187 | } |
176 | } | 188 | } |
177 | 189 | ||
@@ -204,12 +216,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
204 | 216 | ||
205 | lock (m_UrlMap) | 217 | lock (m_UrlMap) |
206 | { | 218 | { |
207 | if (m_UrlMap.Count >= m_TotalUrls) | 219 | if (m_UrlMap.Count >= TotalUrls) |
208 | { | 220 | { |
209 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); | 221 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); |
210 | return urlcode; | 222 | return urlcode; |
211 | } | 223 | } |
212 | string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; | 224 | string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; |
213 | 225 | ||
214 | UrlData urlData = new UrlData(); | 226 | UrlData urlData = new UrlData(); |
215 | urlData.hostID = host.UUID; | 227 | urlData.hostID = host.UUID; |
@@ -223,9 +235,10 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
223 | 235 | ||
224 | string uri = "/lslhttp/" + urlcode.ToString() + "/"; | 236 | string uri = "/lslhttp/" + urlcode.ToString() + "/"; |
225 | 237 | ||
226 | m_HttpServer.AddPollServiceHTTPHandler( | 238 | PollServiceEventArgs args |
227 | uri, | 239 | = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000); |
228 | new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode)); | 240 | args.Type = PollServiceEventArgs.EventType.LslHttp; |
241 | m_HttpServer.AddPollServiceHTTPHandler(uri, args); | ||
229 | 242 | ||
230 | m_log.DebugFormat( | 243 | m_log.DebugFormat( |
231 | "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}", | 244 | "[URL MODULE]: Set up incoming request url {0} for {1} in {2} {3}", |
@@ -249,12 +262,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
249 | 262 | ||
250 | lock (m_UrlMap) | 263 | lock (m_UrlMap) |
251 | { | 264 | { |
252 | if (m_UrlMap.Count >= m_TotalUrls) | 265 | if (m_UrlMap.Count >= TotalUrls) |
253 | { | 266 | { |
254 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); | 267 | engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); |
255 | return urlcode; | 268 | return urlcode; |
256 | } | 269 | } |
257 | string url = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/"; | 270 | string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/"; |
258 | 271 | ||
259 | UrlData urlData = new UrlData(); | 272 | UrlData urlData = new UrlData(); |
260 | urlData.hostID = host.UUID; | 273 | urlData.hostID = host.UUID; |
@@ -268,9 +281,10 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
268 | 281 | ||
269 | string uri = "/lslhttps/" + urlcode.ToString() + "/"; | 282 | string uri = "/lslhttps/" + urlcode.ToString() + "/"; |
270 | 283 | ||
271 | m_HttpsServer.AddPollServiceHTTPHandler( | 284 | PollServiceEventArgs args |
272 | uri, | 285 | = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000); |
273 | new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode)); | 286 | args.Type = PollServiceEventArgs.EventType.LslHttp; |
287 | m_HttpsServer.AddPollServiceHTTPHandler(uri, args); | ||
274 | 288 | ||
275 | m_log.DebugFormat( | 289 | m_log.DebugFormat( |
276 | "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}", | 290 | "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}", |
@@ -328,8 +342,22 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
328 | if (m_RequestMap.ContainsKey(request)) | 342 | if (m_RequestMap.ContainsKey(request)) |
329 | { | 343 | { |
330 | UrlData urlData = m_RequestMap[request]; | 344 | UrlData urlData = m_RequestMap[request]; |
345 | string responseBody = body; | ||
346 | if (urlData.requests[request].responseType.Equals("text/plain")) | ||
347 | { | ||
348 | string value; | ||
349 | if (urlData.requests[request].headers.TryGetValue("user-agent", out value)) | ||
350 | { | ||
351 | if (value != null && value.IndexOf("MSIE") >= 0) | ||
352 | { | ||
353 | // wrap the html escaped response if the target client is IE | ||
354 | // It ignores "text/plain" if the body is html | ||
355 | responseBody = "<html>" + System.Web.HttpUtility.HtmlEncode(body) + "</html>"; | ||
356 | } | ||
357 | } | ||
358 | } | ||
331 | urlData.requests[request].responseCode = status; | 359 | urlData.requests[request].responseCode = status; |
332 | urlData.requests[request].responseBody = body; | 360 | urlData.requests[request].responseBody = responseBody; |
333 | //urlData.requests[request].ev.Set(); | 361 | //urlData.requests[request].ev.Set(); |
334 | urlData.requests[request].requestDone =true; | 362 | urlData.requests[request].requestDone =true; |
335 | } | 363 | } |
@@ -363,7 +391,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
363 | public int GetFreeUrls() | 391 | public int GetFreeUrls() |
364 | { | 392 | { |
365 | lock (m_UrlMap) | 393 | lock (m_UrlMap) |
366 | return m_TotalUrls - m_UrlMap.Count; | 394 | return TotalUrls - m_UrlMap.Count; |
367 | } | 395 | } |
368 | 396 | ||
369 | public void ScriptRemoved(UUID itemID) | 397 | public void ScriptRemoved(UUID itemID) |
@@ -490,7 +518,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
490 | } | 518 | } |
491 | } | 519 | } |
492 | 520 | ||
493 | private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) | 521 | private Hashtable GetEvents(UUID requestID, UUID sessionID) |
494 | { | 522 | { |
495 | Hashtable response; | 523 | Hashtable response; |
496 | 524 | ||
@@ -565,9 +593,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
565 | string url; | 593 | string url; |
566 | 594 | ||
567 | if (is_ssl) | 595 | if (is_ssl) |
568 | url = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; | 596 | url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp; |
569 | else | 597 | else |
570 | url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; | 598 | url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp; |
571 | 599 | ||
572 | // Avoid a race - the request URL may have been released via llRequestUrl() whilst this | 600 | // Avoid a race - the request URL may have been released via llRequestUrl() whilst this |
573 | // request was being processed. | 601 | // request was being processed. |
@@ -642,4 +670,4 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp | |||
642 | ScriptRemoved(itemID); | 670 | ScriptRemoved(itemID); |
643 | } | 671 | } |
644 | } | 672 | } |
645 | } \ No newline at end of file | 673 | } |