* Started on converting UserHTTPServer to BaseHttpServer

* Added a 'param' param to the RestMethod
* Added RestHandlerEntry to store more info about the 'rest' handler
0.1-prestable
lbsa71 2007-04-11 14:14:19 +00:00
parent 348b765aed
commit 08d5d10d62
10 changed files with 178 additions and 172 deletions

View File

@ -49,6 +49,11 @@ namespace OpenGridServices.GridServer
public HttpListener Listener; public HttpListener Listener;
public GridHTTPServer() : base( 8001 ) { public GridHTTPServer() : base( 8001 ) {
Start();
}
public void Start()
{
MainConsole.Instance.WriteLine("Starting up HTTP Server"); MainConsole.Instance.WriteLine("Starting up HTTP Server");
HTTPD = new Thread(new ThreadStart(StartHTTP)); HTTPD = new Thread(new ThreadStart(StartHTTP));
HTTPD.Start(); HTTPD.Start();

View File

@ -105,6 +105,7 @@ namespace OpenGridServices.GridServer
m_console.WriteLine("Main.cs:Startup() - Starting HTTP process"); m_console.WriteLine("Main.cs:Startup() - Starting HTTP process");
_httpd = new GridHTTPServer(); _httpd = new GridHTTPServer();
_httpd.Start();
m_console.WriteLine("Main.cs:Startup() - Starting sim status checker"); m_console.WriteLine("Main.cs:Startup() - Starting sim status checker");
SimCheckTimer = new Timer(); SimCheckTimer = new Timer();

View File

@ -97,6 +97,12 @@ namespace OpenGridServices.UserServer
MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process"); MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting HTTP process");
_httpd = new UserHTTPServer(); _httpd = new UserHTTPServer();
_httpd.AddXmlRPCHandler("login_to_simulator", _profilemanager.XmlRpcLoginMethod);
_httpd.AddRestHandler( "DELETE", "/usersessions/", _profilemanager.RestDeleteUserSessionMethod );
_httpd.Start();
} }

View File

@ -51,6 +51,10 @@ namespace OpenGridServices.UserServer
public HttpListener Listener; public HttpListener Listener;
public UserHTTPServer() : base( 8002 ) public UserHTTPServer() : base( 8002 )
{
}
public void Start()
{ {
MainConsole.Instance.WriteLine("Starting up HTTP Server"); MainConsole.Instance.WriteLine("Starting up HTTP Server");
HTTPD = new Thread(new ThreadStart(StartHTTP)); HTTPD = new Thread(new ThreadStart(StartHTTP));
@ -89,21 +93,13 @@ namespace OpenGridServices.UserServer
switch (req_type) switch (req_type)
{ {
case "usersessions": case "usersessions":
LLUUID sessionid = new LLUUID(rest_params[2]); // get usersessions/sessionid string param = rest_params[2];
string result = "";
if (www_req.HttpMethod == "DELETE") if (www_req.HttpMethod == "DELETE")
{ {
foreach (libsecondlife.LLUUID UUID in OpenUser_Main.userserver._profilemanager.UserProfiles.Keys) result = OpenUser_Main.userserver._profilemanager.RestDeleteUserSessionMethod( null, null, param );
{
if (OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].CurrentSessionID == sessionid)
{
OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].CurrentSessionID = null;
OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].CurrentSecureSessionID = null;
OpenUser_Main.userserver._profilemanager.UserProfiles[UUID].Circuits.Clear();
} }
} return result;
}
return "OK";
} }
return ""; return "";

View File

