/// <summary>Handle an HTTP request containing an XML-RPC request.</summary>
        /// <remarks>This method deserializes the XML-RPC request, invokes the
        /// described method, serializes the response (or fault) and sends the XML-RPC response
        /// back as a valid HTTP page.
        /// </remarks>
        /// <param name="httpReq"><c>SimpleHttpRequest</c> containing the request.</param>
        public void Respond(SimpleHttpRequest httpReq)
        {
            XmlRpcRequest  xmlRpcReq  = (XmlRpcRequest)_deserializer.Deserialize(httpReq.Input);
            XmlRpcResponse xmlRpcResp = new XmlRpcResponse();

            try
            {
                xmlRpcResp.Value = _server.Invoke(xmlRpcReq);
            }
            catch (XmlRpcException e)
            {
                xmlRpcResp.SetFault(e.FaultCode, e.FaultString);
            }
            catch (Exception e2)
            {
                xmlRpcResp.SetFault(XmlRpcErrorCodes.APPLICATION_ERROR,
                                    XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": " + e2.Message);
            }

            if (Logger.Delegate != null)
            {
                Logger.WriteEntry(xmlRpcResp.ToString(), LogLevel.Information);
            }

            XmlRpcServer.HttpHeader(httpReq.Protocol, "text/xml", 0, " 200 OK", httpReq.Output);
            httpReq.Output.Flush();
            XmlTextWriter xml = new XmlTextWriter(httpReq.Output);

            _serializer.Serialize(xml, xmlRpcResp);
            xml.Flush();
            httpReq.Output.Flush();
        }
    /// <summary>Handle an HTTP request containing an XML-RPC request.</summary>
    /// <remarks>This method deserializes the XML-RPC request, invokes the 
    /// described method, serializes the response (or fault) and sends the XML-RPC response
    /// back as a valid HTTP page.
    /// </remarks>
    /// <param name="httpReq"><c>SimpleHttpRequest</c> containing the request.</param>
    public void Respond(SimpleHttpRequest httpReq)
      {
	XmlRpcRequest xmlRpcReq = (XmlRpcRequest)_deserializer.Deserialize(httpReq.Input);
	XmlRpcResponse xmlRpcResp = new XmlRpcResponse();

	try
	  {
	    xmlRpcResp.Value = _server.Invoke(xmlRpcReq);
	  }
	catch (XmlRpcException e)
	  {
	    xmlRpcResp.SetFault(e.FaultCode, e.FaultString);
	  }
	catch (Exception e2)
	  {
	    xmlRpcResp.SetFault(XmlRpcErrorCodes.APPLICATION_ERROR, 
			  XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": " + e2.Message);
	  }

	if (Logger.Delegate != null)
	  Logger.WriteEntry(xmlRpcResp.ToString(), LogLevel.Information);

	XmlRpcServer.HttpHeader(httpReq.Protocol, "text/xml", 0, " 200 OK", httpReq.Output);
	httpReq.Output.Flush();
	XmlTextWriter xml = new XmlTextWriter(httpReq.Output);
	_serializer.Serialize(xml, xmlRpcResp);
	xml.Flush();
	httpReq.Output.Flush();
      }
Exemple #3
0
        public IList multiCall(IList calls)
        {
            IList          responses = new ArrayList();
            XmlRpcResponse fault     = new XmlRpcResponse();

            foreach (IDictionary call in calls)
            {
                try
                {
                    XmlRpcRequest req = new XmlRpcRequest((String)call[XmlRpcXmlTokens.METHOD_NAME],
                                                          (ArrayList)call[XmlRpcXmlTokens.PARAMS]);
                    Object results  = _server.Invoke(req);
                    IList  response = new ArrayList();
                    response.Add(results);
                    responses.Add(response);
                }
                catch (XmlRpcException e)
                {
                    fault.SetFault(e.FaultCode, e.FaultString);
                    responses.Add(fault.Value);
                }
                catch (Exception e2)
                {
                    fault.SetFault(XmlRpcErrorCodes.APPLICATION_ERROR,
                                   XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": " + e2.Message);
                    responses.Add(fault.Value);
                }
            }

            return(responses);
        }
        public XmlRpcResponse GenerateKeyMethod(XmlRpcRequest request, IPEndPoint remoteClient)
        {
            XmlRpcResponse response = new XmlRpcResponse();

            if (request.Params.Count < 2)
            {
                response.IsFault = true;
                response.SetFault(-1, "Invalid parameters");
                return response;
            }

            // Verify the key of who's calling
            UUID userID = UUID.Zero;
            string authKey = string.Empty;
            UUID.TryParse((string)request.Params[0], out userID);
            authKey = (string)request.Params[1];

            m_log.InfoFormat("[AUTH HANDLER] GenerateKey called with authToken {0}", authKey);
            string newKey = string.Empty;

            newKey = m_LocalService.GetKey(userID, authKey.ToString());
 
            response.Value = (string)newKey;
            return response;
        }
        public void HttpPost(SimpleHttpRequest req)
        {
            XmlRpcRequest rpc = XmlRpcRequestDeserializer.Parse(req.Input);

            XmlRpcResponse resp   = new XmlRpcResponse();
            Object         target = _handlers[rpc.MethodNameObject];

            if (target == null)
            {
                resp.SetFault(-1, "Object " + rpc.MethodNameObject + " not registered.");
            }
            else
            {
                try
                {
                    resp.Value = rpc.Invoke(target);
                }
                catch (XmlRpcException e)
                {
                    resp.SetFault(e.Code, e.Message);
                }
                catch (Exception e2)
                {
                    resp.SetFault(-1, e2.Message);
                }
            }

            Logger.WriteEntry(resp.ToString(), EventLogEntryType.Information);

            SendHeader(req.Protocol, "text/xml", 0, " 200 OK", req.Output);
            req.Output.Flush();
            XmlTextWriter xml = new XmlTextWriter(req.Output);

            XmlRpcResponseSerializer.Serialize(xml, resp);
            xml.Flush();
            req.Output.Flush();
        }
