* Add documentation to BaseHttpServer.AddHTTPHandler()

0.6.5-rc1
Justin Clarke Casey 2009-03-19 16:41:23 +00:00
parent 0867302e09
commit eb0c369409
2 changed files with 47 additions and 25 deletions

View File

@ -168,13 +168,41 @@ namespace OpenSim.Framework.Servers
}
}
public bool AddHTTPHandler(string method, GenericHTTPMethod handler)
/// <summary>
/// Add a handler for an HTTP request
/// </summary>
///
/// This handler can actually be invoked either as
///
/// http://<hostname>:<port>/?method=<methodName>
///
/// or
///
/// http://<hostname>:<port><method>
///
/// if the method starts with a slash. For example, AddHTTPHandler("/object/", ...) on a standalone region
/// server will register a handler that can be invoked with either
///
/// http://localhost:9000/?method=/object/
///
/// or
///
/// http://localhost:9000/object/
///
/// <param name="methodName"></param>
/// <param name="handler"></param>
/// <returns>
/// true if the handler was successfully registered, false if a handler with the same name already existed.
/// </returns>
public bool AddHTTPHandler(string methodName, GenericHTTPMethod handler)
{
//m_log.DebugFormat("[BASE HTTP SERVER]: Registering {0}", methodName);
lock (m_HTTPHandlers)
{
if (!m_HTTPHandlers.ContainsKey(method))
if (!m_HTTPHandlers.ContainsKey(methodName))
{
m_HTTPHandlers.Add(method, handler);
m_HTTPHandlers.Add(methodName, handler);
return true;
}
}
@ -517,6 +545,8 @@ namespace OpenSim.Framework.Servers
private bool TryGetHTTPHandler(string handlerKey, out GenericHTTPMethod HTTPHandler)
{
//m_log.DebugFormat("[BASE HTTP HANDLER]: Looking for HTTP handler for {0}", handlerKey);
string bestMatch = null;
foreach (string pattern in m_HTTPHandlers.Keys)
@ -878,7 +908,6 @@ namespace OpenSim.Framework.Servers
/// <returns>true if we have one, false if not</returns>
private bool DoWeHaveAHTTPHandler(string path)
{
string[] pathbase = path.Split('/');
string searchquery = "/";
@ -894,14 +923,13 @@ namespace OpenSim.Framework.Servers
string bestMatch = null;
//m_log.DebugFormat("[BASE HTTP HANDLER]: Checking if we have an HTTP handler for {0}", searchquery);
foreach (string pattern in m_HTTPHandlers.Keys)
{
if (searchquery.StartsWith(pattern) && searchquery.Length >= pattern.Length)
{
bestMatch = pattern;
}
}
@ -911,12 +939,10 @@ namespace OpenSim.Framework.Servers
if (String.IsNullOrEmpty(bestMatch))
{
return false;
}
else
{
return true;
}
}
@ -1024,7 +1050,8 @@ namespace OpenSim.Framework.Servers
catch (SocketException f)
{
// This has to be here to prevent a Linux/Mono crash
m_log.WarnFormat("[BASE HTTP SERVER] XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", f);
m_log.WarnFormat(
"[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", f);
}
}
catch(Exception)
@ -1184,6 +1211,9 @@ namespace OpenSim.Framework.Servers
string bestMatch = null;
// m_log.DebugFormat(
// "[BASE HTTP HANDLER]: TryGetHTTPHandlerPathBased() looking for HTTP handler to match {0}", searchquery);
foreach (string pattern in m_HTTPHandlers.Keys)
{
if (searchquery.ToLower().StartsWith(pattern.ToLower()))
@ -1196,9 +1226,7 @@ namespace OpenSim.Framework.Servers
bestMatch = pattern;
}
}
}
}
if (String.IsNullOrEmpty(bestMatch))
{

View File

@ -69,21 +69,19 @@ namespace OpenSim.Region.UserStatistics
private string m_loglines = String.Empty;
private volatile int lastHit = 12000;
public virtual void Initialise(Scene scene, IConfigSource config)
{
IConfig cnfg;
try
{
cnfg = config.Configs["WebStats"];
enabled = cnfg.GetBoolean("enabled", false);
enabled = cnfg.GetBoolean("enabled", false);
}
catch (Exception)
{
enabled = false;
}
if (!enabled)
{
return;
@ -130,14 +128,12 @@ namespace OpenSim.Region.UserStatistics
scene.CommsManager.HttpServer.AddHTTPHandler("/SStats/", HandleStatsRequest);
scene.CommsManager.HttpServer.AddHTTPHandler("/CAPS/VS/", HandleUnknownCAPSRequest);
}
m_scene.Add(scene);
m_simstatsCounters.Add(scene.RegionInfo.RegionID, new USimStatsData(scene.RegionInfo.RegionID));
scene.StatsReporter.OnSendStatsResult += ReceiveClassicSimStatsPacket;
}
}
}
public void ReceiveClassicSimStatsPacket(SimStats stats)
@ -168,10 +164,10 @@ namespace OpenSim.Region.UserStatistics
}
}
catch (KeyNotFoundException)
{
{
}
}
public Hashtable HandleUnknownCAPSRequest(Hashtable request)
{
//string regpath = request["uri"].ToString();
@ -247,9 +243,7 @@ namespace OpenSim.Region.UserStatistics
return responsedata;
}
public void CheckAndUpdateDatabase(SqliteConnection db)
{
lock (db)