View of /trunk/GridServer/Extensions/RegionFrontend.cs
Parent Directory
|
Revision Log
Revision 73 -
(download)
(annotate)
Thu Feb 5 08:12:58 2009 UTC (4 years, 3 months ago) by jhurliman
File size: 6208 byte(s)
Thu Feb 5 08:12:58 2009 UTC (4 years, 3 months ago) by jhurliman
File size: 6208 byte(s)
* Added web OpenID auth path back in * Added the AuthorizeWhitelist extension to whitelist access based on OpenID identities * Continued work on the GridServer
/*
* Copyright (c) 2008 Intel Corporation
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* -- Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* -- Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* -- Neither the name of the Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using ExtensionLoader;
using HttpServer;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
namespace GridServer.Extensions
{
public class RegionFrontend : IExtension<GridServer>
{
GridServer server;
public RegionFrontend()
{
}
public void Start(GridServer server)
{
this.server = server;
server.HttpServer.AddHandler("PUT", null, @"^/region/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", RegionAddHandler);
server.HttpServer.AddHandler("GET", null, @"^/region/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", RegionInfoHandler);
server.HttpServer.AddHandler("DELETE", null, @"^/region/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", RegionDeleteHandler);
server.HttpServer.AddHandler("POST", null, @"^/region/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", RegionUpdateHandler);
server.HttpServer.AddHandler("HEAD", null, @"^/region/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", RegionHeartbeatHandler);
}
public void Stop()
{
}
bool RegionAddHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{
return true;
}
bool RegionInfoHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{
string path = request.Uri.PathAndQuery;
UUID regionID;
if (UUID.TryParse(path.Substring(path.Length - 36), out regionID))
{
UUID authToken = Utils.GetAuthToken(request);
if (server.AuthorizationProvider.IsRegionAuthorized(authToken, regionID))
{
Region region;
BackendResponse backendResponse = server.GridProvider.TryFetchRegion(regionID, out region);
if (backendResponse == BackendResponse.Success)
{
//response.ContentLength = data.Length;
//response.Body.Write(data, 0, data.Length);
}
else if (backendResponse == BackendResponse.NotFound)
{
response.Status = HttpStatusCode.NotFound;
}
else
{
response.Status = HttpStatusCode.InternalServerError;
}
}
else
{
response.Status = HttpStatusCode.Forbidden;
}
}
else
{
response.Status = HttpStatusCode.NotFound;
}
return true;
}
bool RegionDeleteHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{
string path = request.Uri.PathAndQuery;
UUID regionID;
if (UUID.TryParse(path.Substring(path.Length - 36), out regionID))
{
UUID authToken = Utils.GetAuthToken(request);
if (server.AuthorizationProvider.IsRegionDeleteAuthorized(authToken, regionID))
{
BackendResponse backendResponse = server.GridProvider.TryDeleteRegion(regionID);
if (backendResponse == BackendResponse.Success)
response.Status = HttpStatusCode.NoContent;
else if (backendResponse == BackendResponse.NotFound)
response.Status = HttpStatusCode.NotFound;
else
response.Status = HttpStatusCode.InternalServerError;
}
else
{
response.Status = HttpStatusCode.Forbidden;
}
}
else
{
response.Status = HttpStatusCode.NotFound;
}
return true;
}
bool RegionUpdateHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{
return true;
}
bool RegionHeartbeatHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
{
return true;
}
}
}
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