Exemple #6
0
        public IList multiCall(IList calls)
        {
            IList responses = new ArrayList();
            var   fault     = new XmlRpcResponse();

            foreach (IDictionary call in calls)
            {
                try
                {
                    var req = new XmlRpcRequest((string)call[XmlRpcXmlTokens.METHOD_NAME],
                                                (ArrayList)call[XmlRpcXmlTokens.PARAMS]);
                    var   results  = _server.Invoke(req);
                    IList response = new ArrayList();
                    response.Add(results);
                    responses.Add(response);
                }
                catch (XmlRpcException e)
                {
                    fault.SetFault(e.FaultCode, e.FaultString);
                    responses.Add(fault.Value);
                }
            }
        /// <summary>
        ///     Try all the registered xmlrpc handlers when an xmlrpc request is received.
        ///     Sends back an XMLRPC unknown request response if no handler is registered for the requested method.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private byte[] HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
        {
            string requestBody = HttpServerHandlerHelpers.ReadString(request.InputStream);

            requestBody = requestBody.Replace("<base64></base64>", "");
            string responseString = String.Empty;
            XmlRpcRequest xmlRprcRequest = null;

            try
            {
                xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody);
            }
            catch (XmlException e)
            {
                MainConsole.Instance.WarnFormat(
                    "[BASE HTTP SERVER]: Got XMLRPC request with invalid XML from {0}.  XML was '{1}'.  Sending blank response.  Exception: {2}",
                    request.RemoteIPEndPoint, requestBody, e.ToString());
            }

            if (xmlRprcRequest != null)
            {
                string methodName = xmlRprcRequest.MethodName;
                if (methodName != null)
                {
                    xmlRprcRequest.Params.Add(request.RemoteIPEndPoint); // Param[1]
                    XmlRpcResponse xmlRpcResponse;

                    XmlRpcMethod method;
                    bool methodWasFound;
                    lock (m_rpcHandlers)
                        methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method);

                    if (methodWasFound)
                    {
                        xmlRprcRequest.Params.Add(request.Url); // Param[2]

                        string xff = "X-Forwarded-For";
                        string xfflower = xff.ToLower();
                        foreach (string s in request.Headers.AllKeys)
                        {
                            if (s != null && s.Equals(xfflower))
                            {
                                xff = xfflower;
                                break;
                            }
                        }
                        xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3]

                        try
                        {
                            xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
                        }
                        catch (Exception e)
                        {
                            string errorMessage
                                = String.Format(
                                    "Requested method [{0}] from {1} threw exception: {2} {3}",
                                    methodName, request.RemoteIPEndPoint.Address, e.Message, e.StackTrace);

                            MainConsole.Instance.ErrorFormat("[BASE HTTP SERVER]: {0}", errorMessage);

                            // if the registered XmlRpc method threw an exception, we pass a fault-code along
                            xmlRpcResponse = new XmlRpcResponse();

                            // Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                            xmlRpcResponse.SetFault(-32603, errorMessage);
                        }
                    }
                    else
                    {
                        xmlRpcResponse = new XmlRpcResponse();

                        // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                        xmlRpcResponse.SetFault(
                            XmlRpcErrorCodes.SERVER_ERROR_METHOD,
                            String.Format("Requested method [{0}] not found", methodName));
                    }

                    response.ContentType = "text/xml";
                    responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse);
                }
                else
                {
                    //HandleLLSDRequests(request, response);
                    response.ContentType = "text/plain";
                    response.StatusCode = 404;
                    response.StatusDescription = "Not Found";
                    responseString = "Not found";

                    MainConsole.Instance.ErrorFormat(
                        "[BASE HTTP SERVER]: Handler not found for http request {0} {1}",
                        request.HttpMethod, request.Url.PathAndQuery);
                }
            }

            byte[] buffer = Encoding.UTF8.GetBytes(responseString);

            response.SendChunked = false;
            response.ContentEncoding = Encoding.UTF8;

            return buffer;
        }
