diff options
author | lbsa71 | 2007-07-04 16:28:59 +0000 |
---|---|---|
committer | lbsa71 | 2007-07-04 16:28:59 +0000 |
commit | 5c32b33a66fbdf371d53d85ee54ee8e837481570 (patch) | |
tree | 68121d2b62aa34e2f8e627823314460a19fe06f8 /OpenSim/Framework/Servers/BaseHttpServer.cs | |
parent | * Removed AssetHttpServer, using BaseHttpServer instead (diff) | |
download | opensim-SC_OLD-5c32b33a66fbdf371d53d85ee54ee8e837481570.zip opensim-SC_OLD-5c32b33a66fbdf371d53d85ee54ee8e837481570.tar.gz opensim-SC_OLD-5c32b33a66fbdf371d53d85ee54ee8e837481570.tar.bz2 opensim-SC_OLD-5c32b33a66fbdf371d53d85ee54ee8e837481570.tar.xz |
* re-fixed the utf-16 bug in xmlRpcResponse serialization
* added LLSDStreamHandler.cs to Caps (Haven't enabled it yet, though)
* removed last traces of old rest handling
Diffstat (limited to 'OpenSim/Framework/Servers/BaseHttpServer.cs')
-rw-r--r-- | OpenSim/Framework/Servers/BaseHttpServer.cs | 175 |
1 files changed, 34 insertions, 141 deletions
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index aed538b..84af9f6 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs | |||
@@ -42,7 +42,6 @@ namespace OpenSim.Framework.Servers | |||
42 | { | 42 | { |
43 | protected Thread m_workerThread; | 43 | protected Thread m_workerThread; |
44 | protected HttpListener m_httpListener; | 44 | protected HttpListener m_httpListener; |
45 | //protected Dictionary<string, RestMethodEntry> m_restHandlers = new Dictionary<string, RestMethodEntry>(); | ||
46 | protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); | 45 | protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); |
47 | protected Dictionary<string, IStreamHandler> m_streamHandlers = new Dictionary<string, IStreamHandler>(); | 46 | protected Dictionary<string, IStreamHandler> m_streamHandlers = new Dictionary<string, IStreamHandler>(); |
48 | protected int m_port; | 47 | protected int m_port; |
@@ -67,32 +66,6 @@ namespace OpenSim.Framework.Servers | |||
67 | return httpMethod + ":" + path; | 66 | return httpMethod + ":" + path; |
68 | } | 67 | } |
69 | 68 | ||
70 | //public bool AddRestHandler(string method, string path, RestMethod handler) | ||
71 | //{ | ||
72 | // //Console.WriteLine("adding new REST handler for path " + path); | ||
73 | // string methodKey = String.Format("{0}: {1}", method, path); | ||
74 | |||
75 | // if (!this.m_restHandlers.ContainsKey(methodKey)) | ||
76 | // { | ||
77 | // this.m_restHandlers.Add(methodKey, new RestMethodEntry(path, handler)); | ||
78 | // return true; | ||
79 | // } | ||
80 | |||
81 | // //must already have a handler for that path so return false | ||
82 | // return false; | ||
83 | //} | ||
84 | |||
85 | //public bool RemoveRestHandler(string method, string path) | ||
86 | //{ | ||
87 | // string methodKey = String.Format("{0}: {1}", method, path); | ||
88 | // if (this.m_restHandlers.ContainsKey(methodKey)) | ||
89 | // { | ||
90 | // this.m_restHandlers.Remove(methodKey); | ||
91 | // return true; | ||
92 | // } | ||
93 | // return false; | ||
94 | //} | ||
95 | |||
96 | public bool AddXmlRPCHandler(string method, XmlRpcMethod handler) | 69 | public bool AddXmlRPCHandler(string method, XmlRpcMethod handler) |
97 | { | 70 | { |
98 | if (!this.m_rpcHandlers.ContainsKey(method)) | 71 | if (!this.m_rpcHandlers.ContainsKey(method)) |
@@ -105,76 +78,6 @@ namespace OpenSim.Framework.Servers | |||
105 | return false; | 78 | return false; |
106 | } | 79 | } |
107 | 80 | ||
108 | protected virtual string ProcessXMLRPCMethod(string methodName, XmlRpcRequest request) | ||
109 | { | ||
110 | XmlRpcResponse response; | ||
111 | |||
112 | XmlRpcMethod method; | ||
113 | if (this.m_rpcHandlers.TryGetValue(methodName, out method)) | ||
114 | { | ||
115 | response = method(request); | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | response = new XmlRpcResponse(); | ||
120 | Hashtable unknownMethodError = new Hashtable(); | ||
121 | unknownMethodError["reason"] = "XmlRequest"; ; | ||
122 | unknownMethodError["message"] = "Unknown Rpc request"; | ||
123 | unknownMethodError["login"] = "false"; | ||
124 | response.Value = unknownMethodError; | ||
125 | } | ||
126 | |||
127 | return XmlRpcResponseSerializer.Singleton.Serialize(response); | ||
128 | } | ||
129 | |||
130 | //protected virtual string ParseREST(string request, string path, string method) | ||
131 | //{ | ||
132 | // string response; | ||
133 | |||
134 | // string requestKey = String.Format("{0}: {1}", method, path); | ||
135 | |||
136 | // string bestMatch = String.Empty; | ||
137 | // foreach (string currentKey in m_restHandlers.Keys) | ||
138 | // { | ||
139 | // if (requestKey.StartsWith(currentKey)) | ||
140 | // { | ||
141 | // if (currentKey.Length > bestMatch.Length) | ||
142 | // { | ||
143 | // bestMatch = currentKey; | ||
144 | // } | ||
145 | // } | ||
146 | // } | ||
147 | |||
148 | // RestMethodEntry restMethodEntry; | ||
149 | // if (m_restHandlers.TryGetValue(bestMatch, out restMethodEntry)) | ||
150 | // { | ||
151 | // RestMethod restMethod = restMethodEntry.RestMethod; | ||
152 | |||
153 | // string param = path.Substring(restMethodEntry.Path.Length); | ||
154 | // response = restMethod(request, path, param); | ||
155 | |||
156 | // } | ||
157 | // else | ||
158 | // { | ||
159 | // response = String.Empty; | ||
160 | // } | ||
161 | |||
162 | // return response; | ||
163 | //} | ||
164 | |||
165 | |||
166 | protected virtual string ParseXMLRPC(string requestBody) | ||
167 | { | ||
168 | string responseString = String.Empty; | ||
169 | |||
170 | XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); | ||
171 | |||
172 | string methodName = request.MethodName; | ||
173 | |||
174 | responseString = ProcessXMLRPCMethod(methodName, request); | ||
175 | |||
176 | return responseString; | ||
177 | } | ||
178 | 81 | ||
179 | public virtual void HandleRequest(Object stateinfo) | 82 | public virtual void HandleRequest(Object stateinfo) |
180 | { | 83 | { |
@@ -203,7 +106,7 @@ namespace OpenSim.Framework.Servers | |||
203 | } | 106 | } |
204 | else | 107 | else |
205 | { | 108 | { |
206 | HandleLegacyRequests(request, response); | 109 | HandleXmlRpcRequests(request, response); |
207 | } | 110 | } |
208 | } | 111 | } |
209 | 112 | ||
@@ -234,64 +137,54 @@ namespace OpenSim.Framework.Servers | |||
234 | } | 137 | } |
235 | } | 138 | } |
236 | 139 | ||
237 | private void HandleLegacyRequests(HttpListenerRequest request, HttpListenerResponse response) | 140 | private void HandleXmlRpcRequests(HttpListenerRequest request, HttpListenerResponse response) |
238 | { | 141 | { |
239 | Stream body = request.InputStream; | 142 | Stream requestStream = request.InputStream; |
240 | 143 | ||
241 | Encoding encoding = Encoding.UTF8; | 144 | Encoding encoding = Encoding.UTF8; |
242 | StreamReader reader = new StreamReader(body, encoding); | 145 | StreamReader reader = new StreamReader(requestStream, encoding); |
243 | 146 | ||
244 | string requestBody = reader.ReadToEnd(); | 147 | string requestBody = reader.ReadToEnd(); |
245 | body.Close(); | ||
246 | reader.Close(); | 148 | reader.Close(); |
149 | requestStream.Close(); | ||
247 | 150 | ||
248 | //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType); | 151 | XmlRpcRequest xmlRprcRequest = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); |
249 | //Console.WriteLine(requestBody); | ||
250 | 152 | ||
251 | string responseString = ""; | 153 | string methodName = xmlRprcRequest.MethodName; |
252 | // Console.WriteLine("new request " + request.ContentType +" at "+ request.RawUrl); | 154 | |
253 | switch (request.ContentType) | 155 | XmlRpcResponse xmlRpcResponse; |
254 | { | ||
255 | case "text/xml": | ||
256 | // must be XML-RPC, so pass to the XML-RPC parser | ||
257 | |||
258 | responseString = ParseXMLRPC(requestBody); | ||
259 | responseString = Regex.Replace(responseString, "utf-16", "utf-8"); | ||
260 | |||
261 | response.AddHeader("Content-type", "text/xml"); | ||
262 | break; | ||
263 | |||
264 | //case "application/xml": | ||
265 | //case "application/octet-stream": | ||
266 | // // probably LLSD we hope, otherwise it should be ignored by the parser | ||
267 | // // responseString = ParseLLSDXML(requestBody); | ||
268 | // responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); | ||
269 | // response.AddHeader("Content-type", "application/xml"); | ||
270 | // break; | ||
271 | |||
272 | //case "application/x-www-form-urlencoded": | ||
273 | // // a form data POST so send to the REST parser | ||
274 | // responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); | ||
275 | // response.AddHeader("Content-type", "text/html"); | ||
276 | // break; | ||
277 | |||
278 | //case null: | ||
279 | // // must be REST or invalid crap, so pass to the REST parser | ||
280 | // responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod); | ||
281 | // response.AddHeader("Content-type", "text/html"); | ||
282 | // break; | ||
283 | 156 | ||
157 | XmlRpcMethod method; | ||
158 | if (this.m_rpcHandlers.TryGetValue(methodName, out method)) | ||
159 | { | ||
160 | xmlRpcResponse = method(xmlRprcRequest); | ||
284 | } | 161 | } |
162 | else | ||
163 | { | ||
164 | xmlRpcResponse = new XmlRpcResponse(); | ||
165 | Hashtable unknownMethodError = new Hashtable(); | ||
166 | unknownMethodError["reason"] = "XmlRequest"; ; | ||
167 | unknownMethodError["message"] = "Unknown Rpc Request ["+methodName+"]"; | ||
168 | unknownMethodError["login"] = "false"; | ||
169 | xmlRpcResponse.Value = unknownMethodError; | ||
170 | } | ||
171 | |||
172 | response.AddHeader("Content-type", "text/xml"); | ||
285 | 173 | ||
174 | string responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse); | ||
175 | |||
176 | // This must be absolutely fuggliest hack in this project. Don't just stand there, DO SOMETHING! | ||
177 | responseString = Regex.Replace(responseString, "utf-16", "utf-8"); | ||
178 | |||
286 | byte[] buffer = Encoding.UTF8.GetBytes(responseString); | 179 | byte[] buffer = Encoding.UTF8.GetBytes(responseString); |
287 | Stream output = response.OutputStream; | 180 | |
181 | |||
288 | response.SendChunked = false; | 182 | response.SendChunked = false; |
289 | response.ContentLength64 = buffer.Length; | 183 | response.ContentLength64 = buffer.Length; |
184 | response.ContentEncoding = Encoding.UTF8; | ||
290 | 185 | ||
291 | 186 | response.OutputStream.Write(buffer, 0, buffer.Length); | |
292 | 187 | response.OutputStream.Close(); | |
293 | output.Write(buffer, 0, buffer.Length); | ||
294 | output.Close(); | ||
295 | } | 188 | } |
296 | 189 | ||
297 | public void Start() | 190 | public void Start() |