diff options
Diffstat (limited to 'OpenSim/Server')
30 files changed, 3729 insertions, 515 deletions
diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs index a5d28a4..a399672 100644 --- a/OpenSim/Server/Base/ServerUtils.cs +++ b/OpenSim/Server/Base/ServerUtils.cs | |||
@@ -34,55 +34,13 @@ using System.Text; | |||
34 | using System.Collections.Generic; | 34 | using System.Collections.Generic; |
35 | using log4net; | 35 | using log4net; |
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenMetaverse; | ||
37 | 38 | ||
38 | namespace OpenSim.Server.Base | 39 | namespace OpenSim.Server.Base |
39 | { | 40 | { |
40 | public static class ServerUtils | 41 | public static class ServerUtils |
41 | { | 42 | { |
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
43 | |||
44 | public static string SLAssetTypeToContentType(int assetType) | ||
45 | { | ||
46 | switch (assetType) | ||
47 | { | ||
48 | case 0: | ||
49 | return "image/jp2"; | ||
50 | case 1: | ||
51 | return "application/ogg"; | ||
52 | case 2: | ||
53 | return "application/x-metaverse-callingcard"; | ||
54 | case 3: | ||
55 | return "application/x-metaverse-landmark"; | ||
56 | case 5: | ||
57 | return "application/x-metaverse-clothing"; | ||
58 | case 6: | ||
59 | return "application/x-metaverse-primitive"; | ||
60 | case 7: | ||
61 | return "application/x-metaverse-notecard"; | ||
62 | case 8: | ||
63 | return "application/x-metaverse-folder"; | ||
64 | case 10: | ||
65 | return "application/x-metaverse-lsl"; | ||
66 | case 11: | ||
67 | return "application/x-metaverse-lso"; | ||
68 | case 12: | ||
69 | return "image/tga"; | ||
70 | case 13: | ||
71 | return "application/x-metaverse-bodypart"; | ||
72 | case 17: | ||
73 | return "audio/x-wav"; | ||
74 | case 19: | ||
75 | return "image/jpeg"; | ||
76 | case 20: | ||
77 | return "application/x-metaverse-animation"; | ||
78 | case 21: | ||
79 | return "application/x-metaverse-gesture"; | ||
80 | case 22: | ||
81 | return "application/x-metaverse-simstate"; | ||
82 | default: | ||
83 | return "application/octet-stream"; | ||
84 | } | ||
85 | } | ||
86 | 44 | ||
87 | public static byte[] SerializeResult(XmlSerializer xs, object data) | 45 | public static byte[] SerializeResult(XmlSerializer xs, object data) |
88 | { | 46 | { |
@@ -99,6 +57,12 @@ namespace OpenSim.Server.Base | |||
99 | return ret; | 57 | return ret; |
100 | } | 58 | } |
101 | 59 | ||
60 | /// <summary> | ||
61 | /// Load a plugin from a dll with the given class or interface | ||
62 | /// </summary> | ||
63 | /// <param name="dllName"></param> | ||
64 | /// <param name="args">The arguments which control which constructor is invoked on the plugin</param> | ||
65 | /// <returns></returns> | ||
102 | public static T LoadPlugin<T>(string dllName, Object[] args) where T:class | 66 | public static T LoadPlugin<T>(string dllName, Object[] args) where T:class |
103 | { | 67 | { |
104 | string[] parts = dllName.Split(new char[] {':'}); | 68 | string[] parts = dllName.Split(new char[] {':'}); |
@@ -113,6 +77,13 @@ namespace OpenSim.Server.Base | |||
113 | return LoadPlugin<T>(dllName, className, args); | 77 | return LoadPlugin<T>(dllName, className, args); |
114 | } | 78 | } |
115 | 79 | ||
80 | /// <summary> | ||
81 | /// Load a plugin from a dll with the given class or interface | ||
82 | /// </summary> | ||
83 | /// <param name="dllName"></param> | ||
84 | /// <param name="className"></param> | ||
85 | /// <param name="args">The arguments which control which constructor is invoked on the plugin</param> | ||
86 | /// <returns></returns> | ||
116 | public static T LoadPlugin<T>(string dllName, string className, Object[] args) where T:class | 87 | public static T LoadPlugin<T>(string dllName, string className, Object[] args) where T:class |
117 | { | 88 | { |
118 | string interfaceName = typeof(T).ToString(); | 89 | string interfaceName = typeof(T).ToString(); |
@@ -125,28 +96,15 @@ namespace OpenSim.Server.Base | |||
125 | { | 96 | { |
126 | if (pluginType.IsPublic) | 97 | if (pluginType.IsPublic) |
127 | { | 98 | { |
128 | if (className != String.Empty && | 99 | if (className != String.Empty |
129 | pluginType.ToString() != | 100 | && pluginType.ToString() != pluginType.Namespace + "." + className) |
130 | pluginType.Namespace + "." + className) | ||
131 | continue; | 101 | continue; |
132 | Type typeInterface = | 102 | |
133 | pluginType.GetInterface(interfaceName, true); | 103 | Type typeInterface = pluginType.GetInterface(interfaceName, true); |
104 | |||
134 | if (typeInterface != null) | 105 | if (typeInterface != null) |
135 | { | 106 | { |
136 | T plug = null; | 107 | return (T)Activator.CreateInstance(pluginType, args); |
137 | try | ||
138 | { | ||
139 | plug = (T)Activator.CreateInstance(pluginType, | ||
140 | args); | ||
141 | } | ||
142 | catch (Exception e) | ||
143 | { | ||
144 | if (!(e is System.MissingMethodException)) | ||
145 | m_log.ErrorFormat("Error loading plugin from {0}, exception {1}", dllName, e.InnerException); | ||
146 | return null; | ||
147 | } | ||
148 | |||
149 | return plug; | ||
150 | } | 108 | } |
151 | } | 109 | } |
152 | } | 110 | } |
@@ -155,7 +113,7 @@ namespace OpenSim.Server.Base | |||
155 | } | 113 | } |
156 | catch (Exception e) | 114 | catch (Exception e) |
157 | { | 115 | { |
158 | m_log.ErrorFormat("Error loading plugin from {0}, exception {1}", dllName, e); | 116 | m_log.Error(string.Format("Error loading plugin from {0}", dllName), e); |
159 | return null; | 117 | return null; |
160 | } | 118 | } |
161 | } | 119 | } |
@@ -182,12 +140,13 @@ namespace OpenSim.Server.Base | |||
182 | 140 | ||
183 | if (name.EndsWith("[]")) | 141 | if (name.EndsWith("[]")) |
184 | { | 142 | { |
185 | if (result.ContainsKey(name)) | 143 | string cleanName = name.Substring(0, name.Length - 2); |
144 | if (result.ContainsKey(cleanName)) | ||
186 | { | 145 | { |
187 | if (!(result[name] is List<string>)) | 146 | if (!(result[cleanName] is List<string>)) |
188 | continue; | 147 | continue; |
189 | 148 | ||
190 | List<string> l = (List<string>)result[name]; | 149 | List<string> l = (List<string>)result[cleanName]; |
191 | 150 | ||
192 | l.Add(value); | 151 | l.Add(value); |
193 | } | 152 | } |
@@ -197,7 +156,7 @@ namespace OpenSim.Server.Base | |||
197 | 156 | ||
198 | newList.Add(value); | 157 | newList.Add(value); |
199 | 158 | ||
200 | result[name] = newList; | 159 | result[cleanName] = newList; |
201 | } | 160 | } |
202 | } | 161 | } |
203 | else | 162 | else |
@@ -278,6 +237,9 @@ namespace OpenSim.Server.Base | |||
278 | { | 237 | { |
279 | foreach (KeyValuePair<string, object> kvp in data) | 238 | foreach (KeyValuePair<string, object> kvp in data) |
280 | { | 239 | { |
240 | if (kvp.Value == null) | ||
241 | continue; | ||
242 | |||
281 | XmlElement elem = parent.OwnerDocument.CreateElement("", | 243 | XmlElement elem = parent.OwnerDocument.CreateElement("", |
282 | kvp.Key, ""); | 244 | kvp.Key, ""); |
283 | 245 | ||
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs index fe0da0b..43c1693 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs | |||
@@ -91,7 +91,7 @@ namespace OpenSim.Server.Handlers.Asset | |||
91 | 91 | ||
92 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | 92 | httpResponse.StatusCode = (int)HttpStatusCode.OK; |
93 | httpResponse.ContentType = | 93 | httpResponse.ContentType = |
94 | ServerUtils.SLAssetTypeToContentType(metadata.Type); | 94 | SLUtil.SLAssetTypeToContentType(metadata.Type); |
95 | } | 95 | } |
96 | else | 96 | else |
97 | { | 97 | { |
@@ -111,7 +111,7 @@ namespace OpenSim.Server.Handlers.Asset | |||
111 | 111 | ||
112 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | 112 | httpResponse.StatusCode = (int)HttpStatusCode.OK; |
113 | httpResponse.ContentType = | 113 | httpResponse.ContentType = |
114 | ServerUtils.SLAssetTypeToContentType(asset.Type); | 114 | SLUtil.SLAssetTypeToContentType(asset.Type); |
115 | } | 115 | } |
116 | else | 116 | else |
117 | { | 117 | { |
diff --git a/OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs b/OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs index 2abef0a..adb1e5b 100644 --- a/OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs +++ b/OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs | |||
@@ -49,7 +49,7 @@ namespace OpenSim.Server.Handlers.Authentication | |||
49 | if (serverConfig == null) | 49 | if (serverConfig == null) |
50 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | 50 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); |
51 | 51 | ||
52 | string authenticationService = serverConfig.GetString("AuthenticationServiceModule", | 52 | string authenticationService = serverConfig.GetString("LocalServiceModule", |
53 | String.Empty); | 53 | String.Empty); |
54 | 54 | ||
55 | if (authenticationService == String.Empty) | 55 | if (authenticationService == String.Empty) |
diff --git a/OpenSim/Server/Handlers/Authentication/OpenIdServerConnector.cs b/OpenSim/Server/Handlers/Authentication/OpenIdServerConnector.cs new file mode 100644 index 0000000..a0a92ed --- /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>(authService, 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..e73961b --- /dev/null +++ b/OpenSim/Server/Handlers/Authentication/OpenIdServerHandler.cs | |||
@@ -0,0 +1,345 @@ | |||
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 : 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 | public string ContentType { get { return m_contentType; } } | ||
195 | public string HttpMethod { get { return m_httpMethod; } } | ||
196 | public string Path { get { return m_path; } } | ||
197 | |||
198 | string m_contentType; | ||
199 | string m_httpMethod; | ||
200 | string m_path; | ||
201 | IAuthenticationService m_authenticationService; | ||
202 | IUserAccountService m_userAccountService; | ||
203 | ProviderMemoryStore m_openidStore = new ProviderMemoryStore(); | ||
204 | |||
205 | /// <summary> | ||
206 | /// Constructor | ||
207 | /// </summary> | ||
208 | public OpenIdStreamHandler(string httpMethod, string path, IUserAccountService userService, IAuthenticationService authService) | ||
209 | { | ||
210 | m_authenticationService = authService; | ||
211 | m_userAccountService = userService; | ||
212 | m_httpMethod = httpMethod; | ||
213 | m_path = path; | ||
214 | |||
215 | m_contentType = "text/html"; | ||
216 | } | ||
217 | |||
218 | /// <summary> | ||
219 | /// Handles all GET and POST requests for OpenID identifier pages and endpoint | ||
220 | /// server communication | ||
221 | /// </summary> | ||
222 | public void Handle(string path, Stream request, Stream response, OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
223 | { | ||
224 | Uri providerEndpoint = new Uri(String.Format("{0}://{1}{2}", httpRequest.Url.Scheme, httpRequest.Url.Authority, httpRequest.Url.AbsolutePath)); | ||
225 | |||
226 | // Defult to returning HTML content | ||
227 | m_contentType = "text/html"; | ||
228 | |||
229 | try | ||
230 | { | ||
231 | NameValueCollection postQuery = HttpUtility.ParseQueryString(new StreamReader(httpRequest.InputStream).ReadToEnd()); | ||
232 | NameValueCollection getQuery = HttpUtility.ParseQueryString(httpRequest.Url.Query); | ||
233 | NameValueCollection openIdQuery = (postQuery.GetValues("openid.mode") != null ? postQuery : getQuery); | ||
234 | |||
235 | OpenIdProvider provider = new OpenIdProvider(m_openidStore, providerEndpoint, httpRequest.Url, openIdQuery); | ||
236 | |||
237 | if (provider.Request != null) | ||
238 | { | ||
239 | if (!provider.Request.IsResponseReady && provider.Request is IAuthenticationRequest) | ||
240 | { | ||
241 | IAuthenticationRequest authRequest = (IAuthenticationRequest)provider.Request; | ||
242 | string[] passwordValues = postQuery.GetValues("pass"); | ||
243 | |||
244 | UserAccount account; | ||
245 | if (TryGetAccount(new Uri(authRequest.ClaimedIdentifier.ToString()), out account)) | ||
246 | { | ||
247 | // Check for form POST data | ||
248 | if (passwordValues != null && passwordValues.Length == 1) | ||
249 | { | ||
250 | if (account != null && | ||
251 | (m_authenticationService.Authenticate(account.PrincipalID, passwordValues[0], 30) != string.Empty)) | ||
252 | authRequest.IsAuthenticated = true; | ||
253 | else | ||
254 | authRequest.IsAuthenticated = false; | ||
255 | } | ||
256 | else | ||
257 | { | ||
258 | // Authentication was requested, send the client a login form | ||
259 | using (StreamWriter writer = new StreamWriter(response)) | ||
260 | writer.Write(String.Format(LOGIN_PAGE, account.FirstName, account.LastName)); | ||
261 | return; | ||
262 | } | ||
263 | } | ||
264 | else | ||
265 | { | ||
266 | // Cannot find an avatar matching the claimed identifier | ||
267 | authRequest.IsAuthenticated = false; | ||
268 | } | ||
269 | } | ||
270 | |||
271 | // Add OpenID headers to the response | ||
272 | foreach (string key in provider.Request.Response.Headers.Keys) | ||
273 | httpResponse.AddHeader(key, provider.Request.Response.Headers[key]); | ||
274 | |||
275 | string[] contentTypeValues = provider.Request.Response.Headers.GetValues("Content-Type"); | ||
276 | if (contentTypeValues != null && contentTypeValues.Length == 1) | ||
277 | m_contentType = contentTypeValues[0]; | ||
278 | |||
279 | // Set the response code and document body based on the OpenID result | ||
280 | httpResponse.StatusCode = (int)provider.Request.Response.Code; | ||
281 | response.Write(provider.Request.Response.Body, 0, provider.Request.Response.Body.Length); | ||
282 | response.Close(); | ||
283 | } | ||
284 | else if (httpRequest.Url.AbsolutePath.Contains("/openid/server")) | ||
285 | { | ||
286 | // Standard HTTP GET was made on the OpenID endpoint, send the client the default error page | ||
287 | using (StreamWriter writer = new StreamWriter(response)) | ||
288 | writer.Write(ENDPOINT_PAGE); | ||
289 | } | ||
290 | else | ||
291 | { | ||
292 | // Try and lookup this avatar | ||
293 | UserAccount account; | ||
294 | if (TryGetAccount(httpRequest.Url, out account)) | ||
295 | { | ||
296 | using (StreamWriter writer = new StreamWriter(response)) | ||
297 | { | ||
298 | // TODO: Print out a full profile page for this avatar | ||
299 | writer.Write(String.Format(OPENID_PAGE, httpRequest.Url.Scheme, | ||
300 | httpRequest.Url.Authority, account.FirstName, account.LastName)); | ||
301 | } | ||
302 | } | ||
303 | else | ||
304 | { | ||
305 | // Couldn't parse an avatar name, or couldn't find the avatar in the user server | ||
306 | using (StreamWriter writer = new StreamWriter(response)) | ||
307 | writer.Write(INVALID_OPENID_PAGE); | ||
308 | } | ||
309 | } | ||
310 | } | ||
311 | catch (Exception ex) | ||
312 | { | ||
313 | httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError; | ||
314 | using (StreamWriter writer = new StreamWriter(response)) | ||
315 | writer.Write(ex.Message); | ||
316 | } | ||
317 | } | ||
318 | |||
319 | /// <summary> | ||
320 | /// Parse a URL with a relative path of the form /users/First_Last and try to | ||
321 | /// retrieve the profile matching that avatar name | ||
322 | /// </summary> | ||
323 | /// <param name="requestUrl">URL to parse for an avatar name</param> | ||
324 | /// <param name="profile">Profile data for the avatar</param> | ||
325 | /// <returns>True if the parse and lookup were successful, otherwise false</returns> | ||
326 | bool TryGetAccount(Uri requestUrl, out UserAccount account) | ||
327 | { | ||
328 | if (requestUrl.Segments.Length == 3 && requestUrl.Segments[1] == "users/") | ||
329 | { | ||
330 | // Parse the avatar name from the path | ||
331 | string username = requestUrl.Segments[requestUrl.Segments.Length - 1]; | ||
332 | string[] name = username.Split('_'); | ||
333 | |||
334 | if (name.Length == 2) | ||
335 | { | ||
336 | account = m_userAccountService.GetUserAccount(UUID.Zero, name[0], name[1]); | ||
337 | return (account != null); | ||
338 | } | ||
339 | } | ||
340 | |||
341 | account = null; | ||
342 | return false; | ||
343 | } | ||
344 | } | ||
345 | } | ||
diff --git a/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs b/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs new file mode 100644 index 0000000..9a57cd9 --- /dev/null +++ b/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs | |||
@@ -0,0 +1,61 @@ | |||
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.Avatar | ||
36 | { | ||
37 | public class AvatarServiceConnector : ServiceConnector | ||
38 | { | ||
39 | private IAvatarService m_AvatarService; | ||
40 | private string m_ConfigName = "AvatarService"; | ||
41 | |||
42 | public AvatarServiceConnector(IConfigSource config, IHttpServer server, string configName) : | ||
43 | base(config, server, configName) | ||
44 | { | ||
45 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
46 | if (serverConfig == null) | ||
47 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | ||
48 | |||
49 | string avatarService = serverConfig.GetString("LocalServiceModule", | ||
50 | String.Empty); | ||
51 | |||
52 | if (avatarService == String.Empty) | ||
53 | throw new Exception("No LocalServiceModule in config file"); | ||
54 | |||
55 | Object[] args = new Object[] { config }; | ||
56 | m_AvatarService = ServerUtils.LoadPlugin<IAvatarService>(avatarService, args); | ||
57 | |||
58 | server.AddStreamHandler(new AvatarServerPostHandler(m_AvatarService)); | ||
59 | } | ||
60 | } | ||
61 | } | ||
diff --git a/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs new file mode 100644 index 0000000..49c2e43 --- /dev/null +++ b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs | |||
@@ -0,0 +1,269 @@ | |||
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 OpenMetaverse; | ||
44 | |||
45 | namespace OpenSim.Server.Handlers.Avatar | ||
46 | { | ||
47 | public class AvatarServerPostHandler : BaseStreamHandler | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private IAvatarService m_AvatarService; | ||
52 | |||
53 | public AvatarServerPostHandler(IAvatarService service) : | ||
54 | base("POST", "/avatar") | ||
55 | { | ||
56 | m_AvatarService = service; | ||
57 | } | ||
58 | |||
59 | public override byte[] Handle(string path, Stream requestData, | ||
60 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
61 | { | ||
62 | StreamReader sr = new StreamReader(requestData); | ||
63 | string body = sr.ReadToEnd(); | ||
64 | sr.Close(); | ||
65 | body = body.Trim(); | ||
66 | |||
67 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
68 | |||
69 | try | ||
70 | { | ||
71 | Dictionary<string, object> request = | ||
72 | ServerUtils.ParseQueryString(body); | ||
73 | |||
74 | if (!request.ContainsKey("METHOD")) | ||
75 | return FailureResult(); | ||
76 | |||
77 | string method = request["METHOD"].ToString(); | ||
78 | |||
79 | switch (method) | ||
80 | { | ||
81 | case "getavatar": | ||
82 | return GetAvatar(request); | ||
83 | case "setavatar": | ||
84 | return SetAvatar(request); | ||
85 | case "resetavatar": | ||
86 | return ResetAvatar(request); | ||
87 | case "setitems": | ||
88 | return SetItems(request); | ||
89 | case "removeitems": | ||
90 | return RemoveItems(request); | ||
91 | } | ||
92 | m_log.DebugFormat("[AVATAR HANDLER]: unknown method request: {0}", method); | ||
93 | } | ||
94 | catch (Exception e) | ||
95 | { | ||
96 | m_log.Debug("[AVATAR HANDLER]: Exception {0}" + e); | ||
97 | } | ||
98 | |||
99 | return FailureResult(); | ||
100 | |||
101 | } | ||
102 | |||
103 | byte[] GetAvatar(Dictionary<string, object> request) | ||
104 | { | ||
105 | UUID user = UUID.Zero; | ||
106 | |||
107 | if (!request.ContainsKey("UserID")) | ||
108 | return FailureResult(); | ||
109 | |||
110 | if (UUID.TryParse(request["UserID"].ToString(), out user)) | ||
111 | { | ||
112 | AvatarData avatar = m_AvatarService.GetAvatar(user); | ||
113 | if (avatar == null) | ||
114 | return FailureResult(); | ||
115 | |||
116 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
117 | if (avatar == null) | ||
118 | result["result"] = "null"; | ||
119 | else | ||
120 | result["result"] = avatar.ToKeyValuePairs(); | ||
121 | |||
122 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
123 | |||
124 | UTF8Encoding encoding = new UTF8Encoding(); | ||
125 | return encoding.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 | AvatarData avatar = new AvatarData(request); | ||
142 | if (m_AvatarService.SetAvatar(user, avatar)) | ||
143 | return SuccessResult(); | ||
144 | |||
145 | return FailureResult(); | ||
146 | } | ||
147 | |||
148 | byte[] ResetAvatar(Dictionary<string, object> request) | ||
149 | { | ||
150 | UUID user = UUID.Zero; | ||
151 | if (!request.ContainsKey("UserID")) | ||
152 | return FailureResult(); | ||
153 | |||
154 | if (!UUID.TryParse(request["UserID"].ToString(), out user)) | ||
155 | return FailureResult(); | ||
156 | |||
157 | if (m_AvatarService.ResetAvatar(user)) | ||
158 | return SuccessResult(); | ||
159 | |||
160 | return FailureResult(); | ||
161 | } | ||
162 | |||
163 | byte[] SetItems(Dictionary<string, object> request) | ||
164 | { | ||
165 | UUID user = UUID.Zero; | ||
166 | string[] names, values; | ||
167 | |||
168 | if (!request.ContainsKey("UserID") || !request.ContainsKey("Names") || !request.ContainsKey("Values")) | ||
169 | return FailureResult(); | ||
170 | |||
171 | if (!UUID.TryParse(request["UserID"].ToString(), out user)) | ||
172 | return FailureResult(); | ||
173 | |||
174 | if (!(request["Names"] is List<string> || request["Values"] is List<string>)) | ||
175 | return FailureResult(); | ||
176 | |||
177 | List<string> _names = (List<string>)request["Names"]; | ||
178 | names = _names.ToArray(); | ||
179 | List<string> _values = (List<string>)request["Values"]; | ||
180 | values = _values.ToArray(); | ||
181 | |||
182 | if (m_AvatarService.SetItems(user, names, values)) | ||
183 | return SuccessResult(); | ||
184 | |||
185 | return FailureResult(); | ||
186 | } | ||
187 | |||
188 | byte[] RemoveItems(Dictionary<string, object> request) | ||
189 | { | ||
190 | UUID user = UUID.Zero; | ||
191 | string[] names; | ||
192 | |||
193 | if (!request.ContainsKey("UserID") || !request.ContainsKey("Names")) | ||
194 | return FailureResult(); | ||
195 | |||
196 | if (!UUID.TryParse(request["UserID"].ToString(), out user)) | ||
197 | return FailureResult(); | ||
198 | |||
199 | if (!(request["Names"] is List<string>)) | ||
200 | return FailureResult(); | ||
201 | |||
202 | List<string> _names = (List<string>)request["Names"]; | ||
203 | names = _names.ToArray(); | ||
204 | |||
205 | if (m_AvatarService.RemoveItems(user, names)) | ||
206 | return SuccessResult(); | ||
207 | |||
208 | return FailureResult(); | ||
209 | } | ||
210 | |||
211 | |||
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 DocToBytes(doc); | ||
233 | } | ||
234 | |||
235 | private byte[] FailureResult() | ||
236 | { | ||
237 | XmlDocument doc = new XmlDocument(); | ||
238 | |||
239 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
240 | "", ""); | ||
241 | |||
242 | doc.AppendChild(xmlnode); | ||
243 | |||
244 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
245 | ""); | ||
246 | |||
247 | doc.AppendChild(rootElement); | ||
248 | |||
249 | XmlElement result = doc.CreateElement("", "result", ""); | ||
250 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
251 | |||
252 | rootElement.AppendChild(result); | ||
253 | |||
254 | return DocToBytes(doc); | ||
255 | } | ||
256 | |||
257 | private byte[] DocToBytes(XmlDocument doc) | ||
258 | { | ||
259 | MemoryStream ms = new MemoryStream(); | ||
260 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
261 | xw.Formatting = Formatting.Indented; | ||
262 | doc.WriteTo(xw); | ||
263 | xw.Flush(); | ||
264 | |||
265 | return ms.ToArray(); | ||
266 | } | ||
267 | |||
268 | } | ||
269 | } | ||
diff --git a/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs b/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs new file mode 100644 index 0000000..074f869 --- /dev/null +++ b/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs | |||
@@ -0,0 +1,61 @@ | |||
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.Friends | ||
36 | { | ||
37 | public class FriendsServiceConnector : ServiceConnector | ||
38 | { | ||
39 | private IFriendsService m_FriendsService; | ||
40 | private string m_ConfigName = "FriendsService"; | ||
41 | |||
42 | public FriendsServiceConnector(IConfigSource config, IHttpServer server, string configName) : | ||
43 | base(config, server, configName) | ||
44 | { | ||
45 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
46 | if (serverConfig == null) | ||
47 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | ||
48 | |||
49 | string gridService = serverConfig.GetString("LocalServiceModule", | ||
50 | String.Empty); | ||
51 | |||
52 | if (gridService == String.Empty) | ||
53 | throw new Exception("No LocalServiceModule in config file"); | ||
54 | |||
55 | Object[] args = new Object[] { config }; | ||
56 | m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(gridService, args); | ||
57 | |||
58 | server.AddStreamHandler(new FriendsServerPostHandler(m_FriendsService)); | ||
59 | } | ||
60 | } | ||
61 | } | ||
diff --git a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs new file mode 100644 index 0000000..b168bb3 --- /dev/null +++ b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs | |||
@@ -0,0 +1,238 @@ | |||
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.Servers.HttpServer; | ||
44 | using OpenMetaverse; | ||
45 | |||
46 | namespace OpenSim.Server.Handlers.Friends | ||
47 | { | ||
48 | public class FriendsServerPostHandler : BaseStreamHandler | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private IFriendsService m_FriendsService; | ||
53 | |||
54 | public FriendsServerPostHandler(IFriendsService service) : | ||
55 | base("POST", "/friends") | ||
56 | { | ||
57 | m_FriendsService = service; | ||
58 | } | ||
59 | |||
60 | public override byte[] Handle(string path, Stream requestData, | ||
61 | OSHttpRequest httpRequest, OSHttpResponse 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 "getfriends": | ||
83 | return GetFriends(request); | ||
84 | |||
85 | case "storefriend": | ||
86 | return StoreFriend(request); | ||
87 | |||
88 | case "deletefriend": | ||
89 | return DeleteFriend(request); | ||
90 | |||
91 | } | ||
92 | m_log.DebugFormat("[FRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method); | ||
93 | } | ||
94 | catch (Exception e) | ||
95 | { | ||
96 | m_log.DebugFormat("[FRIENDS HANDLER]: Exception {0}", e); | ||
97 | } | ||
98 | |||
99 | return FailureResult(); | ||
100 | |||
101 | } | ||
102 | |||
103 | #region Method-specific handlers | ||
104 | |||
105 | byte[] GetFriends(Dictionary<string, object> request) | ||
106 | { | ||
107 | UUID principalID = UUID.Zero; | ||
108 | if (request.ContainsKey("PRINCIPALID")) | ||
109 | UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID); | ||
110 | else | ||
111 | m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to get friends"); | ||
112 | |||
113 | FriendInfo[] finfos = m_FriendsService.GetFriends(principalID); | ||
114 | //m_log.DebugFormat("[FRIENDS HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); | ||
115 | |||
116 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
117 | if ((finfos == null) || ((finfos != null) && (finfos.Length == 0))) | ||
118 | result["result"] = "null"; | ||
119 | else | ||
120 | { | ||
121 | int i = 0; | ||
122 | foreach (FriendInfo finfo in finfos) | ||
123 | { | ||
124 | Dictionary<string, object> rinfoDict = finfo.ToKeyValuePairs(); | ||
125 | result["friend" + i] = rinfoDict; | ||
126 | i++; | ||
127 | } | ||
128 | } | ||
129 | |||
130 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
131 | //m_log.DebugFormat("[FRIENDS HANDLER]: resp string: {0}", xmlString); | ||
132 | UTF8Encoding encoding = new UTF8Encoding(); | ||
133 | return encoding.GetBytes(xmlString); | ||
134 | |||
135 | } | ||
136 | |||
137 | byte[] StoreFriend(Dictionary<string, object> request) | ||
138 | { | ||
139 | FriendInfo friend = new FriendInfo(request); | ||
140 | |||
141 | bool success = m_FriendsService.StoreFriend(friend.PrincipalID, friend.Friend, friend.MyFlags); | ||
142 | |||
143 | if (success) | ||
144 | return SuccessResult(); | ||
145 | else | ||
146 | return FailureResult(); | ||
147 | } | ||
148 | |||
149 | byte[] DeleteFriend(Dictionary<string, object> request) | ||
150 | { | ||
151 | UUID principalID = UUID.Zero; | ||
152 | if (request.ContainsKey("PRINCIPALID")) | ||
153 | UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID); | ||
154 | else | ||
155 | m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to delete friend"); | ||
156 | string friend = string.Empty; | ||
157 | if (request.ContainsKey("FRIEND")) | ||
158 | friend = request["FRIEND"].ToString(); | ||
159 | |||
160 | bool success = m_FriendsService.Delete(principalID, friend); | ||
161 | if (success) | ||
162 | return SuccessResult(); | ||
163 | else | ||
164 | return FailureResult(); | ||
165 | } | ||
166 | |||
167 | #endregion | ||
168 | |||
169 | #region Misc | ||
170 | |||
171 | private byte[] SuccessResult() | ||
172 | { | ||
173 | XmlDocument doc = new XmlDocument(); | ||
174 | |||
175 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
176 | "", ""); | ||
177 | |||
178 | doc.AppendChild(xmlnode); | ||
179 | |||
180 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
181 | ""); | ||
182 | |||
183 | doc.AppendChild(rootElement); | ||
184 | |||
185 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
186 | result.AppendChild(doc.CreateTextNode("Success")); | ||
187 | |||
188 | rootElement.AppendChild(result); | ||
189 | |||
190 | return DocToBytes(doc); | ||
191 | } | ||
192 | |||
193 | private byte[] FailureResult() | ||
194 | { | ||
195 | return FailureResult(String.Empty); | ||
196 | } | ||
197 | |||
198 | private byte[] FailureResult(string msg) | ||
199 | { | ||
200 | XmlDocument doc = new XmlDocument(); | ||
201 | |||
202 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
203 | "", ""); | ||
204 | |||
205 | doc.AppendChild(xmlnode); | ||
206 | |||
207 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
208 | ""); | ||
209 | |||
210 | doc.AppendChild(rootElement); | ||
211 | |||
212 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
213 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
214 | |||
215 | rootElement.AppendChild(result); | ||
216 | |||
217 | XmlElement message = doc.CreateElement("", "Message", ""); | ||
218 | message.AppendChild(doc.CreateTextNode(msg)); | ||
219 | |||
220 | rootElement.AppendChild(message); | ||
221 | |||
222 | return DocToBytes(doc); | ||
223 | } | ||
224 | |||
225 | private byte[] DocToBytes(XmlDocument doc) | ||
226 | { | ||
227 | MemoryStream ms = new MemoryStream(); | ||
228 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
229 | xw.Formatting = Formatting.Indented; | ||
230 | doc.WriteTo(xw); | ||
231 | xw.Flush(); | ||
232 | |||
233 | return ms.ToArray(); | ||
234 | } | ||
235 | |||
236 | #endregion | ||
237 | } | ||
238 | } | ||
diff --git a/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs new file mode 100644 index 0000000..d1233dc --- /dev/null +++ b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs | |||
@@ -0,0 +1,154 @@ | |||
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.Text; | ||
34 | using log4net; | ||
35 | using Nini.Config; | ||
36 | using Nwc.XmlRpc; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Servers.HttpServer; | ||
39 | |||
40 | namespace OpenSim.Server.Handlers.Grid | ||
41 | { | ||
42 | public class GridInfoHandlers | ||
43 | { | ||
44 | private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | private Hashtable _info = new Hashtable(); | ||
47 | |||
48 | /// <summary> | ||
49 | /// Instantiate a GridInfoService object. | ||
50 | /// </summary> | ||
51 | /// <param name="configPath">path to config path containing | ||
52 | /// grid information</param> | ||
53 | /// <remarks> | ||
54 | /// GridInfoService uses the [GridInfo] section of the | ||
55 | /// standard OpenSim.ini file --- which is not optimal, but | ||
56 | /// anything else requires a general redesign of the config | ||
57 | /// system. | ||
58 | /// </remarks> | ||
59 | public GridInfoHandlers(IConfigSource configSource) | ||
60 | { | ||
61 | loadGridInfo(configSource); | ||
62 | } | ||
63 | |||
64 | private void loadGridInfo(IConfigSource configSource) | ||
65 | { | ||
66 | _info["platform"] = "OpenSim"; | ||
67 | try | ||
68 | { | ||
69 | IConfig startupCfg = configSource.Configs["Startup"]; | ||
70 | IConfig gridCfg = configSource.Configs["GridInfoService"]; | ||
71 | IConfig netCfg = configSource.Configs["Network"]; | ||
72 | |||
73 | bool grid = startupCfg.GetBoolean("gridmode", false); | ||
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 | if (grid) | ||
85 | _info["login"] | ||
86 | = netCfg.GetString( | ||
87 | "user_server_url", "http://127.0.0.1:" + ConfigSettings.DefaultUserServerHttpPort.ToString()); | ||
88 | else | ||
89 | _info["login"] | ||
90 | = String.Format( | ||
91 | "http://127.0.0.1:{0}/", | ||
92 | netCfg.GetString( | ||
93 | "http_listener_port", ConfigSettings.DefaultRegionHttpPort.ToString())); | ||
94 | |||
95 | IssueWarning(); | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | _info["login"] = "http://127.0.0.1:9000/"; | ||
100 | IssueWarning(); | ||
101 | } | ||
102 | } | ||
103 | catch (Exception) | ||
104 | { | ||
105 | _log.Debug("[GRID INFO SERVICE]: Cannot get grid info from config source, using minimal defaults"); | ||
106 | } | ||
107 | |||
108 | _log.DebugFormat("[GRID INFO SERVICE]: Grid info service initialized with {0} keys", _info.Count); | ||
109 | |||
110 | } | ||
111 | |||
112 | private void IssueWarning() | ||
113 | { | ||
114 | _log.Warn("[GRID INFO SERVICE]: found no [GridInfo] section in your OpenSim.ini"); | ||
115 | _log.Warn("[GRID INFO SERVICE]: trying to guess sensible defaults, you might want to provide better ones:"); | ||
116 | |||
117 | foreach (string k in _info.Keys) | ||
118 | { | ||
119 | _log.WarnFormat("[GRID INFO SERVICE]: {0}: {1}", k, _info[k]); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request, IPEndPoint remoteClient) | ||
124 | { | ||
125 | XmlRpcResponse response = new XmlRpcResponse(); | ||
126 | Hashtable responseData = new Hashtable(); | ||
127 | |||
128 | _log.Info("[GRID INFO SERVICE]: Request for grid info"); | ||
129 | |||
130 | foreach (string k in _info.Keys) | ||
131 | { | ||
132 | responseData[k] = _info[k]; | ||
133 | } | ||
134 | response.Value = responseData; | ||
135 | |||
136 | return response; | ||
137 | } | ||
138 | |||
139 | public string RestGetGridInfoMethod(string request, string path, string param, | ||
140 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
141 | { | ||
142 | StringBuilder sb = new StringBuilder(); | ||
143 | |||
144 | sb.Append("<gridinfo>\n"); | ||
145 | foreach (string k in _info.Keys) | ||
146 | { | ||
147 | sb.AppendFormat("<{0}>{1}</{0}>\n", k, _info[k]); | ||
148 | } | ||
149 | sb.Append("</gridinfo>\n"); | ||
150 | |||
151 | return sb.ToString(); | ||
152 | } | ||
153 | } | ||
154 | } | ||
diff --git a/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs new file mode 100644 index 0000000..c9e80d9 --- /dev/null +++ b/OpenSim/Server/Handlers/Grid/GridInfoServerInConnector.cs | |||
@@ -0,0 +1,55 @@ | |||
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.AddXmlRPCHandler("get_grid_info", handlers.XmlRpcGridInfoMethod); | ||
52 | } | ||
53 | |||
54 | } | ||
55 | } | ||
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs index 85a8738..c90dd6f 100644 --- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs | |||
@@ -103,6 +103,14 @@ namespace OpenSim.Server.Handlers.Grid | |||
103 | case "get_region_range": | 103 | case "get_region_range": |
104 | return GetRegionRange(request); | 104 | return GetRegionRange(request); |
105 | 105 | ||
106 | case "get_default_regions": | ||
107 | return GetDefaultRegions(request); | ||
108 | |||
109 | case "get_fallback_regions": | ||
110 | return GetFallbackRegions(request); | ||
111 | |||
112 | case "get_region_flags": | ||
113 | return GetRegionFlags(request); | ||
106 | } | 114 | } |
107 | m_log.DebugFormat("[GRID HANDLER]: unknown method {0} request {1}", method.Length, method); | 115 | m_log.DebugFormat("[GRID HANDLER]: unknown method {0} request {1}", method.Length, method); |
108 | } | 116 | } |
@@ -404,6 +412,104 @@ namespace OpenSim.Server.Handlers.Grid | |||
404 | return encoding.GetBytes(xmlString); | 412 | return encoding.GetBytes(xmlString); |
405 | } | 413 | } |
406 | 414 | ||
415 | byte[] GetDefaultRegions(Dictionary<string, object> request) | ||
416 | { | ||
417 | //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions"); | ||
418 | UUID scopeID = UUID.Zero; | ||
419 | if (request.ContainsKey("SCOPEID")) | ||
420 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
421 | else | ||
422 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range"); | ||
423 | |||
424 | List<GridRegion> rinfos = m_GridService.GetDefaultRegions(scopeID); | ||
425 | |||
426 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
427 | if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) | ||
428 | result["result"] = "null"; | ||
429 | else | ||
430 | { | ||
431 | int i = 0; | ||
432 | foreach (GridRegion rinfo in rinfos) | ||
433 | { | ||
434 | Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs(); | ||
435 | result["region" + i] = rinfoDict; | ||
436 | i++; | ||
437 | } | ||
438 | } | ||
439 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
440 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
441 | UTF8Encoding encoding = new UTF8Encoding(); | ||
442 | return encoding.GetBytes(xmlString); | ||
443 | } | ||
444 | |||
445 | byte[] GetFallbackRegions(Dictionary<string, object> request) | ||
446 | { | ||
447 | //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange"); | ||
448 | UUID scopeID = UUID.Zero; | ||
449 | if (request.ContainsKey("SCOPEID")) | ||
450 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
451 | else | ||
452 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get fallback regions"); | ||
453 | |||
454 | int x = 0, y = 0; | ||
455 | if (request.ContainsKey("X")) | ||
456 | Int32.TryParse(request["X"].ToString(), out x); | ||
457 | else | ||
458 | m_log.WarnFormat("[GRID HANDLER]: no X in request to get fallback regions"); | ||
459 | if (request.ContainsKey("Y")) | ||
460 | Int32.TryParse(request["Y"].ToString(), out y); | ||
461 | else | ||
462 | m_log.WarnFormat("[GRID HANDLER]: no Y in request to get fallback regions"); | ||
463 | |||
464 | |||
465 | List<GridRegion> rinfos = m_GridService.GetFallbackRegions(scopeID, x, y); | ||
466 | |||
467 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
468 | if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0))) | ||
469 | result["result"] = "null"; | ||
470 | else | ||
471 | { | ||
472 | int i = 0; | ||
473 | foreach (GridRegion rinfo in rinfos) | ||
474 | { | ||
475 | Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs(); | ||
476 | result["region" + i] = rinfoDict; | ||
477 | i++; | ||
478 | } | ||
479 | } | ||
480 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
481 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
482 | UTF8Encoding encoding = new UTF8Encoding(); | ||
483 | return encoding.GetBytes(xmlString); | ||
484 | } | ||
485 | |||
486 | byte[] GetRegionFlags(Dictionary<string, object> request) | ||
487 | { | ||
488 | UUID scopeID = UUID.Zero; | ||
489 | if (request.ContainsKey("SCOPEID")) | ||
490 | UUID.TryParse(request["SCOPEID"].ToString(), out scopeID); | ||
491 | else | ||
492 | m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours"); | ||
493 | |||
494 | UUID regionID = UUID.Zero; | ||
495 | if (request.ContainsKey("REGIONID")) | ||
496 | UUID.TryParse(request["REGIONID"].ToString(), out regionID); | ||
497 | else | ||
498 | m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours"); | ||
499 | |||
500 | int flags = m_GridService.GetRegionFlags(scopeID, regionID); | ||
501 | // m_log.DebugFormat("[GRID HANDLER]: flags for region {0}: {1}", regionID, flags); | ||
502 | |||
503 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
504 | result["result"] = flags.ToString(); | ||
505 | |||
506 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
507 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
508 | UTF8Encoding encoding = new UTF8Encoding(); | ||
509 | return encoding.GetBytes(xmlString); | ||
510 | } | ||
511 | |||
512 | |||
407 | #endregion | 513 | #endregion |
408 | 514 | ||
409 | #region Misc | 515 | #region Misc |
diff --git a/OpenSim/Server/Handlers/Grid/HypergridServerConnector.cs b/OpenSim/Server/Handlers/Grid/HypergridServerConnector.cs deleted file mode 100644 index 7cc0dfa..0000000 --- a/OpenSim/Server/Handlers/Grid/HypergridServerConnector.cs +++ /dev/null | |||
@@ -1,208 +0,0 @@ | |||
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.Reflection; | ||
32 | using System.Net; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using OpenSim.Framework.Servers.HttpServer; | ||
38 | using OpenSim.Server.Handlers.Base; | ||
39 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
40 | |||
41 | using OpenMetaverse; | ||
42 | using log4net; | ||
43 | using Nwc.XmlRpc; | ||
44 | |||
45 | namespace OpenSim.Server.Handlers.Grid | ||
46 | { | ||
47 | public class HypergridServiceInConnector : ServiceConnector | ||
48 | { | ||
49 | private static readonly ILog m_log = | ||
50 | LogManager.GetLogger( | ||
51 | MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | private List<GridRegion> m_RegionsOnSim = new List<GridRegion>(); | ||
54 | private IHyperlinkService m_HyperlinkService; | ||
55 | |||
56 | public HypergridServiceInConnector(IConfigSource config, IHttpServer server, IHyperlinkService hyperService) : | ||
57 | base(config, server, String.Empty) | ||
58 | { | ||
59 | m_HyperlinkService = hyperService; | ||
60 | server.AddXmlRPCHandler("link_region", LinkRegionRequest, false); | ||
61 | server.AddXmlRPCHandler("expect_hg_user", ExpectHGUser, false); | ||
62 | } | ||
63 | |||
64 | public void AddRegion(GridRegion rinfo) | ||
65 | { | ||
66 | m_RegionsOnSim.Add(rinfo); | ||
67 | } | ||
68 | |||
69 | public void RemoveRegion(GridRegion rinfo) | ||
70 | { | ||
71 | if (m_RegionsOnSim.Contains(rinfo)) | ||
72 | m_RegionsOnSim.Remove(rinfo); | ||
73 | } | ||
74 | |||
75 | /// <summary> | ||
76 | /// Someone wants to link to us | ||
77 | /// </summary> | ||
78 | /// <param name="request"></param> | ||
79 | /// <returns></returns> | ||
80 | public XmlRpcResponse LinkRegionRequest(XmlRpcRequest request, IPEndPoint remoteClient) | ||
81 | { | ||
82 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
83 | //string host = (string)requestData["host"]; | ||
84 | //string portstr = (string)requestData["port"]; | ||
85 | string name = (string)requestData["region_name"]; | ||
86 | |||
87 | m_log.DebugFormat("[HGrid]: Hyperlink request"); | ||
88 | |||
89 | GridRegion regInfo = null; | ||
90 | foreach (GridRegion r in m_RegionsOnSim) | ||
91 | { | ||
92 | if ((r.RegionName != null) && (name != null) && (r.RegionName.ToLower() == name.ToLower())) | ||
93 | { | ||
94 | regInfo = r; | ||
95 | break; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | if (regInfo == null) | ||
100 | regInfo = m_RegionsOnSim[0]; // Send out the first region | ||
101 | |||
102 | Hashtable hash = new Hashtable(); | ||
103 | hash["uuid"] = regInfo.RegionID.ToString(); | ||
104 | m_log.Debug(">> Here " + regInfo.RegionID); | ||
105 | hash["handle"] = regInfo.RegionHandle.ToString(); | ||
106 | hash["region_image"] = regInfo.TerrainImage.ToString(); | ||
107 | hash["region_name"] = regInfo.RegionName; | ||
108 | hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString(); | ||
109 | //m_log.Debug(">> Here: " + regInfo.InternalEndPoint.Port); | ||
110 | |||
111 | |||
112 | XmlRpcResponse response = new XmlRpcResponse(); | ||
113 | response.Value = hash; | ||
114 | return response; | ||
115 | } | ||
116 | |||
117 | /// <summary> | ||
118 | /// Received from other HGrid nodes when a user wants to teleport here. This call allows | ||
119 | /// the region to prepare for direct communication from the client. Sends back an empty | ||
120 | /// xmlrpc response on completion. | ||
121 | /// This is somewhat similar to OGS1's ExpectUser, but with the additional task of | ||
122 | /// registering the user in the local user cache. | ||
123 | /// </summary> | ||
124 | /// <param name="request"></param> | ||
125 | /// <returns></returns> | ||
126 | public XmlRpcResponse ExpectHGUser(XmlRpcRequest request, IPEndPoint remoteClient) | ||
127 | { | ||
128 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
129 | ForeignUserProfileData userData = new ForeignUserProfileData(); | ||
130 | |||
131 | userData.FirstName = (string)requestData["firstname"]; | ||
132 | userData.SurName = (string)requestData["lastname"]; | ||
133 | userData.ID = new UUID((string)requestData["agent_id"]); | ||
134 | UUID sessionID = new UUID((string)requestData["session_id"]); | ||
135 | userData.HomeLocation = new Vector3((float)Convert.ToDecimal((string)requestData["startpos_x"], Culture.NumberFormatInfo), | ||
136 | (float)Convert.ToDecimal((string)requestData["startpos_y"], Culture.NumberFormatInfo), | ||
137 | (float)Convert.ToDecimal((string)requestData["startpos_z"], Culture.NumberFormatInfo)); | ||
138 | |||
139 | userData.UserServerURI = (string)requestData["userserver_id"]; | ||
140 | userData.UserAssetURI = (string)requestData["assetserver_id"]; | ||
141 | userData.UserInventoryURI = (string)requestData["inventoryserver_id"]; | ||
142 | |||
143 | m_log.DebugFormat("[HGrid]: Prepare for connection from {0} {1} (@{2}) UUID={3}", | ||
144 | userData.FirstName, userData.SurName, userData.UserServerURI, userData.ID); | ||
145 | |||
146 | ulong userRegionHandle = 0; | ||
147 | int userhomeinternalport = 0; | ||
148 | if (requestData.ContainsKey("region_uuid")) | ||
149 | { | ||
150 | UUID uuid = UUID.Zero; | ||
151 | UUID.TryParse((string)requestData["region_uuid"], out uuid); | ||
152 | userData.HomeRegionID = uuid; | ||
153 | userRegionHandle = Convert.ToUInt64((string)requestData["regionhandle"]); | ||
154 | userData.UserHomeAddress = (string)requestData["home_address"]; | ||
155 | userData.UserHomePort = (string)requestData["home_port"]; | ||
156 | userhomeinternalport = Convert.ToInt32((string)requestData["internal_port"]); | ||
157 | |||
158 | m_log.Debug("[HGrid]: home_address: " + userData.UserHomeAddress + | ||
159 | "; home_port: " + userData.UserHomePort); | ||
160 | } | ||
161 | else | ||
162 | m_log.WarnFormat("[HGrid]: User has no home region information"); | ||
163 | |||
164 | XmlRpcResponse resp = new XmlRpcResponse(); | ||
165 | |||
166 | // Let's check if someone is trying to get in with a stolen local identity. | ||
167 | // The need for this test is a consequence of not having truly global names :-/ | ||
168 | bool comingHome = false; | ||
169 | if (m_HyperlinkService.CheckUserAtEntry(userData.ID, sessionID, out comingHome) == false) | ||
170 | { | ||
171 | m_log.WarnFormat("[HGrid]: Access denied to foreign user."); | ||
172 | Hashtable respdata = new Hashtable(); | ||
173 | respdata["success"] = "FALSE"; | ||
174 | respdata["reason"] = "Foreign user has the same ID as a local user, or logins disabled."; | ||
175 | resp.Value = respdata; | ||
176 | return resp; | ||
177 | } | ||
178 | |||
179 | // Finally, everything looks ok | ||
180 | //m_log.Debug("XXX---- EVERYTHING OK ---XXX"); | ||
181 | |||
182 | if (!comingHome) | ||
183 | { | ||
184 | // We don't do this if the user is coming to the home grid | ||
185 | GridRegion home = new GridRegion(); | ||
186 | home.RegionID = userData.HomeRegionID; | ||
187 | home.ExternalHostName = userData.UserHomeAddress; | ||
188 | home.HttpPort = Convert.ToUInt32(userData.UserHomePort); | ||
189 | uint x = 0, y = 0; | ||
190 | Utils.LongToUInts(userRegionHandle, out x, out y); | ||
191 | home.RegionLocX = (int)x; | ||
192 | home.RegionLocY = (int)y; | ||
193 | home.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)userhomeinternalport); | ||
194 | |||
195 | m_HyperlinkService.AcceptUser(userData, home); | ||
196 | } | ||
197 | // else the user is coming to a non-home region of the home grid | ||
198 | // We simply drop this user information altogether | ||
199 | |||
200 | Hashtable respdata2 = new Hashtable(); | ||
201 | respdata2["success"] = "TRUE"; | ||
202 | resp.Value = respdata2; | ||
203 | |||
204 | return resp; | ||
205 | } | ||
206 | |||
207 | } | ||
208 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs new file mode 100644 index 0000000..c951653 --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.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 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.AgentHandler | ||
53 | { | ||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | private IGatekeeperService m_GatekeeperService; | ||
56 | |||
57 | public GatekeeperAgentHandler(IGatekeeperService gatekeeper) | ||
58 | { | ||
59 | m_GatekeeperService = gatekeeper; | ||
60 | } | ||
61 | |||
62 | protected override bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) | ||
63 | { | ||
64 | return m_GatekeeperService.LoginAgent(aCircuit, destination, out reason); | ||
65 | } | ||
66 | |||
67 | } | ||
68 | |||
69 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs new file mode 100644 index 0000000..f2d9321 --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs | |||
@@ -0,0 +1,82 @@ | |||
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 | public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server, ISimulationService simService) : | ||
55 | base(config, server, String.Empty) | ||
56 | { | ||
57 | IConfig gridConfig = config.Configs["GatekeeperService"]; | ||
58 | if (gridConfig != null) | ||
59 | { | ||
60 | string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); | ||
61 | Object[] args = new Object[] { config, simService }; | ||
62 | m_GatekeeperService = ServerUtils.LoadPlugin<IGatekeeperService>(serviceDll, args); | ||
63 | |||
64 | } | ||
65 | if (m_GatekeeperService == null) | ||
66 | throw new Exception("Gatekeeper server connector cannot proceed because of missing service"); | ||
67 | |||
68 | HypergridHandlers hghandlers = new HypergridHandlers(m_GatekeeperService); | ||
69 | server.AddXmlRPCHandler("link_region", hghandlers.LinkRegionRequest, false); | ||
70 | server.AddXmlRPCHandler("get_region", hghandlers.GetRegion, false); | ||
71 | |||
72 | server.AddHTTPHandler("/foreignagent/", new GatekeeperAgentHandler(m_GatekeeperService).Handler); | ||
73 | |||
74 | } | ||
75 | |||
76 | public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server) | ||
77 | : this(config, server, null) | ||
78 | { | ||
79 | } | ||
80 | |||
81 | } | ||
82 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGInventoryServerInConnector.cs b/OpenSim/Server/Handlers/Hypergrid/HGInventoryServerInConnector.cs new file mode 100644 index 0000000..41897eb --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/HGInventoryServerInConnector.cs | |||
@@ -0,0 +1,104 @@ | |||
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.Server.Handlers.Inventory; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Servers.HttpServer; | ||
41 | using OpenSim.Server.Handlers.Base; | ||
42 | using OpenMetaverse; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.Hypergrid | ||
45 | { | ||
46 | public class HGInventoryServiceInConnector : InventoryServiceInConnector | ||
47 | { | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | //private static readonly int INVENTORY_DEFAULT_SESSION_TIME = 30; // secs | ||
51 | //private AuthedSessionCache m_session_cache = new AuthedSessionCache(INVENTORY_DEFAULT_SESSION_TIME); | ||
52 | |||
53 | private IUserAgentService m_UserAgentService; | ||
54 | |||
55 | public HGInventoryServiceInConnector(IConfigSource config, IHttpServer server, string configName) : | ||
56 | base(config, server, configName) | ||
57 | { | ||
58 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
59 | if (serverConfig == null) | ||
60 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
61 | |||
62 | string userAgentService = serverConfig.GetString("UserAgentService", string.Empty); | ||
63 | string m_userserver_url = serverConfig.GetString("UserAgentURI", String.Empty); | ||
64 | if (m_userserver_url != string.Empty) | ||
65 | { | ||
66 | Object[] args = new Object[] { m_userserver_url }; | ||
67 | m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(userAgentService, args); | ||
68 | } | ||
69 | |||
70 | AddHttpHandlers(server); | ||
71 | m_log.Debug("[HG INVENTORY HANDLER]: handlers initialized"); | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// Check that the source of an inventory request for a particular agent is a current session belonging to | ||
76 | /// that agent. | ||
77 | /// </summary> | ||
78 | /// <param name="session_id"></param> | ||
79 | /// <param name="avatar_id"></param> | ||
80 | /// <returns></returns> | ||
81 | public override bool CheckAuthSession(string session_id, string avatar_id) | ||
82 | { | ||
83 | //m_log.InfoFormat("[HG INVENTORY IN CONNECTOR]: checking authed session {0} {1}", session_id, avatar_id); | ||
84 | // This doesn't work | ||
85 | |||
86 | // if (m_session_cache.getCachedSession(session_id, avatar_id) == null) | ||
87 | // { | ||
88 | // //cache miss, ask userserver | ||
89 | // m_UserAgentService.VerifyAgent(session_id, ???); | ||
90 | // } | ||
91 | // else | ||
92 | // { | ||
93 | // // cache hits | ||
94 | // m_log.Info("[HG INVENTORY IN CONNECTOR]: got authed session from cache"); | ||
95 | // return true; | ||
96 | // } | ||
97 | |||
98 | // m_log.Warn("[HG INVENTORY IN CONNECTOR]: unknown session_id, request rejected"); | ||
99 | // return false; | ||
100 | |||
101 | return true; | ||
102 | } | ||
103 | } | ||
104 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs new file mode 100644 index 0000000..17d7850 --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs | |||
@@ -0,0 +1,181 @@ | |||
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 | ||
53 | { | ||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | private IUserAgentService m_UserAgentService; | ||
56 | |||
57 | public HomeAgentHandler(IUserAgentService userAgentService) | ||
58 | { | ||
59 | m_UserAgentService = userAgentService; | ||
60 | } | ||
61 | |||
62 | public Hashtable Handler(Hashtable request) | ||
63 | { | ||
64 | m_log.Debug("[CONNECTION DEBUGGING]: HomeAgentHandler 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 | responsedata["keepalive"] = false; | ||
75 | |||
76 | |||
77 | UUID agentID; | ||
78 | UUID regionID; | ||
79 | string action; | ||
80 | if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action)) | ||
81 | { | ||
82 | m_log.InfoFormat("[HOME AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]); | ||
83 | responsedata["int_response_code"] = 404; | ||
84 | responsedata["str_response_string"] = "false"; | ||
85 | |||
86 | return responsedata; | ||
87 | } | ||
88 | |||
89 | // Next, let's parse the verb | ||
90 | string method = (string)request["http-method"]; | ||
91 | if (method.Equals("POST")) | ||
92 | { | ||
93 | DoAgentPost(request, responsedata, agentID); | ||
94 | return responsedata; | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | m_log.InfoFormat("[HOME AGENT HANDLER]: method {0} not supported in agent message", method); | ||
99 | responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; | ||
100 | responsedata["str_response_string"] = "Method not allowed"; | ||
101 | |||
102 | return responsedata; | ||
103 | } | ||
104 | |||
105 | } | ||
106 | |||
107 | protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) | ||
108 | { | ||
109 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
110 | if (args == null) | ||
111 | { | ||
112 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
113 | responsedata["str_response_string"] = "Bad request"; | ||
114 | return; | ||
115 | } | ||
116 | |||
117 | // retrieve the input arguments | ||
118 | int x = 0, y = 0; | ||
119 | UUID uuid = UUID.Zero; | ||
120 | string regionname = string.Empty; | ||
121 | string gatekeeper_host = string.Empty; | ||
122 | int gatekeeper_port = 0; | ||
123 | |||
124 | if (args.ContainsKey("gatekeeper_host") && args["gatekeeper_host"] != null) | ||
125 | gatekeeper_host = args["gatekeeper_host"].AsString(); | ||
126 | if (args.ContainsKey("gatekeeper_port") && args["gatekeeper_port"] != null) | ||
127 | Int32.TryParse(args["gatekeeper_port"].AsString(), out gatekeeper_port); | ||
128 | |||
129 | GridRegion gatekeeper = new GridRegion(); | ||
130 | gatekeeper.ExternalHostName = gatekeeper_host; | ||
131 | gatekeeper.HttpPort = (uint)gatekeeper_port; | ||
132 | gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); | ||
133 | |||
134 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
135 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
136 | else | ||
137 | m_log.WarnFormat(" -- request didn't have destination_x"); | ||
138 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
139 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
140 | else | ||
141 | m_log.WarnFormat(" -- request didn't have destination_y"); | ||
142 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
143 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
144 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
145 | regionname = args["destination_name"].ToString(); | ||
146 | |||
147 | GridRegion destination = new GridRegion(); | ||
148 | destination.RegionID = uuid; | ||
149 | destination.RegionLocX = x; | ||
150 | destination.RegionLocY = y; | ||
151 | destination.RegionName = regionname; | ||
152 | |||
153 | AgentCircuitData aCircuit = new AgentCircuitData(); | ||
154 | try | ||
155 | { | ||
156 | aCircuit.UnpackAgentCircuitData(args); | ||
157 | } | ||
158 | catch (Exception ex) | ||
159 | { | ||
160 | m_log.InfoFormat("[HOME AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message); | ||
161 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
162 | responsedata["str_response_string"] = "Bad request"; | ||
163 | return; | ||
164 | } | ||
165 | |||
166 | OSDMap resp = new OSDMap(2); | ||
167 | string reason = String.Empty; | ||
168 | |||
169 | bool result = m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, out reason); | ||
170 | |||
171 | resp["reason"] = OSD.FromString(reason); | ||
172 | resp["success"] = OSD.FromBoolean(result); | ||
173 | |||
174 | // TODO: add reason if not String.Empty? | ||
175 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
176 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); | ||
177 | } | ||
178 | |||
179 | } | ||
180 | |||
181 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs new file mode 100644 index 0000000..0b65245 --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.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 | 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 | } | ||
52 | |||
53 | /// <summary> | ||
54 | /// Someone wants to link to us | ||
55 | /// </summary> | ||
56 | /// <param name="request"></param> | ||
57 | /// <returns></returns> | ||
58 | public XmlRpcResponse LinkRegionRequest(XmlRpcRequest request, IPEndPoint remoteClient) | ||
59 | { | ||
60 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
61 | //string host = (string)requestData["host"]; | ||
62 | //string portstr = (string)requestData["port"]; | ||
63 | string name = (string)requestData["region_name"]; | ||
64 | |||
65 | UUID regionID = UUID.Zero; | ||
66 | string externalName = string.Empty; | ||
67 | string imageURL = string.Empty; | ||
68 | ulong regionHandle = 0; | ||
69 | string reason = string.Empty; | ||
70 | |||
71 | bool success = m_GatekeeperService.LinkRegion(name, out regionID, out regionHandle, out externalName, out imageURL, out reason); | ||
72 | |||
73 | Hashtable hash = new Hashtable(); | ||
74 | hash["result"] = success.ToString(); | ||
75 | hash["uuid"] = regionID.ToString(); | ||
76 | hash["handle"] = regionHandle.ToString(); | ||
77 | hash["region_image"] = imageURL; | ||
78 | hash["external_name"] = externalName; | ||
79 | |||
80 | XmlRpcResponse response = new XmlRpcResponse(); | ||
81 | response.Value = hash; | ||
82 | return response; | ||
83 | } | ||
84 | |||
85 | public XmlRpcResponse GetRegion(XmlRpcRequest request, IPEndPoint remoteClient) | ||
86 | { | ||
87 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
88 | //string host = (string)requestData["host"]; | ||
89 | //string portstr = (string)requestData["port"]; | ||
90 | string regionID_str = (string)requestData["region_uuid"]; | ||
91 | UUID regionID = UUID.Zero; | ||
92 | UUID.TryParse(regionID_str, out regionID); | ||
93 | |||
94 | GridRegion regInfo = m_GatekeeperService.GetHyperlinkRegion(regionID); | ||
95 | |||
96 | Hashtable hash = new Hashtable(); | ||
97 | if (regInfo == null) | ||
98 | hash["result"] = "false"; | ||
99 | else | ||
100 | { | ||
101 | hash["result"] = "true"; | ||
102 | hash["uuid"] = regInfo.RegionID.ToString(); | ||
103 | hash["x"] = regInfo.RegionLocX.ToString(); | ||
104 | hash["y"] = regInfo.RegionLocY.ToString(); | ||
105 | hash["region_name"] = regInfo.RegionName; | ||
106 | hash["hostname"] = regInfo.ExternalHostName; | ||
107 | hash["http_port"] = regInfo.HttpPort.ToString(); | ||
108 | hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString(); | ||
109 | } | ||
110 | XmlRpcResponse response = new XmlRpcResponse(); | ||
111 | response.Value = hash; | ||
112 | return response; | ||
113 | |||
114 | } | ||
115 | |||
116 | } | ||
117 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs new file mode 100644 index 0000000..6b1152b --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs | |||
@@ -0,0 +1,195 @@ | |||
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 | |||
56 | public UserAgentServerConnector(IConfigSource config, IHttpServer server) : | ||
57 | base(config, server, String.Empty) | ||
58 | { | ||
59 | IConfig gridConfig = config.Configs["UserAgentService"]; | ||
60 | if (gridConfig != null) | ||
61 | { | ||
62 | string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); | ||
63 | Object[] args = new Object[] { config }; | ||
64 | m_HomeUsersService = ServerUtils.LoadPlugin<IUserAgentService>(serviceDll, args); | ||
65 | } | ||
66 | if (m_HomeUsersService == null) | ||
67 | throw new Exception("UserAgent server connector cannot proceed because of missing service"); | ||
68 | |||
69 | server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false); | ||
70 | server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false); | ||
71 | server.AddXmlRPCHandler("verify_agent", VerifyAgent, false); | ||
72 | server.AddXmlRPCHandler("verify_client", VerifyClient, false); | ||
73 | server.AddXmlRPCHandler("logout_agent", LogoutAgent, false); | ||
74 | |||
75 | server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService).Handler); | ||
76 | } | ||
77 | |||
78 | public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient) | ||
79 | { | ||
80 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
81 | //string host = (string)requestData["host"]; | ||
82 | //string portstr = (string)requestData["port"]; | ||
83 | string userID_str = (string)requestData["userID"]; | ||
84 | UUID userID = UUID.Zero; | ||
85 | UUID.TryParse(userID_str, out userID); | ||
86 | |||
87 | Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY; | ||
88 | GridRegion regInfo = m_HomeUsersService.GetHomeRegion(userID, out position, out lookAt); | ||
89 | |||
90 | Hashtable hash = new Hashtable(); | ||
91 | if (regInfo == null) | ||
92 | hash["result"] = "false"; | ||
93 | else | ||
94 | { | ||
95 | hash["result"] = "true"; | ||
96 | hash["uuid"] = regInfo.RegionID.ToString(); | ||
97 | hash["x"] = regInfo.RegionLocX.ToString(); | ||
98 | hash["y"] = regInfo.RegionLocY.ToString(); | ||
99 | hash["region_name"] = regInfo.RegionName; | ||
100 | hash["hostname"] = regInfo.ExternalHostName; | ||
101 | hash["http_port"] = regInfo.HttpPort.ToString(); | ||
102 | hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString(); | ||
103 | hash["position"] = position.ToString(); | ||
104 | hash["lookAt"] = lookAt.ToString(); | ||
105 | } | ||
106 | XmlRpcResponse response = new XmlRpcResponse(); | ||
107 | response.Value = hash; | ||
108 | return response; | ||
109 | |||
110 | } | ||
111 | |||
112 | public XmlRpcResponse AgentIsComingHome(XmlRpcRequest request, IPEndPoint remoteClient) | ||
113 | { | ||
114 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
115 | //string host = (string)requestData["host"]; | ||
116 | //string portstr = (string)requestData["port"]; | ||
117 | string sessionID_str = (string)requestData["sessionID"]; | ||
118 | UUID sessionID = UUID.Zero; | ||
119 | UUID.TryParse(sessionID_str, out sessionID); | ||
120 | string gridName = (string)requestData["externalName"]; | ||
121 | |||
122 | bool success = m_HomeUsersService.AgentIsComingHome(sessionID, gridName); | ||
123 | |||
124 | Hashtable hash = new Hashtable(); | ||
125 | hash["result"] = success.ToString(); | ||
126 | XmlRpcResponse response = new XmlRpcResponse(); | ||
127 | response.Value = hash; | ||
128 | return response; | ||
129 | |||
130 | } | ||
131 | |||
132 | public XmlRpcResponse VerifyAgent(XmlRpcRequest request, IPEndPoint remoteClient) | ||
133 | { | ||
134 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
135 | //string host = (string)requestData["host"]; | ||
136 | //string portstr = (string)requestData["port"]; | ||
137 | string sessionID_str = (string)requestData["sessionID"]; | ||
138 | UUID sessionID = UUID.Zero; | ||
139 | UUID.TryParse(sessionID_str, out sessionID); | ||
140 | string token = (string)requestData["token"]; | ||
141 | |||
142 | bool success = m_HomeUsersService.VerifyAgent(sessionID, token); | ||
143 | |||
144 | Hashtable hash = new Hashtable(); | ||
145 | hash["result"] = success.ToString(); | ||
146 | XmlRpcResponse response = new XmlRpcResponse(); | ||
147 | response.Value = hash; | ||
148 | return response; | ||
149 | |||
150 | } | ||
151 | |||
152 | public XmlRpcResponse VerifyClient(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 token = (string)requestData["token"]; | ||
161 | |||
162 | bool success = m_HomeUsersService.VerifyClient(sessionID, token); | ||
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 LogoutAgent(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 userID_str = (string)requestData["userID"]; | ||
181 | UUID userID = UUID.Zero; | ||
182 | UUID.TryParse(userID_str, out userID); | ||
183 | |||
184 | m_HomeUsersService.LogoutAgent(userID, sessionID); | ||
185 | |||
186 | Hashtable hash = new Hashtable(); | ||
187 | hash["result"] = "true"; | ||
188 | XmlRpcResponse response = new XmlRpcResponse(); | ||
189 | response.Value = hash; | ||
190 | return response; | ||
191 | |||
192 | } | ||
193 | |||
194 | } | ||
195 | } | ||
diff --git a/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs index 3c92209..1d422a7 100644 --- a/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs +++ b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs | |||
@@ -46,7 +46,7 @@ namespace OpenSim.Server.Handlers.Inventory | |||
46 | { | 46 | { |
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 48 | ||
49 | private IInventoryService m_InventoryService; | 49 | protected IInventoryService m_InventoryService; |
50 | 50 | ||
51 | private bool m_doLookup = false; | 51 | private bool m_doLookup = false; |
52 | 52 | ||
@@ -54,11 +54,14 @@ namespace OpenSim.Server.Handlers.Inventory | |||
54 | //private AuthedSessionCache m_session_cache = new AuthedSessionCache(INVENTORY_DEFAULT_SESSION_TIME); | 54 | //private AuthedSessionCache m_session_cache = new AuthedSessionCache(INVENTORY_DEFAULT_SESSION_TIME); |
55 | 55 | ||
56 | private string m_userserver_url; | 56 | private string m_userserver_url; |
57 | private string m_ConfigName = "InventoryService"; | 57 | protected string m_ConfigName = "InventoryService"; |
58 | 58 | ||
59 | public InventoryServiceInConnector(IConfigSource config, IHttpServer server, string configName) : | 59 | public InventoryServiceInConnector(IConfigSource config, IHttpServer server, string configName) : |
60 | base(config, server, configName) | 60 | base(config, server, configName) |
61 | { | 61 | { |
62 | if (configName != string.Empty) | ||
63 | m_ConfigName = configName; | ||
64 | |||
62 | IConfig serverConfig = config.Configs[m_ConfigName]; | 65 | IConfig serverConfig = config.Configs[m_ConfigName]; |
63 | if (serverConfig == null) | 66 | if (serverConfig == null) |
64 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | 67 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); |
@@ -328,46 +331,9 @@ namespace OpenSim.Server.Handlers.Inventory | |||
328 | /// <param name="session_id"></param> | 331 | /// <param name="session_id"></param> |
329 | /// <param name="avatar_id"></param> | 332 | /// <param name="avatar_id"></param> |
330 | /// <returns></returns> | 333 | /// <returns></returns> |
331 | public bool CheckAuthSession(string session_id, string avatar_id) | 334 | public virtual bool CheckAuthSession(string session_id, string avatar_id) |
332 | { | 335 | { |
333 | if (m_doLookup) | 336 | return true; |
334 | { | ||
335 | m_log.InfoFormat("[INVENTORY IN CONNECTOR]: checking authed session {0} {1}", session_id, avatar_id); | ||
336 | |||
337 | //if (m_session_cache.getCachedSession(session_id, avatar_id) == null) | ||
338 | //{ | ||
339 | // cache miss, ask userserver | ||
340 | Hashtable requestData = new Hashtable(); | ||
341 | requestData["avatar_uuid"] = avatar_id; | ||
342 | requestData["session_id"] = session_id; | ||
343 | ArrayList SendParams = new ArrayList(); | ||
344 | SendParams.Add(requestData); | ||
345 | XmlRpcRequest UserReq = new XmlRpcRequest("check_auth_session", SendParams); | ||
346 | XmlRpcResponse UserResp = UserReq.Send(m_userserver_url, 3000); | ||
347 | |||
348 | Hashtable responseData = (Hashtable)UserResp.Value; | ||
349 | if (responseData.ContainsKey("auth_session") && responseData["auth_session"].ToString() == "TRUE") | ||
350 | { | ||
351 | m_log.Info("[INVENTORY IN CONNECTOR]: got authed session from userserver"); | ||
352 | //// add to cache; the session time will be automatically renewed | ||
353 | //m_session_cache.Add(session_id, avatar_id); | ||
354 | return true; | ||
355 | } | ||
356 | //} | ||
357 | //else | ||
358 | //{ | ||
359 | // // cache hits | ||
360 | // m_log.Info("[GRID AGENT INVENTORY]: got authed session from cache"); | ||
361 | // return true; | ||
362 | //} | ||
363 | |||
364 | m_log.Warn("[INVENTORY IN CONNECTOR]: unknown session_id, request rejected"); | ||
365 | return false; | ||
366 | } | ||
367 | else | ||
368 | { | ||
369 | return true; | ||
370 | } | ||
371 | } | 337 | } |
372 | 338 | ||
373 | } | 339 | } |
diff --git a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs index 7e3e68b..34f7dcc 100644 --- a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs +++ b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs | |||
@@ -157,6 +157,16 @@ namespace OpenSim.Server.Handlers.Asset | |||
157 | 157 | ||
158 | private byte[] FailureResult() | 158 | private byte[] FailureResult() |
159 | { | 159 | { |
160 | return BoolResult(false); | ||
161 | } | ||
162 | |||
163 | private byte[] SuccessResult() | ||
164 | { | ||
165 | return BoolResult(true); | ||
166 | } | ||
167 | |||
168 | private byte[] BoolResult(bool value) | ||
169 | { | ||
160 | XmlDocument doc = new XmlDocument(); | 170 | XmlDocument doc = new XmlDocument(); |
161 | 171 | ||
162 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | 172 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, |
@@ -170,7 +180,7 @@ namespace OpenSim.Server.Handlers.Asset | |||
170 | doc.AppendChild(rootElement); | 180 | doc.AppendChild(rootElement); |
171 | 181 | ||
172 | XmlElement result = doc.CreateElement("", "RESULT", ""); | 182 | XmlElement result = doc.CreateElement("", "RESULT", ""); |
173 | result.AppendChild(doc.CreateTextNode("False")); | 183 | result.AppendChild(doc.CreateTextNode(value.ToString())); |
174 | 184 | ||
175 | rootElement.AppendChild(result); | 185 | rootElement.AppendChild(result); |
176 | 186 | ||
@@ -216,8 +226,9 @@ namespace OpenSim.Server.Handlers.Asset | |||
216 | 226 | ||
217 | List<InventoryFolderBase> folders = m_InventoryService.GetInventorySkeleton(new UUID(request["PRINCIPAL"].ToString())); | 227 | List<InventoryFolderBase> folders = m_InventoryService.GetInventorySkeleton(new UUID(request["PRINCIPAL"].ToString())); |
218 | 228 | ||
219 | foreach (InventoryFolderBase f in folders) | 229 | if (folders != null) |
220 | result[f.ID.ToString()] = EncodeFolder(f); | 230 | foreach (InventoryFolderBase f in folders) |
231 | result[f.ID.ToString()] = EncodeFolder(f); | ||
221 | 232 | ||
222 | string xmlString = ServerUtils.BuildXmlResponse(result); | 233 | string xmlString = ServerUtils.BuildXmlResponse(result); |
223 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 234 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
@@ -229,6 +240,12 @@ namespace OpenSim.Server.Handlers.Asset | |||
229 | { | 240 | { |
230 | Dictionary<string,object> result = new Dictionary<string,object>(); | 241 | Dictionary<string,object> result = new Dictionary<string,object>(); |
231 | 242 | ||
243 | UUID principal = UUID.Zero; | ||
244 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
245 | InventoryFolderBase rfolder = m_InventoryService.GetRootFolder(principal); | ||
246 | if (rfolder != null) | ||
247 | result[rfolder.ID.ToString()] = EncodeFolder(rfolder); | ||
248 | |||
232 | string xmlString = ServerUtils.BuildXmlResponse(result); | 249 | string xmlString = ServerUtils.BuildXmlResponse(result); |
233 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 250 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
234 | UTF8Encoding encoding = new UTF8Encoding(); | 251 | UTF8Encoding encoding = new UTF8Encoding(); |
@@ -238,6 +255,13 @@ namespace OpenSim.Server.Handlers.Asset | |||
238 | byte[] HandleGetFolderForType(Dictionary<string,object> request) | 255 | byte[] HandleGetFolderForType(Dictionary<string,object> request) |
239 | { | 256 | { |
240 | Dictionary<string,object> result = new Dictionary<string,object>(); | 257 | Dictionary<string,object> result = new Dictionary<string,object>(); |
258 | UUID principal = UUID.Zero; | ||
259 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
260 | int type = 0; | ||
261 | Int32.TryParse(request["TYPE"].ToString(), out type); | ||
262 | InventoryFolderBase folder = m_InventoryService.GetFolderForType(principal, (AssetType)type); | ||
263 | if (folder != null) | ||
264 | result[folder.ID.ToString()] = EncodeFolder(folder); | ||
241 | 265 | ||
242 | string xmlString = ServerUtils.BuildXmlResponse(result); | 266 | string xmlString = ServerUtils.BuildXmlResponse(result); |
243 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 267 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
@@ -248,6 +272,24 @@ namespace OpenSim.Server.Handlers.Asset | |||
248 | byte[] HandleGetFolderContent(Dictionary<string,object> request) | 272 | byte[] HandleGetFolderContent(Dictionary<string,object> request) |
249 | { | 273 | { |
250 | Dictionary<string,object> result = new Dictionary<string,object>(); | 274 | Dictionary<string,object> result = new Dictionary<string,object>(); |
275 | UUID principal = UUID.Zero; | ||
276 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
277 | UUID folderID = UUID.Zero; | ||
278 | UUID.TryParse(request["FOLDER"].ToString(), out folderID); | ||
279 | |||
280 | InventoryCollection icoll = m_InventoryService.GetFolderContent(principal, folderID); | ||
281 | if (icoll != null) | ||
282 | { | ||
283 | Dictionary<string, object> folders = new Dictionary<string, object>(); | ||
284 | foreach (InventoryFolderBase f in icoll.Folders) | ||
285 | folders[f.ID.ToString()] = EncodeFolder(f); | ||
286 | result["FOLDERS"] = folders; | ||
287 | |||
288 | Dictionary<string, object> items = new Dictionary<string, object>(); | ||
289 | foreach (InventoryItemBase i in icoll.Items) | ||
290 | items[i.ID.ToString()] = EncodeItem(i); | ||
291 | result["ITEMS"] = items; | ||
292 | } | ||
251 | 293 | ||
252 | string xmlString = ServerUtils.BuildXmlResponse(result); | 294 | string xmlString = ServerUtils.BuildXmlResponse(result); |
253 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 295 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
@@ -258,7 +300,16 @@ namespace OpenSim.Server.Handlers.Asset | |||
258 | byte[] HandleGetFolderItems(Dictionary<string,object> request) | 300 | byte[] HandleGetFolderItems(Dictionary<string,object> request) |
259 | { | 301 | { |
260 | Dictionary<string,object> result = new Dictionary<string,object>(); | 302 | Dictionary<string,object> result = new Dictionary<string,object>(); |
261 | 303 | UUID principal = UUID.Zero; | |
304 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
305 | UUID folderID = UUID.Zero; | ||
306 | UUID.TryParse(request["FOLDER"].ToString(), out folderID); | ||
307 | |||
308 | List<InventoryItemBase> items = m_InventoryService.GetFolderItems(principal, folderID); | ||
309 | if (items != null) | ||
310 | foreach (InventoryItemBase item in items) | ||
311 | result[item.ID.ToString()] = EncodeItem(item); | ||
312 | |||
262 | string xmlString = ServerUtils.BuildXmlResponse(result); | 313 | string xmlString = ServerUtils.BuildXmlResponse(result); |
263 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 314 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
264 | UTF8Encoding encoding = new UTF8Encoding(); | 315 | UTF8Encoding encoding = new UTF8Encoding(); |
@@ -268,96 +319,169 @@ namespace OpenSim.Server.Handlers.Asset | |||
268 | byte[] HandleAddFolder(Dictionary<string,object> request) | 319 | byte[] HandleAddFolder(Dictionary<string,object> request) |
269 | { | 320 | { |
270 | Dictionary<string,object> result = new Dictionary<string,object>(); | 321 | Dictionary<string,object> result = new Dictionary<string,object>(); |
322 | InventoryFolderBase folder = BuildFolder(request); | ||
271 | 323 | ||
272 | string xmlString = ServerUtils.BuildXmlResponse(result); | 324 | if (m_InventoryService.AddFolder(folder)) |
273 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 325 | return SuccessResult(); |
274 | UTF8Encoding encoding = new UTF8Encoding(); | 326 | else |
275 | return encoding.GetBytes(xmlString); | 327 | return FailureResult(); |
276 | } | 328 | } |
277 | 329 | ||
278 | byte[] HandleUpdateFolder(Dictionary<string,object> request) | 330 | byte[] HandleUpdateFolder(Dictionary<string,object> request) |
279 | { | 331 | { |
280 | Dictionary<string,object> result = new Dictionary<string,object>(); | 332 | Dictionary<string, object> result = new Dictionary<string, object>(); |
333 | InventoryFolderBase folder = BuildFolder(request); | ||
281 | 334 | ||
282 | string xmlString = ServerUtils.BuildXmlResponse(result); | 335 | if (m_InventoryService.UpdateFolder(folder)) |
283 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 336 | return SuccessResult(); |
284 | UTF8Encoding encoding = new UTF8Encoding(); | 337 | else |
285 | return encoding.GetBytes(xmlString); | 338 | return FailureResult(); |
286 | } | 339 | } |
287 | 340 | ||
288 | byte[] HandleMoveFolder(Dictionary<string,object> request) | 341 | byte[] HandleMoveFolder(Dictionary<string,object> request) |
289 | { | 342 | { |
290 | Dictionary<string,object> result = new Dictionary<string,object>(); | 343 | Dictionary<string, object> result = new Dictionary<string, object>(); |
344 | UUID parentID = UUID.Zero; | ||
345 | UUID.TryParse(request["ParentID"].ToString(), out parentID); | ||
346 | UUID folderID = UUID.Zero; | ||
347 | UUID.TryParse(request["ID"].ToString(), out folderID); | ||
348 | UUID principal = UUID.Zero; | ||
349 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
350 | |||
351 | InventoryFolderBase folder = new InventoryFolderBase(folderID, "", principal, parentID); | ||
352 | if (m_InventoryService.MoveFolder(folder)) | ||
353 | return SuccessResult(); | ||
354 | else | ||
355 | return FailureResult(); | ||
291 | 356 | ||
292 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
293 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
294 | UTF8Encoding encoding = new UTF8Encoding(); | ||
295 | return encoding.GetBytes(xmlString); | ||
296 | } | 357 | } |
297 | 358 | ||
298 | byte[] HandleDeleteFolders(Dictionary<string,object> request) | 359 | byte[] HandleDeleteFolders(Dictionary<string,object> request) |
299 | { | 360 | { |
300 | Dictionary<string,object> result = new Dictionary<string,object>(); | 361 | Dictionary<string,object> result = new Dictionary<string,object>(); |
362 | UUID principal = UUID.Zero; | ||
363 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
364 | List<string> slist = (List<string>)request["FOLDERS"]; | ||
365 | List<UUID> uuids = new List<UUID>(); | ||
366 | foreach (string s in slist) | ||
367 | { | ||
368 | UUID u = UUID.Zero; | ||
369 | if (UUID.TryParse(s, out u)) | ||
370 | uuids.Add(u); | ||
371 | } | ||
301 | 372 | ||
302 | string xmlString = ServerUtils.BuildXmlResponse(result); | 373 | if (m_InventoryService.DeleteFolders(principal, uuids)) |
303 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 374 | return SuccessResult(); |
304 | UTF8Encoding encoding = new UTF8Encoding(); | 375 | else |
305 | return encoding.GetBytes(xmlString); | 376 | return |
377 | FailureResult(); | ||
306 | } | 378 | } |
307 | 379 | ||
308 | byte[] HandlePurgeFolder(Dictionary<string,object> request) | 380 | byte[] HandlePurgeFolder(Dictionary<string,object> request) |
309 | { | 381 | { |
310 | Dictionary<string,object> result = new Dictionary<string,object>(); | 382 | Dictionary<string,object> result = new Dictionary<string,object>(); |
383 | UUID folderID = UUID.Zero; | ||
384 | UUID.TryParse(request["ID"].ToString(), out folderID); | ||
311 | 385 | ||
312 | string xmlString = ServerUtils.BuildXmlResponse(result); | 386 | InventoryFolderBase folder = new InventoryFolderBase(folderID); |
313 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 387 | if (m_InventoryService.PurgeFolder(folder)) |
314 | UTF8Encoding encoding = new UTF8Encoding(); | 388 | return SuccessResult(); |
315 | return encoding.GetBytes(xmlString); | 389 | else |
390 | return FailureResult(); | ||
316 | } | 391 | } |
317 | 392 | ||
318 | byte[] HandleAddItem(Dictionary<string,object> request) | 393 | byte[] HandleAddItem(Dictionary<string,object> request) |
319 | { | 394 | { |
320 | Dictionary<string,object> result = new Dictionary<string,object>(); | 395 | Dictionary<string, object> result = new Dictionary<string, object>(); |
396 | InventoryItemBase item = BuildItem(request); | ||
321 | 397 | ||
322 | string xmlString = ServerUtils.BuildXmlResponse(result); | 398 | if (m_InventoryService.AddItem(item)) |
323 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 399 | return SuccessResult(); |
324 | UTF8Encoding encoding = new UTF8Encoding(); | 400 | else |
325 | return encoding.GetBytes(xmlString); | 401 | return FailureResult(); |
326 | } | 402 | } |
327 | 403 | ||
328 | byte[] HandleUpdateItem(Dictionary<string,object> request) | 404 | byte[] HandleUpdateItem(Dictionary<string,object> request) |
329 | { | 405 | { |
330 | Dictionary<string,object> result = new Dictionary<string,object>(); | 406 | Dictionary<string, object> result = new Dictionary<string, object>(); |
407 | InventoryItemBase item = BuildItem(request); | ||
331 | 408 | ||
332 | string xmlString = ServerUtils.BuildXmlResponse(result); | 409 | if (m_InventoryService.UpdateItem(item)) |
333 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 410 | return SuccessResult(); |
334 | UTF8Encoding encoding = new UTF8Encoding(); | 411 | else |
335 | return encoding.GetBytes(xmlString); | 412 | return FailureResult(); |
336 | } | 413 | } |
337 | 414 | ||
338 | byte[] HandleMoveItems(Dictionary<string,object> request) | 415 | byte[] HandleMoveItems(Dictionary<string,object> request) |
339 | { | 416 | { |
340 | Dictionary<string,object> result = new Dictionary<string,object>(); | 417 | Dictionary<string,object> result = new Dictionary<string,object>(); |
418 | List<string> idlist = (List<string>)request["IDLIST"]; | ||
419 | List<string> destlist = (List<string>)request["DESTLIST"]; | ||
420 | UUID principal = UUID.Zero; | ||
421 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
341 | 422 | ||
342 | string xmlString = ServerUtils.BuildXmlResponse(result); | 423 | List<InventoryItemBase> items = new List<InventoryItemBase>(); |
343 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 424 | int n = 0; |
344 | UTF8Encoding encoding = new UTF8Encoding(); | 425 | try |
345 | return encoding.GetBytes(xmlString); | 426 | { |
427 | foreach (string s in idlist) | ||
428 | { | ||
429 | UUID u = UUID.Zero; | ||
430 | if (UUID.TryParse(s, out u)) | ||
431 | { | ||
432 | UUID fid = UUID.Zero; | ||
433 | if (UUID.TryParse(destlist[n++], out fid)) | ||
434 | { | ||
435 | InventoryItemBase item = new InventoryItemBase(u, principal); | ||
436 | item.Folder = fid; | ||
437 | items.Add(item); | ||
438 | } | ||
439 | } | ||
440 | } | ||
441 | } | ||
442 | catch (Exception e) | ||
443 | { | ||
444 | m_log.DebugFormat("[XINVENTORY IN CONNECTOR]: Exception in HandleMoveItems: {0}", e.Message); | ||
445 | return FailureResult(); | ||
446 | } | ||
447 | |||
448 | if (m_InventoryService.MoveItems(principal, items)) | ||
449 | return SuccessResult(); | ||
450 | else | ||
451 | return FailureResult(); | ||
346 | } | 452 | } |
347 | 453 | ||
348 | byte[] HandleDeleteItems(Dictionary<string,object> request) | 454 | byte[] HandleDeleteItems(Dictionary<string,object> request) |
349 | { | 455 | { |
350 | Dictionary<string,object> result = new Dictionary<string,object>(); | 456 | Dictionary<string, object> result = new Dictionary<string, object>(); |
457 | UUID principal = UUID.Zero; | ||
458 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
459 | List<string> slist = (List<string>)request["ITEMS"]; | ||
460 | List<UUID> uuids = new List<UUID>(); | ||
461 | foreach (string s in slist) | ||
462 | { | ||
463 | UUID u = UUID.Zero; | ||
464 | if (UUID.TryParse(s, out u)) | ||
465 | uuids.Add(u); | ||
466 | } | ||
351 | 467 | ||
352 | string xmlString = ServerUtils.BuildXmlResponse(result); | 468 | if (m_InventoryService.DeleteItems(principal, uuids)) |
353 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 469 | return SuccessResult(); |
354 | UTF8Encoding encoding = new UTF8Encoding(); | 470 | else |
355 | return encoding.GetBytes(xmlString); | 471 | return |
472 | FailureResult(); | ||
356 | } | 473 | } |
357 | 474 | ||
358 | byte[] HandleGetItem(Dictionary<string,object> request) | 475 | byte[] HandleGetItem(Dictionary<string,object> request) |
359 | { | 476 | { |
360 | Dictionary<string,object> result = new Dictionary<string,object>(); | 477 | Dictionary<string,object> result = new Dictionary<string,object>(); |
478 | UUID id = UUID.Zero; | ||
479 | UUID.TryParse(request["ID"].ToString(), out id); | ||
480 | |||
481 | InventoryItemBase item = new InventoryItemBase(id); | ||
482 | item = m_InventoryService.GetItem(item); | ||
483 | if (item != null) | ||
484 | result[item.ID.ToString()] = EncodeItem(item); | ||
361 | 485 | ||
362 | string xmlString = ServerUtils.BuildXmlResponse(result); | 486 | string xmlString = ServerUtils.BuildXmlResponse(result); |
363 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 487 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
@@ -367,7 +491,14 @@ namespace OpenSim.Server.Handlers.Asset | |||
367 | 491 | ||
368 | byte[] HandleGetFolder(Dictionary<string,object> request) | 492 | byte[] HandleGetFolder(Dictionary<string,object> request) |
369 | { | 493 | { |
370 | Dictionary<string,object> result = new Dictionary<string,object>(); | 494 | Dictionary<string, object> result = new Dictionary<string, object>(); |
495 | UUID id = UUID.Zero; | ||
496 | UUID.TryParse(request["ID"].ToString(), out id); | ||
497 | |||
498 | InventoryFolderBase folder = new InventoryFolderBase(id); | ||
499 | folder = m_InventoryService.GetFolder(folder); | ||
500 | if (folder != null) | ||
501 | result[folder.ID.ToString()] = EncodeFolder(folder); | ||
371 | 502 | ||
372 | string xmlString = ServerUtils.BuildXmlResponse(result); | 503 | string xmlString = ServerUtils.BuildXmlResponse(result); |
373 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 504 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
@@ -378,6 +509,13 @@ namespace OpenSim.Server.Handlers.Asset | |||
378 | byte[] HandleGetActiveGestures(Dictionary<string,object> request) | 509 | byte[] HandleGetActiveGestures(Dictionary<string,object> request) |
379 | { | 510 | { |
380 | Dictionary<string,object> result = new Dictionary<string,object>(); | 511 | Dictionary<string,object> result = new Dictionary<string,object>(); |
512 | UUID principal = UUID.Zero; | ||
513 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
514 | |||
515 | List<InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(principal); | ||
516 | if (gestures != null) | ||
517 | foreach (InventoryItemBase item in gestures) | ||
518 | result[item.ID.ToString()] = EncodeItem(item); | ||
381 | 519 | ||
382 | string xmlString = ServerUtils.BuildXmlResponse(result); | 520 | string xmlString = ServerUtils.BuildXmlResponse(result); |
383 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 521 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
@@ -388,7 +526,14 @@ namespace OpenSim.Server.Handlers.Asset | |||
388 | byte[] HandleGetAssetPermissions(Dictionary<string,object> request) | 526 | byte[] HandleGetAssetPermissions(Dictionary<string,object> request) |
389 | { | 527 | { |
390 | Dictionary<string,object> result = new Dictionary<string,object>(); | 528 | Dictionary<string,object> result = new Dictionary<string,object>(); |
529 | UUID principal = UUID.Zero; | ||
530 | UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); | ||
531 | UUID assetID = UUID.Zero; | ||
532 | UUID.TryParse(request["ASSET"].ToString(), out assetID); | ||
391 | 533 | ||
534 | int perms = m_InventoryService.GetAssetPermissions(principal, assetID); | ||
535 | |||
536 | result["RESULT"] = perms.ToString(); | ||
392 | string xmlString = ServerUtils.BuildXmlResponse(result); | 537 | string xmlString = ServerUtils.BuildXmlResponse(result); |
393 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | 538 | m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); |
394 | UTF8Encoding encoding = new UTF8Encoding(); | 539 | UTF8Encoding encoding = new UTF8Encoding(); |
@@ -409,6 +554,34 @@ namespace OpenSim.Server.Handlers.Asset | |||
409 | return ret; | 554 | return ret; |
410 | } | 555 | } |
411 | 556 | ||
557 | private Dictionary<string, object> EncodeItem(InventoryItemBase item) | ||
558 | { | ||
559 | Dictionary<string, object> ret = new Dictionary<string, object>(); | ||
560 | |||
561 | ret["AssetID"] = item.AssetID.ToString(); | ||
562 | ret["AssetType"] = item.AssetType.ToString(); | ||
563 | ret["BasePermissions"] = item.BasePermissions.ToString(); | ||
564 | ret["CreationDate"] = item.CreationDate.ToString(); | ||
565 | ret["CreatorId"] = item.CreatorId.ToString(); | ||
566 | ret["CurrentPermissions"] = item.CurrentPermissions.ToString(); | ||
567 | ret["Description"] = item.Description.ToString(); | ||
568 | ret["EveryOnePermissions"] = item.EveryOnePermissions.ToString(); | ||
569 | ret["Flags"] = item.Flags.ToString(); | ||
570 | ret["Folder"] = item.Folder.ToString(); | ||
571 | ret["GroupID"] = item.GroupID.ToString(); | ||
572 | ret["GroupedOwned"] = item.GroupOwned.ToString(); | ||
573 | ret["GroupPermissions"] = item.GroupPermissions.ToString(); | ||
574 | ret["ID"] = item.ID.ToString(); | ||
575 | ret["InvType"] = item.InvType.ToString(); | ||
576 | ret["Name"] = item.Name.ToString(); | ||
577 | ret["NextPermissions"] = item.NextPermissions.ToString(); | ||
578 | ret["Owner"] = item.Owner.ToString(); | ||
579 | ret["SalePrice"] = item.SalePrice.ToString(); | ||
580 | ret["SaleType"] = item.SaleType.ToString(); | ||
581 | |||
582 | return ret; | ||
583 | } | ||
584 | |||
412 | private InventoryFolderBase BuildFolder(Dictionary<string,object> data) | 585 | private InventoryFolderBase BuildFolder(Dictionary<string,object> data) |
413 | { | 586 | { |
414 | InventoryFolderBase folder = new InventoryFolderBase(); | 587 | InventoryFolderBase folder = new InventoryFolderBase(); |
diff --git a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs new file mode 100644 index 0000000..aaa958b --- /dev/null +++ b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs | |||
@@ -0,0 +1,149 @@ | |||
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 | |||
56 | public LLLoginHandlers(ILoginService service) | ||
57 | { | ||
58 | m_LocalService = service; | ||
59 | } | ||
60 | |||
61 | public XmlRpcResponse HandleXMLRPCLogin(XmlRpcRequest request, IPEndPoint remoteClient) | ||
62 | { | ||
63 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
64 | |||
65 | if (requestData != null) | ||
66 | { | ||
67 | if (requestData.ContainsKey("first") && requestData["first"] != null && | ||
68 | requestData.ContainsKey("last") && requestData["last"] != null && | ||
69 | requestData.ContainsKey("passwd") && requestData["passwd"] != null) | ||
70 | { | ||
71 | string first = requestData["first"].ToString(); | ||
72 | string last = requestData["last"].ToString(); | ||
73 | string passwd = requestData["passwd"].ToString(); | ||
74 | string startLocation = string.Empty; | ||
75 | if (requestData.ContainsKey("start")) | ||
76 | startLocation = requestData["start"].ToString(); | ||
77 | |||
78 | string clientVersion = "Unknown"; | ||
79 | if (requestData.Contains("version")) | ||
80 | clientVersion = requestData["version"].ToString(); | ||
81 | // We should do something interesting with the client version... | ||
82 | |||
83 | m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion); | ||
84 | |||
85 | LoginResponse reply = null; | ||
86 | reply = m_LocalService.Login(first, last, passwd, startLocation, remoteClient); | ||
87 | |||
88 | XmlRpcResponse response = new XmlRpcResponse(); | ||
89 | response.Value = reply.ToHashtable(); | ||
90 | return response; | ||
91 | |||
92 | } | ||
93 | } | ||
94 | |||
95 | return FailedXMLRPCResponse(); | ||
96 | |||
97 | } | ||
98 | |||
99 | public OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient) | ||
100 | { | ||
101 | if (request.Type == OSDType.Map) | ||
102 | { | ||
103 | OSDMap map = (OSDMap)request; | ||
104 | |||
105 | if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd")) | ||
106 | { | ||
107 | string startLocation = string.Empty; | ||
108 | |||
109 | if (map.ContainsKey("start")) | ||
110 | startLocation = map["start"].AsString(); | ||
111 | |||
112 | m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation); | ||
113 | |||
114 | LoginResponse reply = null; | ||
115 | reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, remoteClient); | ||
116 | return reply.ToOSDMap(); | ||
117 | |||
118 | } | ||
119 | } | ||
120 | |||
121 | return FailedOSDResponse(); | ||
122 | } | ||
123 | |||
124 | private XmlRpcResponse FailedXMLRPCResponse() | ||
125 | { | ||
126 | Hashtable hash = new Hashtable(); | ||
127 | hash["reason"] = "key"; | ||
128 | hash["message"] = "Incomplete login credentials. Check your username and password."; | ||
129 | hash["login"] = "false"; | ||
130 | |||
131 | XmlRpcResponse response = new XmlRpcResponse(); | ||
132 | response.Value = hash; | ||
133 | |||
134 | return response; | ||
135 | } | ||
136 | |||
137 | private OSD FailedOSDResponse() | ||
138 | { | ||
139 | OSDMap map = new OSDMap(); | ||
140 | |||
141 | map["reason"] = OSD.FromString("key"); | ||
142 | map["message"] = OSD.FromString("Invalid login credentials. Check your username and passwd."); | ||
143 | map["login"] = OSD.FromString("false"); | ||
144 | |||
145 | return map; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | } | ||
diff --git a/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs new file mode 100644 index 0000000..e24055b --- /dev/null +++ b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs | |||
@@ -0,0 +1,95 @@ | |||
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 | |||
47 | public LLLoginServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) : | ||
48 | base(config, server, String.Empty) | ||
49 | { | ||
50 | m_log.Debug("[LLLOGIN IN CONNECTOR]: Starting..."); | ||
51 | string loginService = ReadLocalServiceFromConfig(config); | ||
52 | |||
53 | ISimulationService simService = scene.RequestModuleInterface<ISimulationService>(); | ||
54 | ILibraryService libService = scene.RequestModuleInterface<ILibraryService>(); | ||
55 | |||
56 | Object[] args = new Object[] { config, simService, libService }; | ||
57 | m_LoginService = ServerUtils.LoadPlugin<ILoginService>(loginService, args); | ||
58 | |||
59 | InitializeHandlers(server); | ||
60 | } | ||
61 | |||
62 | public LLLoginServiceInConnector(IConfigSource config, IHttpServer server) : | ||
63 | base(config, server, String.Empty) | ||
64 | { | ||
65 | string loginService = ReadLocalServiceFromConfig(config); | ||
66 | |||
67 | Object[] args = new Object[] { config }; | ||
68 | |||
69 | m_LoginService = ServerUtils.LoadPlugin<ILoginService>(loginService, args); | ||
70 | |||
71 | InitializeHandlers(server); | ||
72 | } | ||
73 | |||
74 | private string ReadLocalServiceFromConfig(IConfigSource config) | ||
75 | { | ||
76 | IConfig serverConfig = config.Configs["LoginService"]; | ||
77 | if (serverConfig == null) | ||
78 | throw new Exception(String.Format("No section LoginService in config file")); | ||
79 | |||
80 | string loginService = serverConfig.GetString("LocalServiceModule", String.Empty); | ||
81 | if (loginService == string.Empty) | ||
82 | throw new Exception(String.Format("No LocalServiceModule for LoginService in config file")); | ||
83 | |||
84 | return loginService; | ||
85 | } | ||
86 | |||
87 | private void InitializeHandlers(IHttpServer server) | ||
88 | { | ||
89 | LLLoginHandlers loginHandlers = new LLLoginHandlers(m_LoginService); | ||
90 | server.AddXmlRPCHandler("login_to_simulator", loginHandlers.HandleXMLRPCLogin, false); | ||
91 | server.SetDefaultLLSDHandler(loginHandlers.HandleLLSDLogin); | ||
92 | } | ||
93 | |||
94 | } | ||
95 | } | ||
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs index b5ae54a..4ebf933 100644 --- a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs | |||
@@ -65,7 +65,7 @@ namespace OpenSim.Server.Handlers.Presence | |||
65 | body = body.Trim(); | 65 | body = body.Trim(); |
66 | 66 | ||
67 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | 67 | //m_log.DebugFormat("[XXX]: query String: {0}", body); |
68 | 68 | string method = string.Empty; | |
69 | try | 69 | try |
70 | { | 70 | { |
71 | Dictionary<string, object> request = | 71 | Dictionary<string, object> request = |
@@ -74,56 +74,195 @@ namespace OpenSim.Server.Handlers.Presence | |||
74 | if (!request.ContainsKey("METHOD")) | 74 | if (!request.ContainsKey("METHOD")) |
75 | return FailureResult(); | 75 | return FailureResult(); |
76 | 76 | ||
77 | string method = request["METHOD"].ToString(); | 77 | method = request["METHOD"].ToString(); |
78 | 78 | ||
79 | switch (method) | 79 | switch (method) |
80 | { | 80 | { |
81 | case "login": | ||
82 | return LoginAgent(request); | ||
83 | case "logout": | ||
84 | return LogoutAgent(request); | ||
85 | case "logoutregion": | ||
86 | return LogoutRegionAgents(request); | ||
81 | case "report": | 87 | case "report": |
82 | return Report(request); | 88 | return Report(request); |
89 | case "getagent": | ||
90 | return GetAgent(request); | ||
91 | case "getagents": | ||
92 | return GetAgents(request); | ||
93 | case "sethome": | ||
94 | return SetHome(request); | ||
83 | } | 95 | } |
84 | m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); | 96 | m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); |
85 | } | 97 | } |
86 | catch (Exception e) | 98 | catch (Exception e) |
87 | { | 99 | { |
88 | m_log.Debug("[PRESENCE HANDLER]: Exception {0}" + e); | 100 | m_log.DebugFormat("[PRESENCE HANDLER]: Exception in method {0}: {1}", method, e); |
89 | } | 101 | } |
90 | 102 | ||
91 | return FailureResult(); | 103 | return FailureResult(); |
92 | 104 | ||
93 | } | 105 | } |
94 | 106 | ||
107 | byte[] LoginAgent(Dictionary<string, object> request) | ||
108 | { | ||
109 | string user = String.Empty; | ||
110 | UUID session = UUID.Zero; | ||
111 | UUID ssession = UUID.Zero; | ||
112 | |||
113 | if (!request.ContainsKey("UserID") || !request.ContainsKey("SessionID")) | ||
114 | return FailureResult(); | ||
115 | |||
116 | user = request["UserID"].ToString(); | ||
117 | |||
118 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) | ||
119 | return FailureResult(); | ||
120 | |||
121 | if (request.ContainsKey("SecureSessionID")) | ||
122 | // If it's malformed, we go on with a Zero on it | ||
123 | UUID.TryParse(request["SecureSessionID"].ToString(), out ssession); | ||
124 | |||
125 | if (m_PresenceService.LoginAgent(user, session, ssession)) | ||
126 | return SuccessResult(); | ||
127 | |||
128 | return FailureResult(); | ||
129 | } | ||
130 | |||
131 | byte[] LogoutAgent(Dictionary<string, object> request) | ||
132 | { | ||
133 | UUID session = UUID.Zero; | ||
134 | Vector3 position = Vector3.Zero; | ||
135 | Vector3 lookat = Vector3.Zero; | ||
136 | |||
137 | if (!request.ContainsKey("SessionID")) | ||
138 | return FailureResult(); | ||
139 | |||
140 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) | ||
141 | return FailureResult(); | ||
142 | |||
143 | if (request.ContainsKey("Position") && request["Position"] != null) | ||
144 | Vector3.TryParse(request["Position"].ToString(), out position); | ||
145 | if (request.ContainsKey("LookAt") && request["Position"] != null) | ||
146 | Vector3.TryParse(request["LookAt"].ToString(), out lookat); | ||
147 | |||
148 | if (m_PresenceService.LogoutAgent(session, position, lookat)) | ||
149 | return SuccessResult(); | ||
150 | |||
151 | return FailureResult(); | ||
152 | } | ||
153 | |||
154 | byte[] LogoutRegionAgents(Dictionary<string, object> request) | ||
155 | { | ||
156 | UUID region = UUID.Zero; | ||
157 | |||
158 | if (!request.ContainsKey("RegionID")) | ||
159 | return FailureResult(); | ||
160 | |||
161 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) | ||
162 | return FailureResult(); | ||
163 | |||
164 | if (m_PresenceService.LogoutRegionAgents(region)) | ||
165 | return SuccessResult(); | ||
166 | |||
167 | return FailureResult(); | ||
168 | } | ||
169 | |||
95 | byte[] Report(Dictionary<string, object> request) | 170 | byte[] Report(Dictionary<string, object> request) |
96 | { | 171 | { |
97 | PresenceInfo info = new PresenceInfo(); | 172 | UUID session = UUID.Zero; |
98 | info.Data = new Dictionary<string, string>(); | 173 | UUID region = UUID.Zero; |
174 | Vector3 position = new Vector3(128, 128, 70); | ||
175 | Vector3 look = Vector3.Zero; | ||
99 | 176 | ||
100 | if (!request.ContainsKey("PrincipalID") || !request.ContainsKey("RegionID")) | 177 | if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID")) |
101 | return FailureResult(); | 178 | return FailureResult(); |
102 | 179 | ||
103 | if (!UUID.TryParse(request["PrincipalID"].ToString(), | 180 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) |
104 | out info.PrincipalID)) | ||
105 | return FailureResult(); | 181 | return FailureResult(); |
106 | 182 | ||
107 | if (!UUID.TryParse(request["RegionID"].ToString(), | 183 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) |
108 | out info.RegionID)) | ||
109 | return FailureResult(); | 184 | return FailureResult(); |
110 | 185 | ||
111 | foreach (KeyValuePair<string, object> kvp in request) | 186 | if (request.ContainsKey("position")) |
112 | { | 187 | Vector3.TryParse(request["position"].ToString(), out position); |
113 | if (kvp.Key == "METHOD" || | ||
114 | kvp.Key == "PrincipalID" || | ||
115 | kvp.Key == "RegionID") | ||
116 | continue; | ||
117 | 188 | ||
118 | info.Data[kvp.Key] = kvp.Value.ToString(); | 189 | if (request.ContainsKey("lookAt")) |
119 | } | 190 | Vector3.TryParse(request["lookAt"].ToString(), out look); |
120 | 191 | ||
121 | if (m_PresenceService.Report(info)) | 192 | if (m_PresenceService.ReportAgent(session, region, position, look)) |
193 | { | ||
122 | return SuccessResult(); | 194 | return SuccessResult(); |
195 | } | ||
123 | 196 | ||
124 | return FailureResult(); | 197 | return FailureResult(); |
125 | } | 198 | } |
126 | 199 | ||
200 | byte[] GetAgent(Dictionary<string, object> request) | ||
201 | { | ||
202 | UUID session = UUID.Zero; | ||
203 | |||
204 | if (!request.ContainsKey("SessionID")) | ||
205 | return FailureResult(); | ||
206 | |||
207 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) | ||
208 | return FailureResult(); | ||
209 | |||
210 | PresenceInfo pinfo = m_PresenceService.GetAgent(session); | ||
211 | |||
212 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
213 | if (pinfo == null) | ||
214 | result["result"] = "null"; | ||
215 | else | ||
216 | result["result"] = pinfo.ToKeyValuePairs(); | ||
217 | |||
218 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
219 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
220 | UTF8Encoding encoding = new UTF8Encoding(); | ||
221 | return encoding.GetBytes(xmlString); | ||
222 | } | ||
223 | |||
224 | byte[] GetAgents(Dictionary<string, object> request) | ||
225 | { | ||
226 | |||
227 | string[] userIDs; | ||
228 | |||
229 | if (!request.ContainsKey("uuids")) | ||
230 | { | ||
231 | m_log.DebugFormat("[PRESENCE HANDLER]: GetAgents called without required uuids argument"); | ||
232 | return FailureResult(); | ||
233 | } | ||
234 | |||
235 | if (!(request["uuids"] is List<string>)) | ||
236 | { | ||
237 | m_log.DebugFormat("[PRESENCE HANDLER]: GetAgents input argument was of unexpected type {0}", request["uuids"].GetType().ToString()); | ||
238 | return FailureResult(); | ||
239 | } | ||
240 | |||
241 | userIDs = ((List<string>)request["uuids"]).ToArray(); | ||
242 | |||
243 | PresenceInfo[] pinfos = m_PresenceService.GetAgents(userIDs); | ||
244 | |||
245 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
246 | if ((pinfos == null) || ((pinfos != null) && (pinfos.Length == 0))) | ||
247 | result["result"] = "null"; | ||
248 | else | ||
249 | { | ||
250 | int i = 0; | ||
251 | foreach (PresenceInfo pinfo in pinfos) | ||
252 | { | ||
253 | Dictionary<string, object> rinfoDict = pinfo.ToKeyValuePairs(); | ||
254 | result["presence" + i] = rinfoDict; | ||
255 | i++; | ||
256 | } | ||
257 | } | ||
258 | |||
259 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
260 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
261 | UTF8Encoding encoding = new UTF8Encoding(); | ||
262 | return encoding.GetBytes(xmlString); | ||
263 | } | ||
264 | |||
265 | |||
127 | private byte[] SuccessResult() | 266 | private byte[] SuccessResult() |
128 | { | 267 | { |
129 | XmlDocument doc = new XmlDocument(); | 268 | XmlDocument doc = new XmlDocument(); |
@@ -138,7 +277,7 @@ namespace OpenSim.Server.Handlers.Presence | |||
138 | 277 | ||
139 | doc.AppendChild(rootElement); | 278 | doc.AppendChild(rootElement); |
140 | 279 | ||
141 | XmlElement result = doc.CreateElement("", "Result", ""); | 280 | XmlElement result = doc.CreateElement("", "result", ""); |
142 | result.AppendChild(doc.CreateTextNode("Success")); | 281 | result.AppendChild(doc.CreateTextNode("Success")); |
143 | 282 | ||
144 | rootElement.AppendChild(result); | 283 | rootElement.AppendChild(result); |
@@ -160,7 +299,7 @@ namespace OpenSim.Server.Handlers.Presence | |||
160 | 299 | ||
161 | doc.AppendChild(rootElement); | 300 | doc.AppendChild(rootElement); |
162 | 301 | ||
163 | XmlElement result = doc.CreateElement("", "Result", ""); | 302 | XmlElement result = doc.CreateElement("", "result", ""); |
164 | result.AppendChild(doc.CreateTextNode("Failure")); | 303 | result.AppendChild(doc.CreateTextNode("Failure")); |
165 | 304 | ||
166 | rootElement.AppendChild(result); | 305 | rootElement.AppendChild(result); |
@@ -178,5 +317,32 @@ namespace OpenSim.Server.Handlers.Presence | |||
178 | 317 | ||
179 | return ms.ToArray(); | 318 | return ms.ToArray(); |
180 | } | 319 | } |
320 | |||
321 | byte[] SetHome(Dictionary<string, object> request) | ||
322 | { | ||
323 | UUID region = UUID.Zero; | ||
324 | Vector3 position = new Vector3(128, 128, 70); | ||
325 | Vector3 look = Vector3.Zero; | ||
326 | |||
327 | if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID")) | ||
328 | return FailureResult(); | ||
329 | |||
330 | string user = request["UserID"].ToString(); | ||
331 | |||
332 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) | ||
333 | return FailureResult(); | ||
334 | |||
335 | if (request.ContainsKey("position")) | ||
336 | Vector3.TryParse(request["position"].ToString(), out position); | ||
337 | |||
338 | if (request.ContainsKey("lookAt")) | ||
339 | Vector3.TryParse(request["lookAt"].ToString(), out look); | ||
340 | |||
341 | if (m_PresenceService.SetHomeLocation(user, region, position, look)) | ||
342 | return SuccessResult(); | ||
343 | |||
344 | return FailureResult(); | ||
345 | } | ||
346 | |||
181 | } | 347 | } |
182 | } | 348 | } |
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs index 3da72c7..ab3250d 100644 --- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | ||
29 | using System.IO; | 30 | using System.IO; |
30 | using System.Reflection; | 31 | using System.Reflection; |
31 | using System.Net; | 32 | using System.Net; |
@@ -34,6 +35,7 @@ using System.Text; | |||
34 | using OpenSim.Server.Base; | 35 | using OpenSim.Server.Base; |
35 | using OpenSim.Server.Handlers.Base; | 36 | using OpenSim.Server.Handlers.Base; |
36 | using OpenSim.Services.Interfaces; | 37 | using OpenSim.Services.Interfaces; |
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
37 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Servers.HttpServer; | 40 | using OpenSim.Framework.Servers.HttpServer; |
39 | 41 | ||
@@ -45,93 +47,113 @@ using log4net; | |||
45 | 47 | ||
46 | namespace OpenSim.Server.Handlers.Simulation | 48 | namespace OpenSim.Server.Handlers.Simulation |
47 | { | 49 | { |
48 | public class AgentGetHandler : BaseStreamHandler | 50 | public class AgentHandler |
49 | { | 51 | { |
50 | // TODO: unused: private ISimulationService m_SimulationService; | 52 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
51 | // TODO: unused: private IAuthenticationService m_AuthenticationService; | 53 | private ISimulationService m_SimulationService; |
54 | |||
55 | public AgentHandler() { } | ||
52 | 56 | ||
53 | public AgentGetHandler(ISimulationService service, IAuthenticationService authentication) : | 57 | public AgentHandler(ISimulationService sim) |
54 | base("GET", "/agent") | ||
55 | { | 58 | { |
56 | // TODO: unused: m_SimulationService = service; | 59 | m_SimulationService = sim; |
57 | // TODO: unused: m_AuthenticationService = authentication; | ||
58 | } | 60 | } |
59 | 61 | ||
60 | public override byte[] Handle(string path, Stream request, | 62 | public Hashtable Handler(Hashtable request) |
61 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
62 | { | 63 | { |
63 | // Not implemented yet | 64 | m_log.Debug("[CONNECTION DEBUGGING]: AgentHandler Called"); |
64 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
65 | return new byte[] { }; | ||
66 | } | ||
67 | } | ||
68 | 65 | ||
69 | public class AgentPostHandler : BaseStreamHandler | 66 | m_log.Debug("---------------------------"); |
70 | { | 67 | m_log.Debug(" >> uri=" + request["uri"]); |
71 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 68 | m_log.Debug(" >> content-type=" + request["content-type"]); |
72 | private ISimulationService m_SimulationService; | 69 | m_log.Debug(" >> http-method=" + request["http-method"]); |
73 | private IAuthenticationService m_AuthenticationService; | 70 | m_log.Debug("---------------------------\n"); |
74 | // TODO: unused: private bool m_AllowForeignGuests; | ||
75 | 71 | ||
76 | public AgentPostHandler(ISimulationService service, IAuthenticationService authentication, bool foreignGuests) : | 72 | Hashtable responsedata = new Hashtable(); |
77 | base("POST", "/agent") | 73 | responsedata["content_type"] = "text/html"; |
78 | { | 74 | responsedata["keepalive"] = false; |
79 | m_SimulationService = service; | ||
80 | m_AuthenticationService = authentication; | ||
81 | // TODO: unused: m_AllowForeignGuests = foreignGuests; | ||
82 | } | ||
83 | 75 | ||
84 | public override byte[] Handle(string path, Stream request, | ||
85 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
86 | { | ||
87 | byte[] result = new byte[0]; | ||
88 | 76 | ||
89 | UUID agentID; | 77 | UUID agentID; |
78 | UUID regionID; | ||
90 | string action; | 79 | string action; |
91 | ulong regionHandle; | 80 | if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action)) |
92 | if (!RestHandlerUtils.GetParams(path, out agentID, out regionHandle, out action)) | ||
93 | { | 81 | { |
94 | m_log.InfoFormat("[AgentPostHandler]: Invalid parameters for agent message {0}", path); | 82 | m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]); |
95 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | 83 | responsedata["int_response_code"] = 404; |
96 | httpResponse.StatusDescription = "Invalid parameters for agent message " + path; | 84 | responsedata["str_response_string"] = "false"; |
97 | 85 | ||
98 | return result; | 86 | return responsedata; |
99 | } | 87 | } |
100 | 88 | ||
101 | if (m_AuthenticationService != null) | 89 | // Next, let's parse the verb |
90 | string method = (string)request["http-method"]; | ||
91 | if (method.Equals("PUT")) | ||
102 | { | 92 | { |
103 | // Authentication | 93 | DoAgentPut(request, responsedata); |
104 | string authority = string.Empty; | 94 | return responsedata; |
105 | string authToken = string.Empty; | 95 | } |
106 | if (!RestHandlerUtils.GetAuthentication(httpRequest, out authority, out authToken)) | 96 | else if (method.Equals("POST")) |
107 | { | 97 | { |
108 | m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path); | 98 | DoAgentPost(request, responsedata, agentID); |
109 | httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized; | 99 | return responsedata; |
110 | return result; | 100 | } |
111 | } | 101 | else if (method.Equals("GET")) |
112 | // TODO: Rethink this | 102 | { |
113 | //if (!m_AuthenticationService.VerifyKey(agentID, authToken)) | 103 | DoAgentGet(request, responsedata, agentID, regionID); |
114 | //{ | 104 | return responsedata; |
115 | // m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path); | 105 | } |
116 | // httpResponse.StatusCode = (int)HttpStatusCode.Forbidden; | 106 | else if (method.Equals("DELETE")) |
117 | // return result; | 107 | { |
118 | //} | 108 | DoAgentDelete(request, responsedata, agentID, action, regionID); |
119 | m_log.DebugFormat("[AgentPostHandler]: Authentication succeeded for {0}", agentID); | 109 | return responsedata; |
120 | } | 110 | } |
111 | else | ||
112 | { | ||
113 | m_log.InfoFormat("[AGENT HANDLER]: method {0} not supported in agent message", method); | ||
114 | responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; | ||
115 | responsedata["str_response_string"] = "Method not allowed"; | ||
116 | |||
117 | return responsedata; | ||
118 | } | ||
119 | |||
120 | } | ||
121 | 121 | ||
122 | OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength); | 122 | protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) |
123 | { | ||
124 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
123 | if (args == null) | 125 | if (args == null) |
124 | { | 126 | { |
125 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | 127 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; |
126 | httpResponse.StatusDescription = "Unable to retrieve data"; | 128 | responsedata["str_response_string"] = "Bad request"; |
127 | m_log.DebugFormat("[AgentPostHandler]: Unable to retrieve data for post {0}", path); | 129 | return; |
128 | return result; | ||
129 | } | 130 | } |
130 | 131 | ||
131 | // retrieve the regionhandle | 132 | // retrieve the input arguments |
132 | ulong regionhandle = 0; | 133 | int x = 0, y = 0; |
133 | if (args["destination_handle"] != null) | 134 | UUID uuid = UUID.Zero; |
134 | UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); | 135 | string regionname = string.Empty; |
136 | uint teleportFlags = 0; | ||
137 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
138 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
139 | else | ||
140 | m_log.WarnFormat(" -- request didn't have destination_x"); | ||
141 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
142 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
143 | else | ||
144 | m_log.WarnFormat(" -- request didn't have destination_y"); | ||
145 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
146 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
147 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
148 | regionname = args["destination_name"].ToString(); | ||
149 | if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null) | ||
150 | teleportFlags = args["teleport_flags"].AsUInteger(); | ||
151 | |||
152 | GridRegion destination = new GridRegion(); | ||
153 | destination.RegionID = uuid; | ||
154 | destination.RegionLocX = x; | ||
155 | destination.RegionLocY = y; | ||
156 | destination.RegionName = regionname; | ||
135 | 157 | ||
136 | AgentCircuitData aCircuit = new AgentCircuitData(); | 158 | AgentCircuitData aCircuit = new AgentCircuitData(); |
137 | try | 159 | try |
@@ -140,70 +162,186 @@ namespace OpenSim.Server.Handlers.Simulation | |||
140 | } | 162 | } |
141 | catch (Exception ex) | 163 | catch (Exception ex) |
142 | { | 164 | { |
143 | m_log.InfoFormat("[AgentPostHandler]: exception on unpacking CreateAgent message {0}", ex.Message); | 165 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message); |
144 | httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; | 166 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; |
145 | httpResponse.StatusDescription = "Problems with data deserialization"; | 167 | responsedata["str_response_string"] = "Bad request"; |
146 | return result; | 168 | return; |
147 | } | 169 | } |
148 | 170 | ||
149 | string reason = string.Empty; | 171 | OSDMap resp = new OSDMap(2); |
172 | string reason = String.Empty; | ||
150 | 173 | ||
151 | // We need to clean up a few things in the user service before I can do this | 174 | // This is the meaning of POST agent |
152 | //if (m_AllowForeignGuests) | 175 | //m_regionClient.AdjustUserInformation(aCircuit); |
153 | // m_regionClient.AdjustUserInformation(aCircuit); | 176 | //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); |
177 | bool result = CreateAgent(destination, aCircuit, teleportFlags, out reason); | ||
154 | 178 | ||
155 | // Finally! | 179 | resp["reason"] = OSD.FromString(reason); |
156 | bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, out reason); | 180 | resp["success"] = OSD.FromBoolean(result); |
157 | 181 | ||
158 | OSDMap resp = new OSDMap(1); | 182 | // TODO: add reason if not String.Empty? |
183 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
184 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); | ||
185 | } | ||
159 | 186 | ||
160 | resp["success"] = OSD.FromBoolean(success); | 187 | // subclasses can override this |
188 | protected virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) | ||
189 | { | ||
190 | return m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); | ||
191 | } | ||
161 | 192 | ||
162 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | 193 | protected void DoAgentPut(Hashtable request, Hashtable responsedata) |
194 | { | ||
195 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
196 | if (args == null) | ||
197 | { | ||
198 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
199 | responsedata["str_response_string"] = "Bad request"; | ||
200 | return; | ||
201 | } | ||
163 | 202 | ||
164 | return Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp)); | 203 | // retrieve the input arguments |
165 | } | 204 | int x = 0, y = 0; |
166 | } | 205 | UUID uuid = UUID.Zero; |
206 | string regionname = string.Empty; | ||
207 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
208 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
209 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
210 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
211 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
212 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
213 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
214 | regionname = args["destination_name"].ToString(); | ||
167 | 215 | ||
168 | public class AgentPutHandler : BaseStreamHandler | 216 | GridRegion destination = new GridRegion(); |
169 | { | 217 | destination.RegionID = uuid; |
170 | // TODO: unused: private ISimulationService m_SimulationService; | 218 | destination.RegionLocX = x; |
171 | // TODO: unused: private IAuthenticationService m_AuthenticationService; | 219 | destination.RegionLocY = y; |
220 | destination.RegionName = regionname; | ||
172 | 221 | ||
173 | public AgentPutHandler(ISimulationService service, IAuthenticationService authentication) : | 222 | string messageType; |
174 | base("PUT", "/agent") | 223 | if (args["message_type"] != null) |
175 | { | 224 | messageType = args["message_type"].AsString(); |
176 | // TODO: unused: m_SimulationService = service; | 225 | else |
177 | // TODO: unused: m_AuthenticationService = authentication; | 226 | { |
227 | m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. "); | ||
228 | messageType = "AgentData"; | ||
229 | } | ||
230 | |||
231 | bool result = true; | ||
232 | if ("AgentData".Equals(messageType)) | ||
233 | { | ||
234 | AgentData agent = new AgentData(); | ||
235 | try | ||
236 | { | ||
237 | agent.Unpack(args); | ||
238 | } | ||
239 | catch (Exception ex) | ||
240 | { | ||
241 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); | ||
242 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
243 | responsedata["str_response_string"] = "Bad request"; | ||
244 | return; | ||
245 | } | ||
246 | |||
247 | //agent.Dump(); | ||
248 | // This is one of the meanings of PUT agent | ||
249 | result = UpdateAgent(destination, agent); | ||
250 | |||
251 | } | ||
252 | else if ("AgentPosition".Equals(messageType)) | ||
253 | { | ||
254 | AgentPosition agent = new AgentPosition(); | ||
255 | try | ||
256 | { | ||
257 | agent.Unpack(args); | ||
258 | } | ||
259 | catch (Exception ex) | ||
260 | { | ||
261 | m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); | ||
262 | return; | ||
263 | } | ||
264 | //agent.Dump(); | ||
265 | // This is one of the meanings of PUT agent | ||
266 | result = m_SimulationService.UpdateAgent(destination, agent); | ||
267 | |||
268 | } | ||
269 | |||
270 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
271 | responsedata["str_response_string"] = result.ToString(); | ||
272 | //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead | ||
178 | } | 273 | } |
179 | 274 | ||
180 | public override byte[] Handle(string path, Stream request, | 275 | // subclasses cab override this |
181 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | 276 | protected virtual bool UpdateAgent(GridRegion destination, AgentData agent) |
182 | { | 277 | { |
183 | // Not implemented yet | 278 | return m_SimulationService.UpdateAgent(destination, agent); |
184 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
185 | return new byte[] { }; | ||
186 | } | 279 | } |
187 | } | ||
188 | 280 | ||
189 | public class AgentDeleteHandler : BaseStreamHandler | 281 | protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, UUID regionID) |
190 | { | 282 | { |
191 | // TODO: unused: private ISimulationService m_SimulationService; | 283 | GridRegion destination = new GridRegion(); |
192 | // TODO: unused: private IAuthenticationService m_AuthenticationService; | 284 | destination.RegionID = regionID; |
285 | |||
286 | IAgentData agent = null; | ||
287 | bool result = m_SimulationService.RetrieveAgent(destination, id, out agent); | ||
288 | OSDMap map = null; | ||
289 | if (result) | ||
290 | { | ||
291 | if (agent != null) // just to make sure | ||
292 | { | ||
293 | map = agent.Pack(); | ||
294 | string strBuffer = ""; | ||
295 | try | ||
296 | { | ||
297 | strBuffer = OSDParser.SerializeJsonString(map); | ||
298 | } | ||
299 | catch (Exception e) | ||
300 | { | ||
301 | m_log.WarnFormat("[AGENT HANDLER]: Exception thrown on serialization of DoAgentGet: {0}", e.Message); | ||
302 | responsedata["int_response_code"] = HttpStatusCode.InternalServerError; | ||
303 | // ignore. buffer will be empty, caller should check. | ||
304 | } | ||
305 | |||
306 | responsedata["content_type"] = "application/json"; | ||
307 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
308 | responsedata["str_response_string"] = strBuffer; | ||
309 | } | ||
310 | else | ||
311 | { | ||
312 | responsedata["int_response_code"] = HttpStatusCode.InternalServerError; | ||
313 | responsedata["str_response_string"] = "Internal error"; | ||
314 | } | ||
315 | } | ||
316 | else | ||
317 | { | ||
318 | responsedata["int_response_code"] = HttpStatusCode.NotFound; | ||
319 | responsedata["str_response_string"] = "Not Found"; | ||
320 | } | ||
321 | } | ||
193 | 322 | ||
194 | public AgentDeleteHandler(ISimulationService service, IAuthenticationService authentication) : | 323 | protected void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID) |
195 | base("DELETE", "/agent") | ||
196 | { | 324 | { |
197 | // TODO: unused: m_SimulationService = service; | 325 | m_log.Debug(" >>> DoDelete action:" + action + "; RegionID:" + regionID); |
198 | // TODO: unused: m_AuthenticationService = authentication; | 326 | |
327 | GridRegion destination = new GridRegion(); | ||
328 | destination.RegionID = regionID; | ||
329 | |||
330 | if (action.Equals("release")) | ||
331 | ReleaseAgent(regionID, id); | ||
332 | else | ||
333 | m_SimulationService.CloseAgent(destination, id); | ||
334 | |||
335 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
336 | responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); | ||
337 | |||
338 | m_log.Debug("[AGENT HANDLER]: Agent Released/Deleted."); | ||
199 | } | 339 | } |
200 | 340 | ||
201 | public override byte[] Handle(string path, Stream request, | 341 | protected virtual void ReleaseAgent(UUID regionID, UUID id) |
202 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
203 | { | 342 | { |
204 | // Not implemented yet | 343 | m_SimulationService.ReleaseAgent(regionID, id, ""); |
205 | httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; | ||
206 | return new byte[] { }; | ||
207 | } | 344 | } |
208 | } | 345 | } |
346 | |||
209 | } | 347 | } |
diff --git a/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs new file mode 100644 index 0000000..33e5aa6 --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs | |||
@@ -0,0 +1,246 @@ | |||
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 | // Next, let's parse the verb | ||
88 | string method = (string)request["http-method"]; | ||
89 | if (method.Equals("POST")) | ||
90 | { | ||
91 | DoObjectPost(request, responsedata, regionID); | ||
92 | return responsedata; | ||
93 | } | ||
94 | else if (method.Equals("PUT")) | ||
95 | { | ||
96 | DoObjectPut(request, responsedata, regionID); | ||
97 | return responsedata; | ||
98 | } | ||
99 | //else if (method.Equals("DELETE")) | ||
100 | //{ | ||
101 | // DoObjectDelete(request, responsedata, agentID, action, regionHandle); | ||
102 | // return responsedata; | ||
103 | //} | ||
104 | else | ||
105 | { | ||
106 | m_log.InfoFormat("[OBJECT HANDLER]: method {0} not supported in object message", method); | ||
107 | responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; | ||
108 | responsedata["str_response_string"] = "Mthod not allowed"; | ||
109 | |||
110 | return responsedata; | ||
111 | } | ||
112 | |||
113 | } | ||
114 | |||
115 | protected void DoObjectPost(Hashtable request, Hashtable responsedata, UUID regionID) | ||
116 | { | ||
117 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
118 | if (args == null) | ||
119 | { | ||
120 | responsedata["int_response_code"] = 400; | ||
121 | responsedata["str_response_string"] = "false"; | ||
122 | return; | ||
123 | } | ||
124 | // retrieve the input arguments | ||
125 | int x = 0, y = 0; | ||
126 | UUID uuid = UUID.Zero; | ||
127 | string regionname = string.Empty; | ||
128 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
129 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
130 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
131 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
132 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
133 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
134 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
135 | regionname = args["destination_name"].ToString(); | ||
136 | |||
137 | GridRegion destination = new GridRegion(); | ||
138 | destination.RegionID = uuid; | ||
139 | destination.RegionLocX = x; | ||
140 | destination.RegionLocY = y; | ||
141 | destination.RegionName = regionname; | ||
142 | |||
143 | string sogXmlStr = "", extraStr = "", stateXmlStr = ""; | ||
144 | if (args.ContainsKey("sog") && args["sog"] != null) | ||
145 | sogXmlStr = args["sog"].AsString(); | ||
146 | if (args.ContainsKey("extra") && args["extra"] != null) | ||
147 | extraStr = args["extra"].AsString(); | ||
148 | |||
149 | IScene s = m_SimulationService.GetScene(destination.RegionHandle); | ||
150 | ISceneObject sog = null; | ||
151 | try | ||
152 | { | ||
153 | //m_log.DebugFormat("[OBJECT HANDLER]: received {0}", sogXmlStr); | ||
154 | sog = s.DeserializeObject(sogXmlStr); | ||
155 | sog.ExtraFromXmlString(extraStr); | ||
156 | } | ||
157 | catch (Exception ex) | ||
158 | { | ||
159 | m_log.InfoFormat("[OBJECT HANDLER]: exception on deserializing scene object {0}", ex.Message); | ||
160 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
161 | responsedata["str_response_string"] = "Bad request"; | ||
162 | return; | ||
163 | } | ||
164 | |||
165 | if ((args["state"] != null) && s.AllowScriptCrossings) | ||
166 | { | ||
167 | stateXmlStr = args["state"].AsString(); | ||
168 | if (stateXmlStr != "") | ||
169 | { | ||
170 | try | ||
171 | { | ||
172 | sog.SetState(stateXmlStr, s); | ||
173 | } | ||
174 | catch (Exception ex) | ||
175 | { | ||
176 | m_log.InfoFormat("[OBJECT HANDLER]: exception on setting state for scene object {0}", ex.Message); | ||
177 | // ignore and continue | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | |||
182 | bool result = false; | ||
183 | try | ||
184 | { | ||
185 | // This is the meaning of POST object | ||
186 | result = CreateObject(destination, sog); | ||
187 | } | ||
188 | catch (Exception e) | ||
189 | { | ||
190 | m_log.DebugFormat("[OBJECT HANDLER]: Exception in CreateObject: {0}", e.StackTrace); | ||
191 | } | ||
192 | |||
193 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
194 | responsedata["str_response_string"] = result.ToString(); | ||
195 | } | ||
196 | |||
197 | // subclasses can override this | ||
198 | protected virtual bool CreateObject(GridRegion destination, ISceneObject sog) | ||
199 | { | ||
200 | return m_SimulationService.CreateObject(destination, sog, false); | ||
201 | } | ||
202 | |||
203 | protected virtual void DoObjectPut(Hashtable request, Hashtable responsedata, UUID regionID) | ||
204 | { | ||
205 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
206 | if (args == null) | ||
207 | { | ||
208 | responsedata["int_response_code"] = 400; | ||
209 | responsedata["str_response_string"] = "false"; | ||
210 | return; | ||
211 | } | ||
212 | |||
213 | // retrieve the input arguments | ||
214 | int x = 0, y = 0; | ||
215 | UUID uuid = UUID.Zero; | ||
216 | string regionname = string.Empty; | ||
217 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
218 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
219 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
220 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
221 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
222 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
223 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
224 | regionname = args["destination_name"].ToString(); | ||
225 | |||
226 | GridRegion destination = new GridRegion(); | ||
227 | destination.RegionID = uuid; | ||
228 | destination.RegionLocX = x; | ||
229 | destination.RegionLocY = y; | ||
230 | destination.RegionName = regionname; | ||
231 | |||
232 | UUID userID = UUID.Zero, itemID = UUID.Zero; | ||
233 | if (args.ContainsKey("userid") && args["userid"] != null) | ||
234 | userID = args["userid"].AsUUID(); | ||
235 | if (args.ContainsKey("itemid") && args["itemid"] != null) | ||
236 | itemID = args["itemid"].AsUUID(); | ||
237 | |||
238 | // This is the meaning of PUT object | ||
239 | bool result = m_SimulationService.CreateObject(destination, userID, itemID); | ||
240 | |||
241 | responsedata["int_response_code"] = 200; | ||
242 | responsedata["str_response_string"] = result.ToString(); | ||
243 | } | ||
244 | |||
245 | } | ||
246 | } \ No newline at end of file | ||
diff --git a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs index fe93fa5..55a575c 100644 --- a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs +++ b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs | |||
@@ -37,22 +37,15 @@ namespace OpenSim.Server.Handlers.Simulation | |||
37 | { | 37 | { |
38 | public class SimulationServiceInConnector : ServiceConnector | 38 | public class SimulationServiceInConnector : ServiceConnector |
39 | { | 39 | { |
40 | private ISimulationService m_SimulationService; | 40 | private ISimulationService m_LocalSimulationService; |
41 | private IAuthenticationService m_AuthenticationService; | 41 | private IAuthenticationService m_AuthenticationService; |
42 | 42 | ||
43 | public SimulationServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) : | 43 | public SimulationServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) : |
44 | base(config, server, String.Empty) | 44 | base(config, server, String.Empty) |
45 | { | 45 | { |
46 | IConfig serverConfig = config.Configs["SimulationService"]; | 46 | //IConfig serverConfig = config.Configs["SimulationService"]; |
47 | if (serverConfig == null) | 47 | //if (serverConfig == null) |
48 | throw new Exception("No section 'SimulationService' in config file"); | 48 | // throw new Exception("No section 'SimulationService' in config file"); |
49 | |||
50 | bool authentication = serverConfig.GetBoolean("RequireAuthentication", false); | ||
51 | |||
52 | if (authentication) | ||
53 | m_AuthenticationService = scene.RequestModuleInterface<IAuthenticationService>(); | ||
54 | |||
55 | bool foreignGuests = serverConfig.GetBoolean("AllowForeignGuests", false); | ||
56 | 49 | ||
57 | //string simService = serverConfig.GetString("LocalServiceModule", | 50 | //string simService = serverConfig.GetString("LocalServiceModule", |
58 | // String.Empty); | 51 | // String.Empty); |
@@ -61,20 +54,18 @@ namespace OpenSim.Server.Handlers.Simulation | |||
61 | // throw new Exception("No SimulationService in config file"); | 54 | // throw new Exception("No SimulationService in config file"); |
62 | 55 | ||
63 | //Object[] args = new Object[] { config }; | 56 | //Object[] args = new Object[] { config }; |
64 | m_SimulationService = scene.RequestModuleInterface<ISimulationService>(); | 57 | m_LocalSimulationService = scene.RequestModuleInterface<ISimulationService>(); |
65 | //ServerUtils.LoadPlugin<ISimulationService>(simService, args); | 58 | //ServerUtils.LoadPlugin<ISimulationService>(simService, args); |
66 | if (m_SimulationService == null) | ||
67 | throw new Exception("No Local ISimulationService Module"); | ||
68 | |||
69 | |||
70 | 59 | ||
71 | //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no")); | 60 | //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no")); |
72 | server.AddStreamHandler(new AgentGetHandler(m_SimulationService, m_AuthenticationService)); | 61 | //server.AddStreamHandler(new AgentGetHandler(m_SimulationService, m_AuthenticationService)); |
73 | server.AddStreamHandler(new AgentPostHandler(m_SimulationService, m_AuthenticationService, foreignGuests)); | 62 | //server.AddStreamHandler(new AgentPostHandler(m_SimulationService, m_AuthenticationService)); |
74 | server.AddStreamHandler(new AgentPutHandler(m_SimulationService, m_AuthenticationService)); | 63 | //server.AddStreamHandler(new AgentPutHandler(m_SimulationService, m_AuthenticationService)); |
75 | server.AddStreamHandler(new AgentDeleteHandler(m_SimulationService, m_AuthenticationService)); | 64 | //server.AddStreamHandler(new AgentDeleteHandler(m_SimulationService, m_AuthenticationService)); |
65 | server.AddHTTPHandler("/agent/", new AgentHandler(m_LocalSimulationService).Handler); | ||
66 | server.AddHTTPHandler("/object/", new ObjectHandler(m_LocalSimulationService).Handler); | ||
67 | |||
76 | //server.AddStreamHandler(new ObjectPostHandler(m_SimulationService, authentication)); | 68 | //server.AddStreamHandler(new ObjectPostHandler(m_SimulationService, authentication)); |
77 | //server.AddStreamHandler(new NeighborPostHandler(m_SimulationService, authentication)); | ||
78 | } | 69 | } |
79 | } | 70 | } |
80 | } | 71 | } |
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..f17a8de --- /dev/null +++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs | |||
@@ -0,0 +1,61 @@ | |||
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.UserAccounts | ||
36 | { | ||
37 | public class UserAccountServiceConnector : ServiceConnector | ||
38 | { | ||
39 | private IUserAccountService m_UserAccountService; | ||
40 | private string m_ConfigName = "UserAccountService"; | ||
41 | |||
42 | public UserAccountServiceConnector(IConfigSource config, IHttpServer server, string configName) : | ||
43 | base(config, server, configName) | ||
44 | { | ||
45 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
46 | if (serverConfig == null) | ||
47 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | ||
48 | |||
49 | string service = serverConfig.GetString("LocalServiceModule", | ||
50 | String.Empty); | ||
51 | |||
52 | if (service == String.Empty) | ||
53 | throw new Exception("No LocalServiceModule in config file"); | ||
54 | |||
55 | Object[] args = new Object[] { config }; | ||
56 | m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(service, args); | ||
57 | |||
58 | server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService)); | ||
59 | } | ||
60 | } | ||
61 | } | ||
diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs new file mode 100644 index 0000000..6a82165 --- /dev/null +++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs | |||
@@ -0,0 +1,258 @@ | |||
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 OpenMetaverse; | ||
44 | |||
45 | namespace OpenSim.Server.Handlers.UserAccounts | ||
46 | { | ||
47 | public class UserAccountServerPostHandler : BaseStreamHandler | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private IUserAccountService m_UserAccountService; | ||
52 | |||
53 | public UserAccountServerPostHandler(IUserAccountService service) : | ||
54 | base("POST", "/accounts") | ||
55 | { | ||
56 | m_UserAccountService = service; | ||
57 | } | ||
58 | |||
59 | public override byte[] Handle(string path, Stream requestData, | ||
60 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
61 | { | ||
62 | StreamReader sr = new StreamReader(requestData); | ||
63 | string body = sr.ReadToEnd(); | ||
64 | sr.Close(); | ||
65 | body = body.Trim(); | ||
66 | |||
67 | // We need to check the authorization header | ||
68 | //httpRequest.Headers["authorization"] ... | ||
69 | |||
70 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
71 | string method = string.Empty; | ||
72 | try | ||
73 | { | ||
74 | Dictionary<string, object> request = | ||
75 | ServerUtils.ParseQueryString(body); | ||
76 | |||
77 | if (!request.ContainsKey("METHOD")) | ||
78 | return FailureResult(); | ||
79 | |||
80 | method = request["METHOD"].ToString(); | ||
81 | |||
82 | switch (method) | ||
83 | { | ||
84 | case "getaccount": | ||
85 | return GetAccount(request); | ||
86 | case "getaccounts": | ||
87 | return GetAccounts(request); | ||
88 | case "setaccount": | ||
89 | return StoreAccount(request); | ||
90 | } | ||
91 | m_log.DebugFormat("[USER SERVICE HANDLER]: unknown method request: {0}", method); | ||
92 | } | ||
93 | catch (Exception e) | ||
94 | { | ||
95 | m_log.DebugFormat("[USER SERVICE HANDLER]: Exception in method {0}: {1}", method, e); | ||
96 | } | ||
97 | |||
98 | return FailureResult(); | ||
99 | |||
100 | } | ||
101 | |||
102 | byte[] GetAccount(Dictionary<string, object> request) | ||
103 | { | ||
104 | UserAccount account = null; | ||
105 | UUID scopeID = UUID.Zero; | ||
106 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
107 | |||
108 | if (!request.ContainsKey("ScopeID")) | ||
109 | { | ||
110 | result["result"] = "null"; | ||
111 | return ResultToBytes(result); | ||
112 | } | ||
113 | |||
114 | if (!UUID.TryParse(request["ScopeID"].ToString(), out scopeID)) | ||
115 | { | ||
116 | result["result"] = "null"; | ||
117 | return ResultToBytes(result); | ||
118 | } | ||
119 | |||
120 | if (request.ContainsKey("UserID") && request["UserID"] != null) | ||
121 | { | ||
122 | UUID userID; | ||
123 | if (UUID.TryParse(request["UserID"].ToString(), out userID)) | ||
124 | account = m_UserAccountService.GetUserAccount(scopeID, userID); | ||
125 | } | ||
126 | |||
127 | else if (request.ContainsKey("Email") && request["Email"] != null) | ||
128 | account = m_UserAccountService.GetUserAccount(scopeID, request["Email"].ToString()); | ||
129 | |||
130 | else if (request.ContainsKey("FirstName") && request.ContainsKey("LastName") && | ||
131 | request["FirstName"] != null && request["LastName"] != null) | ||
132 | account = m_UserAccountService.GetUserAccount(scopeID, request["FirstName"].ToString(), request["LastName"].ToString()); | ||
133 | |||
134 | if (account == null) | ||
135 | result["result"] = "null"; | ||
136 | else | ||
137 | { | ||
138 | result["result"] = account.ToKeyValuePairs(); | ||
139 | } | ||
140 | |||
141 | return ResultToBytes(result); | ||
142 | } | ||
143 | |||
144 | byte[] GetAccounts(Dictionary<string, object> request) | ||
145 | { | ||
146 | if (!request.ContainsKey("ScopeID") || !request.ContainsKey("query")) | ||
147 | return FailureResult(); | ||
148 | |||
149 | UUID scopeID = UUID.Zero; | ||
150 | if (!UUID.TryParse(request["ScopeID"].ToString(), out scopeID)) | ||
151 | return FailureResult(); | ||
152 | |||
153 | string query = request["query"].ToString(); | ||
154 | |||
155 | List<UserAccount> accounts = m_UserAccountService.GetUserAccounts(scopeID, query); | ||
156 | |||
157 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
158 | if ((accounts == null) || ((accounts != null) && (accounts.Count == 0))) | ||
159 | result["result"] = "null"; | ||
160 | else | ||
161 | { | ||
162 | int i = 0; | ||
163 | foreach (UserAccount acc in accounts) | ||
164 | { | ||
165 | Dictionary<string, object> rinfoDict = acc.ToKeyValuePairs(); | ||
166 | result["account" + i] = rinfoDict; | ||
167 | i++; | ||
168 | } | ||
169 | } | ||
170 | |||
171 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
172 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
173 | UTF8Encoding encoding = new UTF8Encoding(); | ||
174 | return encoding.GetBytes(xmlString); | ||
175 | } | ||
176 | |||
177 | byte[] StoreAccount(Dictionary<string, object> request) | ||
178 | { | ||
179 | //if (!request.ContainsKey("account")) | ||
180 | // return FailureResult(); | ||
181 | //if (request["account"] == null) | ||
182 | // return FailureResult(); | ||
183 | //if (!(request["account"] is Dictionary<string, object>)) | ||
184 | // return FailureResult(); | ||
185 | |||
186 | UserAccount account = new UserAccount(request); | ||
187 | |||
188 | if (m_UserAccountService.StoreUserAccount(account)) | ||
189 | return SuccessResult(); | ||
190 | |||
191 | return FailureResult(); | ||
192 | } | ||
193 | |||
194 | private byte[] SuccessResult() | ||
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("Success")); | ||
210 | |||
211 | rootElement.AppendChild(result); | ||
212 | |||
213 | return DocToBytes(doc); | ||
214 | } | ||
215 | |||
216 | private byte[] FailureResult() | ||
217 | { | ||
218 | XmlDocument doc = new XmlDocument(); | ||
219 | |||
220 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
221 | "", ""); | ||
222 | |||
223 | doc.AppendChild(xmlnode); | ||
224 | |||
225 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
226 | ""); | ||
227 | |||
228 | doc.AppendChild(rootElement); | ||
229 | |||
230 | XmlElement result = doc.CreateElement("", "result", ""); | ||
231 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
232 | |||
233 | rootElement.AppendChild(result); | ||
234 | |||
235 | return DocToBytes(doc); | ||
236 | } | ||
237 | |||
238 | private byte[] DocToBytes(XmlDocument doc) | ||
239 | { | ||
240 | MemoryStream ms = new MemoryStream(); | ||
241 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
242 | xw.Formatting = Formatting.Indented; | ||
243 | doc.WriteTo(xw); | ||
244 | xw.Flush(); | ||
245 | |||
246 | return ms.ToArray(); | ||
247 | } | ||
248 | |||
249 | private byte[] ResultToBytes(Dictionary<string, object> result) | ||
250 | { | ||
251 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
252 | UTF8Encoding encoding = new UTF8Encoding(); | ||
253 | return encoding.GetBytes(xmlString); | ||
254 | } | ||
255 | |||
256 | |||
257 | } | ||
258 | } | ||