Worked on Asset server, asset downloads (from server to sim) now work.

Asset uploads (from sim to server) may or may not work, needs more testing, if they don't work then it should be just a encoding problem and not hard to fix.
zircon^2
MW 2007-05-15 17:51:13 +00:00
parent 6b15c6e556
commit 384293ac56
11 changed files with 568 additions and 367 deletions

View File

@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
//using OpenSim.CAPS;
using Nwc.XmlRpc;
using System.Collections;
using OpenSim.Framework.Console;
using OpenSim.Servers;
namespace OpenGridServices.AssetServer
{
public class AssetHttpServer :BaseHttpServer
{
public AssetHttpServer(int port)
: base(port)
{
}
public override void HandleRequest(Object stateinfo)
{
try
{
HttpListenerContext context = (HttpListenerContext)stateinfo;
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
response.KeepAlive = false;
response.SendChunked = false;
System.IO.Stream body = request.InputStream;
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
string requestBody = reader.ReadToEnd();
body.Close();
reader.Close();
//Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType);
//Console.WriteLine(requestBody);
string responseString = "";
switch (request.ContentType)
{
case "text/xml":
// must be XML-RPC, so pass to the XML-RPC parser
responseString = ParseXMLRPC(requestBody);
responseString = Regex.Replace(responseString, "utf-16", "utf-8");
response.AddHeader("Content-type", "text/xml");
break;
case "application/xml":
// probably LLSD we hope, otherwise it should be ignored by the parser
responseString = ParseLLSDXML(requestBody);
response.AddHeader("Content-type", "application/xml");
break;
case "application/x-www-form-urlencoded":
// a form data POST so send to the REST parser
responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
response.AddHeader("Content-type", "text/plain");
break;
case null:
// must be REST or invalid crap, so pass to the REST parser
responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
response.AddHeader("Content-type", "text/plain");
break;
}
Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
byte[] buffer = Windows1252Encoding.GetBytes(responseString);
System.IO.Stream output = response.OutputStream;
response.SendChunked = false;
response.ContentLength64 = buffer.Length;
output.Write(buffer, 0, buffer.Length);
output.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}

View File

@ -40,6 +40,7 @@ using OpenSim.Framework.Sims;
using OpenSim.Framework.Console;
using OpenSim.Framework.Types;
using OpenSim.Framework.Interfaces;
using OpenSim.Framework.Utilities;
using OpenSim.GridInterfaces.Local; // REFACTORING IS NEEDED!!!!!!!!!!!
using OpenSim.Servers;
using Db4objects.Db4o;
@ -90,27 +91,55 @@ namespace OpenGridServices.AssetServer
setupDB();
m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Starting HTTP process");
BaseHttpServer httpServer = new BaseHttpServer(8003);
AssetHttpServer httpServer = new AssetHttpServer(8003);
httpServer.AddRestHandler("GET", "/assets/", this.assetGetMethod);
httpServer.AddRestHandler("POST", "/assets/", this.assetPostMethod);
httpServer.Start();
}
public string assetGetMethod(string request, string path, string param) {
public string assetPostMethod(string requestBody, string path, string param)
{
AssetBase asset = new AssetBase();
asset.Name = "";
asset.FullID = new LLUUID(param);
Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
byte[] buffer = Windows1252Encoding.GetBytes(requestBody);
asset.Data = buffer;
AssetStorage store = new AssetStorage();
store.Data = asset.Data;
store.Name = asset.Name;
store.UUID = asset.FullID;
db.Set(store);
db.Commit();
return "";
}
public string assetGetMethod(string request, string path, string param)
{
Console.WriteLine("got a request " +param);
byte[] assetdata = getAssetData(new LLUUID(param), false);
if(assetdata!=null) {
return System.Text.Encoding.ASCII.GetString(assetdata);
} else {
if (assetdata != null)
{
Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
string ret = Windows1252Encoding.GetString(assetdata);
//string ret = System.Text.Encoding.Unicode.GetString(assetdata);
return ret;
}
else
{
return "";
}
}
public byte[] getAssetData(LLUUID assetID, bool isTexture) {
public byte[] getAssetData(LLUUID assetID, bool isTexture)
{
byte[] idata = null;
bool found = false;
AssetStorage foundAsset = null;
@ -132,7 +161,8 @@ namespace OpenGridServices.AssetServer
}
}
public void setupDB() {
public void setupDB()
{
bool yapfile = System.IO.File.Exists("assets.yap");
try
{
@ -151,7 +181,8 @@ namespace OpenGridServices.AssetServer
}
}
public void LoadDB() {
public void LoadDB()
{
try
{

View File

@ -112,6 +112,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="AssetHttpServer.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Main.cs">
<SubType>Code</SubType>
</Compile>

View File

@ -11,6 +11,7 @@
<resources prefix="OpenGridServices.AssetServer" dynamicprefix="true" >
</resources>
<sources failonempty="true">
<include name="AssetHttpServer.cs" />
<include name="Main.cs" />
<include name="Properties/AssemblyInfo.cs" />
</sources>

View File

@ -49,6 +49,11 @@ namespace OpenSim.GridInterfaces.Remote
public void UploadNewAsset(AssetBase asset)
{
Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
string ret = Windows1252Encoding.GetString(asset.Data);
byte[] buffer = Windows1252Encoding.GetBytes(ret);
WebClient client = new WebClient();
client.UploadData(this.AssetServerUrl + "assets/" + asset.FullID, buffer);
}
@ -66,7 +71,7 @@ namespace OpenSim.GridInterfaces.Remote
// 404... THE MAGIC FILE NOT FOUND ERROR, very useful for telling you things such as a file (or asset ;) ) not being found!!!!!!!!!!! it's 2:22AM
ARequest req = this._assetRequests.Dequeue();
LLUUID assetID = req.AssetID;
OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW," RemoteAssetServer- Got a AssetServer request, processing it - " + this.AssetServerUrl + "assets/" + assetID);
// OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW," RemoteAssetServer- Got a AssetServer request, processing it - " + this.AssetServerUrl + "assets/" + assetID);
WebRequest AssetLoad = WebRequest.Create(this.AssetServerUrl + "assets/" + assetID);
WebResponse AssetResponse = AssetLoad.GetResponse();
byte[] idata = new byte[(int)AssetResponse.ContentLength];

View File

@ -25,7 +25,7 @@ namespace OpenSim
//following should be removed and the GenericConfig object passed around,
//so each class (AssetServer, GridServer etc) can access what config data they want
public string AssetURL = "";
public string AssetURL = "http://127.0.0.1:8003/";
public string AssetSendKey = "";
public string GridURL = "";
@ -230,6 +230,17 @@ namespace OpenSim
this.GridRecvKey = attri;
}
attri = "";
attri = configData.GetAttribute("AssetServerURL");
if (attri == "")
{
this.AssetURL = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Asset server URL", "http://127.0.0.1:8003/");
configData.SetAttribute("AssetServerURL", this.GridURL);
}
else
{
this.AssetURL = attri;
}
}
this.RegionHandle = Util.UIntsToLong((RegionLocX * 256), (RegionLocY * 256));

View File

@ -155,7 +155,8 @@ namespace OpenSim.Servers
public virtual void HandleRequest(Object stateinfo)
{
try {
try
{
HttpListenerContext context = (HttpListenerContext)stateinfo;
HttpListenerRequest request = context.Request;
@ -213,7 +214,9 @@ namespace OpenSim.Servers
response.ContentLength64 = buffer.Length;
output.Write(buffer, 0, buffer.Length);
output.Close();
} catch (Exception e) {
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}

View File

@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual C# Express 2005
# Visual Studio 2005
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Terrain.BasicTerrain", "OpenSim.Terrain.BasicTerrain\OpenSim.Terrain.BasicTerrain.csproj", "{2270B8FE-0000-0000-0000-000000000000}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSim.Storage.LocalStorageBerkeleyDB", "OpenSim.Storage\LocalStorageBerkeleyDB\OpenSim.Storage.LocalStorageBerkeleyDB.csproj", "{EE9E5D96-0000-0000-0000-000000000000}"
@ -65,6 +65,68 @@ Global
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectDependencies) = postSolution
({EE9E5D96-0000-0000-0000-000000000000}).6 = ({8ACA2445-0000-0000-0000-000000000000})
({EE9E5D96-0000-0000-0000-000000000000}).7 = ({A7CD0630-0000-0000-0000-000000000000})
({63A05FE9-0000-0000-0000-000000000000}).2 = ({8BE16150-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})
({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})
({632E1BFD-0000-0000-0000-000000000000}).11 = ({8E81D43C-0000-0000-0000-000000000000})
({8ACA2445-0000-0000-0000-000000000000}).4 = ({8E81D43C-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})
({0F3C3AC1-0000-0000-0000-000000000000}).3 = ({62CDF671-0000-0000-0000-000000000000})
({E88EF749-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})
({66591469-0000-0000-0000-000000000000}).8 = ({8E81D43C-0000-0000-0000-000000000000})
({4F874463-0000-0000-0000-000000000000}).2 = ({8BE16150-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})
({8BB20F0A-0000-0000-0000-000000000000}).5 = ({8E81D43C-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})
({0A563AC1-0000-0000-0000-000000000000}).3 = ({62CDF671-0000-0000-0000-000000000000})
({7924FD35-0000-0000-0000-000000000000}).1 = ({8ACA2445-0000-0000-0000-000000000000})
({7924FD35-0000-0000-0000-000000000000}).2 = ({8BB20F0A-0000-0000-0000-000000000000})
({7924FD35-0000-0000-0000-000000000000}).3 = ({8E81D43C-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})
({B55C0B5D-0000-0000-0000-000000000000}).5 = ({8E81D43C-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})
({21BFC8E2-0000-0000-0000-000000000000}).6 = ({62CDF671-0000-0000-0000-000000000000})
({21BFC8E2-0000-0000-0000-000000000000}).7 = ({7924FD35-0000-0000-0000-000000000000})
({21BFC8E2-0000-0000-0000-000000000000}).10 = ({8E81D43C-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})
({39BD9497-0000-0000-0000-000000000000}).3 = ({62CDF671-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})
({1E3F341A-0000-0000-0000-000000000000}).4 = ({62CDF671-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})
({0021261B-0000-0000-0000-000000000000}).3 = ({8ACA2445-0000-0000-0000-000000000000})
({0021261B-0000-0000-0000-000000000000}).4 = ({A7CD0630-0000-0000-0000-000000000000})
({0021261B-0000-0000-0000-000000000000}).5 = ({546099CD-0000-0000-0000-000000000000})
({0021261B-0000-0000-0000-000000000000}).6 = ({8BB20F0A-0000-0000-0000-000000000000})
({0021261B-0000-0000-0000-000000000000}).9 = ({8E81D43C-0000-0000-0000-000000000000})
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{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

View File

@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>8.0.50727</ProductVersion>
@ -6,8 +6,7 @@
<ProjectGuid>{E141F4EE-0000-0000-0000-000000000000}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ApplicationIcon>
</ApplicationIcon>
<ApplicationIcon></ApplicationIcon>
<AssemblyKeyContainerName>
</AssemblyKeyContainerName>
<AssemblyName>ServiceManager</AssemblyName>
@ -16,11 +15,9 @@
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<OutputType>Exe</OutputType>
<AppDesignerFolder>
</AppDesignerFolder>
<AppDesignerFolder></AppDesignerFolder>
<RootNamespace>ServiceManager</RootNamespace>
<StartupObject>
</StartupObject>
<StartupObject></StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
</PropertyGroup>
@ -31,8 +28,7 @@
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<DocumentationFile>
</DocumentationFile>
<DocumentationFile></DocumentationFile>
<DebugSymbols>True</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>False</Optimize>
@ -41,8 +37,7 @@
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoWarn>
</NoWarn>
<NoWarn></NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
@ -51,8 +46,7 @@
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE</DefineConstants>
<DocumentationFile>
</DocumentationFile>
<DocumentationFile></DocumentationFile>
<DebugSymbols>False</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>True</Optimize>
@ -61,8 +55,7 @@
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoWarn>
</NoWarn>
<NoWarn></NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" >
@ -82,7 +75,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ServiceManager.cs">
<SubType>Component</SubType>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />