Merge branch 'master' into diva-textures

This commit is contained in:
Melanie
2009-10-02 08:23:38 +01:00
356 changed files with 8423 additions and 5997 deletions

View File

@@ -168,7 +168,7 @@ namespace OpenSim.Framework.Servers.HttpServer
"[ASYNC REQUEST]: Request {0} {1} callback failed with exception {2}", verb, requestUrl, e);
}
}, null);
}, null);
}
}
}

View File

@@ -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;
@@ -256,13 +256,51 @@ namespace OpenSim.Framework.Servers.HttpServer
IHttpClientContext context = (IHttpClientContext)source;
IHttpRequest request = args.Request;
PollServiceEventArgs psEvArgs;
if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs))
{
m_PollServiceManager.Enqueue(new PollServiceHttpRequest(psEvArgs, context, request));
//DoHTTPGruntWork(psEvArgs.NoEvents(),new OSHttpResponse(new HttpResponse(context, request)));
PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request);
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);
}
else
{
@@ -275,49 +313,17 @@ 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);
HandleRequest(request,resp);
}
public virtual void HandleRequest(OSHttpRequest request, OSHttpResponse response)
@@ -332,6 +338,7 @@ 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))
@@ -342,10 +349,11 @@ namespace OpenSim.Framework.Servers.HttpServer
}
}
IRequestHandler requestHandler;
//response.KeepAlive = true;
response.SendChunked = false;
IRequestHandler requestHandler;
string path = request.RawUrl;
string handlerKey = GetHandlerKey(request.HttpMethod, path);
@@ -359,6 +367,7 @@ namespace OpenSim.Framework.Servers.HttpServer
response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type.
if (requestHandler is IStreamedRequestHandler)
{
IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler;
@@ -404,6 +413,7 @@ namespace OpenSim.Framework.Servers.HttpServer
// }
keysvals.Add("requestbody", requestBody);
keysvals.Add("headers",headervals);
if (keysvals.Contains("method"))
{
//m_log.Warn("[HTTP]: Contains Method");
@@ -702,7 +712,7 @@ namespace OpenSim.Framework.Servers.HttpServer
lock (m_rpcHandlers)
{
methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method);
}
}
if (methodWasFound)
{
@@ -726,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);
@@ -747,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);
@@ -917,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)
{
@@ -1354,7 +1368,7 @@ namespace OpenSim.Framework.Servers.HttpServer
bestMatch = pattern;
}
}
}
}
if (String.IsNullOrEmpty(bestMatch))
{
@@ -1466,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)
@@ -1575,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
{
@@ -1610,7 +1624,7 @@ namespace OpenSim.Framework.Servers.HttpServer
}
public void httpServerDisconnectMonitor(IHttpClientContext source, SocketError err)
{
{
switch (err)
{
case SocketError.NotSocket:
@@ -1621,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)
@@ -1648,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.");
}
}

View File

@@ -128,6 +128,6 @@ namespace OpenSim.Framework.Servers.HttpServer
string GetHTTP404(string host);
string GetHTTP500();
string GetHTTP500();
}
}

View File

@@ -30,20 +30,23 @@ using System.Collections;
using OpenMetaverse;
namespace OpenSim.Framework.Servers.HttpServer
{
public delegate bool HasEventsMethod(UUID pId);
public delegate void RequestMethod(UUID requestID, Hashtable request);
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();
public delegate Hashtable NoEventsMethod(UUID requestID, UUID pId);
public class PollServiceEventArgs : EventArgs
{
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 pRequest, HasEventsMethod pHasEvents, GetEventsMethod pGetEvents, NoEventsMethod pNoEvents,UUID pId)
{
Request = pRequest;
HasEvents = pHasEvents;
GetEvents = pGetEvents;
NoEvents = pNoEvents;

View File

@@ -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();
}
}
}

View File

@@ -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.RequestID, req.PollServiceArgs.Id), new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext));
}
m_requests.Clear();

View File

@@ -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(),
m_server.DoHTTPGruntWork(req.PollServiceArgs.NoEvents(req.RequestID, req.PollServiceArgs.Id),
new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request),req.HttpContext));
}
else

View File

@@ -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
{
/// <summary>
/// Perform a synchronous REST request.
/// </summary>
/// <param name="verb"></param>
/// <param name="requestUrl"></param>
/// <param name="obj"> </param>
/// <returns></returns>
///
/// <exception cref="System.Net.WebException">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</exception>
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();
int length = 0;
using (StreamWriter writer = new StreamWriter(buffer))
{
writer.Write(obj);
writer.Flush();
}
length = (int)obj.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;
}
}
}