aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Scripting
diff options
context:
space:
mode:
authorDiva Canto2009-09-22 14:46:05 -0700
committerDiva Canto2009-09-22 14:46:05 -0700
commitffd30b8ac31bc408316079ba86076bf9e984a8be (patch)
tree47c85aa445f21037576d6ce5e2df8f7477289343 /OpenSim/Region/CoreModules/Scripting
parentMerge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-ffd30b8ac31bc408316079ba86076bf9e984a8be.zip
opensim-SC-ffd30b8ac31bc408316079ba86076bf9e984a8be.tar.gz
opensim-SC-ffd30b8ac31bc408316079ba86076bf9e984a8be.tar.bz2
opensim-SC-ffd30b8ac31bc408316079ba86076bf9e984a8be.tar.xz
Moved RegionName from RegionInfo to SimpleRegionInfo.
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting')
-rw-r--r--OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs484
1 files changed, 242 insertions, 242 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
index 2d81e4c..8b7a878 100644
--- a/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/LSLHttp/UrlModule.cs
@@ -54,12 +54,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
54 { 54 {
55 public UUID requestID; 55 public UUID requestID;
56 public Dictionary<string, string> headers; 56 public Dictionary<string, string> headers;
57 public string body; 57 public string body;
58 public int responseCode; 58 public int responseCode;
59 public string responseBody; 59 public string responseBody;
60 public ManualResetEvent ev; 60 public ManualResetEvent ev;
61 public bool requestDone; 61 public bool requestDone;
62 public int startTime; 62 public int startTime;
63 public string uri; 63 public string uri;
64 } 64 }
65 65
@@ -73,23 +73,23 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
73 new Dictionary<UUID, UrlData>(); 73 new Dictionary<UUID, UrlData>();
74 74
75 private Dictionary<string, UrlData> m_UrlMap = 75 private Dictionary<string, UrlData> m_UrlMap =
76 new Dictionary<string, UrlData>(); 76 new Dictionary<string, UrlData>();
77 77
78 78
79 private int m_TotalUrls = 100; 79 private int m_TotalUrls = 100;
80 80
81 private IHttpServer m_HttpServer = null; 81 private IHttpServer m_HttpServer = null;
82 82
83 private string m_ExternalHostNameForLSL = ""; 83 private string m_ExternalHostNameForLSL = "";
84 84
85 public Type ReplaceableInterface 85 public Type ReplaceableInterface
86 { 86 {
87 get { return null; } 87 get { return null; }
88 } 88 }
89 89
90 private Hashtable HandleHttpPoll(Hashtable request) 90 private Hashtable HandleHttpPoll(Hashtable request)
91 { 91 {
92 return new Hashtable(); 92 return new Hashtable();
93 } 93 }
94 94
95 public string Name 95 public string Name
@@ -98,7 +98,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
98 } 98 }
99 99
100 public void Initialise(IConfigSource config) 100 public void Initialise(IConfigSource config)
101 { 101 {
102 m_ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", System.Environment.MachineName); 102 m_ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", System.Environment.MachineName);
103 } 103 }
104 104
@@ -130,7 +130,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
130 130
131 public void Close() 131 public void Close()
132 { 132 {
133 } 133 }
134 public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID) 134 public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
135 { 135 {
136 UUID urlcode = UUID.Random(); 136 UUID urlcode = UUID.Random();
@@ -141,8 +141,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
141 { 141 {
142 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" }); 142 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
143 return urlcode; 143 return urlcode;
144 } 144 }
145 string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/"; 145 string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/";
146 146
147 UrlData urlData = new UrlData(); 147 UrlData urlData = new UrlData();
148 urlData.hostID = host.UUID; 148 urlData.hostID = host.UUID;
@@ -152,14 +152,14 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
152 urlData.urlcode = urlcode; 152 urlData.urlcode = urlcode;
153 urlData.requests = new Dictionary<UUID, RequestData>(); 153 urlData.requests = new Dictionary<UUID, RequestData>();
154 154
155 155
156 m_UrlMap[url] = urlData; 156 m_UrlMap[url] = urlData;
157 157
158 string uri = "/lslhttp/" + urlcode.ToString() + "/"; 158 string uri = "/lslhttp/" + urlcode.ToString() + "/";
159 159
160 m_HttpServer.AddPollServiceHTTPHandler(uri,HandleHttpPoll, 160 m_HttpServer.AddPollServiceHTTPHandler(uri,HandleHttpPoll,
161 new PollServiceEventArgs(HttpRequestHandler,HasEvents, GetEvents, NoEvents, 161 new PollServiceEventArgs(HttpRequestHandler,HasEvents, GetEvents, NoEvents,
162 urlcode)); 162 urlcode));
163 163
164 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url }); 164 engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
165 } 165 }
@@ -180,11 +180,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
180 { 180 {
181 lock (m_UrlMap) 181 lock (m_UrlMap)
182 { 182 {
183 UrlData data; 183 UrlData data;
184 184
185 if (!m_UrlMap.TryGetValue(url, out data)) 185 if (!m_UrlMap.TryGetValue(url, out data))
186 { 186 {
187 return; 187 return;
188 } 188 }
189 189
190 foreach (UUID req in data.requests.Keys) 190 foreach (UUID req in data.requests.Keys)
@@ -196,36 +196,36 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
196 } 196 }
197 197
198 public void HttpResponse(UUID request, int status, string body) 198 public void HttpResponse(UUID request, int status, string body)
199 { 199 {
200 if (m_RequestMap.ContainsKey(request)) 200 if (m_RequestMap.ContainsKey(request))
201 { 201 {
202 UrlData urlData = m_RequestMap[request]; 202 UrlData urlData = m_RequestMap[request];
203 RequestData requestData=urlData.requests[request]; 203 RequestData requestData=urlData.requests[request];
204 urlData.requests[request].responseCode = status; 204 urlData.requests[request].responseCode = status;
205 urlData.requests[request].responseBody = body; 205 urlData.requests[request].responseBody = body;
206 //urlData.requests[request].ev.Set(); 206 //urlData.requests[request].ev.Set();
207 urlData.requests[request].requestDone=true; 207 urlData.requests[request].requestDone=true;
208 } 208 }
209 else 209 else
210 { 210 {
211 m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString()); 211 m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString());
212 } 212 }
213 } 213 }
214 214
215 public string GetHttpHeader(UUID requestId, string header) 215 public string GetHttpHeader(UUID requestId, string header)
216 { 216 {
217 if (m_RequestMap.ContainsKey(requestId)) 217 if (m_RequestMap.ContainsKey(requestId))
218 { 218 {
219 UrlData urlData=m_RequestMap[requestId]; 219 UrlData urlData=m_RequestMap[requestId];
220 string value; 220 string value;
221 if (urlData.requests[requestId].headers.TryGetValue(header,out value)) 221 if (urlData.requests[requestId].headers.TryGetValue(header,out value))
222 return value; 222 return value;
223 } 223 }
224 else 224 else
225 { 225 {
226 m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId); 226 m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId);
227 } 227 }
228 return String.Empty; 228 return String.Empty;
229 } 229 }
230 230
231 public int GetFreeUrls() 231 public int GetFreeUrls()
@@ -275,63 +275,63 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
275 foreach (string urlname in removeURLs) 275 foreach (string urlname in removeURLs)
276 m_UrlMap.Remove(urlname); 276 m_UrlMap.Remove(urlname);
277 } 277 }
278 } 278 }
279 279
280 280
281 private void RemoveUrl(UrlData data) 281 private void RemoveUrl(UrlData data)
282 { 282 {
283 m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/"); 283 m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/");
284 } 284 }
285 285
286 private Hashtable NoEvents(UUID requestID, UUID sessionID) 286 private Hashtable NoEvents(UUID requestID, UUID sessionID)
287 { 287 {
288 Hashtable response = new Hashtable(); 288 Hashtable response = new Hashtable();
289 UrlData url; 289 UrlData url;
290 lock (m_RequestMap) 290 lock (m_RequestMap)
291 { 291 {
292 if (!m_RequestMap.ContainsKey(requestID)) 292 if (!m_RequestMap.ContainsKey(requestID))
293 return response; 293 return response;
294 url = m_RequestMap[requestID]; 294 url = m_RequestMap[requestID];
295 } 295 }
296 296
297 if (System.Environment.TickCount - url.requests[requestID].startTime > 25000) 297 if (System.Environment.TickCount - url.requests[requestID].startTime > 25000)
298 { 298 {
299 response["int_response_code"] = 500; 299 response["int_response_code"] = 500;
300 response["str_response_string"] = "Script timeout"; 300 response["str_response_string"] = "Script timeout";
301 response["content_type"] = "text/plain"; 301 response["content_type"] = "text/plain";
302 response["keepalive"] = false; 302 response["keepalive"] = false;
303 response["reusecontext"] = false; 303 response["reusecontext"] = false;
304 304
305 //remove from map 305 //remove from map
306 lock (url) 306 lock (url)
307 { 307 {
308 url.requests.Remove(requestID); 308 url.requests.Remove(requestID);
309 m_RequestMap.Remove(requestID); 309 m_RequestMap.Remove(requestID);
310 } 310 }
311 311
312 return response; 312 return response;
313 } 313 }
314 314
315 315
316 return response; 316 return response;
317 } 317 }
318 318
319 private bool HasEvents(UUID requestID, UUID sessionID) 319 private bool HasEvents(UUID requestID, UUID sessionID)
320 { 320 {
321 UrlData url=null; 321 UrlData url=null;
322 322
323 lock (m_RequestMap) 323 lock (m_RequestMap)
324 { 324 {
325 if (!m_RequestMap.ContainsKey(requestID)) 325 if (!m_RequestMap.ContainsKey(requestID))
326 { 326 {
327 return false; 327 return false;
328 }
329 url = m_RequestMap[requestID];
330 if (!url.requests.ContainsKey(requestID))
331 {
332 return false;
333 } 328 }
334 } 329 url = m_RequestMap[requestID];
330 if (!url.requests.ContainsKey(requestID))
331 {
332 return false;
333 }
334 }
335 335
336 if (System.Environment.TickCount-url.requests[requestID].startTime>25000) 336 if (System.Environment.TickCount-url.requests[requestID].startTime>25000)
337 { 337 {
@@ -343,146 +343,146 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
343 else 343 else
344 return false; 344 return false;
345 345
346 } 346 }
347 private Hashtable GetEvents(UUID requestID, UUID sessionID, string request) 347 private Hashtable GetEvents(UUID requestID, UUID sessionID, string request)
348 { 348 {
349 UrlData url = null; 349 UrlData url = null;
350 RequestData requestData = null; 350 RequestData requestData = null;
351 351
352 lock (m_RequestMap) 352 lock (m_RequestMap)
353 { 353 {
354 if (!m_RequestMap.ContainsKey(requestID)) 354 if (!m_RequestMap.ContainsKey(requestID))
355 return NoEvents(requestID,sessionID); 355 return NoEvents(requestID,sessionID);
356 url = m_RequestMap[requestID]; 356 url = m_RequestMap[requestID];
357 requestData = url.requests[requestID]; 357 requestData = url.requests[requestID];
358 } 358 }
359 359
360 if (!requestData.requestDone) 360 if (!requestData.requestDone)
361 return NoEvents(requestID,sessionID); 361 return NoEvents(requestID,sessionID);
362 362
363 Hashtable response = new Hashtable(); 363 Hashtable response = new Hashtable();
364 364
365 if (System.Environment.TickCount - requestData.startTime > 25000) 365 if (System.Environment.TickCount - requestData.startTime > 25000)
366 { 366 {
367 response["int_response_code"] = 500; 367 response["int_response_code"] = 500;
368 response["str_response_string"] = "Script timeout"; 368 response["str_response_string"] = "Script timeout";
369 response["content_type"] = "text/plain"; 369 response["content_type"] = "text/plain";
370 response["keepalive"] = false; 370 response["keepalive"] = false;
371 response["reusecontext"] = false; 371 response["reusecontext"] = false;
372 return response; 372 return response;
373 } 373 }
374 //put response 374 //put response
375 response["int_response_code"] = requestData.responseCode; 375 response["int_response_code"] = requestData.responseCode;
376 response["str_response_string"] = requestData.responseBody; 376 response["str_response_string"] = requestData.responseBody;
377 response["content_type"] = "text/plain"; 377 response["content_type"] = "text/plain";
378 response["keepalive"] = false; 378 response["keepalive"] = false;
379 response["reusecontext"] = false; 379 response["reusecontext"] = false;
380 380
381 //remove from map 381 //remove from map
382 lock (url) 382 lock (url)
383 { 383 {
384 url.requests.Remove(requestID); 384 url.requests.Remove(requestID);
385 m_RequestMap.Remove(requestID); 385 m_RequestMap.Remove(requestID);
386 } 386 }
387 387
388 return response; 388 return response;
389 } 389 }
390 public void HttpRequestHandler(UUID requestID, Hashtable request) 390 public void HttpRequestHandler(UUID requestID, Hashtable request)
391 { 391 {
392 lock (request) 392 lock (request)
393 { 393 {
394 string uri = request["uri"].ToString(); 394 string uri = request["uri"].ToString();
395 395
396 try 396 try
397 { 397 {
398 Hashtable headers = (Hashtable)request["headers"]; 398 Hashtable headers = (Hashtable)request["headers"];
399 399
400 string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/"; 400 string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/";
401 401
402 int pos1 = uri.IndexOf("/");// /lslhttp 402 int pos1 = uri.IndexOf("/");// /lslhttp
403 int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/ 403 int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/
404 int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/ 404 int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/
405 string uri_tmp = uri.Substring(0, pos3 + 1); 405 string uri_tmp = uri.Substring(0, pos3 + 1);
406 //HTTP server code doesn't provide us with QueryStrings 406 //HTTP server code doesn't provide us with QueryStrings
407 string pathInfo; 407 string pathInfo;
408 string queryString; 408 string queryString;
409 queryString = ""; 409 queryString = "";
410 410
411 pathInfo = uri.Substring(pos3); 411 pathInfo = uri.Substring(pos3);
412 412
413 UrlData url = m_UrlMap["http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp]; 413 UrlData url = m_UrlMap["http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp];
414 414
415 //for llGetHttpHeader support we need to store original URI here 415 //for llGetHttpHeader support we need to store original URI here
416 //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers 416 //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
417 //as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader 417 //as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader
418 418
419 RequestData requestData = new RequestData(); 419 RequestData requestData = new RequestData();
420 requestData.requestID = requestID; 420 requestData.requestID = requestID;
421 requestData.requestDone = false; 421 requestData.requestDone = false;
422 requestData.startTime = System.Environment.TickCount; 422 requestData.startTime = System.Environment.TickCount;
423 requestData.uri = uri; 423 requestData.uri = uri;
424 if (requestData.headers == null) 424 if (requestData.headers == null)
425 requestData.headers = new Dictionary<string, string>(); 425 requestData.headers = new Dictionary<string, string>();
426 426
427 foreach (DictionaryEntry header in headers) 427 foreach (DictionaryEntry header in headers)
428 { 428 {
429 string key = (string)header.Key; 429 string key = (string)header.Key;
430 string value = (string)header.Value; 430 string value = (string)header.Value;
431 requestData.headers.Add(key, value); 431 requestData.headers.Add(key, value);
432 } 432 }
433 foreach (DictionaryEntry de in request) 433 foreach (DictionaryEntry de in request)
434 { 434 {
435 if (de.Key.ToString() == "querystringkeys") 435 if (de.Key.ToString() == "querystringkeys")
436 { 436 {
437 System.String[] keys = (System.String[])de.Value; 437 System.String[] keys = (System.String[])de.Value;
438 foreach (String key in keys) 438 foreach (String key in keys)
439 { 439 {
440 if (request.ContainsKey(key)) 440 if (request.ContainsKey(key))
441 { 441 {
442 string val = (String)request[key]; 442 string val = (String)request[key];
443 queryString = queryString + key + "=" + val + "&"; 443 queryString = queryString + key + "=" + val + "&";
444 } 444 }
445 } 445 }
446 if (queryString.Length > 1) 446 if (queryString.Length > 1)
447 queryString = queryString.Substring(0, queryString.Length - 1); 447 queryString = queryString.Substring(0, queryString.Length - 1);
448 448
449 } 449 }
450 450
451 } 451 }
452 452
453 //if this machine is behind DNAT/port forwarding, currently this is being 453 //if this machine is behind DNAT/port forwarding, currently this is being
454 //set to address of port forwarding router 454 //set to address of port forwarding router
455 requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"]; 455 requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"];
456 requestData.headers["x-path-info"] = pathInfo; 456 requestData.headers["x-path-info"] = pathInfo;
457 requestData.headers["x-query-string"] = queryString; 457 requestData.headers["x-query-string"] = queryString;
458 requestData.headers["x-script-url"] = url.url; 458 requestData.headers["x-script-url"] = url.url;
459 459
460 requestData.ev = new ManualResetEvent(false); 460 requestData.ev = new ManualResetEvent(false);
461 lock (url.requests) 461 lock (url.requests)
462 { 462 {
463 url.requests.Add(requestID, requestData); 463 url.requests.Add(requestID, requestData);
464 } 464 }
465 lock (m_RequestMap) 465 lock (m_RequestMap)
466 { 466 {
467 //add to request map 467 //add to request map
468 m_RequestMap.Add(requestID, url); 468 m_RequestMap.Add(requestID, url);
469 } 469 }
470 470
471 url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() }); 471 url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() });
472 472
473 //send initial response? 473 //send initial response?
474 Hashtable response = new Hashtable(); 474 Hashtable response = new Hashtable();
475 475
476 return; 476 return;
477 477
478 } 478 }
479 catch (Exception we) 479 catch (Exception we)
480 { 480 {
481 //Hashtable response = new Hashtable(); 481 //Hashtable response = new Hashtable();
482 m_log.Warn("[HttpRequestHandler]: http-in request failed"); 482 m_log.Warn("[HttpRequestHandler]: http-in request failed");
483 m_log.Warn(we.Message); 483 m_log.Warn(we.Message);
484 m_log.Warn(we.StackTrace); 484 m_log.Warn(we.StackTrace);
485 } 485 }
486 } 486 }
487 } 487 }
488 488