@ -48,6 +48,22 @@ namespace OpenSim.Framework.User
return ""; return "";
} }
public string RestDeleteUserSessionMethod( string request, string path, string param )
{
LLUUID sessionid = new LLUUID(param); // get usersessions/sessionid
foreach (libsecondlife.LLUUID UUID in UserProfiles.Keys)
{
if ( UserProfiles[UUID].CurrentSessionID == sessionid)
{
UserProfiles[UUID].CurrentSessionID = null;
UserProfiles[UUID].CurrentSecureSessionID = null;
UserProfiles[UUID].Circuits.Clear();
}
}
return "OK";
}
public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
{ {
XmlRpcResponse response = new XmlRpcResponse(); XmlRpcResponse response = new XmlRpcResponse();

View File

@ -48,7 +48,7 @@ namespace OpenSim.CAPS
server.AddRestHandler("POST", "/Admin/Login", PostLogin ); server.AddRestHandler("POST", "/Admin/Login", PostLogin );
} }
private string GetWelcomePage(string request, string path) private string GetWelcomePage(string request, string path, string param)
{ {
string responseString; string responseString;
responseString = "Welcome to the OpenSim Admin Page"; responseString = "Welcome to the OpenSim Admin Page";
@ -56,7 +56,7 @@ namespace OpenSim.CAPS
return responseString; return responseString;
} }
private string PostLogin(string requestBody, string path) private string PostLogin(string requestBody, string path, string param)
{ {
string responseString; string responseString;
// Console.WriteLine(requestBody); // Console.WriteLine(requestBody);
@ -73,7 +73,7 @@ namespace OpenSim.CAPS
return responseString; return responseString;
} }
private string PostNewAccount(string requestBody, string path) private string PostNewAccount(string requestBody, string path, string param)
{ {
string responseString; string responseString;
string firstName = ""; string firstName = "";
@ -122,7 +122,7 @@ namespace OpenSim.CAPS
return responseString; return responseString;
} }
private string GetConnectedClientsPage(string request, string path) private string GetConnectedClientsPage(string request, string path, string param)
{ {
string responseString; string responseString;
responseString = " <p> Listing connected Clients </p>"; responseString = " <p> Listing connected Clients </p>";
@ -140,7 +140,7 @@ namespace OpenSim.CAPS
return responseString; return responseString;
} }
private string AddTestScript(string request, string path) private string AddTestScript(string request, string path, string param)
{ {
int index = path.LastIndexOf('/'); int index = path.LastIndexOf('/');
@ -160,12 +160,12 @@ namespace OpenSim.CAPS
} }
} }
private string GetScriptsPage(string request, string path) private string GetScriptsPage(string request, string path, string param)
{ {
return String.Empty; return String.Empty;
} }
private string GetEntitiesPage(string request, string path) private string GetEntitiesPage(string request, string path, string param)
{ {
string responseString; string responseString;
responseString = " <p> Listing current entities</p><ul>"; responseString = " <p> Listing current entities</p><ul>";
@ -179,7 +179,7 @@ namespace OpenSim.CAPS
return responseString; return responseString;
} }
private string GetClientsInventory(string request, string path) private string GetClientsInventory(string request, string path, string param)
{ {
string[] line; string[] line;
string delimStr = "/"; string delimStr = "/";
@ -208,12 +208,12 @@ namespace OpenSim.CAPS
return responseString; return responseString;
} }
private string GetCachedAssets(string request, string path) private string GetCachedAssets(string request, string path, string param)
{ {
return ""; return "";
} }
private string GetAccountsPage(string request, string path) private string GetAccountsPage(string request, string path, string param)
{ {
string responseString; string responseString;
responseString = "<p> Account management </p>"; responseString = "<p> Account management </p>";
@ -223,7 +223,7 @@ namespace OpenSim.CAPS
return responseString; return responseString;
} }
private string GetAdminPage(string request, string path) private string GetAdminPage(string request, string path, string param)
{ {
return AdminPage; return AdminPage;
} }

View File

@ -197,7 +197,7 @@ namespace OpenSim
return new XmlRpcResponse(); return new XmlRpcResponse();
}); });
_httpServer.AddRestHandler("GET", "/simstatus/", _httpServer.AddRestHandler("GET", "/simstatus/",
delegate(string request, string path) delegate(string request, string path, string param )
{ {
return "OK"; return "OK";
}); });

View File

