diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Addons/OfflineIM | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Addons/OfflineIM')
6 files changed, 916 insertions, 0 deletions
diff --git a/OpenSim/Addons/OfflineIM/OfflineIMRegionModule.cs b/OpenSim/Addons/OfflineIM/OfflineIMRegionModule.cs new file mode 100644 index 0000000..5340bcd --- /dev/null +++ b/OpenSim/Addons/OfflineIM/OfflineIMRegionModule.cs | |||
@@ -0,0 +1,268 @@ | |||
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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using log4net; | ||
31 | using Mono.Addins; | ||
32 | using Nini.Config; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Servers; | ||
36 | using OpenSim.Framework.Client; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | |||
41 | namespace OpenSim.OfflineIM | ||
42 | { | ||
43 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "OfflineIMConnectorModule")] | ||
44 | public class OfflineIMRegionModule : ISharedRegionModule, IOfflineIMService | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private bool m_Enabled = false; | ||
49 | private List<Scene> m_SceneList = new List<Scene>(); | ||
50 | IMessageTransferModule m_TransferModule = null; | ||
51 | private bool m_ForwardOfflineGroupMessages = true; | ||
52 | |||
53 | private IOfflineIMService m_OfflineIMService; | ||
54 | |||
55 | public void Initialise(IConfigSource config) | ||
56 | { | ||
57 | IConfig cnf = config.Configs["Messaging"]; | ||
58 | if (cnf == null) | ||
59 | return; | ||
60 | if (cnf != null && cnf.GetString("OfflineMessageModule", string.Empty) != Name) | ||
61 | return; | ||
62 | |||
63 | m_Enabled = true; | ||
64 | |||
65 | string serviceLocation = cnf.GetString("OfflineMessageURL", string.Empty); | ||
66 | if (serviceLocation == string.Empty) | ||
67 | m_OfflineIMService = new OfflineIMService(config); | ||
68 | else | ||
69 | m_OfflineIMService = new OfflineIMServiceRemoteConnector(config); | ||
70 | |||
71 | m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages); | ||
72 | m_log.DebugFormat("[OfflineIM.V2]: Offline messages enabled by {0}", Name); | ||
73 | } | ||
74 | |||
75 | public void AddRegion(Scene scene) | ||
76 | { | ||
77 | if (!m_Enabled) | ||
78 | return; | ||
79 | |||
80 | scene.RegisterModuleInterface<IOfflineIMService>(this); | ||
81 | m_SceneList.Add(scene); | ||
82 | scene.EventManager.OnNewClient += OnNewClient; | ||
83 | } | ||
84 | |||
85 | public void RegionLoaded(Scene scene) | ||
86 | { | ||
87 | if (!m_Enabled) | ||
88 | return; | ||
89 | |||
90 | if (m_TransferModule == null) | ||
91 | { | ||
92 | m_TransferModule = scene.RequestModuleInterface<IMessageTransferModule>(); | ||
93 | if (m_TransferModule == null) | ||
94 | { | ||
95 | scene.EventManager.OnNewClient -= OnNewClient; | ||
96 | |||
97 | m_SceneList.Clear(); | ||
98 | |||
99 | m_log.Error("[OfflineIM.V2]: No message transfer module is enabled. Disabling offline messages"); | ||
100 | } | ||
101 | m_TransferModule.OnUndeliveredMessage += UndeliveredMessage; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | public void RemoveRegion(Scene scene) | ||
106 | { | ||
107 | if (!m_Enabled) | ||
108 | return; | ||
109 | |||
110 | m_SceneList.Remove(scene); | ||
111 | scene.EventManager.OnNewClient -= OnNewClient; | ||
112 | m_TransferModule.OnUndeliveredMessage -= UndeliveredMessage; | ||
113 | |||
114 | scene.ForEachClient(delegate(IClientAPI client) | ||
115 | { | ||
116 | client.OnRetrieveInstantMessages -= RetrieveInstantMessages; | ||
117 | client.OnMuteListRequest -= OnMuteListRequest; | ||
118 | }); | ||
119 | } | ||
120 | |||
121 | public void PostInitialise() | ||
122 | { | ||
123 | } | ||
124 | |||
125 | public string Name | ||
126 | { | ||
127 | get { return "Offline Message Module V2"; } | ||
128 | } | ||
129 | |||
130 | public Type ReplaceableInterface | ||
131 | { | ||
132 | get { return null; } | ||
133 | } | ||
134 | |||
135 | public void Close() | ||
136 | { | ||
137 | m_SceneList.Clear(); | ||
138 | } | ||
139 | |||
140 | private Scene FindScene(UUID agentID) | ||
141 | { | ||
142 | foreach (Scene s in m_SceneList) | ||
143 | { | ||
144 | ScenePresence presence = s.GetScenePresence(agentID); | ||
145 | if (presence != null && !presence.IsChildAgent) | ||
146 | return s; | ||
147 | } | ||
148 | return null; | ||
149 | } | ||
150 | |||
151 | private IClientAPI FindClient(UUID agentID) | ||
152 | { | ||
153 | foreach (Scene s in m_SceneList) | ||
154 | { | ||
155 | ScenePresence presence = s.GetScenePresence(agentID); | ||
156 | if (presence != null && !presence.IsChildAgent) | ||
157 | return presence.ControllingClient; | ||
158 | } | ||
159 | return null; | ||
160 | } | ||
161 | |||
162 | private void OnNewClient(IClientAPI client) | ||
163 | { | ||
164 | client.OnRetrieveInstantMessages += RetrieveInstantMessages; | ||
165 | client.OnMuteListRequest += OnMuteListRequest; | ||
166 | } | ||
167 | |||
168 | private void RetrieveInstantMessages(IClientAPI client) | ||
169 | { | ||
170 | m_log.DebugFormat("[OfflineIM.V2]: Retrieving stored messages for {0}", client.AgentId); | ||
171 | |||
172 | List<GridInstantMessage> msglist = m_OfflineIMService.GetMessages(client.AgentId); | ||
173 | |||
174 | if (msglist == null) | ||
175 | m_log.DebugFormat("[OfflineIM.V2]: WARNING null message list."); | ||
176 | |||
177 | foreach (GridInstantMessage im in msglist) | ||
178 | { | ||
179 | if (im.dialog == (byte)InstantMessageDialog.InventoryOffered) | ||
180 | // send it directly or else the item will be given twice | ||
181 | client.SendInstantMessage(im); | ||
182 | else | ||
183 | { | ||
184 | // Send through scene event manager so all modules get a chance | ||
185 | // to look at this message before it gets delivered. | ||
186 | // | ||
187 | // Needed for proper state management for stored group | ||
188 | // invitations | ||
189 | // | ||
190 | Scene s = FindScene(client.AgentId); | ||
191 | if (s != null) | ||
192 | s.EventManager.TriggerIncomingInstantMessage(im); | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | |||
197 | // Apparently this is needed in order for the viewer to request the IMs. | ||
198 | private void OnMuteListRequest(IClientAPI client, uint crc) | ||
199 | { | ||
200 | m_log.DebugFormat("[OfflineIM.V2] Got mute list request for crc {0}", crc); | ||
201 | string filename = "mutes" + client.AgentId.ToString(); | ||
202 | |||
203 | IXfer xfer = client.Scene.RequestModuleInterface<IXfer>(); | ||
204 | if (xfer != null) | ||
205 | { | ||
206 | xfer.AddNewFile(filename, new Byte[0]); | ||
207 | client.SendMuteListUpdate(filename); | ||
208 | } | ||
209 | } | ||
210 | |||
211 | private void UndeliveredMessage(GridInstantMessage im) | ||
212 | { | ||
213 | if (im.dialog != (byte)InstantMessageDialog.MessageFromObject && | ||
214 | im.dialog != (byte)InstantMessageDialog.MessageFromAgent && | ||
215 | im.dialog != (byte)InstantMessageDialog.GroupNotice && | ||
216 | im.dialog != (byte)InstantMessageDialog.GroupInvitation && | ||
217 | im.dialog != (byte)InstantMessageDialog.InventoryOffered) | ||
218 | { | ||
219 | return; | ||
220 | } | ||
221 | |||
222 | if (!m_ForwardOfflineGroupMessages) | ||
223 | { | ||
224 | if (im.dialog == (byte)InstantMessageDialog.GroupNotice || | ||
225 | im.dialog == (byte)InstantMessageDialog.GroupInvitation) | ||
226 | return; | ||
227 | } | ||
228 | |||
229 | string reason = string.Empty; | ||
230 | bool success = m_OfflineIMService.StoreMessage(im, out reason); | ||
231 | |||
232 | if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent) | ||
233 | { | ||
234 | IClientAPI client = FindClient(new UUID(im.fromAgentID)); | ||
235 | if (client == null) | ||
236 | return; | ||
237 | |||
238 | client.SendInstantMessage(new GridInstantMessage( | ||
239 | null, new UUID(im.toAgentID), | ||
240 | "System", new UUID(im.fromAgentID), | ||
241 | (byte)InstantMessageDialog.MessageFromAgent, | ||
242 | "User is not logged in. " + | ||
243 | (success ? "Message saved." : "Message not saved: " + reason), | ||
244 | false, new Vector3())); | ||
245 | } | ||
246 | } | ||
247 | |||
248 | #region IOfflineIM | ||
249 | |||
250 | public List<GridInstantMessage> GetMessages(UUID principalID) | ||
251 | { | ||
252 | return m_OfflineIMService.GetMessages(principalID); | ||
253 | } | ||
254 | |||
255 | public bool StoreMessage(GridInstantMessage im, out string reason) | ||
256 | { | ||
257 | return m_OfflineIMService.StoreMessage(im, out reason); | ||
258 | } | ||
259 | |||
260 | public void DeleteMessages(UUID userID) | ||
261 | { | ||
262 | m_OfflineIMService.DeleteMessages(userID); | ||
263 | } | ||
264 | |||
265 | #endregion | ||
266 | } | ||
267 | } | ||
268 | |||
diff --git a/OpenSim/Addons/OfflineIM/Properties/AssemblyInfo.cs b/OpenSim/Addons/OfflineIM/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0699660 --- /dev/null +++ b/OpenSim/Addons/OfflineIM/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,36 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | using Mono.Addins; | ||
5 | |||
6 | // General Information about an assembly is controlled through the following | ||
7 | // set of attributes. Change these attribute values to modify the information | ||
8 | // associated with an assembly. | ||
9 | [assembly: AssemblyTitle("OpenSim.Addons.OfflineIM")] | ||
10 | [assembly: AssemblyDescription("")] | ||
11 | [assembly: AssemblyConfiguration("")] | ||
12 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
13 | [assembly: AssemblyProduct("OpenSim.Addons.OfflineIM")] | ||
14 | [assembly: AssemblyCopyright("Copyright (c) OpenSimulator.org Developers")] | ||
15 | [assembly: AssemblyTrademark("")] | ||
16 | [assembly: AssemblyCulture("")] | ||
17 | |||
18 | // Setting ComVisible to false makes the types in this assembly not visible | ||
19 | // to COM components. If you need to access a type in this assembly from | ||
20 | // COM, set the ComVisible attribute to true on that type. | ||
21 | [assembly: ComVisible(false)] | ||
22 | |||
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
24 | [assembly: Guid("a16a9905-4393-4872-9fca-4c81bedbd9f2")] | ||
25 | |||
26 | // Version information for an assembly consists of the following four values: | ||
27 | // | ||
28 | // Major Version | ||
29 | // Minor Version | ||
30 | // Build Number | ||
31 | // Revision | ||
32 | // | ||
33 | [assembly: AssemblyVersion("0.8.3.*")] | ||
34 | |||
35 | [assembly: Addin("OpenSim.OfflineIM", OpenSim.VersionInfo.VersionNumber)] | ||
36 | [assembly: AddinDependency("OpenSim.Region.Framework", OpenSim.VersionInfo.VersionNumber)] | ||
diff --git a/OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRemoteConnector.cs b/OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRemoteConnector.cs new file mode 100644 index 0000000..047b8be --- /dev/null +++ b/OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRemoteConnector.cs | |||
@@ -0,0 +1,171 @@ | |||
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.Framework.ServiceAuth; | ||
36 | using OpenSim.Server.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | using log4net; | ||
41 | using Nini.Config; | ||
42 | |||
43 | namespace OpenSim.OfflineIM | ||
44 | { | ||
45 | public class OfflineIMServiceRemoteConnector : IOfflineIMService | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private string m_ServerURI = string.Empty; | ||
50 | private IServiceAuth m_Auth; | ||
51 | private object m_Lock = new object(); | ||
52 | |||
53 | public OfflineIMServiceRemoteConnector(string url) | ||
54 | { | ||
55 | m_ServerURI = url; | ||
56 | m_log.DebugFormat("[OfflineIM.V2.RemoteConnector]: Offline IM server at {0}", m_ServerURI); | ||
57 | } | ||
58 | |||
59 | public OfflineIMServiceRemoteConnector(IConfigSource config) | ||
60 | { | ||
61 | IConfig cnf = config.Configs["Messaging"]; | ||
62 | if (cnf == null) | ||
63 | { | ||
64 | m_log.WarnFormat("[OfflineIM.V2.RemoteConnector]: Missing Messaging configuration"); | ||
65 | return; | ||
66 | } | ||
67 | |||
68 | m_ServerURI = cnf.GetString("OfflineMessageURL", string.Empty); | ||
69 | |||
70 | /// This is from BaseServiceConnector | ||
71 | string authType = Util.GetConfigVarFromSections<string>(config, "AuthType", new string[] { "Network", "Messaging" }, "None"); | ||
72 | |||
73 | switch (authType) | ||
74 | { | ||
75 | case "BasicHttpAuthentication": | ||
76 | m_Auth = new BasicHttpAuthentication(config, "Messaging"); | ||
77 | break; | ||
78 | } | ||
79 | /// | ||
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())); | ||
82 | } | ||
83 | |||
84 | #region IOfflineIMService | ||
85 | public List<GridInstantMessage> GetMessages(UUID principalID) | ||
86 | { | ||
87 | List<GridInstantMessage> ims = new List<GridInstantMessage>(); | ||
88 | |||
89 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
90 | sendData["PrincipalID"] = principalID; | ||
91 | Dictionary<string, object> ret = MakeRequest("GET", sendData); | ||
92 | |||
93 | if (ret == null) | ||
94 | return ims; | ||
95 | |||
96 | if (!ret.ContainsKey("RESULT")) | ||
97 | return ims; | ||
98 | |||
99 | string result = ret["RESULT"].ToString(); | ||
100 | if (result == "NULL" || result.ToLower() == "false") | ||
101 | { | ||
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); | ||
104 | return ims; | ||
105 | } | ||
106 | |||
107 | foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values) | ||
108 | { | ||
109 | GridInstantMessage m = OfflineIMDataUtils.GridInstantMessage((Dictionary<string, object>)v); | ||
110 | ims.Add(m); | ||
111 | } | ||
112 | |||
113 | return ims; | ||
114 | } | ||
115 | |||
116 | public bool StoreMessage(GridInstantMessage im, out string reason) | ||
117 | { | ||
118 | reason = string.Empty; | ||
119 | Dictionary<string, object> sendData = OfflineIMDataUtils.GridInstantMessage(im); | ||
120 | |||
121 | Dictionary<string, object> ret = MakeRequest("STORE", sendData); | ||
122 | |||
123 | if (ret == null) | ||
124 | { | ||
125 | reason = "Bad response from server"; | ||
126 | return false; | ||
127 | } | ||
128 | |||
129 | string result = ret["RESULT"].ToString(); | ||
130 | if (result == "NULL" || result.ToLower() == "false") | ||
131 | { | ||
132 | reason = ret.ContainsKey("REASON") ? ret["REASON"].ToString() : "Unknown error"; | ||
133 | return false; | ||
134 | } | ||
135 | |||
136 | return true; | ||
137 | } | ||
138 | |||
139 | public void DeleteMessages(UUID userID) | ||
140 | { | ||
141 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
142 | sendData["UserID"] = userID; | ||
143 | |||
144 | MakeRequest("DELETE", sendData); | ||
145 | } | ||
146 | |||
147 | #endregion | ||
148 | |||
149 | |||
150 | #region Make Request | ||
151 | |||
152 | private Dictionary<string, object> MakeRequest(string method, Dictionary<string, object> sendData) | ||
153 | { | ||
154 | sendData["METHOD"] = method; | ||
155 | |||
156 | string reply = string.Empty; | ||
157 | lock (m_Lock) | ||
158 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
159 | m_ServerURI + "/offlineim", | ||
160 | ServerUtils.BuildQueryString(sendData), | ||
161 | m_Auth); | ||
162 | |||
163 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse( | ||
164 | reply); | ||
165 | |||
166 | return replyData; | ||
167 | } | ||
168 | #endregion | ||
169 | |||
170 | } | ||
171 | } | ||
diff --git a/OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRobustConnector.cs b/OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRobustConnector.cs new file mode 100644 index 0000000..b3673da --- /dev/null +++ b/OpenSim/Addons/OfflineIM/Remote/OfflineIMServiceRobustConnector.cs | |||
@@ -0,0 +1,223 @@ | |||
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.Reflection; | ||
30 | using System.Text; | ||
31 | using System.Xml; | ||
32 | using System.Collections.Generic; | ||
33 | using System.IO; | ||
34 | using Nini.Config; | ||
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; | ||
41 | using log4net; | ||
42 | using OpenMetaverse; | ||
43 | |||
44 | namespace OpenSim.OfflineIM | ||
45 | { | ||
46 | public class OfflineIMServiceRobustConnector : ServiceConnector | ||
47 | { | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private IOfflineIMService m_OfflineIMService; | ||
51 | private string m_ConfigName = "Messaging"; | ||
52 | |||
53 | public OfflineIMServiceRobustConnector(IConfigSource config, IHttpServer server, string configName) : | ||
54 | base(config, server, configName) | ||
55 | { | ||
56 | if (configName != String.Empty) | ||
57 | m_ConfigName = configName; | ||
58 | |||
59 | m_log.DebugFormat("[OfflineIM.V2.RobustConnector]: Starting with config name {0}", m_ConfigName); | ||
60 | |||
61 | m_OfflineIMService = new OfflineIMService(config); | ||
62 | |||
63 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
64 | |||
65 | server.AddStreamHandler(new OfflineIMServicePostHandler(m_OfflineIMService, auth)); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | public class OfflineIMServicePostHandler : BaseStreamHandler | ||
70 | { | ||
71 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
72 | |||
73 | private IOfflineIMService m_OfflineIMService; | ||
74 | |||
75 | public OfflineIMServicePostHandler(IOfflineIMService service, IServiceAuth auth) : | ||
76 | base("POST", "/offlineim", auth) | ||
77 | { | ||
78 | m_OfflineIMService = service; | ||
79 | } | ||
80 | |||
81 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
82 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
83 | { | ||
84 | StreamReader sr = new StreamReader(requestData); | ||
85 | string body = sr.ReadToEnd(); | ||
86 | sr.Close(); | ||
87 | body = body.Trim(); | ||
88 | |||
89 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
90 | |||
91 | try | ||
92 | { | ||
93 | Dictionary<string, object> request = | ||
94 | ServerUtils.ParseQueryString(body); | ||
95 | |||
96 | if (!request.ContainsKey("METHOD")) | ||
97 | return FailureResult(); | ||
98 | |||
99 | string method = request["METHOD"].ToString(); | ||
100 | request.Remove("METHOD"); | ||
101 | |||
102 | switch (method) | ||
103 | { | ||
104 | case "GET": | ||
105 | return HandleGet(request); | ||
106 | case "STORE": | ||
107 | return HandleStore(request); | ||
108 | case "DELETE": | ||
109 | return HandleDelete(request); | ||
110 | } | ||
111 | m_log.DebugFormat("[OFFLINE IM HANDLER]: unknown method request: {0}", method); | ||
112 | } | ||
113 | catch (Exception e) | ||
114 | { | ||
115 | m_log.Error(string.Format("[OFFLINE IM HANDLER]: Exception {0} ", e.Message), e); | ||
116 | } | ||
117 | |||
118 | return FailureResult(); | ||
119 | } | ||
120 | |||
121 | byte[] HandleStore(Dictionary<string, object> request) | ||
122 | { | ||
123 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
124 | |||
125 | GridInstantMessage im = OfflineIMDataUtils.GridInstantMessage(request); | ||
126 | |||
127 | string reason = string.Empty; | ||
128 | |||
129 | bool success = m_OfflineIMService.StoreMessage(im, out reason); | ||
130 | |||
131 | result["RESULT"] = success.ToString(); | ||
132 | if (!success) | ||
133 | result["REASON"] = reason; | ||
134 | |||
135 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
136 | |||
137 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
138 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
139 | } | ||
140 | |||
141 | byte[] HandleGet(Dictionary<string, object> request) | ||
142 | { | ||
143 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
144 | |||
145 | if (!request.ContainsKey("PrincipalID")) | ||
146 | NullResult(result, "Bad network data"); | ||
147 | else | ||
148 | { | ||
149 | UUID principalID = new UUID(request["PrincipalID"].ToString()); | ||
150 | List<GridInstantMessage> ims = m_OfflineIMService.GetMessages(principalID); | ||
151 | |||
152 | Dictionary<string, object> dict = new Dictionary<string, object>(); | ||
153 | int i = 0; | ||
154 | foreach (GridInstantMessage m in ims) | ||
155 | dict["im-" + i++] = OfflineIMDataUtils.GridInstantMessage(m); | ||
156 | |||
157 | result["RESULT"] = dict; | ||
158 | } | ||
159 | |||
160 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
161 | |||
162 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
163 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
164 | } | ||
165 | |||
166 | byte[] HandleDelete(Dictionary<string, object> request) | ||
167 | { | ||
168 | if (!request.ContainsKey("UserID")) | ||
169 | { | ||
170 | return FailureResult(); | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | UUID userID = new UUID(request["UserID"].ToString()); | ||
175 | m_OfflineIMService.DeleteMessages(userID); | ||
176 | |||
177 | return SuccessResult(); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | #region Helpers | ||
182 | |||
183 | private void NullResult(Dictionary<string, object> result, string reason) | ||
184 | { | ||
185 | result["RESULT"] = "NULL"; | ||
186 | result["REASON"] = reason; | ||
187 | } | ||
188 | |||
189 | private byte[] FailureResult() | ||
190 | { | ||
191 | return BoolResult(false); | ||
192 | } | ||
193 | |||
194 | private byte[] SuccessResult() | ||
195 | { | ||
196 | return BoolResult(true); | ||
197 | } | ||
198 | |||
199 | private byte[] BoolResult(bool value) | ||
200 | { | ||
201 | XmlDocument doc = new XmlDocument(); | ||
202 | |||
203 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
204 | "", ""); | ||
205 | |||
206 | doc.AppendChild(xmlnode); | ||
207 | |||
208 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
209 | ""); | ||
210 | |||
211 | doc.AppendChild(rootElement); | ||
212 | |||
213 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
214 | result.AppendChild(doc.CreateTextNode(value.ToString())); | ||
215 | |||
216 | rootElement.AppendChild(result); | ||
217 | |||
218 | return Util.DocToBytes(doc); | ||
219 | } | ||
220 | |||
221 | #endregion | ||
222 | } | ||
223 | } | ||
diff --git a/OpenSim/Addons/OfflineIM/Service/OfflineIMService.cs b/OpenSim/Addons/OfflineIM/Service/OfflineIMService.cs new file mode 100644 index 0000000..02084ff --- /dev/null +++ b/OpenSim/Addons/OfflineIM/Service/OfflineIMService.cs | |||
@@ -0,0 +1,135 @@ | |||
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.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Runtime.Serialization; | ||
33 | using System.Text; | ||
34 | using System.Timers; | ||
35 | using System.Xml; | ||
36 | using System.Xml.Serialization; | ||
37 | using log4net; | ||
38 | using Nini.Config; | ||
39 | |||
40 | using OpenMetaverse; | ||
41 | using OpenSim.Data; | ||
42 | using OpenSim.Framework; | ||
43 | using OpenSim.Services.Interfaces; | ||
44 | |||
45 | namespace OpenSim.OfflineIM | ||
46 | { | ||
47 | public class OfflineIMService : OfflineIMServiceBase, IOfflineIMService | ||
48 | { | ||
49 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | private const int MAX_IM = 25; | ||
51 | |||
52 | private XmlSerializer m_serializer; | ||
53 | private static bool m_Initialized = false; | ||
54 | |||
55 | public OfflineIMService(IConfigSource config) | ||
56 | : base(config) | ||
57 | { | ||
58 | m_serializer = new XmlSerializer(typeof(GridInstantMessage)); | ||
59 | if (!m_Initialized) | ||
60 | { | ||
61 | m_Database.DeleteOld(); | ||
62 | m_Initialized = true; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | public List<GridInstantMessage> GetMessages(UUID principalID) | ||
67 | { | ||
68 | List<GridInstantMessage> ims = new List<GridInstantMessage>(); | ||
69 | |||
70 | OfflineIMData[] messages = m_Database.Get("PrincipalID", principalID.ToString()); | ||
71 | |||
72 | if (messages == null || (messages != null && messages.Length == 0)) | ||
73 | return ims; | ||
74 | |||
75 | foreach (OfflineIMData m in messages) | ||
76 | { | ||
77 | using (MemoryStream mstream = new MemoryStream(Encoding.UTF8.GetBytes(m.Data["Message"]))) | ||
78 | { | ||
79 | GridInstantMessage im = (GridInstantMessage)m_serializer.Deserialize(mstream); | ||
80 | ims.Add(im); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | // Then, delete them | ||
85 | m_Database.Delete("PrincipalID", principalID.ToString()); | ||
86 | |||
87 | return ims; | ||
88 | } | ||
89 | |||
90 | public bool StoreMessage(GridInstantMessage im, out string reason) | ||
91 | { | ||
92 | reason = string.Empty; | ||
93 | |||
94 | // Check limits | ||
95 | UUID principalID = new UUID(im.toAgentID); | ||
96 | long count = m_Database.GetCount("PrincipalID", principalID.ToString()); | ||
97 | if (count >= MAX_IM) | ||
98 | { | ||
99 | reason = "Number of offline IMs has maxed out"; | ||
100 | return false; | ||
101 | } | ||
102 | |||
103 | string imXml; | ||
104 | using (MemoryStream mstream = new MemoryStream()) | ||
105 | { | ||
106 | XmlWriterSettings settings = new XmlWriterSettings(); | ||
107 | settings.Encoding = Util.UTF8NoBomEncoding; | ||
108 | |||
109 | using (XmlWriter writer = XmlWriter.Create(mstream, settings)) | ||
110 | { | ||
111 | m_serializer.Serialize(writer, im); | ||
112 | writer.Flush(); | ||
113 | } | ||
114 | |||
115 | imXml = Util.UTF8NoBomEncoding.GetString(mstream.ToArray()); | ||
116 | } | ||
117 | |||
118 | OfflineIMData data = new OfflineIMData(); | ||
119 | data.PrincipalID = principalID; | ||
120 | data.FromID = new UUID(im.fromAgentID); | ||
121 | data.Data = new Dictionary<string, string>(); | ||
122 | data.Data["Message"] = imXml; | ||
123 | |||
124 | return m_Database.Store(data); | ||
125 | |||
126 | } | ||
127 | |||
128 | public void DeleteMessages(UUID userID) | ||
129 | { | ||
130 | m_Database.Delete("PrincipalID", userID.ToString()); | ||
131 | m_Database.Delete("FromID", userID.ToString()); | ||
132 | } | ||
133 | |||
134 | } | ||
135 | } | ||
diff --git a/OpenSim/Addons/OfflineIM/Service/OfflineIMServiceBase.cs b/OpenSim/Addons/OfflineIM/Service/OfflineIMServiceBase.cs new file mode 100644 index 0000000..3376be4 --- /dev/null +++ b/OpenSim/Addons/OfflineIM/Service/OfflineIMServiceBase.cs | |||
@@ -0,0 +1,83 @@ | |||
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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Data; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Services.Base; | ||
35 | |||
36 | namespace OpenSim.OfflineIM | ||
37 | { | ||
38 | public class OfflineIMServiceBase : ServiceBase | ||
39 | { | ||
40 | protected IOfflineIMData m_Database = null; | ||
41 | |||
42 | public OfflineIMServiceBase(IConfigSource config) | ||
43 | : base(config) | ||
44 | { | ||
45 | string dllName = String.Empty; | ||
46 | string connString = String.Empty; | ||
47 | string realm = "im_offline"; | ||
48 | |||
49 | // | ||
50 | // Try reading the [DatabaseService] section, if it exists | ||
51 | // | ||
52 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
53 | if (dbConfig != null) | ||
54 | { | ||
55 | if (dllName == String.Empty) | ||
56 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
57 | if (connString == String.Empty) | ||
58 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
59 | } | ||
60 | |||
61 | // | ||
62 | // [Messaging] section overrides [DatabaseService], if it exists | ||
63 | // | ||
64 | IConfig imConfig = config.Configs["Messaging"]; | ||
65 | if (imConfig != null) | ||
66 | { | ||
67 | dllName = imConfig.GetString("StorageProvider", dllName); | ||
68 | connString = imConfig.GetString("ConnectionString", connString); | ||
69 | realm = imConfig.GetString("Realm", realm); | ||
70 | } | ||
71 | |||
72 | // | ||
73 | // We tried, but this doesn't exist. We can't proceed. | ||
74 | // | ||
75 | if (dllName.Equals(String.Empty)) | ||
76 | throw new Exception("No StorageProvider configured"); | ||
77 | |||
78 | m_Database = LoadPlugin<IOfflineIMData>(dllName, new Object[] { connString, realm }); | ||
79 | if (m_Database == null) | ||
80 | throw new Exception("Could not find a storage interface in the given module " + dllName); | ||
81 | } | ||
82 | } | ||
83 | } | ||