aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorUbitUmarov2018-01-04 20:56:48 +0000
committerUbitUmarov2018-01-04 20:56:48 +0000
commit48dbba34416e31fa9d525007807b070d0eb25cf9 (patch)
tree7bf4c4e9c7804e8b232eaadab0ea66a7658c9c3d
parentfix estates URI (diff)
downloadopensim-SC-48dbba34416e31fa9d525007807b070d0eb25cf9.zip
opensim-SC-48dbba34416e31fa9d525007807b070d0eb25cf9.tar.gz
opensim-SC-48dbba34416e31fa9d525007807b070d0eb25cf9.tar.bz2
opensim-SC-48dbba34416e31fa9d525007807b070d0eb25cf9.tar.xz
add more files for robust mutes suport. (module is still named MuteListModuleTst for testing, others in core will be removed later
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs14
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/RemoteMuteListServiceConnector.cs143
-rw-r--r--OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs2
-rw-r--r--OpenSim/Server/Handlers/MuteList/MuteListServerConnector.cs63
-rw-r--r--OpenSim/Server/Handlers/MuteList/MuteListServerPostHandler.cs240
-rw-r--r--OpenSim/Services/Connectors/MuteList/MuteListServicesConnector.cs183
6 files changed, 641 insertions, 4 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs
index 833d883..37b30aa 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs
@@ -38,7 +38,7 @@ using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces; 38using OpenSim.Services.Interfaces;
39using OpenMetaverse; 39using OpenMetaverse;
40 40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Land 41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MuteList
42{ 42{
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalMuteListServicesConnector")] 43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalMuteListServicesConnector")]
44 public class LocalMuteListServicesConnector : ISharedRegionModule, IMuteListService 44 public class LocalMuteListServicesConnector : ISharedRegionModule, IMuteListService
@@ -66,7 +66,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Land
66 66
67 public void Initialise(IConfigSource source) 67 public void Initialise(IConfigSource source)
68 { 68 {
69 IConfig moduleConfig = source.Configs["Modules"]; 69 // only active for core mute lists module
70 IConfig moduleConfig = source.Configs["Messaging"];
71 if (moduleConfig == null)
72 return;
73
74 if (moduleConfig.GetString("MuteListModule", "None") != "MuteListModuleTst")
75 return;
76
77 moduleConfig = source.Configs["Modules"];
70 78
71 if (moduleConfig == null) 79 if (moduleConfig == null)
72 return; 80 return;
@@ -99,7 +107,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Land
99 catch 107 catch
100 { 108 {
101 m_log.Error("[MuteList LOCALCONNECTOR]: Failed to load mute service"); 109 m_log.Error("[MuteList LOCALCONNECTOR]: Failed to load mute service");
102 return; 110 return;
103 } 111 }
104 112
105 if (m_service == null) 113 if (m_service == null)
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/RemoteMuteListServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/RemoteMuteListServiceConnector.cs
new file mode 100644
index 0000000..a5dec64
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/RemoteMuteListServiceConnector.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 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30using OpenSim.Framework;
31using OpenSim.Region.Framework.Interfaces;
32using OpenSim.Region.Framework.Scenes;
33using OpenSim.Server.Base;
34using OpenSim.Services.Interfaces;
35using OpenSim.Services.Connectors;
36
37using OpenMetaverse;
38using log4net;
39using Mono.Addins;
40using Nini.Config;
41
42namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MuteList
43{
44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteMuteListServicesConnector")]
45 public class RemoteMuteListServicesConnector : ISharedRegionModule, IMuteListService
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 #region ISharedRegionModule
50
51 private bool m_Enabled = false;
52
53 private IMuteListService m_remoteConnector;
54
55 public Type ReplaceableInterface
56 {
57 get { return null; }
58 }
59
60 public string Name
61 {
62 get { return "RemoteMuteListServicesConnector"; }
63 }
64
65 public void Initialise(IConfigSource source)
66 {
67 // only active for core mute lists module
68 IConfig moduleConfig = source.Configs["Messaging"];
69 if (moduleConfig == null)
70 return;
71
72 if (moduleConfig.GetString("MuteListModule", "None") != "MuteListModuleTst")
73 return;
74
75 moduleConfig = source.Configs["Modules"];
76 if (moduleConfig != null)
77 {
78 string name = moduleConfig.GetString("MuteListService", "");
79 if (name == Name)
80 {
81 m_remoteConnector = new MuteListServicesConnector(source);
82 m_Enabled = true;
83 }
84 }
85 }
86
87 public void PostInitialise()
88 {
89 }
90
91 public void Close()
92 {
93 }
94
95 public void AddRegion(Scene scene)
96 {
97 if (!m_Enabled)
98 return;
99
100 scene.RegisterModuleInterface<IMuteListService>(this);
101 m_log.InfoFormat("[MUTELIST CONNECTOR]: Enabled for region {0}", scene.RegionInfo.RegionName);
102 }
103
104 public void RemoveRegion(Scene scene)
105 {
106 if (!m_Enabled)
107 return;
108 }
109
110 public void RegionLoaded(Scene scene)
111 {
112 if (!m_Enabled)
113 return;
114 }
115
116 #endregion
117
118 #region IMuteListService
119 public Byte[] MuteListRequest(UUID agentID, uint crc)
120 {
121 if (!m_Enabled)
122 return null;
123 return m_remoteConnector.MuteListRequest(agentID, crc);
124 }
125
126 public bool UpdateMute(MuteData mute)
127 {
128 if (!m_Enabled)
129 return false;
130 return m_remoteConnector.UpdateMute(mute);
131 }
132
133 public bool RemoveMute(UUID agentID, UUID muteID, string muteName)
134 {
135 if (!m_Enabled)
136 return false;
137 return m_remoteConnector.RemoveMute(agentID, muteID, muteName);
138 }
139
140 #endregion IMuteListService
141
142 }
143}
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs
index 1e29378..755272b 100644
--- a/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs
+++ b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs
@@ -56,7 +56,7 @@ namespace OpenSim.Server.Handlers.GridUser
56 Object[] args = new Object[] { config }; 56 Object[] args = new Object[] { config };
57 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(service, args); 57 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(service, args);
58 58
59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ; 59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
60 60
61 server.AddStreamHandler(new GridUserServerPostHandler(m_GridUserService, auth)); 61 server.AddStreamHandler(new GridUserServerPostHandler(m_GridUserService, auth));
62 } 62 }
diff --git a/OpenSim/Server/Handlers/MuteList/MuteListServerConnector.cs b/OpenSim/Server/Handlers/MuteList/MuteListServerConnector.cs
new file mode 100644
index 0000000..8d27f07
--- /dev/null
+++ b/OpenSim/Server/Handlers/MuteList/MuteListServerConnector.cs
@@ -0,0 +1,63 @@
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
28using System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.ServiceAuth;
33using OpenSim.Framework.Servers.HttpServer;
34using OpenSim.Server.Handlers.Base;
35
36namespace OpenSim.Server.Handlers.GridUser
37{
38 public class MuteListServiceConnector : ServiceConnector
39 {
40 private IMuteListService m_MuteListService;
41 private string m_ConfigName = "MuteListService";
42
43 public MuteListServiceConnector(IConfigSource config, IHttpServer server, string configName) :
44 base(config, server, configName)
45 {
46 IConfig serverConfig = config.Configs[m_ConfigName];
47 if (serverConfig == null)
48 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
49
50 string service = serverConfig.GetString("LocalServiceModule", String.Empty);
51
52 if (service == String.Empty)
53 throw new Exception("LocalServiceModule not present in MuteListService config file MuteListService section");
54
55 Object[] args = new Object[] { config };
56 m_MuteListService = ServerUtils.LoadPlugin<IMuteListService>(service, args);
57
58 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
59
60 server.AddStreamHandler(new MuteListServerPostHandler(m_MuteListService, auth));
61 }
62 }
63}
diff --git a/OpenSim/Server/Handlers/MuteList/MuteListServerPostHandler.cs b/OpenSim/Server/Handlers/MuteList/MuteListServerPostHandler.cs
new file mode 100644
index 0000000..26c4093
--- /dev/null
+++ b/OpenSim/Server/Handlers/MuteList/MuteListServerPostHandler.cs
@@ -0,0 +1,240 @@
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
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework;
42using OpenSim.Framework.ServiceAuth;
43using OpenSim.Framework.Servers.HttpServer;
44using OpenMetaverse;
45
46namespace OpenSim.Server.Handlers.GridUser
47{
48 public class MuteListServerPostHandler : BaseStreamHandler
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private IMuteListService m_service;
53
54 public MuteListServerPostHandler(IMuteListService service, IServiceAuth auth) :
55 base("POST", "/mutelist", auth)
56 {
57 m_service = service;
58 }
59
60 protected override byte[] ProcessRequest(string path, Stream requestData,
61 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
62 {
63 string body;
64 using(StreamReader sr = new StreamReader(requestData))
65 body = sr.ReadToEnd();
66 body = body.Trim();
67
68 //m_log.DebugFormat("[XXX]: query String: {0}", body);
69 string method = string.Empty;
70
71 try
72 {
73 Dictionary<string, object> request =
74 ServerUtils.ParseQueryString(body);
75
76 if (!request.ContainsKey("METHOD"))
77 return FailureResult();
78
79 method = request["METHOD"].ToString();
80
81 switch (method)
82 {
83 case "get":
84 return getmutes(request);
85 case "update":
86 return updatemute(request);
87 case "delete":
88 return deletemute(request);
89 }
90 m_log.DebugFormat("[MUTELIST HANDLER]: unknown method request: {0}", method);
91 }
92 catch (Exception e)
93 {
94 m_log.DebugFormat("[MUTELIST HANDLER]: Exception in method {0}: {1}", method, e);
95 }
96
97 return FailureResult();
98 }
99
100 byte[] getmutes(Dictionary<string, object> request)
101 {
102 if(!request.ContainsKey("agentid") || !request.ContainsKey("mutecrc"))
103 return FailureResult();
104
105 UUID agentID;
106 if(!UUID.TryParse(request["agentid"].ToString(), out agentID))
107 return FailureResult();
108
109 uint mutecrc;
110 if(!UInt32.TryParse(request["mutecrc"].ToString(), out mutecrc))
111 return FailureResult();
112
113 byte[] data = m_service.MuteListRequest(agentID, mutecrc);
114
115 Dictionary<string, object> result = new Dictionary<string, object>();
116 result["result"] = Convert.ToBase64String(data);
117
118 string xmlString = ServerUtils.BuildXmlResponse(result);
119
120 //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString);
121 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
122 }
123
124 byte[] updatemute(Dictionary<string, object> request)
125 {
126 if(!request.ContainsKey("agentid") || !request.ContainsKey("muteid"))
127 return FailureResult();
128
129 MuteData mute = new MuteData();
130
131 if( !UUID.TryParse(request["agentid"].ToString(), out mute.AgentID))
132 return FailureResult();
133
134 if(!UUID.TryParse(request["muteid"].ToString(), out mute.MuteID))
135 return FailureResult();
136
137 if(request.ContainsKey("mutename"))
138 {
139 mute.MuteName = request["mutename"].ToString();
140 }
141 else
142 mute.MuteName = String.Empty;
143
144 if(request.ContainsKey("mutetype"))
145 {
146 if(!Int32.TryParse(request["mutetype"].ToString(), out mute.MuteType))
147 return FailureResult();
148 }
149 else
150 mute.MuteType = 0;
151
152 if(request.ContainsKey("muteflags"))
153 {
154 if(!Int32.TryParse(request["muteflags"].ToString(), out mute.MuteFlags))
155 return FailureResult();
156 }
157 else
158 mute.MuteFlags = 0;
159
160 if(request.ContainsKey("mutestamp"))
161 {
162 if(!Int32.TryParse(request["mutestamp"].ToString(), out mute.Stamp))
163 return FailureResult();
164 }
165 else
166 mute.Stamp = Util.UnixTimeSinceEpoch();
167
168 return m_service.UpdateMute(mute) ? SuccessResult() : FailureResult();
169 }
170
171 byte[] deletemute(Dictionary<string, object> request)
172 {
173 if(!request.ContainsKey("agentid") || !request.ContainsKey("muteid"))
174 return FailureResult();
175
176 UUID agentID;
177 if( !UUID.TryParse(request["agentid"].ToString(), out agentID))
178 return FailureResult();
179
180 UUID muteID;
181 if(!UUID.TryParse(request["muteid"].ToString(), out muteID))
182 return FailureResult();
183
184 string muteName;
185 if(request.ContainsKey("mutename"))
186 {
187 muteName = request["mutename"].ToString();
188
189 }
190 else
191 muteName = String.Empty;
192
193 return m_service.RemoveMute(agentID, muteID, muteName) ? SuccessResult() : FailureResult();
194 }
195
196 private byte[] SuccessResult()
197 {
198 XmlDocument doc = new XmlDocument();
199
200 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
201 "", "");
202
203 doc.AppendChild(xmlnode);
204
205 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
206 "");
207
208 doc.AppendChild(rootElement);
209
210 XmlElement result = doc.CreateElement("", "result", "");
211 result.AppendChild(doc.CreateTextNode("Success"));
212
213 rootElement.AppendChild(result);
214
215 return Util.DocToBytes(doc);
216 }
217
218 private byte[] FailureResult()
219 {
220 XmlDocument doc = new XmlDocument();
221
222 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
223 "", "");
224
225 doc.AppendChild(xmlnode);
226
227 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
228 "");
229
230 doc.AppendChild(rootElement);
231
232 XmlElement result = doc.CreateElement("", "result", "");
233 result.AppendChild(doc.CreateTextNode("Failure"));
234
235 rootElement.AppendChild(result);
236
237 return Util.DocToBytes(doc);
238 }
239 }
240}
diff --git a/OpenSim/Services/Connectors/MuteList/MuteListServicesConnector.cs b/OpenSim/Services/Connectors/MuteList/MuteListServicesConnector.cs
new file mode 100644
index 0000000..e574c1d
--- /dev/null
+++ b/OpenSim/Services/Connectors/MuteList/MuteListServicesConnector.cs
@@ -0,0 +1,183 @@
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
28using log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35
36using OpenSim.Framework.ServiceAuth;
37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenSim.Server.Base;
40using OpenMetaverse;
41
42namespace OpenSim.Services.Connectors
43{
44 public class MuteListServicesConnector : BaseServiceConnector, IMuteListService
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 private string m_ServerURI = String.Empty;
49
50 public MuteListServicesConnector()
51 {
52 }
53
54 public MuteListServicesConnector(string serverURI)
55 {
56 m_ServerURI = serverURI.TrimEnd('/') + "/mutelist";
57 }
58
59 public MuteListServicesConnector(IConfigSource source)
60 {
61 Initialise(source);
62 }
63
64 public virtual void Initialise(IConfigSource source)
65 {
66 IConfig gridConfig = source.Configs["MuteListService"];
67 if (gridConfig == null)
68 {
69 m_log.Error("[MUTELIST CONNECTOR]: MuteListService missing from configuration");
70 throw new Exception("MuteList connector init error");
71 }
72
73 string serviceURI = gridConfig.GetString("MuteListServerURI",
74 String.Empty);
75
76 if (serviceURI == String.Empty)
77 {
78 m_log.Error("[GRID USER CONNECTOR]: No Server URI named in section GridUserService");
79 throw new Exception("GridUser connector init error");
80 }
81 m_ServerURI = serviceURI + "/mutelist";;
82 base.Initialise(source, "MuteListService");
83 }
84
85 #region IMuteListService
86 public Byte[] MuteListRequest(UUID agentID, uint crc)
87 {
88 Dictionary<string, object> sendData = new Dictionary<string, object>();
89 sendData["METHOD"] = "get";
90 sendData["agentid"] = agentID.ToString();
91 sendData["mutecrc"] = crc.ToString();
92
93 try
94 {
95 string reply = SynchronousRestFormsRequester.MakeRequest("POST", m_ServerURI,
96 ServerUtils.BuildQueryString(sendData), m_Auth);
97 if (reply != string.Empty)
98 {
99 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
100
101 if (replyData.ContainsKey("result"))
102 {
103 string datastr = replyData["result"].ToString();
104 if(String.IsNullOrWhiteSpace(datastr))
105 return null;
106 return Convert.FromBase64String(datastr);
107 }
108 else
109 m_log.DebugFormat("[MUTELIST CONNECTOR]: get reply data does not contain result field");
110 }
111 else
112 m_log.DebugFormat("[MUTELIST CONNECTOR]: get received empty reply");
113 }
114 catch (Exception e)
115 {
116 m_log.DebugFormat("[MUTELIST CONNECTOR]: Exception when contacting server at {0}: {1}", m_ServerURI, e.Message);
117 }
118
119 return null;
120 }
121
122 public bool UpdateMute(MuteData mute)
123 {
124 Dictionary<string, object> sendData = new Dictionary<string, object>();
125 sendData["METHOD"] = "update";
126 sendData["agentid"] = mute.AgentID.ToString();
127 sendData["muteid"] = mute.MuteID.ToString();
128 if(mute.MuteType != 0)
129 sendData["mutetype"] = mute.MuteType.ToString();
130 if(mute.MuteFlags != 0)
131 sendData["muteflags"] = mute.MuteFlags.ToString();
132 sendData["mutestamp"] = mute.Stamp.ToString();
133 if(!String.IsNullOrEmpty(mute.MuteName))
134 sendData["mutename"] = mute.MuteName;
135
136 return doSimplePost(ServerUtils.BuildQueryString(sendData), "update");
137 }
138
139 public bool RemoveMute(UUID agentID, UUID muteID, string muteName)
140 {
141 Dictionary<string, object> sendData = new Dictionary<string, object>();
142 sendData["METHOD"] = "delete";
143 sendData["agentid"] = agentID.ToString();
144 sendData["muteid"] = muteID.ToString();
145 if(!String.IsNullOrEmpty(muteName))
146 sendData["mutename"] = muteName;
147
148 return doSimplePost(ServerUtils.BuildQueryString(sendData), "remove");
149 }
150
151 #endregion IMuteListService
152
153 private bool doSimplePost(string reqString, string meth)
154 {
155 try
156 {
157 string reply = SynchronousRestFormsRequester.MakeRequest("POST", m_ServerURI, reqString, m_Auth);
158 if (reply != string.Empty)
159 {
160 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
161
162 if (replyData.ContainsKey("result"))
163 {
164 if (replyData["result"].ToString().ToLower() == "success")
165 return true;
166 else
167 return false;
168 }
169 else
170 m_log.DebugFormat("[MUTELIST CONNECTOR]: {0} reply data does not contain result field", meth);
171 }
172 else
173 m_log.DebugFormat("[MUTELIST CONNECTOR]: {0} received empty reply", meth);
174 }
175 catch (Exception e)
176 {
177 m_log.DebugFormat("[MUTELIST CONNECTOR]: Exception when contacting server at {0}: {1}", m_ServerURI, e.Message);
178 }
179
180 return false;
181 }
182 }
183}