Exemple #8
0
//        private bool TryGetAgentHandler(OSHttpRequest request, OSHttpResponse response, out IHttpAgentHandler agentHandler)
//        {
//            agentHandler = null;
//            
//            lock (m_agentHandlers)
//            {
//                foreach (IHttpAgentHandler handler in m_agentHandlers.Values)
//                {
//                    if (handler.Match(request, response))
//                    {
//                        agentHandler = handler;
//                        return true;
//                    }
//                }
//            }
//
//            return false;
//        }

        /// <summary>
        /// Try all the registered xmlrpc handlers when an xmlrpc request is received.
        /// Sends back an XMLRPC unknown request response if no handler is registered for the requested method.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private byte[] HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
        {
            Stream requestStream = request.InputStream;

            Encoding encoding = Encoding.UTF8;
            StreamReader reader = new StreamReader(requestStream, encoding);

            string requestBody = reader.ReadToEnd();
            reader.Close();
            requestStream.Close();
            //m_log.Debug(requestBody);
            requestBody = requestBody.Replace("<base64></base64>", "");
            string responseString = String.Empty;
            XmlRpcRequest xmlRprcRequest = null;

            try
            {
                xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody);
            }
            catch (XmlException e)
            {
                if (DebugLevel >= 1)
                {
                    if (DebugLevel >= 2)
                        m_log.Warn(
                            string.Format(
                                "[BASE HTTP SERVER]: Got XMLRPC request with invalid XML from {0}.  XML was '{1}'.  Sending blank response.  Exception ",
                                request.RemoteIPEndPoint, requestBody),
                            e);
                    else
                    {
                        m_log.WarnFormat(
                            "[BASE HTTP SERVER]: Got XMLRPC request with invalid XML from {0}, length {1}.  Sending blank response.",
                            request.RemoteIPEndPoint, requestBody.Length);
                    }
                }
            }

            if (xmlRprcRequest != null)
            {
                string methodName = xmlRprcRequest.MethodName;
                if (methodName != null)
                {
                    xmlRprcRequest.Params.Add(request.RemoteIPEndPoint); // Param[1]
                    XmlRpcResponse xmlRpcResponse;

                    XmlRpcMethod method;
                    bool methodWasFound;
                    bool keepAlive = false;
                    lock (m_rpcHandlers)
                    {
                        methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method);
                        if (methodWasFound)
                            keepAlive = m_rpcHandlersKeepAlive[methodName];
                    }

                    if (methodWasFound)
                    {
                        xmlRprcRequest.Params.Add(request.Url); // Param[2]

                        string xff = "X-Forwarded-For";
                        string xfflower = xff.ToLower();
                        foreach (string s in request.Headers.AllKeys)
                        {
                            if (s != null && s.Equals(xfflower))
                            {
                                xff = xfflower;
                                break;
                            }
                        }
                        xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3]

                        try
                        {
                            xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
                        }
                        catch(Exception e)
                        {
                            string errorMessage
                                = String.Format(
                                    "Requested method [{0}] from {1} threw exception: {2} {3}",
                                    methodName, request.RemoteIPEndPoint.Address, e.Message, e.StackTrace);

                            m_log.ErrorFormat("[BASE HTTP SERVER]: {0}", errorMessage);

                            // if the registered XmlRpc method threw an exception, we pass a fault-code along
                            xmlRpcResponse = new XmlRpcResponse();

                            // Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                            xmlRpcResponse.SetFault(-32603, errorMessage);
                        }

                        // if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here
                        response.KeepAlive = keepAlive;
                    }
                    else
                    {
                        xmlRpcResponse = new XmlRpcResponse();

                        // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                        xmlRpcResponse.SetFault(
                            XmlRpcErrorCodes.SERVER_ERROR_METHOD,
                            String.Format("Requested method [{0}] not found", methodName));
                    }

                    response.ContentType = "text/xml";
                    responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse);
                }
                else
                {
                    //HandleLLSDRequests(request, response);
                    response.ContentType = "text/plain";
                    response.StatusCode = 404;
                    response.StatusDescription = "Not Found";
                    response.ProtocolVersion = "HTTP/1.0";
                    responseString = "Not found";
                    response.KeepAlive = false;

                    m_log.ErrorFormat(
                        "[BASE HTTP SERVER]: Handler not found for http request {0} {1}",
                        request.HttpMethod, request.Url.PathAndQuery);
                }
            }

            byte[] buffer = Encoding.UTF8.GetBytes(responseString);

            response.SendChunked = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;

            return buffer;
        }
        public XmlRpcResponse currencyNotify(XmlRpcRequest request, IPEndPoint ep)
        {
            XmlRpcResponse r = new XmlRpcResponse();
            try
            {
                Hashtable requestData = (Hashtable)request.Params[0];
                Hashtable communicationData = (Hashtable)request.Params[1];

                #region // Debug
            #if DEBUG
                m_log.Debug("[OMCURRENCY]: currencyNotify(...)");
                foreach (DictionaryEntry requestDatum in requestData)
                {
                    m_log.Debug("[OMCURRENCY]:   " + requestDatum.Key.ToString() + " " + (string)requestDatum.Value);
                }
                foreach (DictionaryEntry communicationDatum in communicationData)
                {
                    m_log.Debug("[OMCURRENCY]:   " + communicationDatum.Key.ToString() + " " + (string)communicationDatum.Value);
                }
            #endif
                #endregion

                String method = (string)requestData["method"];
                requestData.Remove("method");
                if (CommunicationHelpers.ValidateRequest(communicationData, requestData, gatewayURL))
                {
                    switch (method)
                    {
                        case "notifyDeliverObject": r.Value = deliverObject(requestData);
                            break;
                        case "notifyOnObjectPaid": r.Value = onObjectPaid(requestData);
                            break;
                        case "notifyLandBuy": r.Value = landBuy(requestData);
                            break;
                        case "notifyChangePrimPermission": r.Value = changePrimPermissions(requestData);
                            break;
                        case "notifyBalanceUpdate": r.Value = balanceUpdate(requestData);
                            break;
                        case "notifyGetVersion": r.Value = GetVersion(requestData);
                            break;
                        default: m_log.ErrorFormat("[{0}]: Method {1} is not supported", Name, method);
                            break;
                    }
                }
                else
                {
                    throw new Exception("Hash values do not match");
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[{0}]: genericNotify() Exception: {1} - {2}", Name, e.Message, e.StackTrace);
                r.SetFault(1, "Could not parse the requested method");
            }
            return r;
        }
Exemple #10
0
//        private bool TryGetAgentHandler(OSHttpRequest request, OSHttpResponse response, out IHttpAgentHandler agentHandler)
//        {
//            agentHandler = null;
//            
//            lock (m_agentHandlers)
//            {
//                foreach (IHttpAgentHandler handler in m_agentHandlers.Values)
//                {
//                    if (handler.Match(request, response))
//                    {
//                        agentHandler = handler;
//                        return true;
//                    }
//                }
//            }
//
//            return false;
//        }

        /// <summary>
        /// Try all the registered xmlrpc handlers when an xmlrpc request is received.
        /// Sends back an XMLRPC unknown request response if no handler is registered for the requested method.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private byte[] HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
        {
            String requestBody;

            Stream requestStream = request.InputStream;
            Stream innerStream = null;
            try
            {
                if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip"))
                {
                    innerStream = requestStream;
                    requestStream = new GZipStream(innerStream, System.IO.Compression.CompressionMode.Decompress);
                }

                using (StreamReader reader = new StreamReader(requestStream, Encoding.UTF8))
                {
                    requestBody = reader.ReadToEnd();
                }
            }
            finally
            {
                if (innerStream != null)
                    innerStream.Dispose();
                requestStream.Dispose();
            }

            //m_log.Debug(requestBody);
            requestBody = requestBody.Replace("<base64></base64>", "");

            string responseString = String.Empty;
            XmlRpcRequest xmlRprcRequest = null;

            bool gridproxy = false;
            if (requestBody.Contains("encoding=\"utf-8"))
            {
                int channelindx = -1;
                int optionsindx = requestBody.IndexOf(">options<");
                if(optionsindx >0)
                {
                    channelindx = requestBody.IndexOf(">channel<");
                    if (optionsindx < channelindx)
                        gridproxy = true;
                }
            }

            try
            {
                xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody);
            }
            catch (XmlException e)
            {
                if (DebugLevel >= 1)
                {
                    if (DebugLevel >= 2)
                        m_log.Warn(
                            string.Format(
                                "[BASE HTTP SERVER]: Got XMLRPC request with invalid XML from {0}.  XML was '{1}'.  Sending blank response.  Exception ",
                                request.RemoteIPEndPoint, requestBody),
                            e);
                    else
                    {
                        m_log.WarnFormat(
                            "[BASE HTTP SERVER]: Got XMLRPC request with invalid XML from {0}, length {1}.  Sending blank response.",
                            request.RemoteIPEndPoint, requestBody.Length);
                    }
                }
            }

            if (xmlRprcRequest != null)
            {
                string methodName = xmlRprcRequest.MethodName;
                if (methodName != null)
                {
                    xmlRprcRequest.Params.Add(request.RemoteIPEndPoint); // Param[1]
                    XmlRpcResponse xmlRpcResponse;

                    XmlRpcMethod method;
                    bool methodWasFound;
                    bool keepAlive = false;
                    lock (m_rpcHandlers)
                    {
                        methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method);
                        if (methodWasFound)
                            keepAlive = m_rpcHandlersKeepAlive[methodName];
                    }

                    if (methodWasFound)
                    {
                        xmlRprcRequest.Params.Add(request.Url); // Param[2]

                        string xff = "X-Forwarded-For";
                        string xfflower = xff.ToLower();
                        foreach (string s in request.Headers.AllKeys)
                        {
                            if (s != null && s.Equals(xfflower))
                            {
                                xff = xfflower;
                                break;
                            }
                        }
                        xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3]

                        if (gridproxy)
                            xmlRprcRequest.Params.Add("gridproxy");  // Param[4]
                        try
                        {
                            xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
                        }
                        catch(Exception e)
                        {
                            string errorMessage
                                = String.Format(
                                    "Requested method [{0}] from {1} threw exception: {2} {3}",
                                    methodName, request.RemoteIPEndPoint.Address, e.Message, e.StackTrace);

                            m_log.ErrorFormat("[BASE HTTP SERVER]: {0}", errorMessage);

                            // if the registered XmlRpc method threw an exception, we pass a fault-code along
                            xmlRpcResponse = new XmlRpcResponse();

                            // Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                            xmlRpcResponse.SetFault(-32603, errorMessage);
                        }

                        // if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here
                        response.KeepAlive = keepAlive;
                    }
                    else
                    {
                        xmlRpcResponse = new XmlRpcResponse();

                        // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                        xmlRpcResponse.SetFault(
                            XmlRpcErrorCodes.SERVER_ERROR_METHOD,
                            String.Format("Requested method [{0}] not found", methodName));
                    }

                    response.ContentType = "text/xml";
                    using (MemoryStream outs = new MemoryStream())
                    using (XmlTextWriter writer = new XmlTextWriter(outs, UTF8NoBOM))
                    {
                        writer.Formatting = Formatting.None;
                        XmlRpcResponseSerializer.Singleton.Serialize(writer, xmlRpcResponse);
                        writer.Flush();
                        outs.Flush();
                        outs.Position = 0;
                        using (StreamReader sr = new StreamReader(outs))
                        {
                            responseString = sr.ReadToEnd();
                        }
                    }
                }
                else
                {
                    //HandleLLSDRequests(request, response);
                    response.ContentType = "text/plain";
                    response.StatusCode = 404;
                    response.StatusDescription = "Not Found";
                    response.ProtocolVersion = "HTTP/1.0";
                    responseString = "Not found";
                    response.KeepAlive = false;

                    m_log.ErrorFormat(
                        "[BASE HTTP SERVER]: Handler not found for http request {0} {1}",
                        request.HttpMethod, request.Url.PathAndQuery);
                }
            }

            byte[] buffer = Encoding.UTF8.GetBytes(responseString);

            response.SendChunked = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;

            return buffer;
        }
        public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            XmlRpcRequest xmlRpcRequest = null;
 			XmlRpcResponse xmlRpcResponse = null;
            string requestBody = null;
            byte[] response;

            Encoding encoding = Encoding.UTF8;
            StreamReader streamReader = new StreamReader(request, encoding);
            requestBody = streamReader.ReadToEnd();
            streamReader.Close();

            try
            {
                xmlRpcRequest = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
            }
			catch (XmlException e)
			{
                m_log.ErrorFormat("[XMLRPC STREAM HANDLER]: XmlRpc request failed to deserialize: {0} -> {1}", e, requestBody);
                xmlRpcRequest = null;
            }

			if (xmlRpcRequest != null)
            {
				string methodName = xmlRpcRequest.MethodName;
                    
                if (methodName != null)
        	    {
					xmlRpcRequest.Params.Add(httpRequest.RemoteIPEndPoint); // Param[1]
					xmlRpcRequest.Params.Add(httpRequest.Url);              // Param[2]
					xmlRpcRequest.Params.Add(getForwardedFor(httpRequest)); // Param[3]						
						
					try
					{
						xmlRpcResponse = m_xmlrpcMethod(xmlRpcRequest, httpRequest.RemoteIPEndPoint);
					}
					catch(Exception e)
					{
						string errorMessage = 
                            String.Format(
						        "Requested method [{0}] from {1} threw exception: {2} {3}",
						        methodName, httpRequest.RemoteIPEndPoint.Address, e.Message, e.StackTrace);

                        m_log.ErrorFormat("[XMLRPC STREAM HANDLER]: {0}", errorMessage);
						
						// if the registered XmlRpc method threw an exception, we pass a fault-code along
						xmlRpcResponse = new XmlRpcResponse();
						
						// Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
						xmlRpcResponse.SetFault(-32603, errorMessage);
					}
			    }
			    else
			    {
			        xmlRpcResponse = new XmlRpcResponse();
			
			        // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
			        xmlRpcResponse.SetFault(
			            XmlRpcErrorCodes.SERVER_ERROR_METHOD,
			            String.Format("Requested method [{0}] not found", methodName));
			    }
			
			    response = Encoding.UTF8.GetBytes(XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse));
			    httpResponse.ContentType = "text/xml";
            }
            else
			{	
			    response = Encoding.UTF8.GetBytes("Not found");
                    
                httpResponse.ContentType = "text/plain";
			    httpResponse.StatusCode = 404;
			    httpResponse.StatusDescription = "Not Found";
			    httpResponse.ProtocolVersion = new System.Version("1.0");
		
			    m_log.ErrorFormat(
                    "[XMLRPC STREAM HANDLER]: Handler not found for http request {0} {1}",
			        httpRequest.HttpMethod, httpRequest.Url.PathAndQuery);
            }

            httpResponse.ContentLength64 = response.LongLength;
            httpResponse.ContentEncoding = Encoding.UTF8;                  
            httpResponse.SendChunked = false;

            return (response);
        }
        public IList multiCall(IList calls)
        {
            IList responses = new ArrayList();
            XmlRpcResponse fault = new XmlRpcResponse();

            foreach (IDictionary call in calls)
            {
                try
                {
                    XmlRpcRequest req = new XmlRpcRequest((String)call[XmlRpcXmlTokens.METHOD_NAME],
                                          (ArrayList)call[XmlRpcXmlTokens.PARAMS]);
                    Object results = _server.Invoke(req);
                    IList response = new ArrayList();
                    response.Add(results);
                    responses.Add(response);
                }
                catch (XmlRpcException e)
                {
                    fault.SetFault(e.FaultCode, e.FaultString);
                    responses.Add(fault.Value);
                }
                catch (Exception e2)
                {
                    fault.SetFault(XmlRpcErrorCodes.APPLICATION_ERROR,
                               XmlRpcErrorCodes.APPLICATION_ERROR_MSG + ": " + e2.Message);
                    responses.Add(fault.Value);
                }
            }

            return responses;
        }
        public XmlRpcResponse VerifyKeyMethod(XmlRpcRequest request, IPEndPoint remoteClient)
        {
            bool success = false;
            XmlRpcResponse response = new XmlRpcResponse();

            if (request.Params.Count != 2)
            {
                response.IsFault = true;
                response.SetFault(-1, "Invalid parameters");
                return response;
            }

            // Verify the key of who's calling
            UUID userID = UUID.Zero;
            string authKey = string.Empty;
            if (UUID.TryParse((string)request.Params[0], out userID))
            {
                authKey = (string)request.Params[1];

                m_log.InfoFormat("[AUTH HANDLER] VerifyKey called with key {0}", authKey);

                success = m_LocalService.VerifyKey(userID, authKey);
            }

            m_log.DebugFormat("[AUTH HANDLER]: Response to VerifyKey is {0}", success);
            response.Value = success;
            return response;
        }
