aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/CAPS/SimHttp.cs
diff options
context:
space:
mode:
authorgareth2007-03-22 10:11:15 +0000
committergareth2007-03-22 10:11:15 +0000
commit7daa3955bc3a1918e40962851f9e8d38597a245e (patch)
treebee3e1372a7eed0c1b220a8a49f7bee7d29a6b91 /OpenSim.RegionServer/CAPS/SimHttp.cs
parentLoad XML for neighbourinfo from grid (diff)
downloadopensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.zip
opensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.gz
opensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.bz2
opensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.xz
brought zircon branch into trunk
Diffstat (limited to '')
-rw-r--r--OpenSim.RegionServer/CAPS/SimHttp.cs175
1 files changed, 175 insertions, 0 deletions
diff --git a/OpenSim.RegionServer/CAPS/SimHttp.cs b/OpenSim.RegionServer/CAPS/SimHttp.cs
new file mode 100644
index 0000000..f5a8705
--- /dev/null
+++ b/OpenSim.RegionServer/CAPS/SimHttp.cs
@@ -0,0 +1,175 @@
1/*
2Copyright (c) OpenSimCAPS project, http://osgrid.org/
3
4
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.Text;
32using Nwc.XmlRpc;
33using System.Threading;
34using System.Text.RegularExpressions;
35using System.Net;
36using System.IO;
37using System.Collections;
38using System.Collections.Generic;
39using libsecondlife;
40using OpenSim.Framework.Console;
41using OpenSim.Framework.Interfaces;
42
43namespace OpenSim.CAPS
44{
45 // Dummy HTTP server, does nothing useful for now
46
47 public class SimCAPSHTTPServer
48 {
49 public Thread HTTPD;
50 public HttpListener Listener;
51
52 public SimCAPSHTTPServer()
53 {
54 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server");
55 HTTPD = new Thread(new ThreadStart(StartHTTP));
56 HTTPD.Start();
57 }
58
59 public void StartHTTP()
60 {
61 try
62 {
63 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SimHttp.cs:StartHTTP() - Spawned main thread OK");
64 Listener = new HttpListener();
65
66 Listener.Prefixes.Add("http://+:" + OpenSimRoot.Instance.Cfg.IPListenPort + "/");
67 Listener.Start();
68
69 HttpListenerContext context;
70 while (true)
71 {
72 context = Listener.GetContext();
73 ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
74 }
75 }
76 catch (Exception e)
77 {
78 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.Message);
79 }
80 }
81
82 static string ParseXMLRPC(string requestBody)
83 {
84 try
85 {
86 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
87
88 Hashtable requestData = (Hashtable)request.Params[0];
89 switch (request.MethodName)
90 {
91 case "expect_user":
92 AgentCircuitData agent_data = new AgentCircuitData();
93 agent_data.SessionID = new LLUUID((string)requestData["session_id"]);
94 agent_data.SecureSessionID = new LLUUID((string)requestData["secure_session_id"]);
95 agent_data.firstname = (string)requestData["firstname"];
96 agent_data.lastname = (string)requestData["lastname"];
97 agent_data.AgentID = new LLUUID((string)requestData["agent_id"]);
98 agent_data.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
99 if (OpenSimRoot.Instance.GridServers.GridServer.GetName() == "Remote")
100 {
101 ((RemoteGridBase)OpenSimRoot.Instance.GridServers.GridServer).agentcircuits.Add((uint)agent_data.circuitcode, agent_data);
102 }
103 return "<?xml version=\"1.0\"?><methodResponse><params /></methodResponse>";
104 break;
105 }
106 }
107 catch (Exception e)
108 {
109 Console.WriteLine(e.ToString());
110 }
111 return "";
112 }
113
114 static string ParseREST(string requestBody, string requestURL)
115 {
116 return "";
117 }
118
119 static string ParseLLSDXML(string requestBody)
120 {
121 // dummy function for now - IMPLEMENT ME!
122 return "";
123 }
124
125 static void HandleRequest(Object stateinfo)
126 {
127 HttpListenerContext context = (HttpListenerContext)stateinfo;
128
129 HttpListenerRequest request = context.Request;
130 HttpListenerResponse response = context.Response;
131
132 response.KeepAlive = false;
133 response.SendChunked = false;
134
135 System.IO.Stream body = request.InputStream;
136 System.Text.Encoding encoding = System.Text.Encoding.UTF8;
137 System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
138
139 string requestBody = reader.ReadToEnd();
140 body.Close();
141 reader.Close();
142
143 string responseString = "";
144 switch (request.ContentType)
145 {
146 case "text/xml":
147 // must be XML-RPC, so pass to the XML-RPC parser
148
149 responseString = ParseXMLRPC(requestBody);
150 response.AddHeader("Content-type", "text/xml");
151 break;
152
153 case "application/xml":
154 // probably LLSD we hope, otherwise it should be ignored by the parser
155 responseString = ParseLLSDXML(requestBody);
156 response.AddHeader("Content-type", "application/xml");
157 break;
158
159 case null:
160 // must be REST or invalid crap, so pass to the REST parser
161 responseString = ParseREST(request.Url.OriginalString, requestBody);
162 break;
163 }
164
165 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
166 System.IO.Stream output = response.OutputStream;
167 response.SendChunked = false;
168 response.ContentLength64 = buffer.Length;
169 output.Write(buffer, 0, buffer.Length);
170 output.Close();
171 }
172 }
173
174
175}