29 using System.Reflection;
32 using System.Collections.Generic;
35 using OpenSim.Framework;
36 using OpenSim.Server.Base;
37 using OpenSim.Services.Interfaces;
38 using OpenSim.Framework.Servers.HttpServer;
39 using OpenSim.Framework.ServiceAuth;
40 using OpenSim.Server.Handlers.Base;
44 namespace OpenSim.OfflineIM
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 private string m_ConfigName =
"Messaging";
54 base(config, server, configName)
56 if (configName != String.Empty)
57 m_ConfigName = configName;
59 m_log.DebugFormat(
"[OfflineIM.V2.RobustConnector]: Starting with config name {0}", m_ConfigName);
63 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
71 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
76 base(
"POST",
"/offlineim", auth)
78 m_OfflineIMService = service;
84 StreamReader sr =
new StreamReader(requestData);
85 string body = sr.ReadToEnd();
93 Dictionary<string, object> request =
94 ServerUtils.ParseQueryString(body);
96 if (!request.ContainsKey(
"METHOD"))
97 return FailureResult();
99 string method = request[
"METHOD"].ToString();
100 request.Remove(
"METHOD");
105 return HandleGet(request);
107 return HandleStore(request);
109 return HandleDelete(request);
111 m_log.DebugFormat(
"[OFFLINE IM HANDLER]: unknown method request: {0}", method);
115 m_log.Error(string.Format(
"[OFFLINE IM HANDLER]: Exception {0} ", e.Message), e);
118 return FailureResult();
121 byte[] HandleStore(Dictionary<string, object> request)
123 Dictionary<string, object> result =
new Dictionary<string, object>();
127 string reason = string.Empty;
129 bool success = m_OfflineIMService.StoreMessage(im, out reason);
131 result[
"RESULT"] = success.ToString();
133 result[
"REASON"] = reason;
135 string xmlString = ServerUtils.BuildXmlResponse(result);
138 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
141 byte[] HandleGet(Dictionary<string, object> request)
143 Dictionary<string, object> result =
new Dictionary<string, object>();
145 if (!request.ContainsKey(
"PrincipalID"))
146 NullResult(result,
"Bad network data");
149 UUID principalID =
new UUID(request[
"PrincipalID"].ToString());
150 List<GridInstantMessage> ims = m_OfflineIMService.GetMessages(principalID);
152 Dictionary<string, object> dict =
new Dictionary<string, object>();
155 dict[
"im-" + i++] = OfflineIMDataUtils.GridInstantMessage(m);
157 result[
"RESULT"] = dict;
160 string xmlString = ServerUtils.BuildXmlResponse(result);
163 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
166 byte[] HandleDelete(Dictionary<string, object> request)
168 if (!request.ContainsKey(
"UserID"))
170 return FailureResult();
174 UUID userID =
new UUID(request[
"UserID"].ToString());
175 m_OfflineIMService.DeleteMessages(userID);
177 return SuccessResult();
183 private void NullResult(Dictionary<string, object> result,
string reason)
185 result[
"RESULT"] =
"NULL";
186 result[
"REASON"] = reason;
189 private byte[] FailureResult()
191 return BoolResult(
false);
194 private byte[] SuccessResult()
196 return BoolResult(
true);
199 private byte[] BoolResult(
bool value)
201 XmlDocument doc =
new XmlDocument();
203 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
206 doc.AppendChild(xmlnode);
208 XmlElement rootElement = doc.CreateElement(
"",
"ServerResponse",
211 doc.AppendChild(rootElement);
213 XmlElement result = doc.CreateElement(
"",
"RESULT",
"");
214 result.AppendChild(doc.CreateTextNode(value.ToString()));
216 rootElement.AppendChild(result);
218 return Util.DocToBytes(doc);
Base streamed request handler.
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
OfflineIMServicePostHandler(IOfflineIMService service, IServiceAuth auth)
override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
OfflineIMServiceRobustConnector(IConfigSource config, IHttpServer server, string configName)