Exemple #14
0
        public XmlRpcResponse XmlRpcCommand(XmlRpcRequest request, IPEndPoint remoteClient)
        {
            XmlRpcResponse response = new XmlRpcResponse();
            Hashtable responseData = new Hashtable();

            try
            {
                responseData["Status"] = "Success";
                responseData["Value"] = "";

                XmlMethodHandler handler = LookupCommand(request.MethodNameObject, request.MethodNameMethod);

                if (handler != null)
                {
                    responseData["Value"] = handler(request.Params, remoteClient);
                    response.Value = responseData;
                }
                else
                {
                    // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                    response.SetFault(
                        XmlRpcErrorCodes.SERVER_ERROR_METHOD,
                        String.Format("Requested method [{0}] not found", request.MethodNameObject + "." + request.MethodNameMethod));
                }
            }
            catch (Exception e)
            {
                responseData["Status"] = "Failure";
                responseData["ErrorDescription"] = e.Message;
                response.Value = responseData;
            }

            return response;
        }
Exemple #15
0
        private void XmlRpcHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
        {
            XmlRpcRequest rpcRequest = null;
            XmlRpcResponse rpcResponse = null;

            try
            { rpcRequest = m_xmlrpcDeserializer.Deserialize(new StreamReader(request.Body)) as XmlRpcRequest; }
            catch (SystemException ex)
            { m_log.Warn("Failed to deserialize incoming XML-RPC request: " + ex.Message); }

            if (rpcRequest != null)
            {
                response.ContentType = "text/xml";
                response.Encoding = Encoding.UTF8;
                response.Chunked = false;

                XmlRpcCallback callback;
                if (m_xmlrpcCallbacks.TryGetValue(rpcRequest.MethodName, out callback))
                {
                    // TODO: Add IHttpClientContext.RemoteEndPoint
                    rpcRequest.Params.Add(null); //rpcRequest.Params.Add(client.RemoteEndPoint);
                    rpcRequest.Params.Add(request.Uri);

                    try
                    {
                        rpcResponse = callback(rpcRequest, request);

                        string responseString = XmlRpcResponseSerializer.Singleton.Serialize(rpcResponse);
                        byte[] buffer = Encoding.UTF8.GetBytes(responseString);
                        // Set the content-length, otherwise the LL viewer freaks out
                        response.ContentLength = buffer.Length;
                        response.Body.Write(buffer, 0, buffer.Length);
                        response.Body.Flush();
                    }
                    catch (Exception ex)
                    {
                        m_log.ErrorFormat("XML-RPC method [{0}] threw exception: {1}", rpcRequest.MethodName, ex);

                        rpcResponse = new XmlRpcResponse();
                        rpcResponse.SetFault(INTERNAL_ERROR, String.Format("Requested method [{0}] threw exception: {1}", rpcRequest.MethodName, ex.Message));
                        XmlRpcResponseSerializer.Singleton.Serialize(new XmlTextWriter(response.Body, Encoding.UTF8), rpcResponse);
                    }
                }
                else
                {
                    m_log.WarnFormat("XML-RPC method [{0}] not found", rpcRequest.MethodName);

                    rpcResponse = new XmlRpcResponse();
                    rpcResponse.SetFault(METHOD_NOT_FOUND, String.Format("Requested method [{0}] not found", rpcRequest.MethodName));
                    XmlRpcResponseSerializer.Singleton.Serialize(new XmlTextWriter(response.Body, Encoding.UTF8), rpcResponse);
                }
            }
            else
            {
                m_log.Warn("Bad XML-RPC request");
                response.Status = HttpStatusCode.BadRequest;
            }
        }
