Beginning of refactoring RESTComms/LocalComms in the new style of services and connectors. This commit has the beginning of the In connector, not the Out. Nothing of this is finished yet, and it doesn't run. But it should compile ok.

This commit is contained in:
diva
2009-05-25 20:30:24 +00:00
parent 582c20b1c4
commit cb704ecde1
7 changed files with 486 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections;
using System.Net;
using OpenSim.Framework;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Services.Interfaces;
using OpenMetaverse;
namespace OpenSim.Server.Handlers.Simulation
{
public class Utils
{
/// <summary>
/// Extract the param from an uri.
/// </summary>
/// <param name="uri">Something like this: /uuid/ or /uuid/handle/release</param>
/// <param name="uri">uuid on uuid field</param>
/// <param name="action">optional action</param>
public static bool GetParams(string path, out UUID uuid, out ulong regionHandle, out string action)
{
uuid = UUID.Zero;
action = "";
regionHandle = 0;
path = path.Trim(new char[] { '/' });
string[] parts = path.Split('/');
if (parts.Length <= 1)
{
return false;
}
else
{
if (!UUID.TryParse(parts[0], out uuid))
return false;
if (parts.Length >= 2)
UInt64.TryParse(parts[1], out regionHandle);
if (parts.Length >= 3)
action = parts[2];
return true;
}
}
public static bool GetAuthentication(OSHttpRequest httpRequest, out string authority, out string authKey)
{
authority = string.Empty;
authKey = string.Empty;
Uri authUri;
string auth = httpRequest.Headers["authentication"];
// Authentication keys look like this:
// http://orgrid.org:8002/<uuid>
if ((auth != null) && (!string.Empty.Equals(auth)) && auth != "None")
{
if (Uri.TryCreate(auth, UriKind.Absolute, out authUri))
{
authority = authUri.Authority;
authKey = authUri.PathAndQuery.Trim('/');
return true;
}
}
return false;
}
}
}