move /friends handler
parent
8900d1139e
commit
8526f938f7
|
@ -187,7 +187,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
|
||||||
IHttpServer server = MainServer.GetHttpServer((uint)mPort);
|
IHttpServer server = MainServer.GetHttpServer((uint)mPort);
|
||||||
|
|
||||||
if (server != null)
|
if (server != null)
|
||||||
server.AddStreamHandler(new FriendsRequestHandler(this));
|
server.AddSimpleStreamHandler(new FriendsSimpleRequestHandler(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_FriendsService == null)
|
if (m_FriendsService == null)
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
|
||||||
{
|
{
|
||||||
|
|
||||||
// public class FriendsRequestHandler : BaseStreamHandlerBasicDOSProtector
|
// public class FriendsRequestHandler : BaseStreamHandlerBasicDOSProtector
|
||||||
public class FriendsRequestHandler : BaseStreamHandler
|
public class FriendsSimpleRequestHandler : SimpleStreamHandler
|
||||||
{
|
{
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
@ -61,30 +62,44 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
|
||||||
ThrottledAction = BasicDOSProtector.ThrottleAction.DoThrottledMethod
|
ThrottledAction = BasicDOSProtector.ThrottleAction.DoThrottledMethod
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
public FriendsRequestHandler(FriendsModule fmodule)
|
public FriendsSimpleRequestHandler(FriendsModule fmodule) : base("/friends")
|
||||||
: base("POST", "/friends")
|
|
||||||
{
|
{
|
||||||
m_FriendsModule = fmodule;
|
m_FriendsModule = fmodule;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override byte[] ProcessRequest(
|
protected override void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||||
string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
|
||||||
{
|
{
|
||||||
string body;
|
if (m_FriendsModule == null)
|
||||||
using(StreamReader sr = new StreamReader(requestData))
|
{
|
||||||
body = sr.ReadToEnd();
|
httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
body = body.Trim();
|
if (httpRequest.HttpMethod != "POST")
|
||||||
|
{
|
||||||
|
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
httpResponse.KeepAlive = false;
|
||||||
|
httpResponse.StatusCode = (int)HttpStatusCode.OK;
|
||||||
|
httpResponse.ContentType = "text/xml";
|
||||||
//m_log.DebugFormat("[XXX]: query String: {0}", body);
|
//m_log.DebugFormat("[XXX]: query String: {0}", body);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Dictionary<string, object> request =
|
string body;
|
||||||
ServerUtils.ParseQueryString(body);
|
using (StreamReader sr = new StreamReader(httpRequest.InputStream))
|
||||||
|
body = sr.ReadToEnd();
|
||||||
|
|
||||||
|
body = body.Trim();
|
||||||
|
Dictionary<string, object> request = ServerUtils.ParseQueryString(body);
|
||||||
|
|
||||||
if (!request.ContainsKey("METHOD"))
|
if (!request.ContainsKey("METHOD"))
|
||||||
return FailureResult();
|
{
|
||||||
|
httpResponse.RawBuffer = FailureResult();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
string method = request["METHOD"].ToString();
|
string method = request["METHOD"].ToString();
|
||||||
request.Remove("METHOD");
|
request.Remove("METHOD");
|
||||||
|
@ -92,25 +107,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
|
||||||
switch (method)
|
switch (method)
|
||||||
{
|
{
|
||||||
case "friendship_offered":
|
case "friendship_offered":
|
||||||
return FriendshipOffered(request);
|
httpResponse.RawBuffer = FriendshipOffered(request);
|
||||||
|
return;
|
||||||
case "friendship_approved":
|
case "friendship_approved":
|
||||||
return FriendshipApproved(request);
|
httpResponse.RawBuffer = FriendshipApproved(request);
|
||||||
|
return;
|
||||||
case "friendship_denied":
|
case "friendship_denied":
|
||||||
return FriendshipDenied(request);
|
httpResponse.RawBuffer = FriendshipDenied(request);
|
||||||
|
return;
|
||||||
case "friendship_terminated":
|
case "friendship_terminated":
|
||||||
return FriendshipTerminated(request);
|
httpResponse.RawBuffer = FriendshipTerminated(request);
|
||||||
|
return;
|
||||||
case "grant_rights":
|
case "grant_rights":
|
||||||
return GrantRights(request);
|
httpResponse.RawBuffer = GrantRights(request);
|
||||||
|
return;
|
||||||
case "status":
|
case "status":
|
||||||
return StatusNotification(request);
|
httpResponse.RawBuffer = StatusNotification(request);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
m_log.Debug("[FRIENDS]: Exception {0}" + e.ToString());
|
m_log.Debug("[FRIENDS]: Exception {0}" + e.ToString());
|
||||||
|
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return FailureResult();
|
httpResponse.RawBuffer = FailureResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] FriendshipOffered(Dictionary<string, object> request)
|
byte[] FriendshipOffered(Dictionary<string, object> request)
|
||||||
|
|
Loading…
Reference in New Issue