Exemple #16
0
        /// <summary>
        /// We can't bind XML-RPC handlers to specific paths with the OpenSim
        /// HTTP server, so this method works around that fact
        /// </summary>
        void XmlRpcLoginHandler(OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            XmlRpcRequest xmlRpcRequest = null;
            XmlRpcResponse xmlRpcResponse = new XmlRpcResponse();

            try
            {
                using (TextReader requestReader = new StreamReader(httpRequest.InputStream))
                    xmlRpcRequest = CableBeachState.XmlRpcLoginDeserializer.Deserialize(requestReader) as XmlRpcRequest;
            }
            catch (XmlException) { }

            if (xmlRpcRequest != null)
            {
                string methodName = xmlRpcRequest.MethodName;
                m_log.Info("[CABLE BEACH XMLRPC]: Received an incoming XML-RPC request: " + methodName);

                if (methodName != null && methodName.Equals("login_to_simulator", StringComparison.InvariantCultureIgnoreCase))
                {
                    xmlRpcRequest.Params.Add(httpRequest.RemoteIPEndPoint); // Param[1]

                    try
                    {
                        xmlRpcResponse = LoginHandler(xmlRpcRequest, httpRequest.Url);
                    }
                    catch (Exception e)
                    {
                        // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                        xmlRpcResponse.SetFault(-32603, String.Format("Requested method [{0}] threw exception: {1}",
                            methodName, e));
                    }
                }
            }
            else
            {
                m_log.Warn("[CABLE BEACH XMLRPC]: Received a login request with an invalid or missing XML-RPC body");
            }

            #region Send the Response

            httpResponse.ContentType = "text/xml";
            httpResponse.SendChunked = false;
            httpResponse.ContentEncoding = System.Text.Encoding.UTF8;

            try
            {
                MemoryStream memoryStream = new MemoryStream();
                using (XmlTextWriter writer = new XmlTextWriter(memoryStream, System.Text.Encoding.UTF8))
                {
                    XmlRpcResponseSerializer.Singleton.Serialize(writer, xmlRpcResponse);
                    writer.Flush();

                    httpResponse.ContentLength = memoryStream.Length;
                    httpResponse.OutputStream.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
                }
            }
            catch (Exception ex)
            {
                m_log.Warn("[CABLE BEACH XMLRPC]: Error writing to the response stream: " + ex.Message);
            }

            #endregion Send the Response
        }
    public void HttpPost(SimpleHttpRequest req)
      {
	XmlRpcRequest rpc = XmlRpcRequestDeserializer.Parse(req.Input);

	XmlRpcResponse resp = new XmlRpcResponse();
	Object target = _handlers[rpc.MethodNameObject];
	
	if (target == null)
	  {
	    resp.SetFault(-1, "Object " + rpc.MethodNameObject + " not registered.");
	  }
	else
	  {
	    try
	      {
		resp.Value = rpc.Invoke(target);
	      }
	    catch (XmlRpcException e)
	      {
		resp.SetFault(e.Code, e.Message);
	      }
	    catch (Exception e2)
	      {
		resp.SetFault(-1, e2.Message);
	      }
	  }

	Logger.WriteEntry(resp.ToString(), EventLogEntryType.Information);

	SendHeader(req.Protocol, "text/xml", 0, " 200 OK", req.Output);
	req.Output.Flush();
	XmlTextWriter xml = new XmlTextWriter(req.Output);
	XmlRpcResponseSerializer.Serialize(xml, resp);
	xml.Flush();
	req.Output.Flush();
      }
 public XmlRpcResponse currencyNotify(XmlRpcRequest request, IPEndPoint ep)
 {
     XmlRpcResponse r = new XmlRpcResponse ();
     Hashtable requestData = m_communication.ValidateRequest(request);
     if(requestData != null) {
         string method = (string)requestData["method"];
         switch (method)
         {
             case "notifyDeliverObject": r.Value = deliverObject(requestData);
                 break;
             case "notifyOnObjectPaid": r.Value = onObjectPaid(requestData);
                 break;
             case "notifyLandBuy": r.Value = landBuy(requestData);
                 break;
             case "notifyChangePrimPermission": r.Value = changePrimPermissions(requestData);
                 break;
             case "notifyBalanceUpdate": r.Value = balanceUpdate(requestData);
                 break;
             case "notifyGetVersion": r.Value = GetVersion(requestData);
                 break;
             default: m_log.ErrorFormat("[{0}]: Method {1} is not supported", Name, method);
                 break;
         }
     } else {
         r.SetFault(-1, "Could not validate the request");
     }
     return r;
 }
        public XmlRpcResponse GenericNotify(XmlRpcRequest request, IPEndPoint ep)
        {
            XmlRpcResponse r = new XmlRpcResponse();
            try
            {
                Hashtable requestData = (Hashtable)request.Params[0];
                Hashtable communicationData = (Hashtable)request.Params[1];

                #region // Debug
            #if DEBUG
                m_log.Debug("[OMBASE]: genericNotify(...)");
                foreach (DictionaryEntry requestDatum in requestData)
                {
                    m_log.Debug("[OMBASE]:   " + requestDatum.Key.ToString() + " " + (string)requestDatum.Value);
                }
                foreach (DictionaryEntry communicationDatum in communicationData)
                {
                    m_log.Debug("[OMBASE]:   " + communicationDatum.Key.ToString() + " " + (string)communicationDatum.Value);
                }
            #endif
                #endregion

                String method = (string)requestData["method"];
                requestData.Remove("method");

                if (CommunicationHelpers.ValidateRequest(communicationData, requestData, gatewayURL))
                {
                    switch (method)
                    {
                        case "notifyUser": r.Value = userInteract(requestData);
                            break;
                        case "writeLog": r.Value = WriteLog(requestData);
                            break;
                        case "notifyIsAlive": r.Value = IsAlive(requestData);
                            break;
                        default: m_log.ErrorFormat("[{0}]: Method {1} is not supported.", Name, method);
                            break;
                    }
                }
                else
                {
                    throw new Exception("Hash values do not match");
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[{0}]: genericNotify() Exception: {1} - {2}", Name, e.Message, e.StackTrace);
                r.SetFault(1, "Could not parse the requested method");
            }
            return r;
        }
Exemple #20
0
        /// <summary>
        /// Try all the registered xmlrpc handlers when an xmlrpc request is received.
        /// Sends back an XMLRPC unknown request response if no handler is registered for the requested method.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private void HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
        {
            Stream requestStream = request.InputStream;

            Encoding encoding = Encoding.UTF8;
            StreamReader reader = new StreamReader(requestStream, encoding);

            string requestBody = reader.ReadToEnd();
            reader.Close();
            requestStream.Close();
            //m_log.Debug(requestBody);
            requestBody = requestBody.Replace("<base64></base64>", "");
            string responseString = String.Empty;
            XmlRpcRequest xmlRprcRequest = null;

            try
            {
                xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody);
            }
            catch (XmlException)
            {
            }

            if (xmlRprcRequest != null)
            {
                string methodName = xmlRprcRequest.MethodName;
                if (methodName != null)
                {
                    xmlRprcRequest.Params.Add(request.RemoteIPEndPoint); // Param[1]
                    XmlRpcResponse xmlRpcResponse;

                    XmlRpcMethod method;
                    bool methodWasFound;
                    bool keepAlive = false;
                    lock (m_rpcHandlers)
                    {
                        methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method);
                        if (methodWasFound)
                            keepAlive = m_rpcHandlersKeepAlive[methodName];
                    }

                    if (methodWasFound)
                    {
                        xmlRprcRequest.Params.Add(request.Url); // Param[2]

                        string xff = "X-Forwarded-For";
                        string xfflower = xff.ToLower();
                        foreach (string s in request.Headers.AllKeys)
                        {
                            if (s != null && s.Equals(xfflower))
                            {
                                xff = xfflower;
                                break;
                            }
                        }
                        xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3]

                        try
                        {
                            xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
                        }
                        catch(Exception e)
                        {
                            string errorMessage
                                = String.Format(
                                    "Requested method [{0}] from {1} threw exception: {2} {3}",
                                    methodName, request.RemoteIPEndPoint.Address, e.Message, e.StackTrace);

                            m_log.ErrorFormat("[BASE HTTP SERVER]: {0}", errorMessage);

                            // if the registered XmlRpc method threw an exception, we pass a fault-code along
                            xmlRpcResponse = new XmlRpcResponse();

                            // Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                            xmlRpcResponse.SetFault(-32603, errorMessage);
                        }

                        // if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here
                        response.KeepAlive = keepAlive;
                    }
                    else
                    {
                        xmlRpcResponse = new XmlRpcResponse();

                        // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                        xmlRpcResponse.SetFault(
                            XmlRpcErrorCodes.SERVER_ERROR_METHOD,
                            String.Format("Requested method [{0}] not found", methodName));
                    }

                    responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse);
                }
                else
                {
                    //HandleLLSDRequests(request, response);
                    response.ContentType = "text/plain";
                    response.StatusCode = 404;
                    response.StatusDescription = "Not Found";
                    response.ProtocolVersion = "HTTP/1.0";
                    byte[] buf = Encoding.UTF8.GetBytes("Not found");
                    response.KeepAlive = false;

                    m_log.ErrorFormat("[BASE HTTP SERVER]: Handler not found for http request {0}", request.RawUrl);

                    response.SendChunked = false;
                    response.ContentLength64 = buf.Length;
                    response.ContentEncoding = Encoding.UTF8;

                    try
                    {
                        response.OutputStream.Write(buf, 0, buf.Length);
                    }
                    catch (Exception ex)
                    {
                        m_log.Warn("[BASE HTTP SERVER]: Error - " + ex.Message);
                    }
                    finally
                    {
                        try
                        {
                            response.Send();
                            //response.FreeContext();
                        }
                        catch (SocketException e)
                        {
                            // This has to be here to prevent a Linux/Mono crash
                            m_log.WarnFormat("[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
                        }
                        catch (IOException e)
                        {
                            m_log.Warn("[BASE HTTP SERVER]: XmlRpcRequest issue: " + e.Message);
                        }
                    }
                    return;
                    //responseString = "Error";
                }
            }

            response.ContentType = "text/xml";

            byte[] buffer = Encoding.UTF8.GetBytes(responseString);

            response.SendChunked = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;
            try
            {
                response.OutputStream.Write(buffer, 0, buffer.Length);
            }
            catch (Exception ex)
            {
                m_log.Warn("[BASE HTTP SERVER]: Error - " + ex.Message);
            }
            finally
            {
                try
                {
                    response.Send();
                    //response.FreeContext();
                }
                catch (SocketException e)
                {
                    // This has to be here to prevent a Linux/Mono crash
                    m_log.WarnFormat("[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
                }
                catch (IOException e)
                {
                    m_log.Warn("[BASE HTTP SERVER]: XmlRpcRequest issue: " + e.Message);
                }
            }
        }
        public XmlRpcResponse GenericNotify(XmlRpcRequest request, IPEndPoint ep)
        {
            XmlRpcResponse r = new XmlRpcResponse();
            try
            {

                Hashtable requestData = m_communication.ValidateRequest(request);

                if (requestData != null)
                {
                    string method = (string)requestData["method"];
                    switch (method)
                    {
                        case "notifyUser": r.Value = UserInteract(requestData);
                            break;
                        case "writeLog": r.Value = WriteLog(requestData);
                            break;
                        case "notifyIsAlive": r.Value = IsAlive(requestData);
                            break;
                        default: m_log.ErrorFormat("[{0}]: Method {1} is not supported.", Name, method);
                            break;
                    }
                }
                else
                {
                    r.SetFault(1, "Could not validate the request");
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[{0}]: genericNotify() Exception: {1} - {2}", Name, e.Message, e.StackTrace);
                r.SetFault(1, "Could not parse the requested method");
            }
            return r;
        }
        public XmlRpcResponse XmlRpcRemoteData(XmlRpcRequest request, IPEndPoint remoteClient)
        {
            XmlRpcResponse response = new XmlRpcResponse();

            Hashtable requestData = (Hashtable) request.Params[0];
            bool GoodXML = (requestData.Contains("Channel") && requestData.Contains("IntValue") &&
                            requestData.Contains("StringValue"));

            if (GoodXML)
            {
                UUID channel = new UUID((string) requestData["Channel"]);
                RPCChannelInfo rpcChanInfo;
                if (m_openChannels.TryGetValue(channel, out rpcChanInfo))
                {
                    string intVal = Convert.ToInt32(requestData["IntValue"]).ToString();
                    string strVal = (string) requestData["StringValue"];

                    RPCRequestInfo rpcInfo;

                    lock (XMLRPCListLock)
                    {
                        rpcInfo =
                            new RPCRequestInfo(rpcChanInfo.GetLocalID(), rpcChanInfo.GetItemID(), channel, strVal,
                                               intVal);
                        m_rpcPending.Add(rpcInfo.GetMessageID(), rpcInfo);
                    }

                    int timeoutCtr = 0;

                    while (!rpcInfo.IsProcessed() && (timeoutCtr < RemoteReplyScriptTimeout))
                    {
                        Thread.Sleep(RemoteReplyScriptWait);
                        timeoutCtr += RemoteReplyScriptWait;
                    }
                    if (rpcInfo.IsProcessed())
                    {
                        Hashtable param = new Hashtable();
                        param["StringValue"] = rpcInfo.GetStrRetval();
                        param["IntValue"] = rpcInfo.GetIntRetval();

                        ArrayList parameters = new ArrayList();
                        parameters.Add(param);

                        response.Value = parameters;
                        rpcInfo = null;
                    }
                    else
                    {
                        response.SetFault(-1, "Script timeout");
                        rpcInfo = null;
                    }
                }
                else
                {
                    response.SetFault(-1, "Invalid channel");
                }
            }

            return response;
        }
        /// <summary>
        /// Try all the registered xmlrpc handlers when an xmlrpc request is received.
        /// Sends back an XMLRPC unknown request response if no handler is registered for the requested method.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private bool HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
        {
            XmlRpcRequest xmlRprcRequest = null;
            string requestBody;

            using (StreamReader reader = new StreamReader(request.InputStream, Encoding.UTF8))
                requestBody = reader.ReadToEnd();

            requestBody = requestBody.Replace("<base64></base64>", "");

            try
            {
                if (requestBody.StartsWith("<?xml"))
                    xmlRprcRequest = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
            }
            catch (XmlException)
            {
            }

            if (xmlRprcRequest != null)
            {
                string methodName = xmlRprcRequest.MethodName;
                byte[] buf;
                if (methodName != null)
                {
                    xmlRprcRequest.Params.Add(request.RemoteIPEndPoint);
                    XmlRpcResponse xmlRpcResponse;
                    XmlRpcMethod method;

                    if (_server.TryGetXMLHandler(methodName, out method))
                    {
                        xmlRprcRequest.Params.Add(request.Url); // Param[2]
                        xmlRprcRequest.Params.Add(request.Headers.Get("X-Forwarded-For")); // Param[3]

                        try
                        {
                            xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
                        }
                        catch (Exception e)
                        {
                            MainConsole.Instance.ErrorFormat("[BASE HTTP SERVER]: Requested method [{0}] from {1} threw exception: {2} {3}",
                                    methodName, request.RemoteIPEndPoint.Address, e, e.StackTrace);

                            // if the registered XmlRpc method threw an exception, we pass a fault-code along
                            xmlRpcResponse = new XmlRpcResponse();

                            // Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                            xmlRpcResponse.SetFault(-32603, string.Format("Requested method [{0}] from {1} threw exception: {2} {3}",
                                    methodName, request.RemoteIPEndPoint.Address, e, e.StackTrace));
                        }

                        // if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here
                        response.KeepAlive = _server.GetXMLHandlerIsKeepAlive(methodName);
                    }
                    else
                    {
                        xmlRpcResponse = new XmlRpcResponse();

                        // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
                        xmlRpcResponse.SetFault(
                            XmlRpcErrorCodes.SERVER_ERROR_METHOD,
                            String.Format("Requested method [{0}] not found", methodName));
                    }

                    buf = Encoding.UTF8.GetBytes(XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse));
                    response.ContentType = "text/xml";
                }
                else
                {
                    response.ContentType = "text/plain";
                    response.StatusCode = (int)HttpStatusCode.NotFound;
                    response.StatusDescription = "Not Found";
                    buf = Encoding.UTF8.GetBytes("Not found");
                    response.ContentEncoding = Encoding.UTF8;
                }

                try
                {
                    response.OutputStream.Write(buf, 0, buf.Length);
                    response.Send();
                }
                catch (SocketException e)
                {
                    // This has to be here to prevent a Linux/Mono crash
                    MainConsole.Instance.WarnFormat("[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
                }
                catch (IOException e)
                {
                    MainConsole.Instance.Debug("[BASE HTTP SERVER]: XmlRpcRequest issue: " + e);
                }
                return true;
            }

            return false;
        }