diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Server/Handlers | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Server/Handlers')
63 files changed, 11723 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs new file mode 100644 index 0000000..713b755 --- /dev/null +++ b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs | |||
@@ -0,0 +1,206 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using System.Collections.Generic; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Framework; | ||
42 | using OpenSim.Framework.ServiceAuth; | ||
43 | using OpenSim.Framework.Servers.HttpServer; | ||
44 | using OpenMetaverse; | ||
45 | |||
46 | namespace OpenSim.Server.Handlers.AgentPreferences | ||
47 | { | ||
48 | public class AgentPreferencesServerPostHandler : BaseStreamHandler | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private IAgentPreferencesService m_AgentPreferencesService; | ||
53 | |||
54 | public AgentPreferencesServerPostHandler(IAgentPreferencesService service, IServiceAuth auth) : | ||
55 | base("POST", "/agentprefs", auth) | ||
56 | { | ||
57 | m_AgentPreferencesService = service; | ||
58 | } | ||
59 | |||
60 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
61 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
62 | { | ||
63 | StreamReader sr = new StreamReader(requestData); | ||
64 | string body = sr.ReadToEnd(); | ||
65 | sr.Close(); | ||
66 | body = body.Trim(); | ||
67 | |||
68 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
69 | |||
70 | try | ||
71 | { | ||
72 | Dictionary<string, object> request = | ||
73 | ServerUtils.ParseQueryString(body); | ||
74 | |||
75 | if (!request.ContainsKey("METHOD")) | ||
76 | return FailureResult(); | ||
77 | |||
78 | string method = request["METHOD"].ToString(); | ||
79 | |||
80 | switch (method) | ||
81 | { | ||
82 | case "getagentprefs": | ||
83 | return GetAgentPrefs(request); | ||
84 | case "setagentprefs": | ||
85 | return SetAgentPrefs(request); | ||
86 | case "getagentlang": | ||
87 | return GetAgentLang(request); | ||
88 | } | ||
89 | m_log.DebugFormat("[AGENT PREFERENCES HANDLER]: unknown method request: {0}", method); | ||
90 | } | ||
91 | catch (Exception e) | ||
92 | { | ||
93 | m_log.DebugFormat("[AGENT PREFERENCES HANDLER]: Exception {0}", e); | ||
94 | } | ||
95 | |||
96 | return FailureResult(); | ||
97 | } | ||
98 | |||
99 | byte[] GetAgentPrefs(Dictionary<string, object> request) | ||
100 | { | ||
101 | if (!request.ContainsKey("UserID")) | ||
102 | return FailureResult(); | ||
103 | |||
104 | UUID userID; | ||
105 | if (!UUID.TryParse(request["UserID"].ToString(), out userID)) | ||
106 | return FailureResult(); | ||
107 | AgentPrefs prefs = m_AgentPreferencesService.GetAgentPreferences(userID); | ||
108 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
109 | result = prefs.ToKeyValuePairs(); | ||
110 | |||
111 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
112 | |||
113 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
114 | } | ||
115 | |||
116 | byte[] SetAgentPrefs(Dictionary<string, object> request) | ||
117 | { | ||
118 | if (!request.ContainsKey("PrincipalID") || !request.ContainsKey("AccessPrefs") || !request.ContainsKey("HoverHeight") | ||
119 | || !request.ContainsKey("Language") || !request.ContainsKey("LanguageIsPublic") || !request.ContainsKey("PermEveryone") | ||
120 | || !request.ContainsKey("PermGroup") || !request.ContainsKey("PermNextOwner")) | ||
121 | { | ||
122 | return FailureResult(); | ||
123 | } | ||
124 | |||
125 | UUID userID; | ||
126 | if (!UUID.TryParse(request["PrincipalID"].ToString(), out userID)) | ||
127 | return FailureResult(); | ||
128 | |||
129 | AgentPrefs data = new AgentPrefs(userID); | ||
130 | data.AccessPrefs = request["AccessPrefs"].ToString(); | ||
131 | data.HoverHeight = double.Parse(request["HoverHeight"].ToString()); | ||
132 | data.Language = request["Language"].ToString(); | ||
133 | data.LanguageIsPublic = bool.Parse(request["LanguageIsPublic"].ToString()); | ||
134 | data.PermEveryone = int.Parse(request["PermEveryone"].ToString()); | ||
135 | data.PermGroup = int.Parse(request["PermGroup"].ToString()); | ||
136 | data.PermNextOwner = int.Parse(request["PermNextOwner"].ToString()); | ||
137 | |||
138 | return m_AgentPreferencesService.StoreAgentPreferences(data) ? SuccessResult() : FailureResult(); | ||
139 | } | ||
140 | |||
141 | byte[] GetAgentLang(Dictionary<string, object> request) | ||
142 | { | ||
143 | if (!request.ContainsKey("UserID")) | ||
144 | return FailureResult(); | ||
145 | UUID userID; | ||
146 | if (!UUID.TryParse(request["UserID"].ToString(), out userID)) | ||
147 | return FailureResult(); | ||
148 | |||
149 | string lang = "en-us"; | ||
150 | AgentPrefs prefs = m_AgentPreferencesService.GetAgentPreferences(userID); | ||
151 | if (prefs != null) | ||
152 | { | ||
153 | if (prefs.LanguageIsPublic) | ||
154 | lang = prefs.Language; | ||
155 | } | ||
156 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
157 | result["Language"] = lang; | ||
158 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
159 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
160 | } | ||
161 | |||
162 | private byte[] SuccessResult() | ||
163 | { | ||
164 | XmlDocument doc = new XmlDocument(); | ||
165 | |||
166 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
167 | "", ""); | ||
168 | |||
169 | doc.AppendChild(xmlnode); | ||
170 | |||
171 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
172 | ""); | ||
173 | |||
174 | doc.AppendChild(rootElement); | ||
175 | |||
176 | XmlElement result = doc.CreateElement("", "result", ""); | ||
177 | result.AppendChild(doc.CreateTextNode("Success")); | ||
178 | |||
179 | rootElement.AppendChild(result); | ||
180 | |||
181 | return Util.DocToBytes(doc); | ||
182 | } | ||
183 | |||
184 | private byte[] FailureResult() | ||
185 | { | ||
186 | XmlDocument doc = new XmlDocument(); | ||
187 | |||
188 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
189 | "", ""); | ||
190 | |||
191 | doc.AppendChild(xmlnode); | ||
192 | |||
193 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
194 | ""); | ||
195 | |||
196 | doc.AppendChild(rootElement); | ||
197 | |||
198 | XmlElement result = doc.CreateElement("", "result", ""); | ||
199 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
200 | |||
201 | rootElement.AppendChild(result); | ||
202 | |||
203 | return Util.DocToBytes(doc); | ||
204 | } | ||
205 | } | ||
206 | } | ||
diff --git a/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs new file mode 100644 index 0000000..a581ea2 --- /dev/null +++ b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs | |||
@@ -0,0 +1,64 @@ | |||
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 | |||
29 | using System; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Server.Base; | ||
32 | using OpenSim.Services.Interfaces; | ||
33 | using OpenSim.Framework.ServiceAuth; | ||
34 | using OpenSim.Framework.Servers.HttpServer; | ||
35 | using OpenSim.Server.Handlers.Base; | ||
36 | |||
37 | namespace OpenSim.Server.Handlers.AgentPreferences | ||
38 | { | ||
39 | public class AgentPreferencesServiceConnector : ServiceConnector | ||
40 | { | ||
41 | private IAgentPreferencesService m_AgentPreferencesService; | ||
42 | private string m_ConfigName = "AgentPreferencesService"; | ||
43 | |||
44 | public AgentPreferencesServiceConnector(IConfigSource config, IHttpServer server, string configName) : | ||
45 | base(config, server, configName) | ||
46 | { | ||
47 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
48 | if (serverConfig == null) | ||
49 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | ||
50 | |||
51 | string service = serverConfig.GetString("LocalServiceModule", String.Empty); | ||
52 | |||
53 | if (String.IsNullOrWhiteSpace(service)) | ||
54 | throw new Exception("No LocalServiceModule in config file"); | ||
55 | |||
56 | Object[] args = new Object[] { config }; | ||
57 | m_AgentPreferencesService = ServerUtils.LoadPlugin<IAgentPreferencesService>(service, args); | ||
58 | |||
59 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ; | ||
60 | |||
61 | server.AddStreamHandler(new AgentPreferencesServerPostHandler(m_AgentPreferencesService, auth)); | ||
62 | } | ||
63 | } | ||
64 | } | ||
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs new file mode 100644 index 0000000..ab81dd6 --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs | |||
@@ -0,0 +1,221 @@ | |||
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.IO; | ||
30 | using Nini.Config; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Framework.ServiceAuth; | ||
34 | using OpenSim.Framework.Console; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using OpenSim.Framework.Servers.HttpServer; | ||
38 | using OpenSim.Server.Handlers.Base; | ||
39 | |||
40 | namespace OpenSim.Server.Handlers.Asset | ||
41 | { | ||
42 | public class AssetServiceConnector : ServiceConnector | ||
43 | { | ||
44 | private IAssetService m_AssetService; | ||
45 | private string m_ConfigName = "AssetService"; | ||
46 | |||
47 | public AssetServiceConnector(IConfigSource config, IHttpServer server, string configName) : | ||
48 | base(config, server, configName) | ||
49 | { | ||
50 | if (configName != String.Empty) | ||
51 | m_ConfigName = configName; | ||
52 | |||
53 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
54 | if (serverConfig == null) | ||
55 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
56 | |||
57 | string assetService = serverConfig.GetString("LocalServiceModule", | ||
58 | String.Empty); | ||
59 | |||
60 | if (assetService == String.Empty) | ||
61 | throw new Exception("No LocalServiceModule in config file"); | ||
62 | |||
63 | Object[] args = new Object[] { config, m_ConfigName }; | ||
64 | m_AssetService = | ||
65 | ServerUtils.LoadPlugin<IAssetService>(assetService, args); | ||
66 | |||
67 | if (m_AssetService == null) | ||
68 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); | ||
69 | |||
70 | bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); | ||
71 | bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false); | ||
72 | |||
73 | string redirectURL = serverConfig.GetString("RedirectURL", string.Empty); | ||
74 | |||
75 | AllowedRemoteDeleteTypes allowedRemoteDeleteTypes; | ||
76 | |||
77 | if (!allowDelete) | ||
78 | { | ||
79 | allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.None; | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | if (allowDeleteAllTypes) | ||
84 | allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.All; | ||
85 | else | ||
86 | allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile; | ||
87 | } | ||
88 | |||
89 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
90 | |||
91 | server.AddStreamHandler(new AssetServerGetHandler(m_AssetService, auth, redirectURL)); | ||
92 | server.AddStreamHandler(new AssetServerPostHandler(m_AssetService, auth)); | ||
93 | server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes, auth)); | ||
94 | server.AddStreamHandler(new AssetsExistHandler(m_AssetService)); | ||
95 | |||
96 | MainConsole.Instance.Commands.AddCommand("Assets", false, | ||
97 | "show asset", | ||
98 | "show asset <ID>", | ||
99 | "Show asset information", | ||
100 | HandleShowAsset); | ||
101 | |||
102 | MainConsole.Instance.Commands.AddCommand("Assets", false, | ||
103 | "delete asset", | ||
104 | "delete asset <ID>", | ||
105 | "Delete asset from database", | ||
106 | HandleDeleteAsset); | ||
107 | |||
108 | MainConsole.Instance.Commands.AddCommand("Assets", false, | ||
109 | "dump asset", | ||
110 | "dump asset <ID>", | ||
111 | "Dump asset to a file", | ||
112 | "The filename is the same as the ID given.", | ||
113 | HandleDumpAsset); | ||
114 | } | ||
115 | |||
116 | void HandleDeleteAsset(string module, string[] args) | ||
117 | { | ||
118 | if (args.Length < 3) | ||
119 | { | ||
120 | MainConsole.Instance.Output("Syntax: delete asset <ID>"); | ||
121 | return; | ||
122 | } | ||
123 | |||
124 | AssetBase asset = m_AssetService.Get(args[2]); | ||
125 | |||
126 | if (asset == null || asset.Data.Length == 0) | ||
127 | { | ||
128 | MainConsole.Instance.OutputFormat("Could not find asset with ID {0}", args[2]); | ||
129 | return; | ||
130 | } | ||
131 | |||
132 | if (!m_AssetService.Delete(asset.ID)) | ||
133 | MainConsole.Instance.OutputFormat("ERROR: Could not delete asset {0} {1}", asset.ID, asset.Name); | ||
134 | else | ||
135 | MainConsole.Instance.OutputFormat("Deleted asset {0} {1}", asset.ID, asset.Name); | ||
136 | } | ||
137 | |||
138 | void HandleDumpAsset(string module, string[] args) | ||
139 | { | ||
140 | if (args.Length < 3) | ||
141 | { | ||
142 | MainConsole.Instance.Output("Usage is dump asset <ID>"); | ||
143 | return; | ||
144 | } | ||
145 | |||
146 | UUID assetId; | ||
147 | string rawAssetId = args[2]; | ||
148 | |||
149 | if (!UUID.TryParse(rawAssetId, out assetId)) | ||
150 | { | ||
151 | MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid ID format", rawAssetId); | ||
152 | return; | ||
153 | } | ||
154 | |||
155 | AssetBase asset = m_AssetService.Get(assetId.ToString()); | ||
156 | if (asset == null) | ||
157 | { | ||
158 | MainConsole.Instance.OutputFormat("ERROR: No asset found with ID {0}", assetId); | ||
159 | return; | ||
160 | } | ||
161 | |||
162 | string fileName = rawAssetId; | ||
163 | |||
164 | if (!ConsoleUtil.CheckFileDoesNotExist(MainConsole.Instance, fileName)) | ||
165 | return; | ||
166 | |||
167 | using (FileStream fs = new FileStream(fileName, FileMode.CreateNew)) | ||
168 | { | ||
169 | using (BinaryWriter bw = new BinaryWriter(fs)) | ||
170 | { | ||
171 | bw.Write(asset.Data); | ||
172 | } | ||
173 | } | ||
174 | |||
175 | MainConsole.Instance.OutputFormat("Asset dumped to file {0}", fileName); | ||
176 | } | ||
177 | |||
178 | void HandleShowAsset(string module, string[] args) | ||
179 | { | ||
180 | if (args.Length < 3) | ||
181 | { | ||
182 | MainConsole.Instance.Output("Syntax: show asset <ID>"); | ||
183 | return; | ||
184 | } | ||
185 | |||
186 | AssetBase asset = m_AssetService.Get(args[2]); | ||
187 | |||
188 | if (asset == null || asset.Data.Length == 0) | ||
189 | { | ||
190 | MainConsole.Instance.Output("Asset not found"); | ||
191 | return; | ||
192 | } | ||
193 | |||
194 | int i; | ||
195 | |||
196 | MainConsole.Instance.OutputFormat("Name: {0}", asset.Name); | ||
197 | MainConsole.Instance.OutputFormat("Description: {0}", asset.Description); | ||
198 | MainConsole.Instance.OutputFormat("Type: {0} (type number = {1})", (AssetType)asset.Type, asset.Type); | ||
199 | MainConsole.Instance.OutputFormat("Content-type: {0}", asset.Metadata.ContentType); | ||
200 | MainConsole.Instance.OutputFormat("Size: {0} bytes", asset.Data.Length); | ||
201 | MainConsole.Instance.OutputFormat("Temporary: {0}", asset.Temporary ? "yes" : "no"); | ||
202 | MainConsole.Instance.OutputFormat("Flags: {0}", asset.Metadata.Flags); | ||
203 | |||
204 | for (i = 0 ; i < 5 ; i++) | ||
205 | { | ||
206 | int off = i * 16; | ||
207 | if (asset.Data.Length <= off) | ||
208 | break; | ||
209 | int len = 16; | ||
210 | if (asset.Data.Length < off + len) | ||
211 | len = asset.Data.Length - off; | ||
212 | |||
213 | byte[] line = new byte[len]; | ||
214 | Array.Copy(asset.Data, off, line, 0, len); | ||
215 | |||
216 | string text = BitConverter.ToString(line); | ||
217 | MainConsole.Instance.Output(String.Format("{0:x4}: {1}", off, text)); | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | } | ||
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs new file mode 100644 index 0000000..d85d471 --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs | |||
@@ -0,0 +1,115 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.ServiceAuth; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.Asset | ||
45 | { | ||
46 | /// <summary> | ||
47 | /// Remote deletes allowed. | ||
48 | /// </summary> | ||
49 | public enum AllowedRemoteDeleteTypes | ||
50 | { | ||
51 | None, | ||
52 | MapTile, | ||
53 | All | ||
54 | } | ||
55 | |||
56 | public class AssetServerDeleteHandler : BaseStreamHandler | ||
57 | { | ||
58 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
59 | |||
60 | private IAssetService m_AssetService; | ||
61 | |||
62 | /// <summary> | ||
63 | /// Asset types that can be deleted remotely. | ||
64 | /// </summary> | ||
65 | private AllowedRemoteDeleteTypes m_allowedTypes; | ||
66 | |||
67 | public AssetServerDeleteHandler(IAssetService service, AllowedRemoteDeleteTypes allowedTypes) : | ||
68 | base("DELETE", "/assets") | ||
69 | { | ||
70 | m_AssetService = service; | ||
71 | m_allowedTypes = allowedTypes; | ||
72 | } | ||
73 | |||
74 | public AssetServerDeleteHandler(IAssetService service, AllowedRemoteDeleteTypes allowedTypes, IServiceAuth auth) : | ||
75 | base("DELETE", "/assets", auth) | ||
76 | { | ||
77 | m_AssetService = service; | ||
78 | m_allowedTypes = allowedTypes; | ||
79 | } | ||
80 | protected override byte[] ProcessRequest(string path, Stream request, | ||
81 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
82 | { | ||
83 | bool result = false; | ||
84 | |||
85 | string[] p = SplitParams(path); | ||
86 | |||
87 | if (p.Length > 0) | ||
88 | { | ||
89 | if (m_allowedTypes != AllowedRemoteDeleteTypes.None) | ||
90 | { | ||
91 | string assetID = p[0]; | ||
92 | |||
93 | AssetBase asset = m_AssetService.Get(assetID); | ||
94 | if (asset != null) | ||
95 | { | ||
96 | if (m_allowedTypes == AllowedRemoteDeleteTypes.All | ||
97 | || (int)(asset.Flags & AssetFlags.Maptile) != 0) | ||
98 | { | ||
99 | result = m_AssetService.Delete(assetID); | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | m_log.DebugFormat( | ||
104 | "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but type is {1} and allowed remote delete types are {2}", | ||
105 | assetID, (AssetFlags)asset.Flags, m_allowedTypes); | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | |||
111 | XmlSerializer xs = new XmlSerializer(typeof(bool)); | ||
112 | return ServerUtils.SerializeResult(xs, result); | ||
113 | } | ||
114 | } | ||
115 | } \ No newline at end of file | ||
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs new file mode 100644 index 0000000..91c5c54 --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | |||
@@ -0,0 +1,172 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.ServiceAuth; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.Asset | ||
45 | { | ||
46 | public class AssetServerGetHandler : BaseStreamHandler | ||
47 | { | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private IAssetService m_AssetService; | ||
51 | private string m_RedirectURL; | ||
52 | |||
53 | public AssetServerGetHandler(IAssetService service) : | ||
54 | base("GET", "/assets") | ||
55 | { | ||
56 | m_AssetService = service; | ||
57 | } | ||
58 | |||
59 | public AssetServerGetHandler(IAssetService service, IServiceAuth auth, string redirectURL) : | ||
60 | base("GET", "/assets", auth) | ||
61 | { | ||
62 | m_AssetService = service; | ||
63 | m_RedirectURL = redirectURL; | ||
64 | if (!m_RedirectURL.EndsWith("/")) | ||
65 | m_RedirectURL = m_RedirectURL.TrimEnd('/'); | ||
66 | } | ||
67 | |||
68 | protected override byte[] ProcessRequest(string path, Stream request, | ||
69 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
70 | { | ||
71 | byte[] result = new byte[0]; | ||
72 | |||
73 | string[] p = SplitParams(path); | ||
74 | |||
75 | if (p.Length == 0) | ||
76 | return result; | ||
77 | |||
78 | string id = string.Empty; | ||
79 | if (p.Length > 1) | ||
80 | { | ||
81 | id = p[0]; | ||
82 | string cmd = p[1]; | ||
83 | |||
84 | if (cmd == "data") | ||
85 | { | ||
86 | result = m_AssetService.GetData(id); | ||
87 | if (result == null) | ||
88 | { | ||
89 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
90 | httpResponse.ContentType = "text/plain"; | ||
91 | result = new byte[0]; | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
96 | httpResponse.ContentType = "application/octet-stream"; | ||
97 | } | ||
98 | } | ||
99 | else if (cmd == "metadata") | ||
100 | { | ||
101 | AssetMetadata metadata = m_AssetService.GetMetadata(id); | ||
102 | |||
103 | if (metadata != null) | ||
104 | { | ||
105 | XmlSerializer xs = | ||
106 | new XmlSerializer(typeof(AssetMetadata)); | ||
107 | result = ServerUtils.SerializeResult(xs, metadata); | ||
108 | |||
109 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
110 | httpResponse.ContentType = | ||
111 | SLUtil.SLAssetTypeToContentType(metadata.Type); | ||
112 | } | ||
113 | else | ||
114 | { | ||
115 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
116 | httpResponse.ContentType = "text/plain"; | ||
117 | result = new byte[0]; | ||
118 | } | ||
119 | } | ||
120 | else | ||
121 | { | ||
122 | // Unknown request | ||
123 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
124 | httpResponse.ContentType = "text/plain"; | ||
125 | result = new byte[0]; | ||
126 | } | ||
127 | } | ||
128 | else if (p.Length == 1) | ||
129 | { | ||
130 | // Get the entire asset (metadata + data) | ||
131 | |||
132 | id = p[0]; | ||
133 | AssetBase asset = m_AssetService.Get(id); | ||
134 | |||
135 | if (asset != null) | ||
136 | { | ||
137 | XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); | ||
138 | result = ServerUtils.SerializeResult(xs, asset); | ||
139 | |||
140 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
141 | httpResponse.ContentType = | ||
142 | SLUtil.SLAssetTypeToContentType(asset.Type); | ||
143 | } | ||
144 | else | ||
145 | { | ||
146 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
147 | httpResponse.ContentType = "text/plain"; | ||
148 | result = new byte[0]; | ||
149 | } | ||
150 | } | ||
151 | else | ||
152 | { | ||
153 | // Unknown request | ||
154 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
155 | httpResponse.ContentType = "text/plain"; | ||
156 | result = new byte[0]; | ||
157 | } | ||
158 | |||
159 | if (httpResponse.StatusCode == (int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(m_RedirectURL) && !string.IsNullOrEmpty(id)) | ||
160 | { | ||
161 | httpResponse.StatusCode = (int)HttpStatusCode.Redirect; | ||
162 | string rurl = m_RedirectURL; | ||
163 | if (!path.StartsWith("/")) | ||
164 | rurl += "/"; | ||
165 | rurl += path; | ||
166 | httpResponse.AddHeader("Location", rurl); | ||
167 | m_log.DebugFormat("[ASSET GET HANDLER]: Asset not found, redirecting to {0} ({1})", rurl, httpResponse.StatusCode); | ||
168 | } | ||
169 | return result; | ||
170 | } | ||
171 | } | ||
172 | } | ||
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs new file mode 100644 index 0000000..1c706a7 --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs | |||
@@ -0,0 +1,98 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.ServiceAuth; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.Asset | ||
45 | { | ||
46 | public class AssetServerPostHandler : BaseStreamHandler | ||
47 | { | ||
48 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private IAssetService m_AssetService; | ||
51 | |||
52 | public AssetServerPostHandler(IAssetService service) : | ||
53 | base("POST", "/assets") | ||
54 | { | ||
55 | m_AssetService = service; | ||
56 | } | ||
57 | |||
58 | public AssetServerPostHandler(IAssetService service, IServiceAuth auth) : | ||
59 | base("POST", "/assets", auth) | ||
60 | { | ||
61 | m_AssetService = service; | ||
62 | } | ||
63 | |||
64 | protected override byte[] ProcessRequest(string path, Stream request, | ||
65 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
66 | { | ||
67 | AssetBase asset; | ||
68 | XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); | ||
69 | |||
70 | try | ||
71 | { | ||
72 | asset = (AssetBase)xs.Deserialize(request); | ||
73 | } | ||
74 | catch (Exception) | ||
75 | { | ||
76 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
77 | return null; | ||
78 | } | ||
79 | |||
80 | string[] p = SplitParams(path); | ||
81 | if (p.Length > 0) | ||
82 | { | ||
83 | string id = p[0]; | ||
84 | bool result = m_AssetService.UpdateContent(id, asset.Data); | ||
85 | |||
86 | xs = new XmlSerializer(typeof(bool)); | ||
87 | return ServerUtils.SerializeResult(xs, result); | ||
88 | } | ||
89 | else | ||
90 | { | ||
91 | string id = m_AssetService.Store(asset); | ||
92 | |||
93 | xs = new XmlSerializer(typeof(string)); | ||
94 | return ServerUtils.SerializeResult(xs, id); | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | } | ||
diff --git a/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs b/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs new file mode 100644 index 0000000..32901b3 --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs | |||
@@ -0,0 +1,87 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.ServiceAuth; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | using OpenMetaverse; | ||
44 | |||
45 | namespace OpenSim.Server.Handlers.Asset | ||
46 | { | ||
47 | public class AssetsExistHandler : BaseStreamHandler | ||
48 | { | ||
49 | //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private IAssetService m_AssetService; | ||
52 | |||
53 | public AssetsExistHandler(IAssetService service) : | ||
54 | base("POST", "/get_assets_exist") | ||
55 | { | ||
56 | m_AssetService = service; | ||
57 | } | ||
58 | |||
59 | public AssetsExistHandler(IAssetService service, IServiceAuth auth) : | ||
60 | base("POST", "/get_assets_exist", auth) | ||
61 | { | ||
62 | m_AssetService = service; | ||
63 | } | ||
64 | |||
65 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
66 | { | ||
67 | XmlSerializer xs; | ||
68 | |||
69 | string[] ids; | ||
70 | try | ||
71 | { | ||
72 | xs = new XmlSerializer(typeof(string[])); | ||
73 | ids = (string[])xs.Deserialize(request); | ||
74 | } | ||
75 | catch (Exception) | ||
76 | { | ||
77 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
78 | return null; | ||
79 | } | ||
80 | |||
81 | bool[] exist = m_AssetService.AssetsExist(ids); | ||
82 | |||
83 | xs = new XmlSerializer(typeof(bool[])); | ||
84 | return ServerUtils.SerializeResult(xs, exist); | ||
85 | } | ||
86 | } | ||
87 | } | ||
diff --git a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs new file mode 100644 index 0000000..faa6fb7 --- /dev/null +++ b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs | |||
@@ -0,0 +1,109 @@ | |||
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.IO; | ||
30 | using System.Net; | ||
31 | using System.Text; | ||
32 | using System.Xml; | ||
33 | using System.Xml.Serialization; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Server.Handlers.Asset; | ||
39 | using OpenSim.Services.AssetService; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Tests.Common; | ||
42 | |||
43 | namespace OpenSim.Server.Handlers.Asset.Test | ||
44 | { | ||
45 | [TestFixture] | ||
46 | public class AssetServerPostHandlerTests : OpenSimTestCase | ||
47 | { | ||
48 | [Test] | ||
49 | public void TestGoodAssetStoreRequest() | ||
50 | { | ||
51 | TestHelpers.InMethod(); | ||
52 | |||
53 | UUID assetId = TestHelpers.ParseTail(0x1); | ||
54 | |||
55 | IConfigSource config = new IniConfigSource(); | ||
56 | config.AddConfig("AssetService"); | ||
57 | config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
58 | |||
59 | AssetService assetService = new AssetService(config); | ||
60 | |||
61 | AssetServerPostHandler asph = new AssetServerPostHandler(assetService); | ||
62 | |||
63 | AssetBase asset = AssetHelpers.CreateNotecardAsset(assetId, "Hello World"); | ||
64 | |||
65 | MemoryStream buffer = new MemoryStream(); | ||
66 | |||
67 | XmlWriterSettings settings = new XmlWriterSettings(); | ||
68 | settings.Encoding = Encoding.UTF8; | ||
69 | |||
70 | using (XmlWriter writer = XmlWriter.Create(buffer, settings)) | ||
71 | { | ||
72 | XmlSerializer serializer = new XmlSerializer(typeof(AssetBase)); | ||
73 | serializer.Serialize(writer, asset); | ||
74 | writer.Flush(); | ||
75 | } | ||
76 | |||
77 | buffer.Position = 0; | ||
78 | asph.Handle(null, buffer, null, null); | ||
79 | |||
80 | AssetBase retrievedAsset = assetService.Get(assetId.ToString()); | ||
81 | |||
82 | Assert.That(retrievedAsset, Is.Not.Null); | ||
83 | } | ||
84 | |||
85 | [Test] | ||
86 | public void TestBadXmlAssetStoreRequest() | ||
87 | { | ||
88 | TestHelpers.InMethod(); | ||
89 | |||
90 | IConfigSource config = new IniConfigSource(); | ||
91 | config.AddConfig("AssetService"); | ||
92 | config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
93 | |||
94 | AssetService assetService = new AssetService(config); | ||
95 | |||
96 | AssetServerPostHandler asph = new AssetServerPostHandler(assetService); | ||
97 | |||
98 | MemoryStream buffer = new MemoryStream(); | ||
99 | byte[] badData = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f }; | ||
100 | buffer.Write(badData, 0, badData.Length); | ||
101 | buffer.Position = 0; | ||
102 | |||
103 | TestOSHttpResponse response = new TestOSHttpResponse(); | ||
104 | asph.Handle(null, buffer, null, response); | ||
105 | |||
106 | Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.BadRequest)); | ||
107 | } | ||
108 | } | ||
109 | } \ No newline at end of file | ||
diff --git a/OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs b/OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs new file mode 100644 index 0000000..c9a8dce --- /dev/null +++ b/OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs | |||
@@ -0,0 +1,67 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.ServiceAuth; | ||
33 | using OpenSim.Framework.Servers.HttpServer; | ||
34 | using OpenSim.Server.Handlers.Base; | ||
35 | |||
36 | namespace OpenSim.Server.Handlers.Authentication | ||
37 | { | ||
38 | public class AuthenticationServiceConnector : ServiceConnector | ||
39 | { | ||
40 | private IAuthenticationService m_AuthenticationService; | ||
41 | private string m_ConfigName = "AuthenticationService"; | ||
42 | |||
43 | public AuthenticationServiceConnector(IConfigSource config, IHttpServer server, string configName) : | ||
44 | base(config, server, configName) | ||
45 | { | ||
46 | if (configName != String.Empty) | ||
47 | m_ConfigName = configName; | ||
48 | |||
49 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
50 | if (serverConfig == null) | ||
51 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
52 | |||
53 | string authenticationService = serverConfig.GetString("LocalServiceModule", | ||
54 | String.Empty); | ||
55 | |||
56 | if (authenticationService == String.Empty) | ||
57 | throw new Exception("No AuthenticationService in config file"); | ||
58 | |||
59 | Object[] args = new Object[] { config }; | ||
60 | m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authenticationService, args); | ||
61 | |||
62 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
63 | |||
64 | server.AddStreamHandler(new AuthenticationServerPostHandler(m_AuthenticationService, serverConfig, auth)); | ||
65 | } | ||
66 | } | ||
67 | } | ||
diff --git a/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs new file mode 100644 index 0000000..6ee98b3 --- /dev/null +++ b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs | |||
@@ -0,0 +1,318 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using System.Collections.Generic; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Framework; | ||
42 | using OpenSim.Framework.ServiceAuth; | ||
43 | using OpenSim.Framework.Servers.HttpServer; | ||
44 | using OpenMetaverse; | ||
45 | |||
46 | namespace OpenSim.Server.Handlers.Authentication | ||
47 | { | ||
48 | public class AuthenticationServerPostHandler : BaseStreamHandler | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private IAuthenticationService m_AuthenticationService; | ||
53 | |||
54 | private bool m_AllowGetAuthInfo = false; | ||
55 | private bool m_AllowSetAuthInfo = false; | ||
56 | private bool m_AllowSetPassword = false; | ||
57 | |||
58 | public AuthenticationServerPostHandler(IAuthenticationService service) : | ||
59 | this(service, null, null) {} | ||
60 | |||
61 | public AuthenticationServerPostHandler(IAuthenticationService service, IConfig config, IServiceAuth auth) : | ||
62 | base("POST", "/auth", auth) | ||
63 | { | ||
64 | m_AuthenticationService = service; | ||
65 | |||
66 | if (config != null) | ||
67 | { | ||
68 | m_AllowGetAuthInfo = config.GetBoolean("AllowGetAuthInfo", m_AllowGetAuthInfo); | ||
69 | m_AllowSetAuthInfo = config.GetBoolean("AllowSetAuthInfo", m_AllowSetAuthInfo); | ||
70 | m_AllowSetPassword = config.GetBoolean("AllowSetPassword", m_AllowSetPassword); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | protected override byte[] ProcessRequest(string path, Stream request, | ||
75 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
76 | { | ||
77 | // m_log.Error("[XXX]: Authenticating..."); | ||
78 | string[] p = SplitParams(path); | ||
79 | |||
80 | if (p.Length > 0) | ||
81 | { | ||
82 | switch (p[0]) | ||
83 | { | ||
84 | case "plain": | ||
85 | StreamReader sr = new StreamReader(request); | ||
86 | string body = sr.ReadToEnd(); | ||
87 | sr.Close(); | ||
88 | |||
89 | return DoPlainMethods(body); | ||
90 | case "crypt": | ||
91 | byte[] buffer = new byte[request.Length]; | ||
92 | long length = request.Length; | ||
93 | if (length > 16384) | ||
94 | length = 16384; | ||
95 | request.Read(buffer, 0, (int)length); | ||
96 | |||
97 | return DoEncryptedMethods(buffer); | ||
98 | } | ||
99 | } | ||
100 | return new byte[0]; | ||
101 | } | ||
102 | |||
103 | private byte[] DoPlainMethods(string body) | ||
104 | { | ||
105 | Dictionary<string, object> request = | ||
106 | ServerUtils.ParseQueryString(body); | ||
107 | |||
108 | int lifetime = 30; | ||
109 | |||
110 | if (request.ContainsKey("LIFETIME")) | ||
111 | { | ||
112 | lifetime = Convert.ToInt32(request["LIFETIME"].ToString()); | ||
113 | if (lifetime > 30) | ||
114 | lifetime = 30; | ||
115 | } | ||
116 | |||
117 | if (!request.ContainsKey("METHOD")) | ||
118 | return FailureResult(); | ||
119 | if (!request.ContainsKey("PRINCIPAL")) | ||
120 | return FailureResult(); | ||
121 | |||
122 | string method = request["METHOD"].ToString(); | ||
123 | |||
124 | UUID principalID; | ||
125 | string token; | ||
126 | |||
127 | if (!UUID.TryParse(request["PRINCIPAL"].ToString(), out principalID)) | ||
128 | return FailureResult(); | ||
129 | |||
130 | switch (method) | ||
131 | { | ||
132 | case "authenticate": | ||
133 | if (!request.ContainsKey("PASSWORD")) | ||
134 | return FailureResult(); | ||
135 | |||
136 | token = m_AuthenticationService.Authenticate(principalID, request["PASSWORD"].ToString(), lifetime); | ||
137 | |||
138 | if (token != String.Empty) | ||
139 | return SuccessResult(token); | ||
140 | return FailureResult(); | ||
141 | |||
142 | case "setpassword": | ||
143 | if (!m_AllowSetPassword) | ||
144 | return FailureResult(); | ||
145 | |||
146 | if (!request.ContainsKey("PASSWORD")) | ||
147 | return FailureResult(); | ||
148 | |||
149 | if (m_AuthenticationService.SetPassword(principalID, request["PASSWORD"].ToString())) | ||
150 | return SuccessResult(); | ||
151 | else | ||
152 | return FailureResult(); | ||
153 | |||
154 | case "verify": | ||
155 | if (!request.ContainsKey("TOKEN")) | ||
156 | return FailureResult(); | ||
157 | |||
158 | if (m_AuthenticationService.Verify(principalID, request["TOKEN"].ToString(), lifetime)) | ||
159 | return SuccessResult(); | ||
160 | |||
161 | return FailureResult(); | ||
162 | |||
163 | case "release": | ||
164 | if (!request.ContainsKey("TOKEN")) | ||
165 | return FailureResult(); | ||
166 | |||
167 | if (m_AuthenticationService.Release(principalID, request["TOKEN"].ToString())) | ||
168 | return SuccessResult(); | ||
169 | |||
170 | return FailureResult(); | ||
171 | |||
172 | case "getauthinfo": | ||
173 | if (m_AllowGetAuthInfo) | ||
174 | return GetAuthInfo(principalID); | ||
175 | |||
176 | break; | ||
177 | |||
178 | case "setauthinfo": | ||
179 | if (m_AllowSetAuthInfo) | ||
180 | return SetAuthInfo(principalID, request); | ||
181 | |||
182 | break; | ||
183 | } | ||
184 | |||
185 | return FailureResult(); | ||
186 | } | ||
187 | |||
188 | private byte[] DoEncryptedMethods(byte[] ciphertext) | ||
189 | { | ||
190 | return new byte[0]; | ||
191 | } | ||
192 | |||
193 | private byte[] SuccessResult() | ||
194 | { | ||
195 | XmlDocument doc = new XmlDocument(); | ||
196 | |||
197 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
198 | "", ""); | ||
199 | |||
200 | doc.AppendChild(xmlnode); | ||
201 | |||
202 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
203 | ""); | ||
204 | |||
205 | doc.AppendChild(rootElement); | ||
206 | |||
207 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
208 | result.AppendChild(doc.CreateTextNode("Success")); | ||
209 | |||
210 | rootElement.AppendChild(result); | ||
211 | |||
212 | return Util.DocToBytes(doc); | ||
213 | } | ||
214 | |||
215 | byte[] GetAuthInfo(UUID principalID) | ||
216 | { | ||
217 | AuthInfo info = m_AuthenticationService.GetAuthInfo(principalID); | ||
218 | |||
219 | if (info != null) | ||
220 | { | ||
221 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
222 | result["result"] = info.ToKeyValuePairs(); | ||
223 | |||
224 | return ResultToBytes(result); | ||
225 | } | ||
226 | else | ||
227 | { | ||
228 | return FailureResult(); | ||
229 | } | ||
230 | } | ||
231 | |||
232 | byte[] SetAuthInfo(UUID principalID, Dictionary<string, object> request) | ||
233 | { | ||
234 | AuthInfo existingInfo = m_AuthenticationService.GetAuthInfo(principalID); | ||
235 | |||
236 | if (existingInfo == null) | ||
237 | return FailureResult(); | ||
238 | |||
239 | if (request.ContainsKey("AccountType")) | ||
240 | existingInfo.AccountType = request["AccountType"].ToString(); | ||
241 | |||
242 | if (request.ContainsKey("PasswordHash")) | ||
243 | existingInfo.PasswordHash = request["PasswordHash"].ToString(); | ||
244 | |||
245 | if (request.ContainsKey("PasswordSalt")) | ||
246 | existingInfo.PasswordSalt = request["PasswordSalt"].ToString(); | ||
247 | |||
248 | if (request.ContainsKey("WebLoginKey")) | ||
249 | existingInfo.WebLoginKey = request["WebLoginKey"].ToString(); | ||
250 | |||
251 | if (!m_AuthenticationService.SetAuthInfo(existingInfo)) | ||
252 | { | ||
253 | m_log.ErrorFormat( | ||
254 | "[AUTHENTICATION SERVER POST HANDLER]: Authentication info store failed for account {0} {1} {2}", | ||
255 | existingInfo.PrincipalID); | ||
256 | |||
257 | return FailureResult(); | ||
258 | } | ||
259 | |||
260 | return SuccessResult(); | ||
261 | } | ||
262 | |||
263 | private byte[] FailureResult() | ||
264 | { | ||
265 | XmlDocument doc = new XmlDocument(); | ||
266 | |||
267 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
268 | "", ""); | ||
269 | |||
270 | doc.AppendChild(xmlnode); | ||
271 | |||
272 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
273 | ""); | ||
274 | |||
275 | doc.AppendChild(rootElement); | ||
276 | |||
277 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
278 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
279 | |||
280 | rootElement.AppendChild(result); | ||
281 | |||
282 | return Util.DocToBytes(doc); | ||
283 | } | ||
284 | |||
285 | private byte[] SuccessResult(string token) | ||
286 | { | ||
287 | XmlDocument doc = new XmlDocument(); | ||
288 | |||
289 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
290 | "", ""); | ||
291 | |||
292 | doc.AppendChild(xmlnode); | ||
293 | |||
294 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
295 | ""); | ||
296 | |||
297 | doc.AppendChild(rootElement); | ||
298 | |||
299 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
300 | result.AppendChild(doc.CreateTextNode("Success")); | ||
301 | |||
302 | rootElement.AppendChild(result); | ||
303 | |||
304 | XmlElement t = doc.CreateElement("", "Token", ""); | ||
305 | t.AppendChild(doc.CreateTextNode(token)); | ||
306 | |||
307 | rootElement.AppendChild(t); | ||
308 | |||
309 | return Util.DocToBytes(doc); | ||
310 | } | ||
311 | |||
312 | private byte[] ResultToBytes(Dictionary<string, object> result) | ||
313 | { | ||
314 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
315 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
316 | } | ||
317 | } | ||
318 | } | ||
diff --git a/OpenSim/Server/Handlers/Authentication/OpenIdServerConnector.cs b/OpenSim/Server/Handlers/Authentication/OpenIdServerConnector.cs new file mode 100644 index 0000000..6464399 --- /dev/null +++ b/OpenSim/Server/Handlers/Authentication/OpenIdServerConnector.cs | |||
@@ -0,0 +1,77 @@ | |||
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 Nini.Config; | ||
31 | using log4net; | ||
32 | using OpenSim.Server.Base; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Framework.Servers.HttpServer; | ||
35 | using OpenSim.Server.Handlers.Base; | ||
36 | |||
37 | namespace OpenSim.Server.Handlers.Authentication | ||
38 | { | ||
39 | public class OpenIdServerConnector : ServiceConnector | ||
40 | { | ||
41 | private static readonly ILog m_log = | ||
42 | LogManager.GetLogger( | ||
43 | MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | private IAuthenticationService m_AuthenticationService; | ||
46 | private IUserAccountService m_UserAccountService; | ||
47 | private string m_ConfigName = "OpenIdService"; | ||
48 | |||
49 | public OpenIdServerConnector(IConfigSource config, IHttpServer server, string configName) : | ||
50 | base(config, server, configName) | ||
51 | { | ||
52 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
53 | if (serverConfig == null) | ||
54 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | ||
55 | |||
56 | string authService = serverConfig.GetString("AuthenticationServiceModule", | ||
57 | String.Empty); | ||
58 | string userService = serverConfig.GetString("UserAccountServiceModule", | ||
59 | String.Empty); | ||
60 | |||
61 | if (authService == String.Empty || userService == String.Empty) | ||
62 | throw new Exception("No AuthenticationServiceModule or no UserAccountServiceModule in config file for OpenId authentication"); | ||
63 | |||
64 | Object[] args = new Object[] { config }; | ||
65 | m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, args); | ||
66 | m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userService, args); | ||
67 | |||
68 | // Handler for OpenID user identity pages | ||
69 | server.AddStreamHandler(new OpenIdStreamHandler("GET", "/users/", m_UserAccountService, m_AuthenticationService)); | ||
70 | // Handlers for the OpenID endpoint server | ||
71 | server.AddStreamHandler(new OpenIdStreamHandler("POST", "/openid/server/", m_UserAccountService, m_AuthenticationService)); | ||
72 | server.AddStreamHandler(new OpenIdStreamHandler("GET", "/openid/server/", m_UserAccountService, m_AuthenticationService)); | ||
73 | |||
74 | m_log.Info("[OPENID]: OpenId service enabled"); | ||
75 | } | ||
76 | } | ||
77 | } | ||
diff --git a/OpenSim/Server/Handlers/Authentication/OpenIdServerHandler.cs b/OpenSim/Server/Handlers/Authentication/OpenIdServerHandler.cs new file mode 100644 index 0000000..b201dc7 --- /dev/null +++ b/OpenSim/Server/Handlers/Authentication/OpenIdServerHandler.cs | |||
@@ -0,0 +1,339 @@ | |||
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.Collections.Specialized; | ||
31 | using System.IO; | ||
32 | using System.Net; | ||
33 | using System.Web; | ||
34 | using DotNetOpenId; | ||
35 | using DotNetOpenId.Provider; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Servers; | ||
38 | using OpenSim.Framework.Servers.HttpServer; | ||
39 | using OpenSim.Server.Handlers.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using Nini.Config; | ||
42 | using OpenMetaverse; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.Authentication | ||
45 | { | ||
46 | /// <summary> | ||
47 | /// Temporary, in-memory store for OpenID associations | ||
48 | /// </summary> | ||
49 | public class ProviderMemoryStore : IAssociationStore<AssociationRelyingPartyType> | ||
50 | { | ||
51 | private class AssociationItem | ||
52 | { | ||
53 | public AssociationRelyingPartyType DistinguishingFactor; | ||
54 | public string Handle; | ||
55 | public DateTime Expires; | ||
56 | public byte[] PrivateData; | ||
57 | } | ||
58 | |||
59 | Dictionary<string, AssociationItem> m_store = new Dictionary<string, AssociationItem>(); | ||
60 | SortedList<DateTime, AssociationItem> m_sortedStore = new SortedList<DateTime, AssociationItem>(); | ||
61 | object m_syncRoot = new object(); | ||
62 | |||
63 | #region IAssociationStore<AssociationRelyingPartyType> Members | ||
64 | |||
65 | public void StoreAssociation(AssociationRelyingPartyType distinguishingFactor, Association assoc) | ||
66 | { | ||
67 | AssociationItem item = new AssociationItem(); | ||
68 | item.DistinguishingFactor = distinguishingFactor; | ||
69 | item.Handle = assoc.Handle; | ||
70 | item.Expires = assoc.Expires.ToLocalTime(); | ||
71 | item.PrivateData = assoc.SerializePrivateData(); | ||
72 | |||
73 | lock (m_syncRoot) | ||
74 | { | ||
75 | m_store[item.Handle] = item; | ||
76 | m_sortedStore[item.Expires] = item; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | public Association GetAssociation(AssociationRelyingPartyType distinguishingFactor) | ||
81 | { | ||
82 | lock (m_syncRoot) | ||
83 | { | ||
84 | if (m_sortedStore.Count > 0) | ||
85 | { | ||
86 | AssociationItem item = m_sortedStore.Values[m_sortedStore.Count - 1]; | ||
87 | return Association.Deserialize(item.Handle, item.Expires.ToUniversalTime(), item.PrivateData); | ||
88 | } | ||
89 | else | ||
90 | { | ||
91 | return null; | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | |||
96 | public Association GetAssociation(AssociationRelyingPartyType distinguishingFactor, string handle) | ||
97 | { | ||
98 | AssociationItem item; | ||
99 | bool success = false; | ||
100 | lock (m_syncRoot) | ||
101 | success = m_store.TryGetValue(handle, out item); | ||
102 | |||
103 | if (success) | ||
104 | return Association.Deserialize(item.Handle, item.Expires.ToUniversalTime(), item.PrivateData); | ||
105 | else | ||
106 | return null; | ||
107 | } | ||
108 | |||
109 | public bool RemoveAssociation(AssociationRelyingPartyType distinguishingFactor, string handle) | ||
110 | { | ||
111 | lock (m_syncRoot) | ||
112 | { | ||
113 | for (int i = 0; i < m_sortedStore.Values.Count; i++) | ||
114 | { | ||
115 | AssociationItem item = m_sortedStore.Values[i]; | ||
116 | if (item.Handle == handle) | ||
117 | { | ||
118 | m_sortedStore.RemoveAt(i); | ||
119 | break; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | return m_store.Remove(handle); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | public void ClearExpiredAssociations() | ||
128 | { | ||
129 | lock (m_syncRoot) | ||
130 | { | ||
131 | List<AssociationItem> itemsCopy = new List<AssociationItem>(m_sortedStore.Values); | ||
132 | DateTime now = DateTime.Now; | ||
133 | |||
134 | for (int i = 0; i < itemsCopy.Count; i++) | ||
135 | { | ||
136 | AssociationItem item = itemsCopy[i]; | ||
137 | |||
138 | if (item.Expires <= now) | ||
139 | { | ||
140 | m_sortedStore.RemoveAt(i); | ||
141 | m_store.Remove(item.Handle); | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | |||
147 | #endregion | ||
148 | } | ||
149 | |||
150 | public class OpenIdStreamHandler : BaseOutputStreamHandler, IStreamHandler | ||
151 | { | ||
152 | #region HTML | ||
153 | |||
154 | /// <summary>Login form used to authenticate OpenID requests</summary> | ||
155 | const string LOGIN_PAGE = | ||
156 | @"<html> | ||
157 | <head><title>OpenSim OpenID Login</title></head> | ||
158 | <body> | ||
159 | <h3>OpenSim Login</h3> | ||
160 | <form method=""post""> | ||
161 | <label for=""first"">First Name:</label> <input readonly type=""text"" name=""first"" id=""first"" value=""{0}""/> | ||
162 | <label for=""last"">Last Name:</label> <input readonly type=""text"" name=""last"" id=""last"" value=""{1}""/> | ||
163 | <label for=""pass"">Password:</label> <input type=""password"" name=""pass"" id=""pass""/> | ||
164 | <input type=""submit"" value=""Login""> | ||
165 | </form> | ||
166 | </body> | ||
167 | </html>"; | ||
168 | |||
169 | /// <summary>Page shown for a valid OpenID identity</summary> | ||
170 | const string OPENID_PAGE = | ||
171 | @"<html> | ||
172 | <head> | ||
173 | <title>{2} {3}</title> | ||
174 | <link rel=""openid2.provider openid.server"" href=""{0}://{1}/openid/server/""/> | ||
175 | </head> | ||
176 | <body>OpenID identifier for {2} {3}</body> | ||
177 | </html> | ||
178 | "; | ||
179 | |||
180 | /// <summary>Page shown for an invalid OpenID identity</summary> | ||
181 | const string INVALID_OPENID_PAGE = | ||
182 | @"<html><head><title>Identity not found</title></head> | ||
183 | <body>Invalid OpenID identity</body></html>"; | ||
184 | |||
185 | /// <summary>Page shown if the OpenID endpoint is requested directly</summary> | ||
186 | const string ENDPOINT_PAGE = | ||
187 | @"<html><head><title>OpenID Endpoint</title></head><body> | ||
188 | This is an OpenID server endpoint, not a human-readable resource. | ||
189 | For more information, see <a href='http://openid.net/'>http://openid.net/</a>. | ||
190 | </body></html>"; | ||
191 | |||
192 | #endregion HTML | ||
193 | |||
194 | IAuthenticationService m_authenticationService; | ||
195 | IUserAccountService m_userAccountService; | ||
196 | ProviderMemoryStore m_openidStore = new ProviderMemoryStore(); | ||
197 | |||
198 | public override string ContentType { get { return "text/html"; } } | ||
199 | |||
200 | /// <summary> | ||
201 | /// Constructor | ||
202 | /// </summary> | ||
203 | public OpenIdStreamHandler( | ||
204 | string httpMethod, string path, IUserAccountService userService, IAuthenticationService authService) | ||
205 | : base(httpMethod, path, "OpenId", "OpenID stream handler") | ||
206 | { | ||
207 | m_authenticationService = authService; | ||
208 | m_userAccountService = userService; | ||
209 | } | ||
210 | |||
211 | /// <summary> | ||
212 | /// Handles all GET and POST requests for OpenID identifier pages and endpoint | ||
213 | /// server communication | ||
214 | /// </summary> | ||
215 | protected override void ProcessRequest( | ||
216 | string path, Stream request, Stream response, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
217 | { | ||
218 | Uri providerEndpoint = new Uri(String.Format("{0}://{1}{2}", httpRequest.Url.Scheme, httpRequest.Url.Authority, httpRequest.Url.AbsolutePath)); | ||
219 | |||
220 | // Defult to returning HTML content | ||
221 | httpResponse.ContentType = ContentType; | ||
222 | |||
223 | try | ||
224 | { | ||
225 | NameValueCollection postQuery = HttpUtility.ParseQueryString(new StreamReader(httpRequest.InputStream).ReadToEnd()); | ||
226 | NameValueCollection getQuery = HttpUtility.ParseQueryString(httpRequest.Url.Query); | ||
227 | NameValueCollection openIdQuery = (postQuery.GetValues("openid.mode") != null ? postQuery : getQuery); | ||
228 | |||
229 | OpenIdProvider provider = new OpenIdProvider(m_openidStore, providerEndpoint, httpRequest.Url, openIdQuery); | ||
230 | |||
231 | if (provider.Request != null) | ||
232 | { | ||
233 | if (!provider.Request.IsResponseReady && provider.Request is IAuthenticationRequest) | ||
234 | { | ||
235 | IAuthenticationRequest authRequest = (IAuthenticationRequest)provider.Request; | ||
236 | string[] passwordValues = postQuery.GetValues("pass"); | ||
237 | |||
238 | UserAccount account; | ||
239 | if (TryGetAccount(new Uri(authRequest.ClaimedIdentifier.ToString()), out account)) | ||
240 | { | ||
241 | // Check for form POST data | ||
242 | if (passwordValues != null && passwordValues.Length == 1) | ||
243 | { | ||
244 | if (account != null && | ||
245 | (m_authenticationService.Authenticate(account.PrincipalID,Util.Md5Hash(passwordValues[0]), 30) != string.Empty)) | ||
246 | authRequest.IsAuthenticated = true; | ||
247 | else | ||
248 | authRequest.IsAuthenticated = false; | ||
249 | } | ||
250 | else | ||
251 | { | ||
252 | // Authentication was requested, send the client a login form | ||
253 | using (StreamWriter writer = new StreamWriter(response)) | ||
254 | writer.Write(String.Format(LOGIN_PAGE, account.FirstName, account.LastName)); | ||
255 | return; | ||
256 | } | ||
257 | } | ||
258 | else | ||
259 | { | ||
260 | // Cannot find an avatar matching the claimed identifier | ||
261 | authRequest.IsAuthenticated = false; | ||
262 | } | ||
263 | } | ||
264 | |||
265 | // Add OpenID headers to the response | ||
266 | foreach (string key in provider.Request.Response.Headers.Keys) | ||
267 | httpResponse.AddHeader(key, provider.Request.Response.Headers[key]); | ||
268 | |||
269 | string[] contentTypeValues = provider.Request.Response.Headers.GetValues("Content-Type"); | ||
270 | if (contentTypeValues != null && contentTypeValues.Length == 1) | ||
271 | httpResponse.ContentType = contentTypeValues[0]; | ||
272 | |||
273 | // Set the response code and document body based on the OpenID result | ||
274 | httpResponse.StatusCode = (int)provider.Request.Response.Code; | ||
275 | response.Write(provider.Request.Response.Body, 0, provider.Request.Response.Body.Length); | ||
276 | response.Close(); | ||
277 | } | ||
278 | else if (httpRequest.Url.AbsolutePath.Contains("/openid/server")) | ||
279 | { | ||
280 | // Standard HTTP GET was made on the OpenID endpoint, send the client the default error page | ||
281 | using (StreamWriter writer = new StreamWriter(response)) | ||
282 | writer.Write(ENDPOINT_PAGE); | ||
283 | } | ||
284 | else | ||
285 | { | ||
286 | // Try and lookup this avatar | ||
287 | UserAccount account; | ||
288 | if (TryGetAccount(httpRequest.Url, out account)) | ||
289 | { | ||
290 | using (StreamWriter writer = new StreamWriter(response)) | ||
291 | { | ||
292 | // TODO: Print out a full profile page for this avatar | ||
293 | writer.Write(String.Format(OPENID_PAGE, httpRequest.Url.Scheme, | ||
294 | httpRequest.Url.Authority, account.FirstName, account.LastName)); | ||
295 | } | ||
296 | } | ||
297 | else | ||
298 | { | ||
299 | // Couldn't parse an avatar name, or couldn't find the avatar in the user server | ||
300 | using (StreamWriter writer = new StreamWriter(response)) | ||
301 | writer.Write(INVALID_OPENID_PAGE); | ||
302 | } | ||
303 | } | ||
304 | } | ||
305 | catch (Exception ex) | ||
306 | { | ||
307 | httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError; | ||
308 | using (StreamWriter writer = new StreamWriter(response)) | ||
309 | writer.Write(ex.Message); | ||
310 | } | ||
311 | } | ||
312 | |||
313 | /// <summary> | ||
314 | /// Parse a URL with a relative path of the form /users/First_Last and try to | ||
315 | /// retrieve the profile matching that avatar name | ||
316 | /// </summary> | ||
317 | /// <param name="requestUrl">URL to parse for an avatar name</param> | ||
318 | /// <param name="profile">Profile data for the avatar</param> | ||
319 | /// <returns>True if the parse and lookup were successful, otherwise false</returns> | ||
320 | bool TryGetAccount(Uri requestUrl, out UserAccount account) | ||
321 | { | ||
322 | if (requestUrl.Segments.Length == 3 && requestUrl.Segments[1] == "users/") | ||
323 | { | ||
324 | // Parse the avatar name from the path | ||
325 | string username = requestUrl.Segments[requestUrl.Segments.Length - 1]; | ||
326 | string[] name = username.Split('_'); | ||
327 | |||
328 | if (name.Length == 2) | ||
329 | { | ||
330 | account = m_userAccountService.GetUserAccount(UUID.Zero, name[0], name[1]); | ||
331 | return (account != null); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | account = null; | ||
336 | return false; | ||
337 | } | ||
338 | } | ||
339 | } \ No newline at end of file | ||
diff --git a/OpenSim/Server/Handlers/Authorization/AuthorizationServerConnector.cs b/OpenSim/Server/Handlers/Authorization/AuthorizationServerConnector.cs new file mode 100644 index 0000000..20fd0f7 --- /dev/null +++ b/OpenSim/Server/Handlers/Authorization/AuthorizationServerConnector.cs | |||
@@ -0,0 +1,64 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Server.Handlers.Base; | ||
34 | |||
35 | namespace OpenSim.Server.Handlers.Authorization | ||
36 | { | ||
37 | public class AuthorizationServerConnector : ServiceConnector | ||
38 | { | ||
39 | private IAuthorizationService m_AuthorizationService; | ||
40 | private string m_ConfigName = "AuthorizationService"; | ||
41 | |||
42 | public AuthorizationServerConnector(IConfigSource config, IHttpServer server, string configName) : | ||
43 | base(config, server, configName) | ||
44 | { | ||
45 | if (configName != String.Empty) | ||
46 | m_ConfigName = configName; | ||
47 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
48 | if (serverConfig == null) | ||
49 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
50 | |||
51 | string authorizationService = serverConfig.GetString("LocalServiceModule", | ||
52 | String.Empty); | ||
53 | |||
54 | if (authorizationService == String.Empty) | ||
55 | throw new Exception("No AuthorizationService in config file"); | ||
56 | |||
57 | Object[] args = new Object[] { config }; | ||
58 | m_AuthorizationService = | ||
59 | ServerUtils.LoadPlugin<IAuthorizationService>(authorizationService, args); | ||
60 | |||
61 | server.AddStreamHandler(new AuthorizationServerPostHandler(m_AuthorizationService)); | ||
62 | } | ||
63 | } | ||
64 | } | ||
diff --git a/OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs b/OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs new file mode 100644 index 0000000..c9b4e9b --- /dev/null +++ b/OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs | |||
@@ -0,0 +1,73 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.Servers.HttpServer; | ||
42 | |||
43 | namespace OpenSim.Server.Handlers.Authorization | ||
44 | { | ||
45 | public class AuthorizationServerPostHandler : BaseStreamHandler | ||
46 | { | ||
47 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private IAuthorizationService m_AuthorizationService; | ||
50 | |||
51 | public AuthorizationServerPostHandler(IAuthorizationService service) : | ||
52 | base("POST", "/authorization") | ||
53 | { | ||
54 | m_AuthorizationService = service; | ||
55 | } | ||
56 | |||
57 | protected override byte[] ProcessRequest(string path, Stream request, | ||
58 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
59 | { | ||
60 | XmlSerializer xs = new XmlSerializer(typeof (AuthorizationRequest)); | ||
61 | AuthorizationRequest Authorization = (AuthorizationRequest) xs.Deserialize(request); | ||
62 | |||
63 | string message = String.Empty; | ||
64 | bool authorized = m_AuthorizationService.IsAuthorizedForRegion(Authorization.ID, Authorization.FirstName, Authorization.SurName, Authorization.RegionID, out message); | ||
65 | |||
66 | AuthorizationResponse result = new AuthorizationResponse(authorized, Authorization.ID + " has been authorized"); | ||
67 | |||
68 | xs = new XmlSerializer(typeof(AuthorizationResponse)); | ||
69 | return ServerUtils.SerializeResult(xs, result); | ||
70 | |||
71 | } | ||
72 | } | ||
73 | } | ||
diff --git a/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs b/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs new file mode 100644 index 0000000..1831e84 --- /dev/null +++ b/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs | |||
@@ -0,0 +1,64 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.ServiceAuth; | ||
33 | using OpenSim.Framework.Servers.HttpServer; | ||
34 | using OpenSim.Server.Handlers.Base; | ||
35 | |||
36 | namespace OpenSim.Server.Handlers.Avatar | ||
37 | { | ||
38 | public class AvatarServiceConnector : ServiceConnector | ||
39 | { | ||
40 | private IAvatarService m_AvatarService; | ||
41 | private string m_ConfigName = "AvatarService"; | ||
42 | |||
43 | public AvatarServiceConnector(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 avatarService = serverConfig.GetString("LocalServiceModule", | ||
51 | String.Empty); | ||
52 | |||
53 | if (avatarService == String.Empty) | ||
54 | throw new Exception("No LocalServiceModule in config file"); | ||
55 | |||
56 | Object[] args = new Object[] { config }; | ||
57 | m_AvatarService = ServerUtils.LoadPlugin<IAvatarService>(avatarService, args); | ||
58 | |||
59 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
60 | |||
61 | server.AddStreamHandler(new AvatarServerPostHandler(m_AvatarService, auth)); | ||
62 | } | ||
63 | } | ||
64 | } | ||
diff --git a/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs new file mode 100644 index 0000000..ff8699f --- /dev/null +++ b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs | |||
@@ -0,0 +1,276 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using System.Collections.Generic; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Framework; | ||
42 | using OpenSim.Framework.ServiceAuth; | ||
43 | using OpenSim.Framework.Servers.HttpServer; | ||
44 | using OpenMetaverse; | ||
45 | |||
46 | namespace OpenSim.Server.Handlers.Avatar | ||
47 | { | ||
48 | public class AvatarServerPostHandler : BaseStreamHandler | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private IAvatarService m_AvatarService; | ||
53 | |||
54 | public AvatarServerPostHandler(IAvatarService service, IServiceAuth auth) : | ||
55 | base("POST", "/avatar", auth) | ||
56 | { | ||
57 | m_AvatarService = service; | ||
58 | } | ||
59 | |||
60 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
61 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
62 | { | ||
63 | StreamReader sr = new StreamReader(requestData); | ||
64 | string body = sr.ReadToEnd(); | ||
65 | sr.Close(); | ||
66 | body = body.Trim(); | ||
67 | |||
68 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
69 | |||
70 | try | ||
71 | { | ||
72 | Dictionary<string, object> request = | ||
73 | ServerUtils.ParseQueryString(body); | ||
74 | |||
75 | if (!request.ContainsKey("METHOD")) | ||
76 | return FailureResult(); | ||
77 | |||
78 | string method = request["METHOD"].ToString(); | ||
79 | |||
80 | switch (method) | ||
81 | { | ||
82 | case "getavatar": | ||
83 | return GetAvatar(request); | ||
84 | case "setavatar": | ||
85 | return SetAvatar(request); | ||
86 | case "resetavatar": | ||
87 | return ResetAvatar(request); | ||
88 | case "setitems": | ||
89 | return SetItems(request); | ||
90 | case "removeitems": | ||
91 | return RemoveItems(request); | ||
92 | } | ||
93 | m_log.DebugFormat("[AVATAR HANDLER]: unknown method request: {0}", method); | ||
94 | } | ||
95 | catch (Exception e) | ||
96 | { | ||
97 | m_log.Debug("[AVATAR HANDLER]: Exception {0}" + e); | ||
98 | } | ||
99 | |||
100 | return FailureResult(); | ||
101 | |||
102 | } | ||
103 | |||
104 | byte[] GetAvatar(Dictionary<string, object> request) | ||
105 | { | ||
106 | UUID user = UUID.Zero; | ||
107 | |||
108 | if (!request.ContainsKey("UserID")) | ||
109 | return FailureResult(); | ||
110 | |||
111 | if (UUID.TryParse(request["UserID"].ToString(), out user)) | ||
112 | { | ||
113 | AvatarData avatar = m_AvatarService.GetAvatar(user); | ||
114 | if (avatar == null) | ||
115 | return FailureResult(); | ||
116 | |||
117 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
118 | if (avatar == null) | ||
119 | result["result"] = "null"; | ||
120 | else | ||
121 | result["result"] = avatar.ToKeyValuePairs(); | ||
122 | |||
123 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
124 | |||
125 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
126 | } | ||
127 | |||
128 | return FailureResult(); | ||
129 | } | ||
130 | |||
131 | byte[] SetAvatar(Dictionary<string, object> request) | ||
132 | { | ||
133 | UUID user = UUID.Zero; | ||
134 | |||
135 | if (!request.ContainsKey("UserID")) | ||
136 | return FailureResult(); | ||
137 | |||
138 | if (!UUID.TryParse(request["UserID"].ToString(), out user)) | ||
139 | return FailureResult(); | ||
140 | |||
141 | RemoveRequestParamsNotForStorage(request); | ||
142 | |||
143 | AvatarData avatar = new AvatarData(request); | ||
144 | if (m_AvatarService.SetAvatar(user, avatar)) | ||
145 | return SuccessResult(); | ||
146 | |||
147 | return FailureResult(); | ||
148 | } | ||
149 | |||
150 | byte[] ResetAvatar(Dictionary<string, object> request) | ||
151 | { | ||
152 | UUID user = UUID.Zero; | ||
153 | if (!request.ContainsKey("UserID")) | ||
154 | return FailureResult(); | ||
155 | |||
156 | if (!UUID.TryParse(request["UserID"].ToString(), out user)) | ||
157 | return FailureResult(); | ||
158 | |||
159 | RemoveRequestParamsNotForStorage(request); | ||
160 | |||
161 | if (m_AvatarService.ResetAvatar(user)) | ||
162 | return SuccessResult(); | ||
163 | |||
164 | return FailureResult(); | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// Remove parameters that were used to invoke the method and should not in themselves be persisted. | ||
169 | /// </summary> | ||
170 | /// <param name='request'></param> | ||
171 | private void RemoveRequestParamsNotForStorage(Dictionary<string, object> request) | ||
172 | { | ||
173 | request.Remove("VERSIONMAX"); | ||
174 | request.Remove("VERSIONMIN"); | ||
175 | request.Remove("METHOD"); | ||
176 | request.Remove("UserID"); | ||
177 | } | ||
178 | |||
179 | byte[] SetItems(Dictionary<string, object> request) | ||
180 | { | ||
181 | UUID user = UUID.Zero; | ||
182 | string[] names, values; | ||
183 | |||
184 | if (!request.ContainsKey("UserID") || !request.ContainsKey("Names") || !request.ContainsKey("Values")) | ||
185 | return FailureResult(); | ||
186 | |||
187 | if (!UUID.TryParse(request["UserID"].ToString(), out user)) | ||
188 | return FailureResult(); | ||
189 | |||
190 | if (!(request["Names"] is List<string> || request["Values"] is List<string>)) | ||
191 | return FailureResult(); | ||
192 | |||
193 | RemoveRequestParamsNotForStorage(request); | ||
194 | |||
195 | List<string> _names = (List<string>)request["Names"]; | ||
196 | names = _names.ToArray(); | ||
197 | List<string> _values = (List<string>)request["Values"]; | ||
198 | values = _values.ToArray(); | ||
199 | |||
200 | if (m_AvatarService.SetItems(user, names, values)) | ||
201 | return SuccessResult(); | ||
202 | |||
203 | return FailureResult(); | ||
204 | } | ||
205 | |||
206 | byte[] RemoveItems(Dictionary<string, object> request) | ||
207 | { | ||
208 | UUID user = UUID.Zero; | ||
209 | string[] names; | ||
210 | |||
211 | if (!request.ContainsKey("UserID") || !request.ContainsKey("Names")) | ||
212 | return FailureResult(); | ||
213 | |||
214 | if (!UUID.TryParse(request["UserID"].ToString(), out user)) | ||
215 | return FailureResult(); | ||
216 | |||
217 | if (!(request["Names"] is List<string>)) | ||
218 | return FailureResult(); | ||
219 | |||
220 | List<string> _names = (List<string>)request["Names"]; | ||
221 | names = _names.ToArray(); | ||
222 | |||
223 | if (m_AvatarService.RemoveItems(user, names)) | ||
224 | return SuccessResult(); | ||
225 | |||
226 | return FailureResult(); | ||
227 | } | ||
228 | |||
229 | |||
230 | |||
231 | private byte[] SuccessResult() | ||
232 | { | ||
233 | XmlDocument doc = new XmlDocument(); | ||
234 | |||
235 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
236 | "", ""); | ||
237 | |||
238 | doc.AppendChild(xmlnode); | ||
239 | |||
240 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
241 | ""); | ||
242 | |||
243 | doc.AppendChild(rootElement); | ||
244 | |||
245 | XmlElement result = doc.CreateElement("", "result", ""); | ||
246 | result.AppendChild(doc.CreateTextNode("Success")); | ||
247 | |||
248 | rootElement.AppendChild(result); | ||
249 | |||
250 | return Util.DocToBytes(doc); | ||
251 | } | ||
252 | |||
253 | private byte[] FailureResult() | ||
254 | { | ||
255 | XmlDocument doc = new XmlDocument(); | ||
256 | |||
257 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
258 | "", ""); | ||
259 | |||
260 | doc.AppendChild(xmlnode); | ||
261 | |||
262 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
263 | ""); | ||
264 | |||
265 | doc.AppendChild(rootElement); | ||
266 | |||
267 | XmlElement result = doc.CreateElement("", "result", ""); | ||
268 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
269 | |||
270 | rootElement.AppendChild(result); | ||
271 | |||
272 | return Util.DocToBytes(doc); | ||
273 | } | ||
274 | |||
275 | } | ||
276 | } | ||
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakes.cs b/OpenSim/Server/Handlers/BakedTextures/XBakes.cs new file mode 100644 index 0000000..4e55433 --- /dev/null +++ b/OpenSim/Server/Handlers/BakedTextures/XBakes.cs | |||
@@ -0,0 +1,148 @@ | |||
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.Diagnostics; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Text; | ||
33 | using System.Threading; | ||
34 | using System.Reflection; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Console; | ||
37 | using OpenSim.Server.Base; | ||
38 | using OpenSim.Services.Base; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using Nini.Config; | ||
41 | using log4net; | ||
42 | using OpenMetaverse; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.BakedTextures | ||
45 | { | ||
46 | public class XBakes : ServiceBase, IBakedTextureService | ||
47 | { | ||
48 | private static readonly ILog m_log = | ||
49 | LogManager.GetLogger( | ||
50 | MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | protected string m_FSBase; | ||
53 | |||
54 | private System.Text.UTF8Encoding utf8encoding = | ||
55 | new System.Text.UTF8Encoding(); | ||
56 | |||
57 | public XBakes(IConfigSource config) : base(config) | ||
58 | { | ||
59 | MainConsole.Instance.Commands.AddCommand("fs", false, | ||
60 | "delete bakes", "delete bakes <ID>", | ||
61 | "Delete agent's baked textures from server", | ||
62 | HandleDeleteBakes); | ||
63 | |||
64 | IConfig assetConfig = config.Configs["BakedTextureService"]; | ||
65 | if (assetConfig == null) | ||
66 | { | ||
67 | throw new Exception("No BakedTextureService configuration"); | ||
68 | } | ||
69 | |||
70 | m_FSBase = assetConfig.GetString("BaseDirectory", String.Empty); | ||
71 | if (m_FSBase == String.Empty) | ||
72 | { | ||
73 | m_log.ErrorFormat("[BAKES]: BaseDirectory not specified"); | ||
74 | throw new Exception("Configuration error"); | ||
75 | } | ||
76 | |||
77 | m_log.Info("[BAKES]: XBakes service enabled"); | ||
78 | } | ||
79 | |||
80 | public string Get(string id) | ||
81 | { | ||
82 | string file = HashToFile(id); | ||
83 | string diskFile = Path.Combine(m_FSBase, file); | ||
84 | |||
85 | if (File.Exists(diskFile)) | ||
86 | { | ||
87 | try | ||
88 | { | ||
89 | byte[] content = File.ReadAllBytes(diskFile); | ||
90 | |||
91 | return utf8encoding.GetString(content); | ||
92 | } | ||
93 | catch | ||
94 | { | ||
95 | } | ||
96 | } | ||
97 | return String.Empty; | ||
98 | } | ||
99 | |||
100 | public void Store(string id, string sdata) | ||
101 | { | ||
102 | string file = HashToFile(id); | ||
103 | string diskFile = Path.Combine(m_FSBase, file); | ||
104 | |||
105 | Directory.CreateDirectory(Path.GetDirectoryName(diskFile)); | ||
106 | |||
107 | File.Delete(diskFile); | ||
108 | |||
109 | byte[] data = utf8encoding.GetBytes(sdata); | ||
110 | |||
111 | using (FileStream fs = File.Create(diskFile)) | ||
112 | fs.Write(data, 0, data.Length); | ||
113 | } | ||
114 | |||
115 | private void HandleDeleteBakes(string module, string[] args) | ||
116 | { | ||
117 | if (args.Length < 3) | ||
118 | { | ||
119 | MainConsole.Instance.Output("Syntax: delete bakes <ID>"); | ||
120 | return; | ||
121 | } | ||
122 | |||
123 | string file = HashToFile(args[2]); | ||
124 | string diskFile = Path.Combine(m_FSBase, file); | ||
125 | |||
126 | if (File.Exists(diskFile)) | ||
127 | { | ||
128 | File.Delete(diskFile); | ||
129 | MainConsole.Instance.Output("Bakes deleted"); | ||
130 | return; | ||
131 | } | ||
132 | MainConsole.Instance.Output("Bakes not found"); | ||
133 | } | ||
134 | |||
135 | public string HashToPath(string hash) | ||
136 | { | ||
137 | return Path.Combine(hash.Substring(0, 2), | ||
138 | Path.Combine(hash.Substring(2, 2), | ||
139 | Path.Combine(hash.Substring(4, 2), | ||
140 | hash.Substring(6, 4)))); | ||
141 | } | ||
142 | |||
143 | public string HashToFile(string hash) | ||
144 | { | ||
145 | return Path.Combine(HashToPath(hash), hash); | ||
146 | } | ||
147 | } | ||
148 | } | ||
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs new file mode 100644 index 0000000..3c61673 --- /dev/null +++ b/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs | |||
@@ -0,0 +1,71 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.ServiceAuth; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.BakedTextures | ||
45 | { | ||
46 | public class BakesServerGetHandler : BaseStreamHandler | ||
47 | { | ||
48 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private IBakedTextureService m_BakesService; | ||
51 | private System.Text.UTF8Encoding utf8 = | ||
52 | new System.Text.UTF8Encoding(); | ||
53 | |||
54 | public BakesServerGetHandler(IBakedTextureService service, IServiceAuth auth) : | ||
55 | base("GET", "/bakes", auth) | ||
56 | { | ||
57 | m_BakesService = service; | ||
58 | } | ||
59 | |||
60 | protected override byte[] ProcessRequest( | ||
61 | string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
62 | { | ||
63 | string[] p = SplitParams(path); | ||
64 | |||
65 | if (p.Length == 0) | ||
66 | return new byte[0]; | ||
67 | |||
68 | return utf8.GetBytes(m_BakesService.Get(p[0])); | ||
69 | } | ||
70 | } | ||
71 | } | ||
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs new file mode 100644 index 0000000..4c12967 --- /dev/null +++ b/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs | |||
@@ -0,0 +1,69 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.ServiceAuth; | ||
33 | using OpenSim.Framework.Servers.HttpServer; | ||
34 | using OpenSim.Server.Handlers.Base; | ||
35 | |||
36 | namespace OpenSim.Server.Handlers.BakedTextures | ||
37 | { | ||
38 | public class XBakesConnector : ServiceConnector | ||
39 | { | ||
40 | private IBakedTextureService m_BakesService; | ||
41 | private string m_ConfigName = "BakedTextureService"; | ||
42 | |||
43 | public XBakesConnector(IConfigSource config, IHttpServer server, string configName) : | ||
44 | base(config, server, configName) | ||
45 | { | ||
46 | if (configName != String.Empty) | ||
47 | m_ConfigName = configName; | ||
48 | |||
49 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
50 | if (serverConfig == null) | ||
51 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
52 | |||
53 | string assetService = serverConfig.GetString("LocalServiceModule", | ||
54 | String.Empty); | ||
55 | |||
56 | if (assetService == String.Empty) | ||
57 | throw new Exception("No BakedTextureService in config file"); | ||
58 | |||
59 | Object[] args = new Object[] { config }; | ||
60 | m_BakesService = | ||
61 | ServerUtils.LoadPlugin<IBakedTextureService>(assetService, args); | ||
62 | |||
63 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
64 | |||
65 | server.AddStreamHandler(new BakesServerGetHandler(m_BakesService, auth)); | ||
66 | server.AddStreamHandler(new BakesServerPostHandler(m_BakesService, auth)); | ||
67 | } | ||
68 | } | ||
69 | } | ||
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs new file mode 100644 index 0000000..e38543b --- /dev/null +++ b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs | |||
@@ -0,0 +1,76 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.ServiceAuth; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.BakedTextures | ||
45 | { | ||
46 | public class BakesServerPostHandler : BaseStreamHandler | ||
47 | { | ||
48 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private IBakedTextureService m_BakesService; | ||
51 | |||
52 | public BakesServerPostHandler(IBakedTextureService service, IServiceAuth auth) : | ||
53 | base("POST", "/bakes", auth) | ||
54 | { | ||
55 | m_BakesService = service; | ||
56 | } | ||
57 | |||
58 | protected override byte[] ProcessRequest( | ||
59 | string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
60 | { | ||
61 | string[] p = SplitParams(path); | ||
62 | |||
63 | if (p.Length == 0) | ||
64 | { | ||
65 | return new byte[0]; | ||
66 | } | ||
67 | |||
68 | StreamReader sr = new StreamReader(request); | ||
69 | |||
70 | m_BakesService.Store(p[0], sr.ReadToEnd()); | ||
71 | sr.Close(); | ||
72 | |||
73 | return new byte[0]; | ||
74 | } | ||
75 | } | ||
76 | } \ No newline at end of file | ||
diff --git a/OpenSim/Server/Handlers/Base/ServerConnector.cs b/OpenSim/Server/Handlers/Base/ServerConnector.cs new file mode 100644 index 0000000..72014db --- /dev/null +++ b/OpenSim/Server/Handlers/Base/ServerConnector.cs | |||
@@ -0,0 +1,113 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | |||
34 | namespace OpenSim.Server.Handlers.Base | ||
35 | { | ||
36 | public interface IServiceConnector | ||
37 | { | ||
38 | } | ||
39 | |||
40 | public class ServiceConnector : IServiceConnector | ||
41 | { | ||
42 | public virtual string ConfigURL | ||
43 | { | ||
44 | get { return String.Empty; } | ||
45 | } | ||
46 | |||
47 | public virtual string ConfigName | ||
48 | { | ||
49 | get; | ||
50 | protected set; | ||
51 | } | ||
52 | |||
53 | public virtual string ConfigFile | ||
54 | { | ||
55 | get; | ||
56 | protected set; | ||
57 | } | ||
58 | |||
59 | public virtual IConfigSource Config | ||
60 | { | ||
61 | get; | ||
62 | protected set; | ||
63 | } | ||
64 | |||
65 | public ServiceConnector() | ||
66 | { | ||
67 | } | ||
68 | |||
69 | public ServiceConnector(IConfigSource config, IHttpServer server, string configName) | ||
70 | { | ||
71 | } | ||
72 | |||
73 | // We call this from our plugin module to get our configuration | ||
74 | public IConfig GetConfig() | ||
75 | { | ||
76 | IConfig config = null; | ||
77 | config = ServerUtils.GetConfig(ConfigFile, ConfigName); | ||
78 | |||
79 | // Our file is not here? We can get one to bootstrap our plugin module | ||
80 | if ( config == null ) | ||
81 | { | ||
82 | IConfigSource remotesource = GetConfigSource(); | ||
83 | |||
84 | if (remotesource != null) | ||
85 | { | ||
86 | IniConfigSource initialconfig = new IniConfigSource(); | ||
87 | initialconfig.Merge (remotesource); | ||
88 | initialconfig.Save(ConfigFile); | ||
89 | } | ||
90 | |||
91 | config = remotesource.Configs[ConfigName]; | ||
92 | } | ||
93 | |||
94 | return config; | ||
95 | } | ||
96 | |||
97 | // We get our remote initial configuration for bootstrapping in case | ||
98 | // we have no configuration in our main file or in an existing | ||
99 | // modular config file. This is the last resort to bootstrap the | ||
100 | // configuration, likely a new plugin loading for the first time. | ||
101 | private IConfigSource GetConfigSource() | ||
102 | { | ||
103 | IConfigSource source = null; | ||
104 | |||
105 | source = ServerUtils.LoadInitialConfig(ConfigURL); | ||
106 | |||
107 | if (source == null) | ||
108 | System.Console.WriteLine(String.Format ("Config Url: {0} Not found!", ConfigURL)); | ||
109 | |||
110 | return source; | ||
111 | } | ||
112 | } | ||
113 | } | ||
diff --git a/OpenSim/Server/Handlers/Base/Utils.cs b/OpenSim/Server/Handlers/Base/Utils.cs new file mode 100644 index 0000000..48d923f --- /dev/null +++ b/OpenSim/Server/Handlers/Base/Utils.cs | |||
@@ -0,0 +1,97 @@ | |||
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; | ||
30 | using System.Net; | ||
31 | |||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Framework.Servers.HttpServer; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OpenMetaverse; | ||
36 | |||
37 | namespace OpenSim.Server.Handlers.Base | ||
38 | { | ||
39 | public class RestHandlerUtils | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// Extract the param from an uri. | ||
43 | /// </summary> | ||
44 | /// <param name="uri">Something like this: /uuid/ or /uuid/handle/release</param> | ||
45 | /// <param name="uri">uuid on uuid field</param> | ||
46 | /// <param name="action">optional action</param> | ||
47 | public static bool GetParams(string path, out UUID uuid, out ulong regionHandle, out string action) | ||
48 | { | ||
49 | uuid = UUID.Zero; | ||
50 | action = ""; | ||
51 | regionHandle = 0; | ||
52 | |||
53 | path = path.Trim(new char[] { '/' }); | ||
54 | string[] parts = path.Split('/'); | ||
55 | if (parts.Length <= 1) | ||
56 | { | ||
57 | return false; | ||
58 | } | ||
59 | else | ||
60 | { | ||
61 | if (!UUID.TryParse(parts[0], out uuid)) | ||
62 | return false; | ||
63 | |||
64 | if (parts.Length >= 2) | ||
65 | UInt64.TryParse(parts[1], out regionHandle); | ||
66 | if (parts.Length >= 3) | ||
67 | action = parts[2]; | ||
68 | |||
69 | return true; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | public static bool GetAuthentication(IOSHttpRequest httpRequest, out string authority, out string authKey) | ||
74 | { | ||
75 | authority = string.Empty; | ||
76 | authKey = string.Empty; | ||
77 | |||
78 | Uri authUri; | ||
79 | |||
80 | string auth = httpRequest.Headers["authentication"]; | ||
81 | // Authentication keys look like this: | ||
82 | // http://orgrid.org:8002/<uuid> | ||
83 | if ((auth != null) && (!string.Empty.Equals(auth)) && auth != "None") | ||
84 | { | ||
85 | if (Uri.TryCreate(auth, UriKind.Absolute, out authUri)) | ||
86 | { | ||
87 | authority = authUri.Authority; | ||
88 | authKey = authUri.PathAndQuery.Trim('/'); | ||
89 | return true; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | return false; | ||
94 | } | ||
95 | |||
96 | } | ||
97 | } | ||
diff --git a/OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs b/OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs new file mode 100644 index 0000000..e0c2810 --- /dev/null +++ b/OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs | |||
@@ -0,0 +1,343 @@ | |||
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.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Net; | ||
32 | |||
33 | using Nini.Config; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | |||
37 | using OpenSim.Server.Base; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.ServiceAuth; | ||
41 | using OpenSim.Framework.Servers.HttpServer; | ||
42 | using OpenSim.Server.Handlers.Base; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers | ||
45 | { | ||
46 | public class EstateDataRobustConnector : ServiceConnector | ||
47 | { | ||
48 | private string m_ConfigName = "EstateService"; | ||
49 | |||
50 | public EstateDataRobustConnector(IConfigSource config, IHttpServer server, string configName) : | ||
51 | base(config, server, configName) | ||
52 | { | ||
53 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
54 | if (serverConfig == null) | ||
55 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | ||
56 | |||
57 | string service = serverConfig.GetString("LocalServiceModule", | ||
58 | String.Empty); | ||
59 | |||
60 | if (service == String.Empty) | ||
61 | throw new Exception("No LocalServiceModule in config file"); | ||
62 | |||
63 | Object[] args = new Object[] { config }; | ||
64 | IEstateDataService e_service = ServerUtils.LoadPlugin<IEstateDataService>(service, args); | ||
65 | |||
66 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ; | ||
67 | |||
68 | server.AddStreamHandler(new EstateServerGetHandler(e_service, auth)); | ||
69 | server.AddStreamHandler(new EstateServerPostHandler(e_service, auth)); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | |||
74 | public class EstateServerGetHandler : BaseStreamHandler | ||
75 | { | ||
76 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
77 | |||
78 | IEstateDataService m_EstateService; | ||
79 | |||
80 | // Possibilities | ||
81 | // /estates/estate/?region=uuid&create=[t|f] | ||
82 | // /estates/estate/?eid=int | ||
83 | // /estates/?name=string | ||
84 | // /estates/?owner=uuid | ||
85 | // /estates/ (all) | ||
86 | // /estates/regions/?eid=int | ||
87 | |||
88 | public EstateServerGetHandler(IEstateDataService service, IServiceAuth auth) : | ||
89 | base("GET", "/estates", auth) | ||
90 | { | ||
91 | m_EstateService = service; | ||
92 | } | ||
93 | |||
94 | protected override byte[] ProcessRequest(string path, Stream request, | ||
95 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
96 | { | ||
97 | Dictionary<string, object> data = null; | ||
98 | |||
99 | string[] p = SplitParams(path); | ||
100 | |||
101 | // /estates/ (all) | ||
102 | // /estates/?name=string | ||
103 | // /estates/?owner=uuid | ||
104 | if (p.Length == 0) | ||
105 | data = GetEstates(httpRequest, httpResponse); | ||
106 | else | ||
107 | { | ||
108 | string resource = p[0]; | ||
109 | |||
110 | // /estates/estate/?region=uuid&create=[t|f] | ||
111 | // /estates/estate/?eid=int | ||
112 | if ("estate".Equals(resource)) | ||
113 | data = GetEstate(httpRequest, httpResponse); | ||
114 | // /estates/regions/?eid=int | ||
115 | else if ("regions".Equals(resource)) | ||
116 | data = GetRegions(httpRequest, httpResponse); | ||
117 | } | ||
118 | |||
119 | if (data == null) | ||
120 | data = new Dictionary<string, object>(); | ||
121 | |||
122 | string xmlString = ServerUtils.BuildXmlResponse(data); | ||
123 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
124 | |||
125 | } | ||
126 | |||
127 | private Dictionary<string, object> GetEstates(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
128 | { | ||
129 | // /estates/ (all) | ||
130 | // /estates/?name=string | ||
131 | // /estates/?owner=uuid | ||
132 | |||
133 | Dictionary<string, object> data = null; | ||
134 | string name = (string)httpRequest.Query["name"]; | ||
135 | string owner = (string)httpRequest.Query["owner"]; | ||
136 | |||
137 | if (!string.IsNullOrEmpty(name) || !string.IsNullOrEmpty(owner)) | ||
138 | { | ||
139 | List<int> estateIDs = null; | ||
140 | if (!string.IsNullOrEmpty(name)) | ||
141 | { | ||
142 | estateIDs = m_EstateService.GetEstates(name); | ||
143 | } | ||
144 | else if (!string.IsNullOrEmpty(owner)) | ||
145 | { | ||
146 | UUID ownerID = UUID.Zero; | ||
147 | if (UUID.TryParse(owner, out ownerID)) | ||
148 | estateIDs = m_EstateService.GetEstatesByOwner(ownerID); | ||
149 | } | ||
150 | |||
151 | if (estateIDs == null || (estateIDs != null && estateIDs.Count == 0)) | ||
152 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
153 | else | ||
154 | { | ||
155 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
156 | httpResponse.ContentType = "text/xml"; | ||
157 | data = new Dictionary<string, object>(); | ||
158 | int i = 0; | ||
159 | foreach (int id in estateIDs) | ||
160 | data["estate" + i++] = id; | ||
161 | } | ||
162 | } | ||
163 | else | ||
164 | { | ||
165 | List<EstateSettings> estates = m_EstateService.LoadEstateSettingsAll(); | ||
166 | if (estates == null || estates.Count == 0) | ||
167 | { | ||
168 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
173 | httpResponse.ContentType = "text/xml"; | ||
174 | data = new Dictionary<string, object>(); | ||
175 | int i = 0; | ||
176 | foreach (EstateSettings es in estates) | ||
177 | data["estate" + i++] = es.ToMap(); | ||
178 | |||
179 | } | ||
180 | } | ||
181 | |||
182 | return data; | ||
183 | } | ||
184 | |||
185 | private Dictionary<string, object> GetEstate(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
186 | { | ||
187 | // /estates/estate/?region=uuid&create=[t|f] | ||
188 | // /estates/estate/?eid=int | ||
189 | Dictionary<string, object> data = null; | ||
190 | string region = (string)httpRequest.Query["region"]; | ||
191 | string eid = (string)httpRequest.Query["eid"]; | ||
192 | |||
193 | EstateSettings estate = null; | ||
194 | |||
195 | if (!string.IsNullOrEmpty(region)) | ||
196 | { | ||
197 | UUID regionID = UUID.Zero; | ||
198 | if (UUID.TryParse(region, out regionID)) | ||
199 | { | ||
200 | string create = (string)httpRequest.Query["create"]; | ||
201 | bool createYN = false; | ||
202 | Boolean.TryParse(create, out createYN); | ||
203 | estate = m_EstateService.LoadEstateSettings(regionID, createYN); | ||
204 | } | ||
205 | } | ||
206 | else if (!string.IsNullOrEmpty(eid)) | ||
207 | { | ||
208 | int id = 0; | ||
209 | if (Int32.TryParse(eid, out id)) | ||
210 | estate = m_EstateService.LoadEstateSettings(id); | ||
211 | } | ||
212 | |||
213 | if (estate != null) | ||
214 | { | ||
215 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
216 | httpResponse.ContentType = "text/xml"; | ||
217 | data = estate.ToMap(); | ||
218 | } | ||
219 | else | ||
220 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
221 | |||
222 | return data; | ||
223 | } | ||
224 | |||
225 | private Dictionary<string, object> GetRegions(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
226 | { | ||
227 | // /estates/regions/?eid=int | ||
228 | Dictionary<string, object> data = null; | ||
229 | string eid = (string)httpRequest.Query["eid"]; | ||
230 | |||
231 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
232 | if (!string.IsNullOrEmpty(eid)) | ||
233 | { | ||
234 | int id = 0; | ||
235 | if (Int32.TryParse(eid, out id)) | ||
236 | { | ||
237 | List<UUID> regions = m_EstateService.GetRegions(id); | ||
238 | if (regions != null && regions.Count > 0) | ||
239 | { | ||
240 | data = new Dictionary<string, object>(); | ||
241 | int i = 0; | ||
242 | foreach (UUID uuid in regions) | ||
243 | data["region" + i++] = uuid.ToString(); | ||
244 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
245 | httpResponse.ContentType = "text/xml"; | ||
246 | } | ||
247 | } | ||
248 | } | ||
249 | |||
250 | return data; | ||
251 | } | ||
252 | } | ||
253 | |||
254 | public class EstateServerPostHandler : BaseStreamHandler | ||
255 | { | ||
256 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
257 | |||
258 | IEstateDataService m_EstateService; | ||
259 | |||
260 | // Possibilities | ||
261 | // /estates/estate/ (post an estate) | ||
262 | // /estates/estate/?eid=int®ion=uuid (link a region to an estate) | ||
263 | |||
264 | public EstateServerPostHandler(IEstateDataService service, IServiceAuth auth) : | ||
265 | base("POST", "/estates", auth) | ||
266 | { | ||
267 | m_EstateService = service; | ||
268 | } | ||
269 | |||
270 | protected override byte[] ProcessRequest(string path, Stream request, | ||
271 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
272 | { | ||
273 | Dictionary<string, object> data = null; | ||
274 | |||
275 | string[] p = SplitParams(path); | ||
276 | |||
277 | if (p.Length > 0) | ||
278 | { | ||
279 | string resource = p[0]; | ||
280 | |||
281 | // /estates/estate/ | ||
282 | // /estates/estate/?eid=int®ion=uuid | ||
283 | if ("estate".Equals(resource)) | ||
284 | { | ||
285 | StreamReader sr = new StreamReader(request); | ||
286 | string body = sr.ReadToEnd(); | ||
287 | sr.Close(); | ||
288 | body = body.Trim(); | ||
289 | |||
290 | Dictionary<string, object> requestData = ServerUtils.ParseQueryString(body); | ||
291 | |||
292 | data = UpdateEstate(requestData, httpRequest, httpResponse); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | if (data == null) | ||
297 | data = new Dictionary<string, object>(); | ||
298 | |||
299 | string xmlString = ServerUtils.BuildXmlResponse(data); | ||
300 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
301 | |||
302 | } | ||
303 | |||
304 | private Dictionary<string, object> UpdateEstate(Dictionary<string, object> requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
305 | { | ||
306 | // /estates/estate/ | ||
307 | // /estates/estate/?eid=int®ion=uuid | ||
308 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
309 | string eid = (string)httpRequest.Query["eid"]; | ||
310 | string region = (string)httpRequest.Query["region"]; | ||
311 | |||
312 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
313 | |||
314 | if (string.IsNullOrEmpty(eid) && string.IsNullOrEmpty(region) && | ||
315 | requestData.ContainsKey("OP") && requestData["OP"] != null && "STORE".Equals(requestData["OP"])) | ||
316 | { | ||
317 | // /estates/estate/ | ||
318 | EstateSettings es = new EstateSettings(requestData); | ||
319 | m_EstateService.StoreEstateSettings(es); | ||
320 | //m_log.DebugFormat("[EstateServerPostHandler]: Store estate {0}", es.ToString()); | ||
321 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
322 | result["Result"] = true; | ||
323 | } | ||
324 | else if (!string.IsNullOrEmpty(region) && !string.IsNullOrEmpty(eid) && | ||
325 | requestData.ContainsKey("OP") && requestData["OP"] != null && "LINK".Equals(requestData["OP"])) | ||
326 | { | ||
327 | int id = 0; | ||
328 | UUID regionID = UUID.Zero; | ||
329 | if (UUID.TryParse(region, out regionID) && Int32.TryParse(eid, out id)) | ||
330 | { | ||
331 | m_log.DebugFormat("[EstateServerPostHandler]: Link region {0} to estate {1}", regionID, id); | ||
332 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
333 | result["Result"] = m_EstateService.LinkRegion(regionID, id); | ||
334 | } | ||
335 | } | ||
336 | else | ||
337 | m_log.WarnFormat("[EstateServerPostHandler]: something wrong with POST request {0}", httpRequest.RawUrl); | ||
338 | |||
339 | return result; | ||
340 | } | ||
341 | |||
342 | } | ||
343 | } | ||
diff --git a/OpenSim/Server/Handlers/Freeswitch/FreeswitchServerConnector.cs b/OpenSim/Server/Handlers/Freeswitch/FreeswitchServerConnector.cs new file mode 100644 index 0000000..da56b87 --- /dev/null +++ b/OpenSim/Server/Handlers/Freeswitch/FreeswitchServerConnector.cs | |||
@@ -0,0 +1,128 @@ | |||
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; | ||
30 | using System.Web; | ||
31 | using System.Reflection; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Server.Base; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OpenSim.Framework.Servers.HttpServer; | ||
36 | using OpenSim.Server.Handlers.Base; | ||
37 | using log4net; | ||
38 | using OpenMetaverse; | ||
39 | using OpenMetaverse.StructuredData; | ||
40 | |||
41 | namespace OpenSim.Server.Handlers.Freeswitch | ||
42 | { | ||
43 | public class FreeswitchServerConnector : ServiceConnector | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private IFreeswitchService m_FreeswitchService; | ||
48 | private string m_ConfigName = "FreeswitchService"; | ||
49 | protected readonly string m_freeSwitchAPIPrefix = "/fsapi"; | ||
50 | |||
51 | public FreeswitchServerConnector(IConfigSource config, IHttpServer server, string configName) : | ||
52 | base(config, server, configName) | ||
53 | { | ||
54 | if (configName != String.Empty) | ||
55 | m_ConfigName = configName; | ||
56 | |||
57 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
58 | if (serverConfig == null) | ||
59 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
60 | |||
61 | string freeswitchService = serverConfig.GetString("LocalServiceModule", | ||
62 | String.Empty); | ||
63 | |||
64 | if (freeswitchService == String.Empty) | ||
65 | throw new Exception("No LocalServiceModule in config file"); | ||
66 | |||
67 | Object[] args = new Object[] { config }; | ||
68 | m_FreeswitchService = | ||
69 | ServerUtils.LoadPlugin<IFreeswitchService>(freeswitchService, args); | ||
70 | |||
71 | server.AddHTTPHandler(String.Format("{0}/freeswitch-config", m_freeSwitchAPIPrefix), FreeSwitchConfigHTTPHandler); | ||
72 | server.AddHTTPHandler(String.Format("{0}/region-config", m_freeSwitchAPIPrefix), RegionConfigHTTPHandler); | ||
73 | } | ||
74 | |||
75 | public Hashtable FreeSwitchConfigHTTPHandler(Hashtable request) | ||
76 | { | ||
77 | Hashtable response = new Hashtable(); | ||
78 | response["str_response_string"] = string.Empty; | ||
79 | response["content_type"] = "text/plain"; | ||
80 | response["keepalive"] = false; | ||
81 | response["int_response_code"] = 500; | ||
82 | |||
83 | Hashtable requestBody = ParseRequestBody((string) request["body"]); | ||
84 | |||
85 | string section = (string) requestBody["section"]; | ||
86 | |||
87 | if (section == "directory") | ||
88 | response = m_FreeswitchService.HandleDirectoryRequest(requestBody); | ||
89 | else if (section == "dialplan") | ||
90 | response = m_FreeswitchService.HandleDialplanRequest(requestBody); | ||
91 | else | ||
92 | m_log.WarnFormat("[FreeSwitchVoice]: section was {0}", section); | ||
93 | |||
94 | return response; | ||
95 | } | ||
96 | |||
97 | private Hashtable ParseRequestBody(string body) | ||
98 | { | ||
99 | Hashtable bodyParams = new Hashtable(); | ||
100 | // split string | ||
101 | string [] nvps = body.Split(new Char [] {'&'}); | ||
102 | |||
103 | foreach (string s in nvps) | ||
104 | { | ||
105 | if (s.Trim() != "") | ||
106 | { | ||
107 | string [] nvp = s.Split(new Char [] {'='}); | ||
108 | bodyParams.Add(HttpUtility.UrlDecode(nvp[0]), HttpUtility.UrlDecode(nvp[1])); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | return bodyParams; | ||
113 | } | ||
114 | |||
115 | public Hashtable RegionConfigHTTPHandler(Hashtable request) | ||
116 | { | ||
117 | Hashtable response = new Hashtable(); | ||
118 | response["content_type"] = "text/json"; | ||
119 | response["keepalive"] = false; | ||
120 | response["int_response_code"] = 200; | ||
121 | |||
122 | response["str_response_string"] = m_FreeswitchService.GetJsonConfig(); | ||
123 | |||
124 | return response; | ||
125 | } | ||
126 | |||
127 | } | ||
128 | } | ||
diff --git a/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs b/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs new file mode 100644 index 0000000..b0e6c7d --- /dev/null +++ b/OpenSim/Server/Handlers/Friends/FriendServerConnector.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 | |||
28 | using System; | ||
29 | using Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.ServiceAuth; | ||
33 | using OpenSim.Framework.Servers.HttpServer; | ||
34 | using OpenSim.Server.Handlers.Base; | ||
35 | |||
36 | namespace OpenSim.Server.Handlers.Friends | ||
37 | { | ||
38 | public class FriendsServiceConnector : ServiceConnector | ||
39 | { | ||
40 | private IFriendsService m_FriendsService; | ||
41 | private string m_ConfigName = "FriendsService"; | ||
42 | |||
43 | public FriendsServiceConnector(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 theService = serverConfig.GetString("LocalServiceModule", | ||
51 | String.Empty); | ||
52 | |||
53 | if (theService == String.Empty) | ||
54 | throw new Exception("No LocalServiceModule in config file"); | ||
55 | |||
56 | Object[] args = new Object[] { config }; | ||
57 | m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(theService, args); | ||
58 | |||
59 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
60 | server.AddStreamHandler(new FriendsServerPostHandler(m_FriendsService, auth)); | ||
61 | } | ||
62 | } | ||
63 | } | ||
diff --git a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs new file mode 100644 index 0000000..3aab30b --- /dev/null +++ b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs | |||
@@ -0,0 +1,282 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using System.Collections.Generic; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
42 | using OpenSim.Framework; | ||
43 | using OpenSim.Framework.ServiceAuth; | ||
44 | using OpenSim.Framework.Servers.HttpServer; | ||
45 | using OpenMetaverse; | ||
46 | |||
47 | namespace OpenSim.Server.Handlers.Friends | ||
48 | { | ||
49 | public class FriendsServerPostHandler : BaseStreamHandler | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | private IFriendsService m_FriendsService; | ||
54 | |||
55 | public FriendsServerPostHandler(IFriendsService service, IServiceAuth auth) : | ||
56 | base("POST", "/friends", auth) | ||
57 | { | ||
58 | m_FriendsService = service; | ||
59 | } | ||
60 | |||
61 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
62 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
63 | { | ||
64 | StreamReader sr = new StreamReader(requestData); | ||
65 | string body = sr.ReadToEnd(); | ||
66 | sr.Close(); | ||
67 | body = body.Trim(); | ||
68 | |||
69 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
70 | |||
71 | try | ||
72 | { | ||
73 | Dictionary<string, object> request = | ||
74 | ServerUtils.ParseQueryString(body); | ||
75 | |||
76 | if (!request.ContainsKey("METHOD")) | ||
77 | return FailureResult(); | ||
78 | |||
79 | string method = request["METHOD"].ToString(); | ||
80 | |||
81 | switch (method) | ||
82 | { | ||
83 | case "getfriends": | ||
84 | return GetFriends(request); | ||
85 | |||
86 | case "getfriends_string": | ||
87 | return GetFriendsString(request); | ||
88 | |||
89 | case "storefriend": | ||
90 | return StoreFriend(request); | ||
91 | |||
92 | case "deletefriend": | ||
93 | return DeleteFriend(request); | ||
94 | |||
95 | case "deletefriend_string": | ||
96 | return DeleteFriendString(request); | ||
97 | |||
98 | } | ||
99 | |||
100 | m_log.DebugFormat("[FRIENDS HANDLER]: unknown method request {0}", method); | ||
101 | } | ||
102 | catch (Exception e) | ||
103 | { | ||
104 | m_log.DebugFormat("[FRIENDS HANDLER]: Exception {0}", e); | ||
105 | } | ||
106 | |||
107 | return FailureResult(); | ||
108 | } | ||
109 | |||
110 | #region Method-specific handlers | ||
111 | |||
112 | byte[] GetFriends(Dictionary<string, object> request) | ||
113 | { | ||
114 | UUID principalID = UUID.Zero; | ||
115 | if (request.ContainsKey("PRINCIPALID")) | ||
116 | UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID); | ||
117 | else | ||
118 | m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to get friends"); | ||
119 | |||
120 | FriendInfo[] finfos = m_FriendsService.GetFriends(principalID); | ||
121 | |||
122 | return PackageFriends(finfos); | ||
123 | } | ||
124 | |||
125 | byte[] GetFriendsString(Dictionary<string, object> request) | ||
126 | { | ||
127 | string principalID = string.Empty; | ||
128 | if (request.ContainsKey("PRINCIPALID")) | ||
129 | principalID = request["PRINCIPALID"].ToString(); | ||
130 | else | ||
131 | m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to get friends"); | ||
132 | |||
133 | FriendInfo[] finfos = m_FriendsService.GetFriends(principalID); | ||
134 | |||
135 | return PackageFriends(finfos); | ||
136 | } | ||
137 | |||
138 | private byte[] PackageFriends(FriendInfo[] finfos) | ||
139 | { | ||
140 | |||
141 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
142 | if ((finfos == null) || ((finfos != null) && (finfos.Length == 0))) | ||
143 | result["result"] = "null"; | ||
144 | else | ||
145 | { | ||
146 | int i = 0; | ||
147 | foreach (FriendInfo finfo in finfos) | ||
148 | { | ||
149 | Dictionary<string, object> rinfoDict = finfo.ToKeyValuePairs(); | ||
150 | result["friend" + i] = rinfoDict; | ||
151 | i++; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
156 | |||
157 | //m_log.DebugFormat("[FRIENDS HANDLER]: resp string: {0}", xmlString); | ||
158 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
159 | } | ||
160 | |||
161 | byte[] StoreFriend(Dictionary<string, object> request) | ||
162 | { | ||
163 | string principalID = string.Empty, friend = string.Empty; int flags = 0; | ||
164 | FromKeyValuePairs(request, out principalID, out friend, out flags); | ||
165 | bool success = m_FriendsService.StoreFriend(principalID, friend, flags); | ||
166 | |||
167 | if (success) | ||
168 | return SuccessResult(); | ||
169 | else | ||
170 | return FailureResult(); | ||
171 | } | ||
172 | |||
173 | byte[] DeleteFriend(Dictionary<string, object> request) | ||
174 | { | ||
175 | UUID principalID = UUID.Zero; | ||
176 | if (request.ContainsKey("PRINCIPALID")) | ||
177 | UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID); | ||
178 | else | ||
179 | m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to delete friend"); | ||
180 | string friend = string.Empty; | ||
181 | if (request.ContainsKey("FRIEND")) | ||
182 | friend = request["FRIEND"].ToString(); | ||
183 | |||
184 | bool success = m_FriendsService.Delete(principalID, friend); | ||
185 | if (success) | ||
186 | return SuccessResult(); | ||
187 | else | ||
188 | return FailureResult(); | ||
189 | } | ||
190 | |||
191 | byte[] DeleteFriendString(Dictionary<string, object> request) | ||
192 | { | ||
193 | string principalID = string.Empty; | ||
194 | if (request.ContainsKey("PRINCIPALID")) | ||
195 | principalID = request["PRINCIPALID"].ToString(); | ||
196 | else | ||
197 | m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to delete friend"); | ||
198 | string friend = string.Empty; | ||
199 | if (request.ContainsKey("FRIEND")) | ||
200 | friend = request["FRIEND"].ToString(); | ||
201 | |||
202 | bool success = m_FriendsService.Delete(principalID, friend); | ||
203 | if (success) | ||
204 | return SuccessResult(); | ||
205 | else | ||
206 | return FailureResult(); | ||
207 | } | ||
208 | |||
209 | #endregion | ||
210 | |||
211 | #region Misc | ||
212 | |||
213 | private byte[] SuccessResult() | ||
214 | { | ||
215 | XmlDocument doc = new XmlDocument(); | ||
216 | |||
217 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
218 | "", ""); | ||
219 | |||
220 | doc.AppendChild(xmlnode); | ||
221 | |||
222 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
223 | ""); | ||
224 | |||
225 | doc.AppendChild(rootElement); | ||
226 | |||
227 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
228 | result.AppendChild(doc.CreateTextNode("Success")); | ||
229 | |||
230 | rootElement.AppendChild(result); | ||
231 | |||
232 | return Util.DocToBytes(doc); | ||
233 | } | ||
234 | |||
235 | private byte[] FailureResult() | ||
236 | { | ||
237 | return FailureResult(String.Empty); | ||
238 | } | ||
239 | |||
240 | private byte[] FailureResult(string msg) | ||
241 | { | ||
242 | XmlDocument doc = new XmlDocument(); | ||
243 | |||
244 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
245 | "", ""); | ||
246 | |||
247 | doc.AppendChild(xmlnode); | ||
248 | |||
249 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
250 | ""); | ||
251 | |||
252 | doc.AppendChild(rootElement); | ||
253 | |||
254 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
255 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
256 | |||
257 | rootElement.AppendChild(result); | ||
258 | |||
259 | XmlElement message = doc.CreateElement("", "Message", ""); | ||
260 | message.AppendChild(doc.CreateTextNode(msg)); | ||
261 | |||
262 | rootElement.AppendChild(message); | ||
263 | |||
264 | return Util.DocToBytes(doc); | ||
265 | } | ||
266 | |||
267 | void FromKeyValuePairs(Dictionary<string, object> kvp, out string principalID, out string friend, out int flags) | ||
268 | { | ||
269 | principalID = string.Empty; | ||
270 | if (kvp.ContainsKey("PrincipalID") && kvp["PrincipalID"] != null) | ||
271 | principalID = kvp["PrincipalID"].ToString(); | ||
272 | friend = string.Empty; | ||
273 | if (kvp.ContainsKey("Friend") && kvp["Friend"] != null) | ||
274 | friend = kvp["Friend"].ToString(); | ||
275 | flags = 0; | ||
276 | if (kvp.ContainsKey("MyFlags") && kvp["MyFlags"] != null) | ||
277 | Int32.TryParse(kvp["MyFlags"].ToString(), out flags); | ||
278 | } | ||
279 | |||
280 | #endregion | ||
281 | } | ||
282 | } | ||
diff --git a/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs new file mode 100644 index 0000000..346af32 --- /dev/null +++ b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs | |||
@@ -0,0 +1,199 @@ | |||
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; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Security; | ||
34 | using System.Text; | ||
35 | using log4net; | ||
36 | using Nini.Config; | ||
37 | using Nwc.XmlRpc; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | |||
42 | namespace OpenSim.Server.Handlers.Grid | ||
43 | { | ||
44 | public class GridInfoHandlers | ||
45 | { | ||
46 | private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | private IConfigSource m_Config; | ||
48 | private Hashtable _info = new Hashtable(); | ||
49 | |||
50 | /// <summary> | ||
51 | /// Instantiate a GridInfoService object. | ||
52 | /// </summary> | ||
53 | /// <param name="configPath">path to config path containing | ||
54 | /// grid information</param> | ||
55 | /// <remarks> | ||
56 | /// GridInfoService uses the [GridInfo] section of the | ||
57 | /// standard OpenSim.ini file --- which is not optimal, but | ||
58 | /// anything else requires a general redesign of the config | ||
59 | /// system. | ||
60 | /// </remarks> | ||
61 | public GridInfoHandlers(IConfigSource configSource) | ||
62 | { | ||
63 | m_Config = configSource; | ||
64 | loadGridInfo(configSource); | ||
65 | } | ||
66 | |||
67 | private void loadGridInfo(IConfigSource configSource) | ||
68 | { | ||
69 | _info["platform"] = "OpenSim"; | ||
70 | try | ||
71 | { | ||
72 | IConfig gridCfg = configSource.Configs["GridInfoService"]; | ||
73 | IConfig netCfg = configSource.Configs["Network"]; | ||
74 | |||
75 | if (null != gridCfg) | ||
76 | { | ||
77 | foreach (string k in gridCfg.GetKeys()) | ||
78 | { | ||
79 | _info[k] = gridCfg.GetString(k); | ||
80 | } | ||
81 | } | ||
82 | else if (null != netCfg) | ||
83 | { | ||
84 | _info["login"] | ||
85 | = String.Format( | ||
86 | "http://127.0.0.1:{0}/", | ||
87 | netCfg.GetString( | ||
88 | "http_listener_port", ConfigSettings.DefaultRegionHttpPort.ToString())); | ||
89 | |||
90 | IssueWarning(); | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | _info["login"] = "http://127.0.0.1:9000/"; | ||
95 | IssueWarning(); | ||
96 | } | ||
97 | } | ||
98 | catch (Exception) | ||
99 | { | ||
100 | _log.Warn("[GRID INFO SERVICE]: Cannot get grid info from config source, using minimal defaults"); | ||
101 | } | ||
102 | |||
103 | _log.DebugFormat("[GRID INFO SERVICE]: Grid info service initialized with {0} keys", _info.Count); | ||
104 | } | ||
105 | |||
106 | private void IssueWarning() | ||
107 | { | ||
108 | _log.Warn("[GRID INFO SERVICE]: found no [GridInfo] section in your configuration files"); | ||
109 | _log.Warn("[GRID INFO SERVICE]: trying to guess sensible defaults, you might want to provide better ones:"); | ||
110 | |||
111 | foreach (string k in _info.Keys) | ||
112 | { | ||
113 | _log.WarnFormat("[GRID INFO SERVICE]: {0}: {1}", k, _info[k]); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request, IPEndPoint remoteClient) | ||
118 | { | ||
119 | XmlRpcResponse response = new XmlRpcResponse(); | ||
120 | Hashtable responseData = new Hashtable(); | ||
121 | |||
122 | _log.Debug("[GRID INFO SERVICE]: Request for grid info"); | ||
123 | |||
124 | foreach (string k in _info.Keys) | ||
125 | { | ||
126 | responseData[k] = _info[k]; | ||
127 | } | ||
128 | response.Value = responseData; | ||
129 | |||
130 | return response; | ||
131 | } | ||
132 | |||
133 | public string RestGetGridInfoMethod(string request, string path, string param, | ||
134 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
135 | { | ||
136 | StringBuilder sb = new StringBuilder(); | ||
137 | |||
138 | sb.Append("<gridinfo>\n"); | ||
139 | foreach (string k in _info.Keys) | ||
140 | { | ||
141 | sb.AppendFormat("<{0}>{1}</{0}>\n", k, SecurityElement.Escape(_info[k].ToString())); | ||
142 | } | ||
143 | sb.Append("</gridinfo>\n"); | ||
144 | |||
145 | return sb.ToString(); | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// Get GridInfo in json format: Used bu the OSSL osGetGrid* | ||
150 | /// Adding the SRV_HomeIRI to the kvp returned for use in scripts | ||
151 | /// </summary> | ||
152 | /// <returns> | ||
153 | /// json string | ||
154 | /// </returns> | ||
155 | /// <param name='request'> | ||
156 | /// Request. | ||
157 | /// </param> | ||
158 | /// <param name='path'> | ||
159 | /// /json_grid_info | ||
160 | /// </param> | ||
161 | /// <param name='param'> | ||
162 | /// Parameter. | ||
163 | /// </param> | ||
164 | /// <param name='httpRequest'> | ||
165 | /// Http request. | ||
166 | /// </param> | ||
167 | /// <param name='httpResponse'> | ||
168 | /// Http response. | ||
169 | /// </param> | ||
170 | public string JsonGetGridInfoMethod(string request, string path, string param, | ||
171 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
172 | { | ||
173 | OSDMap map = new OSDMap(); | ||
174 | |||
175 | foreach (string k in _info.Keys) | ||
176 | { | ||
177 | map[k] = OSD.FromString(_info[k].ToString()); | ||
178 | } | ||
179 | |||
180 | string HomeURI = Util.GetConfigVarFromSections<string>(m_Config, "HomeURI", | ||
181 | new string[] { "Startup", "Hypergrid" }, String.Empty); | ||
182 | |||
183 | if (!String.IsNullOrEmpty(HomeURI)) | ||
184 | map["home"] = OSD.FromString(HomeURI); | ||
185 | else // Legacy. Remove soon! | ||
186 | { | ||
187 | IConfig cfg = m_Config.Configs["LoginService"]; | ||
188 | |||
189 | if (null != cfg) | ||
190 | HomeURI = cfg.GetString("SRV_HomeURI", HomeURI); | ||
191 | |||
192 | if (!String.IsNullOrEmpty(HomeURI)) | ||
193 | map["home"] = OSD.FromString(HomeURI); | ||
194 | } | ||
195 | |||
196 | return OSDParser.SerializeJsonString(map).ToString(); | ||
197 | } | ||
198 | } | ||
199 | } | ||
diff --git a/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs new file mode 100644 index 0000000..f9b5915 --- /dev/null +++ b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs | |||
@@ -0,0 +1,57 @@ | |||
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.Reflection; | ||
31 | using log4net; | ||
32 | using OpenMetaverse; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Servers.HttpServer; | ||
36 | using OpenSim.Server.Handlers.Base; | ||
37 | |||
38 | namespace OpenSim.Server.Handlers.Grid | ||
39 | { | ||
40 | public class GridInfoServerInConnector : ServiceConnector | ||
41 | { | ||
42 | // private string m_ConfigName = "GridInfoService"; | ||
43 | |||
44 | public GridInfoServerInConnector(IConfigSource config, IHttpServer server, string configName) : | ||
45 | base(config, server, configName) | ||
46 | { | ||
47 | GridInfoHandlers handlers = new GridInfoHandlers(config); | ||
48 | |||
49 | server.AddStreamHandler(new RestStreamHandler("GET", "/get_grid_info", | ||
50 | handlers.RestGetGridInfoMethod)); | ||
51 | server.AddStreamHandler(new RestStreamHandler("GET", "/json_grid_info", | ||
52 | handlers.JsonGetGridInfoMethod)); | ||
53 | server.AddXmlRPCHandler("get_grid_info", handlers.XmlRpcGridInfoMethod); | ||
54 | } | ||
55 | |||
56 | } | ||
57 | } | ||
diff --git a/OpenSim/Server/Handlers/Grid/GridServerConnector.cs b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs new file mode 100644 index 0000000..6eb6a79 --- /dev/null +++ b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs | |||
@@ -0,0 +1,64 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.ServiceAuth; | ||
33 | using OpenSim.Framework.Servers.HttpServer; | ||
34 | using OpenSim.Server.Handlers.Base; | ||
35 | |||
36 | namespace OpenSim.Server.Handlers.Grid | ||
37 | { | ||
38 | public class GridServiceConnector : ServiceConnector | ||
39 | { | ||
40 | private IGridService m_GridService; | ||
41 | private string m_ConfigName = "GridService"; | ||
42 | |||
43 | public GridServiceConnector(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 gridService = serverConfig.GetString("LocalServiceModule", | ||
51 | String.Empty); | ||
52 | |||
53 | if (gridService == String.Empty) | ||
54 | throw new Exception("No LocalServiceModule in config file"); | ||
55 | |||
56 | Object[] args = new Object[] { config }; | ||
57 | m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); | ||
58 | |||
59 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
60 | |||
61 | server.AddStreamHandler(new GridServerPostHandler(m_GridService, auth)); | ||
62 | } | ||
63 | } | ||
64 | } | ||
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs new file mode 100644 index 0000000..849fa94 --- /dev/null +++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs | |||
@@ -0,0 +1,661 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using System.Collections.Generic; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
42 | using OpenSim.Framework; | ||
43 | using OpenSim.Framework.ServiceAuth; | ||
44 | using OpenSim.Framework.Servers.HttpServer; | ||
45 | using OpenMetaverse; | ||
46 | |||
47 | namespace OpenSim.Server.Handlers.Grid | ||
48 | { | ||
49 | public class GridServerPostHandler : BaseStreamHandler | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | #pragma warning disable 414 | ||
54 | private static string LogHeader = "[GRID HANDLER]"; | ||
55 | #pragma warning restore 414 | ||
56 | |||
57 | private IGridService m_GridService; | ||
58 | |||
59 | public GridServerPostHandler(IGridService service, IServiceAuth auth) : | ||
60 | base("POST", "/grid", auth) | ||
61 | { | ||
62 | m_GridService = service; | ||
63 | } | ||
64 | |||
65 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
66 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
67 | { | ||
68 | StreamReader sr = new StreamReader(requestData); | ||
69 | string body = sr.ReadToEnd(); | ||
70 | sr.Close(); | ||
71 | body = body.Trim(); | ||
72 | |||
73 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
74 | |||
75 | try | ||
76 | { | ||
77 | Dictionary<string, object> request = | ||
78 | ServerUtils.ParseQueryString(body); | ||
79 | |||
80 | if (!request.ContainsKey("METHOD")) | ||
81 | return FailureResult(); | ||
82 | |||
83 | string method = request["METHOD"].ToString(); | ||
84 | |||
85 | switch (method) | ||
86 | { | ||
87 | case "register": | ||
88 | return Register(request); | ||
89 | |||
90 | case "deregister": | ||
91 | return Deregister(request); | ||
92 | |||
93 | case "get_neighbours": | ||
94 | return GetNeighbours(request); | ||
95 | |||
96 | case "get_region_by_uuid": | ||
97 | return GetRegionByUUID(request); | ||
98 | |||
99 | case "get_region_by_position": | ||
100 | return GetRegionByPosition(request); | ||
101 | |||
102 | case "get_region_by_name": | ||
103 | return GetRegionByName(request); | ||
104 | |||
105 | case "get_regions_by_name": | ||
106 | return GetRegionsByName(request); | ||
107 | |||
108 | case "get_region_range": | ||
109 | return GetRegionRange(request); | ||
110 | |||
111 | case "get_default_regions": | ||
112 | return GetDefaultRegions(request); | ||
113 | |||
114 | case "get_default_hypergrid_regions": | ||
115 | return GetDefaultHypergridRegions(request); | ||
116 | |||
117 | case "get_fallback_regions": | ||
118 | return GetFallbackRegions(request); | ||
119 | |||
120 | case "get_hyperlinks": | ||
121 | return GetHyperlinks(request); | ||
122 | |||
123 | case "get_region_flags": | ||
124 | return GetRegionFlags(request); | ||
125 | |||
126 | case "get_grid_extra_features": | ||
127 | return GetGridExtraFeatures(request); | ||
128 | } | ||
129 | |||
130 | m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method); | ||
131 | } | ||
132 | catch (Exception e) | ||
133 | { | ||
134 | m_log.ErrorFormat("[GRID HANDLER]: Exception {0} {1}", e.Message, e.StackTrace); | ||
135 | } | ||
136 | |||
137 | return FailureResult(); | ||
138 | } | ||
139 | |||
140 | #region Method-specific handlers | ||
141 | |||
142 | byte[] Register(Dictionary<string, object> request) | ||
143 | { | ||
144 | UUID scopeID = UUID.Zero; | ||
145 | if (request.ContainsKey("SCOPEID")) | ||
146 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
147 | else | ||
148 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region"); | ||
149 | |||
150 | int versionNumberMin = 0, versionNumberMax = 0; | ||
151 | if (request.ContainsKey("VERSIONMIN")) | ||
152 | Int32.TryParse(request["VERSIONMIN"].ToString(), out versionNumberMin); | ||
153 | else | ||
154 | m_log.WarnFormat("[GRID HANDLER]: no minimum protocol version in request to register region"); | ||
155 | |||
156 | if (request.ContainsKey("VERSIONMAX")) | ||
157 | Int32.TryParse(request["VERSIONMAX"].ToString(), out versionNumberMax); | ||
158 | else | ||
159 | m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region"); | ||
160 | |||
161 | // Check the protocol version | ||
162 | if ((versionNumberMin > ProtocolVersions.ServerProtocolVersionMax && versionNumberMax < ProtocolVersions.ServerProtocolVersionMax)) | ||
163 | { | ||
164 | // Can't do, there is no overlap in the acceptable ranges | ||
165 | return FailureResult(); | ||
166 | } | ||
167 | |||
168 | Dictionary<string, object> rinfoData = new Dictionary<string, object>(); | ||
169 | GridRegion rinfo = null; | ||
170 | try | ||
171 | { | ||
172 | foreach (KeyValuePair<string, object> kvp in request) | ||
173 | rinfoData[kvp.Key] = kvp.Value.ToString(); | ||
174 | rinfo = new GridRegion(rinfoData); | ||
175 | } | ||
176 | catch (Exception e) | ||
177 | { | ||
178 | m_log.DebugFormat("[GRID HANDLER]: exception unpacking region data: {0}", e); | ||
179 | } | ||
180 | |||
181 | string result = "Error communicating with grid service"; | ||
182 | if (rinfo != null) | ||
183 | result = m_GridService.RegisterRegion(scopeID, rinfo); | ||
184 | |||
185 | if (result == String.Empty) | ||
186 | return SuccessResult(); | ||
187 | else | ||
188 | return FailureResult(result); | ||
189 | } | ||
190 | |||
191 | byte[] Deregister(Dictionary<string, object> request) | ||
192 | { | ||
193 | UUID regionID = UUID.Zero; | ||
194 | if (request.ContainsKey("REGIONID")) | ||
195 | UUID.TryParse(request["REGIONID"].ToString(), out regionID); | ||
196 | else | ||
197 | m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region"); | ||
198 | |||
199 | bool result = m_GridService.DeregisterRegion(regionID); | ||
200 | |||
201 | if (result) | ||
202 | return SuccessResult(); | ||
203 | else | ||
204 | return FailureResult(); | ||
205 | |||
206 | } | ||
207 | |||
208 | byte[] GetNeighbours(Dictionary<string, object> request) | ||
209 | { | ||
210 | UUID scopeID = UUID.Zero; | ||
211 | if (request.ContainsKey("SCOPEID")) | ||
212 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
213 | else | ||
214 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours"); | ||
215 | |||
216 | UUID regionID = UUID.Zero; | ||
217 | if (request.ContainsKey("REGIONID")) | ||
218 | UUID.TryParse(request["REGIONID"].ToString(), out regionID); | ||
219 | else | ||
220 | m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours"); | ||
221 | |||
222 | List<GridRegion> rinfos = m_GridService.GetNeighbours(scopeID, regionID); | ||
223 | //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); | ||
224 | |||
225 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
226 | if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) | ||
227 | result["result"] = "null"; | ||
228 | else | ||
229 | { | ||
230 | int i = 0; | ||
231 | foreach (GridRegion rinfo in rinfos) | ||
232 | { | ||
233 | Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs(); | ||
234 | result["region" + i] = rinfoDict; | ||
235 | i++; | ||
236 | } | ||
237 | } | ||
238 | |||
239 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
240 | |||
241 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
242 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
243 | } | ||
244 | |||
245 | byte[] GetRegionByUUID(Dictionary<string, object> request) | ||
246 | { | ||
247 | UUID scopeID = UUID.Zero; | ||
248 | if (request.ContainsKey("SCOPEID")) | ||
249 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
250 | else | ||
251 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours"); | ||
252 | |||
253 | UUID regionID = UUID.Zero; | ||
254 | if (request.ContainsKey("REGIONID")) | ||
255 | UUID.TryParse(request["REGIONID"].ToString(), out regionID); | ||
256 | else | ||
257 | m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours"); | ||
258 | |||
259 | GridRegion rinfo = m_GridService.GetRegionByUUID(scopeID, regionID); | ||
260 | //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); | ||
261 | |||
262 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
263 | if (rinfo == null) | ||
264 | result["result"] = "null"; | ||
265 | else | ||
266 | result["result"] = rinfo.ToKeyValuePairs(); | ||
267 | |||
268 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
269 | |||
270 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
271 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
272 | } | ||
273 | |||
274 | byte[] GetRegionByPosition(Dictionary<string, object> request) | ||
275 | { | ||
276 | UUID scopeID = UUID.Zero; | ||
277 | if (request.ContainsKey("SCOPEID")) | ||
278 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
279 | else | ||
280 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position"); | ||
281 | |||
282 | int x = 0, y = 0; | ||
283 | if (request.ContainsKey("X")) | ||
284 | Int32.TryParse(request["X"].ToString(), out x); | ||
285 | else | ||
286 | m_log.WarnFormat("[GRID HANDLER]: no X in request to get region by position"); | ||
287 | if (request.ContainsKey("Y")) | ||
288 | Int32.TryParse(request["Y"].ToString(), out y); | ||
289 | else | ||
290 | m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position"); | ||
291 | |||
292 | // m_log.DebugFormat("{0} GetRegionByPosition: loc=<{1},{2}>", LogHeader, x, y); | ||
293 | GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y); | ||
294 | |||
295 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
296 | if (rinfo == null) | ||
297 | result["result"] = "null"; | ||
298 | else | ||
299 | result["result"] = rinfo.ToKeyValuePairs(); | ||
300 | |||
301 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
302 | |||
303 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
304 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
305 | } | ||
306 | |||
307 | byte[] GetRegionByName(Dictionary<string, object> request) | ||
308 | { | ||
309 | UUID scopeID = UUID.Zero; | ||
310 | if (request.ContainsKey("SCOPEID")) | ||
311 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
312 | else | ||
313 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by name"); | ||
314 | |||
315 | string regionName = string.Empty; | ||
316 | if (request.ContainsKey("NAME")) | ||
317 | regionName = request["NAME"].ToString(); | ||
318 | else | ||
319 | m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name"); | ||
320 | |||
321 | GridRegion rinfo = m_GridService.GetRegionByName(scopeID, regionName); | ||
322 | //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); | ||
323 | |||
324 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
325 | if (rinfo == null) | ||
326 | result["result"] = "null"; | ||
327 | else | ||
328 | result["result"] = rinfo.ToKeyValuePairs(); | ||
329 | |||
330 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
331 | |||
332 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
333 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
334 | } | ||
335 | |||
336 | byte[] GetRegionsByName(Dictionary<string, object> request) | ||
337 | { | ||
338 | UUID scopeID = UUID.Zero; | ||
339 | if (request.ContainsKey("SCOPEID")) | ||
340 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
341 | else | ||
342 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get regions by name"); | ||
343 | |||
344 | string regionName = string.Empty; | ||
345 | if (request.ContainsKey("NAME")) | ||
346 | regionName = request["NAME"].ToString(); | ||
347 | else | ||
348 | m_log.WarnFormat("[GRID HANDLER]: no NAME in request to get regions by name"); | ||
349 | |||
350 | int max = 0; | ||
351 | if (request.ContainsKey("MAX")) | ||
352 | Int32.TryParse(request["MAX"].ToString(), out max); | ||
353 | else | ||
354 | m_log.WarnFormat("[GRID HANDLER]: no MAX in request to get regions by name"); | ||
355 | |||
356 | List<GridRegion> rinfos = m_GridService.GetRegionsByName(scopeID, regionName, max); | ||
357 | //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); | ||
358 | |||
359 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
360 | if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) | ||
361 | result["result"] = "null"; | ||
362 | else | ||
363 | { | ||
364 | int i = 0; | ||
365 | foreach (GridRegion rinfo in rinfos) | ||
366 | { | ||
367 | Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs(); | ||
368 | result["region" + i] = rinfoDict; | ||
369 | i++; | ||
370 | } | ||
371 | } | ||
372 | |||
373 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
374 | |||
375 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
376 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
377 | } | ||
378 | |||
379 | byte[] GetRegionRange(Dictionary<string, object> request) | ||
380 | { | ||
381 | //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange"); | ||
382 | UUID scopeID = UUID.Zero; | ||
383 | if (request.ContainsKey("SCOPEID")) | ||
384 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
385 | else | ||
386 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range"); | ||
387 | |||
388 | int xmin = 0, xmax = 0, ymin = 0, ymax = 0; | ||
389 | if (request.ContainsKey("XMIN")) | ||
390 | Int32.TryParse(request["XMIN"].ToString(), out xmin); | ||
391 | else | ||
392 | m_log.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range"); | ||
393 | if (request.ContainsKey("XMAX")) | ||
394 | Int32.TryParse(request["XMAX"].ToString(), out xmax); | ||
395 | else | ||
396 | m_log.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range"); | ||
397 | if (request.ContainsKey("YMIN")) | ||
398 | Int32.TryParse(request["YMIN"].ToString(), out ymin); | ||
399 | else | ||
400 | m_log.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range"); | ||
401 | if (request.ContainsKey("YMAX")) | ||
402 | Int32.TryParse(request["YMAX"].ToString(), out ymax); | ||
403 | else | ||
404 | m_log.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range"); | ||
405 | |||
406 | |||
407 | List<GridRegion> rinfos = m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax); | ||
408 | |||
409 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
410 | if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) | ||
411 | result["result"] = "null"; | ||
412 | else | ||
413 | { | ||
414 | int i = 0; | ||
415 | foreach (GridRegion rinfo in rinfos) | ||
416 | { | ||
417 | Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs(); | ||
418 | result["region" + i] = rinfoDict; | ||
419 | i++; | ||
420 | } | ||
421 | } | ||
422 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
423 | |||
424 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
425 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
426 | } | ||
427 | |||
428 | byte[] GetDefaultRegions(Dictionary<string, object> request) | ||
429 | { | ||
430 | //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions"); | ||
431 | UUID scopeID = UUID.Zero; | ||
432 | if (request.ContainsKey("SCOPEID")) | ||
433 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
434 | else | ||
435 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range"); | ||
436 | |||
437 | List<GridRegion> rinfos = m_GridService.GetDefaultRegions(scopeID); | ||
438 | |||
439 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
440 | if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) | ||
441 | result["result"] = "null"; | ||
442 | else | ||
443 | { | ||
444 | int i = 0; | ||
445 | foreach (GridRegion rinfo in rinfos) | ||
446 | { | ||
447 | Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs(); | ||
448 | result["region" + i] = rinfoDict; | ||
449 | i++; | ||
450 | } | ||
451 | } | ||
452 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
453 | |||
454 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
455 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
456 | } | ||
457 | |||
458 | byte[] GetDefaultHypergridRegions(Dictionary<string, object> request) | ||
459 | { | ||
460 | //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions"); | ||
461 | UUID scopeID = UUID.Zero; | ||
462 | if (request.ContainsKey("SCOPEID")) | ||
463 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
464 | else | ||
465 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range"); | ||
466 | |||
467 | List<GridRegion> rinfos = m_GridService.GetDefaultHypergridRegions(scopeID); | ||
468 | |||
469 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
470 | if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) | ||
471 | result["result"] = "null"; | ||
472 | else | ||
473 | { | ||
474 | int i = 0; | ||
475 | foreach (GridRegion rinfo in rinfos) | ||
476 | { | ||
477 | Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs(); | ||
478 | result["region" + i] = rinfoDict; | ||
479 | i++; | ||
480 | } | ||
481 | } | ||
482 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
483 | |||
484 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
485 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
486 | } | ||
487 | |||
488 | byte[] GetFallbackRegions(Dictionary<string, object> request) | ||
489 | { | ||
490 | //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange"); | ||
491 | UUID scopeID = UUID.Zero; | ||
492 | if (request.ContainsKey("SCOPEID")) | ||
493 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
494 | else | ||
495 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get fallback regions"); | ||
496 | |||
497 | int x = 0, y = 0; | ||
498 | if (request.ContainsKey("X")) | ||
499 | Int32.TryParse(request["X"].ToString(), out x); | ||
500 | else | ||
501 | m_log.WarnFormat("[GRID HANDLER]: no X in request to get fallback regions"); | ||
502 | if (request.ContainsKey("Y")) | ||
503 | Int32.TryParse(request["Y"].ToString(), out y); | ||
504 | else | ||
505 | m_log.WarnFormat("[GRID HANDLER]: no Y in request to get fallback regions"); | ||
506 | |||
507 | |||
508 | List<GridRegion> rinfos = m_GridService.GetFallbackRegions(scopeID, x, y); | ||
509 | |||
510 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
511 | if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) | ||
512 | result["result"] = "null"; | ||
513 | else | ||
514 | { | ||
515 | int i = 0; | ||
516 | foreach (GridRegion rinfo in rinfos) | ||
517 | { | ||
518 | Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs(); | ||
519 | result["region" + i] = rinfoDict; | ||
520 | i++; | ||
521 | } | ||
522 | } | ||
523 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
524 | |||
525 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
526 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
527 | } | ||
528 | |||
529 | byte[] GetHyperlinks(Dictionary<string, object> request) | ||
530 | { | ||
531 | //m_log.DebugFormat("[GRID HANDLER]: GetHyperlinks"); | ||
532 | UUID scopeID = UUID.Zero; | ||
533 | if (request.ContainsKey("SCOPEID")) | ||
534 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
535 | else | ||
536 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get linked regions"); | ||
537 | |||
538 | List<GridRegion> rinfos = m_GridService.GetHyperlinks(scopeID); | ||
539 | |||
540 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
541 | if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) | ||
542 | result["result"] = "null"; | ||
543 | else | ||
544 | { | ||
545 | int i = 0; | ||
546 | foreach (GridRegion rinfo in rinfos) | ||
547 | { | ||
548 | Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs(); | ||
549 | result["region" + i] = rinfoDict; | ||
550 | i++; | ||
551 | } | ||
552 | } | ||
553 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
554 | |||
555 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
556 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
557 | } | ||
558 | |||
559 | byte[] GetRegionFlags(Dictionary<string, object> request) | ||
560 | { | ||
561 | UUID scopeID = UUID.Zero; | ||
562 | if (request.ContainsKey("SCOPEID")) | ||
563 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
564 | else | ||
565 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours"); | ||
566 | |||
567 | UUID regionID = UUID.Zero; | ||
568 | if (request.ContainsKey("REGIONID")) | ||
569 | UUID.TryParse(request["REGIONID"].ToString(), out regionID); | ||
570 | else | ||
571 | m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours"); | ||
572 | |||
573 | int flags = m_GridService.GetRegionFlags(scopeID, regionID); | ||
574 | // m_log.DebugFormat("[GRID HANDLER]: flags for region {0}: {1}", regionID, flags); | ||
575 | |||
576 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
577 | result["result"] = flags.ToString(); | ||
578 | |||
579 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
580 | |||
581 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
582 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
583 | } | ||
584 | |||
585 | byte[] GetGridExtraFeatures(Dictionary<string, object> request) | ||
586 | { | ||
587 | |||
588 | Dictionary<string, object> result = new Dictionary<string, object> (); | ||
589 | Dictionary<string, object> extraFeatures = m_GridService.GetExtraFeatures (); | ||
590 | |||
591 | foreach (string key in extraFeatures.Keys) | ||
592 | { | ||
593 | result [key] = extraFeatures [key]; | ||
594 | } | ||
595 | |||
596 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
597 | |||
598 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
599 | } | ||
600 | |||
601 | #endregion | ||
602 | |||
603 | #region Misc | ||
604 | |||
605 | private byte[] SuccessResult() | ||
606 | { | ||
607 | XmlDocument doc = new XmlDocument(); | ||
608 | |||
609 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
610 | "", ""); | ||
611 | |||
612 | doc.AppendChild(xmlnode); | ||
613 | |||
614 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
615 | ""); | ||
616 | |||
617 | doc.AppendChild(rootElement); | ||
618 | |||
619 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
620 | result.AppendChild(doc.CreateTextNode("Success")); | ||
621 | |||
622 | rootElement.AppendChild(result); | ||
623 | |||
624 | return Util.DocToBytes(doc); | ||
625 | } | ||
626 | |||
627 | private byte[] FailureResult() | ||
628 | { | ||
629 | return FailureResult(String.Empty); | ||
630 | } | ||
631 | |||
632 | private byte[] FailureResult(string msg) | ||
633 | { | ||
634 | XmlDocument doc = new XmlDocument(); | ||
635 | |||
636 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
637 | "", ""); | ||
638 | |||
639 | doc.AppendChild(xmlnode); | ||
640 | |||
641 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
642 | ""); | ||
643 | |||
644 | doc.AppendChild(rootElement); | ||
645 | |||
646 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
647 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
648 | |||
649 | rootElement.AppendChild(result); | ||
650 | |||
651 | XmlElement message = doc.CreateElement("", "Message", ""); | ||
652 | message.AppendChild(doc.CreateTextNode(msg)); | ||
653 | |||
654 | rootElement.AppendChild(message); | ||
655 | |||
656 | return Util.DocToBytes(doc); | ||
657 | } | ||
658 | |||
659 | #endregion | ||
660 | } | ||
661 | } | ||
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs new file mode 100644 index 0000000..1e29378 --- /dev/null +++ b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs | |||
@@ -0,0 +1,64 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.ServiceAuth; | ||
33 | using OpenSim.Framework.Servers.HttpServer; | ||
34 | using OpenSim.Server.Handlers.Base; | ||
35 | |||
36 | namespace OpenSim.Server.Handlers.GridUser | ||
37 | { | ||
38 | public class GridUserServiceConnector : ServiceConnector | ||
39 | { | ||
40 | private IGridUserService m_GridUserService; | ||
41 | private string m_ConfigName = "GridUserService"; | ||
42 | |||
43 | public GridUserServiceConnector(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", | ||
51 | String.Empty); | ||
52 | |||
53 | if (service == String.Empty) | ||
54 | throw new Exception("No LocalServiceModule in config file"); | ||
55 | |||
56 | Object[] args = new Object[] { config }; | ||
57 | m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(service, args); | ||
58 | |||
59 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ; | ||
60 | |||
61 | server.AddStreamHandler(new GridUserServerPostHandler(m_GridUserService, auth)); | ||
62 | } | ||
63 | } | ||
64 | } | ||
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs new file mode 100644 index 0000000..9237c63 --- /dev/null +++ b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs | |||
@@ -0,0 +1,308 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using System.Collections.Generic; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Framework; | ||
42 | using OpenSim.Framework.ServiceAuth; | ||
43 | using OpenSim.Framework.Servers.HttpServer; | ||
44 | using OpenMetaverse; | ||
45 | |||
46 | namespace OpenSim.Server.Handlers.GridUser | ||
47 | { | ||
48 | public class GridUserServerPostHandler : BaseStreamHandler | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private IGridUserService m_GridUserService; | ||
53 | |||
54 | public GridUserServerPostHandler(IGridUserService service, IServiceAuth auth) : | ||
55 | base("POST", "/griduser", auth) | ||
56 | { | ||
57 | m_GridUserService = service; | ||
58 | } | ||
59 | |||
60 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
61 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
62 | { | ||
63 | StreamReader sr = new StreamReader(requestData); | ||
64 | string body = sr.ReadToEnd(); | ||
65 | sr.Close(); | ||
66 | body = body.Trim(); | ||
67 | |||
68 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
69 | string method = string.Empty; | ||
70 | try | ||
71 | { | ||
72 | Dictionary<string, object> request = | ||
73 | ServerUtils.ParseQueryString(body); | ||
74 | |||
75 | if (!request.ContainsKey("METHOD")) | ||
76 | return FailureResult(); | ||
77 | |||
78 | method = request["METHOD"].ToString(); | ||
79 | |||
80 | switch (method) | ||
81 | { | ||
82 | case "loggedin": | ||
83 | return LoggedIn(request); | ||
84 | case "loggedout": | ||
85 | return LoggedOut(request); | ||
86 | case "sethome": | ||
87 | return SetHome(request); | ||
88 | case "setposition": | ||
89 | return SetPosition(request); | ||
90 | case "getgriduserinfo": | ||
91 | return GetGridUserInfo(request); | ||
92 | case "getgriduserinfos": | ||
93 | return GetGridUserInfos(request); | ||
94 | } | ||
95 | m_log.DebugFormat("[GRID USER HANDLER]: unknown method request: {0}", method); | ||
96 | } | ||
97 | catch (Exception e) | ||
98 | { | ||
99 | m_log.DebugFormat("[GRID USER HANDLER]: Exception in method {0}: {1}", method, e); | ||
100 | } | ||
101 | |||
102 | return FailureResult(); | ||
103 | |||
104 | } | ||
105 | |||
106 | byte[] LoggedIn(Dictionary<string, object> request) | ||
107 | { | ||
108 | string user = String.Empty; | ||
109 | |||
110 | if (!request.ContainsKey("UserID")) | ||
111 | return FailureResult(); | ||
112 | |||
113 | user = request["UserID"].ToString(); | ||
114 | |||
115 | GridUserInfo guinfo = m_GridUserService.LoggedIn(user); | ||
116 | |||
117 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
118 | result["result"] = guinfo.ToKeyValuePairs(); | ||
119 | |||
120 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
121 | |||
122 | //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString); | ||
123 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
124 | } | ||
125 | |||
126 | byte[] LoggedOut(Dictionary<string, object> request) | ||
127 | { | ||
128 | string userID = string.Empty; | ||
129 | UUID regionID = UUID.Zero; | ||
130 | Vector3 position = Vector3.Zero; | ||
131 | Vector3 lookat = Vector3.Zero; | ||
132 | |||
133 | if (!UnpackArgs(request, out userID, out regionID, out position, out lookat)) | ||
134 | return FailureResult(); | ||
135 | |||
136 | if (m_GridUserService.LoggedOut(userID, UUID.Zero, regionID, position, lookat)) | ||
137 | return SuccessResult(); | ||
138 | |||
139 | return FailureResult(); | ||
140 | } | ||
141 | |||
142 | byte[] SetHome(Dictionary<string, object> request) | ||
143 | { | ||
144 | string user = string.Empty; | ||
145 | UUID region = UUID.Zero; | ||
146 | Vector3 position = new Vector3(128, 128, 70); | ||
147 | Vector3 look = Vector3.Zero; | ||
148 | |||
149 | if (!UnpackArgs(request, out user, out region, out position, out look)) | ||
150 | return FailureResult(); | ||
151 | |||
152 | if (m_GridUserService.SetHome(user, region, position, look)) | ||
153 | return SuccessResult(); | ||
154 | |||
155 | return FailureResult(); | ||
156 | } | ||
157 | |||
158 | byte[] SetPosition(Dictionary<string, object> request) | ||
159 | { | ||
160 | string user = string.Empty; | ||
161 | UUID region = UUID.Zero; | ||
162 | Vector3 position = new Vector3(128, 128, 70); | ||
163 | Vector3 look = Vector3.Zero; | ||
164 | |||
165 | if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID")) | ||
166 | return FailureResult(); | ||
167 | |||
168 | if (!UnpackArgs(request, out user, out region, out position, out look)) | ||
169 | return FailureResult(); | ||
170 | |||
171 | if (m_GridUserService.SetLastPosition(user, UUID.Zero, region, position, look)) | ||
172 | return SuccessResult(); | ||
173 | |||
174 | return FailureResult(); | ||
175 | } | ||
176 | |||
177 | byte[] GetGridUserInfo(Dictionary<string, object> request) | ||
178 | { | ||
179 | string user = String.Empty; | ||
180 | |||
181 | if (!request.ContainsKey("UserID")) | ||
182 | return FailureResult(); | ||
183 | |||
184 | user = request["UserID"].ToString(); | ||
185 | |||
186 | GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(user); | ||
187 | |||
188 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
189 | if (guinfo != null) | ||
190 | result["result"] = guinfo.ToKeyValuePairs(); | ||
191 | else | ||
192 | result["result"] = "null"; | ||
193 | |||
194 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
195 | //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString); | ||
196 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
197 | } | ||
198 | |||
199 | byte[] GetGridUserInfos(Dictionary<string, object> request) | ||
200 | { | ||
201 | |||
202 | string[] userIDs; | ||
203 | |||
204 | if (!request.ContainsKey("AgentIDs")) | ||
205 | { | ||
206 | m_log.DebugFormat("[GRID USER HANDLER]: GetGridUserInfos called without required uuids argument"); | ||
207 | return FailureResult(); | ||
208 | } | ||
209 | |||
210 | if (!(request["AgentIDs"] is List<string>)) | ||
211 | { | ||
212 | m_log.DebugFormat("[GRID USER HANDLER]: GetGridUserInfos input argument was of unexpected type {0}", request["uuids"].GetType().ToString()); | ||
213 | return FailureResult(); | ||
214 | } | ||
215 | |||
216 | userIDs = ((List<string>)request["AgentIDs"]).ToArray(); | ||
217 | |||
218 | GridUserInfo[] pinfos = m_GridUserService.GetGridUserInfo(userIDs); | ||
219 | |||
220 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
221 | if ((pinfos == null) || ((pinfos != null) && (pinfos.Length == 0))) | ||
222 | result["result"] = "null"; | ||
223 | else | ||
224 | { | ||
225 | int i = 0; | ||
226 | foreach (GridUserInfo pinfo in pinfos) | ||
227 | { | ||
228 | Dictionary<string, object> rinfoDict = pinfo.ToKeyValuePairs(); | ||
229 | result["griduser" + i] = rinfoDict; | ||
230 | i++; | ||
231 | } | ||
232 | } | ||
233 | |||
234 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
235 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
236 | } | ||
237 | |||
238 | private bool UnpackArgs(Dictionary<string, object> request, out string user, out UUID region, out Vector3 position, out Vector3 lookAt) | ||
239 | { | ||
240 | user = string.Empty; | ||
241 | region = UUID.Zero; | ||
242 | position = new Vector3(128, 128, 70); | ||
243 | lookAt = Vector3.Zero; | ||
244 | |||
245 | if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID")) | ||
246 | return false; | ||
247 | |||
248 | user = request["UserID"].ToString(); | ||
249 | |||
250 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) | ||
251 | return false; | ||
252 | |||
253 | if (request.ContainsKey("Position")) | ||
254 | Vector3.TryParse(request["Position"].ToString(), out position); | ||
255 | |||
256 | if (request.ContainsKey("LookAt")) | ||
257 | Vector3.TryParse(request["LookAt"].ToString(), out lookAt); | ||
258 | |||
259 | return true; | ||
260 | } | ||
261 | |||
262 | |||
263 | private byte[] SuccessResult() | ||
264 | { | ||
265 | XmlDocument doc = new XmlDocument(); | ||
266 | |||
267 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
268 | "", ""); | ||
269 | |||
270 | doc.AppendChild(xmlnode); | ||
271 | |||
272 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
273 | ""); | ||
274 | |||
275 | doc.AppendChild(rootElement); | ||
276 | |||
277 | XmlElement result = doc.CreateElement("", "result", ""); | ||
278 | result.AppendChild(doc.CreateTextNode("Success")); | ||
279 | |||
280 | rootElement.AppendChild(result); | ||
281 | |||
282 | return Util.DocToBytes(doc); | ||
283 | } | ||
284 | |||
285 | private byte[] FailureResult() | ||
286 | { | ||
287 | XmlDocument doc = new XmlDocument(); | ||
288 | |||
289 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
290 | "", ""); | ||
291 | |||
292 | doc.AppendChild(xmlnode); | ||
293 | |||
294 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
295 | ""); | ||
296 | |||
297 | doc.AppendChild(rootElement); | ||
298 | |||
299 | XmlElement result = doc.CreateElement("", "result", ""); | ||
300 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
301 | |||
302 | rootElement.AppendChild(result); | ||
303 | |||
304 | return Util.DocToBytes(doc); | ||
305 | } | ||
306 | |||
307 | } | ||
308 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs new file mode 100644 index 0000000..95a0510 --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs | |||
@@ -0,0 +1,70 @@ | |||
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; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Net; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Server.Handlers.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Servers.HttpServer; | ||
41 | using OpenSim.Server.Handlers.Simulation; | ||
42 | using Utils = OpenSim.Server.Handlers.Simulation.Utils; | ||
43 | |||
44 | using OpenMetaverse; | ||
45 | using OpenMetaverse.StructuredData; | ||
46 | using Nini.Config; | ||
47 | using log4net; | ||
48 | |||
49 | |||
50 | namespace OpenSim.Server.Handlers.Hypergrid | ||
51 | { | ||
52 | public class GatekeeperAgentHandler : OpenSim.Server.Handlers.Simulation.AgentPostHandler | ||
53 | { | ||
54 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | |||
56 | private IGatekeeperService m_GatekeeperService; | ||
57 | |||
58 | public GatekeeperAgentHandler(IGatekeeperService gatekeeper, bool proxy) : base("/foreignagent") | ||
59 | { | ||
60 | m_GatekeeperService = gatekeeper; | ||
61 | m_Proxy = proxy; | ||
62 | } | ||
63 | |||
64 | protected override bool CreateAgent(GridRegion source, GridRegion gatekeeper, GridRegion destination, | ||
65 | AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason) | ||
66 | { | ||
67 | return m_GatekeeperService.LoginAgent(source, aCircuit, destination, out reason); | ||
68 | } | ||
69 | } | ||
70 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs new file mode 100644 index 0000000..ffe2f36 --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs | |||
@@ -0,0 +1,89 @@ | |||
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.Reflection; | ||
31 | using Nini.Config; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Server.Base; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OpenSim.Framework.Servers.HttpServer; | ||
36 | using OpenSim.Server.Handlers.Base; | ||
37 | |||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Server.Handlers.Hypergrid | ||
41 | { | ||
42 | public class GatekeeperServiceInConnector : ServiceConnector | ||
43 | { | ||
44 | // private static readonly ILog m_log = | ||
45 | // LogManager.GetLogger( | ||
46 | // MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private IGatekeeperService m_GatekeeperService; | ||
49 | public IGatekeeperService GateKeeper | ||
50 | { | ||
51 | get { return m_GatekeeperService; } | ||
52 | } | ||
53 | |||
54 | bool m_Proxy = false; | ||
55 | |||
56 | public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server, ISimulationService simService) : | ||
57 | base(config, server, String.Empty) | ||
58 | { | ||
59 | IConfig gridConfig = config.Configs["GatekeeperService"]; | ||
60 | if (gridConfig != null) | ||
61 | { | ||
62 | string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); | ||
63 | Object[] args = new Object[] { config, simService }; | ||
64 | m_GatekeeperService = ServerUtils.LoadPlugin<IGatekeeperService>(serviceDll, args); | ||
65 | |||
66 | } | ||
67 | if (m_GatekeeperService == null) | ||
68 | throw new Exception("Gatekeeper server connector cannot proceed because of missing service"); | ||
69 | |||
70 | m_Proxy = gridConfig.GetBoolean("HasProxy", false); | ||
71 | |||
72 | HypergridHandlers hghandlers = new HypergridHandlers(m_GatekeeperService); | ||
73 | server.AddXmlRPCHandler("link_region", hghandlers.LinkRegionRequest, false); | ||
74 | server.AddXmlRPCHandler("get_region", hghandlers.GetRegion, false); | ||
75 | |||
76 | server.AddStreamHandler(new GatekeeperAgentHandler(m_GatekeeperService, m_Proxy)); | ||
77 | } | ||
78 | |||
79 | public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server, string configName) | ||
80 | : this(config, server, (ISimulationService)null) | ||
81 | { | ||
82 | } | ||
83 | |||
84 | public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server) | ||
85 | : this(config, server, String.Empty) | ||
86 | { | ||
87 | } | ||
88 | } | ||
89 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs new file mode 100644 index 0000000..6c79c60 --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs | |||
@@ -0,0 +1,77 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Server.Handlers.Base; | ||
34 | |||
35 | namespace OpenSim.Server.Handlers.Hypergrid | ||
36 | { | ||
37 | public class HGFriendsServerConnector : ServiceConnector | ||
38 | { | ||
39 | private IUserAgentService m_UserAgentService; | ||
40 | private IHGFriendsService m_TheService; | ||
41 | private string m_ConfigName = "HGFriendsService"; | ||
42 | |||
43 | // Called from Robust | ||
44 | public HGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName) : | ||
45 | this(config, server, configName, null) | ||
46 | { | ||
47 | |||
48 | } | ||
49 | |||
50 | // Called from standalone configurations | ||
51 | public HGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName, IFriendsSimConnector localConn) | ||
52 | : base(config, server, configName) | ||
53 | { | ||
54 | if (configName != string.Empty) | ||
55 | m_ConfigName = configName; | ||
56 | |||
57 | Object[] args = new Object[] { config, m_ConfigName, localConn }; | ||
58 | |||
59 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
60 | if (serverConfig == null) | ||
61 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | ||
62 | |||
63 | string theService = serverConfig.GetString("LocalServiceModule", | ||
64 | String.Empty); | ||
65 | if (theService == String.Empty) | ||
66 | throw new Exception("No LocalServiceModule in config file"); | ||
67 | m_TheService = ServerUtils.LoadPlugin<IHGFriendsService>(theService, args); | ||
68 | |||
69 | theService = serverConfig.GetString("UserAgentService", string.Empty); | ||
70 | if (theService == String.Empty) | ||
71 | throw new Exception("No UserAgentService in " + m_ConfigName); | ||
72 | m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(theService, new Object[] { config, localConn }); | ||
73 | |||
74 | server.AddStreamHandler(new HGFriendsServerPostHandler(m_TheService, m_UserAgentService, localConn)); | ||
75 | } | ||
76 | } | ||
77 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs new file mode 100644 index 0000000..37b47ed --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs | |||
@@ -0,0 +1,425 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using System.Collections.Generic; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
42 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
43 | using OpenSim.Framework; | ||
44 | using OpenSim.Framework.Servers.HttpServer; | ||
45 | using OpenMetaverse; | ||
46 | |||
47 | namespace OpenSim.Server.Handlers.Hypergrid | ||
48 | { | ||
49 | public class HGFriendsServerPostHandler : BaseStreamHandler | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | private IUserAgentService m_UserAgentService; | ||
54 | private IFriendsSimConnector m_FriendsLocalSimConnector; | ||
55 | private IHGFriendsService m_TheService; | ||
56 | |||
57 | public HGFriendsServerPostHandler(IHGFriendsService service, IUserAgentService uas, IFriendsSimConnector friendsConn) : | ||
58 | base("POST", "/hgfriends") | ||
59 | { | ||
60 | m_TheService = service; | ||
61 | m_UserAgentService = uas; | ||
62 | m_FriendsLocalSimConnector = friendsConn; | ||
63 | |||
64 | m_log.DebugFormat("[HGFRIENDS HANDLER]: HGFriendsServerPostHandler is On ({0})", | ||
65 | (m_FriendsLocalSimConnector == null ? "robust" : "standalone")); | ||
66 | |||
67 | if (m_TheService == null) | ||
68 | m_log.ErrorFormat("[HGFRIENDS HANDLER]: TheService is null!"); | ||
69 | } | ||
70 | |||
71 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
72 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
73 | { | ||
74 | StreamReader sr = new StreamReader(requestData); | ||
75 | string body = sr.ReadToEnd(); | ||
76 | sr.Close(); | ||
77 | body = body.Trim(); | ||
78 | |||
79 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
80 | |||
81 | try | ||
82 | { | ||
83 | Dictionary<string, object> request = | ||
84 | ServerUtils.ParseQueryString(body); | ||
85 | |||
86 | if (!request.ContainsKey("METHOD")) | ||
87 | return FailureResult(); | ||
88 | |||
89 | string method = request["METHOD"].ToString(); | ||
90 | |||
91 | switch (method) | ||
92 | { | ||
93 | case "getfriendperms": | ||
94 | return GetFriendPerms(request); | ||
95 | |||
96 | case "newfriendship": | ||
97 | return NewFriendship(request); | ||
98 | |||
99 | case "deletefriendship": | ||
100 | return DeleteFriendship(request); | ||
101 | |||
102 | /* Same as inter-sim */ | ||
103 | case "friendship_offered": | ||
104 | return FriendshipOffered(request); | ||
105 | |||
106 | case "validate_friendship_offered": | ||
107 | return ValidateFriendshipOffered(request); | ||
108 | |||
109 | case "statusnotification": | ||
110 | return StatusNotification(request); | ||
111 | /* | ||
112 | case "friendship_approved": | ||
113 | return FriendshipApproved(request); | ||
114 | |||
115 | case "friendship_denied": | ||
116 | return FriendshipDenied(request); | ||
117 | |||
118 | case "friendship_terminated": | ||
119 | return FriendshipTerminated(request); | ||
120 | |||
121 | case "grant_rights": | ||
122 | return GrantRights(request); | ||
123 | */ | ||
124 | } | ||
125 | |||
126 | m_log.DebugFormat("[HGFRIENDS HANDLER]: unknown method {0}", method); | ||
127 | } | ||
128 | catch (Exception e) | ||
129 | { | ||
130 | m_log.DebugFormat("[HGFRIENDS HANDLER]: Exception {0}", e); | ||
131 | } | ||
132 | |||
133 | return FailureResult(); | ||
134 | } | ||
135 | |||
136 | #region Method-specific handlers | ||
137 | |||
138 | byte[] GetFriendPerms(Dictionary<string, object> request) | ||
139 | { | ||
140 | if (!VerifyServiceKey(request)) | ||
141 | return FailureResult(); | ||
142 | |||
143 | UUID principalID = UUID.Zero; | ||
144 | if (request.ContainsKey("PRINCIPALID")) | ||
145 | UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID); | ||
146 | else | ||
147 | { | ||
148 | m_log.WarnFormat("[HGFRIENDS HANDLER]: no principalID in request to get friend perms"); | ||
149 | return FailureResult(); | ||
150 | } | ||
151 | |||
152 | UUID friendID = UUID.Zero; | ||
153 | if (request.ContainsKey("FRIENDID")) | ||
154 | UUID.TryParse(request["FRIENDID"].ToString(), out friendID); | ||
155 | else | ||
156 | { | ||
157 | m_log.WarnFormat("[HGFRIENDS HANDLER]: no friendID in request to get friend perms"); | ||
158 | return FailureResult(); | ||
159 | } | ||
160 | |||
161 | int perms = m_TheService.GetFriendPerms(principalID, friendID); | ||
162 | if (perms < 0) | ||
163 | return FailureResult("Friend not found"); | ||
164 | |||
165 | return SuccessResult(perms.ToString()); | ||
166 | } | ||
167 | |||
168 | byte[] NewFriendship(Dictionary<string, object> request) | ||
169 | { | ||
170 | bool verified = VerifyServiceKey(request); | ||
171 | |||
172 | FriendInfo friend = new FriendInfo(request); | ||
173 | |||
174 | bool success = m_TheService.NewFriendship(friend, verified); | ||
175 | |||
176 | if (success) | ||
177 | return SuccessResult(); | ||
178 | else | ||
179 | return FailureResult(); | ||
180 | } | ||
181 | |||
182 | byte[] DeleteFriendship(Dictionary<string, object> request) | ||
183 | { | ||
184 | FriendInfo friend = new FriendInfo(request); | ||
185 | string secret = string.Empty; | ||
186 | if (request.ContainsKey("SECRET")) | ||
187 | secret = request["SECRET"].ToString(); | ||
188 | |||
189 | if (secret == string.Empty) | ||
190 | return BoolResult(false); | ||
191 | |||
192 | bool success = m_TheService.DeleteFriendship(friend, secret); | ||
193 | |||
194 | return BoolResult(success); | ||
195 | } | ||
196 | |||
197 | byte[] FriendshipOffered(Dictionary<string, object> request) | ||
198 | { | ||
199 | UUID fromID = UUID.Zero; | ||
200 | UUID toID = UUID.Zero; | ||
201 | string message = string.Empty; | ||
202 | string name = string.Empty; | ||
203 | |||
204 | if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID")) | ||
205 | return BoolResult(false); | ||
206 | |||
207 | if (!UUID.TryParse(request["ToID"].ToString(), out toID)) | ||
208 | return BoolResult(false); | ||
209 | |||
210 | message = request["Message"].ToString(); | ||
211 | |||
212 | if (!UUID.TryParse(request["FromID"].ToString(), out fromID)) | ||
213 | return BoolResult(false); | ||
214 | |||
215 | if (request.ContainsKey("FromName")) | ||
216 | name = request["FromName"].ToString(); | ||
217 | |||
218 | bool success = m_TheService.FriendshipOffered(fromID, name, toID, message); | ||
219 | |||
220 | return BoolResult(success); | ||
221 | } | ||
222 | |||
223 | byte[] ValidateFriendshipOffered(Dictionary<string, object> request) | ||
224 | { | ||
225 | FriendInfo friend = new FriendInfo(request); | ||
226 | UUID friendID = UUID.Zero; | ||
227 | if (!UUID.TryParse(friend.Friend, out friendID)) | ||
228 | return BoolResult(false); | ||
229 | |||
230 | bool success = m_TheService.ValidateFriendshipOffered(friend.PrincipalID, friendID); | ||
231 | |||
232 | return BoolResult(success); | ||
233 | } | ||
234 | |||
235 | byte[] StatusNotification(Dictionary<string, object> request) | ||
236 | { | ||
237 | UUID principalID = UUID.Zero; | ||
238 | if (request.ContainsKey("userID")) | ||
239 | UUID.TryParse(request["userID"].ToString(), out principalID); | ||
240 | else | ||
241 | { | ||
242 | m_log.WarnFormat("[HGFRIENDS HANDLER]: no userID in request to notify"); | ||
243 | return FailureResult(); | ||
244 | } | ||
245 | |||
246 | bool online = true; | ||
247 | if (request.ContainsKey("online")) | ||
248 | Boolean.TryParse(request["online"].ToString(), out online); | ||
249 | else | ||
250 | { | ||
251 | m_log.WarnFormat("[HGFRIENDS HANDLER]: no online in request to notify"); | ||
252 | return FailureResult(); | ||
253 | } | ||
254 | |||
255 | List<string> friends = new List<string>(); | ||
256 | int i = 0; | ||
257 | foreach (KeyValuePair<string, object> kvp in request) | ||
258 | { | ||
259 | if (kvp.Key.Equals("friend_" + i.ToString())) | ||
260 | { | ||
261 | friends.Add(kvp.Value.ToString()); | ||
262 | i++; | ||
263 | } | ||
264 | } | ||
265 | |||
266 | List<UUID> onlineFriends = m_TheService.StatusNotification(friends, principalID, online); | ||
267 | |||
268 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
269 | if ((onlineFriends == null) || ((onlineFriends != null) && (onlineFriends.Count == 0))) | ||
270 | result["RESULT"] = "NULL"; | ||
271 | else | ||
272 | { | ||
273 | i = 0; | ||
274 | foreach (UUID f in onlineFriends) | ||
275 | { | ||
276 | result["friend_" + i] = f.ToString(); | ||
277 | i++; | ||
278 | } | ||
279 | } | ||
280 | |||
281 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
282 | |||
283 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
284 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
285 | } | ||
286 | |||
287 | #endregion | ||
288 | |||
289 | #region Misc | ||
290 | |||
291 | private bool VerifyServiceKey(Dictionary<string, object> request) | ||
292 | { | ||
293 | if (!request.ContainsKey("KEY") || !request.ContainsKey("SESSIONID")) | ||
294 | { | ||
295 | m_log.WarnFormat("[HGFRIENDS HANDLER]: ignoring request without Key or SessionID"); | ||
296 | return false; | ||
297 | } | ||
298 | |||
299 | if (request["KEY"] == null || request["SESSIONID"] == null) | ||
300 | return false; | ||
301 | |||
302 | string serviceKey = request["KEY"].ToString(); | ||
303 | string sessionStr = request["SESSIONID"].ToString(); | ||
304 | |||
305 | UUID sessionID; | ||
306 | if (!UUID.TryParse(sessionStr, out sessionID) || serviceKey == string.Empty) | ||
307 | return false; | ||
308 | |||
309 | if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey)) | ||
310 | { | ||
311 | m_log.WarnFormat("[HGFRIENDS HANDLER]: Key {0} for session {1} did not match existing key. Ignoring request", serviceKey, sessionID); | ||
312 | return false; | ||
313 | } | ||
314 | |||
315 | m_log.DebugFormat("[HGFRIENDS HANDLER]: Verification ok"); | ||
316 | return true; | ||
317 | } | ||
318 | |||
319 | private byte[] SuccessResult() | ||
320 | { | ||
321 | XmlDocument doc = new XmlDocument(); | ||
322 | |||
323 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
324 | "", ""); | ||
325 | |||
326 | doc.AppendChild(xmlnode); | ||
327 | |||
328 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
329 | ""); | ||
330 | |||
331 | doc.AppendChild(rootElement); | ||
332 | |||
333 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
334 | result.AppendChild(doc.CreateTextNode("Success")); | ||
335 | |||
336 | rootElement.AppendChild(result); | ||
337 | |||
338 | return Util.DocToBytes(doc); | ||
339 | } | ||
340 | |||
341 | private byte[] SuccessResult(string value) | ||
342 | { | ||
343 | XmlDocument doc = new XmlDocument(); | ||
344 | |||
345 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
346 | "", ""); | ||
347 | |||
348 | doc.AppendChild(xmlnode); | ||
349 | |||
350 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
351 | ""); | ||
352 | |||
353 | doc.AppendChild(rootElement); | ||
354 | |||
355 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
356 | result.AppendChild(doc.CreateTextNode("Success")); | ||
357 | |||
358 | rootElement.AppendChild(result); | ||
359 | |||
360 | XmlElement message = doc.CreateElement("", "Value", ""); | ||
361 | message.AppendChild(doc.CreateTextNode(value)); | ||
362 | |||
363 | rootElement.AppendChild(message); | ||
364 | |||
365 | return Util.DocToBytes(doc); | ||
366 | } | ||
367 | |||
368 | |||
369 | private byte[] FailureResult() | ||
370 | { | ||
371 | return FailureResult(String.Empty); | ||
372 | } | ||
373 | |||
374 | private byte[] FailureResult(string msg) | ||
375 | { | ||
376 | XmlDocument doc = new XmlDocument(); | ||
377 | |||
378 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
379 | "", ""); | ||
380 | |||
381 | doc.AppendChild(xmlnode); | ||
382 | |||
383 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
384 | ""); | ||
385 | |||
386 | doc.AppendChild(rootElement); | ||
387 | |||
388 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
389 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
390 | |||
391 | rootElement.AppendChild(result); | ||
392 | |||
393 | XmlElement message = doc.CreateElement("", "Message", ""); | ||
394 | message.AppendChild(doc.CreateTextNode(msg)); | ||
395 | |||
396 | rootElement.AppendChild(message); | ||
397 | |||
398 | return Util.DocToBytes(doc); | ||
399 | } | ||
400 | |||
401 | private byte[] BoolResult(bool value) | ||
402 | { | ||
403 | XmlDocument doc = new XmlDocument(); | ||
404 | |||
405 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
406 | "", ""); | ||
407 | |||
408 | doc.AppendChild(xmlnode); | ||
409 | |||
410 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
411 | ""); | ||
412 | |||
413 | doc.AppendChild(rootElement); | ||
414 | |||
415 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
416 | result.AppendChild(doc.CreateTextNode(value.ToString())); | ||
417 | |||
418 | rootElement.AppendChild(result); | ||
419 | |||
420 | return Util.DocToBytes(doc); | ||
421 | } | ||
422 | |||
423 | #endregion | ||
424 | } | ||
425 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/HeloServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/HeloServerConnector.cs new file mode 100644 index 0000000..dac4ca8 --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/HeloServerConnector.cs | |||
@@ -0,0 +1,113 @@ | |||
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.Net; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using log4net; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using OpenSim.Framework.Servers.HttpServer; | ||
38 | using OpenSim.Server.Handlers.Base; | ||
39 | |||
40 | namespace OpenSim.Server.Handlers.Hypergrid | ||
41 | { | ||
42 | public class HeloServiceInConnector : ServiceConnector | ||
43 | { | ||
44 | public HeloServiceInConnector(IConfigSource config, IHttpServer server, string configName) : | ||
45 | base(config, server, configName) | ||
46 | { | ||
47 | #pragma warning disable 0612 | ||
48 | server.AddStreamHandler(new HeloServerGetHandler("opensim-robust")); | ||
49 | #pragma warning restore 0612 | ||
50 | server.AddStreamHandler(new HeloServerHeadHandler("opensim-robust")); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | [Obsolete] | ||
55 | public class HeloServerGetHandler : BaseStreamHandler | ||
56 | { | ||
57 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
58 | |||
59 | private string m_HandlersType; | ||
60 | |||
61 | public HeloServerGetHandler(string handlersType) : | ||
62 | base("GET", "/helo") | ||
63 | { | ||
64 | m_HandlersType = handlersType; | ||
65 | } | ||
66 | |||
67 | public override byte[] Handle(string path, Stream requestData, | ||
68 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
69 | { | ||
70 | return OKResponse(httpResponse); | ||
71 | } | ||
72 | |||
73 | private byte[] OKResponse(IOSHttpResponse httpResponse) | ||
74 | { | ||
75 | m_log.Debug("[HELO]: hi, GET was called"); | ||
76 | httpResponse.AddHeader("X-Handlers-Provided", m_HandlersType); | ||
77 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
78 | httpResponse.StatusDescription = "OK"; | ||
79 | return new byte[0]; | ||
80 | } | ||
81 | |||
82 | } | ||
83 | |||
84 | public class HeloServerHeadHandler : BaseStreamHandler | ||
85 | { | ||
86 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
87 | |||
88 | private string m_HandlersType; | ||
89 | |||
90 | public HeloServerHeadHandler(string handlersType) : | ||
91 | base("HEAD", "/helo") | ||
92 | { | ||
93 | m_HandlersType = handlersType; | ||
94 | } | ||
95 | |||
96 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
97 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
98 | { | ||
99 | return OKResponse(httpResponse); | ||
100 | } | ||
101 | |||
102 | private byte[] OKResponse(IOSHttpResponse httpResponse) | ||
103 | { | ||
104 | m_log.Debug("[HELO]: hi, HEAD was called"); | ||
105 | httpResponse.AddHeader("X-Handlers-Provided", m_HandlersType); | ||
106 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
107 | httpResponse.StatusDescription = "OK"; | ||
108 | return new byte[0]; | ||
109 | } | ||
110 | |||
111 | } | ||
112 | |||
113 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs new file mode 100644 index 0000000..e787f7c --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs | |||
@@ -0,0 +1,137 @@ | |||
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; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Net; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Server.Handlers.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Servers.HttpServer; | ||
41 | using OpenSim.Server.Handlers.Simulation; | ||
42 | using Utils = OpenSim.Server.Handlers.Simulation.Utils; | ||
43 | |||
44 | using OpenMetaverse; | ||
45 | using OpenMetaverse.StructuredData; | ||
46 | using Nini.Config; | ||
47 | using log4net; | ||
48 | |||
49 | |||
50 | namespace OpenSim.Server.Handlers.Hypergrid | ||
51 | { | ||
52 | public class HomeAgentHandler : AgentPostHandler | ||
53 | { | ||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | private IUserAgentService m_UserAgentService; | ||
56 | |||
57 | private string m_LoginServerIP; | ||
58 | |||
59 | public HomeAgentHandler(IUserAgentService userAgentService, string loginServerIP, bool proxy) : | ||
60 | base("/homeagent") | ||
61 | { | ||
62 | m_UserAgentService = userAgentService; | ||
63 | m_LoginServerIP = loginServerIP; | ||
64 | m_Proxy = proxy; | ||
65 | } | ||
66 | |||
67 | protected override AgentDestinationData CreateAgentDestinationData() | ||
68 | { | ||
69 | return new ExtendedAgentDestinationData(); | ||
70 | } | ||
71 | |||
72 | protected override void UnpackData(OSDMap args, AgentDestinationData d, Hashtable request) | ||
73 | { | ||
74 | base.UnpackData(args, d, request); | ||
75 | ExtendedAgentDestinationData data = (ExtendedAgentDestinationData)d; | ||
76 | try | ||
77 | { | ||
78 | if (args.ContainsKey("gatekeeper_host") && args["gatekeeper_host"] != null) | ||
79 | data.host = args["gatekeeper_host"].AsString(); | ||
80 | if (args.ContainsKey("gatekeeper_port") && args["gatekeeper_port"] != null) | ||
81 | Int32.TryParse(args["gatekeeper_port"].AsString(), out data.port); | ||
82 | if (args.ContainsKey("gatekeeper_serveruri") && args["gatekeeper_serveruri"] != null) | ||
83 | data.gatekeeperServerURI = args["gatekeeper_serveruri"]; | ||
84 | if (args.ContainsKey("destination_serveruri") && args["destination_serveruri"] != null) | ||
85 | data.destinationServerURI = args["destination_serveruri"]; | ||
86 | |||
87 | } | ||
88 | catch (InvalidCastException) | ||
89 | { | ||
90 | m_log.ErrorFormat("[HOME AGENT HANDLER]: Bad cast in UnpackData"); | ||
91 | } | ||
92 | |||
93 | string callerIP = GetCallerIP(request); | ||
94 | // Verify if this call came from the login server | ||
95 | if (callerIP == m_LoginServerIP) | ||
96 | data.fromLogin = true; | ||
97 | |||
98 | } | ||
99 | |||
100 | protected override GridRegion ExtractGatekeeper(AgentDestinationData d) | ||
101 | { | ||
102 | if (d is ExtendedAgentDestinationData) | ||
103 | { | ||
104 | ExtendedAgentDestinationData data = (ExtendedAgentDestinationData)d; | ||
105 | GridRegion gatekeeper = new GridRegion(); | ||
106 | gatekeeper.ServerURI = data.gatekeeperServerURI; | ||
107 | gatekeeper.ExternalHostName = data.host; | ||
108 | gatekeeper.HttpPort = (uint)data.port; | ||
109 | gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); | ||
110 | |||
111 | return gatekeeper; | ||
112 | } | ||
113 | else | ||
114 | m_log.WarnFormat("[HOME AGENT HANDLER]: Wrong data type"); | ||
115 | |||
116 | return null; | ||
117 | } | ||
118 | |||
119 | |||
120 | protected override bool CreateAgent(GridRegion source, GridRegion gatekeeper, GridRegion destination, | ||
121 | AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason) | ||
122 | { | ||
123 | return m_UserAgentService.LoginAgentToGrid(source, aCircuit, gatekeeper, destination, fromLogin, out reason); | ||
124 | } | ||
125 | |||
126 | } | ||
127 | |||
128 | public class ExtendedAgentDestinationData : AgentDestinationData | ||
129 | { | ||
130 | public string host; | ||
131 | public int port; | ||
132 | public string gatekeeperServerURI; | ||
133 | public string destinationServerURI; | ||
134 | |||
135 | } | ||
136 | |||
137 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs new file mode 100644 index 0000000..c7ac9be --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs | |||
@@ -0,0 +1,136 @@ | |||
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; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using System.Reflection; | ||
32 | |||
33 | using OpenSim.Services.Interfaces; | ||
34 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
35 | |||
36 | using log4net; | ||
37 | using Nwc.XmlRpc; | ||
38 | using OpenMetaverse; | ||
39 | |||
40 | namespace OpenSim.Server.Handlers.Hypergrid | ||
41 | { | ||
42 | public class HypergridHandlers | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | private IGatekeeperService m_GatekeeperService; | ||
47 | |||
48 | public HypergridHandlers(IGatekeeperService gatekeeper) | ||
49 | { | ||
50 | m_GatekeeperService = gatekeeper; | ||
51 | m_log.DebugFormat("[HYPERGRID HANDLERS]: Active"); | ||
52 | } | ||
53 | |||
54 | /// <summary> | ||
55 | /// Someone wants to link to us | ||
56 | /// </summary> | ||
57 | /// <param name="request"></param> | ||
58 | /// <returns></returns> | ||
59 | public XmlRpcResponse LinkRegionRequest(XmlRpcRequest request, IPEndPoint remoteClient) | ||
60 | { | ||
61 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
62 | //string host = (string)requestData["host"]; | ||
63 | //string portstr = (string)requestData["port"]; | ||
64 | string name = (string)requestData["region_name"]; | ||
65 | if (name == null) | ||
66 | name = string.Empty; | ||
67 | |||
68 | UUID regionID = UUID.Zero; | ||
69 | string externalName = string.Empty; | ||
70 | string imageURL = string.Empty; | ||
71 | ulong regionHandle = 0; | ||
72 | string reason = string.Empty; | ||
73 | |||
74 | bool success = m_GatekeeperService.LinkRegion(name, out regionID, out regionHandle, out externalName, out imageURL, out reason); | ||
75 | |||
76 | Hashtable hash = new Hashtable(); | ||
77 | hash["result"] = success.ToString(); | ||
78 | hash["uuid"] = regionID.ToString(); | ||
79 | hash["handle"] = regionHandle.ToString(); | ||
80 | hash["region_image"] = imageURL; | ||
81 | hash["external_name"] = externalName; | ||
82 | |||
83 | XmlRpcResponse response = new XmlRpcResponse(); | ||
84 | response.Value = hash; | ||
85 | return response; | ||
86 | } | ||
87 | |||
88 | public XmlRpcResponse GetRegion(XmlRpcRequest request, IPEndPoint remoteClient) | ||
89 | { | ||
90 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
91 | //string host = (string)requestData["host"]; | ||
92 | //string portstr = (string)requestData["port"]; | ||
93 | string regionID_str = (string)requestData["region_uuid"]; | ||
94 | UUID regionID = UUID.Zero; | ||
95 | UUID.TryParse(regionID_str, out regionID); | ||
96 | |||
97 | UUID agentID = UUID.Zero; | ||
98 | string agentHomeURI = null; | ||
99 | if (requestData.ContainsKey("agent_id")) | ||
100 | agentID = UUID.Parse((string)requestData["agent_id"]); | ||
101 | if (requestData.ContainsKey("agent_home_uri")) | ||
102 | agentHomeURI = (string)requestData["agent_home_uri"]; | ||
103 | |||
104 | string message; | ||
105 | GridRegion regInfo = m_GatekeeperService.GetHyperlinkRegion(regionID, agentID, agentHomeURI, out message); | ||
106 | |||
107 | Hashtable hash = new Hashtable(); | ||
108 | if (regInfo == null) | ||
109 | { | ||
110 | hash["result"] = "false"; | ||
111 | } | ||
112 | else | ||
113 | { | ||
114 | hash["result"] = "true"; | ||
115 | hash["uuid"] = regInfo.RegionID.ToString(); | ||
116 | hash["x"] = regInfo.RegionLocX.ToString(); | ||
117 | hash["y"] = regInfo.RegionLocY.ToString(); | ||
118 | hash["size_x"] = regInfo.RegionSizeX.ToString(); | ||
119 | hash["size_y"] = regInfo.RegionSizeY.ToString(); | ||
120 | hash["region_name"] = regInfo.RegionName; | ||
121 | hash["hostname"] = regInfo.ExternalHostName; | ||
122 | hash["http_port"] = regInfo.HttpPort.ToString(); | ||
123 | hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString(); | ||
124 | } | ||
125 | |||
126 | if (message != null) | ||
127 | hash["message"] = message; | ||
128 | |||
129 | XmlRpcResponse response = new XmlRpcResponse(); | ||
130 | response.Value = hash; | ||
131 | return response; | ||
132 | |||
133 | } | ||
134 | |||
135 | } | ||
136 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs new file mode 100644 index 0000000..8145a21 --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs | |||
@@ -0,0 +1,248 @@ | |||
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; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | |||
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.Server.Handlers.Base; | ||
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
41 | |||
42 | using log4net; | ||
43 | using Nwc.XmlRpc; | ||
44 | using OpenMetaverse; | ||
45 | |||
46 | namespace OpenSim.Server.Handlers.Hypergrid | ||
47 | { | ||
48 | public class InstantMessageServerConnector : ServiceConnector | ||
49 | { | ||
50 | private static readonly ILog m_log = | ||
51 | LogManager.GetLogger( | ||
52 | MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | |||
54 | private IInstantMessage m_IMService; | ||
55 | |||
56 | public InstantMessageServerConnector(IConfigSource config, IHttpServer server) : | ||
57 | this(config, server, (IInstantMessageSimConnector)null) | ||
58 | { | ||
59 | } | ||
60 | |||
61 | public InstantMessageServerConnector(IConfigSource config, IHttpServer server, string configName) : | ||
62 | this(config, server) | ||
63 | { | ||
64 | } | ||
65 | |||
66 | public InstantMessageServerConnector(IConfigSource config, IHttpServer server, IInstantMessageSimConnector simConnector) : | ||
67 | base(config, server, String.Empty) | ||
68 | { | ||
69 | IConfig gridConfig = config.Configs["HGInstantMessageService"]; | ||
70 | if (gridConfig != null) | ||
71 | { | ||
72 | string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); | ||
73 | |||
74 | Object[] args = new Object[] { config, simConnector }; | ||
75 | m_IMService = ServerUtils.LoadPlugin<IInstantMessage>(serviceDll, args); | ||
76 | } | ||
77 | if (m_IMService == null) | ||
78 | throw new Exception("InstantMessage server connector cannot proceed because of missing service"); | ||
79 | |||
80 | server.AddXmlRPCHandler("grid_instant_message", ProcessInstantMessage, false); | ||
81 | |||
82 | } | ||
83 | |||
84 | public IInstantMessage GetService() | ||
85 | { | ||
86 | return m_IMService; | ||
87 | } | ||
88 | |||
89 | protected virtual XmlRpcResponse ProcessInstantMessage(XmlRpcRequest request, IPEndPoint remoteClient) | ||
90 | { | ||
91 | bool successful = false; | ||
92 | |||
93 | try | ||
94 | { | ||
95 | // various rational defaults | ||
96 | UUID fromAgentID = UUID.Zero; | ||
97 | UUID toAgentID = UUID.Zero; | ||
98 | UUID imSessionID = UUID.Zero; | ||
99 | uint timestamp = 0; | ||
100 | string fromAgentName = ""; | ||
101 | string message = ""; | ||
102 | byte dialog = (byte)0; | ||
103 | bool fromGroup = false; | ||
104 | byte offline = (byte)0; | ||
105 | uint ParentEstateID = 0; | ||
106 | Vector3 Position = Vector3.Zero; | ||
107 | UUID RegionID = UUID.Zero; | ||
108 | byte[] binaryBucket = new byte[0]; | ||
109 | |||
110 | float pos_x = 0; | ||
111 | float pos_y = 0; | ||
112 | float pos_z = 0; | ||
113 | //m_log.Info("Processing IM"); | ||
114 | |||
115 | |||
116 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
117 | // Check if it's got all the data | ||
118 | if (requestData.ContainsKey("from_agent_id") | ||
119 | && requestData.ContainsKey("to_agent_id") && requestData.ContainsKey("im_session_id") | ||
120 | && requestData.ContainsKey("timestamp") && requestData.ContainsKey("from_agent_name") | ||
121 | && requestData.ContainsKey("message") && requestData.ContainsKey("dialog") | ||
122 | && requestData.ContainsKey("from_group") | ||
123 | && requestData.ContainsKey("offline") && requestData.ContainsKey("parent_estate_id") | ||
124 | && requestData.ContainsKey("position_x") && requestData.ContainsKey("position_y") | ||
125 | && requestData.ContainsKey("position_z") && requestData.ContainsKey("region_id") | ||
126 | && requestData.ContainsKey("binary_bucket")) | ||
127 | { | ||
128 | // Do the easy way of validating the UUIDs | ||
129 | UUID.TryParse((string)requestData["from_agent_id"], out fromAgentID); | ||
130 | UUID.TryParse((string)requestData["to_agent_id"], out toAgentID); | ||
131 | UUID.TryParse((string)requestData["im_session_id"], out imSessionID); | ||
132 | UUID.TryParse((string)requestData["region_id"], out RegionID); | ||
133 | try | ||
134 | { | ||
135 | timestamp = (uint)Convert.ToInt32((string)requestData["timestamp"]); | ||
136 | } | ||
137 | catch (ArgumentException) | ||
138 | { | ||
139 | } | ||
140 | catch (FormatException) | ||
141 | { | ||
142 | } | ||
143 | catch (OverflowException) | ||
144 | { | ||
145 | } | ||
146 | |||
147 | fromAgentName = (string)requestData["from_agent_name"]; | ||
148 | message = (string)requestData["message"]; | ||
149 | if (message == null) | ||
150 | message = string.Empty; | ||
151 | |||
152 | // Bytes don't transfer well over XMLRPC, so, we Base64 Encode them. | ||
153 | string requestData1 = (string)requestData["dialog"]; | ||
154 | if (string.IsNullOrEmpty(requestData1)) | ||
155 | { | ||
156 | dialog = 0; | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | byte[] dialogdata = Convert.FromBase64String(requestData1); | ||
161 | dialog = dialogdata[0]; | ||
162 | } | ||
163 | |||
164 | if ((string)requestData["from_group"] == "TRUE") | ||
165 | fromGroup = true; | ||
166 | |||
167 | string requestData2 = (string)requestData["offline"]; | ||
168 | if (String.IsNullOrEmpty(requestData2)) | ||
169 | { | ||
170 | offline = 0; | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | byte[] offlinedata = Convert.FromBase64String(requestData2); | ||
175 | offline = offlinedata[0]; | ||
176 | } | ||
177 | |||
178 | try | ||
179 | { | ||
180 | ParentEstateID = (uint)Convert.ToInt32((string)requestData["parent_estate_id"]); | ||
181 | } | ||
182 | catch (ArgumentException) | ||
183 | { | ||
184 | } | ||
185 | catch (FormatException) | ||
186 | { | ||
187 | } | ||
188 | catch (OverflowException) | ||
189 | { | ||
190 | } | ||
191 | |||
192 | float.TryParse((string)requestData["position_x"], out pos_x); | ||
193 | float.TryParse((string)requestData["position_y"], out pos_y); | ||
194 | float.TryParse((string)requestData["position_z"], out pos_z); | ||
195 | |||
196 | Position = new Vector3(pos_x, pos_y, pos_z); | ||
197 | |||
198 | string requestData3 = (string)requestData["binary_bucket"]; | ||
199 | if (string.IsNullOrEmpty(requestData3)) | ||
200 | { | ||
201 | binaryBucket = new byte[0]; | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | binaryBucket = Convert.FromBase64String(requestData3); | ||
206 | } | ||
207 | |||
208 | // Create a New GridInstantMessageObject the the data | ||
209 | GridInstantMessage gim = new GridInstantMessage(); | ||
210 | gim.fromAgentID = fromAgentID.Guid; | ||
211 | gim.fromAgentName = fromAgentName; | ||
212 | gim.fromGroup = fromGroup; | ||
213 | gim.imSessionID = imSessionID.Guid; | ||
214 | gim.RegionID = RegionID.Guid; | ||
215 | gim.timestamp = timestamp; | ||
216 | gim.toAgentID = toAgentID.Guid; | ||
217 | gim.message = message; | ||
218 | gim.dialog = dialog; | ||
219 | gim.offline = offline; | ||
220 | gim.ParentEstateID = ParentEstateID; | ||
221 | gim.Position = Position; | ||
222 | gim.binaryBucket = binaryBucket; | ||
223 | |||
224 | successful = m_IMService.IncomingInstantMessage(gim); | ||
225 | |||
226 | } | ||
227 | } | ||
228 | catch (Exception e) | ||
229 | { | ||
230 | m_log.Error("[INSTANT MESSAGE]: Caught unexpected exception:", e); | ||
231 | successful = false; | ||
232 | } | ||
233 | |||
234 | //Send response back to region calling if it was successful | ||
235 | // calling region uses this to know when to look up a user's location again. | ||
236 | XmlRpcResponse resp = new XmlRpcResponse(); | ||
237 | Hashtable respdata = new Hashtable(); | ||
238 | if (successful) | ||
239 | respdata["success"] = "TRUE"; | ||
240 | else | ||
241 | respdata["success"] = "FALSE"; | ||
242 | resp.Value = respdata; | ||
243 | |||
244 | return resp; | ||
245 | } | ||
246 | |||
247 | } | ||
248 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs new file mode 100644 index 0000000..e112e0e --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs | |||
@@ -0,0 +1,488 @@ | |||
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; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | |||
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.Server.Handlers.Base; | ||
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
41 | |||
42 | using log4net; | ||
43 | using Nwc.XmlRpc; | ||
44 | using OpenMetaverse; | ||
45 | |||
46 | namespace OpenSim.Server.Handlers.Hypergrid | ||
47 | { | ||
48 | public class UserAgentServerConnector : ServiceConnector | ||
49 | { | ||
50 | // private static readonly ILog m_log = | ||
51 | // LogManager.GetLogger( | ||
52 | // MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | |||
54 | private IUserAgentService m_HomeUsersService; | ||
55 | public IUserAgentService HomeUsersService | ||
56 | { | ||
57 | get { return m_HomeUsersService; } | ||
58 | } | ||
59 | |||
60 | private string[] m_AuthorizedCallers; | ||
61 | |||
62 | private bool m_VerifyCallers = false; | ||
63 | |||
64 | public UserAgentServerConnector(IConfigSource config, IHttpServer server) : | ||
65 | this(config, server, (IFriendsSimConnector)null) | ||
66 | { | ||
67 | } | ||
68 | |||
69 | public UserAgentServerConnector(IConfigSource config, IHttpServer server, string configName) : | ||
70 | this(config, server) | ||
71 | { | ||
72 | } | ||
73 | |||
74 | public UserAgentServerConnector(IConfigSource config, IHttpServer server, IFriendsSimConnector friendsConnector) : | ||
75 | base(config, server, String.Empty) | ||
76 | { | ||
77 | IConfig gridConfig = config.Configs["UserAgentService"]; | ||
78 | if (gridConfig != null) | ||
79 | { | ||
80 | string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); | ||
81 | |||
82 | Object[] args = new Object[] { config, friendsConnector }; | ||
83 | m_HomeUsersService = ServerUtils.LoadPlugin<IUserAgentService>(serviceDll, args); | ||
84 | } | ||
85 | if (m_HomeUsersService == null) | ||
86 | throw new Exception("UserAgent server connector cannot proceed because of missing service"); | ||
87 | |||
88 | string loginServerIP = gridConfig.GetString("LoginServerIP", "127.0.0.1"); | ||
89 | bool proxy = gridConfig.GetBoolean("HasProxy", false); | ||
90 | |||
91 | m_VerifyCallers = gridConfig.GetBoolean("VerifyCallers", false); | ||
92 | string csv = gridConfig.GetString("AuthorizedCallers", "127.0.0.1"); | ||
93 | csv = csv.Replace(" ", ""); | ||
94 | m_AuthorizedCallers = csv.Split(','); | ||
95 | |||
96 | server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false); | ||
97 | server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false); | ||
98 | server.AddXmlRPCHandler("verify_agent", VerifyAgent, false); | ||
99 | server.AddXmlRPCHandler("verify_client", VerifyClient, false); | ||
100 | server.AddXmlRPCHandler("logout_agent", LogoutAgent, false); | ||
101 | |||
102 | #pragma warning disable 0612 | ||
103 | server.AddXmlRPCHandler("status_notification", StatusNotification, false); | ||
104 | server.AddXmlRPCHandler("get_online_friends", GetOnlineFriends, false); | ||
105 | #pragma warning restore 0612 | ||
106 | server.AddXmlRPCHandler("get_user_info", GetUserInfo, false); | ||
107 | server.AddXmlRPCHandler("get_server_urls", GetServerURLs, false); | ||
108 | |||
109 | server.AddXmlRPCHandler("locate_user", LocateUser, false); | ||
110 | server.AddXmlRPCHandler("get_uui", GetUUI, false); | ||
111 | server.AddXmlRPCHandler("get_uuid", GetUUID, false); | ||
112 | |||
113 | server.AddStreamHandler(new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy)); | ||
114 | } | ||
115 | |||
116 | public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient) | ||
117 | { | ||
118 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
119 | //string host = (string)requestData["host"]; | ||
120 | //string portstr = (string)requestData["port"]; | ||
121 | string userID_str = (string)requestData["userID"]; | ||
122 | UUID userID = UUID.Zero; | ||
123 | UUID.TryParse(userID_str, out userID); | ||
124 | |||
125 | Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY; | ||
126 | GridRegion regInfo = m_HomeUsersService.GetHomeRegion(userID, out position, out lookAt); | ||
127 | |||
128 | Hashtable hash = new Hashtable(); | ||
129 | if (regInfo == null) | ||
130 | hash["result"] = "false"; | ||
131 | else | ||
132 | { | ||
133 | hash["result"] = "true"; | ||
134 | hash["uuid"] = regInfo.RegionID.ToString(); | ||
135 | hash["x"] = regInfo.RegionLocX.ToString(); | ||
136 | hash["y"] = regInfo.RegionLocY.ToString(); | ||
137 | hash["size_x"] = regInfo.RegionSizeX.ToString(); | ||
138 | hash["size_y"] = regInfo.RegionSizeY.ToString(); | ||
139 | hash["region_name"] = regInfo.RegionName; | ||
140 | hash["hostname"] = regInfo.ExternalHostName; | ||
141 | hash["http_port"] = regInfo.HttpPort.ToString(); | ||
142 | hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString(); | ||
143 | hash["position"] = position.ToString(); | ||
144 | hash["lookAt"] = lookAt.ToString(); | ||
145 | } | ||
146 | XmlRpcResponse response = new XmlRpcResponse(); | ||
147 | response.Value = hash; | ||
148 | return response; | ||
149 | |||
150 | } | ||
151 | |||
152 | public XmlRpcResponse AgentIsComingHome(XmlRpcRequest request, IPEndPoint remoteClient) | ||
153 | { | ||
154 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
155 | //string host = (string)requestData["host"]; | ||
156 | //string portstr = (string)requestData["port"]; | ||
157 | string sessionID_str = (string)requestData["sessionID"]; | ||
158 | UUID sessionID = UUID.Zero; | ||
159 | UUID.TryParse(sessionID_str, out sessionID); | ||
160 | string gridName = (string)requestData["externalName"]; | ||
161 | |||
162 | bool success = m_HomeUsersService.IsAgentComingHome(sessionID, gridName); | ||
163 | |||
164 | Hashtable hash = new Hashtable(); | ||
165 | hash["result"] = success.ToString(); | ||
166 | XmlRpcResponse response = new XmlRpcResponse(); | ||
167 | response.Value = hash; | ||
168 | return response; | ||
169 | |||
170 | } | ||
171 | |||
172 | public XmlRpcResponse VerifyAgent(XmlRpcRequest request, IPEndPoint remoteClient) | ||
173 | { | ||
174 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
175 | //string host = (string)requestData["host"]; | ||
176 | //string portstr = (string)requestData["port"]; | ||
177 | string sessionID_str = (string)requestData["sessionID"]; | ||
178 | UUID sessionID = UUID.Zero; | ||
179 | UUID.TryParse(sessionID_str, out sessionID); | ||
180 | string token = (string)requestData["token"]; | ||
181 | |||
182 | bool success = m_HomeUsersService.VerifyAgent(sessionID, token); | ||
183 | |||
184 | Hashtable hash = new Hashtable(); | ||
185 | hash["result"] = success.ToString(); | ||
186 | XmlRpcResponse response = new XmlRpcResponse(); | ||
187 | response.Value = hash; | ||
188 | return response; | ||
189 | |||
190 | } | ||
191 | |||
192 | public XmlRpcResponse VerifyClient(XmlRpcRequest request, IPEndPoint remoteClient) | ||
193 | { | ||
194 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
195 | //string host = (string)requestData["host"]; | ||
196 | //string portstr = (string)requestData["port"]; | ||
197 | string sessionID_str = (string)requestData["sessionID"]; | ||
198 | UUID sessionID = UUID.Zero; | ||
199 | UUID.TryParse(sessionID_str, out sessionID); | ||
200 | string token = (string)requestData["token"]; | ||
201 | |||
202 | bool success = m_HomeUsersService.VerifyClient(sessionID, token); | ||
203 | |||
204 | Hashtable hash = new Hashtable(); | ||
205 | hash["result"] = success.ToString(); | ||
206 | XmlRpcResponse response = new XmlRpcResponse(); | ||
207 | response.Value = hash; | ||
208 | return response; | ||
209 | |||
210 | } | ||
211 | |||
212 | public XmlRpcResponse LogoutAgent(XmlRpcRequest request, IPEndPoint remoteClient) | ||
213 | { | ||
214 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
215 | //string host = (string)requestData["host"]; | ||
216 | //string portstr = (string)requestData["port"]; | ||
217 | string sessionID_str = (string)requestData["sessionID"]; | ||
218 | UUID sessionID = UUID.Zero; | ||
219 | UUID.TryParse(sessionID_str, out sessionID); | ||
220 | string userID_str = (string)requestData["userID"]; | ||
221 | UUID userID = UUID.Zero; | ||
222 | UUID.TryParse(userID_str, out userID); | ||
223 | |||
224 | m_HomeUsersService.LogoutAgent(userID, sessionID); | ||
225 | |||
226 | Hashtable hash = new Hashtable(); | ||
227 | hash["result"] = "true"; | ||
228 | XmlRpcResponse response = new XmlRpcResponse(); | ||
229 | response.Value = hash; | ||
230 | return response; | ||
231 | |||
232 | } | ||
233 | |||
234 | [Obsolete] | ||
235 | public XmlRpcResponse StatusNotification(XmlRpcRequest request, IPEndPoint remoteClient) | ||
236 | { | ||
237 | Hashtable hash = new Hashtable(); | ||
238 | hash["result"] = "false"; | ||
239 | |||
240 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
241 | //string host = (string)requestData["host"]; | ||
242 | //string portstr = (string)requestData["port"]; | ||
243 | if (requestData.ContainsKey("userID") && requestData.ContainsKey("online")) | ||
244 | { | ||
245 | string userID_str = (string)requestData["userID"]; | ||
246 | UUID userID = UUID.Zero; | ||
247 | UUID.TryParse(userID_str, out userID); | ||
248 | List<string> ids = new List<string>(); | ||
249 | foreach (object key in requestData.Keys) | ||
250 | { | ||
251 | if (key is string && ((string)key).StartsWith("friend_") && requestData[key] != null) | ||
252 | ids.Add(requestData[key].ToString()); | ||
253 | } | ||
254 | bool online = false; | ||
255 | bool.TryParse(requestData["online"].ToString(), out online); | ||
256 | |||
257 | // let's spawn a thread for this, because it may take a long time... | ||
258 | List<UUID> friendsOnline = m_HomeUsersService.StatusNotification(ids, userID, online); | ||
259 | if (friendsOnline.Count > 0) | ||
260 | { | ||
261 | int i = 0; | ||
262 | foreach (UUID id in friendsOnline) | ||
263 | { | ||
264 | hash["friend_" + i.ToString()] = id.ToString(); | ||
265 | i++; | ||
266 | } | ||
267 | } | ||
268 | else | ||
269 | hash["result"] = "No Friends Online"; | ||
270 | |||
271 | } | ||
272 | |||
273 | XmlRpcResponse response = new XmlRpcResponse(); | ||
274 | response.Value = hash; | ||
275 | return response; | ||
276 | |||
277 | } | ||
278 | |||
279 | [Obsolete] | ||
280 | public XmlRpcResponse GetOnlineFriends(XmlRpcRequest request, IPEndPoint remoteClient) | ||
281 | { | ||
282 | Hashtable hash = new Hashtable(); | ||
283 | |||
284 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
285 | //string host = (string)requestData["host"]; | ||
286 | //string portstr = (string)requestData["port"]; | ||
287 | if (requestData.ContainsKey("userID")) | ||
288 | { | ||
289 | string userID_str = (string)requestData["userID"]; | ||
290 | UUID userID = UUID.Zero; | ||
291 | UUID.TryParse(userID_str, out userID); | ||
292 | List<string> ids = new List<string>(); | ||
293 | foreach (object key in requestData.Keys) | ||
294 | { | ||
295 | if (key is string && ((string)key).StartsWith("friend_") && requestData[key] != null) | ||
296 | ids.Add(requestData[key].ToString()); | ||
297 | } | ||
298 | |||
299 | //List<UUID> online = m_HomeUsersService.GetOnlineFriends(userID, ids); | ||
300 | //if (online.Count > 0) | ||
301 | //{ | ||
302 | // int i = 0; | ||
303 | // foreach (UUID id in online) | ||
304 | // { | ||
305 | // hash["friend_" + i.ToString()] = id.ToString(); | ||
306 | // i++; | ||
307 | // } | ||
308 | //} | ||
309 | //else | ||
310 | // hash["result"] = "No Friends Online"; | ||
311 | } | ||
312 | |||
313 | XmlRpcResponse response = new XmlRpcResponse(); | ||
314 | response.Value = hash; | ||
315 | return response; | ||
316 | |||
317 | } | ||
318 | |||
319 | public XmlRpcResponse GetUserInfo(XmlRpcRequest request, IPEndPoint remoteClient) | ||
320 | { | ||
321 | Hashtable hash = new Hashtable(); | ||
322 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
323 | |||
324 | // This needs checking! | ||
325 | if (requestData.ContainsKey("userID")) | ||
326 | { | ||
327 | string userID_str = (string)requestData["userID"]; | ||
328 | UUID userID = UUID.Zero; | ||
329 | UUID.TryParse(userID_str, out userID); | ||
330 | |||
331 | //int userFlags = m_HomeUsersService.GetUserFlags(userID); | ||
332 | Dictionary<string,object> userInfo = m_HomeUsersService.GetUserInfo(userID); | ||
333 | if (userInfo.Count > 0) | ||
334 | { | ||
335 | foreach (KeyValuePair<string, object> kvp in userInfo) | ||
336 | { | ||
337 | hash[kvp.Key] = kvp.Value; | ||
338 | } | ||
339 | } | ||
340 | else | ||
341 | { | ||
342 | hash["result"] = "failure"; | ||
343 | } | ||
344 | } | ||
345 | |||
346 | XmlRpcResponse response = new XmlRpcResponse(); | ||
347 | response.Value = hash; | ||
348 | return response; | ||
349 | } | ||
350 | |||
351 | public XmlRpcResponse GetServerURLs(XmlRpcRequest request, IPEndPoint remoteClient) | ||
352 | { | ||
353 | Hashtable hash = new Hashtable(); | ||
354 | |||
355 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
356 | //string host = (string)requestData["host"]; | ||
357 | //string portstr = (string)requestData["port"]; | ||
358 | if (requestData.ContainsKey("userID")) | ||
359 | { | ||
360 | string userID_str = (string)requestData["userID"]; | ||
361 | UUID userID = UUID.Zero; | ||
362 | UUID.TryParse(userID_str, out userID); | ||
363 | |||
364 | Dictionary<string, object> serverURLs = m_HomeUsersService.GetServerURLs(userID); | ||
365 | if (serverURLs.Count > 0) | ||
366 | { | ||
367 | foreach (KeyValuePair<string, object> kvp in serverURLs) | ||
368 | hash["SRV_" + kvp.Key] = kvp.Value.ToString(); | ||
369 | } | ||
370 | else | ||
371 | hash["result"] = "No Service URLs"; | ||
372 | } | ||
373 | |||
374 | XmlRpcResponse response = new XmlRpcResponse(); | ||
375 | response.Value = hash; | ||
376 | return response; | ||
377 | |||
378 | } | ||
379 | |||
380 | /// <summary> | ||
381 | /// Locates the user. | ||
382 | /// This is a sensitive operation, only authorized IP addresses can perform it. | ||
383 | /// </summary> | ||
384 | /// <param name="request"></param> | ||
385 | /// <param name="remoteClient"></param> | ||
386 | /// <returns></returns> | ||
387 | public XmlRpcResponse LocateUser(XmlRpcRequest request, IPEndPoint remoteClient) | ||
388 | { | ||
389 | Hashtable hash = new Hashtable(); | ||
390 | |||
391 | bool authorized = true; | ||
392 | if (m_VerifyCallers) | ||
393 | { | ||
394 | authorized = false; | ||
395 | foreach (string s in m_AuthorizedCallers) | ||
396 | if (s == remoteClient.Address.ToString()) | ||
397 | { | ||
398 | authorized = true; | ||
399 | break; | ||
400 | } | ||
401 | } | ||
402 | |||
403 | if (authorized) | ||
404 | { | ||
405 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
406 | //string host = (string)requestData["host"]; | ||
407 | //string portstr = (string)requestData["port"]; | ||
408 | if (requestData.ContainsKey("userID")) | ||
409 | { | ||
410 | string userID_str = (string)requestData["userID"]; | ||
411 | UUID userID = UUID.Zero; | ||
412 | UUID.TryParse(userID_str, out userID); | ||
413 | |||
414 | string url = m_HomeUsersService.LocateUser(userID); | ||
415 | if (url != string.Empty) | ||
416 | hash["URL"] = url; | ||
417 | else | ||
418 | hash["result"] = "Unable to locate user"; | ||
419 | } | ||
420 | } | ||
421 | |||
422 | XmlRpcResponse response = new XmlRpcResponse(); | ||
423 | response.Value = hash; | ||
424 | return response; | ||
425 | |||
426 | } | ||
427 | |||
428 | /// <summary> | ||
429 | /// Returns the UUI of a user given a UUID. | ||
430 | /// </summary> | ||
431 | /// <param name="request"></param> | ||
432 | /// <param name="remoteClient"></param> | ||
433 | /// <returns></returns> | ||
434 | public XmlRpcResponse GetUUI(XmlRpcRequest request, IPEndPoint remoteClient) | ||
435 | { | ||
436 | Hashtable hash = new Hashtable(); | ||
437 | |||
438 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
439 | //string host = (string)requestData["host"]; | ||
440 | //string portstr = (string)requestData["port"]; | ||
441 | if (requestData.ContainsKey("userID") && requestData.ContainsKey("targetUserID")) | ||
442 | { | ||
443 | string userID_str = (string)requestData["userID"]; | ||
444 | UUID userID = UUID.Zero; | ||
445 | UUID.TryParse(userID_str, out userID); | ||
446 | |||
447 | string tuserID_str = (string)requestData["targetUserID"]; | ||
448 | UUID targetUserID = UUID.Zero; | ||
449 | UUID.TryParse(tuserID_str, out targetUserID); | ||
450 | string uui = m_HomeUsersService.GetUUI(userID, targetUserID); | ||
451 | if (uui != string.Empty) | ||
452 | hash["UUI"] = uui; | ||
453 | else | ||
454 | hash["result"] = "User unknown"; | ||
455 | } | ||
456 | |||
457 | XmlRpcResponse response = new XmlRpcResponse(); | ||
458 | response.Value = hash; | ||
459 | return response; | ||
460 | } | ||
461 | |||
462 | /// <summary> | ||
463 | /// Gets the UUID of a user given First name, Last name. | ||
464 | /// </summary> | ||
465 | /// <param name="request"></param> | ||
466 | /// <param name="remoteClient"></param> | ||
467 | /// <returns></returns> | ||
468 | public XmlRpcResponse GetUUID(XmlRpcRequest request, IPEndPoint remoteClient) | ||
469 | { | ||
470 | Hashtable hash = new Hashtable(); | ||
471 | |||
472 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
473 | //string host = (string)requestData["host"]; | ||
474 | //string portstr = (string)requestData["port"]; | ||
475 | if (requestData.ContainsKey("first") && requestData.ContainsKey("last")) | ||
476 | { | ||
477 | string first = (string)requestData["first"]; | ||
478 | string last = (string)requestData["last"]; | ||
479 | UUID uuid = m_HomeUsersService.GetUUID(first, last); | ||
480 | hash["UUID"] = uuid.ToString(); | ||
481 | } | ||
482 | |||
483 | XmlRpcResponse response = new XmlRpcResponse(); | ||
484 | response.Value = hash; | ||
485 | return response; | ||
486 | } | ||
487 | } | ||
488 | } \ No newline at end of file | ||
diff --git a/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs new file mode 100644 index 0000000..b295446 --- /dev/null +++ b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs | |||
@@ -0,0 +1,330 @@ | |||
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; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using Nwc.XmlRpc; | ||
36 | using OpenSim.Server.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenSim.Server.Handlers.Base; | ||
41 | using OpenMetaverse; | ||
42 | |||
43 | namespace OpenSim.Server.Handlers.Inventory | ||
44 | { | ||
45 | public class InventoryServiceInConnector : ServiceConnector | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | protected IInventoryService m_InventoryService; | ||
50 | |||
51 | private bool m_doLookup = false; | ||
52 | |||
53 | //private static readonly int INVENTORY_DEFAULT_SESSION_TIME = 30; // secs | ||
54 | //private AuthedSessionCache m_session_cache = new AuthedSessionCache(INVENTORY_DEFAULT_SESSION_TIME); | ||
55 | |||
56 | private string m_userserver_url; | ||
57 | protected string m_ConfigName = "InventoryService"; | ||
58 | |||
59 | public InventoryServiceInConnector(IConfigSource config, IHttpServer server, string configName) : | ||
60 | base(config, server, configName) | ||
61 | { | ||
62 | if (configName != string.Empty) | ||
63 | m_ConfigName = configName; | ||
64 | |||
65 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
66 | if (serverConfig == null) | ||
67 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
68 | |||
69 | string inventoryService = serverConfig.GetString("LocalServiceModule", | ||
70 | String.Empty); | ||
71 | |||
72 | if (inventoryService == String.Empty) | ||
73 | throw new Exception("No LocalServiceModule in config file"); | ||
74 | |||
75 | Object[] args = new Object[] { config }; | ||
76 | m_InventoryService = | ||
77 | ServerUtils.LoadPlugin<IInventoryService>(inventoryService, args); | ||
78 | |||
79 | m_userserver_url = serverConfig.GetString("UserServerURI", String.Empty); | ||
80 | m_doLookup = serverConfig.GetBoolean("SessionAuthentication", false); | ||
81 | |||
82 | AddHttpHandlers(server); | ||
83 | m_log.Debug("[INVENTORY HANDLER]: handlers initialized"); | ||
84 | } | ||
85 | |||
86 | protected virtual void AddHttpHandlers(IHttpServer m_httpServer) | ||
87 | { | ||
88 | m_httpServer.AddStreamHandler( | ||
89 | new RestDeserialiseSecureHandler<Guid, List<InventoryFolderBase>>( | ||
90 | "POST", "/SystemFolders/", GetSystemFolders, CheckAuthSession)); | ||
91 | |||
92 | m_httpServer.AddStreamHandler( | ||
93 | new RestDeserialiseSecureHandler<Guid, InventoryCollection>( | ||
94 | "POST", "/GetFolderContent/", GetFolderContent, CheckAuthSession)); | ||
95 | |||
96 | m_httpServer.AddStreamHandler( | ||
97 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( | ||
98 | "POST", "/UpdateFolder/", m_InventoryService.UpdateFolder, CheckAuthSession)); | ||
99 | |||
100 | m_httpServer.AddStreamHandler( | ||
101 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( | ||
102 | "POST", "/MoveFolder/", m_InventoryService.MoveFolder, CheckAuthSession)); | ||
103 | |||
104 | m_httpServer.AddStreamHandler( | ||
105 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( | ||
106 | "POST", "/PurgeFolder/", m_InventoryService.PurgeFolder, CheckAuthSession)); | ||
107 | |||
108 | m_httpServer.AddStreamHandler( | ||
109 | new RestDeserialiseSecureHandler<List<Guid>, bool>( | ||
110 | "POST", "/DeleteFolders/", DeleteFolders, CheckAuthSession)); | ||
111 | |||
112 | m_httpServer.AddStreamHandler( | ||
113 | new RestDeserialiseSecureHandler<List<Guid>, bool>( | ||
114 | "POST", "/DeleteItem/", DeleteItems, CheckAuthSession)); | ||
115 | |||
116 | m_httpServer.AddStreamHandler( | ||
117 | new RestDeserialiseSecureHandler<InventoryItemBase, InventoryItemBase>( | ||
118 | "POST", "/QueryItem/", m_InventoryService.GetItem, CheckAuthSession)); | ||
119 | |||
120 | m_httpServer.AddStreamHandler( | ||
121 | new RestDeserialiseSecureHandler<InventoryFolderBase, InventoryFolderBase>( | ||
122 | "POST", "/QueryFolder/", m_InventoryService.GetFolder, CheckAuthSession)); | ||
123 | |||
124 | m_httpServer.AddStreamHandler( | ||
125 | new RestDeserialiseTrustedHandler<Guid, bool>( | ||
126 | "POST", "/CreateInventory/", CreateUsersInventory, CheckTrustSource)); | ||
127 | |||
128 | m_httpServer.AddStreamHandler( | ||
129 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( | ||
130 | "POST", "/NewFolder/", m_InventoryService.AddFolder, CheckAuthSession)); | ||
131 | |||
132 | m_httpServer.AddStreamHandler( | ||
133 | new RestDeserialiseSecureHandler<InventoryFolderBase, bool>( | ||
134 | "POST", "/CreateFolder/", m_InventoryService.AddFolder, CheckAuthSession)); | ||
135 | |||
136 | m_httpServer.AddStreamHandler( | ||
137 | new RestDeserialiseSecureHandler<InventoryItemBase, bool>( | ||
138 | "POST", "/NewItem/", m_InventoryService.AddItem, CheckAuthSession)); | ||
139 | |||
140 | m_httpServer.AddStreamHandler( | ||
141 | new RestDeserialiseTrustedHandler<InventoryItemBase, bool>( | ||
142 | "POST", "/AddNewItem/", m_InventoryService.AddItem, CheckTrustSource)); | ||
143 | |||
144 | m_httpServer.AddStreamHandler( | ||
145 | new RestDeserialiseSecureHandler<Guid, List<InventoryItemBase>>( | ||
146 | "POST", "/GetItems/", GetFolderItems, CheckAuthSession)); | ||
147 | |||
148 | m_httpServer.AddStreamHandler( | ||
149 | new RestDeserialiseSecureHandler<List<InventoryItemBase>, bool>( | ||
150 | "POST", "/MoveItems/", MoveItems, CheckAuthSession)); | ||
151 | |||
152 | m_httpServer.AddStreamHandler(new InventoryServerMoveItemsHandler(m_InventoryService)); | ||
153 | |||
154 | |||
155 | // for persistent active gestures | ||
156 | m_httpServer.AddStreamHandler( | ||
157 | new RestDeserialiseTrustedHandler<Guid, List<InventoryItemBase>> | ||
158 | ("POST", "/ActiveGestures/", GetActiveGestures, CheckTrustSource)); | ||
159 | |||
160 | // WARNING: Root folders no longer just delivers the root and immediate child folders (e.g | ||
161 | // system folders such as Objects, Textures), but it now returns the entire inventory skeleton. | ||
162 | // It would have been better to rename this request, but complexities in the BaseHttpServer | ||
163 | // (e.g. any http request not found is automatically treated as an xmlrpc request) make it easier | ||
164 | // to do this for now. | ||
165 | m_httpServer.AddStreamHandler( | ||
166 | new RestDeserialiseTrustedHandler<Guid, List<InventoryFolderBase>> | ||
167 | ("POST", "/RootFolders/", GetInventorySkeleton, CheckTrustSource)); | ||
168 | |||
169 | m_httpServer.AddStreamHandler( | ||
170 | new RestDeserialiseTrustedHandler<InventoryItemBase, int> | ||
171 | ("POST", "/AssetPermissions/", GetAssetPermissions, CheckTrustSource)); | ||
172 | |||
173 | } | ||
174 | |||
175 | #region Wrappers for converting the Guid parameter | ||
176 | |||
177 | public List<InventoryFolderBase> GetSystemFolders(Guid guid) | ||
178 | { | ||
179 | UUID userID = new UUID(guid); | ||
180 | return new List<InventoryFolderBase>(GetSystemFolders(userID).Values); | ||
181 | } | ||
182 | |||
183 | // This shouldn't be here, it should be in the inventory service. | ||
184 | // But I don't want to deal with types and dependencies for now. | ||
185 | private Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID) | ||
186 | { | ||
187 | InventoryFolderBase root = m_InventoryService.GetRootFolder(userID); | ||
188 | if (root != null) | ||
189 | { | ||
190 | InventoryCollection content = m_InventoryService.GetFolderContent(userID, root.ID); | ||
191 | if (content != null) | ||
192 | { | ||
193 | Dictionary<AssetType, InventoryFolderBase> folders = new Dictionary<AssetType, InventoryFolderBase>(); | ||
194 | foreach (InventoryFolderBase folder in content.Folders) | ||
195 | { | ||
196 | if ((folder.Type != (short)AssetType.Folder) && (folder.Type != (short)AssetType.Unknown)) | ||
197 | folders[(AssetType)folder.Type] = folder; | ||
198 | } | ||
199 | // Put the root folder there, as type Folder | ||
200 | folders[AssetType.Folder] = root; | ||
201 | return folders; | ||
202 | } | ||
203 | } | ||
204 | m_log.WarnFormat("[INVENTORY SERVICE]: System folders for {0} not found", userID); | ||
205 | return new Dictionary<AssetType, InventoryFolderBase>(); | ||
206 | } | ||
207 | |||
208 | public InventoryCollection GetFolderContent(Guid guid) | ||
209 | { | ||
210 | return m_InventoryService.GetFolderContent(UUID.Zero, new UUID(guid)); | ||
211 | } | ||
212 | |||
213 | public List<InventoryItemBase> GetFolderItems(Guid folderID) | ||
214 | { | ||
215 | List<InventoryItemBase> allItems = new List<InventoryItemBase>(); | ||
216 | |||
217 | // TODO: UUID.Zero is passed as the userID here, making the old assumption that the OpenSim | ||
218 | // inventory server only has a single inventory database and not per-user inventory databases. | ||
219 | // This could be changed but it requirs a bit of hackery to pass another parameter into this | ||
220 | // callback | ||
221 | List<InventoryItemBase> items = m_InventoryService.GetFolderItems(UUID.Zero, new UUID(folderID)); | ||
222 | |||
223 | if (items != null) | ||
224 | { | ||
225 | allItems.InsertRange(0, items); | ||
226 | } | ||
227 | return allItems; | ||
228 | } | ||
229 | |||
230 | public bool CreateUsersInventory(Guid rawUserID) | ||
231 | { | ||
232 | UUID userID = new UUID(rawUserID); | ||
233 | |||
234 | |||
235 | return m_InventoryService.CreateUserInventory(userID); | ||
236 | } | ||
237 | |||
238 | public List<InventoryItemBase> GetActiveGestures(Guid rawUserID) | ||
239 | { | ||
240 | UUID userID = new UUID(rawUserID); | ||
241 | |||
242 | return m_InventoryService.GetActiveGestures(userID); | ||
243 | } | ||
244 | |||
245 | public List<InventoryFolderBase> GetInventorySkeleton(Guid rawUserID) | ||
246 | { | ||
247 | UUID userID = new UUID(rawUserID); | ||
248 | return m_InventoryService.GetInventorySkeleton(userID); | ||
249 | } | ||
250 | |||
251 | public int GetAssetPermissions(InventoryItemBase item) | ||
252 | { | ||
253 | return m_InventoryService.GetAssetPermissions(item.Owner, item.AssetID); | ||
254 | } | ||
255 | |||
256 | public bool DeleteFolders(List<Guid> items) | ||
257 | { | ||
258 | List<UUID> uuids = new List<UUID>(); | ||
259 | foreach (Guid g in items) | ||
260 | uuids.Add(new UUID(g)); | ||
261 | // oops we lost the user info here. Bad bad handlers | ||
262 | return m_InventoryService.DeleteFolders(UUID.Zero, uuids); | ||
263 | } | ||
264 | |||
265 | public bool DeleteItems(List<Guid> items) | ||
266 | { | ||
267 | List<UUID> uuids = new List<UUID>(); | ||
268 | foreach (Guid g in items) | ||
269 | uuids.Add(new UUID(g)); | ||
270 | // oops we lost the user info here. Bad bad handlers | ||
271 | return m_InventoryService.DeleteItems(UUID.Zero, uuids); | ||
272 | } | ||
273 | |||
274 | public bool MoveItems(List<InventoryItemBase> items) | ||
275 | { | ||
276 | // oops we lost the user info here. Bad bad handlers | ||
277 | // let's peek at one item | ||
278 | UUID ownerID = UUID.Zero; | ||
279 | if (items.Count > 0) | ||
280 | ownerID = items[0].Owner; | ||
281 | return m_InventoryService.MoveItems(ownerID, items); | ||
282 | } | ||
283 | #endregion | ||
284 | |||
285 | /// <summary> | ||
286 | /// Check that the source of an inventory request is one that we trust. | ||
287 | /// </summary> | ||
288 | /// <param name="peer"></param> | ||
289 | /// <returns></returns> | ||
290 | public bool CheckTrustSource(IPEndPoint peer) | ||
291 | { | ||
292 | if (m_doLookup) | ||
293 | { | ||
294 | m_log.InfoFormat("[INVENTORY IN CONNECTOR]: Checking trusted source {0}", peer); | ||
295 | UriBuilder ub = new UriBuilder(m_userserver_url); | ||
296 | IPAddress[] uaddrs = Dns.GetHostAddresses(ub.Host); | ||
297 | foreach (IPAddress uaddr in uaddrs) | ||
298 | { | ||
299 | if (uaddr.Equals(peer.Address)) | ||
300 | { | ||
301 | return true; | ||
302 | } | ||
303 | } | ||
304 | |||
305 | m_log.WarnFormat( | ||
306 | "[INVENTORY IN CONNECTOR]: Rejecting request since source {0} was not in the list of trusted sources", | ||
307 | peer); | ||
308 | |||
309 | return false; | ||
310 | } | ||
311 | else | ||
312 | { | ||
313 | return true; | ||
314 | } | ||
315 | } | ||
316 | |||
317 | /// <summary> | ||
318 | /// Check that the source of an inventory request for a particular agent is a current session belonging to | ||
319 | /// that agent. | ||
320 | /// </summary> | ||
321 | /// <param name="session_id"></param> | ||
322 | /// <param name="avatar_id"></param> | ||
323 | /// <returns></returns> | ||
324 | public virtual bool CheckAuthSession(string session_id, string avatar_id) | ||
325 | { | ||
326 | return true; | ||
327 | } | ||
328 | |||
329 | } | ||
330 | } | ||
diff --git a/OpenSim/Server/Handlers/Inventory/InventoryServerMoveItemsHandler.cs b/OpenSim/Server/Handlers/Inventory/InventoryServerMoveItemsHandler.cs new file mode 100644 index 0000000..e2c50fe --- /dev/null +++ b/OpenSim/Server/Handlers/Inventory/InventoryServerMoveItemsHandler.cs | |||
@@ -0,0 +1,81 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Reflection; | ||
33 | using System.IO; | ||
34 | using System.Net; | ||
35 | using System.Text; | ||
36 | using System.Text.RegularExpressions; | ||
37 | using System.Xml; | ||
38 | using System.Xml.Serialization; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Framework; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | using OpenMetaverse; | ||
44 | |||
45 | namespace OpenSim.Server.Handlers.Inventory | ||
46 | { | ||
47 | public class InventoryServerMoveItemsHandler : BaseStreamHandler | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private IInventoryService m_InventoryService; | ||
52 | |||
53 | public InventoryServerMoveItemsHandler(IInventoryService service) : | ||
54 | base("PUT", "/inventory") | ||
55 | { | ||
56 | m_InventoryService = service; | ||
57 | } | ||
58 | |||
59 | protected override byte[] ProcessRequest(string path, Stream request, | ||
60 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
61 | { | ||
62 | XmlSerializer xs = new XmlSerializer(typeof (List<InventoryItemBase>)); | ||
63 | List<InventoryItemBase> items = (List<InventoryItemBase>)xs.Deserialize(request); | ||
64 | |||
65 | bool result = false; | ||
66 | string[] p = SplitParams(path); | ||
67 | |||
68 | if (p.Length > 0) | ||
69 | { | ||
70 | UUID ownerID = UUID.Zero; | ||
71 | UUID.TryParse(p[0], out ownerID); | ||
72 | result = m_InventoryService.MoveItems(ownerID, items); | ||
73 | } | ||
74 | else | ||
75 | m_log.WarnFormat("[MOVEITEMS HANDLER]: ownerID not provided in request. Unable to serve."); | ||
76 | |||
77 | xs = new XmlSerializer(typeof(bool)); | ||
78 | return ServerUtils.SerializeResult(xs, result); | ||
79 | } | ||
80 | } | ||
81 | } | ||
diff --git a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs new file mode 100644 index 0000000..5c4e7a9 --- /dev/null +++ b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs | |||
@@ -0,0 +1,767 @@ | |||
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.Framework.ServiceAuth; | ||
37 | using OpenSim.Server.Base; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenSim.Server.Handlers.Base; | ||
41 | using log4net; | ||
42 | using OpenMetaverse; | ||
43 | |||
44 | using System.Threading; | ||
45 | |||
46 | namespace OpenSim.Server.Handlers.Inventory | ||
47 | { | ||
48 | public class XInventoryInConnector : ServiceConnector | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private IInventoryService m_InventoryService; | ||
53 | private string m_ConfigName = "InventoryService"; | ||
54 | |||
55 | public XInventoryInConnector(IConfigSource config, IHttpServer server, string configName) : | ||
56 | base(config, server, configName) | ||
57 | { | ||
58 | if (configName != String.Empty) | ||
59 | m_ConfigName = configName; | ||
60 | |||
61 | m_log.DebugFormat("[XInventoryInConnector]: Starting with config name {0}", m_ConfigName); | ||
62 | |||
63 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
64 | if (serverConfig == null) | ||
65 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
66 | |||
67 | string inventoryService = serverConfig.GetString("LocalServiceModule", | ||
68 | String.Empty); | ||
69 | |||
70 | if (inventoryService == String.Empty) | ||
71 | throw new Exception("No InventoryService in config file"); | ||
72 | |||
73 | Object[] args = new Object[] { config, m_ConfigName }; | ||
74 | m_InventoryService = | ||
75 | ServerUtils.LoadPlugin<IInventoryService>(inventoryService, args); | ||
76 | |||
77 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
78 | |||
79 | server.AddStreamHandler(new XInventoryConnectorPostHandler(m_InventoryService, auth)); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | public class XInventoryConnectorPostHandler : BaseStreamHandler | ||
84 | { | ||
85 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
86 | |||
87 | private IInventoryService m_InventoryService; | ||
88 | |||
89 | public XInventoryConnectorPostHandler(IInventoryService service, IServiceAuth auth) : | ||
90 | base("POST", "/xinventory", auth) | ||
91 | { | ||
92 | m_InventoryService = service; | ||
93 | } | ||
94 | |||
95 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
96 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
97 | { | ||
98 | StreamReader sr = new StreamReader(requestData); | ||
99 | string body = sr.ReadToEnd(); | ||
100 | sr.Close(); | ||
101 | body = body.Trim(); | ||
102 | |||
103 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
104 | |||
105 | try | ||
106 | { | ||
107 | Dictionary<string, object> request = | ||
108 | ServerUtils.ParseQueryString(body); | ||
109 | |||
110 | if (!request.ContainsKey("METHOD")) | ||
111 | return FailureResult(); | ||
112 | |||
113 | string method = request["METHOD"].ToString(); | ||
114 | request.Remove("METHOD"); | ||
115 | |||
116 | switch (method) | ||
117 | { | ||
118 | case "CREATEUSERINVENTORY": | ||
119 | return HandleCreateUserInventory(request); | ||
120 | case "GETINVENTORYSKELETON": | ||
121 | return HandleGetInventorySkeleton(request); | ||
122 | case "GETROOTFOLDER": | ||
123 | return HandleGetRootFolder(request); | ||
124 | case "GETFOLDERFORTYPE": | ||
125 | return HandleGetFolderForType(request); | ||
126 | case "GETFOLDERCONTENT": | ||
127 | return HandleGetFolderContent(request); | ||
128 | case "GETMULTIPLEFOLDERSCONTENT": | ||
129 | return HandleGetMultipleFoldersContent(request); | ||
130 | case "GETFOLDERITEMS": | ||
131 | return HandleGetFolderItems(request); | ||
132 | case "ADDFOLDER": | ||
133 | return HandleAddFolder(request); | ||
134 | case "UPDATEFOLDER": | ||
135 | return HandleUpdateFolder(request); | ||
136 | case "MOVEFOLDER": | ||
137 | return HandleMoveFolder(request); | ||
138 | case "DELETEFOLDERS": | ||
139 | return HandleDeleteFolders(request); | ||
140 | case "PURGEFOLDER": | ||
141 | return HandlePurgeFolder(request); | ||
142 | case "ADDITEM": | ||
143 | return HandleAddItem(request); | ||
144 | case "UPDATEITEM": | ||
145 | return HandleUpdateItem(request); | ||
146 | case "MOVEITEMS": | ||
147 | return HandleMoveItems(request); | ||
148 | case "DELETEITEMS": | ||
149 | return HandleDeleteItems(request); | ||
150 | case "GETITEM": | ||
151 | return HandleGetItem(request); | ||
152 | case "GETMULTIPLEITEMS": | ||
153 | return HandleGetMultipleItems(request); | ||
154 | case "GETFOLDER": | ||
155 | return HandleGetFolder(request); | ||
156 | case "GETACTIVEGESTURES": | ||
157 | return HandleGetActiveGestures(request); | ||
158 | case "GETASSETPERMISSIONS": | ||
159 | return HandleGetAssetPermissions(request); | ||
160 | } | ||
161 | m_log.DebugFormat("[XINVENTORY HANDLER]: unknown method request: {0}", method); | ||
162 | } | ||
163 | catch (Exception e) | ||
164 | { | ||
165 | m_log.Error(string.Format("[XINVENTORY HANDLER]: Exception {0} ", e.Message), e); | ||
166 | } | ||
167 | |||
168 | return FailureResult(); | ||
169 | } | ||
170 | |||
171 | private byte[] FailureResult() | ||
172 | { | ||
173 | return BoolResult(false); | ||
174 | } | ||
175 | |||
176 | private byte[] SuccessResult() | ||
177 | { | ||
178 | return BoolResult(true); | ||
179 | } | ||
180 | |||
181 | private byte[] BoolResult(bool value) | ||
182 | { | ||
183 | XmlDocument doc = new XmlDocument(); | ||
184 | |||
185 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
186 | "", ""); | ||
187 | |||
188 | doc.AppendChild(xmlnode); | ||
189 | |||
190 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
191 | ""); | ||
192 | |||
193 | doc.AppendChild(rootElement); | ||
194 | |||
195 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
196 | result.AppendChild(doc.CreateTextNode(value.ToString())); | ||
197 | |||
198 | rootElement.AppendChild(result); | ||
199 | |||
200 | return Util.DocToBytes(doc); | ||
201 | } | ||
202 | |||
203 | byte[] HandleCreateUserInventory(Dictionary<string,object> request) | ||
204 | { | ||
205 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
206 | |||
207 | if (!request.ContainsKey("PRINCIPAL")) | ||
208 | return FailureResult(); | ||
209 | |||
210 | if (m_InventoryService.CreateUserInventory(new UUID(request["PRINCIPAL"].ToString()))) | ||
211 | result["RESULT"] = "True"; | ||
212 | else | ||
213 | result["RESULT"] = "False"; | ||
214 | |||
215 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
216 | |||
217 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
218 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
219 | } | ||
220 | |||
221 | byte[] HandleGetInventorySkeleton(Dictionary<string,object> request) | ||
222 | { | ||
223 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
224 | |||
225 | if (!request.ContainsKey("PRINCIPAL")) | ||
226 | return FailureResult(); | ||
227 | |||
228 | |||
229 | List<InventoryFolderBase> folders = m_InventoryService.GetInventorySkeleton(new UUID(request["PRINCIPAL"].ToString())); | ||
230 | |||
231 | Dictionary<string, object> sfolders = new Dictionary<string, object>(); | ||
232 | if (folders != null) | ||
233 | { | ||
234 | int i = 0; | ||
235 | foreach (InventoryFolderBase f in folders) | ||
236 | { | ||
237 | sfolders["folder_" + i.ToString()] = EncodeFolder(f); | ||
238 | i++; | ||
239 | } | ||
240 | } | ||
241 | result["FOLDERS"] = sfolders; | ||
242 | |||
243 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
244 | |||
245 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
246 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
247 | } | ||
248 | |||
249 | byte[] HandleGetRootFolder(Dictionary<string,object> request) | ||
250 | { | ||
251 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
252 | |||
253 | UUID principal = UUID.Zero; | ||
254 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
255 | InventoryFolderBase rfolder = m_InventoryService.GetRootFolder(principal); | ||
256 | if (rfolder != null) | ||
257 | result["folder"] = EncodeFolder(rfolder); | ||
258 | |||
259 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
260 | |||
261 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
262 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
263 | } | ||
264 | |||
265 | byte[] HandleGetFolderForType(Dictionary<string,object> request) | ||
266 | { | ||
267 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
268 | UUID principal = UUID.Zero; | ||
269 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
270 | int type = 0; | ||
271 | Int32.TryParse(request["TYPE"].ToString(), out type); | ||
272 | InventoryFolderBase folder = m_InventoryService.GetFolderForType(principal, (FolderType)type); | ||
273 | if (folder != null) | ||
274 | result["folder"] = EncodeFolder(folder); | ||
275 | |||
276 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
277 | |||
278 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
279 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
280 | } | ||
281 | |||
282 | byte[] HandleGetFolderContent(Dictionary<string,object> request) | ||
283 | { | ||
284 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
285 | UUID principal = UUID.Zero; | ||
286 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
287 | UUID folderID = UUID.Zero; | ||
288 | UUID.TryParse(request["FOLDER"].ToString(), out folderID); | ||
289 | |||
290 | InventoryCollection icoll = m_InventoryService.GetFolderContent(principal, folderID); | ||
291 | if (icoll != null) | ||
292 | { | ||
293 | result["FID"] = icoll.FolderID.ToString(); | ||
294 | result["VERSION"] = icoll.Version.ToString(); | ||
295 | Dictionary<string, object> folders = new Dictionary<string, object>(); | ||
296 | int i = 0; | ||
297 | if (icoll.Folders != null) | ||
298 | { | ||
299 | foreach (InventoryFolderBase f in icoll.Folders) | ||
300 | { | ||
301 | folders["folder_" + i.ToString()] = EncodeFolder(f); | ||
302 | i++; | ||
303 | } | ||
304 | result["FOLDERS"] = folders; | ||
305 | } | ||
306 | if (icoll.Items != null) | ||
307 | { | ||
308 | i = 0; | ||
309 | Dictionary<string, object> items = new Dictionary<string, object>(); | ||
310 | foreach (InventoryItemBase it in icoll.Items) | ||
311 | { | ||
312 | items["item_" + i.ToString()] = EncodeItem(it); | ||
313 | i++; | ||
314 | } | ||
315 | result["ITEMS"] = items; | ||
316 | } | ||
317 | } | ||
318 | |||
319 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
320 | |||
321 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
322 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
323 | } | ||
324 | |||
325 | byte[] HandleGetMultipleFoldersContent(Dictionary<string, object> request) | ||
326 | { | ||
327 | Dictionary<string, object> resultSet = new Dictionary<string, object>(); | ||
328 | UUID principal = UUID.Zero; | ||
329 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
330 | string folderIDstr = request["FOLDERS"].ToString(); | ||
331 | int count = 0; | ||
332 | Int32.TryParse(request["COUNT"].ToString(), out count); | ||
333 | |||
334 | UUID[] fids = new UUID[count]; | ||
335 | string[] uuids = folderIDstr.Split(','); | ||
336 | int i = 0; | ||
337 | foreach (string id in uuids) | ||
338 | { | ||
339 | UUID fid = UUID.Zero; | ||
340 | if (UUID.TryParse(id, out fid)) | ||
341 | fids[i] = fid; | ||
342 | i += 1; | ||
343 | } | ||
344 | |||
345 | count = 0; | ||
346 | InventoryCollection[] icollList = m_InventoryService.GetMultipleFoldersContent(principal, fids); | ||
347 | if (icollList != null && icollList.Length > 0) | ||
348 | { | ||
349 | foreach (InventoryCollection icoll in icollList) | ||
350 | { | ||
351 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
352 | result["FID"] = icoll.FolderID.ToString(); | ||
353 | result["VERSION"] = icoll.Version.ToString(); | ||
354 | result["OWNER"] = icoll.OwnerID.ToString(); | ||
355 | Dictionary<string, object> folders = new Dictionary<string, object>(); | ||
356 | i = 0; | ||
357 | if (icoll.Folders != null) | ||
358 | { | ||
359 | foreach (InventoryFolderBase f in icoll.Folders) | ||
360 | { | ||
361 | folders["folder_" + i.ToString()] = EncodeFolder(f); | ||
362 | i++; | ||
363 | } | ||
364 | result["FOLDERS"] = folders; | ||
365 | } | ||
366 | i = 0; | ||
367 | if (icoll.Items != null) | ||
368 | { | ||
369 | Dictionary<string, object> items = new Dictionary<string, object>(); | ||
370 | foreach (InventoryItemBase it in icoll.Items) | ||
371 | { | ||
372 | items["item_" + i.ToString()] = EncodeItem(it); | ||
373 | i++; | ||
374 | } | ||
375 | result["ITEMS"] = items; | ||
376 | } | ||
377 | |||
378 | resultSet["F_" + fids[count++]] = result; | ||
379 | //m_log.DebugFormat("[XXX]: Sending {0} {1}", fids[count-1], icoll.FolderID); | ||
380 | } | ||
381 | } | ||
382 | |||
383 | string xmlString = ServerUtils.BuildXmlResponse(resultSet); | ||
384 | |||
385 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
386 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
387 | } | ||
388 | |||
389 | byte[] HandleGetFolderItems(Dictionary<string, object> request) | ||
390 | { | ||
391 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
392 | UUID principal = UUID.Zero; | ||
393 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
394 | UUID folderID = UUID.Zero; | ||
395 | UUID.TryParse(request["FOLDER"].ToString(), out folderID); | ||
396 | |||
397 | List<InventoryItemBase> items = m_InventoryService.GetFolderItems(principal, folderID); | ||
398 | Dictionary<string, object> sitems = new Dictionary<string, object>(); | ||
399 | |||
400 | if (items != null) | ||
401 | { | ||
402 | int i = 0; | ||
403 | foreach (InventoryItemBase item in items) | ||
404 | { | ||
405 | sitems["item_" + i.ToString()] = EncodeItem(item); | ||
406 | i++; | ||
407 | } | ||
408 | } | ||
409 | result["ITEMS"] = sitems; | ||
410 | |||
411 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
412 | |||
413 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
414 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
415 | } | ||
416 | |||
417 | byte[] HandleAddFolder(Dictionary<string,object> request) | ||
418 | { | ||
419 | InventoryFolderBase folder = BuildFolder(request); | ||
420 | |||
421 | if (m_InventoryService.AddFolder(folder)) | ||
422 | return SuccessResult(); | ||
423 | else | ||
424 | return FailureResult(); | ||
425 | } | ||
426 | |||
427 | byte[] HandleUpdateFolder(Dictionary<string,object> request) | ||
428 | { | ||
429 | InventoryFolderBase folder = BuildFolder(request); | ||
430 | |||
431 | if (m_InventoryService.UpdateFolder(folder)) | ||
432 | return SuccessResult(); | ||
433 | else | ||
434 | return FailureResult(); | ||
435 | } | ||
436 | |||
437 | byte[] HandleMoveFolder(Dictionary<string,object> request) | ||
438 | { | ||
439 | UUID parentID = UUID.Zero; | ||
440 | UUID.TryParse(request["ParentID"].ToString(), out parentID); | ||
441 | UUID folderID = UUID.Zero; | ||
442 | UUID.TryParse(request["ID"].ToString(), out folderID); | ||
443 | UUID principal = UUID.Zero; | ||
444 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
445 | |||
446 | InventoryFolderBase folder = new InventoryFolderBase(folderID, "", principal, parentID); | ||
447 | if (m_InventoryService.MoveFolder(folder)) | ||
448 | return SuccessResult(); | ||
449 | else | ||
450 | return FailureResult(); | ||
451 | |||
452 | } | ||
453 | |||
454 | byte[] HandleDeleteFolders(Dictionary<string,object> request) | ||
455 | { | ||
456 | UUID principal = UUID.Zero; | ||
457 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
458 | List<string> slist = (List<string>)request["FOLDERS"]; | ||
459 | List<UUID> uuids = new List<UUID>(); | ||
460 | foreach (string s in slist) | ||
461 | { | ||
462 | UUID u = UUID.Zero; | ||
463 | if (UUID.TryParse(s, out u)) | ||
464 | uuids.Add(u); | ||
465 | } | ||
466 | |||
467 | if (m_InventoryService.DeleteFolders(principal, uuids)) | ||
468 | return SuccessResult(); | ||
469 | else | ||
470 | return | ||
471 | FailureResult(); | ||
472 | } | ||
473 | |||
474 | byte[] HandlePurgeFolder(Dictionary<string,object> request) | ||
475 | { | ||
476 | UUID folderID = UUID.Zero; | ||
477 | UUID.TryParse(request["ID"].ToString(), out folderID); | ||
478 | |||
479 | InventoryFolderBase folder = new InventoryFolderBase(folderID); | ||
480 | if (m_InventoryService.PurgeFolder(folder)) | ||
481 | return SuccessResult(); | ||
482 | else | ||
483 | return FailureResult(); | ||
484 | } | ||
485 | |||
486 | byte[] HandleAddItem(Dictionary<string,object> request) | ||
487 | { | ||
488 | InventoryItemBase item = BuildItem(request); | ||
489 | |||
490 | if (m_InventoryService.AddItem(item)) | ||
491 | return SuccessResult(); | ||
492 | else | ||
493 | return FailureResult(); | ||
494 | } | ||
495 | |||
496 | byte[] HandleUpdateItem(Dictionary<string,object> request) | ||
497 | { | ||
498 | InventoryItemBase item = BuildItem(request); | ||
499 | |||
500 | if (m_InventoryService.UpdateItem(item)) | ||
501 | return SuccessResult(); | ||
502 | else | ||
503 | return FailureResult(); | ||
504 | } | ||
505 | |||
506 | byte[] HandleMoveItems(Dictionary<string,object> request) | ||
507 | { | ||
508 | List<string> idlist = (List<string>)request["IDLIST"]; | ||
509 | List<string> destlist = (List<string>)request["DESTLIST"]; | ||
510 | UUID principal = UUID.Zero; | ||
511 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
512 | |||
513 | List<InventoryItemBase> items = new List<InventoryItemBase>(); | ||
514 | int n = 0; | ||
515 | try | ||
516 | { | ||
517 | foreach (string s in idlist) | ||
518 | { | ||
519 | UUID u = UUID.Zero; | ||
520 | if (UUID.TryParse(s, out u)) | ||
521 | { | ||
522 | UUID fid = UUID.Zero; | ||
523 | if (UUID.TryParse(destlist[n++], out fid)) | ||
524 | { | ||
525 | InventoryItemBase item = new InventoryItemBase(u, principal); | ||
526 | item.Folder = fid; | ||
527 | items.Add(item); | ||
528 | } | ||
529 | } | ||
530 | } | ||
531 | } | ||
532 | catch (Exception e) | ||
533 | { | ||
534 | m_log.DebugFormat("[XINVENTORY IN CONNECTOR]: Exception in HandleMoveItems: {0}", e.Message); | ||
535 | return FailureResult(); | ||
536 | } | ||
537 | |||
538 | if (m_InventoryService.MoveItems(principal, items)) | ||
539 | return SuccessResult(); | ||
540 | else | ||
541 | return FailureResult(); | ||
542 | } | ||
543 | |||
544 | byte[] HandleDeleteItems(Dictionary<string,object> request) | ||
545 | { | ||
546 | UUID principal = UUID.Zero; | ||
547 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
548 | List<string> slist = (List<string>)request["ITEMS"]; | ||
549 | List<UUID> uuids = new List<UUID>(); | ||
550 | foreach (string s in slist) | ||
551 | { | ||
552 | UUID u = UUID.Zero; | ||
553 | if (UUID.TryParse(s, out u)) | ||
554 | uuids.Add(u); | ||
555 | } | ||
556 | |||
557 | if (m_InventoryService.DeleteItems(principal, uuids)) | ||
558 | return SuccessResult(); | ||
559 | else | ||
560 | return | ||
561 | FailureResult(); | ||
562 | } | ||
563 | |||
564 | byte[] HandleGetItem(Dictionary<string,object> request) | ||
565 | { | ||
566 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
567 | UUID id = UUID.Zero; | ||
568 | UUID.TryParse(request["ID"].ToString(), out id); | ||
569 | |||
570 | InventoryItemBase item = new InventoryItemBase(id); | ||
571 | item = m_InventoryService.GetItem(item); | ||
572 | if (item != null) | ||
573 | result["item"] = EncodeItem(item); | ||
574 | |||
575 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
576 | |||
577 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
578 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
579 | } | ||
580 | |||
581 | byte[] HandleGetMultipleItems(Dictionary<string, object> request) | ||
582 | { | ||
583 | Dictionary<string, object> resultSet = new Dictionary<string, object>(); | ||
584 | UUID principal = UUID.Zero; | ||
585 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
586 | string itemIDstr = request["ITEMS"].ToString(); | ||
587 | int count = 0; | ||
588 | Int32.TryParse(request["COUNT"].ToString(), out count); | ||
589 | |||
590 | UUID[] fids = new UUID[count]; | ||
591 | string[] uuids = itemIDstr.Split(','); | ||
592 | int i = 0; | ||
593 | foreach (string id in uuids) | ||
594 | { | ||
595 | UUID fid = UUID.Zero; | ||
596 | if (UUID.TryParse(id, out fid)) | ||
597 | fids[i] = fid; | ||
598 | i += 1; | ||
599 | } | ||
600 | |||
601 | InventoryItemBase[] itemsList = m_InventoryService.GetMultipleItems(principal, fids); | ||
602 | if (itemsList != null && itemsList.Length > 0) | ||
603 | { | ||
604 | count = 0; | ||
605 | foreach (InventoryItemBase item in itemsList) | ||
606 | resultSet["item_" + count++] = (item == null) ? (object)"NULL" : EncodeItem(item); | ||
607 | } | ||
608 | |||
609 | string xmlString = ServerUtils.BuildXmlResponse(resultSet); | ||
610 | |||
611 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
612 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
613 | } | ||
614 | |||
615 | byte[] HandleGetFolder(Dictionary<string,object> request) | ||
616 | { | ||
617 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
618 | UUID id = UUID.Zero; | ||
619 | UUID.TryParse(request["ID"].ToString(), out id); | ||
620 | |||
621 | InventoryFolderBase folder = new InventoryFolderBase(id); | ||
622 | folder = m_InventoryService.GetFolder(folder); | ||
623 | if (folder != null) | ||
624 | result["folder"] = EncodeFolder(folder); | ||
625 | |||
626 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
627 | |||
628 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
629 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
630 | } | ||
631 | |||
632 | byte[] HandleGetActiveGestures(Dictionary<string,object> request) | ||
633 | { | ||
634 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
635 | UUID principal = UUID.Zero; | ||
636 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
637 | |||
638 | List<InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(principal); | ||
639 | Dictionary<string, object> items = new Dictionary<string, object>(); | ||
640 | if (gestures != null) | ||
641 | { | ||
642 | int i = 0; | ||
643 | foreach (InventoryItemBase item in gestures) | ||
644 | { | ||
645 | items["item_" + i.ToString()] = EncodeItem(item); | ||
646 | i++; | ||
647 | } | ||
648 | } | ||
649 | result["ITEMS"] = items; | ||
650 | |||
651 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
652 | |||
653 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
654 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
655 | } | ||
656 | |||
657 | byte[] HandleGetAssetPermissions(Dictionary<string,object> request) | ||
658 | { | ||
659 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
660 | UUID principal = UUID.Zero; | ||
661 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
662 | UUID assetID = UUID.Zero; | ||
663 | UUID.TryParse(request["ASSET"].ToString(), out assetID); | ||
664 | |||
665 | int perms = m_InventoryService.GetAssetPermissions(principal, assetID); | ||
666 | |||
667 | result["RESULT"] = perms.ToString(); | ||
668 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
669 | |||
670 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
671 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
672 | } | ||
673 | |||
674 | private Dictionary<string, object> EncodeFolder(InventoryFolderBase f) | ||
675 | { | ||
676 | Dictionary<string, object> ret = new Dictionary<string, object>(); | ||
677 | |||
678 | ret["ParentID"] = f.ParentID.ToString(); | ||
679 | ret["Type"] = f.Type.ToString(); | ||
680 | ret["Version"] = f.Version.ToString(); | ||
681 | ret["Name"] = f.Name; | ||
682 | ret["Owner"] = f.Owner.ToString(); | ||
683 | ret["ID"] = f.ID.ToString(); | ||
684 | |||
685 | return ret; | ||
686 | } | ||
687 | |||
688 | private Dictionary<string, object> EncodeItem(InventoryItemBase item) | ||
689 | { | ||
690 | Dictionary<string, object> ret = new Dictionary<string, object>(); | ||
691 | |||
692 | ret["AssetID"] = item.AssetID.ToString(); | ||
693 | ret["AssetType"] = item.AssetType.ToString(); | ||
694 | ret["BasePermissions"] = item.BasePermissions.ToString(); | ||
695 | ret["CreationDate"] = item.CreationDate.ToString(); | ||
696 | if (item.CreatorId != null) | ||
697 | ret["CreatorId"] = item.CreatorId.ToString(); | ||
698 | else | ||
699 | ret["CreatorId"] = String.Empty; | ||
700 | if (item.CreatorData != null) | ||
701 | ret["CreatorData"] = item.CreatorData; | ||
702 | else | ||
703 | ret["CreatorData"] = String.Empty; | ||
704 | ret["CurrentPermissions"] = item.CurrentPermissions.ToString(); | ||
705 | ret["Description"] = item.Description.ToString(); | ||
706 | ret["EveryOnePermissions"] = item.EveryOnePermissions.ToString(); | ||
707 | ret["Flags"] = item.Flags.ToString(); | ||
708 | ret["Folder"] = item.Folder.ToString(); | ||
709 | ret["GroupID"] = item.GroupID.ToString(); | ||
710 | ret["GroupOwned"] = item.GroupOwned.ToString(); | ||
711 | ret["GroupPermissions"] = item.GroupPermissions.ToString(); | ||
712 | ret["ID"] = item.ID.ToString(); | ||
713 | ret["InvType"] = item.InvType.ToString(); | ||
714 | ret["Name"] = item.Name.ToString(); | ||
715 | ret["NextPermissions"] = item.NextPermissions.ToString(); | ||
716 | ret["Owner"] = item.Owner.ToString(); | ||
717 | ret["SalePrice"] = item.SalePrice.ToString(); | ||
718 | ret["SaleType"] = item.SaleType.ToString(); | ||
719 | |||
720 | return ret; | ||
721 | } | ||
722 | |||
723 | private InventoryFolderBase BuildFolder(Dictionary<string,object> data) | ||
724 | { | ||
725 | InventoryFolderBase folder = new InventoryFolderBase(); | ||
726 | |||
727 | folder.ParentID = new UUID(data["ParentID"].ToString()); | ||
728 | folder.Type = short.Parse(data["Type"].ToString()); | ||
729 | folder.Version = ushort.Parse(data["Version"].ToString()); | ||
730 | folder.Name = data["Name"].ToString(); | ||
731 | folder.Owner = new UUID(data["Owner"].ToString()); | ||
732 | folder.ID = new UUID(data["ID"].ToString()); | ||
733 | |||
734 | return folder; | ||
735 | } | ||
736 | |||
737 | private InventoryItemBase BuildItem(Dictionary<string,object> data) | ||
738 | { | ||
739 | InventoryItemBase item = new InventoryItemBase(); | ||
740 | |||
741 | item.AssetID = new UUID(data["AssetID"].ToString()); | ||
742 | item.AssetType = int.Parse(data["AssetType"].ToString()); | ||
743 | item.Name = data["Name"].ToString(); | ||
744 | item.Owner = new UUID(data["Owner"].ToString()); | ||
745 | item.ID = new UUID(data["ID"].ToString()); | ||
746 | item.InvType = int.Parse(data["InvType"].ToString()); | ||
747 | item.Folder = new UUID(data["Folder"].ToString()); | ||
748 | item.CreatorId = data["CreatorId"].ToString(); | ||
749 | item.CreatorData = data["CreatorData"].ToString(); | ||
750 | item.Description = data["Description"].ToString(); | ||
751 | item.NextPermissions = uint.Parse(data["NextPermissions"].ToString()); | ||
752 | item.CurrentPermissions = uint.Parse(data["CurrentPermissions"].ToString()); | ||
753 | item.BasePermissions = uint.Parse(data["BasePermissions"].ToString()); | ||
754 | item.EveryOnePermissions = uint.Parse(data["EveryOnePermissions"].ToString()); | ||
755 | item.GroupPermissions = uint.Parse(data["GroupPermissions"].ToString()); | ||
756 | item.GroupID = new UUID(data["GroupID"].ToString()); | ||
757 | item.GroupOwned = bool.Parse(data["GroupOwned"].ToString()); | ||
758 | item.SalePrice = int.Parse(data["SalePrice"].ToString()); | ||
759 | item.SaleType = byte.Parse(data["SaleType"].ToString()); | ||
760 | item.Flags = uint.Parse(data["Flags"].ToString()); | ||
761 | item.CreationDate = int.Parse(data["CreationDate"].ToString()); | ||
762 | |||
763 | return item; | ||
764 | } | ||
765 | |||
766 | } | ||
767 | } | ||
diff --git a/OpenSim/Server/Handlers/Land/LandHandlers.cs b/OpenSim/Server/Handlers/Land/LandHandlers.cs new file mode 100644 index 0000000..b45289a --- /dev/null +++ b/OpenSim/Server/Handlers/Land/LandHandlers.cs | |||
@@ -0,0 +1,96 @@ | |||
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; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Net; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Server.Handlers.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | |||
41 | using OpenMetaverse; | ||
42 | using OpenMetaverse.StructuredData; | ||
43 | using Nwc.XmlRpc; | ||
44 | using Nini.Config; | ||
45 | using log4net; | ||
46 | |||
47 | |||
48 | namespace OpenSim.Server.Handlers.Land | ||
49 | { | ||
50 | public class LandHandlers | ||
51 | { | ||
52 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | |||
54 | private ILandService m_LocalService; | ||
55 | |||
56 | public LandHandlers(ILandService service) | ||
57 | { | ||
58 | m_LocalService = service; | ||
59 | } | ||
60 | |||
61 | public XmlRpcResponse GetLandData(XmlRpcRequest request, IPEndPoint remoteClient) | ||
62 | { | ||
63 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
64 | ulong regionHandle = Convert.ToUInt64(requestData["region_handle"]); | ||
65 | uint x = Convert.ToUInt32(requestData["x"]); | ||
66 | uint y = Convert.ToUInt32(requestData["y"]); | ||
67 | m_log.DebugFormat("[LAND HANDLER]: Got request for land data at {0}, {1} for region {2}", x, y, regionHandle); | ||
68 | |||
69 | byte regionAccess; | ||
70 | LandData landData = m_LocalService.GetLandData(UUID.Zero, regionHandle, x, y, out regionAccess); | ||
71 | Hashtable hash = new Hashtable(); | ||
72 | if (landData != null) | ||
73 | { | ||
74 | // for now, only push out the data we need for answering a ParcelInfoReqeust | ||
75 | hash["AABBMax"] = landData.AABBMax.ToString(); | ||
76 | hash["AABBMin"] = landData.AABBMin.ToString(); | ||
77 | hash["Area"] = landData.Area.ToString(); | ||
78 | hash["AuctionID"] = landData.AuctionID.ToString(); | ||
79 | hash["Description"] = landData.Description; | ||
80 | hash["Flags"] = landData.Flags.ToString(); | ||
81 | hash["GlobalID"] = landData.GlobalID.ToString(); | ||
82 | hash["Name"] = landData.Name; | ||
83 | hash["OwnerID"] = landData.OwnerID.ToString(); | ||
84 | hash["SalePrice"] = landData.SalePrice.ToString(); | ||
85 | hash["SnapshotID"] = landData.SnapshotID.ToString(); | ||
86 | hash["UserLocation"] = landData.UserLocation.ToString(); | ||
87 | hash["RegionAccess"] = regionAccess.ToString(); | ||
88 | } | ||
89 | |||
90 | XmlRpcResponse response = new XmlRpcResponse(); | ||
91 | response.Value = hash; | ||
92 | return response; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | } | ||
diff --git a/OpenSim/Server/Handlers/Land/LandServiceInConnector.cs b/OpenSim/Server/Handlers/Land/LandServiceInConnector.cs new file mode 100644 index 0000000..d368bd3 --- /dev/null +++ b/OpenSim/Server/Handlers/Land/LandServiceInConnector.cs | |||
@@ -0,0 +1,66 @@ | |||
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.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Server.Base; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Server.Handlers.Base; | ||
38 | |||
39 | namespace OpenSim.Server.Handlers.Land | ||
40 | { | ||
41 | public class LandServiceInConnector : ServiceConnector | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | private ILandService m_LandService; | ||
46 | // TODO : private IAuthenticationService m_AuthenticationService; | ||
47 | |||
48 | public LandServiceInConnector(IConfigSource source, IHttpServer server, ILandService service, IScene scene) : | ||
49 | base(source, server, String.Empty) | ||
50 | { | ||
51 | m_LandService = service; | ||
52 | if (m_LandService == null) | ||
53 | { | ||
54 | m_log.Error("[LAND IN CONNECTOR]: Land service was not provided"); | ||
55 | return; | ||
56 | } | ||
57 | |||
58 | //bool authentication = neighbourConfig.GetBoolean("RequireAuthentication", false); | ||
59 | //if (authentication) | ||
60 | // m_AuthenticationService = scene.RequestModuleInterface<IAuthenticationService>(); | ||
61 | |||
62 | LandHandlers landHandlers = new LandHandlers(m_LandService); | ||
63 | server.AddXmlRPCHandler("land_data", landHandlers.GetLandData, false); | ||
64 | } | ||
65 | } | ||
66 | } | ||
diff --git a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs new file mode 100644 index 0000000..f2a5678 --- /dev/null +++ b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs | |||
@@ -0,0 +1,309 @@ | |||
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; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Net; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Server.Handlers.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | |||
41 | using OpenMetaverse; | ||
42 | using OpenMetaverse.StructuredData; | ||
43 | using Nwc.XmlRpc; | ||
44 | using Nini.Config; | ||
45 | using log4net; | ||
46 | |||
47 | |||
48 | namespace OpenSim.Server.Handlers.Login | ||
49 | { | ||
50 | public class LLLoginHandlers | ||
51 | { | ||
52 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | |||
54 | private ILoginService m_LocalService; | ||
55 | private bool m_Proxy; | ||
56 | |||
57 | |||
58 | public LLLoginHandlers(ILoginService service, bool hasProxy) | ||
59 | { | ||
60 | m_LocalService = service; | ||
61 | m_Proxy = hasProxy; | ||
62 | } | ||
63 | |||
64 | public XmlRpcResponse HandleXMLRPCLogin(XmlRpcRequest request, IPEndPoint remoteClient) | ||
65 | { | ||
66 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
67 | if (m_Proxy && request.Params[3] != null) | ||
68 | { | ||
69 | IPEndPoint ep = Util.GetClientIPFromXFF((string)request.Params[3]); | ||
70 | if (ep != null) | ||
71 | // Bang! | ||
72 | remoteClient = ep; | ||
73 | } | ||
74 | |||
75 | if (requestData != null) | ||
76 | { | ||
77 | // Debug code to show exactly what login parameters the viewer is sending us. | ||
78 | // TODO: Extract into a method that can be generally applied if one doesn't already exist. | ||
79 | // foreach (string key in requestData.Keys) | ||
80 | // { | ||
81 | // object value = requestData[key]; | ||
82 | // Console.WriteLine("{0}:{1}", key, value); | ||
83 | // if (value is ArrayList) | ||
84 | // { | ||
85 | // ICollection col = value as ICollection; | ||
86 | // foreach (object item in col) | ||
87 | // Console.WriteLine(" {0}", item); | ||
88 | // } | ||
89 | // } | ||
90 | |||
91 | if (requestData.ContainsKey("first") && requestData["first"] != null && | ||
92 | requestData.ContainsKey("last") && requestData["last"] != null && ( | ||
93 | (requestData.ContainsKey("passwd") && requestData["passwd"] != null) || | ||
94 | (!requestData.ContainsKey("passwd") && requestData.ContainsKey("web_login_key") && requestData["web_login_key"] != null && requestData["web_login_key"].ToString() != UUID.Zero.ToString()) | ||
95 | )) | ||
96 | { | ||
97 | string first = requestData["first"].ToString(); | ||
98 | string last = requestData["last"].ToString(); | ||
99 | string passwd = null; | ||
100 | if (requestData.ContainsKey("passwd")) | ||
101 | { | ||
102 | passwd = requestData["passwd"].ToString(); | ||
103 | } | ||
104 | else if (requestData.ContainsKey("web_login_key")) | ||
105 | { | ||
106 | passwd = "$1$" + requestData["web_login_key"].ToString(); | ||
107 | m_log.InfoFormat("[LOGIN]: XMLRPC Login Req key {0}", passwd); | ||
108 | } | ||
109 | string startLocation = string.Empty; | ||
110 | UUID scopeID = UUID.Zero; | ||
111 | if (requestData["scope_id"] != null) | ||
112 | scopeID = new UUID(requestData["scope_id"].ToString()); | ||
113 | if (requestData.ContainsKey("start")) | ||
114 | startLocation = requestData["start"].ToString(); | ||
115 | |||
116 | string clientVersion = "Unknown"; | ||
117 | if (requestData.Contains("version") && requestData["version"] != null) | ||
118 | clientVersion = requestData["version"].ToString(); | ||
119 | // We should do something interesting with the client version... | ||
120 | |||
121 | string channel = "Unknown"; | ||
122 | if (requestData.Contains("channel") && requestData["channel"] != null) | ||
123 | channel = requestData["channel"].ToString(); | ||
124 | |||
125 | string mac = "Unknown"; | ||
126 | if (requestData.Contains("mac") && requestData["mac"] != null) | ||
127 | mac = requestData["mac"].ToString(); | ||
128 | |||
129 | string id0 = "Unknown"; | ||
130 | if (requestData.Contains("id0") && requestData["id0"] != null) | ||
131 | id0 = requestData["id0"].ToString(); | ||
132 | |||
133 | //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion); | ||
134 | |||
135 | LoginResponse reply = null; | ||
136 | reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, channel, mac, id0, remoteClient); | ||
137 | |||
138 | XmlRpcResponse response = new XmlRpcResponse(); | ||
139 | response.Value = reply.ToHashtable(); | ||
140 | return response; | ||
141 | |||
142 | } | ||
143 | } | ||
144 | |||
145 | return FailedXMLRPCResponse(); | ||
146 | |||
147 | } | ||
148 | public XmlRpcResponse HandleXMLRPCLoginBlocked(XmlRpcRequest request, IPEndPoint client) | ||
149 | { | ||
150 | XmlRpcResponse response = new XmlRpcResponse(); | ||
151 | Hashtable resp = new Hashtable(); | ||
152 | |||
153 | resp["reason"] = "presence"; | ||
154 | resp["message"] = "Logins are currently restricted. Please try again later."; | ||
155 | resp["login"] = "false"; | ||
156 | response.Value = resp; | ||
157 | return response; | ||
158 | } | ||
159 | |||
160 | public XmlRpcResponse HandleXMLRPCSetLoginLevel(XmlRpcRequest request, IPEndPoint remoteClient) | ||
161 | { | ||
162 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
163 | |||
164 | if (requestData != null) | ||
165 | { | ||
166 | if (requestData.ContainsKey("first") && requestData["first"] != null && | ||
167 | requestData.ContainsKey("last") && requestData["last"] != null && | ||
168 | requestData.ContainsKey("level") && requestData["level"] != null && | ||
169 | requestData.ContainsKey("passwd") && requestData["passwd"] != null) | ||
170 | { | ||
171 | string first = requestData["first"].ToString(); | ||
172 | string last = requestData["last"].ToString(); | ||
173 | string passwd = requestData["passwd"].ToString(); | ||
174 | int level = Int32.Parse(requestData["level"].ToString()); | ||
175 | |||
176 | m_log.InfoFormat("[LOGIN]: XMLRPC Set Level to {2} Requested by {0} {1}", first, last, level); | ||
177 | |||
178 | Hashtable reply = m_LocalService.SetLevel(first, last, passwd, level, remoteClient); | ||
179 | |||
180 | XmlRpcResponse response = new XmlRpcResponse(); | ||
181 | response.Value = reply; | ||
182 | |||
183 | return response; | ||
184 | |||
185 | } | ||
186 | } | ||
187 | |||
188 | XmlRpcResponse failResponse = new XmlRpcResponse(); | ||
189 | Hashtable failHash = new Hashtable(); | ||
190 | failHash["success"] = "false"; | ||
191 | failResponse.Value = failHash; | ||
192 | |||
193 | return failResponse; | ||
194 | |||
195 | } | ||
196 | |||
197 | public OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient) | ||
198 | { | ||
199 | if (request.Type == OSDType.Map) | ||
200 | { | ||
201 | OSDMap map = (OSDMap)request; | ||
202 | |||
203 | if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd")) | ||
204 | { | ||
205 | string startLocation = string.Empty; | ||
206 | |||
207 | if (map.ContainsKey("start")) | ||
208 | startLocation = map["start"].AsString(); | ||
209 | |||
210 | UUID scopeID = UUID.Zero; | ||
211 | |||
212 | if (map.ContainsKey("scope_id")) | ||
213 | scopeID = new UUID(map["scope_id"].AsString()); | ||
214 | |||
215 | m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation); | ||
216 | |||
217 | LoginResponse reply = null; | ||
218 | reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID, | ||
219 | map["version"].AsString(), map["channel"].AsString(), map["mac"].AsString(), map["id0"].AsString(), remoteClient); | ||
220 | return reply.ToOSDMap(); | ||
221 | |||
222 | } | ||
223 | } | ||
224 | |||
225 | return FailedOSDResponse(); | ||
226 | } | ||
227 | |||
228 | public void HandleWebSocketLoginEvents(string path, WebSocketHttpServerHandler sock) | ||
229 | { | ||
230 | sock.MaxPayloadSize = 16384; //16 kb payload | ||
231 | sock.InitialMsgTimeout = 5000; //5 second first message to trigger at least one of these events | ||
232 | sock.NoDelay_TCP_Nagle = true; | ||
233 | sock.OnData += delegate(object sender, WebsocketDataEventArgs data) { sock.Close("fail"); }; | ||
234 | sock.OnPing += delegate(object sender, PingEventArgs pingdata) { sock.Close("fail"); }; | ||
235 | sock.OnPong += delegate(object sender, PongEventArgs pongdata) { sock.Close("fail"); }; | ||
236 | sock.OnText += delegate(object sender, WebsocketTextEventArgs text) | ||
237 | { | ||
238 | OSD request = null; | ||
239 | try | ||
240 | { | ||
241 | request = OSDParser.DeserializeJson(text.Data); | ||
242 | if (!(request is OSDMap)) | ||
243 | { | ||
244 | sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse())); | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | OSDMap req = request as OSDMap; | ||
249 | string first = req["firstname"].AsString(); | ||
250 | string last = req["lastname"].AsString(); | ||
251 | string passwd = req["passwd"].AsString(); | ||
252 | string start = req["startlocation"].AsString(); | ||
253 | string version = req["version"].AsString(); | ||
254 | string channel = req["channel"].AsString(); | ||
255 | string mac = req["mac"].AsString(); | ||
256 | string id0 = req["id0"].AsString(); | ||
257 | UUID scope = UUID.Zero; | ||
258 | IPEndPoint endPoint = | ||
259 | (sender as WebSocketHttpServerHandler).GetRemoteIPEndpoint(); | ||
260 | LoginResponse reply = null; | ||
261 | reply = m_LocalService.Login(first, last, passwd, start, scope, version, | ||
262 | channel, mac, id0, endPoint); | ||
263 | sock.SendMessage(OSDParser.SerializeJsonString(reply.ToOSDMap())); | ||
264 | |||
265 | } | ||
266 | |||
267 | } | ||
268 | catch (Exception) | ||
269 | { | ||
270 | sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse())); | ||
271 | } | ||
272 | finally | ||
273 | { | ||
274 | sock.Close("success"); | ||
275 | } | ||
276 | }; | ||
277 | |||
278 | sock.HandshakeAndUpgrade(); | ||
279 | |||
280 | } | ||
281 | |||
282 | |||
283 | private XmlRpcResponse FailedXMLRPCResponse() | ||
284 | { | ||
285 | Hashtable hash = new Hashtable(); | ||
286 | hash["reason"] = "key"; | ||
287 | hash["message"] = "Incomplete login credentials. Check your username and password."; | ||
288 | hash["login"] = "false"; | ||
289 | |||
290 | XmlRpcResponse response = new XmlRpcResponse(); | ||
291 | response.Value = hash; | ||
292 | |||
293 | return response; | ||
294 | } | ||
295 | |||
296 | private OSD FailedOSDResponse() | ||
297 | { | ||
298 | OSDMap map = new OSDMap(); | ||
299 | |||
300 | map["reason"] = OSD.FromString("key"); | ||
301 | map["message"] = OSD.FromString("Invalid login credentials. Check your username and passwd."); | ||
302 | map["login"] = OSD.FromString("false"); | ||
303 | |||
304 | return map; | ||
305 | } | ||
306 | |||
307 | } | ||
308 | |||
309 | } | ||
diff --git a/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs new file mode 100644 index 0000000..f60e892 --- /dev/null +++ b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs | |||
@@ -0,0 +1,117 @@ | |||
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.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Server.Base; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Server.Handlers.Base; | ||
38 | |||
39 | namespace OpenSim.Server.Handlers.Login | ||
40 | { | ||
41 | public class LLLoginServiceInConnector : ServiceConnector | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | private ILoginService m_LoginService; | ||
46 | private bool m_Proxy; | ||
47 | private BasicDosProtectorOptions m_DosProtectionOptions; | ||
48 | |||
49 | public LLLoginServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) : | ||
50 | base(config, server, String.Empty) | ||
51 | { | ||
52 | m_log.Debug("[LLLOGIN IN CONNECTOR]: Starting..."); | ||
53 | string loginService = ReadLocalServiceFromConfig(config); | ||
54 | |||
55 | ISimulationService simService = scene.RequestModuleInterface<ISimulationService>(); | ||
56 | ILibraryService libService = scene.RequestModuleInterface<ILibraryService>(); | ||
57 | |||
58 | Object[] args = new Object[] { config, simService, libService }; | ||
59 | m_LoginService = ServerUtils.LoadPlugin<ILoginService>(loginService, args); | ||
60 | |||
61 | InitializeHandlers(server); | ||
62 | } | ||
63 | |||
64 | public LLLoginServiceInConnector(IConfigSource config, IHttpServer server, string configName) : | ||
65 | base(config, server, configName) | ||
66 | { | ||
67 | string loginService = ReadLocalServiceFromConfig(config); | ||
68 | |||
69 | Object[] args = new Object[] { config }; | ||
70 | |||
71 | m_LoginService = ServerUtils.LoadPlugin<ILoginService>(loginService, args); | ||
72 | |||
73 | InitializeHandlers(server); | ||
74 | } | ||
75 | |||
76 | public LLLoginServiceInConnector(IConfigSource config, IHttpServer server) : | ||
77 | this(config, server, String.Empty) | ||
78 | { | ||
79 | } | ||
80 | |||
81 | private string ReadLocalServiceFromConfig(IConfigSource config) | ||
82 | { | ||
83 | IConfig serverConfig = config.Configs["LoginService"]; | ||
84 | if (serverConfig == null) | ||
85 | throw new Exception(String.Format("No section LoginService in config file")); | ||
86 | |||
87 | string loginService = serverConfig.GetString("LocalServiceModule", String.Empty); | ||
88 | if (loginService == string.Empty) | ||
89 | throw new Exception(String.Format("No LocalServiceModule for LoginService in config file")); | ||
90 | |||
91 | m_Proxy = serverConfig.GetBoolean("HasProxy", false); | ||
92 | m_DosProtectionOptions = new BasicDosProtectorOptions(); | ||
93 | // Dos Protection Options | ||
94 | m_DosProtectionOptions.AllowXForwardedFor = serverConfig.GetBoolean("DOSAllowXForwardedForHeader", false); | ||
95 | m_DosProtectionOptions.RequestTimeSpan = | ||
96 | TimeSpan.FromMilliseconds(serverConfig.GetInt("DOSRequestTimeFrameMS", 10000)); | ||
97 | m_DosProtectionOptions.MaxRequestsInTimeframe = serverConfig.GetInt("DOSMaxRequestsInTimeFrame", 5); | ||
98 | m_DosProtectionOptions.ForgetTimeSpan = | ||
99 | TimeSpan.FromMilliseconds(serverConfig.GetInt("DOSForgiveClientAfterMS", 120000)); | ||
100 | m_DosProtectionOptions.ReportingName = "LOGINDOSPROTECTION"; | ||
101 | |||
102 | |||
103 | return loginService; | ||
104 | } | ||
105 | |||
106 | private void InitializeHandlers(IHttpServer server) | ||
107 | { | ||
108 | LLLoginHandlers loginHandlers = new LLLoginHandlers(m_LoginService, m_Proxy); | ||
109 | server.AddXmlRPCHandler("login_to_simulator", | ||
110 | new XmlRpcBasicDOSProtector(loginHandlers.HandleXMLRPCLogin,loginHandlers.HandleXMLRPCLoginBlocked, | ||
111 | m_DosProtectionOptions).Process, false); | ||
112 | server.AddXmlRPCHandler("set_login_level", loginHandlers.HandleXMLRPCSetLoginLevel, false); | ||
113 | server.SetDefaultLLSDHandler(loginHandlers.HandleLLSDLogin); | ||
114 | server.AddWebSocketHandler("/WebSocket/GridLogin", loginHandlers.HandleWebSocketLoginEvents); | ||
115 | } | ||
116 | } | ||
117 | } | ||
diff --git a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs new file mode 100644 index 0000000..649a27e --- /dev/null +++ b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs | |||
@@ -0,0 +1,247 @@ | |||
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.Xml; | ||
33 | |||
34 | using Nini.Config; | ||
35 | using log4net; | ||
36 | using OpenMetaverse; | ||
37 | |||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Framework.ServiceAuth; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | using OpenSim.Server.Handlers.Base; | ||
44 | |||
45 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
46 | |||
47 | namespace OpenSim.Server.Handlers.MapImage | ||
48 | { | ||
49 | public class MapAddServiceConnector : ServiceConnector | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | private IMapImageService m_MapService; | ||
54 | private IGridService m_GridService; | ||
55 | private string m_ConfigName = "MapImageService"; | ||
56 | |||
57 | public MapAddServiceConnector(IConfigSource config, IHttpServer server, string configName) : | ||
58 | base(config, server, configName) | ||
59 | { | ||
60 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
61 | if (serverConfig == null) | ||
62 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | ||
63 | |||
64 | string mapService = serverConfig.GetString("LocalServiceModule", | ||
65 | String.Empty); | ||
66 | |||
67 | if (mapService == String.Empty) | ||
68 | throw new Exception("No LocalServiceModule in config file"); | ||
69 | |||
70 | Object[] args = new Object[] { config }; | ||
71 | m_MapService = ServerUtils.LoadPlugin<IMapImageService>(mapService, args); | ||
72 | |||
73 | string gridService = serverConfig.GetString("GridService", String.Empty); | ||
74 | if (gridService != string.Empty) | ||
75 | m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); | ||
76 | |||
77 | if (m_GridService != null) | ||
78 | m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is ON"); | ||
79 | else | ||
80 | m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is OFF"); | ||
81 | |||
82 | bool proxy = serverConfig.GetBoolean("HasProxy", false); | ||
83 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
84 | server.AddStreamHandler(new MapServerPostHandler(m_MapService, m_GridService, proxy, auth)); | ||
85 | |||
86 | } | ||
87 | } | ||
88 | |||
89 | class MapServerPostHandler : BaseStreamHandler | ||
90 | { | ||
91 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
92 | private IMapImageService m_MapService; | ||
93 | private IGridService m_GridService; | ||
94 | bool m_Proxy; | ||
95 | |||
96 | public MapServerPostHandler(IMapImageService service, IGridService grid, bool proxy, IServiceAuth auth) : | ||
97 | base("POST", "/map", auth) | ||
98 | { | ||
99 | m_MapService = service; | ||
100 | m_GridService = grid; | ||
101 | m_Proxy = proxy; | ||
102 | } | ||
103 | |||
104 | protected override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
105 | { | ||
106 | // m_log.DebugFormat("[MAP SERVICE IMAGE HANDLER]: Received {0}", path); | ||
107 | StreamReader sr = new StreamReader(requestData); | ||
108 | string body = sr.ReadToEnd(); | ||
109 | sr.Close(); | ||
110 | body = body.Trim(); | ||
111 | |||
112 | try | ||
113 | { | ||
114 | Dictionary<string, object> request = ServerUtils.ParseQueryString(body); | ||
115 | |||
116 | if (!request.ContainsKey("X") || !request.ContainsKey("Y") || !request.ContainsKey("DATA")) | ||
117 | { | ||
118 | httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest; | ||
119 | return FailureResult("Bad request."); | ||
120 | } | ||
121 | uint x = 0, y = 0; | ||
122 | UInt32.TryParse(request["X"].ToString(), out x); | ||
123 | UInt32.TryParse(request["Y"].ToString(), out y); | ||
124 | |||
125 | m_log.DebugFormat("[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y); | ||
126 | |||
127 | // string type = "image/jpeg"; | ||
128 | // | ||
129 | // if (request.ContainsKey("TYPE")) | ||
130 | // type = request["TYPE"].ToString(); | ||
131 | |||
132 | if (m_GridService != null) | ||
133 | { | ||
134 | System.Net.IPAddress ipAddr = GetCallerIP(httpRequest); | ||
135 | GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc(x), (int)Util.RegionToWorldLoc(y)); | ||
136 | if (r != null) | ||
137 | { | ||
138 | if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString()) | ||
139 | { | ||
140 | m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be trying to impersonate region in IP {1}", ipAddr, r.ExternalEndPoint.Address); | ||
141 | return FailureResult("IP address of caller does not match IP address of registered region"); | ||
142 | } | ||
143 | |||
144 | } | ||
145 | else | ||
146 | { | ||
147 | m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be rogue. Region not found at coordinates {1}-{2}", | ||
148 | ipAddr, x, y); | ||
149 | return FailureResult("Region not found at given coordinates"); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | byte[] data = Convert.FromBase64String(request["DATA"].ToString()); | ||
154 | |||
155 | string reason = string.Empty; | ||
156 | bool result = m_MapService.AddMapTile((int)x, (int)y, data, out reason); | ||
157 | |||
158 | if (result) | ||
159 | return SuccessResult(); | ||
160 | else | ||
161 | return FailureResult(reason); | ||
162 | |||
163 | } | ||
164 | catch (Exception e) | ||
165 | { | ||
166 | m_log.ErrorFormat("[MAP SERVICE IMAGE HANDLER]: Exception {0} {1}", e.Message, e.StackTrace); | ||
167 | } | ||
168 | |||
169 | return FailureResult("Unexpected server error"); | ||
170 | } | ||
171 | |||
172 | private byte[] SuccessResult() | ||
173 | { | ||
174 | XmlDocument doc = new XmlDocument(); | ||
175 | |||
176 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
177 | "", ""); | ||
178 | |||
179 | doc.AppendChild(xmlnode); | ||
180 | |||
181 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
182 | ""); | ||
183 | |||
184 | doc.AppendChild(rootElement); | ||
185 | |||
186 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
187 | result.AppendChild(doc.CreateTextNode("Success")); | ||
188 | |||
189 | rootElement.AppendChild(result); | ||
190 | |||
191 | return Util.DocToBytes(doc); | ||
192 | } | ||
193 | |||
194 | private byte[] FailureResult(string msg) | ||
195 | { | ||
196 | XmlDocument doc = new XmlDocument(); | ||
197 | |||
198 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
199 | "", ""); | ||
200 | |||
201 | doc.AppendChild(xmlnode); | ||
202 | |||
203 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
204 | ""); | ||
205 | |||
206 | doc.AppendChild(rootElement); | ||
207 | |||
208 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
209 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
210 | |||
211 | rootElement.AppendChild(result); | ||
212 | |||
213 | XmlElement message = doc.CreateElement("", "Message", ""); | ||
214 | message.AppendChild(doc.CreateTextNode(msg)); | ||
215 | |||
216 | rootElement.AppendChild(message); | ||
217 | |||
218 | return Util.DocToBytes(doc); | ||
219 | } | ||
220 | |||
221 | private System.Net.IPAddress GetCallerIP(IOSHttpRequest request) | ||
222 | { | ||
223 | if (!m_Proxy) | ||
224 | return request.RemoteIPEndPoint.Address; | ||
225 | |||
226 | // We're behind a proxy | ||
227 | string xff = "X-Forwarded-For"; | ||
228 | string xffValue = request.Headers[xff.ToLower()]; | ||
229 | if (xffValue == null || (xffValue != null && xffValue == string.Empty)) | ||
230 | xffValue = request.Headers[xff]; | ||
231 | |||
232 | if (xffValue == null || (xffValue != null && xffValue == string.Empty)) | ||
233 | { | ||
234 | m_log.WarnFormat("[MAP IMAGE HANDLER]: No XFF header"); | ||
235 | return request.RemoteIPEndPoint.Address; | ||
236 | } | ||
237 | |||
238 | System.Net.IPEndPoint ep = Util.GetClientIPFromXFF(xffValue); | ||
239 | if (ep != null) | ||
240 | return ep.Address; | ||
241 | |||
242 | // Oops | ||
243 | return request.RemoteIPEndPoint.Address; | ||
244 | } | ||
245 | |||
246 | } | ||
247 | } | ||
diff --git a/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs b/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs new file mode 100644 index 0000000..7bb2f39 --- /dev/null +++ b/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs | |||
@@ -0,0 +1,107 @@ | |||
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.IO; | ||
30 | using System.Net; | ||
31 | using System.Reflection; | ||
32 | |||
33 | using Nini.Config; | ||
34 | using log4net; | ||
35 | |||
36 | using OpenSim.Server.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Framework.Servers.HttpServer; | ||
39 | using OpenSim.Server.Handlers.Base; | ||
40 | |||
41 | namespace OpenSim.Server.Handlers.MapImage | ||
42 | { | ||
43 | public class MapGetServiceConnector : ServiceConnector | ||
44 | { | ||
45 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private IMapImageService m_MapService; | ||
48 | |||
49 | private string m_ConfigName = "MapImageService"; | ||
50 | |||
51 | public MapGetServiceConnector(IConfigSource config, IHttpServer server, string configName) : | ||
52 | base(config, server, configName) | ||
53 | { | ||
54 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
55 | if (serverConfig == null) | ||
56 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | ||
57 | |||
58 | string gridService = serverConfig.GetString("LocalServiceModule", | ||
59 | String.Empty); | ||
60 | |||
61 | if (gridService == String.Empty) | ||
62 | throw new Exception("No LocalServiceModule in config file"); | ||
63 | |||
64 | Object[] args = new Object[] { config }; | ||
65 | m_MapService = ServerUtils.LoadPlugin<IMapImageService>(gridService, args); | ||
66 | |||
67 | server.AddStreamHandler(new MapServerGetHandler(m_MapService)); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | class MapServerGetHandler : BaseStreamHandler | ||
72 | { | ||
73 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
74 | |||
75 | private IMapImageService m_MapService; | ||
76 | |||
77 | public MapServerGetHandler(IMapImageService service) : | ||
78 | base("GET", "/map") | ||
79 | { | ||
80 | m_MapService = service; | ||
81 | } | ||
82 | |||
83 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
84 | { | ||
85 | byte[] result = new byte[0]; | ||
86 | |||
87 | string format = string.Empty; | ||
88 | result = m_MapService.GetMapTile(path.Trim('/'), out format); | ||
89 | if (result.Length > 0) | ||
90 | { | ||
91 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
92 | if (format.Equals(".png")) | ||
93 | httpResponse.ContentType = "image/png"; | ||
94 | else if (format.Equals(".jpg") || format.Equals(".jpeg")) | ||
95 | httpResponse.ContentType = "image/jpeg"; | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | httpResponse.StatusCode = (int)HttpStatusCode.NotFound; | ||
100 | httpResponse.ContentType = "text/plain"; | ||
101 | } | ||
102 | |||
103 | return result; | ||
104 | } | ||
105 | |||
106 | } | ||
107 | } | ||
diff --git a/OpenSim/Server/Handlers/Neighbour/NeighbourHandlers.cs b/OpenSim/Server/Handlers/Neighbour/NeighbourHandlers.cs new file mode 100644 index 0000000..3525a01 --- /dev/null +++ b/OpenSim/Server/Handlers/Neighbour/NeighbourHandlers.cs | |||
@@ -0,0 +1,208 @@ | |||
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.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Net; | ||
32 | using System.Text; | ||
33 | |||
34 | using OpenSim.Server.Base; | ||
35 | using OpenSim.Server.Handlers.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Servers.HttpServer; | ||
39 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
40 | |||
41 | using OpenMetaverse; | ||
42 | using OpenMetaverse.StructuredData; | ||
43 | using Nini.Config; | ||
44 | using log4net; | ||
45 | |||
46 | |||
47 | namespace OpenSim.Server.Handlers.Neighbour | ||
48 | { | ||
49 | public class NeighbourGetHandler : BaseStreamHandler | ||
50 | { | ||
51 | // TODO: unused: private ISimulationService m_SimulationService; | ||
52 | // TODO: unused: private IAuthenticationService m_AuthenticationService; | ||
53 | |||
54 | public NeighbourGetHandler(INeighbourService service, IAuthenticationService authentication) : | ||
55 | base("GET", "/region") | ||
56 | { | ||
57 | // TODO: unused: m_SimulationService = service; | ||
58 | // TODO: unused: m_AuthenticationService = authentication; | ||
59 | } | ||
60 | |||
61 | protected override byte[] ProcessRequest(string path, Stream request, | ||
62 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
63 | { | ||
64 | // Not implemented yet | ||
65 | Console.WriteLine("--- Get region --- " + path); | ||
66 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
67 | return new byte[] { }; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | public class NeighbourPostHandler : BaseStreamHandler | ||
72 | { | ||
73 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
74 | private INeighbourService m_NeighbourService; | ||
75 | private IAuthenticationService m_AuthenticationService; | ||
76 | // TODO: unused: private bool m_AllowForeignGuests; | ||
77 | |||
78 | public NeighbourPostHandler(INeighbourService service, IAuthenticationService authentication) : | ||
79 | base("POST", "/region") | ||
80 | { | ||
81 | m_NeighbourService = service; | ||
82 | m_AuthenticationService = authentication; | ||
83 | // TODO: unused: m_AllowForeignGuests = foreignGuests; | ||
84 | } | ||
85 | |||
86 | protected override byte[] ProcessRequest(string path, Stream request, | ||
87 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
88 | { | ||
89 | byte[] result = new byte[0]; | ||
90 | |||
91 | UUID regionID; | ||
92 | string action; | ||
93 | ulong regionHandle; | ||
94 | if (RestHandlerUtils.GetParams(path, out regionID, out regionHandle, out action)) | ||
95 | { | ||
96 | m_log.InfoFormat("[RegionPostHandler]: Invalid parameters for neighbour message {0}", path); | ||
97 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
98 | httpResponse.StatusDescription = "Invalid parameters for neighbour message " + path; | ||
99 | |||
100 | return result; | ||
101 | } | ||
102 | |||
103 | if (m_AuthenticationService != null) | ||
104 | { | ||
105 | // Authentication | ||
106 | string authority = string.Empty; | ||
107 | string authToken = string.Empty; | ||
108 | if (!RestHandlerUtils.GetAuthentication(httpRequest, out authority, out authToken)) | ||
109 | { | ||
110 | m_log.InfoFormat("[RegionPostHandler]: Authentication failed for neighbour message {0}", path); | ||
111 | httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized; | ||
112 | return result; | ||
113 | } | ||
114 | // TODO: Rethink this | ||
115 | //if (!m_AuthenticationService.VerifyKey(regionID, authToken)) | ||
116 | //{ | ||
117 | // m_log.InfoFormat("[RegionPostHandler]: Authentication failed for neighbour message {0}", path); | ||
118 | // httpResponse.StatusCode = (int)HttpStatusCode.Forbidden; | ||
119 | // return result; | ||
120 | //} | ||
121 | m_log.DebugFormat("[RegionPostHandler]: Authentication succeeded for {0}", regionID); | ||
122 | } | ||
123 | |||
124 | OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength); | ||
125 | if (args == null) | ||
126 | { | ||
127 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
128 | httpResponse.StatusDescription = "Unable to retrieve data"; | ||
129 | m_log.DebugFormat("[RegionPostHandler]: Unable to retrieve data for post {0}", path); | ||
130 | return result; | ||
131 | } | ||
132 | |||
133 | // retrieve the regionhandle | ||
134 | ulong regionhandle = 0; | ||
135 | if (args["destination_handle"] != null) | ||
136 | UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); | ||
137 | |||
138 | RegionInfo aRegion = new RegionInfo(); | ||
139 | try | ||
140 | { | ||
141 | aRegion.UnpackRegionInfoData(args); | ||
142 | } | ||
143 | catch (Exception ex) | ||
144 | { | ||
145 | m_log.InfoFormat("[RegionPostHandler]: exception on unpacking region info {0}", ex.Message); | ||
146 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | ||
147 | httpResponse.StatusDescription = "Problems with data deserialization"; | ||
148 | return result; | ||
149 | } | ||
150 | |||
151 | // Finally! | ||
152 | GridRegion thisRegion = m_NeighbourService.HelloNeighbour(regionhandle, aRegion); | ||
153 | |||
154 | OSDMap resp = new OSDMap(1); | ||
155 | |||
156 | if (thisRegion != null) | ||
157 | resp["success"] = OSD.FromBoolean(true); | ||
158 | else | ||
159 | resp["success"] = OSD.FromBoolean(false); | ||
160 | |||
161 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
162 | |||
163 | return Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp)); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | public class NeighbourPutHandler : BaseStreamHandler | ||
168 | { | ||
169 | // TODO: unused: private ISimulationService m_SimulationService; | ||
170 | // TODO: unused: private IAuthenticationService m_AuthenticationService; | ||
171 | |||
172 | public NeighbourPutHandler(INeighbourService service, IAuthenticationService authentication) : | ||
173 | base("PUT", "/region") | ||
174 | { | ||
175 | // TODO: unused: m_SimulationService = service; | ||
176 | // TODO: unused: m_AuthenticationService = authentication; | ||
177 | } | ||
178 | |||
179 | protected override byte[] ProcessRequest(string path, Stream request, | ||
180 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
181 | { | ||
182 | // Not implemented yet | ||
183 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
184 | return new byte[] { }; | ||
185 | } | ||
186 | } | ||
187 | |||
188 | public class NeighbourDeleteHandler : BaseStreamHandler | ||
189 | { | ||
190 | // TODO: unused: private ISimulationService m_SimulationService; | ||
191 | // TODO: unused: private IAuthenticationService m_AuthenticationService; | ||
192 | |||
193 | public NeighbourDeleteHandler(INeighbourService service, IAuthenticationService authentication) : | ||
194 | base("DELETE", "/region") | ||
195 | { | ||
196 | // TODO: unused: m_SimulationService = service; | ||
197 | // TODO: unused: m_AuthenticationService = authentication; | ||
198 | } | ||
199 | |||
200 | protected override byte[] ProcessRequest(string path, Stream request, | ||
201 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
202 | { | ||
203 | // Not implemented yet | ||
204 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
205 | return new byte[] { }; | ||
206 | } | ||
207 | } | ||
208 | } | ||
diff --git a/OpenSim/Server/Handlers/Neighbour/NeighbourServiceInConnector.cs b/OpenSim/Server/Handlers/Neighbour/NeighbourServiceInConnector.cs new file mode 100644 index 0000000..ac2e75f --- /dev/null +++ b/OpenSim/Server/Handlers/Neighbour/NeighbourServiceInConnector.cs | |||
@@ -0,0 +1,68 @@ | |||
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.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Server.Base; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Server.Handlers.Base; | ||
38 | |||
39 | namespace OpenSim.Server.Handlers.Neighbour | ||
40 | { | ||
41 | public class NeighbourServiceInConnector : ServiceConnector | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | private INeighbourService m_NeighbourService; | ||
46 | private IAuthenticationService m_AuthenticationService = null; | ||
47 | |||
48 | public NeighbourServiceInConnector(IConfigSource source, IHttpServer server, INeighbourService nService, IScene scene) : | ||
49 | base(source, server, String.Empty) | ||
50 | { | ||
51 | |||
52 | m_NeighbourService = nService; | ||
53 | if (m_NeighbourService == null) | ||
54 | { | ||
55 | m_log.Error("[NEIGHBOUR IN CONNECTOR]: neighbour service was not provided"); | ||
56 | return; | ||
57 | } | ||
58 | |||
59 | //bool authentication = neighbourConfig.GetBoolean("RequireAuthentication", false); | ||
60 | //if (authentication) | ||
61 | // m_AuthenticationService = scene.RequestModuleInterface<IAuthenticationService>(); | ||
62 | |||
63 | |||
64 | server.AddStreamHandler(new NeighbourPostHandler(m_NeighbourService, m_AuthenticationService)); | ||
65 | server.AddStreamHandler(new NeighbourGetHandler(m_NeighbourService, m_AuthenticationService)); | ||
66 | } | ||
67 | } | ||
68 | } | ||
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs b/OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs new file mode 100644 index 0000000..7a63c36 --- /dev/null +++ b/OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs | |||
@@ -0,0 +1,64 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Framework.ServiceAuth; | ||
34 | using OpenSim.Server.Handlers.Base; | ||
35 | |||
36 | namespace OpenSim.Server.Handlers.Presence | ||
37 | { | ||
38 | public class PresenceServiceConnector : ServiceConnector | ||
39 | { | ||
40 | private IPresenceService m_PresenceService; | ||
41 | private string m_ConfigName = "PresenceService"; | ||
42 | |||
43 | public PresenceServiceConnector(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 gridService = serverConfig.GetString("LocalServiceModule", | ||
51 | String.Empty); | ||
52 | |||
53 | if (gridService == String.Empty) | ||
54 | throw new Exception("No LocalServiceModule in config file"); | ||
55 | |||
56 | Object[] args = new Object[] { config }; | ||
57 | m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(gridService, args); | ||
58 | |||
59 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
60 | |||
61 | server.AddStreamHandler(new PresenceServerPostHandler(m_PresenceService, auth)); | ||
62 | } | ||
63 | } | ||
64 | } | ||
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs new file mode 100644 index 0000000..49dbcb5 --- /dev/null +++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs | |||
@@ -0,0 +1,294 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using System.Collections.Generic; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Framework; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | using OpenSim.Framework.ServiceAuth; | ||
44 | using OpenMetaverse; | ||
45 | |||
46 | namespace OpenSim.Server.Handlers.Presence | ||
47 | { | ||
48 | public class PresenceServerPostHandler : BaseStreamHandler | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private IPresenceService m_PresenceService; | ||
53 | |||
54 | public PresenceServerPostHandler(IPresenceService service, IServiceAuth auth) : | ||
55 | base("POST", "/presence", auth) | ||
56 | { | ||
57 | m_PresenceService = service; | ||
58 | } | ||
59 | |||
60 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
61 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
62 | { | ||
63 | StreamReader sr = new StreamReader(requestData); | ||
64 | string body = sr.ReadToEnd(); | ||
65 | sr.Close(); | ||
66 | body = body.Trim(); | ||
67 | |||
68 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
69 | string method = string.Empty; | ||
70 | try | ||
71 | { | ||
72 | Dictionary<string, object> request = | ||
73 | ServerUtils.ParseQueryString(body); | ||
74 | |||
75 | if (!request.ContainsKey("METHOD")) | ||
76 | return FailureResult(); | ||
77 | |||
78 | method = request["METHOD"].ToString(); | ||
79 | |||
80 | switch (method) | ||
81 | { | ||
82 | case "login": | ||
83 | return LoginAgent(request); | ||
84 | case "logout": | ||
85 | return LogoutAgent(request); | ||
86 | case "logoutregion": | ||
87 | return LogoutRegionAgents(request); | ||
88 | case "report": | ||
89 | return Report(request); | ||
90 | case "getagent": | ||
91 | return GetAgent(request); | ||
92 | case "getagents": | ||
93 | return GetAgents(request); | ||
94 | } | ||
95 | m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); | ||
96 | } | ||
97 | catch (Exception e) | ||
98 | { | ||
99 | m_log.DebugFormat("[PRESENCE HANDLER]: Exception in method {0}: {1}", method, e); | ||
100 | } | ||
101 | |||
102 | return FailureResult(); | ||
103 | |||
104 | } | ||
105 | |||
106 | byte[] LoginAgent(Dictionary<string, object> request) | ||
107 | { | ||
108 | string user = String.Empty; | ||
109 | UUID session = UUID.Zero; | ||
110 | UUID ssession = UUID.Zero; | ||
111 | |||
112 | if (!request.ContainsKey("UserID") || !request.ContainsKey("SessionID")) | ||
113 | return FailureResult(); | ||
114 | |||
115 | user = request["UserID"].ToString(); | ||
116 | |||
117 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) | ||
118 | return FailureResult(); | ||
119 | |||
120 | if (request.ContainsKey("SecureSessionID")) | ||
121 | // If it's malformed, we go on with a Zero on it | ||
122 | UUID.TryParse(request["SecureSessionID"].ToString(), out ssession); | ||
123 | |||
124 | if (m_PresenceService.LoginAgent(user, session, ssession)) | ||
125 | return SuccessResult(); | ||
126 | |||
127 | return FailureResult(); | ||
128 | } | ||
129 | |||
130 | byte[] LogoutAgent(Dictionary<string, object> request) | ||
131 | { | ||
132 | UUID session = UUID.Zero; | ||
133 | |||
134 | if (!request.ContainsKey("SessionID")) | ||
135 | return FailureResult(); | ||
136 | |||
137 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) | ||
138 | return FailureResult(); | ||
139 | |||
140 | if (m_PresenceService.LogoutAgent(session)) | ||
141 | return SuccessResult(); | ||
142 | |||
143 | return FailureResult(); | ||
144 | } | ||
145 | |||
146 | byte[] LogoutRegionAgents(Dictionary<string, object> request) | ||
147 | { | ||
148 | UUID region = UUID.Zero; | ||
149 | |||
150 | if (!request.ContainsKey("RegionID")) | ||
151 | return FailureResult(); | ||
152 | |||
153 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) | ||
154 | return FailureResult(); | ||
155 | |||
156 | if (m_PresenceService.LogoutRegionAgents(region)) | ||
157 | return SuccessResult(); | ||
158 | |||
159 | return FailureResult(); | ||
160 | } | ||
161 | |||
162 | byte[] Report(Dictionary<string, object> request) | ||
163 | { | ||
164 | UUID session = UUID.Zero; | ||
165 | UUID region = UUID.Zero; | ||
166 | |||
167 | if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID")) | ||
168 | return FailureResult(); | ||
169 | |||
170 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) | ||
171 | return FailureResult(); | ||
172 | |||
173 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) | ||
174 | return FailureResult(); | ||
175 | |||
176 | if (m_PresenceService.ReportAgent(session, region)) | ||
177 | { | ||
178 | return SuccessResult(); | ||
179 | } | ||
180 | |||
181 | return FailureResult(); | ||
182 | } | ||
183 | |||
184 | byte[] GetAgent(Dictionary<string, object> request) | ||
185 | { | ||
186 | UUID session = UUID.Zero; | ||
187 | |||
188 | if (!request.ContainsKey("SessionID")) | ||
189 | return FailureResult(); | ||
190 | |||
191 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) | ||
192 | return FailureResult(); | ||
193 | |||
194 | PresenceInfo pinfo = m_PresenceService.GetAgent(session); | ||
195 | |||
196 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
197 | if (pinfo == null) | ||
198 | result["result"] = "null"; | ||
199 | else | ||
200 | result["result"] = pinfo.ToKeyValuePairs(); | ||
201 | |||
202 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
203 | |||
204 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
205 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
206 | } | ||
207 | |||
208 | byte[] GetAgents(Dictionary<string, object> request) | ||
209 | { | ||
210 | |||
211 | string[] userIDs; | ||
212 | |||
213 | if (!request.ContainsKey("uuids")) | ||
214 | { | ||
215 | m_log.DebugFormat("[PRESENCE HANDLER]: GetAgents called without required uuids argument"); | ||
216 | return FailureResult(); | ||
217 | } | ||
218 | |||
219 | if (!(request["uuids"] is List<string>)) | ||
220 | { | ||
221 | m_log.DebugFormat("[PRESENCE HANDLER]: GetAgents input argument was of unexpected type {0}", request["uuids"].GetType().ToString()); | ||
222 | return FailureResult(); | ||
223 | } | ||
224 | |||
225 | userIDs = ((List<string>)request["uuids"]).ToArray(); | ||
226 | |||
227 | PresenceInfo[] pinfos = m_PresenceService.GetAgents(userIDs); | ||
228 | |||
229 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
230 | if ((pinfos == null) || ((pinfos != null) && (pinfos.Length == 0))) | ||
231 | result["result"] = "null"; | ||
232 | else | ||
233 | { | ||
234 | int i = 0; | ||
235 | foreach (PresenceInfo pinfo in pinfos) | ||
236 | { | ||
237 | Dictionary<string, object> rinfoDict = pinfo.ToKeyValuePairs(); | ||
238 | result["presence" + i] = rinfoDict; | ||
239 | i++; | ||
240 | } | ||
241 | } | ||
242 | |||
243 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
244 | |||
245 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
246 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
247 | } | ||
248 | |||
249 | private byte[] SuccessResult() | ||
250 | { | ||
251 | XmlDocument doc = new XmlDocument(); | ||
252 | |||
253 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
254 | "", ""); | ||
255 | |||
256 | doc.AppendChild(xmlnode); | ||
257 | |||
258 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
259 | ""); | ||
260 | |||
261 | doc.AppendChild(rootElement); | ||
262 | |||
263 | XmlElement result = doc.CreateElement("", "result", ""); | ||
264 | result.AppendChild(doc.CreateTextNode("Success")); | ||
265 | |||
266 | rootElement.AppendChild(result); | ||
267 | |||
268 | return Util.DocToBytes(doc); | ||
269 | } | ||
270 | |||
271 | private byte[] FailureResult() | ||
272 | { | ||
273 | XmlDocument doc = new XmlDocument(); | ||
274 | |||
275 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
276 | "", ""); | ||
277 | |||
278 | doc.AppendChild(xmlnode); | ||
279 | |||
280 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
281 | ""); | ||
282 | |||
283 | doc.AppendChild(rootElement); | ||
284 | |||
285 | XmlElement result = doc.CreateElement("", "result", ""); | ||
286 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
287 | |||
288 | rootElement.AppendChild(result); | ||
289 | |||
290 | return Util.DocToBytes(doc); | ||
291 | } | ||
292 | |||
293 | } | ||
294 | } | ||
diff --git a/OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs b/OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs new file mode 100644 index 0000000..2dfb862 --- /dev/null +++ b/OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs | |||
@@ -0,0 +1,109 @@ | |||
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 Nini.Config; | ||
31 | using OpenSim.Server.Base; | ||
32 | using OpenSim.Services.Interfaces; | ||
33 | using OpenSim.Framework.Servers.HttpServer; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Server.Handlers.Base; | ||
36 | using log4net; | ||
37 | |||
38 | namespace OpenSim.Server.Handlers.Profiles | ||
39 | { | ||
40 | public class UserProfilesConnector: ServiceConnector | ||
41 | { | ||
42 | // static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | // Our Local Module | ||
45 | public IUserProfilesService ServiceModule | ||
46 | { | ||
47 | get; private set; | ||
48 | } | ||
49 | |||
50 | // The HTTP server. | ||
51 | public IHttpServer Server | ||
52 | { | ||
53 | get; private set; | ||
54 | } | ||
55 | |||
56 | public bool Enabled | ||
57 | { | ||
58 | get; private set; | ||
59 | } | ||
60 | |||
61 | public UserProfilesConnector(IConfigSource config, IHttpServer server, string configName) : | ||
62 | base(config, server, configName) | ||
63 | { | ||
64 | ConfigName = "UserProfilesService"; | ||
65 | if(!string.IsNullOrEmpty(configName)) | ||
66 | ConfigName = configName; | ||
67 | |||
68 | IConfig serverConfig = config.Configs[ConfigName]; | ||
69 | if (serverConfig == null) | ||
70 | throw new Exception(String.Format("No section {0} in config file", ConfigName)); | ||
71 | |||
72 | if(!serverConfig.GetBoolean("Enabled",false)) | ||
73 | { | ||
74 | Enabled = false; | ||
75 | return; | ||
76 | } | ||
77 | |||
78 | Enabled = true; | ||
79 | |||
80 | Server = server; | ||
81 | |||
82 | string service = serverConfig.GetString("LocalServiceModule", String.Empty); | ||
83 | |||
84 | Object[] args = new Object[] { config, ConfigName }; | ||
85 | ServiceModule = ServerUtils.LoadPlugin<IUserProfilesService>(service, args); | ||
86 | |||
87 | JsonRpcProfileHandlers handler = new JsonRpcProfileHandlers(ServiceModule); | ||
88 | |||
89 | Server.AddJsonRPCHandler("avatarclassifiedsrequest", handler.AvatarClassifiedsRequest); | ||
90 | Server.AddJsonRPCHandler("classified_update", handler.ClassifiedUpdate); | ||
91 | Server.AddJsonRPCHandler("classifieds_info_query", handler.ClassifiedInfoRequest); | ||
92 | Server.AddJsonRPCHandler("classified_delete", handler.ClassifiedDelete); | ||
93 | Server.AddJsonRPCHandler("avatarpicksrequest", handler.AvatarPicksRequest); | ||
94 | Server.AddJsonRPCHandler("pickinforequest", handler.PickInfoRequest); | ||
95 | Server.AddJsonRPCHandler("picks_update", handler.PicksUpdate); | ||
96 | Server.AddJsonRPCHandler("picks_delete", handler.PicksDelete); | ||
97 | Server.AddJsonRPCHandler("avatarnotesrequest", handler.AvatarNotesRequest); | ||
98 | Server.AddJsonRPCHandler("avatar_notes_update", handler.NotesUpdate); | ||
99 | Server.AddJsonRPCHandler("avatar_properties_request", handler.AvatarPropertiesRequest); | ||
100 | Server.AddJsonRPCHandler("avatar_properties_update", handler.AvatarPropertiesUpdate); | ||
101 | Server.AddJsonRPCHandler("avatar_interests_update", handler.AvatarInterestsUpdate); | ||
102 | Server.AddJsonRPCHandler("user_preferences_update", handler.UserPreferenecesUpdate); | ||
103 | Server.AddJsonRPCHandler("user_preferences_request", handler.UserPreferencesRequest); | ||
104 | Server.AddJsonRPCHandler("image_assets_request", handler.AvatarImageAssetsRequest); | ||
105 | Server.AddJsonRPCHandler("user_data_request", handler.RequestUserAppData); | ||
106 | Server.AddJsonRPCHandler("user_data_update", handler.UpdateUserAppData); | ||
107 | } | ||
108 | } | ||
109 | } \ No newline at end of file | ||
diff --git a/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs b/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs new file mode 100644 index 0000000..49aa8ba --- /dev/null +++ b/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs | |||
@@ -0,0 +1,513 @@ | |||
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 OpenMetaverse; | ||
31 | using OpenMetaverse.StructuredData; | ||
32 | using log4net; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Framework.Servers.HttpServer; | ||
35 | using OpenSim.Framework; | ||
36 | |||
37 | namespace OpenSim.Server.Handlers | ||
38 | { | ||
39 | public class UserProfilesHandlers | ||
40 | { | ||
41 | public UserProfilesHandlers () | ||
42 | { | ||
43 | } | ||
44 | } | ||
45 | |||
46 | public class JsonRpcProfileHandlers | ||
47 | { | ||
48 | static readonly ILog m_log = | ||
49 | LogManager.GetLogger( | ||
50 | MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | public IUserProfilesService Service | ||
53 | { | ||
54 | get; private set; | ||
55 | } | ||
56 | |||
57 | public JsonRpcProfileHandlers(IUserProfilesService service) | ||
58 | { | ||
59 | Service = service; | ||
60 | } | ||
61 | |||
62 | #region Classifieds | ||
63 | /// <summary> | ||
64 | /// Request avatar's classified ads. | ||
65 | /// </summary> | ||
66 | /// <returns> | ||
67 | /// An array containing all the calassified uuid and it's name created by the creator id | ||
68 | /// </returns> | ||
69 | /// <param name='json'> | ||
70 | /// Our parameters are in the OSDMap json["params"] | ||
71 | /// </param> | ||
72 | /// <param name='response'> | ||
73 | /// If set to <c>true</c> response. | ||
74 | /// </param> | ||
75 | public bool AvatarClassifiedsRequest(OSDMap json, ref JsonRpcResponse response) | ||
76 | { | ||
77 | if(!json.ContainsKey("params")) | ||
78 | { | ||
79 | response.Error.Code = ErrorCode.ParseError; | ||
80 | m_log.DebugFormat ("Classified Request"); | ||
81 | return false; | ||
82 | } | ||
83 | |||
84 | OSDMap request = (OSDMap)json["params"]; | ||
85 | UUID creatorId = new UUID(request["creatorId"].AsString()); | ||
86 | |||
87 | |||
88 | OSDArray data = (OSDArray) Service.AvatarClassifiedsRequest(creatorId); | ||
89 | response.Result = data; | ||
90 | |||
91 | return true; | ||
92 | } | ||
93 | |||
94 | public bool ClassifiedUpdate(OSDMap json, ref JsonRpcResponse response) | ||
95 | { | ||
96 | if(!json.ContainsKey("params")) | ||
97 | { | ||
98 | response.Error.Code = ErrorCode.ParseError; | ||
99 | response.Error.Message = "Error parsing classified update request"; | ||
100 | m_log.DebugFormat ("Classified Update Request"); | ||
101 | return false; | ||
102 | } | ||
103 | |||
104 | string result = string.Empty; | ||
105 | UserClassifiedAdd ad = new UserClassifiedAdd(); | ||
106 | object Ad = (object)ad; | ||
107 | OSD.DeserializeMembers(ref Ad, (OSDMap)json["params"]); | ||
108 | if(Service.ClassifiedUpdate(ad, ref result)) | ||
109 | { | ||
110 | response.Result = OSD.SerializeMembers(ad); | ||
111 | return true; | ||
112 | } | ||
113 | |||
114 | response.Error.Code = ErrorCode.InternalError; | ||
115 | response.Error.Message = string.Format("{0}", result); | ||
116 | return false; | ||
117 | } | ||
118 | |||
119 | public bool ClassifiedDelete(OSDMap json, ref JsonRpcResponse response) | ||
120 | { | ||
121 | if(!json.ContainsKey("params")) | ||
122 | { | ||
123 | response.Error.Code = ErrorCode.ParseError; | ||
124 | m_log.DebugFormat ("Classified Delete Request"); | ||
125 | return false; | ||
126 | } | ||
127 | |||
128 | OSDMap request = (OSDMap)json["params"]; | ||
129 | UUID classifiedId = new UUID(request["classifiedId"].AsString()); | ||
130 | |||
131 | if (Service.ClassifiedDelete(classifiedId)) | ||
132 | return true; | ||
133 | |||
134 | response.Error.Code = ErrorCode.InternalError; | ||
135 | response.Error.Message = "data error removing record"; | ||
136 | return false; | ||
137 | } | ||
138 | |||
139 | public bool ClassifiedInfoRequest(OSDMap json, ref JsonRpcResponse response) | ||
140 | { | ||
141 | if(!json.ContainsKey("params")) | ||
142 | { | ||
143 | response.Error.Code = ErrorCode.ParseError; | ||
144 | response.Error.Message = "no parameters supplied"; | ||
145 | m_log.DebugFormat ("Classified Info Request"); | ||
146 | return false; | ||
147 | } | ||
148 | |||
149 | string result = string.Empty; | ||
150 | UserClassifiedAdd ad = new UserClassifiedAdd(); | ||
151 | object Ad = (object)ad; | ||
152 | OSD.DeserializeMembers(ref Ad, (OSDMap)json["params"]); | ||
153 | if(Service.ClassifiedInfoRequest(ref ad, ref result)) | ||
154 | { | ||
155 | response.Result = OSD.SerializeMembers(ad); | ||
156 | return true; | ||
157 | } | ||
158 | |||
159 | response.Error.Code = ErrorCode.InternalError; | ||
160 | response.Error.Message = string.Format("{0}", result); | ||
161 | return false; | ||
162 | } | ||
163 | #endregion Classifieds | ||
164 | |||
165 | #region Picks | ||
166 | public bool AvatarPicksRequest(OSDMap json, ref JsonRpcResponse response) | ||
167 | { | ||
168 | if(!json.ContainsKey("params")) | ||
169 | { | ||
170 | response.Error.Code = ErrorCode.ParseError; | ||
171 | m_log.DebugFormat ("Avatar Picks Request"); | ||
172 | return false; | ||
173 | } | ||
174 | |||
175 | OSDMap request = (OSDMap)json["params"]; | ||
176 | UUID creatorId = new UUID(request["creatorId"].AsString()); | ||
177 | |||
178 | |||
179 | OSDArray data = (OSDArray) Service.AvatarPicksRequest(creatorId); | ||
180 | response.Result = data; | ||
181 | |||
182 | return true; | ||
183 | } | ||
184 | |||
185 | public bool PickInfoRequest(OSDMap json, ref JsonRpcResponse response) | ||
186 | { | ||
187 | if(!json.ContainsKey("params")) | ||
188 | { | ||
189 | response.Error.Code = ErrorCode.ParseError; | ||
190 | response.Error.Message = "no parameters supplied"; | ||
191 | m_log.DebugFormat ("Avatar Picks Info Request"); | ||
192 | return false; | ||
193 | } | ||
194 | |||
195 | string result = string.Empty; | ||
196 | UserProfilePick pick = new UserProfilePick(); | ||
197 | object Pick = (object)pick; | ||
198 | OSD.DeserializeMembers(ref Pick, (OSDMap)json["params"]); | ||
199 | if(Service.PickInfoRequest(ref pick, ref result)) | ||
200 | { | ||
201 | response.Result = OSD.SerializeMembers(pick); | ||
202 | return true; | ||
203 | } | ||
204 | |||
205 | response.Error.Code = ErrorCode.InternalError; | ||
206 | response.Error.Message = string.Format("{0}", result); | ||
207 | return false; | ||
208 | } | ||
209 | |||
210 | public bool PicksUpdate(OSDMap json, ref JsonRpcResponse response) | ||
211 | { | ||
212 | if(!json.ContainsKey("params")) | ||
213 | { | ||
214 | response.Error.Code = ErrorCode.ParseError; | ||
215 | response.Error.Message = "no parameters supplied"; | ||
216 | m_log.DebugFormat ("Avatar Picks Update Request"); | ||
217 | return false; | ||
218 | } | ||
219 | |||
220 | string result = string.Empty; | ||
221 | UserProfilePick pick = new UserProfilePick(); | ||
222 | object Pick = (object)pick; | ||
223 | OSD.DeserializeMembers(ref Pick, (OSDMap)json["params"]); | ||
224 | if(Service.PicksUpdate(ref pick, ref result)) | ||
225 | { | ||
226 | response.Result = OSD.SerializeMembers(pick); | ||
227 | return true; | ||
228 | } | ||
229 | |||
230 | response.Error.Code = ErrorCode.InternalError; | ||
231 | response.Error.Message = "unable to update pick"; | ||
232 | |||
233 | return false; | ||
234 | } | ||
235 | |||
236 | public bool PicksDelete(OSDMap json, ref JsonRpcResponse response) | ||
237 | { | ||
238 | if(!json.ContainsKey("params")) | ||
239 | { | ||
240 | response.Error.Code = ErrorCode.ParseError; | ||
241 | m_log.DebugFormat ("Avatar Picks Delete Request"); | ||
242 | return false; | ||
243 | } | ||
244 | |||
245 | OSDMap request = (OSDMap)json["params"]; | ||
246 | UUID pickId = new UUID(request["pickId"].AsString()); | ||
247 | if(Service.PicksDelete(pickId)) | ||
248 | return true; | ||
249 | |||
250 | response.Error.Code = ErrorCode.InternalError; | ||
251 | response.Error.Message = "data error removing record"; | ||
252 | return false; | ||
253 | } | ||
254 | #endregion Picks | ||
255 | |||
256 | #region Notes | ||
257 | public bool AvatarNotesRequest(OSDMap json, ref JsonRpcResponse response) | ||
258 | { | ||
259 | if(!json.ContainsKey("params")) | ||
260 | { | ||
261 | response.Error.Code = ErrorCode.ParseError; | ||
262 | response.Error.Message = "Params missing"; | ||
263 | m_log.DebugFormat ("Avatar Notes Request"); | ||
264 | return false; | ||
265 | } | ||
266 | |||
267 | UserProfileNotes note = new UserProfileNotes(); | ||
268 | object Note = (object)note; | ||
269 | OSD.DeserializeMembers(ref Note, (OSDMap)json["params"]); | ||
270 | if(Service.AvatarNotesRequest(ref note)) | ||
271 | { | ||
272 | response.Result = OSD.SerializeMembers(note); | ||
273 | return true; | ||
274 | } | ||
275 | |||
276 | response.Error.Code = ErrorCode.InternalError; | ||
277 | response.Error.Message = "Error reading notes"; | ||
278 | return false; | ||
279 | } | ||
280 | |||
281 | public bool NotesUpdate(OSDMap json, ref JsonRpcResponse response) | ||
282 | { | ||
283 | if(!json.ContainsKey("params")) | ||
284 | { | ||
285 | response.Error.Code = ErrorCode.ParseError; | ||
286 | response.Error.Message = "No parameters"; | ||
287 | m_log.DebugFormat ("Avatar Notes Update Request"); | ||
288 | return false; | ||
289 | } | ||
290 | |||
291 | string result = string.Empty; | ||
292 | UserProfileNotes note = new UserProfileNotes(); | ||
293 | object Notes = (object) note; | ||
294 | OSD.DeserializeMembers(ref Notes, (OSDMap)json["params"]); | ||
295 | if(Service.NotesUpdate(ref note, ref result)) | ||
296 | { | ||
297 | response.Result = OSD.SerializeMembers(note); | ||
298 | return true; | ||
299 | } | ||
300 | return true; | ||
301 | } | ||
302 | #endregion Notes | ||
303 | |||
304 | #region Profile Properties | ||
305 | public bool AvatarPropertiesRequest(OSDMap json, ref JsonRpcResponse response) | ||
306 | { | ||
307 | if(!json.ContainsKey("params")) | ||
308 | { | ||
309 | response.Error.Code = ErrorCode.ParseError; | ||
310 | response.Error.Message = "no parameters supplied"; | ||
311 | m_log.DebugFormat ("Avatar Properties Request"); | ||
312 | return false; | ||
313 | } | ||
314 | |||
315 | string result = string.Empty; | ||
316 | UserProfileProperties props = new UserProfileProperties(); | ||
317 | object Props = (object)props; | ||
318 | OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]); | ||
319 | if(Service.AvatarPropertiesRequest(ref props, ref result)) | ||
320 | { | ||
321 | response.Result = OSD.SerializeMembers(props); | ||
322 | return true; | ||
323 | } | ||
324 | |||
325 | response.Error.Code = ErrorCode.InternalError; | ||
326 | response.Error.Message = string.Format("{0}", result); | ||
327 | return false; | ||
328 | } | ||
329 | |||
330 | public bool AvatarPropertiesUpdate(OSDMap json, ref JsonRpcResponse response) | ||
331 | { | ||
332 | if(!json.ContainsKey("params")) | ||
333 | { | ||
334 | response.Error.Code = ErrorCode.ParseError; | ||
335 | response.Error.Message = "no parameters supplied"; | ||
336 | m_log.DebugFormat ("Avatar Properties Update Request"); | ||
337 | return false; | ||
338 | } | ||
339 | |||
340 | string result = string.Empty; | ||
341 | UserProfileProperties props = new UserProfileProperties(); | ||
342 | object Props = (object)props; | ||
343 | OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]); | ||
344 | if(Service.AvatarPropertiesUpdate(ref props, ref result)) | ||
345 | { | ||
346 | response.Result = OSD.SerializeMembers(props); | ||
347 | return true; | ||
348 | } | ||
349 | |||
350 | response.Error.Code = ErrorCode.InternalError; | ||
351 | response.Error.Message = string.Format("{0}", result); | ||
352 | return false; | ||
353 | } | ||
354 | #endregion Profile Properties | ||
355 | |||
356 | #region Interests | ||
357 | public bool AvatarInterestsUpdate(OSDMap json, ref JsonRpcResponse response) | ||
358 | { | ||
359 | if(!json.ContainsKey("params")) | ||
360 | { | ||
361 | response.Error.Code = ErrorCode.ParseError; | ||
362 | response.Error.Message = "no parameters supplied"; | ||
363 | m_log.DebugFormat ("Avatar Interests Update Request"); | ||
364 | return false; | ||
365 | } | ||
366 | |||
367 | string result = string.Empty; | ||
368 | UserProfileProperties props = new UserProfileProperties(); | ||
369 | object Props = (object)props; | ||
370 | OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]); | ||
371 | if(Service.AvatarInterestsUpdate(props, ref result)) | ||
372 | { | ||
373 | response.Result = OSD.SerializeMembers(props); | ||
374 | return true; | ||
375 | } | ||
376 | |||
377 | response.Error.Code = ErrorCode.InternalError; | ||
378 | response.Error.Message = string.Format("{0}", result); | ||
379 | return false; | ||
380 | } | ||
381 | #endregion Interests | ||
382 | |||
383 | #region User Preferences | ||
384 | public bool UserPreferencesRequest(OSDMap json, ref JsonRpcResponse response) | ||
385 | { | ||
386 | if(!json.ContainsKey("params")) | ||
387 | { | ||
388 | response.Error.Code = ErrorCode.ParseError; | ||
389 | m_log.DebugFormat ("User Preferences Request"); | ||
390 | return false; | ||
391 | } | ||
392 | |||
393 | string result = string.Empty; | ||
394 | UserPreferences prefs = new UserPreferences(); | ||
395 | object Prefs = (object)prefs; | ||
396 | OSD.DeserializeMembers(ref Prefs, (OSDMap)json["params"]); | ||
397 | if(Service.UserPreferencesRequest(ref prefs, ref result)) | ||
398 | { | ||
399 | response.Result = OSD.SerializeMembers(prefs); | ||
400 | return true; | ||
401 | } | ||
402 | |||
403 | response.Error.Code = ErrorCode.InternalError; | ||
404 | response.Error.Message = string.Format("{0}", result); | ||
405 | // m_log.InfoFormat("[PROFILES]: User preferences request error - {0}", response.Error.Message); | ||
406 | return false; | ||
407 | } | ||
408 | |||
409 | public bool UserPreferenecesUpdate(OSDMap json, ref JsonRpcResponse response) | ||
410 | { | ||
411 | if(!json.ContainsKey("params")) | ||
412 | { | ||
413 | response.Error.Code = ErrorCode.ParseError; | ||
414 | response.Error.Message = "no parameters supplied"; | ||
415 | m_log.DebugFormat ("User Preferences Update Request"); | ||
416 | return false; | ||
417 | } | ||
418 | |||
419 | string result = string.Empty; | ||
420 | UserPreferences prefs = new UserPreferences(); | ||
421 | object Prefs = (object)prefs; | ||
422 | OSD.DeserializeMembers(ref Prefs, (OSDMap)json["params"]); | ||
423 | if(Service.UserPreferencesUpdate(ref prefs, ref result)) | ||
424 | { | ||
425 | response.Result = OSD.SerializeMembers(prefs); | ||
426 | return true; | ||
427 | } | ||
428 | |||
429 | response.Error.Code = ErrorCode.InternalError; | ||
430 | response.Error.Message = string.Format("{0}", result); | ||
431 | m_log.InfoFormat("[PROFILES]: User preferences update error - {0}", response.Error.Message); | ||
432 | return false; | ||
433 | } | ||
434 | #endregion User Preferences | ||
435 | |||
436 | #region Utility | ||
437 | public bool AvatarImageAssetsRequest(OSDMap json, ref JsonRpcResponse response) | ||
438 | { | ||
439 | if(!json.ContainsKey("params")) | ||
440 | { | ||
441 | response.Error.Code = ErrorCode.ParseError; | ||
442 | m_log.DebugFormat ("Avatar Image Assets Request"); | ||
443 | return false; | ||
444 | } | ||
445 | |||
446 | OSDMap request = (OSDMap)json["params"]; | ||
447 | UUID avatarId = new UUID(request["avatarId"].AsString()); | ||
448 | |||
449 | OSDArray data = (OSDArray) Service.AvatarImageAssetsRequest(avatarId); | ||
450 | response.Result = data; | ||
451 | |||
452 | return true; | ||
453 | } | ||
454 | #endregion Utiltiy | ||
455 | |||
456 | #region UserData | ||
457 | public bool RequestUserAppData(OSDMap json, ref JsonRpcResponse response) | ||
458 | { | ||
459 | if(!json.ContainsKey("params")) | ||
460 | { | ||
461 | response.Error.Code = ErrorCode.ParseError; | ||
462 | response.Error.Message = "no parameters supplied"; | ||
463 | m_log.DebugFormat ("User Application Service URL Request: No Parameters!"); | ||
464 | return false; | ||
465 | } | ||
466 | |||
467 | string result = string.Empty; | ||
468 | UserAppData props = new UserAppData(); | ||
469 | object Props = (object)props; | ||
470 | OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]); | ||
471 | if(Service.RequestUserAppData(ref props, ref result)) | ||
472 | { | ||
473 | OSDMap res = new OSDMap(); | ||
474 | res["result"] = OSD.FromString("success"); | ||
475 | res["token"] = OSD.FromString (result); | ||
476 | response.Result = res; | ||
477 | |||
478 | return true; | ||
479 | } | ||
480 | |||
481 | response.Error.Code = ErrorCode.InternalError; | ||
482 | response.Error.Message = string.Format("{0}", result); | ||
483 | return false; | ||
484 | } | ||
485 | |||
486 | public bool UpdateUserAppData(OSDMap json, ref JsonRpcResponse response) | ||
487 | { | ||
488 | if(!json.ContainsKey("params")) | ||
489 | { | ||
490 | response.Error.Code = ErrorCode.ParseError; | ||
491 | response.Error.Message = "no parameters supplied"; | ||
492 | m_log.DebugFormat ("User App Data Update Request"); | ||
493 | return false; | ||
494 | } | ||
495 | |||
496 | string result = string.Empty; | ||
497 | UserAppData props = new UserAppData(); | ||
498 | object Props = (object)props; | ||
499 | OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]); | ||
500 | if(Service.SetUserAppData(props, ref result)) | ||
501 | { | ||
502 | response.Result = OSD.SerializeMembers(props); | ||
503 | return true; | ||
504 | } | ||
505 | |||
506 | response.Error.Code = ErrorCode.InternalError; | ||
507 | response.Error.Message = string.Format("{0}", result); | ||
508 | return false; | ||
509 | } | ||
510 | #endregion UserData | ||
511 | } | ||
512 | } | ||
513 | |||
diff --git a/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs b/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..780e454 --- /dev/null +++ b/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Server.Handlers")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("6319afca-d740-4468-a95d-d7f87a081cb3")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.8.2.*")] | ||
33 | |||
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs new file mode 100644 index 0000000..e7544b5 --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | |||
@@ -0,0 +1,647 @@ | |||
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; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Collections.Specialized; | ||
32 | using System.IO; | ||
33 | using System.IO.Compression; | ||
34 | using System.Reflection; | ||
35 | using System.Net; | ||
36 | using System.Text; | ||
37 | using System.Web; | ||
38 | |||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Server.Handlers.Base; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
43 | using OpenSim.Framework; | ||
44 | using OpenSim.Framework.Servers.HttpServer; | ||
45 | |||
46 | using OpenMetaverse; | ||
47 | using OpenMetaverse.StructuredData; | ||
48 | using Nini.Config; | ||
49 | using log4net; | ||
50 | |||
51 | |||
52 | namespace OpenSim.Server.Handlers.Simulation | ||
53 | { | ||
54 | public class AgentHandler | ||
55 | { | ||
56 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
57 | |||
58 | private ISimulationService m_SimulationService; | ||
59 | |||
60 | public AgentHandler() { } | ||
61 | |||
62 | public AgentHandler(ISimulationService sim) | ||
63 | { | ||
64 | m_SimulationService = sim; | ||
65 | } | ||
66 | |||
67 | public Hashtable Handler(Hashtable request) | ||
68 | { | ||
69 | // m_log.Debug("[CONNECTION DEBUGGING]: AgentHandler Called"); | ||
70 | // | ||
71 | // m_log.Debug("---------------------------"); | ||
72 | // m_log.Debug(" >> uri=" + request["uri"]); | ||
73 | // m_log.Debug(" >> content-type=" + request["content-type"]); | ||
74 | // m_log.Debug(" >> http-method=" + request["http-method"]); | ||
75 | // m_log.Debug("---------------------------\n"); | ||
76 | |||
77 | Hashtable responsedata = new Hashtable(); | ||
78 | responsedata["content_type"] = "text/html"; | ||
79 | responsedata["keepalive"] = false; | ||
80 | |||
81 | |||
82 | UUID agentID; | ||
83 | UUID regionID; | ||
84 | string action; | ||
85 | if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action)) | ||
86 | { | ||
87 | m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]); | ||
88 | responsedata["int_response_code"] = 404; | ||
89 | responsedata["str_response_string"] = "false"; | ||
90 | |||
91 | return responsedata; | ||
92 | } | ||
93 | |||
94 | // Next, let's parse the verb | ||
95 | string method = (string)request["http-method"]; | ||
96 | if (method.Equals("DELETE")) | ||
97 | { | ||
98 | string auth_token = string.Empty; | ||
99 | if (request.ContainsKey("auth")) | ||
100 | auth_token = request["auth"].ToString(); | ||
101 | |||
102 | DoAgentDelete(request, responsedata, agentID, action, regionID, auth_token); | ||
103 | return responsedata; | ||
104 | } | ||
105 | else if (method.Equals("QUERYACCESS")) | ||
106 | { | ||
107 | DoQueryAccess(request, responsedata, agentID, regionID); | ||
108 | return responsedata; | ||
109 | } | ||
110 | else | ||
111 | { | ||
112 | m_log.ErrorFormat("[AGENT HANDLER]: method {0} not supported in agent message {1} (caller is {2})", method, (string)request["uri"], Util.GetCallerIP(request)); | ||
113 | responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; | ||
114 | responsedata["str_response_string"] = "Method not allowed"; | ||
115 | |||
116 | return responsedata; | ||
117 | } | ||
118 | |||
119 | } | ||
120 | |||
121 | protected virtual void DoQueryAccess(Hashtable request, Hashtable responsedata, UUID agentID, UUID regionID) | ||
122 | { | ||
123 | if (m_SimulationService == null) | ||
124 | { | ||
125 | m_log.Debug("[AGENT HANDLER]: Agent QUERY called. Harmless but useless."); | ||
126 | responsedata["content_type"] = "application/json"; | ||
127 | responsedata["int_response_code"] = HttpStatusCode.NotImplemented; | ||
128 | responsedata["str_response_string"] = string.Empty; | ||
129 | |||
130 | return; | ||
131 | } | ||
132 | |||
133 | // m_log.DebugFormat("[AGENT HANDLER]: Received QUERYACCESS with {0}", (string)request["body"]); | ||
134 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
135 | |||
136 | bool viaTeleport = true; | ||
137 | if (args.ContainsKey("viaTeleport")) | ||
138 | viaTeleport = args["viaTeleport"].AsBoolean(); | ||
139 | |||
140 | Vector3 position = Vector3.Zero; | ||
141 | if (args.ContainsKey("position")) | ||
142 | position = Vector3.Parse(args["position"].AsString()); | ||
143 | |||
144 | string agentHomeURI = null; | ||
145 | if (args.ContainsKey("agent_home_uri")) | ||
146 | agentHomeURI = args["agent_home_uri"].AsString(); | ||
147 | |||
148 | string theirVersion = string.Empty; | ||
149 | if (args.ContainsKey("my_version")) | ||
150 | theirVersion = args["my_version"].AsString(); | ||
151 | |||
152 | List<UUID> features = new List<UUID>(); | ||
153 | |||
154 | if (args.ContainsKey("features")) | ||
155 | { | ||
156 | OSDArray array = (OSDArray)args["features"]; | ||
157 | |||
158 | foreach (OSD o in array) | ||
159 | features.Add(new UUID(o.AsString())); | ||
160 | } | ||
161 | |||
162 | GridRegion destination = new GridRegion(); | ||
163 | destination.RegionID = regionID; | ||
164 | |||
165 | string reason; | ||
166 | string version; | ||
167 | bool result = m_SimulationService.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, theirVersion, features, out version, out reason); | ||
168 | |||
169 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
170 | |||
171 | OSDMap resp = new OSDMap(3); | ||
172 | |||
173 | resp["success"] = OSD.FromBoolean(result); | ||
174 | resp["reason"] = OSD.FromString(reason); | ||
175 | resp["version"] = OSD.FromString(version); | ||
176 | |||
177 | OSDArray featuresWanted = new OSDArray(); | ||
178 | foreach (UUID feature in features) | ||
179 | featuresWanted.Add(OSD.FromString(feature.ToString())); | ||
180 | |||
181 | resp["features"] = featuresWanted; | ||
182 | |||
183 | // We must preserve defaults here, otherwise a false "success" will not be put into the JSON map! | ||
184 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); | ||
185 | |||
186 | // Console.WriteLine("str_response_string [{0}]", responsedata["str_response_string"]); | ||
187 | } | ||
188 | |||
189 | protected void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID, string auth_token) | ||
190 | { | ||
191 | if (string.IsNullOrEmpty(action)) | ||
192 | m_log.DebugFormat("[AGENT HANDLER]: >>> DELETE <<< RegionID: {0}; from: {1}; auth_code: {2}", regionID, Util.GetCallerIP(request), auth_token); | ||
193 | else | ||
194 | m_log.DebugFormat("[AGENT HANDLER]: Release {0} to RegionID: {1}", id, regionID); | ||
195 | |||
196 | GridRegion destination = new GridRegion(); | ||
197 | destination.RegionID = regionID; | ||
198 | |||
199 | if (action.Equals("release")) | ||
200 | ReleaseAgent(regionID, id); | ||
201 | else | ||
202 | Util.FireAndForget( | ||
203 | o => m_SimulationService.CloseAgent(destination, id, auth_token), null, "AgentHandler.DoAgentDelete"); | ||
204 | |||
205 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
206 | responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); | ||
207 | |||
208 | //m_log.DebugFormat("[AGENT HANDLER]: Agent {0} Released/Deleted from region {1}", id, regionID); | ||
209 | } | ||
210 | |||
211 | protected virtual void ReleaseAgent(UUID regionID, UUID id) | ||
212 | { | ||
213 | m_SimulationService.ReleaseAgent(regionID, id, ""); | ||
214 | } | ||
215 | } | ||
216 | |||
217 | public class AgentPostHandler : BaseStreamHandler | ||
218 | { | ||
219 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
220 | |||
221 | private ISimulationService m_SimulationService; | ||
222 | protected bool m_Proxy = false; | ||
223 | |||
224 | public AgentPostHandler(ISimulationService service) : | ||
225 | base("POST", "/agent") | ||
226 | { | ||
227 | m_SimulationService = service; | ||
228 | } | ||
229 | |||
230 | public AgentPostHandler(string path) : | ||
231 | base("POST", path) | ||
232 | { | ||
233 | m_SimulationService = null; | ||
234 | } | ||
235 | |||
236 | protected override byte[] ProcessRequest(string path, Stream request, | ||
237 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
238 | { | ||
239 | // m_log.DebugFormat("[SIMULATION]: Stream handler called"); | ||
240 | |||
241 | Hashtable keysvals = new Hashtable(); | ||
242 | Hashtable headervals = new Hashtable(); | ||
243 | |||
244 | string[] querystringkeys = httpRequest.QueryString.AllKeys; | ||
245 | string[] rHeaders = httpRequest.Headers.AllKeys; | ||
246 | |||
247 | keysvals.Add("uri", httpRequest.RawUrl); | ||
248 | keysvals.Add("content-type", httpRequest.ContentType); | ||
249 | keysvals.Add("http-method", httpRequest.HttpMethod); | ||
250 | |||
251 | foreach (string queryname in querystringkeys) | ||
252 | keysvals.Add(queryname, httpRequest.QueryString[queryname]); | ||
253 | |||
254 | foreach (string headername in rHeaders) | ||
255 | headervals[headername] = httpRequest.Headers[headername]; | ||
256 | |||
257 | keysvals.Add("headers", headervals); | ||
258 | keysvals.Add("querystringkeys", querystringkeys); | ||
259 | |||
260 | httpResponse.StatusCode = 200; | ||
261 | httpResponse.ContentType = "text/html"; | ||
262 | httpResponse.KeepAlive = false; | ||
263 | Encoding encoding = Encoding.UTF8; | ||
264 | |||
265 | if (httpRequest.ContentType != "application/json") | ||
266 | { | ||
267 | httpResponse.StatusCode = 406; | ||
268 | return encoding.GetBytes("false"); | ||
269 | } | ||
270 | |||
271 | string requestBody; | ||
272 | |||
273 | Stream inputStream = request; | ||
274 | Stream innerStream = null; | ||
275 | try | ||
276 | { | ||
277 | if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip")) | ||
278 | { | ||
279 | innerStream = inputStream; | ||
280 | inputStream = new GZipStream(innerStream, CompressionMode.Decompress); | ||
281 | } | ||
282 | |||
283 | using (StreamReader reader = new StreamReader(inputStream, encoding)) | ||
284 | { | ||
285 | requestBody = reader.ReadToEnd(); | ||
286 | } | ||
287 | } | ||
288 | finally | ||
289 | { | ||
290 | if (innerStream != null) | ||
291 | innerStream.Dispose(); | ||
292 | inputStream.Dispose(); | ||
293 | } | ||
294 | |||
295 | keysvals.Add("body", requestBody); | ||
296 | |||
297 | Hashtable responsedata = new Hashtable(); | ||
298 | |||
299 | UUID agentID; | ||
300 | UUID regionID; | ||
301 | string action; | ||
302 | |||
303 | if (!Utils.GetParams((string)keysvals["uri"], out agentID, out regionID, out action)) | ||
304 | { | ||
305 | m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", keysvals["uri"]); | ||
306 | |||
307 | httpResponse.StatusCode = 404; | ||
308 | |||
309 | return encoding.GetBytes("false"); | ||
310 | } | ||
311 | |||
312 | DoAgentPost(keysvals, responsedata, agentID); | ||
313 | |||
314 | httpResponse.StatusCode = (int)responsedata["int_response_code"]; | ||
315 | return encoding.GetBytes((string)responsedata["str_response_string"]); | ||
316 | } | ||
317 | |||
318 | protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) | ||
319 | { | ||
320 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
321 | if (args == null) | ||
322 | { | ||
323 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
324 | responsedata["str_response_string"] = "Bad request"; | ||
325 | return; | ||
326 | } | ||
327 | |||
328 | AgentDestinationData data = CreateAgentDestinationData(); | ||
329 | UnpackData(args, data, request); | ||
330 | |||
331 | GridRegion destination = new GridRegion(); | ||
332 | destination.RegionID = data.uuid; | ||
333 | destination.RegionLocX = data.x; | ||
334 | destination.RegionLocY = data.y; | ||
335 | destination.RegionName = data.name; | ||
336 | |||
337 | GridRegion gatekeeper = ExtractGatekeeper(data); | ||
338 | |||
339 | AgentCircuitData aCircuit = new AgentCircuitData(); | ||
340 | try | ||
341 | { | ||
342 | aCircuit.UnpackAgentCircuitData(args); | ||
343 | } | ||
344 | catch (Exception ex) | ||
345 | { | ||
346 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message); | ||
347 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
348 | responsedata["str_response_string"] = "Bad request"; | ||
349 | return; | ||
350 | } | ||
351 | |||
352 | GridRegion source = null; | ||
353 | |||
354 | if (args.ContainsKey("source_uuid")) | ||
355 | { | ||
356 | source = new GridRegion(); | ||
357 | source.RegionLocX = Int32.Parse(args["source_x"].AsString()); | ||
358 | source.RegionLocY = Int32.Parse(args["source_y"].AsString()); | ||
359 | source.RegionName = args["source_name"].AsString(); | ||
360 | source.RegionID = UUID.Parse(args["source_uuid"].AsString()); | ||
361 | |||
362 | if (args.ContainsKey("source_server_uri")) | ||
363 | source.RawServerURI = args["source_server_uri"].AsString(); | ||
364 | else | ||
365 | source.RawServerURI = null; | ||
366 | } | ||
367 | |||
368 | OSDMap resp = new OSDMap(2); | ||
369 | string reason = String.Empty; | ||
370 | |||
371 | // This is the meaning of POST agent | ||
372 | //m_regionClient.AdjustUserInformation(aCircuit); | ||
373 | //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); | ||
374 | bool result = CreateAgent(source, gatekeeper, destination, aCircuit, data.flags, data.fromLogin, out reason); | ||
375 | |||
376 | resp["reason"] = OSD.FromString(reason); | ||
377 | resp["success"] = OSD.FromBoolean(result); | ||
378 | // Let's also send out the IP address of the caller back to the caller (HG 1.5) | ||
379 | resp["your_ip"] = OSD.FromString(GetCallerIP(request)); | ||
380 | |||
381 | // TODO: add reason if not String.Empty? | ||
382 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
383 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); | ||
384 | } | ||
385 | |||
386 | protected virtual AgentDestinationData CreateAgentDestinationData() | ||
387 | { | ||
388 | return new AgentDestinationData(); | ||
389 | } | ||
390 | |||
391 | protected virtual void UnpackData(OSDMap args, AgentDestinationData data, Hashtable request) | ||
392 | { | ||
393 | // retrieve the input arguments | ||
394 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
395 | Int32.TryParse(args["destination_x"].AsString(), out data.x); | ||
396 | else | ||
397 | m_log.WarnFormat(" -- request didn't have destination_x"); | ||
398 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
399 | Int32.TryParse(args["destination_y"].AsString(), out data.y); | ||
400 | else | ||
401 | m_log.WarnFormat(" -- request didn't have destination_y"); | ||
402 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
403 | UUID.TryParse(args["destination_uuid"].AsString(), out data.uuid); | ||
404 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
405 | data.name = args["destination_name"].ToString(); | ||
406 | if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null) | ||
407 | data.flags = args["teleport_flags"].AsUInteger(); | ||
408 | } | ||
409 | |||
410 | protected virtual GridRegion ExtractGatekeeper(AgentDestinationData data) | ||
411 | { | ||
412 | return null; | ||
413 | } | ||
414 | |||
415 | protected string GetCallerIP(Hashtable request) | ||
416 | { | ||
417 | if (!m_Proxy) | ||
418 | return Util.GetCallerIP(request); | ||
419 | |||
420 | // We're behind a proxy | ||
421 | Hashtable headers = (Hashtable)request["headers"]; | ||
422 | |||
423 | //// DEBUG | ||
424 | //foreach (object o in headers.Keys) | ||
425 | // m_log.DebugFormat("XXX {0} = {1}", o.ToString(), (headers[o] == null? "null" : headers[o].ToString())); | ||
426 | |||
427 | string xff = "X-Forwarded-For"; | ||
428 | if (headers.ContainsKey(xff.ToLower())) | ||
429 | xff = xff.ToLower(); | ||
430 | |||
431 | if (!headers.ContainsKey(xff) || headers[xff] == null) | ||
432 | { | ||
433 | m_log.WarnFormat("[AGENT HANDLER]: No XFF header"); | ||
434 | return Util.GetCallerIP(request); | ||
435 | } | ||
436 | |||
437 | m_log.DebugFormat("[AGENT HANDLER]: XFF is {0}", headers[xff]); | ||
438 | |||
439 | IPEndPoint ep = Util.GetClientIPFromXFF((string)headers[xff]); | ||
440 | if (ep != null) | ||
441 | return ep.Address.ToString(); | ||
442 | |||
443 | // Oops | ||
444 | return Util.GetCallerIP(request); | ||
445 | } | ||
446 | |||
447 | // subclasses can override this | ||
448 | protected virtual bool CreateAgent(GridRegion source, GridRegion gatekeeper, GridRegion destination, | ||
449 | AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason) | ||
450 | { | ||
451 | return m_SimulationService.CreateAgent(source, destination, aCircuit, teleportFlags, out reason); | ||
452 | } | ||
453 | } | ||
454 | |||
455 | public class AgentPutHandler : BaseStreamHandler | ||
456 | { | ||
457 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
458 | |||
459 | private ISimulationService m_SimulationService; | ||
460 | protected bool m_Proxy = false; | ||
461 | |||
462 | public AgentPutHandler(ISimulationService service) : | ||
463 | base("PUT", "/agent") | ||
464 | { | ||
465 | m_SimulationService = service; | ||
466 | } | ||
467 | |||
468 | public AgentPutHandler(string path) : | ||
469 | base("PUT", path) | ||
470 | { | ||
471 | m_SimulationService = null; | ||
472 | } | ||
473 | |||
474 | protected override byte[] ProcessRequest(string path, Stream request, | ||
475 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
476 | { | ||
477 | // m_log.DebugFormat("[SIMULATION]: Stream handler called"); | ||
478 | |||
479 | Hashtable keysvals = new Hashtable(); | ||
480 | Hashtable headervals = new Hashtable(); | ||
481 | |||
482 | string[] querystringkeys = httpRequest.QueryString.AllKeys; | ||
483 | string[] rHeaders = httpRequest.Headers.AllKeys; | ||
484 | |||
485 | keysvals.Add("uri", httpRequest.RawUrl); | ||
486 | keysvals.Add("content-type", httpRequest.ContentType); | ||
487 | keysvals.Add("http-method", httpRequest.HttpMethod); | ||
488 | |||
489 | foreach (string queryname in querystringkeys) | ||
490 | keysvals.Add(queryname, httpRequest.QueryString[queryname]); | ||
491 | |||
492 | foreach (string headername in rHeaders) | ||
493 | headervals[headername] = httpRequest.Headers[headername]; | ||
494 | |||
495 | keysvals.Add("headers", headervals); | ||
496 | keysvals.Add("querystringkeys", querystringkeys); | ||
497 | |||
498 | String requestBody; | ||
499 | Encoding encoding = Encoding.UTF8; | ||
500 | |||
501 | Stream inputStream = request; | ||
502 | Stream innerStream = null; | ||
503 | try | ||
504 | { | ||
505 | if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip")) | ||
506 | { | ||
507 | innerStream = inputStream; | ||
508 | inputStream = new GZipStream(innerStream, CompressionMode.Decompress); | ||
509 | } | ||
510 | |||
511 | using (StreamReader reader = new StreamReader(inputStream, encoding)) | ||
512 | { | ||
513 | requestBody = reader.ReadToEnd(); | ||
514 | } | ||
515 | } | ||
516 | finally | ||
517 | { | ||
518 | if (innerStream != null) | ||
519 | innerStream.Dispose(); | ||
520 | inputStream.Dispose(); | ||
521 | } | ||
522 | |||
523 | keysvals.Add("body", requestBody); | ||
524 | |||
525 | httpResponse.StatusCode = 200; | ||
526 | httpResponse.ContentType = "text/html"; | ||
527 | httpResponse.KeepAlive = false; | ||
528 | |||
529 | Hashtable responsedata = new Hashtable(); | ||
530 | |||
531 | UUID agentID; | ||
532 | UUID regionID; | ||
533 | string action; | ||
534 | |||
535 | if (!Utils.GetParams((string)keysvals["uri"], out agentID, out regionID, out action)) | ||
536 | { | ||
537 | m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", keysvals["uri"]); | ||
538 | |||
539 | httpResponse.StatusCode = 404; | ||
540 | |||
541 | return encoding.GetBytes("false"); | ||
542 | } | ||
543 | |||
544 | DoAgentPut(keysvals, responsedata); | ||
545 | |||
546 | httpResponse.StatusCode = (int)responsedata["int_response_code"]; | ||
547 | return encoding.GetBytes((string)responsedata["str_response_string"]); | ||
548 | } | ||
549 | |||
550 | protected void DoAgentPut(Hashtable request, Hashtable responsedata) | ||
551 | { | ||
552 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
553 | if (args == null) | ||
554 | { | ||
555 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
556 | responsedata["str_response_string"] = "Bad request"; | ||
557 | return; | ||
558 | } | ||
559 | |||
560 | // retrieve the input arguments | ||
561 | int x = 0, y = 0; | ||
562 | UUID uuid = UUID.Zero; | ||
563 | string regionname = string.Empty; | ||
564 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
565 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
566 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
567 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
568 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
569 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
570 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
571 | regionname = args["destination_name"].ToString(); | ||
572 | |||
573 | GridRegion destination = new GridRegion(); | ||
574 | destination.RegionID = uuid; | ||
575 | destination.RegionLocX = x; | ||
576 | destination.RegionLocY = y; | ||
577 | destination.RegionName = regionname; | ||
578 | |||
579 | string messageType; | ||
580 | if (args["message_type"] != null) | ||
581 | messageType = args["message_type"].AsString(); | ||
582 | else | ||
583 | { | ||
584 | m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. "); | ||
585 | messageType = "AgentData"; | ||
586 | } | ||
587 | |||
588 | bool result = true; | ||
589 | if ("AgentData".Equals(messageType)) | ||
590 | { | ||
591 | AgentData agent = new AgentData(); | ||
592 | try | ||
593 | { | ||
594 | agent.Unpack(args, m_SimulationService.GetScene(destination.RegionID)); | ||
595 | } | ||
596 | catch (Exception ex) | ||
597 | { | ||
598 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); | ||
599 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
600 | responsedata["str_response_string"] = "Bad request"; | ||
601 | return; | ||
602 | } | ||
603 | |||
604 | //agent.Dump(); | ||
605 | // This is one of the meanings of PUT agent | ||
606 | result = UpdateAgent(destination, agent); | ||
607 | } | ||
608 | else if ("AgentPosition".Equals(messageType)) | ||
609 | { | ||
610 | AgentPosition agent = new AgentPosition(); | ||
611 | try | ||
612 | { | ||
613 | agent.Unpack(args, m_SimulationService.GetScene(destination.RegionID)); | ||
614 | } | ||
615 | catch (Exception ex) | ||
616 | { | ||
617 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); | ||
618 | return; | ||
619 | } | ||
620 | //agent.Dump(); | ||
621 | // This is one of the meanings of PUT agent | ||
622 | result = m_SimulationService.UpdateAgent(destination, agent); | ||
623 | |||
624 | } | ||
625 | |||
626 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
627 | responsedata["str_response_string"] = result.ToString(); | ||
628 | //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead | ||
629 | } | ||
630 | |||
631 | // subclasses can override this | ||
632 | protected virtual bool UpdateAgent(GridRegion destination, AgentData agent) | ||
633 | { | ||
634 | return m_SimulationService.UpdateAgent(destination, agent); | ||
635 | } | ||
636 | } | ||
637 | |||
638 | public class AgentDestinationData | ||
639 | { | ||
640 | public int x; | ||
641 | public int y; | ||
642 | public string name; | ||
643 | public UUID uuid; | ||
644 | public uint flags; | ||
645 | public bool fromLogin; | ||
646 | } | ||
647 | } | ||
diff --git a/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs new file mode 100644 index 0000000..dbb1a15 --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs | |||
@@ -0,0 +1,218 @@ | |||
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; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Net; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Server.Handlers.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Servers.HttpServer; | ||
41 | |||
42 | using OpenMetaverse; | ||
43 | using OpenMetaverse.StructuredData; | ||
44 | using Nini.Config; | ||
45 | using log4net; | ||
46 | |||
47 | |||
48 | namespace OpenSim.Server.Handlers.Simulation | ||
49 | { | ||
50 | public class ObjectHandler | ||
51 | { | ||
52 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | private ISimulationService m_SimulationService; | ||
54 | |||
55 | public ObjectHandler() { } | ||
56 | |||
57 | public ObjectHandler(ISimulationService sim) | ||
58 | { | ||
59 | m_SimulationService = sim; | ||
60 | } | ||
61 | |||
62 | public Hashtable Handler(Hashtable request) | ||
63 | { | ||
64 | //m_log.Debug("[CONNECTION DEBUGGING]: ObjectHandler Called"); | ||
65 | |||
66 | //m_log.Debug("---------------------------"); | ||
67 | //m_log.Debug(" >> uri=" + request["uri"]); | ||
68 | //m_log.Debug(" >> content-type=" + request["content-type"]); | ||
69 | //m_log.Debug(" >> http-method=" + request["http-method"]); | ||
70 | //m_log.Debug("---------------------------\n"); | ||
71 | |||
72 | Hashtable responsedata = new Hashtable(); | ||
73 | responsedata["content_type"] = "text/html"; | ||
74 | |||
75 | UUID objectID; | ||
76 | UUID regionID; | ||
77 | string action; | ||
78 | if (!Utils.GetParams((string)request["uri"], out objectID, out regionID, out action)) | ||
79 | { | ||
80 | m_log.InfoFormat("[OBJECT HANDLER]: Invalid parameters for object message {0}", request["uri"]); | ||
81 | responsedata["int_response_code"] = 404; | ||
82 | responsedata["str_response_string"] = "false"; | ||
83 | |||
84 | return responsedata; | ||
85 | } | ||
86 | |||
87 | try | ||
88 | { | ||
89 | // Next, let's parse the verb | ||
90 | string method = (string)request["http-method"]; | ||
91 | if (method.Equals("POST")) | ||
92 | { | ||
93 | DoObjectPost(request, responsedata, regionID); | ||
94 | return responsedata; | ||
95 | } | ||
96 | //else if (method.Equals("DELETE")) | ||
97 | //{ | ||
98 | // DoObjectDelete(request, responsedata, agentID, action, regionHandle); | ||
99 | // return responsedata; | ||
100 | //} | ||
101 | else | ||
102 | { | ||
103 | m_log.InfoFormat("[OBJECT HANDLER]: method {0} not supported in object message", method); | ||
104 | responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; | ||
105 | responsedata["str_response_string"] = "Method not allowed"; | ||
106 | |||
107 | return responsedata; | ||
108 | } | ||
109 | } | ||
110 | catch (Exception e) | ||
111 | { | ||
112 | m_log.WarnFormat("[OBJECT HANDLER]: Caught exception {0}", e.StackTrace); | ||
113 | responsedata["int_response_code"] = HttpStatusCode.InternalServerError; | ||
114 | responsedata["str_response_string"] = "Internal server error"; | ||
115 | |||
116 | return responsedata; | ||
117 | |||
118 | } | ||
119 | } | ||
120 | |||
121 | protected void DoObjectPost(Hashtable request, Hashtable responsedata, UUID regionID) | ||
122 | { | ||
123 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
124 | if (args == null) | ||
125 | { | ||
126 | responsedata["int_response_code"] = 400; | ||
127 | responsedata["str_response_string"] = "false"; | ||
128 | return; | ||
129 | } | ||
130 | // retrieve the input arguments | ||
131 | int x = 0, y = 0; | ||
132 | UUID uuid = UUID.Zero; | ||
133 | string regionname = string.Empty; | ||
134 | Vector3 newPosition = Vector3.Zero; | ||
135 | |||
136 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
137 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
138 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
139 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
140 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
141 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
142 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
143 | regionname = args["destination_name"].ToString(); | ||
144 | if (args.ContainsKey("new_position") && args["new_position"] != null) | ||
145 | Vector3.TryParse(args["new_position"], out newPosition); | ||
146 | |||
147 | GridRegion destination = new GridRegion(); | ||
148 | destination.RegionID = uuid; | ||
149 | destination.RegionLocX = x; | ||
150 | destination.RegionLocY = y; | ||
151 | destination.RegionName = regionname; | ||
152 | |||
153 | string sogXmlStr = "", extraStr = "", stateXmlStr = ""; | ||
154 | if (args.ContainsKey("sog") && args["sog"] != null) | ||
155 | sogXmlStr = args["sog"].AsString(); | ||
156 | if (args.ContainsKey("extra") && args["extra"] != null) | ||
157 | extraStr = args["extra"].AsString(); | ||
158 | |||
159 | IScene s = m_SimulationService.GetScene(destination.RegionID); | ||
160 | ISceneObject sog = null; | ||
161 | try | ||
162 | { | ||
163 | //m_log.DebugFormat("[OBJECT HANDLER]: received {0}", sogXmlStr); | ||
164 | sog = s.DeserializeObject(sogXmlStr); | ||
165 | sog.ExtraFromXmlString(extraStr); | ||
166 | } | ||
167 | catch (Exception ex) | ||
168 | { | ||
169 | m_log.InfoFormat("[OBJECT HANDLER]: exception on deserializing scene object {0}", ex.Message); | ||
170 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
171 | responsedata["str_response_string"] = "Bad request"; | ||
172 | return; | ||
173 | } | ||
174 | |||
175 | if (args.ContainsKey("modified")) | ||
176 | sog.HasGroupChanged = args["modified"].AsBoolean(); | ||
177 | else | ||
178 | sog.HasGroupChanged = false; | ||
179 | |||
180 | if ((args["state"] != null) && s.AllowScriptCrossings) | ||
181 | { | ||
182 | stateXmlStr = args["state"].AsString(); | ||
183 | if (stateXmlStr != "") | ||
184 | { | ||
185 | try | ||
186 | { | ||
187 | sog.SetState(stateXmlStr, s); | ||
188 | } | ||
189 | catch (Exception ex) | ||
190 | { | ||
191 | m_log.InfoFormat("[OBJECT HANDLER]: exception on setting state for scene object {0}", ex.Message); | ||
192 | // ignore and continue | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | |||
197 | bool result = false; | ||
198 | try | ||
199 | { | ||
200 | // This is the meaning of POST object | ||
201 | result = CreateObject(destination, newPosition, sog); | ||
202 | } | ||
203 | catch (Exception e) | ||
204 | { | ||
205 | m_log.DebugFormat("[OBJECT HANDLER]: Exception in CreateObject: {0}", e.StackTrace); | ||
206 | } | ||
207 | |||
208 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
209 | responsedata["str_response_string"] = result.ToString(); | ||
210 | } | ||
211 | |||
212 | // subclasses can override this | ||
213 | protected virtual bool CreateObject(GridRegion destination, Vector3 newPosition, ISceneObject sog) | ||
214 | { | ||
215 | return m_SimulationService.CreateObject(destination, newPosition, sog, false); | ||
216 | } | ||
217 | } | ||
218 | } | ||
diff --git a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs new file mode 100644 index 0000000..0da08f8 --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs | |||
@@ -0,0 +1,58 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Framework.Servers.HttpServer; | ||
34 | using OpenSim.Server.Handlers.Base; | ||
35 | |||
36 | namespace OpenSim.Server.Handlers.Simulation | ||
37 | { | ||
38 | public class SimulationServiceInConnector : ServiceConnector | ||
39 | { | ||
40 | private ISimulationService m_LocalSimulationService; | ||
41 | // private IAuthenticationService m_AuthenticationService; | ||
42 | |||
43 | public SimulationServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) : | ||
44 | base(config, server, String.Empty) | ||
45 | { | ||
46 | m_LocalSimulationService = scene.RequestModuleInterface<ISimulationService>(); | ||
47 | m_LocalSimulationService = m_LocalSimulationService.GetInnerService(); | ||
48 | |||
49 | // This one MUST be a stream handler because compressed fatpacks | ||
50 | // are pure binary and shoehorning that into a string with UTF-8 | ||
51 | // encoding breaks it | ||
52 | server.AddStreamHandler(new AgentPostHandler(m_LocalSimulationService)); | ||
53 | server.AddStreamHandler(new AgentPutHandler(m_LocalSimulationService)); | ||
54 | server.AddHTTPHandler("/agent/", new AgentHandler(m_LocalSimulationService).Handler); | ||
55 | server.AddHTTPHandler("/object/", new ObjectHandler(m_LocalSimulationService).Handler); | ||
56 | } | ||
57 | } | ||
58 | } | ||
diff --git a/OpenSim/Server/Handlers/Simulation/Utils.cs b/OpenSim/Server/Handlers/Simulation/Utils.cs new file mode 100644 index 0000000..ed379da --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/Utils.cs | |||
@@ -0,0 +1,103 @@ | |||
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.Reflection; | ||
31 | |||
32 | using OpenMetaverse; | ||
33 | using OpenMetaverse.StructuredData; | ||
34 | |||
35 | using log4net; | ||
36 | |||
37 | namespace OpenSim.Server.Handlers.Simulation | ||
38 | { | ||
39 | public class Utils | ||
40 | { | ||
41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
42 | |||
43 | /// <summary> | ||
44 | /// Extract the param from an uri. | ||
45 | /// </summary> | ||
46 | /// <param name="uri">Something like this: /agent/uuid/ or /agent/uuid/handle/release</param> | ||
47 | /// <param name="uri">uuid on uuid field</param> | ||
48 | /// <param name="action">optional action</param> | ||
49 | public static bool GetParams(string uri, out UUID uuid, out UUID regionID, out string action) | ||
50 | { | ||
51 | uuid = UUID.Zero; | ||
52 | regionID = UUID.Zero; | ||
53 | action = ""; | ||
54 | |||
55 | uri = uri.Trim(new char[] { '/' }); | ||
56 | string[] parts = uri.Split('/'); | ||
57 | if (parts.Length <= 1) | ||
58 | { | ||
59 | return false; | ||
60 | } | ||
61 | else | ||
62 | { | ||
63 | if (!UUID.TryParse(parts[1], out uuid)) | ||
64 | return false; | ||
65 | |||
66 | if (parts.Length >= 3) | ||
67 | UUID.TryParse(parts[2], out regionID); | ||
68 | if (parts.Length >= 4) | ||
69 | action = parts[3]; | ||
70 | |||
71 | return true; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | public static OSDMap GetOSDMap(string data) | ||
76 | { | ||
77 | OSDMap args = null; | ||
78 | try | ||
79 | { | ||
80 | OSD buffer; | ||
81 | // We should pay attention to the content-type, but let's assume we know it's Json | ||
82 | buffer = OSDParser.DeserializeJson(data); | ||
83 | if (buffer.Type == OSDType.Map) | ||
84 | { | ||
85 | args = (OSDMap)buffer; | ||
86 | return args; | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | // uh? | ||
91 | m_log.Debug(("[REST COMMS]: Got OSD of unexpected type " + buffer.Type.ToString())); | ||
92 | return null; | ||
93 | } | ||
94 | } | ||
95 | catch (Exception ex) | ||
96 | { | ||
97 | m_log.Debug("[REST COMMS]: exception on parse of REST message " + ex.Message); | ||
98 | return null; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | } | ||
103 | } | ||
diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs new file mode 100644 index 0000000..e95e3dc --- /dev/null +++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs | |||
@@ -0,0 +1,64 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Framework.ServiceAuth; | ||
34 | using OpenSim.Server.Handlers.Base; | ||
35 | |||
36 | namespace OpenSim.Server.Handlers.UserAccounts | ||
37 | { | ||
38 | public class UserAccountServiceConnector : ServiceConnector | ||
39 | { | ||
40 | private IUserAccountService m_UserAccountService; | ||
41 | private string m_ConfigName = "UserAccountService"; | ||
42 | |||
43 | public UserAccountServiceConnector(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", | ||
51 | String.Empty); | ||
52 | |||
53 | if (service == String.Empty) | ||
54 | throw new Exception("No LocalServiceModule in config file"); | ||
55 | |||
56 | Object[] args = new Object[] { config }; | ||
57 | m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(service, args); | ||
58 | |||
59 | IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); | ||
60 | |||
61 | server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService, serverConfig, auth)); | ||
62 | } | ||
63 | } | ||
64 | } | ||
diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs new file mode 100644 index 0000000..21eb790 --- /dev/null +++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs | |||
@@ -0,0 +1,348 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using System.Collections.Generic; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Services.UserAccountService; | ||
42 | using OpenSim.Framework; | ||
43 | using OpenSim.Framework.Servers.HttpServer; | ||
44 | using OpenSim.Framework.ServiceAuth; | ||
45 | using OpenMetaverse; | ||
46 | |||
47 | namespace OpenSim.Server.Handlers.UserAccounts | ||
48 | { | ||
49 | public class UserAccountServerPostHandler : BaseStreamHandler | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | private IUserAccountService m_UserAccountService; | ||
54 | private bool m_AllowCreateUser = false; | ||
55 | private bool m_AllowSetAccount = false; | ||
56 | |||
57 | public UserAccountServerPostHandler(IUserAccountService service) | ||
58 | : this(service, null, null) {} | ||
59 | |||
60 | public UserAccountServerPostHandler(IUserAccountService service, IConfig config, IServiceAuth auth) : | ||
61 | base("POST", "/accounts", auth) | ||
62 | { | ||
63 | m_UserAccountService = service; | ||
64 | |||
65 | if (config != null) | ||
66 | { | ||
67 | m_AllowCreateUser = config.GetBoolean("AllowCreateUser", m_AllowCreateUser); | ||
68 | m_AllowSetAccount = config.GetBoolean("AllowSetAccount", m_AllowSetAccount); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
73 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
74 | { | ||
75 | StreamReader sr = new StreamReader(requestData); | ||
76 | string body = sr.ReadToEnd(); | ||
77 | sr.Close(); | ||
78 | body = body.Trim(); | ||
79 | |||
80 | // We need to check the authorization header | ||
81 | //httpRequest.Headers["authorization"] ... | ||
82 | |||
83 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
84 | string method = string.Empty; | ||
85 | try | ||
86 | { | ||
87 | Dictionary<string, object> request = | ||
88 | ServerUtils.ParseQueryString(body); | ||
89 | |||
90 | if (!request.ContainsKey("METHOD")) | ||
91 | return FailureResult(); | ||
92 | |||
93 | method = request["METHOD"].ToString(); | ||
94 | |||
95 | switch (method) | ||
96 | { | ||
97 | case "createuser": | ||
98 | if (m_AllowCreateUser) | ||
99 | return CreateUser(request); | ||
100 | else | ||
101 | break; | ||
102 | case "getaccount": | ||
103 | return GetAccount(request); | ||
104 | case "getaccounts": | ||
105 | return GetAccounts(request); | ||
106 | case "setaccount": | ||
107 | if (m_AllowSetAccount) | ||
108 | return StoreAccount(request); | ||
109 | else | ||
110 | break; | ||
111 | } | ||
112 | |||
113 | m_log.DebugFormat("[USER SERVICE HANDLER]: unknown method request: {0}", method); | ||
114 | } | ||
115 | catch (Exception e) | ||
116 | { | ||
117 | m_log.DebugFormat("[USER SERVICE HANDLER]: Exception in method {0}: {1}", method, e); | ||
118 | } | ||
119 | |||
120 | return FailureResult(); | ||
121 | } | ||
122 | |||
123 | byte[] GetAccount(Dictionary<string, object> request) | ||
124 | { | ||
125 | UserAccount account = null; | ||
126 | UUID scopeID = UUID.Zero; | ||
127 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
128 | |||
129 | if (request.ContainsKey("ScopeID") && !UUID.TryParse(request["ScopeID"].ToString(), out scopeID)) | ||
130 | { | ||
131 | result["result"] = "null"; | ||
132 | return ResultToBytes(result); | ||
133 | } | ||
134 | |||
135 | if (request.ContainsKey("UserID") && request["UserID"] != null) | ||
136 | { | ||
137 | UUID userID; | ||
138 | if (UUID.TryParse(request["UserID"].ToString(), out userID)) | ||
139 | account = m_UserAccountService.GetUserAccount(scopeID, userID); | ||
140 | } | ||
141 | else if (request.ContainsKey("PrincipalID") && request["PrincipalID"] != null) | ||
142 | { | ||
143 | UUID userID; | ||
144 | if (UUID.TryParse(request["PrincipalID"].ToString(), out userID)) | ||
145 | account = m_UserAccountService.GetUserAccount(scopeID, userID); | ||
146 | } | ||
147 | else if (request.ContainsKey("Email") && request["Email"] != null) | ||
148 | { | ||
149 | account = m_UserAccountService.GetUserAccount(scopeID, request["Email"].ToString()); | ||
150 | } | ||
151 | else if (request.ContainsKey("FirstName") && request.ContainsKey("LastName") && | ||
152 | request["FirstName"] != null && request["LastName"] != null) | ||
153 | { | ||
154 | account = m_UserAccountService.GetUserAccount(scopeID, request["FirstName"].ToString(), request["LastName"].ToString()); | ||
155 | } | ||
156 | |||
157 | if (account == null) | ||
158 | { | ||
159 | result["result"] = "null"; | ||
160 | } | ||
161 | else | ||
162 | { | ||
163 | result["result"] = account.ToKeyValuePairs(); | ||
164 | } | ||
165 | |||
166 | return ResultToBytes(result); | ||
167 | } | ||
168 | |||
169 | byte[] GetAccounts(Dictionary<string, object> request) | ||
170 | { | ||
171 | if (!request.ContainsKey("query")) | ||
172 | return FailureResult(); | ||
173 | |||
174 | UUID scopeID = UUID.Zero; | ||
175 | if (request.ContainsKey("ScopeID") && !UUID.TryParse(request["ScopeID"].ToString(), out scopeID)) | ||
176 | return FailureResult(); | ||
177 | |||
178 | string query = request["query"].ToString(); | ||
179 | |||
180 | List<UserAccount> accounts = m_UserAccountService.GetUserAccounts(scopeID, query); | ||
181 | |||
182 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
183 | if ((accounts == null) || ((accounts != null) && (accounts.Count == 0))) | ||
184 | { | ||
185 | result["result"] = "null"; | ||
186 | } | ||
187 | else | ||
188 | { | ||
189 | int i = 0; | ||
190 | foreach (UserAccount acc in accounts) | ||
191 | { | ||
192 | Dictionary<string, object> rinfoDict = acc.ToKeyValuePairs(); | ||
193 | result["account" + i] = rinfoDict; | ||
194 | i++; | ||
195 | } | ||
196 | } | ||
197 | |||
198 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
199 | |||
200 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
201 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
202 | } | ||
203 | |||
204 | byte[] StoreAccount(Dictionary<string, object> request) | ||
205 | { | ||
206 | UUID principalID = UUID.Zero; | ||
207 | if (request.ContainsKey("PrincipalID") && !UUID.TryParse(request["PrincipalID"].ToString(), out principalID)) | ||
208 | return FailureResult(); | ||
209 | |||
210 | UUID scopeID = UUID.Zero; | ||
211 | if (request.ContainsKey("ScopeID") && !UUID.TryParse(request["ScopeID"].ToString(), out scopeID)) | ||
212 | return FailureResult(); | ||
213 | |||
214 | UserAccount existingAccount = m_UserAccountService.GetUserAccount(scopeID, principalID); | ||
215 | if (existingAccount == null) | ||
216 | return FailureResult(); | ||
217 | |||
218 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
219 | |||
220 | if (request.ContainsKey("FirstName")) | ||
221 | existingAccount.FirstName = request["FirstName"].ToString(); | ||
222 | |||
223 | if (request.ContainsKey("LastName")) | ||
224 | existingAccount.LastName = request["LastName"].ToString(); | ||
225 | |||
226 | if (request.ContainsKey("Email")) | ||
227 | existingAccount.Email = request["Email"].ToString(); | ||
228 | |||
229 | int created = 0; | ||
230 | if (request.ContainsKey("Created") && int.TryParse(request["Created"].ToString(), out created)) | ||
231 | existingAccount.Created = created; | ||
232 | |||
233 | int userLevel = 0; | ||
234 | if (request.ContainsKey("UserLevel") && int.TryParse(request["UserLevel"].ToString(), out userLevel)) | ||
235 | existingAccount.UserLevel = userLevel; | ||
236 | |||
237 | int userFlags = 0; | ||
238 | if (request.ContainsKey("UserFlags") && int.TryParse(request["UserFlags"].ToString(), out userFlags)) | ||
239 | existingAccount.UserFlags = userFlags; | ||
240 | |||
241 | if (request.ContainsKey("UserTitle")) | ||
242 | existingAccount.UserTitle = request["UserTitle"].ToString(); | ||
243 | |||
244 | if (!m_UserAccountService.StoreUserAccount(existingAccount)) | ||
245 | { | ||
246 | m_log.ErrorFormat( | ||
247 | "[USER ACCOUNT SERVER POST HANDLER]: Account store failed for account {0} {1} {2}", | ||
248 | existingAccount.FirstName, existingAccount.LastName, existingAccount.PrincipalID); | ||
249 | |||
250 | return FailureResult(); | ||
251 | } | ||
252 | |||
253 | result["result"] = existingAccount.ToKeyValuePairs(); | ||
254 | |||
255 | return ResultToBytes(result); | ||
256 | } | ||
257 | |||
258 | byte[] CreateUser(Dictionary<string, object> request) | ||
259 | { | ||
260 | if (! request.ContainsKey("FirstName") | ||
261 | && request.ContainsKey("LastName") | ||
262 | && request.ContainsKey("Password")) | ||
263 | return FailureResult(); | ||
264 | |||
265 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
266 | |||
267 | UUID scopeID = UUID.Zero; | ||
268 | if (request.ContainsKey("ScopeID") && !UUID.TryParse(request["ScopeID"].ToString(), out scopeID)) | ||
269 | return FailureResult(); | ||
270 | |||
271 | UUID principalID = UUID.Random(); | ||
272 | if (request.ContainsKey("PrincipalID") && !UUID.TryParse(request["PrincipalID"].ToString(), out principalID)) | ||
273 | return FailureResult(); | ||
274 | |||
275 | string firstName = request["FirstName"].ToString(); | ||
276 | string lastName = request["LastName"].ToString(); | ||
277 | string password = request["Password"].ToString(); | ||
278 | |||
279 | string email = ""; | ||
280 | if (request.ContainsKey("Email")) | ||
281 | email = request["Email"].ToString(); | ||
282 | |||
283 | UserAccount createdUserAccount = null; | ||
284 | |||
285 | if (m_UserAccountService is UserAccountService) | ||
286 | createdUserAccount | ||
287 | = ((UserAccountService)m_UserAccountService).CreateUser( | ||
288 | scopeID, principalID, firstName, lastName, password, email); | ||
289 | |||
290 | if (createdUserAccount == null) | ||
291 | return FailureResult(); | ||
292 | |||
293 | result["result"] = createdUserAccount.ToKeyValuePairs(); | ||
294 | |||
295 | return ResultToBytes(result); | ||
296 | } | ||
297 | |||
298 | private byte[] SuccessResult() | ||
299 | { | ||
300 | XmlDocument doc = new XmlDocument(); | ||
301 | |||
302 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
303 | "", ""); | ||
304 | |||
305 | doc.AppendChild(xmlnode); | ||
306 | |||
307 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
308 | ""); | ||
309 | |||
310 | doc.AppendChild(rootElement); | ||
311 | |||
312 | XmlElement result = doc.CreateElement("", "result", ""); | ||
313 | result.AppendChild(doc.CreateTextNode("Success")); | ||
314 | |||
315 | rootElement.AppendChild(result); | ||
316 | |||
317 | return Util.DocToBytes(doc); | ||
318 | } | ||
319 | |||
320 | private byte[] FailureResult() | ||
321 | { | ||
322 | XmlDocument doc = new XmlDocument(); | ||
323 | |||
324 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
325 | "", ""); | ||
326 | |||
327 | doc.AppendChild(xmlnode); | ||
328 | |||
329 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
330 | ""); | ||
331 | |||
332 | doc.AppendChild(rootElement); | ||
333 | |||
334 | XmlElement result = doc.CreateElement("", "result", ""); | ||
335 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
336 | |||
337 | rootElement.AppendChild(result); | ||
338 | |||
339 | return Util.DocToBytes(doc); | ||
340 | } | ||
341 | |||
342 | private byte[] ResultToBytes(Dictionary<string, object> result) | ||
343 | { | ||
344 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
345 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
346 | } | ||
347 | } | ||
348 | } \ No newline at end of file | ||