aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.AssetServer
diff options
context:
space:
mode:
authorMW2007-05-15 17:51:13 +0000
committerMW2007-05-15 17:51:13 +0000
commit384293ac5676cf7ba1fbf77c182a117bd61822be (patch)
tree122b1ecab835ba2dca6383e5b33375be233821ba /OpenGridServices.AssetServer
parentAdded SimClientPacketHandlers.cs (moved the SimClient Packet handlers into it) (diff)
downloadopensim-SC_OLD-384293ac5676cf7ba1fbf77c182a117bd61822be.zip
opensim-SC_OLD-384293ac5676cf7ba1fbf77c182a117bd61822be.tar.gz
opensim-SC_OLD-384293ac5676cf7ba1fbf77c182a117bd61822be.tar.bz2
opensim-SC_OLD-384293ac5676cf7ba1fbf77c182a117bd61822be.tar.xz
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.
Diffstat (limited to 'OpenGridServices.AssetServer')
-rw-r--r--OpenGridServices.AssetServer/AssetHttpServer.cs92
-rw-r--r--OpenGridServices.AssetServer/Main.cs323
-rw-r--r--OpenGridServices.AssetServer/OpenGridServices.AssetServer.csproj3
-rw-r--r--OpenGridServices.AssetServer/OpenGridServices.AssetServer.exe.build1
4 files changed, 273 insertions, 146 deletions
diff --git a/OpenGridServices.AssetServer/AssetHttpServer.cs b/OpenGridServices.AssetServer/AssetHttpServer.cs
new file mode 100644
index 0000000..8439e92
--- /dev/null
+++ b/OpenGridServices.AssetServer/AssetHttpServer.cs
@@ -0,0 +1,92 @@
1using System;
2using System.Collections.Generic;
3using System.Net;
4using System.Text;
5using System.Text.RegularExpressions;
6using System.Threading;
7//using OpenSim.CAPS;
8using Nwc.XmlRpc;
9using System.Collections;
10using OpenSim.Framework.Console;
11using OpenSim.Servers;
12
13namespace OpenGridServices.AssetServer
14{
15 public class AssetHttpServer :BaseHttpServer
16 {
17 public AssetHttpServer(int port)
18 : base(port)
19 {
20 }
21
22 public override void HandleRequest(Object stateinfo)
23 {
24 try
25 {
26 HttpListenerContext context = (HttpListenerContext)stateinfo;
27
28 HttpListenerRequest request = context.Request;
29 HttpListenerResponse response = context.Response;
30
31 response.KeepAlive = false;
32 response.SendChunked = false;
33
34 System.IO.Stream body = request.InputStream;
35 System.Text.Encoding encoding = System.Text.Encoding.UTF8;
36 System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
37
38 string requestBody = reader.ReadToEnd();
39 body.Close();
40 reader.Close();
41
42 //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType);
43 //Console.WriteLine(requestBody);
44
45 string responseString = "";
46 switch (request.ContentType)
47 {
48 case "text/xml":
49 // must be XML-RPC, so pass to the XML-RPC parser
50
51 responseString = ParseXMLRPC(requestBody);
52 responseString = Regex.Replace(responseString, "utf-16", "utf-8");
53
54 response.AddHeader("Content-type", "text/xml");
55 break;
56
57 case "application/xml":
58 // probably LLSD we hope, otherwise it should be ignored by the parser
59 responseString = ParseLLSDXML(requestBody);
60 response.AddHeader("Content-type", "application/xml");
61 break;
62
63 case "application/x-www-form-urlencoded":
64 // a form data POST so send to the REST parser
65 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
66 response.AddHeader("Content-type", "text/plain");
67 break;
68
69 case null:
70 // must be REST or invalid crap, so pass to the REST parser
71 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
72 response.AddHeader("Content-type", "text/plain");
73 break;
74
75 }
76
77 Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
78 byte[] buffer = Windows1252Encoding.GetBytes(responseString);
79 System.IO.Stream output = response.OutputStream;
80 response.SendChunked = false;
81 response.ContentLength64 = buffer.Length;
82 output.Write(buffer, 0, buffer.Length);
83 output.Close();
84 }
85 catch (Exception e)
86 {
87 Console.WriteLine(e.ToString());
88 }
89 }
90
91 }
92}
diff --git a/OpenGridServices.AssetServer/Main.cs b/OpenGridServices.AssetServer/Main.cs
index c2607c1..ef9cc67 100644
--- a/OpenGridServices.AssetServer/Main.cs
+++ b/OpenGridServices.AssetServer/Main.cs
@@ -40,6 +40,7 @@ using OpenSim.Framework.Sims;
40using OpenSim.Framework.Console; 40using OpenSim.Framework.Console;
41using OpenSim.Framework.Types; 41using OpenSim.Framework.Types;
42using OpenSim.Framework.Interfaces; 42using OpenSim.Framework.Interfaces;
43using OpenSim.Framework.Utilities;
43using OpenSim.GridInterfaces.Local; // REFACTORING IS NEEDED!!!!!!!!!!! 44using OpenSim.GridInterfaces.Local; // REFACTORING IS NEEDED!!!!!!!!!!!
44using OpenSim.Servers; 45using OpenSim.Servers;
45using Db4objects.Db4o; 46using Db4objects.Db4o;
@@ -52,7 +53,7 @@ namespace OpenGridServices.AssetServer
52 public class OpenAsset_Main : BaseServer, conscmd_callback 53 public class OpenAsset_Main : BaseServer, conscmd_callback
53 { 54 {
54 private IObjectContainer db; 55 private IObjectContainer db;
55 56
56 public static OpenAsset_Main assetserver; 57 public static OpenAsset_Main assetserver;
57 58
58 private ConsoleBase m_console; 59 private ConsoleBase m_console;
@@ -70,7 +71,7 @@ namespace OpenGridServices.AssetServer
70 71
71 private void Work() 72 private void Work()
72 { 73 {
73 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH,"\nEnter help for a list of commands\n"); 74 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "\nEnter help for a list of commands\n");
74 75
75 while (true) 76 while (true)
76 { 77 {
@@ -86,161 +87,191 @@ namespace OpenGridServices.AssetServer
86 87
87 public void Startup() 88 public void Startup()
88 { 89 {
89 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Setting up asset DB"); 90 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Setting up asset DB");
90 setupDB(); 91 setupDB();
91
92 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Starting HTTP process");
93 BaseHttpServer httpServer = new BaseHttpServer(8003);
94 92
93 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Starting HTTP process");
94 AssetHttpServer httpServer = new AssetHttpServer(8003);
95 95
96 httpServer.AddRestHandler("GET", "/assets/", this.assetGetMethod);
97 96
97 httpServer.AddRestHandler("GET", "/assets/", this.assetGetMethod);
98 httpServer.AddRestHandler("POST", "/assets/", this.assetPostMethod);
98 99
99 httpServer.Start(); 100 httpServer.Start();
100 101
101 } 102 }
102 103
103 public string assetGetMethod(string request, string path, string param) { 104 public string assetPostMethod(string requestBody, string path, string param)
104 byte[] assetdata=getAssetData(new LLUUID(param),false); 105 {
105 if(assetdata!=null) { 106 AssetBase asset = new AssetBase();
106 return System.Text.Encoding.ASCII.GetString(assetdata); 107 asset.Name = "";
107 } else { 108 asset.FullID = new LLUUID(param);
108 return ""; 109 Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
109 } 110 byte[] buffer = Windows1252Encoding.GetBytes(requestBody);
111 asset.Data = buffer;
112 AssetStorage store = new AssetStorage();
113 store.Data = asset.Data;
114 store.Name = asset.Name;
115 store.UUID = asset.FullID;
116 db.Set(store);
117 db.Commit();
118 return "";
119 }
110 120
111 } 121 public string assetGetMethod(string request, string path, string param)
122 {
123 Console.WriteLine("got a request " +param);
124 byte[] assetdata = getAssetData(new LLUUID(param), false);
125 if (assetdata != null)
126 {
127 Encoding Windows1252Encoding = Encoding.GetEncoding(1252);
128 string ret = Windows1252Encoding.GetString(assetdata);
129 //string ret = System.Text.Encoding.Unicode.GetString(assetdata);
112 130
113 public byte[] getAssetData(LLUUID assetID, bool isTexture) { 131 return ret;
114 byte[] idata = null; 132
115 bool found = false; 133 }
116 AssetStorage foundAsset = null; 134 else
135 {
136 return "";
137 }
117 138
118 IObjectSet result = db.Get(new AssetStorage(assetID)); 139 }
119 if (result.Count > 0)
120 {
121 foundAsset = (AssetStorage)result.Next();
122 found = true;
123 }
124 140
125 if (found) 141 public byte[] getAssetData(LLUUID assetID, bool isTexture)
126 { 142 {
127 return foundAsset.Data; 143 byte[] idata = null;
128 } 144 bool found = false;
129 else 145 AssetStorage foundAsset = null;
130 { 146
131 return null; 147 IObjectSet result = db.Get(new AssetStorage(assetID));
132 } 148 if (result.Count > 0)
133 } 149 {
134 150 foundAsset = (AssetStorage)result.Next();
135 public void setupDB() { 151 found = true;
136 bool yapfile=System.IO.File.Exists("assets.yap"); 152 }
137 try 153
138 { 154 if (found)
139 db = Db4oFactory.OpenFile("assets.yap"); 155 {
140 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:setupDB() - creation"); 156 return foundAsset.Data;
141 } 157 }
142 catch (Exception e) 158 else
143 { 159 {
144 db.Close(); 160 return null;
145 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"Main.cs:setupDB() - Exception occured"); 161 }
146 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,e.ToString()); 162 }
147 } 163
148 if (!yapfile) 164 public void setupDB()
149 { 165 {
150 this.LoadDB(); 166 bool yapfile = System.IO.File.Exists("assets.yap");
151 } 167 try
152 } 168 {
153 169 db = Db4oFactory.OpenFile("assets.yap");
154 public void LoadDB() { 170 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:setupDB() - creation");
155 try 171 }
156 { 172 catch (Exception e)
157 173 {
158 Console.WriteLine("setting up Asset database"); 174 db.Close();
159 175 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "Main.cs:setupDB() - Exception occured");
160 AssetBase Image = new AssetBase(); 176 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, e.ToString());
161 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001"); 177 }
162 Image.Name = "Bricks"; 178 if (!yapfile)
163 this.LoadAsset(Image, true, "bricks.jp2"); 179 {
164 AssetStorage store = new AssetStorage(); 180 this.LoadDB();
165 store.Data = Image.Data; 181 }
166 store.Name = Image.Name; 182 }
167 store.UUID = Image.FullID; 183
168 db.Set(store); 184 public void LoadDB()
169 db.Commit(); 185 {
170 186 try
171 Image = new AssetBase(); 187 {
172 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002"); 188
173 Image.Name = "Plywood"; 189 Console.WriteLine("setting up Asset database");
174 this.LoadAsset(Image, true, "plywood.jp2"); 190
175 store = new AssetStorage(); 191 AssetBase Image = new AssetBase();
176 store.Data = Image.Data; 192 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001");
177 store.Name = Image.Name; 193 Image.Name = "Bricks";
178 store.UUID = Image.FullID; 194 this.LoadAsset(Image, true, "bricks.jp2");
179 db.Set(store); 195 AssetStorage store = new AssetStorage();
180 db.Commit(); 196 store.Data = Image.Data;
181 197 store.Name = Image.Name;
182 Image = new AssetBase(); 198 store.UUID = Image.FullID;
183 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003"); 199 db.Set(store);
184 Image.Name = "Rocks"; 200 db.Commit();
185 this.LoadAsset(Image, true, "rocks.jp2"); 201
186 store = new AssetStorage(); 202 Image = new AssetBase();
187 store.Data = Image.Data; 203 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002");
188 store.Name = Image.Name; 204 Image.Name = "Plywood";
189 store.UUID = Image.FullID; 205 this.LoadAsset(Image, true, "plywood.jp2");
190 db.Set(store); 206 store = new AssetStorage();
191 db.Commit(); 207 store.Data = Image.Data;
192 208 store.Name = Image.Name;
193 Image = new AssetBase(); 209 store.UUID = Image.FullID;
194 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004"); 210 db.Set(store);
195 Image.Name = "Granite"; 211 db.Commit();
196 this.LoadAsset(Image, true, "granite.jp2"); 212
197 store = new AssetStorage(); 213 Image = new AssetBase();
198 store.Data = Image.Data; 214 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003");
199 store.Name = Image.Name; 215 Image.Name = "Rocks";
200 store.UUID = Image.FullID; 216 this.LoadAsset(Image, true, "rocks.jp2");
201 db.Set(store); 217 store = new AssetStorage();
202 db.Commit(); 218 store.Data = Image.Data;
203 219 store.Name = Image.Name;
204 Image = new AssetBase(); 220 store.UUID = Image.FullID;
205 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005"); 221 db.Set(store);
206 Image.Name = "Hardwood"; 222 db.Commit();
207 this.LoadAsset(Image, true, "hardwood.jp2"); 223
208 store = new AssetStorage(); 224 Image = new AssetBase();
209 store.Data = Image.Data; 225 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004");
210 store.Name = Image.Name; 226 Image.Name = "Granite";
211 store.UUID = Image.FullID; 227 this.LoadAsset(Image, true, "granite.jp2");
212 db.Set(store); 228 store = new AssetStorage();
213 db.Commit(); 229 store.Data = Image.Data;
214 230 store.Name = Image.Name;
215 Image = new AssetBase(); 231 store.UUID = Image.FullID;
216 Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005"); 232 db.Set(store);
217 Image.Name = "Prim Base Texture"; 233 db.Commit();
218 this.LoadAsset(Image, true, "plywood.jp2"); 234
219 store = new AssetStorage(); 235 Image = new AssetBase();
220 store.Data = Image.Data; 236 Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005");
221 store.Name = Image.Name; 237 Image.Name = "Hardwood";
222 store.UUID = Image.FullID; 238 this.LoadAsset(Image, true, "hardwood.jp2");
223 db.Set(store); 239 store = new AssetStorage();
224 db.Commit(); 240 store.Data = Image.Data;
225 241 store.Name = Image.Name;
226 Image = new AssetBase(); 242 store.UUID = Image.FullID;
227 Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); 243 db.Set(store);
228 Image.Name = "Shape"; 244 db.Commit();
229 this.LoadAsset(Image, false, "base_shape.dat"); 245
230 store = new AssetStorage(); 246 Image = new AssetBase();
231 store.Data = Image.Data; 247 Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005");
232 store.Name = Image.Name; 248 Image.Name = "Prim Base Texture";
233 store.UUID = Image.FullID; 249 this.LoadAsset(Image, true, "plywood.jp2");
234 db.Set(store); 250 store = new AssetStorage();
235 db.Commit(); 251 store.Data = Image.Data;
236 } 252 store.Name = Image.Name;
237 catch (Exception e) 253 store.UUID = Image.FullID;
238 { 254 db.Set(store);
239 Console.WriteLine(e.Message); 255 db.Commit();
240 } 256
241 } 257 Image = new AssetBase();
242 258 Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
243 private void LoadAsset(AssetBase info, bool image, string filename) 259 Image.Name = "Shape";
260 this.LoadAsset(Image, false, "base_shape.dat");
261 store = new AssetStorage();
262 store.Data = Image.Data;
263 store.Name = Image.Name;
264 store.UUID = Image.FullID;
265 db.Set(store);
266 db.Commit();
267 }
268 catch (Exception e)
269 {
270 Console.WriteLine(e.Message);
271 }
272 }
273
274 private void LoadAsset(AssetBase info, bool image, string filename)
244 { 275 {
245 276
246 277
@@ -291,7 +322,7 @@ namespace OpenGridServices.AssetServer
291 switch (cmd) 322 switch (cmd)
292 { 323 {
293 case "help": 324 case "help":
294 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH,"shutdown - shutdown this asset server (USE CAUTION!)"); 325 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "shutdown - shutdown this asset server (USE CAUTION!)");
295 break; 326 break;
296 327
297 case "shutdown": 328 case "shutdown":
diff --git a/OpenGridServices.AssetServer/OpenGridServices.AssetServer.csproj b/OpenGridServices.AssetServer/OpenGridServices.AssetServer.csproj
index 0392d9f..d01a52e 100644
--- a/OpenGridServices.AssetServer/OpenGridServices.AssetServer.csproj
+++ b/OpenGridServices.AssetServer/OpenGridServices.AssetServer.csproj
@@ -112,6 +112,9 @@
112 </ProjectReference> 112 </ProjectReference>
113 </ItemGroup> 113 </ItemGroup>
114 <ItemGroup> 114 <ItemGroup>
115 <Compile Include="AssetHttpServer.cs">
116 <SubType>Code</SubType>
117 </Compile>
115 <Compile Include="Main.cs"> 118 <Compile Include="Main.cs">
116 <SubType>Code</SubType> 119 <SubType>Code</SubType>
117 </Compile> 120 </Compile>
diff --git a/OpenGridServices.AssetServer/OpenGridServices.AssetServer.exe.build b/OpenGridServices.AssetServer/OpenGridServices.AssetServer.exe.build
index a2b1e37..cd76f22 100644
--- a/OpenGridServices.AssetServer/OpenGridServices.AssetServer.exe.build
+++ b/OpenGridServices.AssetServer/OpenGridServices.AssetServer.exe.build
@@ -11,6 +11,7 @@
11 <resources prefix="OpenGridServices.AssetServer" dynamicprefix="true" > 11 <resources prefix="OpenGridServices.AssetServer" dynamicprefix="true" >
12 </resources> 12 </resources>
13 <sources failonempty="true"> 13 <sources failonempty="true">
14 <include name="AssetHttpServer.cs" />
14 <include name="Main.cs" /> 15 <include name="Main.cs" />
15 <include name="Properties/AssemblyInfo.cs" /> 16 <include name="Properties/AssemblyInfo.cs" />
16 </sources> 17 </sources>