diff options
author | Diva Canto | 2013-02-18 15:44:00 -0800 |
---|---|---|
committer | Diva Canto | 2013-02-18 15:44:00 -0800 |
commit | 5e709b087ccf380749c6a6da8a8293c23f211efd (patch) | |
tree | 741c82f14bb9ede51b7003fb8f6529df1fc36be6 /OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRemoteConnector.cs | |
parent | I need these for OfflineIM and Groups. (diff) | |
download | opensim-SC-5e709b087ccf380749c6a6da8a8293c23f211efd.zip opensim-SC-5e709b087ccf380749c6a6da8a8293c23f211efd.tar.gz opensim-SC-5e709b087ccf380749c6a6da8a8293c23f211efd.tar.bz2 opensim-SC-5e709b087ccf380749c6a6da8a8293c23f211efd.tar.xz |
Donating Diva OfflineIM as an addon in a single dll, OpenSim.Addons.OpenSim.dll
Diffstat (limited to 'OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRemoteConnector.cs')
-rw-r--r-- | OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRemoteConnector.cs | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRemoteConnector.cs b/OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRemoteConnector.cs new file mode 100644 index 0000000..69feb76 --- /dev/null +++ b/OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRemoteConnector.cs | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | |||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | |||
38 | using OpenMetaverse; | ||
39 | using log4net; | ||
40 | using Nini.Config; | ||
41 | |||
42 | namespace OpenSim.OfflineIM | ||
43 | { | ||
44 | public class OfflineIMServiceRemoteConnector : IOfflineIMService | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private string m_ServerURI = string.Empty; | ||
49 | private object m_Lock = new object(); | ||
50 | |||
51 | public OfflineIMServiceRemoteConnector(string url) | ||
52 | { | ||
53 | m_ServerURI = url; | ||
54 | m_log.DebugFormat("[OfflineIM.V2.RemoteConnector]: Offline IM server at {0}", m_ServerURI); | ||
55 | } | ||
56 | |||
57 | public OfflineIMServiceRemoteConnector(IConfigSource config) | ||
58 | { | ||
59 | IConfig cnf = config.Configs["Messaging"]; | ||
60 | if (cnf == null) | ||
61 | { | ||
62 | m_log.WarnFormat("[OfflineIM.V2.RemoteConnector]: Missing Messaging configuration"); | ||
63 | return; | ||
64 | } | ||
65 | |||
66 | m_ServerURI = cnf.GetString("OfflineMessageURL", string.Empty); | ||
67 | |||
68 | } | ||
69 | |||
70 | #region IOfflineIMService | ||
71 | public List<GridInstantMessage> GetMessages(UUID principalID) | ||
72 | { | ||
73 | List<GridInstantMessage> ims = new List<GridInstantMessage>(); | ||
74 | |||
75 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
76 | sendData["PrincipalID"] = principalID; | ||
77 | Dictionary<string, object> ret = MakeRequest("GET", sendData); | ||
78 | |||
79 | if (ret == null) | ||
80 | return ims; | ||
81 | |||
82 | if (!ret.ContainsKey("RESULT")) | ||
83 | return ims; | ||
84 | |||
85 | if (ret["RESULT"].ToString() == "NULL") | ||
86 | return ims; | ||
87 | |||
88 | foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values) | ||
89 | { | ||
90 | GridInstantMessage m = OfflineIMDataUtils.GridInstantMessage((Dictionary<string, object>)v); | ||
91 | ims.Add(m); | ||
92 | } | ||
93 | |||
94 | return ims; | ||
95 | } | ||
96 | |||
97 | public bool StoreMessage(GridInstantMessage im, out string reason) | ||
98 | { | ||
99 | reason = string.Empty; | ||
100 | Dictionary<string, object> sendData = OfflineIMDataUtils.GridInstantMessage(im); | ||
101 | |||
102 | Dictionary<string, object> ret = MakeRequest("STORE", sendData); | ||
103 | |||
104 | if (ret == null) | ||
105 | { | ||
106 | reason = "Bad response from server"; | ||
107 | return false; | ||
108 | } | ||
109 | |||
110 | string result = ret["RESULT"].ToString(); | ||
111 | if (result == "NULL" || result.ToLower() == "false") | ||
112 | { | ||
113 | reason = ret["REASON"].ToString(); | ||
114 | return false; | ||
115 | } | ||
116 | |||
117 | return true; | ||
118 | } | ||
119 | |||
120 | #endregion | ||
121 | |||
122 | |||
123 | #region Make Request | ||
124 | |||
125 | private Dictionary<string, object> MakeRequest(string method, Dictionary<string, object> sendData) | ||
126 | { | ||
127 | sendData["METHOD"] = method; | ||
128 | |||
129 | string reply = string.Empty; | ||
130 | lock (m_Lock) | ||
131 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
132 | m_ServerURI + "/offlineim", | ||
133 | ServerUtils.BuildQueryString(sendData)); | ||
134 | |||
135 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse( | ||
136 | reply); | ||
137 | |||
138 | return replyData; | ||
139 | } | ||
140 | #endregion | ||
141 | |||
142 | } | ||
143 | } | ||