SampleMoneyModule: add private xmlrpc methods

master
UbitUmarov 2020-05-08 14:50:46 +01:00
parent c2c00c5d84
commit 72c1c923f8
2 changed files with 34 additions and 10 deletions

View File

@ -1104,7 +1104,7 @@ namespace OpenSim.Framework.Servers.HttpServer
/// <param name="response"></param>
public void HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
{
String requestBody;
String requestBody = null;
Stream requestStream = request.InputStream;
Stream innerStream = null;
@ -1119,6 +1119,10 @@ namespace OpenSim.Framework.Servers.HttpServer
using (StreamReader reader = new StreamReader(requestStream, Encoding.UTF8))
requestBody = reader.ReadToEnd();
}
catch
{
requestBody = null;
}
finally
{
if (innerStream != null && innerStream.CanRead)
@ -1127,6 +1131,13 @@ namespace OpenSim.Framework.Servers.HttpServer
requestStream.Dispose();
}
if (string.IsNullOrWhiteSpace(requestBody))
{
response.StatusCode = (int)HttpStatusCode.NotFound;
response.KeepAlive = false;
return;
}
//m_log.Debug(requestBody);
requestBody = requestBody.Replace("<base64></base64>", "");
@ -1274,9 +1285,9 @@ namespace OpenSim.Framework.Servers.HttpServer
response.StatusCode = (int)HttpStatusCode.OK;
}
public void HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response, Dictionary<string, XmlRpcMethod> rpchandlers)
public void HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response, Dictionary<string, XmlRpcMethod> rpcHandlers)
{
String requestBody;
String requestBody = null;
Stream requestStream = request.InputStream;
Stream innerStream = null;
@ -1291,6 +1302,10 @@ namespace OpenSim.Framework.Servers.HttpServer
using (StreamReader reader = new StreamReader(requestStream, Encoding.UTF8))
requestBody = reader.ReadToEnd();
}
catch
{
requestBody = null;
}
finally
{
if (innerStream != null && innerStream.CanRead)
@ -1299,6 +1314,13 @@ namespace OpenSim.Framework.Servers.HttpServer
requestStream.Dispose();
}
if (string.IsNullOrWhiteSpace(requestBody))
{
response.StatusCode = (int)HttpStatusCode.NotFound;
response.KeepAlive = false;
return;
}
//m_log.Debug(requestBody);
requestBody = requestBody.Replace("<base64></base64>", "");
@ -1357,7 +1379,7 @@ namespace OpenSim.Framework.Servers.HttpServer
XmlRpcMethod method;
bool methodWasFound;
methodWasFound = rpchandlers.TryGetValue(methodName, out method);
methodWasFound = rpcHandlers.TryGetValue(methodName, out method);
XmlRpcResponse xmlRpcResponse;
if (methodWasFound)

View File

@ -65,6 +65,8 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule
/// </summary>
// private UUID EconomyBaseAccount = UUID.Zero;
private Dictionary<string, XmlRpcMethod> m_rpcHandlers;
private float EnergyEfficiency = 1f;
// private ObjectPaid handerOnObjectPaid;
private bool m_enabled = true;
@ -145,12 +147,12 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule
// to the command line parameters you use to start up your client
// This commonly looks like -helperuri http://127.0.0.1:9000/
m_rpcHandlers = new Dictionary<string, XmlRpcMethod>();
// Local Server.. enables functionality only.
httpServer.AddXmlRPCHandler("getCurrencyQuote", quote_func);
httpServer.AddXmlRPCHandler("buyCurrency", buy_func);
httpServer.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func);
httpServer.AddXmlRPCHandler("buyLandPrep", landBuy_func);
m_rpcHandlers.Add("getCurrencyQuote", quote_func);
m_rpcHandlers.Add("buyCurrency", buy_func);
m_rpcHandlers.Add("preflightBuyLandPrep", preflightBuyLandPrep_func);
m_rpcHandlers.Add("buyLandPrep", landBuy_func);
// add php
MainServer.Instance.AddSimpleStreamHandler(new SimpleStreamHandler("/currency.php", processPHP));
@ -188,7 +190,7 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule
public void processPHP(IOSHttpRequest request, IOSHttpResponse response)
{
MainServer.Instance.HandleXmlRpcRequests((OSHttpRequest)request, (OSHttpResponse)response);
MainServer.Instance.HandleXmlRpcRequests((OSHttpRequest)request, (OSHttpResponse)response, m_rpcHandlers);
}
// Please do not refactor these to be just one method