Add most of the meat to the LSL HTTP server

0.6.5-rc1
Melanie Thielker 2009-05-13 04:04:26 +00:00
parent ba8850f254
commit 1196f3eac7
3 changed files with 133 additions and 12 deletions

View File

@ -26,11 +26,14 @@
*/ */
using System; using System;
using System.Threading;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections;
using System.Reflection; using System.Reflection;
using log4net; using log4net;
using Nini.Config; using Nini.Config;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
@ -40,17 +43,18 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
{ {
public UUID hostID; public UUID hostID;
public UUID itemID; public UUID itemID;
Scene scene; public IScriptModule engine;
IScriptModule engine; public string url;
string url; public UUID urlcode;
Dictionary<UUID, RequestData> requests; public Dictionary<UUID, RequestData> requests;
} }
public class RequestData public class RequestData
{ {
UUID requestID; public UUID requestID;
Dictionary<string, string> headers; public Dictionary<string, string> headers;
string body; public string body;
public ManualResetEvent ev;
} }
public class UrlModule : ISharedRegionModule, IUrlModule public class UrlModule : ISharedRegionModule, IUrlModule
@ -61,7 +65,9 @@ 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 = 0; private int m_TotalUrls = 100;
private IHttpServer m_HttpServer = null;
public string Name public string Name
{ {
@ -78,6 +84,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
public void AddRegion(Scene scene) public void AddRegion(Scene scene)
{ {
if (m_HttpServer == null)
{
// There can only be one
//
m_HttpServer = scene.CommsManager.HttpServer;
}
} }
public void RegionLoaded(Scene scene) public void RegionLoaded(Scene scene)
@ -94,16 +106,59 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID) public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
{ {
return UUID.Zero; UUID urlcode = UUID.Random();
lock (m_UrlMap)
{
if (m_UrlMap.Count >= m_TotalUrls)
{
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
return urlcode;
}
string url = "http://"+System.Environment.MachineName+"/"+urlcode.ToString();
UrlData urlData = new UrlData();
urlData.hostID = host.UUID;
urlData.itemID = itemID;
urlData.engine = engine;
urlData.url = url;
urlData.urlcode = urlcode;
urlData.requests = new Dictionary<UUID, RequestData>();
m_UrlMap[url] = urlData;
m_HttpServer.AddHTTPHandler("/lslhttp/"+urlcode.ToString(), HttpRequestHandler);
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
}
return urlcode;
} }
public UUID RequestSecureURL(IScriptModule engine, SceneObjectPart host, UUID itemID) public UUID RequestSecureURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
{ {
return UUID.Zero; UUID urlcode = UUID.Random();
engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
return urlcode;
} }
public void ReleaseURL(string url) public void ReleaseURL(string url)
{ {
lock (m_UrlMap)
{
UrlData data;
if (!m_UrlMap.TryGetValue(url, out data))
return;
foreach (UUID req in data.requests.Keys)
m_RequestMap.Remove(req);
RemoveUrl(data);
m_UrlMap.Remove(url);
}
} }
public void HttpResponse(UUID request, int status, string body) public void HttpResponse(UUID request, int status, string body)
@ -117,7 +172,64 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
public int GetFreeUrls() public int GetFreeUrls()
{ {
return 0; return m_TotalUrls - m_UrlMap.Count;
}
public void ScriptRemoved(UUID itemID)
{
lock(m_UrlMap)
{
List<string> removeURLs = new List<string>();
foreach(KeyValuePair<string, UrlData> url in m_UrlMap)
{
if (url.Value.itemID == itemID)
{
RemoveUrl(url.Value);
removeURLs.Add(url.Key);
foreach (UUID req in url.Value.requests.Keys)
m_RequestMap.Remove(req);
}
}
foreach (string urlname in removeURLs)
m_UrlMap.Remove(urlname);
}
}
public void ObjectRemoved(UUID objectID)
{
lock(m_UrlMap)
{
List<string> removeURLs = new List<string>();
foreach(KeyValuePair<string, UrlData> url in m_UrlMap)
{
if (url.Value.hostID == objectID)
{
RemoveUrl(url.Value);
removeURLs.Add(url.Key);
foreach (UUID req in url.Value.requests.Keys)
m_RequestMap.Remove(req);
}
}
foreach (string urlname in removeURLs)
m_UrlMap.Remove(urlname);
}
}
private void RemoveUrl(UrlData data)
{
m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString());
}
private Hashtable HttpRequestHandler(Hashtable request)
{
Hashtable response = new Hashtable();
response["int_response_code"] = 404;
return response;
} }
} }
} }

View File

@ -40,5 +40,8 @@ namespace OpenSim.Region.Framework.Interfaces
void HttpResponse(UUID request, int status, string body); void HttpResponse(UUID request, int status, string body);
string GetHttpHeader(UUID request, string header); string GetHttpHeader(UUID request, string header);
int GetFreeUrls(); int GetFreeUrls();
void ScriptRemoved(UUID itemID);
void ObjectRemoved(UUID objectID);
} }
} }

View File

@ -109,6 +109,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_TransferModule = m_TransferModule =
m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
if (m_UrlModule != null)
{
m_ScriptEngine.OnScriptRemoved += m_UrlModule.ScriptRemoved;
m_ScriptEngine.OnObjectRemoved += m_UrlModule.ObjectRemoved;
}
AsyncCommands = new AsyncCommandManager(ScriptEngine); AsyncCommands = new AsyncCommandManager(ScriptEngine);
} }
@ -5616,7 +5621,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Integer llGetFreeURLs() public LSL_Integer llGetFreeURLs()
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
NotImplemented("llGetFreeURLs"); if (m_UrlModule != null)
return new LSL_Integer(m_UrlModule.GetFreeUrls());
return new LSL_Integer(0); return new LSL_Integer(0);
} }