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); }
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); }
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; } }
public XmlRpcResponse GenericNotify(XmlRpcRequest request, IPEndPoint ep) { XmlRpcResponse r = new XmlRpcResponse(); try { Hashtable requestData = (Hashtable)request.Params[0]; Hashtable communicationData = (Hashtable)request.Params[1]; m_log.Debug("[OMECONOMY]: genericNotify(...)"); foreach (DictionaryEntry requestDatum in requestData) { m_log.Debug("[OMECONOMY]: " + requestDatum.Key.ToString() + " " + (string)requestDatum.Value); } foreach (DictionaryEntry communicationDatum in communicationData) { m_log.Debug("[OMECONOMY]: " + communicationDatum.Key.ToString() + " " + (string)communicationDatum.Value); } 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("[OMECONOMY]: Method {1} is not supported.", Name, method); break; } } else { throw new Exception("Hash values do not match"); } } catch (Exception e) { m_log.ErrorFormat("[OMECONOMY]: genericNotify() Exception: {1} - {2}", Name, e.Message, e.StackTrace); r.SetFault(1, "Could not parse the requested method"); } return(r); }
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 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); }
/// <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); }
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("[OMECONOMY]: currencyNotify(...)"); foreach (DictionaryEntry requestDatum in requestData) { m_log.Debug("[OMECONOMY]: " + requestDatum.Key.ToString() + " " + (string)requestDatum.Value); } foreach (DictionaryEntry communicationDatum in communicationData) { m_log.Debug("[OMECONOMY]: " + 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("[OMECONOMY]: Method {1} is not supported", Name, method); break; } } else { throw new Exception("Hash values do not match"); } } catch (Exception e) { m_log.ErrorFormat("[OMECONOMY]: genericNotify() Exception: {1} - {2}", Name, e.Message, e.StackTrace); r.SetFault(1, "Could not parse the requested method"); } return(r); }
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); }