@ -12,9 +12,30 @@ namespace OpenSim.Servers
{ {
public class BaseHttpServer public class BaseHttpServer
{ {
protected class RestMethodEntry
{
private string m_path;
public string Path
{
get { return m_path; }
}
private RestMethod m_restMethod;
public RestMethod RestMethod
{
get { return m_restMethod; }
}
public RestMethodEntry( string path, RestMethod restMethod )
{
m_path = path;
m_restMethod = restMethod;
}
}
protected Thread m_workerThread; protected Thread m_workerThread;
protected HttpListener m_httpListener; protected HttpListener m_httpListener;
protected Dictionary<string, RestMethod> m_restHandlers = new Dictionary<string, RestMethod>(); protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>();
protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>();
protected int m_port; protected int m_port;
@ -29,7 +50,7 @@ namespace OpenSim.Servers
if (!this.m_restHandlers.ContainsKey(methodKey)) if (!this.m_restHandlers.ContainsKey(methodKey))
{ {
this.m_restHandlers.Add(methodKey, handler); this.m_restHandlers.Add(methodKey, new RestMethodEntry( path, handler ));
return true; return true;
} }
@ -74,7 +95,6 @@ namespace OpenSim.Servers
protected virtual string ParseREST(string request, string path, string method) protected virtual string ParseREST(string request, string path, string method)
{ {
string response; string response;
RestMethod handler;
string requestKey = String.Format("{0}: {1}", method, path); string requestKey = String.Format("{0}: {1}", method, path);
@ -90,9 +110,13 @@ namespace OpenSim.Servers
} }
} }
if (m_restHandlers.TryGetValue(bestMatch, out handler)) RestMethodEntry restMethodEntry;
if (m_restHandlers.TryGetValue(bestMatch, out restMethodEntry))
{ {
response = handler(request, path); RestMethod restMethod = restMethodEntry.RestMethod;
string param = path.Substring( restMethodEntry.Path.Length );
response = restMethod(request, path, param);
} }
else else

View File

@ -4,5 +4,5 @@ using System.Text;
namespace OpenSim.Servers namespace OpenSim.Servers
{ {
public delegate string RestMethod( string request, string path ); public delegate string RestMethod( string request, string path, string param );
} }

View File

@ -47,48 +47,6 @@ Global
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectDependencies) = postSolution
({632E1BFD-0000-0000-0000-000000000000}).5 = ({2270B8FE-0000-0000-0000-000000000000})
({632E1BFD-0000-0000-0000-000000000000}).6 = ({8ACA2445-0000-0000-0000-000000000000})
({632E1BFD-0000-0000-0000-000000000000}).7 = ({A7CD0630-0000-0000-0000-000000000000})
({632E1BFD-0000-0000-0000-000000000000}).8 = ({E88EF749-0000-0000-0000-000000000000})
({632E1BFD-0000-0000-0000-000000000000}).9 = ({8BE16150-0000-0000-0000-000000000000})
({632E1BFD-0000-0000-0000-000000000000}).10 = ({8BB20F0A-0000-0000-0000-000000000000})
({63A05FE9-0000-0000-0000-000000000000}).2 = ({8BE16150-0000-0000-0000-000000000000})
({EE9E5D96-0000-0000-0000-000000000000}).6 = ({8ACA2445-0000-0000-0000-000000000000})
({EE9E5D96-0000-0000-0000-000000000000}).7 = ({A7CD0630-0000-0000-0000-000000000000})
({438A9556-0000-0000-0000-000000000000}).5 = ({8ACA2445-0000-0000-0000-000000000000})
({438A9556-0000-0000-0000-000000000000}).6 = ({A7CD0630-0000-0000-0000-000000000000})
({438A9556-0000-0000-0000-000000000000}).7 = ({8BE16150-0000-0000-0000-000000000000})
({438A9556-0000-0000-0000-000000000000}).8 = ({8BB20F0A-0000-0000-0000-000000000000})
({438A9556-0000-0000-0000-000000000000}).9 = ({632E1BFD-0000-0000-0000-000000000000})
({E88EF749-0000-0000-0000-000000000000}).2 = ({8ACA2445-0000-0000-0000-000000000000})
({8BE16150-0000-0000-0000-000000000000}).3 = ({8ACA2445-0000-0000-0000-000000000000})
({8BE16150-0000-0000-0000-000000000000}).4 = ({A7CD0630-0000-0000-0000-000000000000})
({97A82740-0000-0000-0000-000000000000}).2 = ({8ACA2445-0000-0000-0000-000000000000})
({66591469-0000-0000-0000-000000000000}).3 = ({8ACA2445-0000-0000-0000-000000000000})
({66591469-0000-0000-0000-000000000000}).4 = ({A7CD0630-0000-0000-0000-000000000000})
({66591469-0000-0000-0000-000000000000}).5 = ({8BB20F0A-0000-0000-0000-000000000000})
({4F874463-0000-0000-0000-000000000000}).2 = ({8BE16150-0000-0000-0000-000000000000})
({B0027747-0000-0000-0000-000000000000}).5 = ({8ACA2445-0000-0000-0000-000000000000})
({B0027747-0000-0000-0000-000000000000}).6 = ({A7CD0630-0000-0000-0000-000000000000})
({988F0AC4-0000-0000-0000-000000000000}).3 = ({8BE16150-0000-0000-0000-000000000000})
({B55C0B5D-0000-0000-0000-000000000000}).3 = ({8ACA2445-0000-0000-0000-000000000000})
({B55C0B5D-0000-0000-0000-000000000000}).4 = ({A7CD0630-0000-0000-0000-000000000000})
({8BB20F0A-0000-0000-0000-000000000000}).2 = ({8ACA2445-0000-0000-0000-000000000000})
({8BB20F0A-0000-0000-0000-000000000000}).3 = ({A7CD0630-0000-0000-0000-000000000000})
({E1B79ECF-0000-0000-0000-000000000000}).4 = ({8ACA2445-0000-0000-0000-000000000000})
({E1B79ECF-0000-0000-0000-000000000000}).5 = ({A7CD0630-0000-0000-0000-000000000000})
({6B20B603-0000-0000-0000-000000000000}).5 = ({8ACA2445-0000-0000-0000-000000000000})
({6B20B603-0000-0000-0000-000000000000}).6 = ({A7CD0630-0000-0000-0000-000000000000})
({7E494328-0000-0000-0000-000000000000}).5 = ({8ACA2445-0000-0000-0000-000000000000})
({7E494328-0000-0000-0000-000000000000}).6 = ({A7CD0630-0000-0000-0000-000000000000})
({546099CD-0000-0000-0000-000000000000}).4 = ({8ACA2445-0000-0000-0000-000000000000})
({546099CD-0000-0000-0000-000000000000}).5 = ({A7CD0630-0000-0000-0000-000000000000})
({21BFC8E2-0000-0000-0000-000000000000}).3 = ({8ACA2445-0000-0000-0000-000000000000})
({21BFC8E2-0000-0000-0000-000000000000}).4 = ({A7CD0630-0000-0000-0000-000000000000})
({21BFC8E2-0000-0000-0000-000000000000}).5 = ({8BB20F0A-0000-0000-0000-000000000000})
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2270B8FE-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2270B8FE-0000-0000-0000-000000000000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2270B8FE-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU {2270B8FE-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU