29 using System.Collections.Generic;
31 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Framework.ServiceAuth;
36 using OpenSim.Server.Base;
37 using OpenSim.Services.Interfaces;
43 namespace OpenSim.OfflineIM
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 private string m_ServerURI = string.Empty;
51 private object m_Lock =
new object();
56 m_log.DebugFormat(
"[OfflineIM.V2.RemoteConnector]: Offline IM server at {0}", m_ServerURI);
61 IConfig cnf = config.Configs[
"Messaging"];
64 m_log.WarnFormat(
"[OfflineIM.V2.RemoteConnector]: Missing Messaging configuration");
68 m_ServerURI = cnf.GetString(
"OfflineMessageURL", string.Empty);
71 string authType = Util.GetConfigVarFromSections<
string>(config,
"AuthType",
new string[] {
"Network",
"Messaging" },
"None");
75 case "BasicHttpAuthentication":
80 m_log.DebugFormat(
"[OfflineIM.V2.RemoteConnector]: Offline IM server at {0} with auth {1}",
81 m_ServerURI, (m_Auth == null ?
"None" : m_Auth.GetType().ToString()));
84 #region IOfflineIMService
87 List<GridInstantMessage> ims =
new List<GridInstantMessage>();
89 Dictionary<string, object> sendData =
new Dictionary<string, object>();
90 sendData[
"PrincipalID"] = principalID;
91 Dictionary<string, object> ret = MakeRequest(
"GET", sendData);
96 if (!ret.ContainsKey(
"RESULT"))
99 string result = ret[
"RESULT"].ToString();
100 if (result ==
"NULL" || result.ToLower() ==
"false")
102 string reason = ret.ContainsKey(
"REASON") ? ret[
"REASON"].ToString() :
"Unknown error";
103 m_log.DebugFormat(
"[OfflineIM.V2.RemoteConnector]: GetMessages for {0} failed: {1}", principalID, reason);
107 foreach (
object v
in ((Dictionary<string, object>)ret[
"RESULT"]).Values)
109 GridInstantMessage m = OfflineIMDataUtils.GridInstantMessage((Dictionary<string, object>)v);
118 reason = string.Empty;
119 Dictionary<string, object> sendData = OfflineIMDataUtils.GridInstantMessage(im);
121 Dictionary<string, object> ret = MakeRequest(
"STORE", sendData);
125 reason =
"Bad response from server";
129 string result = ret[
"RESULT"].ToString();
130 if (result ==
"NULL" || result.ToLower() ==
"false")
132 reason = ret.ContainsKey(
"REASON") ? ret[
"REASON"].ToString() :
"Unknown error";
141 Dictionary<string, object> sendData =
new Dictionary<string, object>();
142 sendData[
"UserID"] = userID;
144 MakeRequest(
"DELETE", sendData);
152 private Dictionary<string, object> MakeRequest(
string method, Dictionary<string, object> sendData)
154 sendData[
"METHOD"] = method;
156 string reply = string.Empty;
158 reply = SynchronousRestFormsRequester.MakeRequest("POST",
159 m_ServerURI + "/offlineim",
160 ServerUtils.BuildQueryString(sendData),
163 Dictionary<
string,
object> replyData = ServerUtils.ParseXmlResponse(
List< GridInstantMessage > GetMessages(UUID principalID)
OfflineIMServiceRemoteConnector(string url)
void DeleteMessages(UUID userID)
Delete messages to or from this user (or group).
bool StoreMessage(GridInstantMessage im, out string reason)
OfflineIMServiceRemoteConnector(IConfigSource config)