Merge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim
commit
0fc2b73e7b
|
@ -198,7 +198,7 @@ namespace OpenSim.Framework.Console
|
||||||
string uri = "/ReadResponses/" + sessionID.ToString() + "/";
|
string uri = "/ReadResponses/" + sessionID.ToString() + "/";
|
||||||
|
|
||||||
m_Server.AddPollServiceHTTPHandler(uri, HandleHttpPoll,
|
m_Server.AddPollServiceHTTPHandler(uri, HandleHttpPoll,
|
||||||
new PollServiceEventArgs(HasEvents, GetEvents, NoEvents,
|
new PollServiceEventArgs(null, HasEvents, GetEvents, NoEvents,
|
||||||
sessionID));
|
sessionID));
|
||||||
|
|
||||||
XmlDocument xmldoc = new XmlDocument();
|
XmlDocument xmldoc = new XmlDocument();
|
||||||
|
|
|
@ -256,17 +256,51 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
IHttpClientContext context = (IHttpClientContext)source;
|
IHttpClientContext context = (IHttpClientContext)source;
|
||||||
IHttpRequest request = args.Request;
|
IHttpRequest request = args.Request;
|
||||||
|
|
||||||
|
|
||||||
PollServiceEventArgs psEvArgs;
|
PollServiceEventArgs psEvArgs;
|
||||||
|
|
||||||
if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs))
|
if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs))
|
||||||
|
{
|
||||||
|
PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request);
|
||||||
|
|
||||||
|
if (psEvArgs.Request != null)
|
||||||
{
|
{
|
||||||
OSHttpRequest req = new OSHttpRequest(context, request);
|
OSHttpRequest req = new OSHttpRequest(context, request);
|
||||||
|
|
||||||
PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request);
|
Stream requestStream = req.InputStream;
|
||||||
req.Headers["X-PollServiceID"] = psreq.RequestID.ToString();
|
|
||||||
HandleRequest(req, null);
|
Encoding encoding = Encoding.UTF8;
|
||||||
|
StreamReader reader = new StreamReader(requestStream, encoding);
|
||||||
|
|
||||||
|
string requestBody = reader.ReadToEnd();
|
||||||
|
|
||||||
|
Hashtable keysvals = new Hashtable();
|
||||||
|
Hashtable headervals = new Hashtable();
|
||||||
|
|
||||||
|
string[] querystringkeys = req.QueryString.AllKeys;
|
||||||
|
string[] rHeaders = req.Headers.AllKeys;
|
||||||
|
|
||||||
|
keysvals.Add("body", requestBody);
|
||||||
|
keysvals.Add("uri", req.RawUrl);
|
||||||
|
keysvals.Add("content-type", req.ContentType);
|
||||||
|
keysvals.Add("http-method", req.HttpMethod);
|
||||||
|
|
||||||
|
foreach (string queryname in querystringkeys)
|
||||||
|
{
|
||||||
|
keysvals.Add(queryname, req.QueryString[queryname]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string headername in rHeaders)
|
||||||
|
{
|
||||||
|
headervals[headername] = req.Headers[headername];
|
||||||
|
}
|
||||||
|
|
||||||
|
keysvals.Add("headers",headervals);
|
||||||
|
keysvals.Add("querystringkeys", querystringkeys);
|
||||||
|
|
||||||
|
psEvArgs.Request(psreq.RequestID, keysvals);
|
||||||
|
}
|
||||||
|
|
||||||
m_PollServiceManager.Enqueue(psreq);
|
m_PollServiceManager.Enqueue(psreq);
|
||||||
//DoHTTPGruntWork(psEvArgs.NoEvents(),new OSHttpResponse(new HttpResponse(context, request)));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -279,48 +313,16 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
{
|
{
|
||||||
OSHttpRequest req = new OSHttpRequest(context, request);
|
OSHttpRequest req = new OSHttpRequest(context, request);
|
||||||
OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context);
|
OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context);
|
||||||
//resp.KeepAlive = req.KeepAlive;
|
|
||||||
//m_log.Info("[Debug BASE HTTP SERVER]: Got Request");
|
|
||||||
//HttpServerContextObj objstate= new HttpServerContextObj(req,resp);
|
|
||||||
//ThreadPool.QueueUserWorkItem(new WaitCallback(ConvertIHttpClientContextToOSHttp), (object)objstate);
|
|
||||||
HandleRequest(req, resp);
|
HandleRequest(req, resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ConvertIHttpClientContextToOSHttp(object stateinfo)
|
public void ConvertIHttpClientContextToOSHttp(object stateinfo)
|
||||||
{
|
{
|
||||||
HttpServerContextObj objstate = (HttpServerContextObj)stateinfo;
|
HttpServerContextObj objstate = (HttpServerContextObj)stateinfo;
|
||||||
//OSHttpRequest request = new OSHttpRequest(objstate.context,objstate.req);
|
|
||||||
//OSHttpResponse resp = new OSHttpResponse(new HttpServer.HttpResponse(objstate.context, objstate.req));
|
|
||||||
|
|
||||||
OSHttpRequest request = objstate.oreq;
|
OSHttpRequest request = objstate.oreq;
|
||||||
OSHttpResponse resp = objstate.oresp;
|
OSHttpResponse resp = objstate.oresp;
|
||||||
//OSHttpResponse resp = new OSHttpResponse(new HttpServer.HttpResponse(objstate.context, objstate.req));
|
|
||||||
|
|
||||||
/*
|
|
||||||
request.AcceptTypes = objstate.req.AcceptTypes;
|
|
||||||
request.ContentLength = (long)objstate.req.ContentLength;
|
|
||||||
request.Headers = objstate.req.Headers;
|
|
||||||
request.HttpMethod = objstate.req.Method;
|
|
||||||
request.InputStream = objstate.req.Body;
|
|
||||||
foreach (string str in request.Headers)
|
|
||||||
{
|
|
||||||
if (str.ToLower().Contains("content-type: "))
|
|
||||||
{
|
|
||||||
request.ContentType = str.Substring(13, str.Length - 13);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//request.KeepAlive = objstate.req.
|
|
||||||
foreach (HttpServer.HttpInput httpinput in objstate.req.QueryString)
|
|
||||||
{
|
|
||||||
request.QueryString.Add(httpinput.Name, httpinput[httpinput.Name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//request.Query = objstate.req.//objstate.req.QueryString;
|
|
||||||
//foreach (
|
|
||||||
//request.QueryString = objstate.req.QueryString;
|
|
||||||
|
|
||||||
*/
|
|
||||||
HandleRequest(request,resp);
|
HandleRequest(request,resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,11 +339,6 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
// handled
|
// handled
|
||||||
//m_log.Debug("[BASE HTTP SERVER]: Handling Request" + request.RawUrl);
|
//m_log.Debug("[BASE HTTP SERVER]: Handling Request" + request.RawUrl);
|
||||||
|
|
||||||
// If the response is null, then we're not going to respond here. This case
|
|
||||||
// triggers when we're at the head of a HTTP poll
|
|
||||||
//
|
|
||||||
if (response != null)
|
|
||||||
{
|
|
||||||
IHttpAgentHandler agentHandler;
|
IHttpAgentHandler agentHandler;
|
||||||
|
|
||||||
if (TryGetAgentHandler(request, response, out agentHandler))
|
if (TryGetAgentHandler(request, response, out agentHandler))
|
||||||
|
@ -354,7 +351,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
|
|
||||||
//response.KeepAlive = true;
|
//response.KeepAlive = true;
|
||||||
response.SendChunked = false;
|
response.SendChunked = false;
|
||||||
}
|
|
||||||
IRequestHandler requestHandler;
|
IRequestHandler requestHandler;
|
||||||
|
|
||||||
string path = request.RawUrl;
|
string path = request.RawUrl;
|
||||||
|
@ -368,7 +365,6 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
// Okay, so this is bad, but should be considered temporary until everything is IStreamHandler.
|
// Okay, so this is bad, but should be considered temporary until everything is IStreamHandler.
|
||||||
byte[] buffer = null;
|
byte[] buffer = null;
|
||||||
|
|
||||||
if (response != null)
|
|
||||||
response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type.
|
response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type.
|
||||||
|
|
||||||
|
|
||||||
|
@ -425,11 +421,6 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
//m_log.Warn("[HTTP]: " + requestBody);
|
//m_log.Warn("[HTTP]: " + requestBody);
|
||||||
|
|
||||||
}
|
}
|
||||||
// If we're not responding, we dont' care about the reply
|
|
||||||
//
|
|
||||||
if (response == null)
|
|
||||||
HTTPRequestHandler.Handle(path, keysvals);
|
|
||||||
else
|
|
||||||
DoHTTPGruntWork(HTTPRequestHandler.Handle(path, keysvals), response);
|
DoHTTPGruntWork(HTTPRequestHandler.Handle(path, keysvals), response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -445,11 +436,6 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The handler has run and we're not yet ready to respond, bail
|
|
||||||
//
|
|
||||||
if (response == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
request.InputStream.Close();
|
request.InputStream.Close();
|
||||||
|
|
||||||
// HTTP IN support. The script engine taes it from here
|
// HTTP IN support. The script engine taes it from here
|
||||||
|
|
|
@ -30,6 +30,7 @@ using System.Collections;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
namespace OpenSim.Framework.Servers.HttpServer
|
namespace OpenSim.Framework.Servers.HttpServer
|
||||||
{
|
{
|
||||||
|
public delegate void RequestMethod(UUID requestID, Hashtable request);
|
||||||
public delegate bool HasEventsMethod(UUID requestID, UUID pId);
|
public delegate bool HasEventsMethod(UUID requestID, UUID pId);
|
||||||
|
|
||||||
public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId, string request);
|
public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId, string request);
|
||||||
|
@ -41,9 +42,11 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
public HasEventsMethod HasEvents;
|
public HasEventsMethod HasEvents;
|
||||||
public GetEventsMethod GetEvents;
|
public GetEventsMethod GetEvents;
|
||||||
public NoEventsMethod NoEvents;
|
public NoEventsMethod NoEvents;
|
||||||
|
public RequestMethod Request;
|
||||||
public UUID Id;
|
public UUID Id;
|
||||||
public PollServiceEventArgs(HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,UUID pId)
|
public PollServiceEventArgs(RequestMethod pRequest, HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,UUID pId)
|
||||||
{
|
{
|
||||||
|
Request = pRequest;
|
||||||
HasEvents = pHasEvents;
|
HasEvents = pHasEvents;
|
||||||
GetEvents = pGetEvents;
|
GetEvents = pGetEvents;
|
||||||
NoEvents = pNoEvents;
|
NoEvents = pNoEvents;
|
||||||
|
|
|
@ -316,7 +316,7 @@ namespace OpenSim.Region.CoreModules.Framework.EventQueue
|
||||||
|
|
||||||
// This will persist this beyond the expiry of the caps handlers
|
// This will persist this beyond the expiry of the caps handlers
|
||||||
MainServer.Instance.AddPollServiceHTTPHandler(
|
MainServer.Instance.AddPollServiceHTTPHandler(
|
||||||
capsBase + EventQueueGetUUID.ToString() + "/", EventQueuePoll, new PollServiceEventArgs(HasEvents, GetEvents, NoEvents, agentID));
|
capsBase + EventQueueGetUUID.ToString() + "/", EventQueuePoll, new PollServiceEventArgs(null, HasEvents, GetEvents, NoEvents, agentID));
|
||||||
|
|
||||||
Random rnd = new Random(Environment.TickCount);
|
Random rnd = new Random(Environment.TickCount);
|
||||||
lock (m_ids)
|
lock (m_ids)
|
||||||
|
|
|
@ -55,14 +55,19 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||||
public UUID requestID;
|
public UUID requestID;
|
||||||
public Dictionary<string, string> headers;
|
public Dictionary<string, string> headers;
|
||||||
public string body;
|
public string body;
|
||||||
|
public int responseCode;
|
||||||
|
public string responseBody;
|
||||||
public ManualResetEvent ev;
|
public ManualResetEvent ev;
|
||||||
|
public bool requestDone;
|
||||||
|
public int startTime;
|
||||||
|
public string uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UrlModule : ISharedRegionModule, IUrlModule
|
public class UrlModule : ISharedRegionModule, IUrlModule
|
||||||
{
|
{
|
||||||
// private static readonly ILog m_log =
|
private static readonly ILog m_log =
|
||||||
// LogManager.GetLogger(
|
LogManager.GetLogger(
|
||||||
// MethodBase.GetCurrentMethod().DeclaringType);
|
MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
private Dictionary<UUID, UrlData> m_RequestMap =
|
private Dictionary<UUID, UrlData> m_RequestMap =
|
||||||
new Dictionary<UUID, UrlData>();
|
new Dictionary<UUID, UrlData>();
|
||||||
|
@ -70,15 +75,23 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||||
private Dictionary<string, UrlData> m_UrlMap =
|
private Dictionary<string, UrlData> m_UrlMap =
|
||||||
new Dictionary<string, UrlData>();
|
new Dictionary<string, UrlData>();
|
||||||
|
|
||||||
|
|
||||||
private int m_TotalUrls = 100;
|
private int m_TotalUrls = 100;
|
||||||
|
|
||||||
private IHttpServer m_HttpServer = null;
|
private IHttpServer m_HttpServer = null;
|
||||||
|
|
||||||
|
private string m_ExternalHostNameForLSL = "";
|
||||||
|
|
||||||
public Type ReplaceableInterface
|
public Type ReplaceableInterface
|
||||||
{
|
{
|
||||||
get { return null; }
|
get { return null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Hashtable HandleHttpPoll(Hashtable request)
|
||||||
|
{
|
||||||
|
return new Hashtable();
|
||||||
|
}
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
get { return "UrlModule"; }
|
get { return "UrlModule"; }
|
||||||
|
@ -86,6 +99,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||||
|
|
||||||
public void Initialise(IConfigSource config)
|
public void Initialise(IConfigSource config)
|
||||||
{
|
{
|
||||||
|
m_ExternalHostNameForLSL = config.Configs["Network"].GetString("ExternalHostNameForLSL", System.Environment.MachineName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PostInitialise()
|
public void PostInitialise()
|
||||||
|
@ -117,7 +131,6 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
|
public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
|
||||||
{
|
{
|
||||||
UUID urlcode = UUID.Random();
|
UUID urlcode = UUID.Random();
|
||||||
|
@ -129,7 +142,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||||
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
|
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
|
||||||
return urlcode;
|
return urlcode;
|
||||||
}
|
}
|
||||||
string url = "http://"+System.Environment.MachineName+":"+m_HttpServer.Port.ToString()+"/lslhttp/"+urlcode.ToString()+"/";
|
string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/";
|
||||||
|
|
||||||
UrlData urlData = new UrlData();
|
UrlData urlData = new UrlData();
|
||||||
urlData.hostID = host.UUID;
|
urlData.hostID = host.UUID;
|
||||||
|
@ -139,9 +152,14 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||||
urlData.urlcode = urlcode;
|
urlData.urlcode = urlcode;
|
||||||
urlData.requests = new Dictionary<UUID, RequestData>();
|
urlData.requests = new Dictionary<UUID, RequestData>();
|
||||||
|
|
||||||
|
|
||||||
m_UrlMap[url] = urlData;
|
m_UrlMap[url] = urlData;
|
||||||
|
|
||||||
m_HttpServer.AddHTTPHandler("/lslhttp/"+urlcode.ToString()+"/", HttpRequestHandler);
|
string uri = "/lslhttp/" + urlcode.ToString() + "/";
|
||||||
|
|
||||||
|
m_HttpServer.AddPollServiceHTTPHandler(uri,HandleHttpPoll,
|
||||||
|
new PollServiceEventArgs(HttpRequestHandler,HasEvents, GetEvents, NoEvents,
|
||||||
|
urlcode));
|
||||||
|
|
||||||
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
|
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
|
||||||
}
|
}
|
||||||
|
@ -165,7 +183,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||||
UrlData data;
|
UrlData data;
|
||||||
|
|
||||||
if (!m_UrlMap.TryGetValue(url, out data))
|
if (!m_UrlMap.TryGetValue(url, out data))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (UUID req in data.requests.Keys)
|
foreach (UUID req in data.requests.Keys)
|
||||||
m_RequestMap.Remove(req);
|
m_RequestMap.Remove(req);
|
||||||
|
@ -177,10 +197,34 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||||
|
|
||||||
public void HttpResponse(UUID request, int status, string body)
|
public void HttpResponse(UUID request, int status, string body)
|
||||||
{
|
{
|
||||||
|
if (m_RequestMap.ContainsKey(request))
|
||||||
|
{
|
||||||
|
UrlData urlData = m_RequestMap[request];
|
||||||
|
RequestData requestData=urlData.requests[request];
|
||||||
|
urlData.requests[request].responseCode = status;
|
||||||
|
urlData.requests[request].responseBody = body;
|
||||||
|
//urlData.requests[request].ev.Set();
|
||||||
|
urlData.requests[request].requestDone=true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.Info("[HttpRequestHandler] There is no http-in request with id " + request.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetHttpHeader(UUID request, string header)
|
public string GetHttpHeader(UUID requestId, string header)
|
||||||
{
|
{
|
||||||
|
if (m_RequestMap.ContainsKey(requestId))
|
||||||
|
{
|
||||||
|
UrlData urlData=m_RequestMap[requestId];
|
||||||
|
string value;
|
||||||
|
if (urlData.requests[requestId].headers.TryGetValue(header,out value))
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.Warn("[HttpRequestHandler] There was no http-in request with id " + requestId);
|
||||||
|
}
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,27 +277,215 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void RemoveUrl(UrlData data)
|
private void RemoveUrl(UrlData data)
|
||||||
{
|
{
|
||||||
m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/");
|
m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Hashtable HttpRequestHandler(Hashtable request)
|
private Hashtable NoEvents(UUID requestID, UUID sessionID)
|
||||||
{
|
{
|
||||||
string uri = request["uri"].ToString();
|
|
||||||
//A solution to this ugly mess would be to use only the /lslhttp/<UUID>/ part of the URI as the key.
|
|
||||||
UrlData url = m_UrlMap["http://"+System.Environment.MachineName+":"+m_HttpServer.Port.ToString()+uri];
|
|
||||||
|
|
||||||
//UUID.Random() below is a hack! Eventually we will do HTTP requests and responses properly.
|
|
||||||
url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { UUID.Random().ToString(), request["http-method"].ToString(), request["body"].ToString() });
|
|
||||||
|
|
||||||
Hashtable response = new Hashtable();
|
Hashtable response = new Hashtable();
|
||||||
response["int_response_code"] = 200;
|
UrlData url;
|
||||||
response["str_response_string"] = "This is a generic response as OpenSim does not yet support proper responses. Your request has been passed to the object.";
|
lock (m_RequestMap)
|
||||||
|
{
|
||||||
|
if (!m_RequestMap.ContainsKey(requestID))
|
||||||
|
return response;
|
||||||
|
url = m_RequestMap[requestID];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (System.Environment.TickCount - url.requests[requestID].startTime > 25000)
|
||||||
|
{
|
||||||
|
response["int_response_code"] = 500;
|
||||||
|
response["str_response_string"] = "Script timeout";
|
||||||
|
response["content_type"] = "text/plain";
|
||||||
|
response["keepalive"] = false;
|
||||||
|
response["reusecontext"] = false;
|
||||||
|
|
||||||
|
//remove from map
|
||||||
|
lock (url)
|
||||||
|
{
|
||||||
|
url.requests.Remove(requestID);
|
||||||
|
m_RequestMap.Remove(requestID);
|
||||||
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool HasEvents(UUID requestID, UUID sessionID)
|
||||||
|
{
|
||||||
|
UrlData url=null;
|
||||||
|
|
||||||
|
lock (m_RequestMap)
|
||||||
|
{
|
||||||
|
if (!m_RequestMap.ContainsKey(requestID))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
url = m_RequestMap[requestID];
|
||||||
|
if (!url.requests.ContainsKey(requestID))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (System.Environment.TickCount-url.requests[requestID].startTime>25000)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url.requests[requestID].requestDone)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
private Hashtable GetEvents(UUID requestID, UUID sessionID, string request)
|
||||||
|
{
|
||||||
|
UrlData url = null;
|
||||||
|
RequestData requestData = null;
|
||||||
|
|
||||||
|
lock (m_RequestMap)
|
||||||
|
{
|
||||||
|
if (!m_RequestMap.ContainsKey(requestID))
|
||||||
|
return NoEvents(requestID,sessionID);
|
||||||
|
url = m_RequestMap[requestID];
|
||||||
|
requestData = url.requests[requestID];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!requestData.requestDone)
|
||||||
|
return NoEvents(requestID,sessionID);
|
||||||
|
|
||||||
|
Hashtable response = new Hashtable();
|
||||||
|
|
||||||
|
if (System.Environment.TickCount - requestData.startTime > 25000)
|
||||||
|
{
|
||||||
|
response["int_response_code"] = 500;
|
||||||
|
response["str_response_string"] = "Script timeout";
|
||||||
|
response["content_type"] = "text/plain";
|
||||||
|
response["keepalive"] = false;
|
||||||
|
response["reusecontext"] = false;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
//put response
|
||||||
|
response["int_response_code"] = requestData.responseCode;
|
||||||
|
response["str_response_string"] = requestData.responseBody;
|
||||||
|
response["content_type"] = "text/plain";
|
||||||
|
response["keepalive"] = false;
|
||||||
|
response["reusecontext"] = false;
|
||||||
|
|
||||||
|
//remove from map
|
||||||
|
lock (url)
|
||||||
|
{
|
||||||
|
url.requests.Remove(requestID);
|
||||||
|
m_RequestMap.Remove(requestID);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
public void HttpRequestHandler(UUID requestID, Hashtable request)
|
||||||
|
{
|
||||||
|
lock (request)
|
||||||
|
{
|
||||||
|
string uri = request["uri"].ToString();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Hashtable headers = (Hashtable)request["headers"];
|
||||||
|
|
||||||
|
string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/";
|
||||||
|
|
||||||
|
int pos1 = uri.IndexOf("/");// /lslhttp
|
||||||
|
int pos2 = uri.IndexOf("/", pos1 + 1);// /lslhttp/
|
||||||
|
int pos3 = uri.IndexOf("/", pos2 + 1);// /lslhttp/<UUID>/
|
||||||
|
string uri_tmp = uri.Substring(0, pos3 + 1);
|
||||||
|
//HTTP server code doesn't provide us with QueryStrings
|
||||||
|
string pathInfo;
|
||||||
|
string queryString;
|
||||||
|
queryString = "";
|
||||||
|
|
||||||
|
pathInfo = uri.Substring(pos3);
|
||||||
|
|
||||||
|
UrlData url = m_UrlMap["http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp];
|
||||||
|
|
||||||
|
//for llGetHttpHeader support we need to store original URI here
|
||||||
|
//to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
|
||||||
|
//as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader
|
||||||
|
|
||||||
|
RequestData requestData = new RequestData();
|
||||||
|
requestData.requestID = requestID;
|
||||||
|
requestData.requestDone = false;
|
||||||
|
requestData.startTime = System.Environment.TickCount;
|
||||||
|
requestData.uri = uri;
|
||||||
|
if (requestData.headers == null)
|
||||||
|
requestData.headers = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
foreach (DictionaryEntry header in headers)
|
||||||
|
{
|
||||||
|
string key = (string)header.Key;
|
||||||
|
string value = (string)header.Value;
|
||||||
|
requestData.headers.Add(key, value);
|
||||||
|
}
|
||||||
|
foreach (DictionaryEntry de in request)
|
||||||
|
{
|
||||||
|
if (de.Key.ToString() == "querystringkeys")
|
||||||
|
{
|
||||||
|
System.String[] keys = (System.String[])de.Value;
|
||||||
|
foreach (String key in keys)
|
||||||
|
{
|
||||||
|
if (request.ContainsKey(key))
|
||||||
|
{
|
||||||
|
string val = (String)request[key];
|
||||||
|
queryString = queryString + key + "=" + val + "&";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (queryString.Length > 1)
|
||||||
|
queryString = queryString.Substring(0, queryString.Length - 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//if this machine is behind DNAT/port forwarding, currently this is being
|
||||||
|
//set to address of port forwarding router
|
||||||
|
requestData.headers["x-remote-ip"] = requestData.headers["remote_addr"];
|
||||||
|
requestData.headers["x-path-info"] = pathInfo;
|
||||||
|
requestData.headers["x-query-string"] = queryString;
|
||||||
|
requestData.headers["x-script-url"] = url.url;
|
||||||
|
|
||||||
|
requestData.ev = new ManualResetEvent(false);
|
||||||
|
lock (url.requests)
|
||||||
|
{
|
||||||
|
url.requests.Add(requestID, requestData);
|
||||||
|
}
|
||||||
|
lock (m_RequestMap)
|
||||||
|
{
|
||||||
|
//add to request map
|
||||||
|
m_RequestMap.Add(requestID, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() });
|
||||||
|
|
||||||
|
//send initial response?
|
||||||
|
Hashtable response = new Hashtable();
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception we)
|
||||||
|
{
|
||||||
|
//Hashtable response = new Hashtable();
|
||||||
|
m_log.Warn("[HttpRequestHandler]: http-in request failed");
|
||||||
|
m_log.Warn(we.Message);
|
||||||
|
m_log.Warn(we.StackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnScriptReset(uint localID, UUID itemID)
|
private void OnScriptReset(uint localID, UUID itemID)
|
||||||
{
|
{
|
||||||
ScriptRemoved(itemID);
|
ScriptRemoved(itemID);
|
||||||
|
|
|
@ -7838,7 +7838,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
|
public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
|
||||||
{
|
{
|
||||||
m_host.AddScriptLPS(1);
|
m_host.AddScriptLPS(1);
|
||||||
NotImplemented("llGetHTTPHeader");
|
|
||||||
|
if (m_UrlModule != null)
|
||||||
|
return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9117,13 +9119,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void llHTTPResponse(string url, int status, string body)
|
public void llHTTPResponse(LSL_Key id, int status, string body)
|
||||||
{
|
{
|
||||||
// Partial implementation: support for parameter flags needed
|
// Partial implementation: support for parameter flags needed
|
||||||
// see http://wiki.secondlife.com/wiki/llHTTPResponse
|
// see http://wiki.secondlife.com/wiki/llHTTPResponse
|
||||||
|
|
||||||
m_host.AddScriptLPS(1);
|
m_host.AddScriptLPS(1);
|
||||||
NotImplemented("llHTTPResponse");
|
|
||||||
|
if (m_UrlModule != null)
|
||||||
|
m_UrlModule.HttpResponse(new UUID(id), status,body);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void llResetLandBanList()
|
public void llResetLandBanList()
|
||||||
|
|
|
@ -201,7 +201,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
||||||
void llGroundRepel(double height, int water, double tau);
|
void llGroundRepel(double height, int water, double tau);
|
||||||
LSL_Vector llGroundSlope(LSL_Vector offset);
|
LSL_Vector llGroundSlope(LSL_Vector offset);
|
||||||
LSL_String llHTTPRequest(string url, LSL_List parameters, string body);
|
LSL_String llHTTPRequest(string url, LSL_List parameters, string body);
|
||||||
void llHTTPResponse(string url, int status, string body);
|
void llHTTPResponse(LSL_Key id, int status, string body);
|
||||||
LSL_String llInsertString(string dst, int position, string src);
|
LSL_String llInsertString(string dst, int position, string src);
|
||||||
void llInstantMessage(string user, string message);
|
void llInstantMessage(string user, string message);
|
||||||
LSL_String llIntegerToBase64(int number);
|
LSL_String llIntegerToBase64(int number);
|
||||||
|
|
|
@ -864,9 +864,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||||
return m_LSL_Functions.llHTTPRequest(url, parameters, body);
|
return m_LSL_Functions.llHTTPRequest(url, parameters, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void llHTTPResponse(string url, int status, string body)
|
public void llHTTPResponse(LSL_Key id, int status, string body)
|
||||||
{
|
{
|
||||||
m_LSL_Functions.llHTTPResponse(url, status, body);
|
m_LSL_Functions.llHTTPResponse(id, status, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LSL_String llInsertString(string dst, int position, string src)
|
public LSL_String llInsertString(string dst, int position, string src)
|
||||||
|
|
|
@ -305,6 +305,10 @@
|
||||||
http_listener_sslport = 9001 ; Use this port for SSL connections
|
http_listener_sslport = 9001 ; Use this port for SSL connections
|
||||||
http_listener_ssl_cert = "" ; Currently unused, but will be used for OSHttpServer
|
http_listener_ssl_cert = "" ; Currently unused, but will be used for OSHttpServer
|
||||||
|
|
||||||
|
; Hostname to use in llRequestURL/llRequestSecureURL
|
||||||
|
; if not defined - default machine name is being used
|
||||||
|
; (on Windows this mean NETBIOS name - useably only inside local network)
|
||||||
|
; ExternalHostNameForLSL=127.0.0.1
|
||||||
; Uncomment below to enable llRemoteData/remote channels
|
; Uncomment below to enable llRemoteData/remote channels
|
||||||
; remoteDataPort = 20800
|
; remoteDataPort = 20800
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue