From 2d9d25b367cd6a33747d2b647abfe57ede97e805 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 19 Sep 2009 17:33:57 +0100 Subject: Add the skeleton of the authentication connector and the forms data requester --- .../HttpServer/SynchronousRestFormsRequester.cs | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs new file mode 100644 index 0000000..0f0c790 --- /dev/null +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -0,0 +1,95 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.IO; +using System.Net; +using System.Text; +using System.Xml; +using System.Xml.Serialization; + +namespace OpenSim.Framework.Servers.HttpServer +{ + public class SynchronousRestFormsRequester + { + /// + /// Perform a synchronous REST request. + /// + /// + /// + /// + /// + /// + /// Thrown if we encounter a network issue while posting + /// the request. You'll want to make sure you deal with this as they're not uncommon + public static string MakeRequest(string verb, string requestUrl, string obj) + { + WebRequest request = WebRequest.Create(requestUrl); + request.Method = verb; + + if ((verb == "POST") || (verb == "PUT")) + { + request.ContentType = "text/www-form-urlencoded"; + + MemoryStream buffer = new MemoryStream(); + + using (StreamWriter writer = new StreamWriter(buffer)) + { + writer.WriteLine(obj); + writer.Flush(); + } + + int length = (int) buffer.Length; + request.ContentLength = length; + + Stream requestStream = request.GetRequestStream(); + requestStream.Write(buffer.ToArray(), 0, length); + } + + string respstring = String.Empty; + + try + { + using (WebResponse resp = request.GetResponse()) + { + if (resp.ContentLength > 0) + { + using (StreamReader reader = new StreamReader(resp.GetResponseStream())) + { + respstring = reader.ReadToEnd(); + } + } + } + } + catch (System.InvalidOperationException) + { + // This is what happens when there is invalid XML + } + return respstring; + } + } +} -- cgit v1.1 From 04170521f081bf009bf15f76451b119dc280a438 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 21 Sep 2009 14:59:31 +0100 Subject: Add a UUID param to NoEvents in PollServiceEventArgs to make it more generic --- OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs | 2 +- OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 2 +- OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index fed490e..ed387d1 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -34,7 +34,7 @@ namespace OpenSim.Framework.Servers.HttpServer public delegate Hashtable GetEventsMethod(UUID pId, string request); - public delegate Hashtable NoEventsMethod(); + public delegate Hashtable NoEventsMethod(UUID pId); public class PollServiceEventArgs : EventArgs { diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 4020190..db80f1d 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -130,7 +130,7 @@ namespace OpenSim.Framework.Servers.HttpServer foreach (object o in m_requests) { PollServiceHttpRequest req = (PollServiceHttpRequest) o; - m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(), new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); + m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.PollServiceArgs.Id), new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); } m_requests.Clear(); diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs index 41fb376..1e8706c 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs @@ -112,7 +112,7 @@ namespace OpenSim.Framework.Servers.HttpServer { if ((Environment.TickCount - req.RequestTime) > m_timeout) { - m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(), + m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.PollServiceArgs.Id), new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request),req.HttpContext)); } else -- cgit v1.1 From bc9e4cfd961e6ed0184165e4f3cbb770b47a8dff Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 21 Sep 2009 18:11:40 +0100 Subject: Add a RequestID (UUID.Random()) to the PollRequest and pass it to all even hander delegates. --- OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs | 6 +++--- OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs | 3 +++ OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs | 2 +- OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index ed387d1..61cb8aa 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -30,11 +30,11 @@ using System.Collections; using OpenMetaverse; namespace OpenSim.Framework.Servers.HttpServer { - public delegate bool HasEventsMethod(UUID pId); + public delegate bool HasEventsMethod(UUID requestID, UUID pId); - public delegate Hashtable GetEventsMethod(UUID pId, string request); + public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId, string request); - public delegate Hashtable NoEventsMethod(UUID pId); + public delegate Hashtable NoEventsMethod(UUID requestID, UUID pId); public class PollServiceEventArgs : EventArgs { diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs index ff7c1e8..553a7eb 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceHttpRequest.cs @@ -27,6 +27,7 @@ using System; using HttpServer; +using OpenMetaverse; namespace OpenSim.Framework.Servers.HttpServer { @@ -37,12 +38,14 @@ namespace OpenSim.Framework.Servers.HttpServer public readonly IHttpClientContext HttpContext; public readonly IHttpRequest Request; public readonly int RequestTime; + public readonly UUID RequestID; public PollServiceHttpRequest(PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest) { PollServiceArgs = pPollServiceArgs; HttpContext = pHttpContext; Request = pRequest; RequestTime = System.Environment.TickCount; + RequestID = UUID.Random(); } } } diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index db80f1d..1c54581 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -130,7 +130,7 @@ namespace OpenSim.Framework.Servers.HttpServer foreach (object o in m_requests) { PollServiceHttpRequest req = (PollServiceHttpRequest) o; - m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.PollServiceArgs.Id), new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); + m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext)); } m_requests.Clear(); diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs index 1e8706c..ce32443 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceWorkerThread.cs @@ -100,11 +100,11 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceHttpRequest req = m_request.Dequeue(); try { - if (req.PollServiceArgs.HasEvents(req.PollServiceArgs.Id)) + if (req.PollServiceArgs.HasEvents(req.RequestID, req.PollServiceArgs.Id)) { StreamReader str = new StreamReader(req.Request.Body); - Hashtable responsedata = req.PollServiceArgs.GetEvents(req.PollServiceArgs.Id, str.ReadToEnd()); + Hashtable responsedata = req.PollServiceArgs.GetEvents(req.RequestID, req.PollServiceArgs.Id, str.ReadToEnd()); m_server.DoHTTPGruntWork(responsedata, new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request),req.HttpContext)); } @@ -112,7 +112,7 @@ namespace OpenSim.Framework.Servers.HttpServer { if ((Environment.TickCount - req.RequestTime) > m_timeout) { - m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.PollServiceArgs.Id), + m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id), new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request),req.HttpContext)); } else -- cgit v1.1 From 69b76acce1abc87dbeafa6d0773637682ce4e1d4 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 21 Sep 2009 19:46:29 +0100 Subject: Make the poll service handler call the handler method on incoming requests. --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 39 +++++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 771ae05..b73557f 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -260,7 +260,9 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceEventArgs psEvArgs; if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs)) { + OSHttpRequest req = new OSHttpRequest(context, request); + HandleRequest(req, null); m_PollServiceManager.Enqueue(new PollServiceHttpRequest(psEvArgs, context, request)); //DoHTTPGruntWork(psEvArgs.NoEvents(),new OSHttpResponse(new HttpResponse(context, request))); } @@ -332,19 +334,26 @@ namespace OpenSim.Framework.Servers.HttpServer // probability event; if a request is matched it is normally expected to be // handled //m_log.Debug("[BASE HTTP SERVER]: Handling Request" + request.RawUrl); - IHttpAgentHandler agentHandler; - if (TryGetAgentHandler(request, response, out agentHandler)) + // If the response is null, then we're not going to respond here. This case + // triggers when we're at the head of a HTTP poll + // + if (response != null) { - if (HandleAgentRequest(agentHandler, request, response)) + IHttpAgentHandler agentHandler; + + if (TryGetAgentHandler(request, response, out agentHandler)) { - return; + if (HandleAgentRequest(agentHandler, request, response)) + { + return; + } } - } + //response.KeepAlive = true; + response.SendChunked = false; + } IRequestHandler requestHandler; - //response.KeepAlive = true; - response.SendChunked = false; string path = request.RawUrl; string handlerKey = GetHandlerKey(request.HttpMethod, path); @@ -357,7 +366,9 @@ namespace OpenSim.Framework.Servers.HttpServer // Okay, so this is bad, but should be considered temporary until everything is IStreamHandler. byte[] buffer = null; - response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type. + if (response != null) + response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type. + if (requestHandler is IStreamedRequestHandler) { @@ -411,7 +422,12 @@ namespace OpenSim.Framework.Servers.HttpServer //m_log.Warn("[HTTP]: " + requestBody); } - DoHTTPGruntWork(HTTPRequestHandler.Handle(path, keysvals), response); + // If we're not responding, we dont' care about the reply + // + if (response == null) + HTTPRequestHandler.Handle(path, keysvals); + else + DoHTTPGruntWork(HTTPRequestHandler.Handle(path, keysvals), response); return; } else @@ -426,6 +442,11 @@ namespace OpenSim.Framework.Servers.HttpServer } } + // The handler has run and we're not yet ready to respond, bail + // + if (response == null) + return; + request.InputStream.Close(); // HTTP IN support. The script engine taes it from here -- cgit v1.1 From 61aaf3532ae0de94ea39ee7dc4b13a31cd149b40 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 21 Sep 2009 20:10:26 +0100 Subject: Add X-PollServiceID pseudo-header to the request handling for polls --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index b73557f..5a7f20a 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -262,8 +262,10 @@ namespace OpenSim.Framework.Servers.HttpServer { OSHttpRequest req = new OSHttpRequest(context, request); + PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request); + req.Headers["X-PollServiceID"] = psreq.RequestID.ToString(); HandleRequest(req, null); - m_PollServiceManager.Enqueue(new PollServiceHttpRequest(psEvArgs, context, request)); + m_PollServiceManager.Enqueue(psreq); //DoHTTPGruntWork(psEvArgs.NoEvents(),new OSHttpResponse(new HttpResponse(context, request))); } else -- cgit v1.1 From b6b8a18d377999e02c65cdc5d0188d530dc1498b Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 21 Sep 2009 20:21:01 +0100 Subject: Add the headers collection to the keysvals for HTT requests --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 5a7f20a..5d83e34 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -417,6 +417,7 @@ namespace OpenSim.Framework.Servers.HttpServer // } keysvals.Add("requestbody", requestBody); + keysvals.Add("headers",headervals); if (keysvals.Contains("method")) { //m_log.Warn("[HTTP]: Contains Method"); -- cgit v1.1 From 06871d51dd47cd59185e2123f8235b4d79aee02c Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 22 Sep 2009 05:13:50 +0100 Subject: Disable the handler execution for poll services until the ramifications can be studied --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 5d83e34..5c9fa9b 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -260,11 +260,11 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceEventArgs psEvArgs; if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs)) { - OSHttpRequest req = new OSHttpRequest(context, request); +// OSHttpRequest req = new OSHttpRequest(context, request); PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request); - req.Headers["X-PollServiceID"] = psreq.RequestID.ToString(); - HandleRequest(req, null); +// req.Headers["X-PollServiceID"] = psreq.RequestID.ToString(); +// HandleRequest(req, null); m_PollServiceManager.Enqueue(psreq); //DoHTTPGruntWork(psEvArgs.NoEvents(),new OSHttpResponse(new HttpResponse(context, request))); } -- cgit v1.1 From c5be401d46dfbb1e47927b4123130c43c6a054b5 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 22 Sep 2009 05:24:22 +0100 Subject: Remove support for executing a handler on poll. It caused other issues --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 38 +++++++--------------- 1 file changed, 11 insertions(+), 27 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 5c9fa9b..0198960 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -337,24 +337,19 @@ namespace OpenSim.Framework.Servers.HttpServer // handled //m_log.Debug("[BASE HTTP SERVER]: Handling Request" + request.RawUrl); - // If the response is null, then we're not going to respond here. This case - // triggers when we're at the head of a HTTP poll - // - if (response != null) - { - IHttpAgentHandler agentHandler; + IHttpAgentHandler agentHandler; - if (TryGetAgentHandler(request, response, out agentHandler)) + if (TryGetAgentHandler(request, response, out agentHandler)) + { + if (HandleAgentRequest(agentHandler, request, response)) { - if (HandleAgentRequest(agentHandler, request, response)) - { - return; - } + return; } - - //response.KeepAlive = true; - response.SendChunked = false; } + + //response.KeepAlive = true; + response.SendChunked = false; + IRequestHandler requestHandler; string path = request.RawUrl; @@ -368,8 +363,7 @@ namespace OpenSim.Framework.Servers.HttpServer // Okay, so this is bad, but should be considered temporary until everything is IStreamHandler. byte[] buffer = null; - if (response != null) - response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type. + response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type. if (requestHandler is IStreamedRequestHandler) @@ -425,12 +419,7 @@ namespace OpenSim.Framework.Servers.HttpServer //m_log.Warn("[HTTP]: " + requestBody); } - // If we're not responding, we dont' care about the reply - // - if (response == null) - HTTPRequestHandler.Handle(path, keysvals); - else - DoHTTPGruntWork(HTTPRequestHandler.Handle(path, keysvals), response); + DoHTTPGruntWork(HTTPRequestHandler.Handle(path, keysvals), response); return; } else @@ -445,11 +434,6 @@ namespace OpenSim.Framework.Servers.HttpServer } } - // The handler has run and we're not yet ready to respond, bail - // - if (response == null) - return; - request.InputStream.Close(); // HTTP IN support. The script engine taes it from here -- cgit v1.1 From dafe5bf05f6d85d4140a0b733f0fbf9a5c43cf37 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 22 Sep 2009 06:19:02 +0100 Subject: Completely remove the prior implementation of the request event handling on poll handlers. Introduce a new delegate on the PollServiceEventArgs that allow access to the request headers and body. --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 78 +++++++++++----------- .../Servers/HttpServer/PollServiceEventArgs.cs | 5 +- 2 files changed, 44 insertions(+), 39 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 0198960..db87958 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -256,17 +256,51 @@ namespace OpenSim.Framework.Servers.HttpServer IHttpClientContext context = (IHttpClientContext)source; IHttpRequest request = args.Request; - PollServiceEventArgs psEvArgs; + if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs)) { -// OSHttpRequest req = new OSHttpRequest(context, request); - PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request); -// req.Headers["X-PollServiceID"] = psreq.RequestID.ToString(); -// HandleRequest(req, null); + + if (psEvArgs.Request != null) + { + OSHttpRequest req = new OSHttpRequest(context, request); + + Stream requestStream = req.InputStream; + + Encoding encoding = Encoding.UTF8; + StreamReader reader = new StreamReader(requestStream, encoding); + + string requestBody = reader.ReadToEnd(); + + Hashtable keysvals = new Hashtable(); + Hashtable headervals = new Hashtable(); + + string[] querystringkeys = req.QueryString.AllKeys; + string[] rHeaders = req.Headers.AllKeys; + + keysvals.Add("body", requestBody); + keysvals.Add("uri", req.RawUrl); + keysvals.Add("content-type", req.ContentType); + keysvals.Add("http-method", req.HttpMethod); + + foreach (string queryname in querystringkeys) + { + keysvals.Add(queryname, req.QueryString[queryname]); + } + + foreach (string headername in rHeaders) + { + headervals[headername] = req.Headers[headername]; + } + + keysvals.Add("headers",headervals); + keysvals.Add("querystringkeys", querystringkeys); + + psEvArgs.Request(psreq.RequestID, keysvals); + } + m_PollServiceManager.Enqueue(psreq); - //DoHTTPGruntWork(psEvArgs.NoEvents(),new OSHttpResponse(new HttpResponse(context, request))); } else { @@ -279,48 +313,16 @@ namespace OpenSim.Framework.Servers.HttpServer { OSHttpRequest req = new OSHttpRequest(context, request); OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context); - //resp.KeepAlive = req.KeepAlive; - //m_log.Info("[Debug BASE HTTP SERVER]: Got Request"); - //HttpServerContextObj objstate= new HttpServerContextObj(req,resp); - //ThreadPool.QueueUserWorkItem(new WaitCallback(ConvertIHttpClientContextToOSHttp), (object)objstate); HandleRequest(req, resp); } public void ConvertIHttpClientContextToOSHttp(object stateinfo) { HttpServerContextObj objstate = (HttpServerContextObj)stateinfo; - //OSHttpRequest request = new OSHttpRequest(objstate.context,objstate.req); - //OSHttpResponse resp = new OSHttpResponse(new HttpServer.HttpResponse(objstate.context, objstate.req)); OSHttpRequest request = objstate.oreq; OSHttpResponse resp = objstate.oresp; - //OSHttpResponse resp = new OSHttpResponse(new HttpServer.HttpResponse(objstate.context, objstate.req)); - - /* - request.AcceptTypes = objstate.req.AcceptTypes; - request.ContentLength = (long)objstate.req.ContentLength; - request.Headers = objstate.req.Headers; - request.HttpMethod = objstate.req.Method; - request.InputStream = objstate.req.Body; - foreach (string str in request.Headers) - { - if (str.ToLower().Contains("content-type: ")) - { - request.ContentType = str.Substring(13, str.Length - 13); - break; - } - } - //request.KeepAlive = objstate.req. - foreach (HttpServer.HttpInput httpinput in objstate.req.QueryString) - { - request.QueryString.Add(httpinput.Name, httpinput[httpinput.Name]); - } - - //request.Query = objstate.req.//objstate.req.QueryString; - //foreach ( - //request.QueryString = objstate.req.QueryString; - */ HandleRequest(request,resp); } diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index 61cb8aa..7ed9e5c 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -30,6 +30,7 @@ using System.Collections; using OpenMetaverse; namespace OpenSim.Framework.Servers.HttpServer { + public delegate void RequestMethod(UUID requestID, Hashtable request); public delegate bool HasEventsMethod(UUID requestID, UUID pId); public delegate Hashtable GetEventsMethod(UUID requestID, UUID pId, string request); @@ -41,9 +42,11 @@ namespace OpenSim.Framework.Servers.HttpServer public HasEventsMethod HasEvents; public GetEventsMethod GetEvents; public NoEventsMethod NoEvents; + public RequestMethod Request; public UUID Id; - public PollServiceEventArgs(HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,UUID pId) + public PollServiceEventArgs(RequestMethod Request, HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,UUID pId) { + Request = Request; HasEvents = pHasEvents; GetEvents = pGetEvents; NoEvents = pNoEvents; -- cgit v1.1 From 97c18caa766e2dd72b152b78827ef554f2054f8c Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 22 Sep 2009 17:04:34 +0100 Subject: Thank you, Intari, for a patch that implements the missing pieces of Http-in and makes the host name for URL generation configurable. Applied with changes: llGetSimulatorHostname was not changed, because the change breaks existing behavior and carries a data exposure risk. That value needs to be configurable, the proposed fixed change is not acceptable. --- OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs index 7ed9e5c..9d512c6 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceEventArgs.cs @@ -44,9 +44,9 @@ namespace OpenSim.Framework.Servers.HttpServer public NoEventsMethod NoEvents; public RequestMethod Request; public UUID Id; - public PollServiceEventArgs(RequestMethod Request, HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,UUID pId) + public PollServiceEventArgs(RequestMethod pRequest, HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,UUID pId) { - Request = Request; + Request = pRequest; HasEvents = pHasEvents; GetEvents = pGetEvents; NoEvents = pNoEvents; -- cgit v1.1 From e67341f24c3706be09d2c0c5d2d4ddeba1ddd089 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 24 Sep 2009 15:02:55 +0100 Subject: minor: replace xmlprc 'no method found' magic number with constant from xmlrpc library --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index db87958..01990fa 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -736,8 +736,11 @@ namespace OpenSim.Framework.Servers.HttpServer else { xmlRpcResponse = new XmlRpcResponse(); + // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php - xmlRpcResponse.SetFault(-32601, String.Format("Requested method [{0}] not found", methodName)); + xmlRpcResponse.SetFault( + XmlRpcErrorCodes.SERVER_ERROR_METHOD, + String.Format("Requested method [{0}] not found", methodName)); } responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse); @@ -757,6 +760,7 @@ namespace OpenSim.Framework.Servers.HttpServer response.SendChunked = false; response.ContentLength64 = buf.Length; response.ContentEncoding = Encoding.UTF8; + try { response.OutputStream.Write(buf, 0, buf.Length); -- cgit v1.1 From dd3d52ae1faefbca85e2fe8d8cea67f7db4005ac Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 24 Sep 2009 13:33:58 -0700 Subject: Added test GridClient, which allowed me to remove a few bugs out of the new code. --- OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index 0f0c790..ebb2691 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -56,14 +56,14 @@ namespace OpenSim.Framework.Servers.HttpServer request.ContentType = "text/www-form-urlencoded"; MemoryStream buffer = new MemoryStream(); - + int length = 0; using (StreamWriter writer = new StreamWriter(buffer)) { writer.WriteLine(obj); writer.Flush(); + length = (int)buffer.Length; } - int length = (int) buffer.Length; request.ContentLength = length; Stream requestStream = request.GetRequestStream(); -- cgit v1.1 From 69da82b39fbb9952e29f57ff08f731b14f969f04 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 28 Sep 2009 06:44:57 -0700 Subject: Bug fix in SynchronousRestFormsRequester -- Write instead of WriteLine, which was causing an extra \n to be written into the buffer. --- OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index ebb2691..a0d4008 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -59,11 +59,11 @@ namespace OpenSim.Framework.Servers.HttpServer int length = 0; using (StreamWriter writer = new StreamWriter(buffer)) { - writer.WriteLine(obj); + writer.Write(obj); writer.Flush(); - length = (int)buffer.Length; } + length = (int)obj.Length; request.ContentLength = length; Stream requestStream = request.GetRequestStream(); -- cgit v1.1 From ee205e7e812e170f670e690a4e0fa9caa652f226 Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Thu, 1 Oct 2009 01:00:09 +0900 Subject: Formatting cleanup. --- .../HttpServer/AsynchronousRestObjectRequester.cs | 2 +- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 22 +++++++++++----------- .../Servers/HttpServer/Interfaces/IHttpServer.cs | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs index fe69ad3..5afa110 100644 --- a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs @@ -168,7 +168,7 @@ namespace OpenSim.Framework.Servers.HttpServer "[ASYNC REQUEST]: Request {0} {1} callback failed with exception {2}", verb, requestUrl, e); } - }, null); + }, null); } } } diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 01990fa..6c63c6c 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -110,7 +110,7 @@ namespace OpenSim.Framework.Servers.HttpServer public BaseHttpServer(uint port, bool ssl) : this (port) { - m_ssl = ssl; + m_ssl = ssl; } public BaseHttpServer(uint port, bool ssl, uint sslport, string CN) : this (port, ssl) @@ -156,7 +156,7 @@ namespace OpenSim.Framework.Servers.HttpServer lock (m_rpcHandlers) { m_rpcHandlers[method] = handler; - m_rpcHandlersKeepAlive[method] = keepAlive; // default + m_rpcHandlersKeepAlive[method] = keepAlive; // default } return true; @@ -323,7 +323,7 @@ namespace OpenSim.Framework.Servers.HttpServer OSHttpRequest request = objstate.oreq; OSHttpResponse resp = objstate.oresp; - HandleRequest(request,resp); + HandleRequest(request,resp); } public virtual void HandleRequest(OSHttpRequest request, OSHttpResponse response) @@ -712,7 +712,7 @@ namespace OpenSim.Framework.Servers.HttpServer lock (m_rpcHandlers) { methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method); - } + } if (methodWasFound) { @@ -931,7 +931,7 @@ namespace OpenSim.Framework.Servers.HttpServer } catch (IOException e) { - m_log.DebugFormat("[BASE HTTP SERVER] LLSD IOException {0}.", e); + m_log.DebugFormat("[BASE HTTP SERVER] LLSD IOException {0}.", e); } catch (SocketException e) { @@ -1368,7 +1368,7 @@ namespace OpenSim.Framework.Servers.HttpServer bestMatch = pattern; } } - } + } if (String.IsNullOrEmpty(bestMatch)) { @@ -1480,7 +1480,7 @@ namespace OpenSim.Framework.Servers.HttpServer { m_log.Warn("[BASE HTTP SERVER] XmlRpcRequest issue: " + e.Message); } - } + } } public void SendHTML404(OSHttpResponse response, string host) @@ -1589,7 +1589,7 @@ namespace OpenSim.Framework.Servers.HttpServer // if you want more detailed trace information from the HttpServer //m_httpListener2.UseTraceLogs = true; - //m_httpListener2.DisconnectHandler = httpServerDisconnectMonitor; + //m_httpListener2.DisconnectHandler = httpServerDisconnectMonitor; } else { @@ -1624,7 +1624,7 @@ namespace OpenSim.Framework.Servers.HttpServer } public void httpServerDisconnectMonitor(IHttpClientContext source, SocketError err) - { + { switch (err) { case SocketError.NotSocket: @@ -1635,7 +1635,7 @@ namespace OpenSim.Framework.Servers.HttpServer } public void httpServerException(object source, Exception exception) - { + { m_log.ErrorFormat("[HTTPSERVER]: {0} had an exception {1}", source.ToString(), exception.ToString()); /* if (HTTPDRunning)// && NotSocketErrors > 5) @@ -1662,7 +1662,7 @@ namespace OpenSim.Framework.Servers.HttpServer } catch (NullReferenceException) { - m_log.Warn("[BASEHTTPSERVER]: Null Reference when stopping HttpServer."); + m_log.Warn("[BASEHTTPSERVER]: Null Reference when stopping HttpServer."); } } diff --git a/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs index 1bdf4fa..d13408d 100644 --- a/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs @@ -128,6 +128,6 @@ namespace OpenSim.Framework.Servers.HttpServer string GetHTTP404(string host); - string GetHTTP500(); + string GetHTTP500(); } } -- cgit v1.1