aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/CAPS/SimHttp.cs
diff options
context:
space:
mode:
authorMW2007-03-29 11:08:42 +0000
committerMW2007-03-29 11:08:42 +0000
commit17b00785ee10a71d290cbcddca9b0152fdf60c8f (patch)
tree88a78c0b9a0357af823e4ecdad25e09a64569f79 /OpenSim.RegionServer/CAPS/SimHttp.cs
parentDoh! need to return the response (diff)
downloadopensim-SC_OLD-17b00785ee10a71d290cbcddca9b0152fdf60c8f.zip
opensim-SC_OLD-17b00785ee10a71d290cbcddca9b0152fdf60c8f.tar.gz
opensim-SC_OLD-17b00785ee10a71d290cbcddca9b0152fdf60c8f.tar.bz2
opensim-SC_OLD-17b00785ee10a71d290cbcddca9b0152fdf60c8f.tar.xz
Added lbsa71's http server changes.
So it now has a single http listener that passes incoming requests to the correct handler. This means that logins (in sandbox mode) now go through this listener, which for now is listening on the port you set in startup (default 9000). (This needs changing so that the http listener and udp server are not using the same port)
Diffstat (limited to '')
-rw-r--r--OpenSim.RegionServer/CAPS/SimHttp.cs241
1 files changed, 0 insertions, 241 deletions
diff --git a/OpenSim.RegionServer/CAPS/SimHttp.cs b/OpenSim.RegionServer/CAPS/SimHttp.cs
deleted file mode 100644
index bfba635..0000000
--- a/OpenSim.RegionServer/CAPS/SimHttp.cs
+++ /dev/null
@@ -1,241 +0,0 @@
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;
42using OpenSim.Servers;
43
44namespace OpenSim.CAPS
45{
46 // Dummy HTTP server, does nothing useful for now
47
48 public class SimCAPSHTTPServer : BaseHttpServer
49 {
50 private Thread m_workerThread;
51 private HttpListener m_httpListener;
52 private Dictionary<string, IRestHandler> m_restHandlers = new Dictionary<string, IRestHandler>();
53 private Dictionary<string, IXmlRPCHandler> RPCHandlers = new Dictionary<string, IXmlRPCHandler>();
54 private IGridServer m_gridServer;
55 private int m_port;
56
57 public SimCAPSHTTPServer(IGridServer gridServer, int port)
58 {
59 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server");
60 m_workerThread = new Thread(new ThreadStart(StartHTTP));
61 m_workerThread.Start();
62 m_gridServer = gridServer;
63 m_port = port;
64 }
65
66 public void StartHTTP()
67 {
68 try
69 {
70 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SimHttp.cs:StartHTTP() - Spawned main thread OK");
71 m_httpListener = new HttpListener();
72
73 m_httpListener.Prefixes.Add("http://+:" + m_port + "/");
74 m_httpListener.Start();
75
76 HttpListenerContext context;
77 while (true)
78 {
79 context = m_httpListener.GetContext();
80 ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
81 }
82 }
83 catch (Exception e)
84 {
85 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.Message);
86 }
87 }
88
89 public bool AddRestHandler(string path, IRestHandler handler)
90 {
91 if (!this.m_restHandlers.ContainsKey(path))
92 {
93 this.m_restHandlers.Add(path, handler);
94 return true;
95 }
96
97 //must already have a handler for that path so return false
98 return false;
99 }
100
101 public bool AddXmlRPCHandler(string method, IXmlRPCHandler handler)
102 {
103 if (!this.RPCHandlers.ContainsKey(method))
104 {
105 this.RPCHandlers.Add(method, handler);
106 return true;
107 }
108
109 //must already have a handler for that path so return false
110 return false;
111 }
112
113 protected virtual string ParseXMLRPC(string requestBody)
114 {
115 string responseString = "";
116 try
117 {
118 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
119
120 Hashtable requestData = (Hashtable)request.Params[0];
121 switch (request.MethodName)
122 {
123 case "expect_user":
124 AgentCircuitData agent_data = new AgentCircuitData();
125 agent_data.SessionID = new LLUUID((string)requestData["session_id"]);
126 agent_data.SecureSessionID = new LLUUID((string)requestData["secure_session_id"]);
127 agent_data.firstname = (string)requestData["firstname"];
128 agent_data.lastname = (string)requestData["lastname"];
129 agent_data.AgentID = new LLUUID((string)requestData["agent_id"]);
130 agent_data.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
131 if (m_gridServer.GetName() == "Remote")
132 {
133 ((RemoteGridBase) m_gridServer).agentcircuits.Add((uint)agent_data.circuitcode, agent_data);
134 }
135 responseString = "<?xml version=\"1.0\"?><methodResponse><params /></methodResponse>";
136 break;
137 default:
138 if (this.RPCHandlers.ContainsKey(request.MethodName))
139 {
140 //responseString = this.RPCHandlers[request.MethodName]
141 }
142 break;
143 }
144 }
145 catch (Exception e)
146 {
147 Console.WriteLine(e.ToString());
148 }
149 return responseString;
150 }
151
152 protected virtual string ParseREST(string requestBody, string requestURL, string requestMethod)
153 {
154 string[] path;
155 string pathDelimStr = "/";
156 char[] pathDelimiter = pathDelimStr.ToCharArray();
157 path = requestURL.Split(pathDelimiter);
158
159 string responseString = "";
160
161 //path[0] should be empty so we are interested in path[1]
162 if (path.Length > 1)
163 {
164 if ((path[1] != "") && (this.m_restHandlers.ContainsKey(path[1])))
165 {
166 responseString = this.m_restHandlers[path[1]].HandleREST(requestBody, requestURL, requestMethod);
167 }
168 }
169
170 return responseString;
171 }
172
173 protected virtual string ParseLLSDXML(string requestBody)
174 {
175 // dummy function for now - IMPLEMENT ME!
176 return "";
177 }
178
179 public virtual void HandleRequest(Object stateinfo)
180 {
181 // Console.WriteLine("new http incoming");
182 HttpListenerContext context = (HttpListenerContext)stateinfo;
183
184 HttpListenerRequest request = context.Request;
185 HttpListenerResponse response = context.Response;
186
187 response.KeepAlive = false;
188 response.SendChunked = false;
189
190 System.IO.Stream body = request.InputStream;
191 System.Text.Encoding encoding = System.Text.Encoding.UTF8;
192 System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
193
194 string requestBody = reader.ReadToEnd();
195 body.Close();
196 reader.Close();
197
198 //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType);
199 //Console.WriteLine(requestBody);
200
201 string responseString = "";
202 switch (request.ContentType)
203 {
204 case "text/xml":
205 // must be XML-RPC, so pass to the XML-RPC parser
206
207 responseString = ParseXMLRPC(requestBody);
208 response.AddHeader("Content-type", "text/xml");
209 break;
210
211 case "application/xml":
212 // probably LLSD we hope, otherwise it should be ignored by the parser
213 responseString = ParseLLSDXML(requestBody);
214 response.AddHeader("Content-type", "application/xml");
215 break;
216
217 case "application/x-www-form-urlencoded":
218 // a form data POST so send to the REST parser
219 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
220 response.AddHeader("Content-type", "text/html");
221 break;
222
223 case null:
224 // must be REST or invalid crap, so pass to the REST parser
225 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
226 response.AddHeader("Content-type", "text/html");
227 break;
228
229 }
230
231 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
232 System.IO.Stream output = response.OutputStream;
233 response.SendChunked = false;
234 response.ContentLength64 = buffer.Length;
235 output.Write(buffer, 0, buffer.Length);
236 output.Close();
237 }
238 }
239
240
241}