aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Server/Handlers
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Server/Handlers')
-rw-r--r--OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs206
-rw-r--r--OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs64
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetServerConnector.cs26
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs9
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs100
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs28
-rw-r--r--OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs87
-rw-r--r--OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs1
-rw-r--r--OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs5
-rw-r--r--OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs27
-rw-r--r--OpenSim/Server/Handlers/Authentication/OpenIdServerHandler.cs30
-rw-r--r--OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs2
-rw-r--r--OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs5
-rw-r--r--OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs22
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakes.cs148
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs71
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs69
-rw-r--r--OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs76
-rw-r--r--OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs343
-rw-r--r--OpenSim/Server/Handlers/Friends/FriendServerConnector.cs4
-rw-r--r--OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs22
-rw-r--r--OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs21
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerConnector.cs5
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs99
-rw-r--r--OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs5
-rw-r--r--OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs29
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs5
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs8
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs22
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HeloServerConnector.cs4
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs202
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs20
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs7
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs19
-rw-r--r--OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs10
-rw-r--r--OpenSim/Server/Handlers/Inventory/InventoryServerMoveItemsHandler.cs2
-rw-r--r--OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs179
-rw-r--r--OpenSim/Server/Handlers/Login/LLLoginHandlers.cs67
-rw-r--r--OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs25
-rw-r--r--OpenSim/Server/Handlers/Map/MapAddServerConnector.cs35
-rw-r--r--OpenSim/Server/Handlers/Map/MapGetServerConnector.cs2
-rw-r--r--OpenSim/Server/Handlers/Neighbour/NeighbourHandlers.cs8
-rw-r--r--OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs5
-rw-r--r--OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs22
-rw-r--r--OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs109
-rw-r--r--OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs513
-rw-r--r--OpenSim/Server/Handlers/Properties/AssemblyInfo.cs4
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs369
-rw-r--r--OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs5
-rw-r--r--OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs27
50 files changed, 2564 insertions, 609 deletions
diff --git a/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs
new file mode 100644
index 0000000..713b755
--- /dev/null
+++ b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServerPostHandler.cs
@@ -0,0 +1,206 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework;
42using OpenSim.Framework.ServiceAuth;
43using OpenSim.Framework.Servers.HttpServer;
44using OpenMetaverse;
45
46namespace OpenSim.Server.Handlers.AgentPreferences
47{
48 public class AgentPreferencesServerPostHandler : BaseStreamHandler
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private IAgentPreferencesService m_AgentPreferencesService;
53
54 public AgentPreferencesServerPostHandler(IAgentPreferencesService service, IServiceAuth auth) :
55 base("POST", "/agentprefs", auth)
56 {
57 m_AgentPreferencesService = service;
58 }
59
60 protected override byte[] ProcessRequest(string path, Stream requestData,
61 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
62 {
63 StreamReader sr = new StreamReader(requestData);
64 string body = sr.ReadToEnd();
65 sr.Close();
66 body = body.Trim();
67
68 //m_log.DebugFormat("[XXX]: query String: {0}", body);
69
70 try
71 {
72 Dictionary<string, object> request =
73 ServerUtils.ParseQueryString(body);
74
75 if (!request.ContainsKey("METHOD"))
76 return FailureResult();
77
78 string method = request["METHOD"].ToString();
79
80 switch (method)
81 {
82 case "getagentprefs":
83 return GetAgentPrefs(request);
84 case "setagentprefs":
85 return SetAgentPrefs(request);
86 case "getagentlang":
87 return GetAgentLang(request);
88 }
89 m_log.DebugFormat("[AGENT PREFERENCES HANDLER]: unknown method request: {0}", method);
90 }
91 catch (Exception e)
92 {
93 m_log.DebugFormat("[AGENT PREFERENCES HANDLER]: Exception {0}", e);
94 }
95
96 return FailureResult();
97 }
98
99 byte[] GetAgentPrefs(Dictionary<string, object> request)
100 {
101 if (!request.ContainsKey("UserID"))
102 return FailureResult();
103
104 UUID userID;
105 if (!UUID.TryParse(request["UserID"].ToString(), out userID))
106 return FailureResult();
107 AgentPrefs prefs = m_AgentPreferencesService.GetAgentPreferences(userID);
108 Dictionary<string, object> result = new Dictionary<string, object>();
109 result = prefs.ToKeyValuePairs();
110
111 string xmlString = ServerUtils.BuildXmlResponse(result);
112
113 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
114 }
115
116 byte[] SetAgentPrefs(Dictionary<string, object> request)
117 {
118 if (!request.ContainsKey("PrincipalID") || !request.ContainsKey("AccessPrefs") || !request.ContainsKey("HoverHeight")
119 || !request.ContainsKey("Language") || !request.ContainsKey("LanguageIsPublic") || !request.ContainsKey("PermEveryone")
120 || !request.ContainsKey("PermGroup") || !request.ContainsKey("PermNextOwner"))
121 {
122 return FailureResult();
123 }
124
125 UUID userID;
126 if (!UUID.TryParse(request["PrincipalID"].ToString(), out userID))
127 return FailureResult();
128
129 AgentPrefs data = new AgentPrefs(userID);
130 data.AccessPrefs = request["AccessPrefs"].ToString();
131 data.HoverHeight = double.Parse(request["HoverHeight"].ToString());
132 data.Language = request["Language"].ToString();
133 data.LanguageIsPublic = bool.Parse(request["LanguageIsPublic"].ToString());
134 data.PermEveryone = int.Parse(request["PermEveryone"].ToString());
135 data.PermGroup = int.Parse(request["PermGroup"].ToString());
136 data.PermNextOwner = int.Parse(request["PermNextOwner"].ToString());
137
138 return m_AgentPreferencesService.StoreAgentPreferences(data) ? SuccessResult() : FailureResult();
139 }
140
141 byte[] GetAgentLang(Dictionary<string, object> request)
142 {
143 if (!request.ContainsKey("UserID"))
144 return FailureResult();
145 UUID userID;
146 if (!UUID.TryParse(request["UserID"].ToString(), out userID))
147 return FailureResult();
148
149 string lang = "en-us";
150 AgentPrefs prefs = m_AgentPreferencesService.GetAgentPreferences(userID);
151 if (prefs != null)
152 {
153 if (prefs.LanguageIsPublic)
154 lang = prefs.Language;
155 }
156 Dictionary<string, object> result = new Dictionary<string, object>();
157 result["Language"] = lang;
158 string xmlString = ServerUtils.BuildXmlResponse(result);
159 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
160 }
161
162 private byte[] SuccessResult()
163 {
164 XmlDocument doc = new XmlDocument();
165
166 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
167 "", "");
168
169 doc.AppendChild(xmlnode);
170
171 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
172 "");
173
174 doc.AppendChild(rootElement);
175
176 XmlElement result = doc.CreateElement("", "result", "");
177 result.AppendChild(doc.CreateTextNode("Success"));
178
179 rootElement.AppendChild(result);
180
181 return Util.DocToBytes(doc);
182 }
183
184 private byte[] FailureResult()
185 {
186 XmlDocument doc = new XmlDocument();
187
188 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
189 "", "");
190
191 doc.AppendChild(xmlnode);
192
193 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
194 "");
195
196 doc.AppendChild(rootElement);
197
198 XmlElement result = doc.CreateElement("", "result", "");
199 result.AppendChild(doc.CreateTextNode("Failure"));
200
201 rootElement.AppendChild(result);
202
203 return Util.DocToBytes(doc);
204 }
205 }
206}
diff --git a/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs
new file mode 100644
index 0000000..a581ea2
--- /dev/null
+++ b/OpenSim/Server/Handlers/AgentPreferences/AgentPreferencesServiceConnector.cs
@@ -0,0 +1,64 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28
29using System;
30using Nini.Config;
31using OpenSim.Server.Base;
32using OpenSim.Services.Interfaces;
33using OpenSim.Framework.ServiceAuth;
34using OpenSim.Framework.Servers.HttpServer;
35using OpenSim.Server.Handlers.Base;
36
37namespace OpenSim.Server.Handlers.AgentPreferences
38{
39 public class AgentPreferencesServiceConnector : ServiceConnector
40 {
41 private IAgentPreferencesService m_AgentPreferencesService;
42 private string m_ConfigName = "AgentPreferencesService";
43
44 public AgentPreferencesServiceConnector(IConfigSource config, IHttpServer server, string configName) :
45 base(config, server, configName)
46 {
47 IConfig serverConfig = config.Configs[m_ConfigName];
48 if (serverConfig == null)
49 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
50
51 string service = serverConfig.GetString("LocalServiceModule", String.Empty);
52
53 if (String.IsNullOrWhiteSpace(service))
54 throw new Exception("No LocalServiceModule in config file");
55
56 Object[] args = new Object[] { config };
57 m_AgentPreferencesService = ServerUtils.LoadPlugin<IAgentPreferencesService>(service, args);
58
59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ;
60
61 server.AddStreamHandler(new AgentPreferencesServerPostHandler(m_AgentPreferencesService, auth));
62 }
63 }
64}
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
index ff45d94..ab81dd6 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
@@ -30,6 +30,7 @@ using System.IO;
30using Nini.Config; 30using Nini.Config;
31using OpenMetaverse; 31using OpenMetaverse;
32using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Framework.ServiceAuth;
33using OpenSim.Framework.Console; 34using OpenSim.Framework.Console;
34using OpenSim.Server.Base; 35using OpenSim.Server.Base;
35using OpenSim.Services.Interfaces; 36using OpenSim.Services.Interfaces;
@@ -69,6 +70,8 @@ namespace OpenSim.Server.Handlers.Asset
69 bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); 70 bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false);
70 bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false); 71 bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false);
71 72
73 string redirectURL = serverConfig.GetString("RedirectURL", string.Empty);
74
72 AllowedRemoteDeleteTypes allowedRemoteDeleteTypes; 75 AllowedRemoteDeleteTypes allowedRemoteDeleteTypes;
73 76
74 if (!allowDelete) 77 if (!allowDelete)
@@ -83,9 +86,12 @@ namespace OpenSim.Server.Handlers.Asset
83 allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile; 86 allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile;
84 } 87 }
85 88
86 server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); 89 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
87 server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); 90
88 server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes)); 91 server.AddStreamHandler(new AssetServerGetHandler(m_AssetService, auth, redirectURL));
92 server.AddStreamHandler(new AssetServerPostHandler(m_AssetService, auth));
93 server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes, auth));
94 server.AddStreamHandler(new AssetsExistHandler(m_AssetService));
89 95
90 MainConsole.Instance.Commands.AddCommand("Assets", false, 96 MainConsole.Instance.Commands.AddCommand("Assets", false,
91 "show asset", 97 "show asset",
@@ -119,16 +125,14 @@ namespace OpenSim.Server.Handlers.Asset
119 125
120 if (asset == null || asset.Data.Length == 0) 126 if (asset == null || asset.Data.Length == 0)
121 { 127 {
122 MainConsole.Instance.Output("Asset not found"); 128 MainConsole.Instance.OutputFormat("Could not find asset with ID {0}", args[2]);
123 return; 129 return;
124 } 130 }
125 131
126 m_AssetService.Delete(args[2]); 132 if (!m_AssetService.Delete(asset.ID))
127 133 MainConsole.Instance.OutputFormat("ERROR: Could not delete asset {0} {1}", asset.ID, asset.Name);
128 //MainConsole.Instance.Output("Asset deleted"); 134 else
129 // TODO: Implement this 135 MainConsole.Instance.OutputFormat("Deleted asset {0} {1}", asset.ID, asset.Name);
130
131 MainConsole.Instance.Output("Asset deletion not supported by database");
132 } 136 }
133 137
134 void HandleDumpAsset(string module, string[] args) 138 void HandleDumpAsset(string module, string[] args)
@@ -214,4 +218,4 @@ namespace OpenSim.Server.Handlers.Asset
214 } 218 }
215 } 219 }
216 } 220 }
217} \ No newline at end of file 221}
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
index 986394b..d85d471 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs
@@ -38,6 +38,7 @@ using System.Xml.Serialization;
38using OpenSim.Server.Base; 38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces; 39using OpenSim.Services.Interfaces;
40using OpenSim.Framework; 40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
41using OpenSim.Framework.Servers.HttpServer; 42using OpenSim.Framework.Servers.HttpServer;
42 43
43namespace OpenSim.Server.Handlers.Asset 44namespace OpenSim.Server.Handlers.Asset
@@ -70,7 +71,13 @@ namespace OpenSim.Server.Handlers.Asset
70 m_allowedTypes = allowedTypes; 71 m_allowedTypes = allowedTypes;
71 } 72 }
72 73
73 public override byte[] Handle(string path, Stream request, 74 public AssetServerDeleteHandler(IAssetService service, AllowedRemoteDeleteTypes allowedTypes, IServiceAuth auth) :
75 base("DELETE", "/assets", auth)
76 {
77 m_AssetService = service;
78 m_allowedTypes = allowedTypes;
79 }
80 protected override byte[] ProcessRequest(string path, Stream request,
74 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 81 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
75 { 82 {
76 bool result = false; 83 bool result = false;
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
index 8f7412b..91c5c54 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerGetHandler.cs
@@ -38,23 +38,34 @@ using System.Xml.Serialization;
38using OpenSim.Server.Base; 38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces; 39using OpenSim.Services.Interfaces;
40using OpenSim.Framework; 40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
41using OpenSim.Framework.Servers.HttpServer; 42using OpenSim.Framework.Servers.HttpServer;
42 43
43namespace OpenSim.Server.Handlers.Asset 44namespace OpenSim.Server.Handlers.Asset
44{ 45{
45 public class AssetServerGetHandler : BaseStreamHandler 46 public class AssetServerGetHandler : BaseStreamHandler
46 { 47 {
47 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 49
49 private IAssetService m_AssetService; 50 private IAssetService m_AssetService;
51 private string m_RedirectURL;
50 52
51 public AssetServerGetHandler(IAssetService service) : 53 public AssetServerGetHandler(IAssetService service) :
52 base("GET", "/assets") 54 base("GET", "/assets")
53 { 55 {
56 m_AssetService = service;
57 }
58
59 public AssetServerGetHandler(IAssetService service, IServiceAuth auth, string redirectURL) :
60 base("GET", "/assets", auth)
61 {
54 m_AssetService = service; 62 m_AssetService = service;
63 m_RedirectURL = redirectURL;
64 if (!m_RedirectURL.EndsWith("/"))
65 m_RedirectURL = m_RedirectURL.TrimEnd('/');
55 } 66 }
56 67
57 public override byte[] Handle(string path, Stream request, 68 protected override byte[] ProcessRequest(string path, Stream request,
58 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 69 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
59 { 70 {
60 byte[] result = new byte[0]; 71 byte[] result = new byte[0];
@@ -64,45 +75,62 @@ namespace OpenSim.Server.Handlers.Asset
64 if (p.Length == 0) 75 if (p.Length == 0)
65 return result; 76 return result;
66 77
67 if (p.Length > 1 && p[1] == "data") 78 string id = string.Empty;
79 if (p.Length > 1)
68 { 80 {
69 result = m_AssetService.GetData(p[0]); 81 id = p[0];
70 if (result == null) 82 string cmd = p[1];
83
84 if (cmd == "data")
71 { 85 {
72 httpResponse.StatusCode = (int)HttpStatusCode.NotFound; 86 result = m_AssetService.GetData(id);
73 httpResponse.ContentType = "text/plain"; 87 if (result == null)
74 result = new byte[0]; 88 {
89 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
90 httpResponse.ContentType = "text/plain";
91 result = new byte[0];
92 }
93 else
94 {
95 httpResponse.StatusCode = (int)HttpStatusCode.OK;
96 httpResponse.ContentType = "application/octet-stream";
97 }
75 } 98 }
76 else 99 else if (cmd == "metadata")
77 { 100 {
78 httpResponse.StatusCode = (int)HttpStatusCode.OK; 101 AssetMetadata metadata = m_AssetService.GetMetadata(id);
79 httpResponse.ContentType = "application/octet-stream";
80 }
81 }
82 else if (p.Length > 1 && p[1] == "metadata")
83 {
84 AssetMetadata metadata = m_AssetService.GetMetadata(p[0]);
85 102
86 if (metadata != null) 103 if (metadata != null)
87 { 104 {
88 XmlSerializer xs = 105 XmlSerializer xs =
89 new XmlSerializer(typeof(AssetMetadata)); 106 new XmlSerializer(typeof(AssetMetadata));
90 result = ServerUtils.SerializeResult(xs, metadata); 107 result = ServerUtils.SerializeResult(xs, metadata);
91 108
92 httpResponse.StatusCode = (int)HttpStatusCode.OK; 109 httpResponse.StatusCode = (int)HttpStatusCode.OK;
93 httpResponse.ContentType = 110 httpResponse.ContentType =
94 SLUtil.SLAssetTypeToContentType(metadata.Type); 111 SLUtil.SLAssetTypeToContentType(metadata.Type);
112 }
113 else
114 {
115 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
116 httpResponse.ContentType = "text/plain";
117 result = new byte[0];
118 }
95 } 119 }
96 else 120 else
97 { 121 {
98 httpResponse.StatusCode = (int)HttpStatusCode.NotFound; 122 // Unknown request
123 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
99 httpResponse.ContentType = "text/plain"; 124 httpResponse.ContentType = "text/plain";
100 result = new byte[0]; 125 result = new byte[0];
101 } 126 }
102 } 127 }
103 else 128 else if (p.Length == 1)
104 { 129 {
105 AssetBase asset = m_AssetService.Get(p[0]); 130 // Get the entire asset (metadata + data)
131
132 id = p[0];
133 AssetBase asset = m_AssetService.Get(id);
106 134
107 if (asset != null) 135 if (asset != null)
108 { 136 {
@@ -120,6 +148,24 @@ namespace OpenSim.Server.Handlers.Asset
120 result = new byte[0]; 148 result = new byte[0];
121 } 149 }
122 } 150 }
151 else
152 {
153 // Unknown request
154 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
155 httpResponse.ContentType = "text/plain";
156 result = new byte[0];
157 }
158
159 if (httpResponse.StatusCode == (int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(m_RedirectURL) && !string.IsNullOrEmpty(id))
160 {
161 httpResponse.StatusCode = (int)HttpStatusCode.Redirect;
162 string rurl = m_RedirectURL;
163 if (!path.StartsWith("/"))
164 rurl += "/";
165 rurl += path;
166 httpResponse.AddHeader("Location", rurl);
167 m_log.DebugFormat("[ASSET GET HANDLER]: Asset not found, redirecting to {0} ({1})", rurl, httpResponse.StatusCode);
168 }
123 return result; 169 return result;
124 } 170 }
125 } 171 }
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs
index a006fa8..1c706a7 100644
--- a/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Asset/AssetServerPostHandler.cs
@@ -38,6 +38,7 @@ using System.Xml.Serialization;
38using OpenSim.Server.Base; 38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces; 39using OpenSim.Services.Interfaces;
40using OpenSim.Framework; 40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
41using OpenSim.Framework.Servers.HttpServer; 42using OpenSim.Framework.Servers.HttpServer;
42 43
43namespace OpenSim.Server.Handlers.Asset 44namespace OpenSim.Server.Handlers.Asset
@@ -54,35 +55,44 @@ namespace OpenSim.Server.Handlers.Asset
54 m_AssetService = service; 55 m_AssetService = service;
55 } 56 }
56 57
57 public override byte[] Handle(string path, Stream request, 58 public AssetServerPostHandler(IAssetService service, IServiceAuth auth) :
59 base("POST", "/assets", auth)
60 {
61 m_AssetService = service;
62 }
63
64 protected override byte[] ProcessRequest(string path, Stream request,
58 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 65 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
59 { 66 {
60 AssetBase asset; 67 AssetBase asset;
61 XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); 68 XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
62 69
63 try 70 try
64 { 71 {
65 asset = (AssetBase)xs.Deserialize(request); 72 asset = (AssetBase)xs.Deserialize(request);
66 } 73 }
67 catch (XmlException) 74 catch (Exception)
68 { 75 {
69 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; 76 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
70 return null; 77 return null;
71 } 78 }
72 79
73 string[] p = SplitParams(path); 80 string[] p = SplitParams(path);
74 if (p.Length > 1) 81 if (p.Length > 0)
75 { 82 {
76 bool result = m_AssetService.UpdateContent(p[1], asset.Data); 83 string id = p[0];
84 bool result = m_AssetService.UpdateContent(id, asset.Data);
77 85
78 xs = new XmlSerializer(typeof(bool)); 86 xs = new XmlSerializer(typeof(bool));
79 return ServerUtils.SerializeResult(xs, result); 87 return ServerUtils.SerializeResult(xs, result);
80 } 88 }
89 else
90 {
91 string id = m_AssetService.Store(asset);
81 92
82 string id = m_AssetService.Store(asset); 93 xs = new XmlSerializer(typeof(string));
83 94 return ServerUtils.SerializeResult(xs, id);
84 xs = new XmlSerializer(typeof(string)); 95 }
85 return ServerUtils.SerializeResult(xs, id);
86 } 96 }
87 } 97 }
88} 98}
diff --git a/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs b/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs
new file mode 100644
index 0000000..32901b3
--- /dev/null
+++ b/OpenSim/Server/Handlers/Asset/AssetsExistHandler.cs
@@ -0,0 +1,87 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces;
40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
42using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.Asset
46{
47 public class AssetsExistHandler : BaseStreamHandler
48 {
49 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IAssetService m_AssetService;
52
53 public AssetsExistHandler(IAssetService service) :
54 base("POST", "/get_assets_exist")
55 {
56 m_AssetService = service;
57 }
58
59 public AssetsExistHandler(IAssetService service, IServiceAuth auth) :
60 base("POST", "/get_assets_exist", auth)
61 {
62 m_AssetService = service;
63 }
64
65 protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
66 {
67 XmlSerializer xs;
68
69 string[] ids;
70 try
71 {
72 xs = new XmlSerializer(typeof(string[]));
73 ids = (string[])xs.Deserialize(request);
74 }
75 catch (Exception)
76 {
77 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
78 return null;
79 }
80
81 bool[] exist = m_AssetService.AssetsExist(ids);
82
83 xs = new XmlSerializer(typeof(bool[]));
84 return ServerUtils.SerializeResult(xs, exist);
85 }
86 }
87}
diff --git a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs
index 427fa16..faa6fb7 100644
--- a/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs
+++ b/OpenSim/Server/Handlers/Asset/Tests/AssetServerPostHandlerTests.cs
@@ -39,7 +39,6 @@ using OpenSim.Server.Handlers.Asset;
39using OpenSim.Services.AssetService; 39using OpenSim.Services.AssetService;
40using OpenSim.Services.Interfaces; 40using OpenSim.Services.Interfaces;
41using OpenSim.Tests.Common; 41using OpenSim.Tests.Common;
42using OpenSim.Tests.Common.Mock;
43 42
44namespace OpenSim.Server.Handlers.Asset.Test 43namespace OpenSim.Server.Handlers.Asset.Test
45{ 44{
diff --git a/OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs b/OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs
index 848a037..c9a8dce 100644
--- a/OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs
+++ b/OpenSim/Server/Handlers/Authentication/AuthenticationServerConnector.cs
@@ -29,6 +29,7 @@ using System;
29using Nini.Config; 29using Nini.Config;
30using OpenSim.Server.Base; 30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces; 31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.ServiceAuth;
32using OpenSim.Framework.Servers.HttpServer; 33using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base; 34using OpenSim.Server.Handlers.Base;
34 35
@@ -58,7 +59,9 @@ namespace OpenSim.Server.Handlers.Authentication
58 Object[] args = new Object[] { config }; 59 Object[] args = new Object[] { config };
59 m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authenticationService, args); 60 m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authenticationService, args);
60 61
61 server.AddStreamHandler(new AuthenticationServerPostHandler(m_AuthenticationService, serverConfig)); 62 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
63
64 server.AddStreamHandler(new AuthenticationServerPostHandler(m_AuthenticationService, serverConfig, auth));
62 } 65 }
63 } 66 }
64} 67}
diff --git a/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs
index 6b93cd9..6ee98b3 100644
--- a/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs
@@ -39,6 +39,7 @@ using System.Collections.Generic;
39using OpenSim.Server.Base; 39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces; 40using OpenSim.Services.Interfaces;
41using OpenSim.Framework; 41using OpenSim.Framework;
42using OpenSim.Framework.ServiceAuth;
42using OpenSim.Framework.Servers.HttpServer; 43using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse; 44using OpenMetaverse;
44 45
@@ -55,10 +56,10 @@ namespace OpenSim.Server.Handlers.Authentication
55 private bool m_AllowSetPassword = false; 56 private bool m_AllowSetPassword = false;
56 57
57 public AuthenticationServerPostHandler(IAuthenticationService service) : 58 public AuthenticationServerPostHandler(IAuthenticationService service) :
58 this(service, null) {} 59 this(service, null, null) {}
59 60
60 public AuthenticationServerPostHandler(IAuthenticationService service, IConfig config) : 61 public AuthenticationServerPostHandler(IAuthenticationService service, IConfig config, IServiceAuth auth) :
61 base("POST", "/auth") 62 base("POST", "/auth", auth)
62 { 63 {
63 m_AuthenticationService = service; 64 m_AuthenticationService = service;
64 65
@@ -70,9 +71,10 @@ namespace OpenSim.Server.Handlers.Authentication
70 } 71 }
71 } 72 }
72 73
73 public override byte[] Handle(string path, Stream request, 74 protected override byte[] ProcessRequest(string path, Stream request,
74 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 75 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
75 { 76 {
77// m_log.Error("[XXX]: Authenticating...");
76 string[] p = SplitParams(path); 78 string[] p = SplitParams(path);
77 79
78 if (p.Length > 0) 80 if (p.Length > 0)
@@ -207,7 +209,7 @@ namespace OpenSim.Server.Handlers.Authentication
207 209
208 rootElement.AppendChild(result); 210 rootElement.AppendChild(result);
209 211
210 return DocToBytes(doc); 212 return Util.DocToBytes(doc);
211 } 213 }
212 214
213 byte[] GetAuthInfo(UUID principalID) 215 byte[] GetAuthInfo(UUID principalID)
@@ -277,7 +279,7 @@ namespace OpenSim.Server.Handlers.Authentication
277 279
278 rootElement.AppendChild(result); 280 rootElement.AppendChild(result);
279 281
280 return DocToBytes(doc); 282 return Util.DocToBytes(doc);
281 } 283 }
282 284
283 private byte[] SuccessResult(string token) 285 private byte[] SuccessResult(string token)
@@ -304,18 +306,7 @@ namespace OpenSim.Server.Handlers.Authentication
304 306
305 rootElement.AppendChild(t); 307 rootElement.AppendChild(t);
306 308
307 return DocToBytes(doc); 309 return Util.DocToBytes(doc);
308 }
309
310 private byte[] DocToBytes(XmlDocument doc)
311 {
312 MemoryStream ms = new MemoryStream();
313 XmlTextWriter xw = new XmlTextWriter(ms, null);
314 xw.Formatting = Formatting.Indented;
315 doc.WriteTo(xw);
316 xw.Flush();
317
318 return ms.GetBuffer();
319 } 310 }
320 311
321 private byte[] ResultToBytes(Dictionary<string, object> result) 312 private byte[] ResultToBytes(Dictionary<string, object> result)
diff --git a/OpenSim/Server/Handlers/Authentication/OpenIdServerHandler.cs b/OpenSim/Server/Handlers/Authentication/OpenIdServerHandler.cs
index 18cef15..b201dc7 100644
--- a/OpenSim/Server/Handlers/Authentication/OpenIdServerHandler.cs
+++ b/OpenSim/Server/Handlers/Authentication/OpenIdServerHandler.cs
@@ -147,7 +147,7 @@ namespace OpenSim.Server.Handlers.Authentication
147 #endregion 147 #endregion
148 } 148 }
149 149
150 public class OpenIdStreamHandler : IStreamHandler 150 public class OpenIdStreamHandler : BaseOutputStreamHandler, IStreamHandler
151 { 151 {
152 #region HTML 152 #region HTML
153 153
@@ -191,42 +191,34 @@ For more information, see <a href='http://openid.net/'>http://openid.net/</a>.
191 191
192 #endregion HTML 192 #endregion HTML
193 193
194 public string Name { get { return "OpenId"; } }
195 public string Description { get { return null; } }
196 public string ContentType { get { return m_contentType; } }
197 public string HttpMethod { get { return m_httpMethod; } }
198 public string Path { get { return m_path; } }
199
200 string m_contentType;
201 string m_httpMethod;
202 string m_path;
203 IAuthenticationService m_authenticationService; 194 IAuthenticationService m_authenticationService;
204 IUserAccountService m_userAccountService; 195 IUserAccountService m_userAccountService;
205 ProviderMemoryStore m_openidStore = new ProviderMemoryStore(); 196 ProviderMemoryStore m_openidStore = new ProviderMemoryStore();
206 197
198 public override string ContentType { get { return "text/html"; } }
199
207 /// <summary> 200 /// <summary>
208 /// Constructor 201 /// Constructor
209 /// </summary> 202 /// </summary>
210 public OpenIdStreamHandler(string httpMethod, string path, IUserAccountService userService, IAuthenticationService authService) 203 public OpenIdStreamHandler(
204 string httpMethod, string path, IUserAccountService userService, IAuthenticationService authService)
205 : base(httpMethod, path, "OpenId", "OpenID stream handler")
211 { 206 {
212 m_authenticationService = authService; 207 m_authenticationService = authService;
213 m_userAccountService = userService; 208 m_userAccountService = userService;
214 m_httpMethod = httpMethod;
215 m_path = path;
216
217 m_contentType = "text/html";
218 } 209 }
219 210
220 /// <summary> 211 /// <summary>
221 /// Handles all GET and POST requests for OpenID identifier pages and endpoint 212 /// Handles all GET and POST requests for OpenID identifier pages and endpoint
222 /// server communication 213 /// server communication
223 /// </summary> 214 /// </summary>
224 public void Handle(string path, Stream request, Stream response, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 215 protected override void ProcessRequest(
216 string path, Stream request, Stream response, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
225 { 217 {
226 Uri providerEndpoint = new Uri(String.Format("{0}://{1}{2}", httpRequest.Url.Scheme, httpRequest.Url.Authority, httpRequest.Url.AbsolutePath)); 218 Uri providerEndpoint = new Uri(String.Format("{0}://{1}{2}", httpRequest.Url.Scheme, httpRequest.Url.Authority, httpRequest.Url.AbsolutePath));
227 219
228 // Defult to returning HTML content 220 // Defult to returning HTML content
229 m_contentType = "text/html"; 221 httpResponse.ContentType = ContentType;
230 222
231 try 223 try
232 { 224 {
@@ -276,7 +268,7 @@ For more information, see <a href='http://openid.net/'>http://openid.net/</a>.
276 268
277 string[] contentTypeValues = provider.Request.Response.Headers.GetValues("Content-Type"); 269 string[] contentTypeValues = provider.Request.Response.Headers.GetValues("Content-Type");
278 if (contentTypeValues != null && contentTypeValues.Length == 1) 270 if (contentTypeValues != null && contentTypeValues.Length == 1)
279 m_contentType = contentTypeValues[0]; 271 httpResponse.ContentType = contentTypeValues[0];
280 272
281 // Set the response code and document body based on the OpenID result 273 // Set the response code and document body based on the OpenID result
282 httpResponse.StatusCode = (int)provider.Request.Response.Code; 274 httpResponse.StatusCode = (int)provider.Request.Response.Code;
@@ -344,4 +336,4 @@ For more information, see <a href='http://openid.net/'>http://openid.net/</a>.
344 return false; 336 return false;
345 } 337 }
346 } 338 }
347} 339} \ No newline at end of file
diff --git a/OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs b/OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs
index bcf9d47..c9b4e9b 100644
--- a/OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs
@@ -54,7 +54,7 @@ namespace OpenSim.Server.Handlers.Authorization
54 m_AuthorizationService = service; 54 m_AuthorizationService = service;
55 } 55 }
56 56
57 public override byte[] Handle(string path, Stream request, 57 protected override byte[] ProcessRequest(string path, Stream request,
58 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 58 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
59 { 59 {
60 XmlSerializer xs = new XmlSerializer(typeof (AuthorizationRequest)); 60 XmlSerializer xs = new XmlSerializer(typeof (AuthorizationRequest));
diff --git a/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs b/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs
index 9a57cd9..1831e84 100644
--- a/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs
+++ b/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs
@@ -29,6 +29,7 @@ using System;
29using Nini.Config; 29using Nini.Config;
30using OpenSim.Server.Base; 30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces; 31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.ServiceAuth;
32using OpenSim.Framework.Servers.HttpServer; 33using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base; 34using OpenSim.Server.Handlers.Base;
34 35
@@ -55,7 +56,9 @@ namespace OpenSim.Server.Handlers.Avatar
55 Object[] args = new Object[] { config }; 56 Object[] args = new Object[] { config };
56 m_AvatarService = ServerUtils.LoadPlugin<IAvatarService>(avatarService, args); 57 m_AvatarService = ServerUtils.LoadPlugin<IAvatarService>(avatarService, args);
57 58
58 server.AddStreamHandler(new AvatarServerPostHandler(m_AvatarService)); 59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
60
61 server.AddStreamHandler(new AvatarServerPostHandler(m_AvatarService, auth));
59 } 62 }
60 } 63 }
61} 64}
diff --git a/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs
index 8cd747e..ff8699f 100644
--- a/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs
@@ -39,6 +39,7 @@ using System.Collections.Generic;
39using OpenSim.Server.Base; 39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces; 40using OpenSim.Services.Interfaces;
41using OpenSim.Framework; 41using OpenSim.Framework;
42using OpenSim.Framework.ServiceAuth;
42using OpenSim.Framework.Servers.HttpServer; 43using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse; 44using OpenMetaverse;
44 45
@@ -50,13 +51,13 @@ namespace OpenSim.Server.Handlers.Avatar
50 51
51 private IAvatarService m_AvatarService; 52 private IAvatarService m_AvatarService;
52 53
53 public AvatarServerPostHandler(IAvatarService service) : 54 public AvatarServerPostHandler(IAvatarService service, IServiceAuth auth) :
54 base("POST", "/avatar") 55 base("POST", "/avatar", auth)
55 { 56 {
56 m_AvatarService = service; 57 m_AvatarService = service;
57 } 58 }
58 59
59 public override byte[] Handle(string path, Stream requestData, 60 protected override byte[] ProcessRequest(string path, Stream requestData,
60 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 61 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
61 { 62 {
62 StreamReader sr = new StreamReader(requestData); 63 StreamReader sr = new StreamReader(requestData);
@@ -246,7 +247,7 @@ namespace OpenSim.Server.Handlers.Avatar
246 247
247 rootElement.AppendChild(result); 248 rootElement.AppendChild(result);
248 249
249 return DocToBytes(doc); 250 return Util.DocToBytes(doc);
250 } 251 }
251 252
252 private byte[] FailureResult() 253 private byte[] FailureResult()
@@ -268,18 +269,7 @@ namespace OpenSim.Server.Handlers.Avatar
268 269
269 rootElement.AppendChild(result); 270 rootElement.AppendChild(result);
270 271
271 return DocToBytes(doc); 272 return Util.DocToBytes(doc);
272 }
273
274 private byte[] DocToBytes(XmlDocument doc)
275 {
276 MemoryStream ms = new MemoryStream();
277 XmlTextWriter xw = new XmlTextWriter(ms, null);
278 xw.Formatting = Formatting.Indented;
279 doc.WriteTo(xw);
280 xw.Flush();
281
282 return ms.ToArray();
283 } 273 }
284 274
285 } 275 }
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakes.cs b/OpenSim/Server/Handlers/BakedTextures/XBakes.cs
new file mode 100644
index 0000000..4e55433
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakes.cs
@@ -0,0 +1,148 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Diagnostics;
30using System.Collections.Generic;
31using System.IO;
32using System.Text;
33using System.Threading;
34using System.Reflection;
35using OpenSim.Framework;
36using OpenSim.Framework.Console;
37using OpenSim.Server.Base;
38using OpenSim.Services.Base;
39using OpenSim.Services.Interfaces;
40using Nini.Config;
41using log4net;
42using OpenMetaverse;
43
44namespace OpenSim.Server.Handlers.BakedTextures
45{
46 public class XBakes : ServiceBase, IBakedTextureService
47 {
48 private static readonly ILog m_log =
49 LogManager.GetLogger(
50 MethodBase.GetCurrentMethod().DeclaringType);
51
52 protected string m_FSBase;
53
54 private System.Text.UTF8Encoding utf8encoding =
55 new System.Text.UTF8Encoding();
56
57 public XBakes(IConfigSource config) : base(config)
58 {
59 MainConsole.Instance.Commands.AddCommand("fs", false,
60 "delete bakes", "delete bakes <ID>",
61 "Delete agent's baked textures from server",
62 HandleDeleteBakes);
63
64 IConfig assetConfig = config.Configs["BakedTextureService"];
65 if (assetConfig == null)
66 {
67 throw new Exception("No BakedTextureService configuration");
68 }
69
70 m_FSBase = assetConfig.GetString("BaseDirectory", String.Empty);
71 if (m_FSBase == String.Empty)
72 {
73 m_log.ErrorFormat("[BAKES]: BaseDirectory not specified");
74 throw new Exception("Configuration error");
75 }
76
77 m_log.Info("[BAKES]: XBakes service enabled");
78 }
79
80 public string Get(string id)
81 {
82 string file = HashToFile(id);
83 string diskFile = Path.Combine(m_FSBase, file);
84
85 if (File.Exists(diskFile))
86 {
87 try
88 {
89 byte[] content = File.ReadAllBytes(diskFile);
90
91 return utf8encoding.GetString(content);
92 }
93 catch
94 {
95 }
96 }
97 return String.Empty;
98 }
99
100 public void Store(string id, string sdata)
101 {
102 string file = HashToFile(id);
103 string diskFile = Path.Combine(m_FSBase, file);
104
105 Directory.CreateDirectory(Path.GetDirectoryName(diskFile));
106
107 File.Delete(diskFile);
108
109 byte[] data = utf8encoding.GetBytes(sdata);
110
111 using (FileStream fs = File.Create(diskFile))
112 fs.Write(data, 0, data.Length);
113 }
114
115 private void HandleDeleteBakes(string module, string[] args)
116 {
117 if (args.Length < 3)
118 {
119 MainConsole.Instance.Output("Syntax: delete bakes <ID>");
120 return;
121 }
122
123 string file = HashToFile(args[2]);
124 string diskFile = Path.Combine(m_FSBase, file);
125
126 if (File.Exists(diskFile))
127 {
128 File.Delete(diskFile);
129 MainConsole.Instance.Output("Bakes deleted");
130 return;
131 }
132 MainConsole.Instance.Output("Bakes not found");
133 }
134
135 public string HashToPath(string hash)
136 {
137 return Path.Combine(hash.Substring(0, 2),
138 Path.Combine(hash.Substring(2, 2),
139 Path.Combine(hash.Substring(4, 2),
140 hash.Substring(6, 4))));
141 }
142
143 public string HashToFile(string hash)
144 {
145 return Path.Combine(HashToPath(hash), hash);
146 }
147 }
148}
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs
new file mode 100644
index 0000000..3c61673
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs
@@ -0,0 +1,71 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using Nini.Config;
29using log4net;
30using System;
31using System.IO;
32using System.Reflection;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces;
40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
42using OpenSim.Framework.Servers.HttpServer;
43
44namespace OpenSim.Server.Handlers.BakedTextures
45{
46 public class BakesServerGetHandler : BaseStreamHandler
47 {
48// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 private IBakedTextureService m_BakesService;
51 private System.Text.UTF8Encoding utf8 =
52 new System.Text.UTF8Encoding();
53
54 public BakesServerGetHandler(IBakedTextureService service, IServiceAuth auth) :
55 base("GET", "/bakes", auth)
56 {
57 m_BakesService = service;
58 }
59
60 protected override byte[] ProcessRequest(
61 string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
62 {
63 string[] p = SplitParams(path);
64
65 if (p.Length == 0)
66 return new byte[0];
67
68 return utf8.GetBytes(m_BakesService.Get(p[0]));
69 }
70 }
71}
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs
new file mode 100644
index 0000000..4c12967
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs
@@ -0,0 +1,69 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.ServiceAuth;
33using OpenSim.Framework.Servers.HttpServer;
34using OpenSim.Server.Handlers.Base;
35
36namespace OpenSim.Server.Handlers.BakedTextures
37{
38 public class XBakesConnector : ServiceConnector
39 {
40 private IBakedTextureService m_BakesService;
41 private string m_ConfigName = "BakedTextureService";
42
43 public XBakesConnector(IConfigSource config, IHttpServer server, string configName) :
44 base(config, server, configName)
45 {
46 if (configName != String.Empty)
47 m_ConfigName = configName;
48
49 IConfig serverConfig = config.Configs[m_ConfigName];
50 if (serverConfig == null)
51 throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));
52
53 string assetService = serverConfig.GetString("LocalServiceModule",
54 String.Empty);
55
56 if (assetService == String.Empty)
57 throw new Exception("No BakedTextureService in config file");
58
59 Object[] args = new Object[] { config };
60 m_BakesService =
61 ServerUtils.LoadPlugin<IBakedTextureService>(assetService, args);
62
63 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
64
65 server.AddStreamHandler(new BakesServerGetHandler(m_BakesService, auth));
66 server.AddStreamHandler(new BakesServerPostHandler(m_BakesService, auth));
67 }
68 }
69}
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs
new file mode 100644
index 0000000..e38543b
--- /dev/null
+++ b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs
@@ -0,0 +1,76 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces;
40using OpenSim.Framework;
41using OpenSim.Framework.ServiceAuth;
42using OpenSim.Framework.Servers.HttpServer;
43
44namespace OpenSim.Server.Handlers.BakedTextures
45{
46 public class BakesServerPostHandler : BaseStreamHandler
47 {
48// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 private IBakedTextureService m_BakesService;
51
52 public BakesServerPostHandler(IBakedTextureService service, IServiceAuth auth) :
53 base("POST", "/bakes", auth)
54 {
55 m_BakesService = service;
56 }
57
58 protected override byte[] ProcessRequest(
59 string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
60 {
61 string[] p = SplitParams(path);
62
63 if (p.Length == 0)
64 {
65 return new byte[0];
66 }
67
68 StreamReader sr = new StreamReader(request);
69
70 m_BakesService.Store(p[0], sr.ReadToEnd());
71 sr.Close();
72
73 return new byte[0];
74 }
75 }
76} \ No newline at end of file
diff --git a/OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs b/OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs
new file mode 100644
index 0000000..e0c2810
--- /dev/null
+++ b/OpenSim/Server/Handlers/Estate/EstateDataRobustConnector.cs
@@ -0,0 +1,343 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.IO;
30using System.Reflection;
31using System.Net;
32
33using Nini.Config;
34using log4net;
35using OpenMetaverse;
36
37using OpenSim.Server.Base;
38using OpenSim.Services.Interfaces;
39using OpenSim.Framework;
40using OpenSim.Framework.ServiceAuth;
41using OpenSim.Framework.Servers.HttpServer;
42using OpenSim.Server.Handlers.Base;
43
44namespace OpenSim.Server.Handlers
45{
46 public class EstateDataRobustConnector : ServiceConnector
47 {
48 private string m_ConfigName = "EstateService";
49
50 public EstateDataRobustConnector(IConfigSource config, IHttpServer server, string configName) :
51 base(config, server, configName)
52 {
53 IConfig serverConfig = config.Configs[m_ConfigName];
54 if (serverConfig == null)
55 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
56
57 string service = serverConfig.GetString("LocalServiceModule",
58 String.Empty);
59
60 if (service == String.Empty)
61 throw new Exception("No LocalServiceModule in config file");
62
63 Object[] args = new Object[] { config };
64 IEstateDataService e_service = ServerUtils.LoadPlugin<IEstateDataService>(service, args);
65
66 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ;
67
68 server.AddStreamHandler(new EstateServerGetHandler(e_service, auth));
69 server.AddStreamHandler(new EstateServerPostHandler(e_service, auth));
70 }
71 }
72
73
74 public class EstateServerGetHandler : BaseStreamHandler
75 {
76// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
77
78 IEstateDataService m_EstateService;
79
80 // Possibilities
81 // /estates/estate/?region=uuid&create=[t|f]
82 // /estates/estate/?eid=int
83 // /estates/?name=string
84 // /estates/?owner=uuid
85 // /estates/ (all)
86 // /estates/regions/?eid=int
87
88 public EstateServerGetHandler(IEstateDataService service, IServiceAuth auth) :
89 base("GET", "/estates", auth)
90 {
91 m_EstateService = service;
92 }
93
94 protected override byte[] ProcessRequest(string path, Stream request,
95 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
96 {
97 Dictionary<string, object> data = null;
98
99 string[] p = SplitParams(path);
100
101 // /estates/ (all)
102 // /estates/?name=string
103 // /estates/?owner=uuid
104 if (p.Length == 0)
105 data = GetEstates(httpRequest, httpResponse);
106 else
107 {
108 string resource = p[0];
109
110 // /estates/estate/?region=uuid&create=[t|f]
111 // /estates/estate/?eid=int
112 if ("estate".Equals(resource))
113 data = GetEstate(httpRequest, httpResponse);
114 // /estates/regions/?eid=int
115 else if ("regions".Equals(resource))
116 data = GetRegions(httpRequest, httpResponse);
117 }
118
119 if (data == null)
120 data = new Dictionary<string, object>();
121
122 string xmlString = ServerUtils.BuildXmlResponse(data);
123 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
124
125 }
126
127 private Dictionary<string, object> GetEstates(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
128 {
129 // /estates/ (all)
130 // /estates/?name=string
131 // /estates/?owner=uuid
132
133 Dictionary<string, object> data = null;
134 string name = (string)httpRequest.Query["name"];
135 string owner = (string)httpRequest.Query["owner"];
136
137 if (!string.IsNullOrEmpty(name) || !string.IsNullOrEmpty(owner))
138 {
139 List<int> estateIDs = null;
140 if (!string.IsNullOrEmpty(name))
141 {
142 estateIDs = m_EstateService.GetEstates(name);
143 }
144 else if (!string.IsNullOrEmpty(owner))
145 {
146 UUID ownerID = UUID.Zero;
147 if (UUID.TryParse(owner, out ownerID))
148 estateIDs = m_EstateService.GetEstatesByOwner(ownerID);
149 }
150
151 if (estateIDs == null || (estateIDs != null && estateIDs.Count == 0))
152 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
153 else
154 {
155 httpResponse.StatusCode = (int)HttpStatusCode.OK;
156 httpResponse.ContentType = "text/xml";
157 data = new Dictionary<string, object>();
158 int i = 0;
159 foreach (int id in estateIDs)
160 data["estate" + i++] = id;
161 }
162 }
163 else
164 {
165 List<EstateSettings> estates = m_EstateService.LoadEstateSettingsAll();
166 if (estates == null || estates.Count == 0)
167 {
168 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
169 }
170 else
171 {
172 httpResponse.StatusCode = (int)HttpStatusCode.OK;
173 httpResponse.ContentType = "text/xml";
174 data = new Dictionary<string, object>();
175 int i = 0;
176 foreach (EstateSettings es in estates)
177 data["estate" + i++] = es.ToMap();
178
179 }
180 }
181
182 return data;
183 }
184
185 private Dictionary<string, object> GetEstate(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
186 {
187 // /estates/estate/?region=uuid&create=[t|f]
188 // /estates/estate/?eid=int
189 Dictionary<string, object> data = null;
190 string region = (string)httpRequest.Query["region"];
191 string eid = (string)httpRequest.Query["eid"];
192
193 EstateSettings estate = null;
194
195 if (!string.IsNullOrEmpty(region))
196 {
197 UUID regionID = UUID.Zero;
198 if (UUID.TryParse(region, out regionID))
199 {
200 string create = (string)httpRequest.Query["create"];
201 bool createYN = false;
202 Boolean.TryParse(create, out createYN);
203 estate = m_EstateService.LoadEstateSettings(regionID, createYN);
204 }
205 }
206 else if (!string.IsNullOrEmpty(eid))
207 {
208 int id = 0;
209 if (Int32.TryParse(eid, out id))
210 estate = m_EstateService.LoadEstateSettings(id);
211 }
212
213 if (estate != null)
214 {
215 httpResponse.StatusCode = (int)HttpStatusCode.OK;
216 httpResponse.ContentType = "text/xml";
217 data = estate.ToMap();
218 }
219 else
220 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
221
222 return data;
223 }
224
225 private Dictionary<string, object> GetRegions(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
226 {
227 // /estates/regions/?eid=int
228 Dictionary<string, object> data = null;
229 string eid = (string)httpRequest.Query["eid"];
230
231 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
232 if (!string.IsNullOrEmpty(eid))
233 {
234 int id = 0;
235 if (Int32.TryParse(eid, out id))
236 {
237 List<UUID> regions = m_EstateService.GetRegions(id);
238 if (regions != null && regions.Count > 0)
239 {
240 data = new Dictionary<string, object>();
241 int i = 0;
242 foreach (UUID uuid in regions)
243 data["region" + i++] = uuid.ToString();
244 httpResponse.StatusCode = (int)HttpStatusCode.OK;
245 httpResponse.ContentType = "text/xml";
246 }
247 }
248 }
249
250 return data;
251 }
252 }
253
254 public class EstateServerPostHandler : BaseStreamHandler
255 {
256 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
257
258 IEstateDataService m_EstateService;
259
260 // Possibilities
261 // /estates/estate/ (post an estate)
262 // /estates/estate/?eid=int&region=uuid (link a region to an estate)
263
264 public EstateServerPostHandler(IEstateDataService service, IServiceAuth auth) :
265 base("POST", "/estates", auth)
266 {
267 m_EstateService = service;
268 }
269
270 protected override byte[] ProcessRequest(string path, Stream request,
271 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
272 {
273 Dictionary<string, object> data = null;
274
275 string[] p = SplitParams(path);
276
277 if (p.Length > 0)
278 {
279 string resource = p[0];
280
281 // /estates/estate/
282 // /estates/estate/?eid=int&region=uuid
283 if ("estate".Equals(resource))
284 {
285 StreamReader sr = new StreamReader(request);
286 string body = sr.ReadToEnd();
287 sr.Close();
288 body = body.Trim();
289
290 Dictionary<string, object> requestData = ServerUtils.ParseQueryString(body);
291
292 data = UpdateEstate(requestData, httpRequest, httpResponse);
293 }
294 }
295
296 if (data == null)
297 data = new Dictionary<string, object>();
298
299 string xmlString = ServerUtils.BuildXmlResponse(data);
300 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
301
302 }
303
304 private Dictionary<string, object> UpdateEstate(Dictionary<string, object> requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
305 {
306 // /estates/estate/
307 // /estates/estate/?eid=int&region=uuid
308 Dictionary<string, object> result = new Dictionary<string, object>();
309 string eid = (string)httpRequest.Query["eid"];
310 string region = (string)httpRequest.Query["region"];
311
312 httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
313
314 if (string.IsNullOrEmpty(eid) && string.IsNullOrEmpty(region) &&
315 requestData.ContainsKey("OP") && requestData["OP"] != null && "STORE".Equals(requestData["OP"]))
316 {
317 // /estates/estate/
318 EstateSettings es = new EstateSettings(requestData);
319 m_EstateService.StoreEstateSettings(es);
320 //m_log.DebugFormat("[EstateServerPostHandler]: Store estate {0}", es.ToString());
321 httpResponse.StatusCode = (int)HttpStatusCode.OK;
322 result["Result"] = true;
323 }
324 else if (!string.IsNullOrEmpty(region) && !string.IsNullOrEmpty(eid) &&
325 requestData.ContainsKey("OP") && requestData["OP"] != null && "LINK".Equals(requestData["OP"]))
326 {
327 int id = 0;
328 UUID regionID = UUID.Zero;
329 if (UUID.TryParse(region, out regionID) && Int32.TryParse(eid, out id))
330 {
331 m_log.DebugFormat("[EstateServerPostHandler]: Link region {0} to estate {1}", regionID, id);
332 httpResponse.StatusCode = (int)HttpStatusCode.OK;
333 result["Result"] = m_EstateService.LinkRegion(regionID, id);
334 }
335 }
336 else
337 m_log.WarnFormat("[EstateServerPostHandler]: something wrong with POST request {0}", httpRequest.RawUrl);
338
339 return result;
340 }
341
342 }
343}
diff --git a/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs b/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs
index 5784bdf..b0e6c7d 100644
--- a/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs
+++ b/OpenSim/Server/Handlers/Friends/FriendServerConnector.cs
@@ -29,6 +29,7 @@ using System;
29using Nini.Config; 29using Nini.Config;
30using OpenSim.Server.Base; 30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces; 31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.ServiceAuth;
32using OpenSim.Framework.Servers.HttpServer; 33using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base; 34using OpenSim.Server.Handlers.Base;
34 35
@@ -55,7 +56,8 @@ namespace OpenSim.Server.Handlers.Friends
55 Object[] args = new Object[] { config }; 56 Object[] args = new Object[] { config };
56 m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(theService, args); 57 m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(theService, args);
57 58
58 server.AddStreamHandler(new FriendsServerPostHandler(m_FriendsService)); 59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
60 server.AddStreamHandler(new FriendsServerPostHandler(m_FriendsService, auth));
59 } 61 }
60 } 62 }
61} 63}
diff --git a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
index 47a8558..3aab30b 100644
--- a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
@@ -40,6 +40,7 @@ using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces; 40using OpenSim.Services.Interfaces;
41using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; 41using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
42using OpenSim.Framework; 42using OpenSim.Framework;
43using OpenSim.Framework.ServiceAuth;
43using OpenSim.Framework.Servers.HttpServer; 44using OpenSim.Framework.Servers.HttpServer;
44using OpenMetaverse; 45using OpenMetaverse;
45 46
@@ -51,13 +52,13 @@ namespace OpenSim.Server.Handlers.Friends
51 52
52 private IFriendsService m_FriendsService; 53 private IFriendsService m_FriendsService;
53 54
54 public FriendsServerPostHandler(IFriendsService service) : 55 public FriendsServerPostHandler(IFriendsService service, IServiceAuth auth) :
55 base("POST", "/friends") 56 base("POST", "/friends", auth)
56 { 57 {
57 m_FriendsService = service; 58 m_FriendsService = service;
58 } 59 }
59 60
60 public override byte[] Handle(string path, Stream requestData, 61 protected override byte[] ProcessRequest(string path, Stream requestData,
61 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 62 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
62 { 63 {
63 StreamReader sr = new StreamReader(requestData); 64 StreamReader sr = new StreamReader(requestData);
@@ -228,7 +229,7 @@ namespace OpenSim.Server.Handlers.Friends
228 229
229 rootElement.AppendChild(result); 230 rootElement.AppendChild(result);
230 231
231 return DocToBytes(doc); 232 return Util.DocToBytes(doc);
232 } 233 }
233 234
234 private byte[] FailureResult() 235 private byte[] FailureResult()
@@ -260,18 +261,7 @@ namespace OpenSim.Server.Handlers.Friends
260 261
261 rootElement.AppendChild(message); 262 rootElement.AppendChild(message);
262 263
263 return DocToBytes(doc); 264 return Util.DocToBytes(doc);
264 }
265
266 private byte[] DocToBytes(XmlDocument doc)
267 {
268 MemoryStream ms = new MemoryStream();
269 XmlTextWriter xw = new XmlTextWriter(ms, null);
270 xw.Formatting = Formatting.Indented;
271 doc.WriteTo(xw);
272 xw.Flush();
273
274 return ms.ToArray();
275 } 265 }
276 266
277 void FromKeyValuePairs(Dictionary<string, object> kvp, out string principalID, out string friend, out int flags) 267 void FromKeyValuePairs(Dictionary<string, object> kvp, out string principalID, out string friend, out int flags)
diff --git a/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs
index 965a54e..346af32 100644
--- a/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs
+++ b/OpenSim/Server/Handlers/Grid/GridInfoHandlers.cs
@@ -170,14 +170,6 @@ namespace OpenSim.Server.Handlers.Grid
170 public string JsonGetGridInfoMethod(string request, string path, string param, 170 public string JsonGetGridInfoMethod(string request, string path, string param,
171 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 171 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
172 { 172 {
173 string HomeURI = String.Empty;
174 IConfig cfg = m_Config.Configs["LoginService"];
175
176 if (null != cfg)
177 {
178 HomeURI = cfg.GetString("SRV_HomeURI", HomeURI);
179 }
180
181 OSDMap map = new OSDMap(); 173 OSDMap map = new OSDMap();
182 174
183 foreach (string k in _info.Keys) 175 foreach (string k in _info.Keys)
@@ -185,9 +177,20 @@ namespace OpenSim.Server.Handlers.Grid
185 map[k] = OSD.FromString(_info[k].ToString()); 177 map[k] = OSD.FromString(_info[k].ToString());
186 } 178 }
187 179
180 string HomeURI = Util.GetConfigVarFromSections<string>(m_Config, "HomeURI",
181 new string[] { "Startup", "Hypergrid" }, String.Empty);
182
188 if (!String.IsNullOrEmpty(HomeURI)) 183 if (!String.IsNullOrEmpty(HomeURI))
184 map["home"] = OSD.FromString(HomeURI);
185 else // Legacy. Remove soon!
189 { 186 {
190 map["home"] = OSD.FromString(HomeURI); 187 IConfig cfg = m_Config.Configs["LoginService"];
188
189 if (null != cfg)
190 HomeURI = cfg.GetString("SRV_HomeURI", HomeURI);
191
192 if (!String.IsNullOrEmpty(HomeURI))
193 map["home"] = OSD.FromString(HomeURI);
191 } 194 }
192 195
193 return OSDParser.SerializeJsonString(map).ToString(); 196 return OSDParser.SerializeJsonString(map).ToString();
diff --git a/OpenSim/Server/Handlers/Grid/GridServerConnector.cs b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs
index 14daf12..6eb6a79 100644
--- a/OpenSim/Server/Handlers/Grid/GridServerConnector.cs
+++ b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs
@@ -29,6 +29,7 @@ using System;
29using Nini.Config; 29using Nini.Config;
30using OpenSim.Server.Base; 30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces; 31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.ServiceAuth;
32using OpenSim.Framework.Servers.HttpServer; 33using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base; 34using OpenSim.Server.Handlers.Base;
34 35
@@ -55,7 +56,9 @@ namespace OpenSim.Server.Handlers.Grid
55 Object[] args = new Object[] { config }; 56 Object[] args = new Object[] { config };
56 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); 57 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
57 58
58 server.AddStreamHandler(new GridServerPostHandler(m_GridService)); 59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
60
61 server.AddStreamHandler(new GridServerPostHandler(m_GridService, auth));
59 } 62 }
60 } 63 }
61} 64}
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
index ef5f33e..86fda36 100644
--- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
@@ -40,6 +40,7 @@ using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces; 40using OpenSim.Services.Interfaces;
41using GridRegion = OpenSim.Services.Interfaces.GridRegion; 41using GridRegion = OpenSim.Services.Interfaces.GridRegion;
42using OpenSim.Framework; 42using OpenSim.Framework;
43using OpenSim.Framework.ServiceAuth;
43using OpenSim.Framework.Servers.HttpServer; 44using OpenSim.Framework.Servers.HttpServer;
44using OpenMetaverse; 45using OpenMetaverse;
45 46
@@ -49,15 +50,19 @@ namespace OpenSim.Server.Handlers.Grid
49 { 50 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 52
53#pragma warning disable 414
54 private static string LogHeader = "[GRID HANDLER]";
55#pragma warning restore 414
56
52 private IGridService m_GridService; 57 private IGridService m_GridService;
53 58
54 public GridServerPostHandler(IGridService service) : 59 public GridServerPostHandler(IGridService service, IServiceAuth auth) :
55 base("POST", "/grid") 60 base("POST", "/grid", auth)
56 { 61 {
57 m_GridService = service; 62 m_GridService = service;
58 } 63 }
59 64
60 public override byte[] Handle(string path, Stream requestData, 65 protected override byte[] ProcessRequest(string path, Stream requestData,
61 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 66 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
62 { 67 {
63 StreamReader sr = new StreamReader(requestData); 68 StreamReader sr = new StreamReader(requestData);
@@ -106,6 +111,9 @@ namespace OpenSim.Server.Handlers.Grid
106 case "get_default_regions": 111 case "get_default_regions":
107 return GetDefaultRegions(request); 112 return GetDefaultRegions(request);
108 113
114 case "get_default_hypergrid_regions":
115 return GetDefaultHypergridRegions(request);
116
109 case "get_fallback_regions": 117 case "get_fallback_regions":
110 return GetFallbackRegions(request); 118 return GetFallbackRegions(request);
111 119
@@ -114,6 +122,9 @@ namespace OpenSim.Server.Handlers.Grid
114 122
115 case "get_region_flags": 123 case "get_region_flags":
116 return GetRegionFlags(request); 124 return GetRegionFlags(request);
125
126 case "get_grid_extra_features":
127 return GetGridExtraFeatures(request);
117 } 128 }
118 129
119 m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method); 130 m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method);
@@ -148,7 +159,24 @@ namespace OpenSim.Server.Handlers.Grid
148 m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region"); 159 m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region");
149 160
150 // Check the protocol version 161 // Check the protocol version
151 if ((versionNumberMin > ProtocolVersions.ServerProtocolVersionMax && versionNumberMax < ProtocolVersions.ServerProtocolVersionMax)) 162 // This is how it works:
163 // Example 1:
164 // Client: [0 0]
165 // Server: [1 1]
166 // ==> fail
167 // Example 2:
168 // Client: [1 1]
169 // Server: [0 0]
170 // ==> fail
171 // Example 3:
172 // Client: [0 1]
173 // Server: [1 1]
174 // ==> success
175 // Example 4:
176 // Client: [1 1]
177 // Server: [0 1]
178 // ==> success
179 if ((versionNumberMin > ProtocolVersions.ServerProtocolVersionMax || versionNumberMax < ProtocolVersions.ServerProtocolVersionMin))
152 { 180 {
153 // Can't do, there is no overlap in the acceptable ranges 181 // Can't do, there is no overlap in the acceptable ranges
154 return FailureResult(); 182 return FailureResult();
@@ -278,8 +306,8 @@ namespace OpenSim.Server.Handlers.Grid
278 else 306 else
279 m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position"); 307 m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position");
280 308
309 // m_log.DebugFormat("{0} GetRegionByPosition: loc=<{1},{2}>", LogHeader, x, y);
281 GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y); 310 GridRegion rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
282 //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
283 311
284 Dictionary<string, object> result = new Dictionary<string, object>(); 312 Dictionary<string, object> result = new Dictionary<string, object>();
285 if (rinfo == null) 313 if (rinfo == null)
@@ -444,6 +472,36 @@ namespace OpenSim.Server.Handlers.Grid
444 return Util.UTF8NoBomEncoding.GetBytes(xmlString); 472 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
445 } 473 }
446 474
475 byte[] GetDefaultHypergridRegions(Dictionary<string, object> request)
476 {
477 //m_log.DebugFormat("[GRID HANDLER]: GetDefaultRegions");
478 UUID scopeID = UUID.Zero;
479 if (request.ContainsKey("SCOPEID"))
480 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
481 else
482 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
483
484 List<GridRegion> rinfos = m_GridService.GetDefaultHypergridRegions(scopeID);
485
486 Dictionary<string, object> result = new Dictionary<string, object>();
487 if ((rinfos == null) || ((rinfos != null) && (rinfos.Count == 0)))
488 result["result"] = "null";
489 else
490 {
491 int i = 0;
492 foreach (GridRegion rinfo in rinfos)
493 {
494 Dictionary<string, object> rinfoDict = rinfo.ToKeyValuePairs();
495 result["region" + i] = rinfoDict;
496 i++;
497 }
498 }
499 string xmlString = ServerUtils.BuildXmlResponse(result);
500
501 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
502 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
503 }
504
447 byte[] GetFallbackRegions(Dictionary<string, object> request) 505 byte[] GetFallbackRegions(Dictionary<string, object> request)
448 { 506 {
449 //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange"); 507 //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
@@ -540,6 +598,22 @@ namespace OpenSim.Server.Handlers.Grid
540 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); 598 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
541 return Util.UTF8NoBomEncoding.GetBytes(xmlString); 599 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
542 } 600 }
601
602 byte[] GetGridExtraFeatures(Dictionary<string, object> request)
603 {
604
605 Dictionary<string, object> result = new Dictionary<string, object> ();
606 Dictionary<string, object> extraFeatures = m_GridService.GetExtraFeatures ();
607
608 foreach (string key in extraFeatures.Keys)
609 {
610 result [key] = extraFeatures [key];
611 }
612
613 string xmlString = ServerUtils.BuildXmlResponse(result);
614
615 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
616 }
543 617
544 #endregion 618 #endregion
545 619
@@ -564,7 +638,7 @@ namespace OpenSim.Server.Handlers.Grid
564 638
565 rootElement.AppendChild(result); 639 rootElement.AppendChild(result);
566 640
567 return DocToBytes(doc); 641 return Util.DocToBytes(doc);
568 } 642 }
569 643
570 private byte[] FailureResult() 644 private byte[] FailureResult()
@@ -596,18 +670,7 @@ namespace OpenSim.Server.Handlers.Grid
596 670
597 rootElement.AppendChild(message); 671 rootElement.AppendChild(message);
598 672
599 return DocToBytes(doc); 673 return Util.DocToBytes(doc);
600 }
601
602 private byte[] DocToBytes(XmlDocument doc)
603 {
604 MemoryStream ms = new MemoryStream();
605 XmlTextWriter xw = new XmlTextWriter(ms, null);
606 xw.Formatting = Formatting.Indented;
607 doc.WriteTo(xw);
608 xw.Flush();
609
610 return ms.ToArray();
611 } 674 }
612 675
613 #endregion 676 #endregion
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs
index 66f35e3..1e29378 100644
--- a/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs
+++ b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs
@@ -29,6 +29,7 @@ using System;
29using Nini.Config; 29using Nini.Config;
30using OpenSim.Server.Base; 30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces; 31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.ServiceAuth;
32using OpenSim.Framework.Servers.HttpServer; 33using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base; 34using OpenSim.Server.Handlers.Base;
34 35
@@ -55,7 +56,9 @@ namespace OpenSim.Server.Handlers.GridUser
55 Object[] args = new Object[] { config }; 56 Object[] args = new Object[] { config };
56 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(service, args); 57 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(service, args);
57 58
58 server.AddStreamHandler(new GridUserServerPostHandler(m_GridUserService)); 59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName); ;
60
61 server.AddStreamHandler(new GridUserServerPostHandler(m_GridUserService, auth));
59 } 62 }
60 } 63 }
61} 64}
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
index 687cf8d..9237c63 100644
--- a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
@@ -39,6 +39,7 @@ using System.Collections.Generic;
39using OpenSim.Server.Base; 39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces; 40using OpenSim.Services.Interfaces;
41using OpenSim.Framework; 41using OpenSim.Framework;
42using OpenSim.Framework.ServiceAuth;
42using OpenSim.Framework.Servers.HttpServer; 43using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse; 44using OpenMetaverse;
44 45
@@ -50,13 +51,13 @@ namespace OpenSim.Server.Handlers.GridUser
50 51
51 private IGridUserService m_GridUserService; 52 private IGridUserService m_GridUserService;
52 53
53 public GridUserServerPostHandler(IGridUserService service) : 54 public GridUserServerPostHandler(IGridUserService service, IServiceAuth auth) :
54 base("POST", "/griduser") 55 base("POST", "/griduser", auth)
55 { 56 {
56 m_GridUserService = service; 57 m_GridUserService = service;
57 } 58 }
58 59
59 public override byte[] Handle(string path, Stream requestData, 60 protected override byte[] ProcessRequest(string path, Stream requestData,
60 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 61 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
61 { 62 {
62 StreamReader sr = new StreamReader(requestData); 63 StreamReader sr = new StreamReader(requestData);
@@ -185,10 +186,12 @@ namespace OpenSim.Server.Handlers.GridUser
185 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(user); 186 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(user);
186 187
187 Dictionary<string, object> result = new Dictionary<string, object>(); 188 Dictionary<string, object> result = new Dictionary<string, object>();
188 result["result"] = guinfo.ToKeyValuePairs(); 189 if (guinfo != null)
190 result["result"] = guinfo.ToKeyValuePairs();
191 else
192 result["result"] = "null";
189 193
190 string xmlString = ServerUtils.BuildXmlResponse(result); 194 string xmlString = ServerUtils.BuildXmlResponse(result);
191
192 //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString); 195 //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString);
193 return Util.UTF8NoBomEncoding.GetBytes(xmlString); 196 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
194 } 197 }
@@ -276,7 +279,7 @@ namespace OpenSim.Server.Handlers.GridUser
276 279
277 rootElement.AppendChild(result); 280 rootElement.AppendChild(result);
278 281
279 return DocToBytes(doc); 282 return Util.DocToBytes(doc);
280 } 283 }
281 284
282 private byte[] FailureResult() 285 private byte[] FailureResult()
@@ -298,20 +301,8 @@ namespace OpenSim.Server.Handlers.GridUser
298 301
299 rootElement.AppendChild(result); 302 rootElement.AppendChild(result);
300 303
301 return DocToBytes(doc); 304 return Util.DocToBytes(doc);
302 } 305 }
303 306
304 private byte[] DocToBytes(XmlDocument doc)
305 {
306 MemoryStream ms = new MemoryStream();
307 XmlTextWriter xw = new XmlTextWriter(ms, null);
308 xw.Formatting = Formatting.Indented;
309 doc.WriteTo(xw);
310 xw.Flush();
311
312 return ms.ToArray();
313 }
314
315
316 } 307 }
317} 308}
diff --git a/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs
index cf1af15..95a0510 100644
--- a/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs
@@ -61,9 +61,10 @@ namespace OpenSim.Server.Handlers.Hypergrid
61 m_Proxy = proxy; 61 m_Proxy = proxy;
62 } 62 }
63 63
64 protected override bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) 64 protected override bool CreateAgent(GridRegion source, GridRegion gatekeeper, GridRegion destination,
65 AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason)
65 { 66 {
66 return m_GatekeeperService.LoginAgent(aCircuit, destination, out reason); 67 return m_GatekeeperService.LoginAgent(source, aCircuit, destination, out reason);
67 } 68 }
68 } 69 }
69} 70}
diff --git a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs
index 0d4990a..ffe2f36 100644
--- a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs
@@ -76,10 +76,14 @@ namespace OpenSim.Server.Handlers.Hypergrid
76 server.AddStreamHandler(new GatekeeperAgentHandler(m_GatekeeperService, m_Proxy)); 76 server.AddStreamHandler(new GatekeeperAgentHandler(m_GatekeeperService, m_Proxy));
77 } 77 }
78 78
79 public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server) 79 public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server, string configName)
80 : this(config, server, null) 80 : this(config, server, (ISimulationService)null)
81 { 81 {
82 } 82 }
83 83
84 public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server)
85 : this(config, server, String.Empty)
86 {
87 }
84 } 88 }
85} 89}
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
index 0aa2729..37b47ed 100644
--- a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
@@ -68,7 +68,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
68 m_log.ErrorFormat("[HGFRIENDS HANDLER]: TheService is null!"); 68 m_log.ErrorFormat("[HGFRIENDS HANDLER]: TheService is null!");
69 } 69 }
70 70
71 public override byte[] Handle(string path, Stream requestData, 71 protected override byte[] ProcessRequest(string path, Stream requestData,
72 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 72 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
73 { 73 {
74 StreamReader sr = new StreamReader(requestData); 74 StreamReader sr = new StreamReader(requestData);
@@ -335,7 +335,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
335 335
336 rootElement.AppendChild(result); 336 rootElement.AppendChild(result);
337 337
338 return DocToBytes(doc); 338 return Util.DocToBytes(doc);
339 } 339 }
340 340
341 private byte[] SuccessResult(string value) 341 private byte[] SuccessResult(string value)
@@ -362,7 +362,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
362 362
363 rootElement.AppendChild(message); 363 rootElement.AppendChild(message);
364 364
365 return DocToBytes(doc); 365 return Util.DocToBytes(doc);
366 } 366 }
367 367
368 368
@@ -395,7 +395,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
395 395
396 rootElement.AppendChild(message); 396 rootElement.AppendChild(message);
397 397
398 return DocToBytes(doc); 398 return Util.DocToBytes(doc);
399 } 399 }
400 400
401 private byte[] BoolResult(bool value) 401 private byte[] BoolResult(bool value)
@@ -417,21 +417,9 @@ namespace OpenSim.Server.Handlers.Hypergrid
417 417
418 rootElement.AppendChild(result); 418 rootElement.AppendChild(result);
419 419
420 return DocToBytes(doc); 420 return Util.DocToBytes(doc);
421 } 421 }
422 422
423 private byte[] DocToBytes(XmlDocument doc)
424 {
425 MemoryStream ms = new MemoryStream();
426 XmlTextWriter xw = new XmlTextWriter(ms, null);
427 xw.Formatting = Formatting.Indented;
428 doc.WriteTo(xw);
429 xw.Flush();
430
431 return ms.ToArray();
432 }
433
434
435 #endregion 423 #endregion
436 } 424 }
437} 425}
diff --git a/OpenSim/Server/Handlers/Hypergrid/HeloServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/HeloServerConnector.cs
index f306b1c..dac4ca8 100644
--- a/OpenSim/Server/Handlers/Hypergrid/HeloServerConnector.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/HeloServerConnector.cs
@@ -44,7 +44,9 @@ namespace OpenSim.Server.Handlers.Hypergrid
44 public HeloServiceInConnector(IConfigSource config, IHttpServer server, string configName) : 44 public HeloServiceInConnector(IConfigSource config, IHttpServer server, string configName) :
45 base(config, server, configName) 45 base(config, server, configName)
46 { 46 {
47#pragma warning disable 0612
47 server.AddStreamHandler(new HeloServerGetHandler("opensim-robust")); 48 server.AddStreamHandler(new HeloServerGetHandler("opensim-robust"));
49#pragma warning restore 0612
48 server.AddStreamHandler(new HeloServerHeadHandler("opensim-robust")); 50 server.AddStreamHandler(new HeloServerHeadHandler("opensim-robust"));
49 } 51 }
50 } 52 }
@@ -91,7 +93,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
91 m_HandlersType = handlersType; 93 m_HandlersType = handlersType;
92 } 94 }
93 95
94 public override byte[] Handle(string path, Stream requestData, 96 protected override byte[] ProcessRequest(string path, Stream requestData,
95 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 97 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
96 { 98 {
97 return OKResponse(httpResponse); 99 return OKResponse(httpResponse);
diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs
index 968c1e6..e787f7c 100644
--- a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs
@@ -49,191 +49,89 @@ using log4net;
49 49
50namespace OpenSim.Server.Handlers.Hypergrid 50namespace OpenSim.Server.Handlers.Hypergrid
51{ 51{
52 public class HomeAgentHandler 52 public class HomeAgentHandler : AgentPostHandler
53 { 53 {
54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 private IUserAgentService m_UserAgentService; 55 private IUserAgentService m_UserAgentService;
56 56
57 private string m_LoginServerIP; 57 private string m_LoginServerIP;
58 private bool m_Proxy = false;
59 58
60 public HomeAgentHandler(IUserAgentService userAgentService, string loginServerIP, bool proxy) 59 public HomeAgentHandler(IUserAgentService userAgentService, string loginServerIP, bool proxy) :
60 base("/homeagent")
61 { 61 {
62 m_UserAgentService = userAgentService; 62 m_UserAgentService = userAgentService;
63 m_LoginServerIP = loginServerIP; 63 m_LoginServerIP = loginServerIP;
64 m_Proxy = proxy; 64 m_Proxy = proxy;
65 } 65 }
66 66
67 public Hashtable Handler(Hashtable request) 67 protected override AgentDestinationData CreateAgentDestinationData()
68 { 68 {
69// m_log.Debug("[CONNECTION DEBUGGING]: HomeAgentHandler Called"); 69 return new ExtendedAgentDestinationData();
70// 70 }
71// m_log.Debug("---------------------------"); 71
72// m_log.Debug(" >> uri=" + request["uri"]); 72 protected override void UnpackData(OSDMap args, AgentDestinationData d, Hashtable request)
73// m_log.Debug(" >> content-type=" + request["content-type"]); 73 {
74// m_log.Debug(" >> http-method=" + request["http-method"]); 74 base.UnpackData(args, d, request);
75// m_log.Debug("---------------------------\n"); 75 ExtendedAgentDestinationData data = (ExtendedAgentDestinationData)d;
76 76 try
77 Hashtable responsedata = new Hashtable();
78 responsedata["content_type"] = "text/html";
79 responsedata["keepalive"] = false;
80
81
82 UUID agentID;
83 UUID regionID;
84 string action;
85 if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action))
86 { 77 {
87 m_log.InfoFormat("[HOME AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]); 78 if (args.ContainsKey("gatekeeper_host") && args["gatekeeper_host"] != null)
88 responsedata["int_response_code"] = 404; 79 data.host = args["gatekeeper_host"].AsString();
89 responsedata["str_response_string"] = "false"; 80 if (args.ContainsKey("gatekeeper_port") && args["gatekeeper_port"] != null)
81 Int32.TryParse(args["gatekeeper_port"].AsString(), out data.port);
82 if (args.ContainsKey("gatekeeper_serveruri") && args["gatekeeper_serveruri"] != null)
83 data.gatekeeperServerURI = args["gatekeeper_serveruri"];
84 if (args.ContainsKey("destination_serveruri") && args["destination_serveruri"] != null)
85 data.destinationServerURI = args["destination_serveruri"];
90 86
91 return responsedata;
92 } 87 }
93 88 catch (InvalidCastException)
94 // Next, let's parse the verb
95 string method = (string)request["http-method"];
96 if (method.Equals("POST"))
97 { 89 {
98 DoAgentPost(request, responsedata, agentID); 90 m_log.ErrorFormat("[HOME AGENT HANDLER]: Bad cast in UnpackData");
99 return responsedata;
100 } 91 }
101 else
102 {
103 m_log.InfoFormat("[HOME AGENT HANDLER]: method {0} not supported in agent message", method);
104 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
105 responsedata["str_response_string"] = "Method not allowed";
106 92
107 return responsedata; 93 string callerIP = GetCallerIP(request);
108 } 94 // Verify if this call came from the login server
95 if (callerIP == m_LoginServerIP)
96 data.fromLogin = true;
109 97
110 } 98 }
111 99
112 protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) 100 protected override GridRegion ExtractGatekeeper(AgentDestinationData d)
113 { 101 {
114 OSDMap args = Utils.GetOSDMap((string)request["body"]); 102 if (d is ExtendedAgentDestinationData)
115 if (args == null)
116 { 103 {
117 responsedata["int_response_code"] = HttpStatusCode.BadRequest; 104 ExtendedAgentDestinationData data = (ExtendedAgentDestinationData)d;
118 responsedata["str_response_string"] = "Bad request"; 105 GridRegion gatekeeper = new GridRegion();
119 return; 106 gatekeeper.ServerURI = data.gatekeeperServerURI;
107 gatekeeper.ExternalHostName = data.host;
108 gatekeeper.HttpPort = (uint)data.port;
109 gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
110
111 return gatekeeper;
120 } 112 }
121
122 // retrieve the input arguments
123 int x = 0, y = 0;
124 UUID uuid = UUID.Zero;
125 string regionname = string.Empty;
126 string gatekeeper_host = string.Empty;
127 string gatekeeper_serveruri = string.Empty;
128 string destination_serveruri = string.Empty;
129 int gatekeeper_port = 0;
130 IPEndPoint client_ipaddress = null;
131
132 if (args.ContainsKey("gatekeeper_host") && args["gatekeeper_host"] != null)
133 gatekeeper_host = args["gatekeeper_host"].AsString();
134 if (args.ContainsKey("gatekeeper_port") && args["gatekeeper_port"] != null)
135 Int32.TryParse(args["gatekeeper_port"].AsString(), out gatekeeper_port);
136 if (args.ContainsKey("gatekeeper_serveruri") && args["gatekeeper_serveruri"] !=null)
137 gatekeeper_serveruri = args["gatekeeper_serveruri"];
138 if (args.ContainsKey("destination_serveruri") && args["destination_serveruri"] !=null)
139 destination_serveruri = args["destination_serveruri"];
140
141 GridRegion gatekeeper = new GridRegion();
142 gatekeeper.ServerURI = gatekeeper_serveruri;
143 gatekeeper.ExternalHostName = gatekeeper_host;
144 gatekeeper.HttpPort = (uint)gatekeeper_port;
145 gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
146
147 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
148 Int32.TryParse(args["destination_x"].AsString(), out x);
149 else
150 m_log.WarnFormat(" -- request didn't have destination_x");
151 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
152 Int32.TryParse(args["destination_y"].AsString(), out y);
153 else 113 else
154 m_log.WarnFormat(" -- request didn't have destination_y"); 114 m_log.WarnFormat("[HOME AGENT HANDLER]: Wrong data type");
155 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
156 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
157 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
158 regionname = args["destination_name"].ToString();
159
160 if (args.ContainsKey("client_ip") && args["client_ip"] != null)
161 {
162 string ip_str = args["client_ip"].ToString();
163 try
164 {
165 string callerIP = GetCallerIP(request);
166 // Verify if this caller has authority to send the client IP
167 if (callerIP == m_LoginServerIP)
168 client_ipaddress = new IPEndPoint(IPAddress.Parse(ip_str), 0);
169 else // leaving this for now, but this warning should be removed
170 m_log.WarnFormat("[HOME AGENT HANDLER]: Unauthorized machine {0} tried to set client ip to {1}", callerIP, ip_str);
171 }
172 catch
173 {
174 m_log.DebugFormat("[HOME AGENT HANDLER]: Exception parsing client ip address from {0}", ip_str);
175 }
176 }
177 115
178 GridRegion destination = new GridRegion(); 116 return null;
179 destination.RegionID = uuid;
180 destination.RegionLocX = x;
181 destination.RegionLocY = y;
182 destination.RegionName = regionname;
183 destination.ServerURI = destination_serveruri;
184
185 AgentCircuitData aCircuit = new AgentCircuitData();
186 try
187 {
188 aCircuit.UnpackAgentCircuitData(args);
189 }
190 catch (Exception ex)
191 {
192 m_log.InfoFormat("[HOME AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
193 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
194 responsedata["str_response_string"] = "Bad request";
195 return;
196 }
197
198 OSDMap resp = new OSDMap(2);
199 string reason = String.Empty;
200
201 bool result = m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, client_ipaddress, out reason);
202
203 resp["reason"] = OSD.FromString(reason);
204 resp["success"] = OSD.FromBoolean(result);
205
206 // TODO: add reason if not String.Empty?
207 responsedata["int_response_code"] = HttpStatusCode.OK;
208 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
209 } 117 }
210 118
211 private string GetCallerIP(Hashtable request)
212 {
213 if (!m_Proxy)
214 return Util.GetCallerIP(request);
215
216 // We're behind a proxy
217 Hashtable headers = (Hashtable)request["headers"];
218 string xff = "X-Forwarded-For";
219 if (headers.ContainsKey(xff.ToLower()))
220 xff = xff.ToLower();
221 119
222 if (!headers.ContainsKey(xff) || headers[xff] == null) 120 protected override bool CreateAgent(GridRegion source, GridRegion gatekeeper, GridRegion destination,
223 { 121 AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason)
224 m_log.WarnFormat("[AGENT HANDLER]: No XFF header"); 122 {
225 return Util.GetCallerIP(request); 123 return m_UserAgentService.LoginAgentToGrid(source, aCircuit, gatekeeper, destination, fromLogin, out reason);
226 } 124 }
227 125
228 m_log.DebugFormat("[AGENT HANDLER]: XFF is {0}", headers[xff]); 126 }
229 127
230 IPEndPoint ep = Util.GetClientIPFromXFF((string)headers[xff]); 128 public class ExtendedAgentDestinationData : AgentDestinationData
231 if (ep != null) 129 {
232 return ep.Address.ToString(); 130 public string host;
131 public int port;
132 public string gatekeeperServerURI;
133 public string destinationServerURI;
233 134
234 // Oops
235 return Util.GetCallerIP(request);
236 }
237 } 135 }
238 136
239} 137}
diff --git a/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs
index 5d03097..c7ac9be 100644
--- a/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -94,22 +94,38 @@ namespace OpenSim.Server.Handlers.Hypergrid
94 UUID regionID = UUID.Zero; 94 UUID regionID = UUID.Zero;
95 UUID.TryParse(regionID_str, out regionID); 95 UUID.TryParse(regionID_str, out regionID);
96 96
97 GridRegion regInfo = m_GatekeeperService.GetHyperlinkRegion(regionID); 97 UUID agentID = UUID.Zero;
98 string agentHomeURI = null;
99 if (requestData.ContainsKey("agent_id"))
100 agentID = UUID.Parse((string)requestData["agent_id"]);
101 if (requestData.ContainsKey("agent_home_uri"))
102 agentHomeURI = (string)requestData["agent_home_uri"];
103
104 string message;
105 GridRegion regInfo = m_GatekeeperService.GetHyperlinkRegion(regionID, agentID, agentHomeURI, out message);
98 106
99 Hashtable hash = new Hashtable(); 107 Hashtable hash = new Hashtable();
100 if (regInfo == null) 108 if (regInfo == null)
109 {
101 hash["result"] = "false"; 110 hash["result"] = "false";
111 }
102 else 112 else
103 { 113 {
104 hash["result"] = "true"; 114 hash["result"] = "true";
105 hash["uuid"] = regInfo.RegionID.ToString(); 115 hash["uuid"] = regInfo.RegionID.ToString();
106 hash["x"] = regInfo.RegionLocX.ToString(); 116 hash["x"] = regInfo.RegionLocX.ToString();
107 hash["y"] = regInfo.RegionLocY.ToString(); 117 hash["y"] = regInfo.RegionLocY.ToString();
118 hash["size_x"] = regInfo.RegionSizeX.ToString();
119 hash["size_y"] = regInfo.RegionSizeY.ToString();
108 hash["region_name"] = regInfo.RegionName; 120 hash["region_name"] = regInfo.RegionName;
109 hash["hostname"] = regInfo.ExternalHostName; 121 hash["hostname"] = regInfo.ExternalHostName;
110 hash["http_port"] = regInfo.HttpPort.ToString(); 122 hash["http_port"] = regInfo.HttpPort.ToString();
111 hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString(); 123 hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString();
112 } 124 }
125
126 if (message != null)
127 hash["message"] = message;
128
113 XmlRpcResponse response = new XmlRpcResponse(); 129 XmlRpcResponse response = new XmlRpcResponse();
114 response.Value = hash; 130 response.Value = hash;
115 return response; 131 return response;
diff --git a/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs
index 80eb5d2..8145a21 100644
--- a/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/InstantMessageServerConnector.cs
@@ -54,10 +54,15 @@ namespace OpenSim.Server.Handlers.Hypergrid
54 private IInstantMessage m_IMService; 54 private IInstantMessage m_IMService;
55 55
56 public InstantMessageServerConnector(IConfigSource config, IHttpServer server) : 56 public InstantMessageServerConnector(IConfigSource config, IHttpServer server) :
57 this(config, server, null) 57 this(config, server, (IInstantMessageSimConnector)null)
58 { 58 {
59 } 59 }
60 60
61 public InstantMessageServerConnector(IConfigSource config, IHttpServer server, string configName) :
62 this(config, server)
63 {
64 }
65
61 public InstantMessageServerConnector(IConfigSource config, IHttpServer server, IInstantMessageSimConnector simConnector) : 66 public InstantMessageServerConnector(IConfigSource config, IHttpServer server, IInstantMessageSimConnector simConnector) :
62 base(config, server, String.Empty) 67 base(config, server, String.Empty)
63 { 68 {
diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
index db62aaa..e112e0e 100644
--- a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs
@@ -62,10 +62,15 @@ namespace OpenSim.Server.Handlers.Hypergrid
62 private bool m_VerifyCallers = false; 62 private bool m_VerifyCallers = false;
63 63
64 public UserAgentServerConnector(IConfigSource config, IHttpServer server) : 64 public UserAgentServerConnector(IConfigSource config, IHttpServer server) :
65 this(config, server, null) 65 this(config, server, (IFriendsSimConnector)null)
66 { 66 {
67 } 67 }
68 68
69 public UserAgentServerConnector(IConfigSource config, IHttpServer server, string configName) :
70 this(config, server)
71 {
72 }
73
69 public UserAgentServerConnector(IConfigSource config, IHttpServer server, IFriendsSimConnector friendsConnector) : 74 public UserAgentServerConnector(IConfigSource config, IHttpServer server, IFriendsSimConnector friendsConnector) :
70 base(config, server, String.Empty) 75 base(config, server, String.Empty)
71 { 76 {
@@ -94,8 +99,10 @@ namespace OpenSim.Server.Handlers.Hypergrid
94 server.AddXmlRPCHandler("verify_client", VerifyClient, false); 99 server.AddXmlRPCHandler("verify_client", VerifyClient, false);
95 server.AddXmlRPCHandler("logout_agent", LogoutAgent, false); 100 server.AddXmlRPCHandler("logout_agent", LogoutAgent, false);
96 101
102#pragma warning disable 0612
97 server.AddXmlRPCHandler("status_notification", StatusNotification, false); 103 server.AddXmlRPCHandler("status_notification", StatusNotification, false);
98 server.AddXmlRPCHandler("get_online_friends", GetOnlineFriends, false); 104 server.AddXmlRPCHandler("get_online_friends", GetOnlineFriends, false);
105#pragma warning restore 0612
99 server.AddXmlRPCHandler("get_user_info", GetUserInfo, false); 106 server.AddXmlRPCHandler("get_user_info", GetUserInfo, false);
100 server.AddXmlRPCHandler("get_server_urls", GetServerURLs, false); 107 server.AddXmlRPCHandler("get_server_urls", GetServerURLs, false);
101 108
@@ -103,7 +110,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
103 server.AddXmlRPCHandler("get_uui", GetUUI, false); 110 server.AddXmlRPCHandler("get_uui", GetUUI, false);
104 server.AddXmlRPCHandler("get_uuid", GetUUID, false); 111 server.AddXmlRPCHandler("get_uuid", GetUUID, false);
105 112
106 server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy).Handler); 113 server.AddStreamHandler(new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy));
107 } 114 }
108 115
109 public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient) 116 public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient)
@@ -127,6 +134,8 @@ namespace OpenSim.Server.Handlers.Hypergrid
127 hash["uuid"] = regInfo.RegionID.ToString(); 134 hash["uuid"] = regInfo.RegionID.ToString();
128 hash["x"] = regInfo.RegionLocX.ToString(); 135 hash["x"] = regInfo.RegionLocX.ToString();
129 hash["y"] = regInfo.RegionLocY.ToString(); 136 hash["y"] = regInfo.RegionLocY.ToString();
137 hash["size_x"] = regInfo.RegionSizeX.ToString();
138 hash["size_y"] = regInfo.RegionSizeY.ToString();
130 hash["region_name"] = regInfo.RegionName; 139 hash["region_name"] = regInfo.RegionName;
131 hash["hostname"] = regInfo.ExternalHostName; 140 hash["hostname"] = regInfo.ExternalHostName;
132 hash["http_port"] = regInfo.HttpPort.ToString(); 141 hash["http_port"] = regInfo.HttpPort.ToString();
@@ -448,7 +457,6 @@ namespace OpenSim.Server.Handlers.Hypergrid
448 XmlRpcResponse response = new XmlRpcResponse(); 457 XmlRpcResponse response = new XmlRpcResponse();
449 response.Value = hash; 458 response.Value = hash;
450 return response; 459 return response;
451
452 } 460 }
453 461
454 /// <summary> 462 /// <summary>
@@ -466,9 +474,7 @@ namespace OpenSim.Server.Handlers.Hypergrid
466 //string portstr = (string)requestData["port"]; 474 //string portstr = (string)requestData["port"];
467 if (requestData.ContainsKey("first") && requestData.ContainsKey("last")) 475 if (requestData.ContainsKey("first") && requestData.ContainsKey("last"))
468 { 476 {
469 UUID userID = UUID.Zero;
470 string first = (string)requestData["first"]; 477 string first = (string)requestData["first"];
471
472 string last = (string)requestData["last"]; 478 string last = (string)requestData["last"];
473 UUID uuid = m_HomeUsersService.GetUUID(first, last); 479 UUID uuid = m_HomeUsersService.GetUUID(first, last);
474 hash["UUID"] = uuid.ToString(); 480 hash["UUID"] = uuid.ToString();
@@ -477,7 +483,6 @@ namespace OpenSim.Server.Handlers.Hypergrid
477 XmlRpcResponse response = new XmlRpcResponse(); 483 XmlRpcResponse response = new XmlRpcResponse();
478 response.Value = hash; 484 response.Value = hash;
479 return response; 485 return response;
480
481 } 486 }
482 } 487 }
483} 488} \ No newline at end of file
diff --git a/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs
index 1d422a7..b295446 100644
--- a/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs
+++ b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs
@@ -86,10 +86,6 @@ namespace OpenSim.Server.Handlers.Inventory
86 protected virtual void AddHttpHandlers(IHttpServer m_httpServer) 86 protected virtual void AddHttpHandlers(IHttpServer m_httpServer)
87 { 87 {
88 m_httpServer.AddStreamHandler( 88 m_httpServer.AddStreamHandler(
89 new RestDeserialiseSecureHandler<Guid, InventoryCollection>(
90 "POST", "/GetInventory/", GetUserInventory, CheckAuthSession));
91
92 m_httpServer.AddStreamHandler(
93 new RestDeserialiseSecureHandler<Guid, List<InventoryFolderBase>>( 89 new RestDeserialiseSecureHandler<Guid, List<InventoryFolderBase>>(
94 "POST", "/SystemFolders/", GetSystemFolders, CheckAuthSession)); 90 "POST", "/SystemFolders/", GetSystemFolders, CheckAuthSession));
95 91
@@ -178,12 +174,6 @@ namespace OpenSim.Server.Handlers.Inventory
178 174
179 #region Wrappers for converting the Guid parameter 175 #region Wrappers for converting the Guid parameter
180 176
181 public InventoryCollection GetUserInventory(Guid guid)
182 {
183 UUID userID = new UUID(guid);
184 return m_InventoryService.GetUserInventory(userID);
185 }
186
187 public List<InventoryFolderBase> GetSystemFolders(Guid guid) 177 public List<InventoryFolderBase> GetSystemFolders(Guid guid)
188 { 178 {
189 UUID userID = new UUID(guid); 179 UUID userID = new UUID(guid);
diff --git a/OpenSim/Server/Handlers/Inventory/InventoryServerMoveItemsHandler.cs b/OpenSim/Server/Handlers/Inventory/InventoryServerMoveItemsHandler.cs
index 231e32f..e2c50fe 100644
--- a/OpenSim/Server/Handlers/Inventory/InventoryServerMoveItemsHandler.cs
+++ b/OpenSim/Server/Handlers/Inventory/InventoryServerMoveItemsHandler.cs
@@ -56,7 +56,7 @@ namespace OpenSim.Server.Handlers.Inventory
56 m_InventoryService = service; 56 m_InventoryService = service;
57 } 57 }
58 58
59 public override byte[] Handle(string path, Stream request, 59 protected override byte[] ProcessRequest(string path, Stream request,
60 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 60 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
61 { 61 {
62 XmlSerializer xs = new XmlSerializer(typeof (List<InventoryItemBase>)); 62 XmlSerializer xs = new XmlSerializer(typeof (List<InventoryItemBase>));
diff --git a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs
index 64127c2..5c4e7a9 100644
--- a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs
+++ b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs
@@ -33,6 +33,7 @@ using System.Collections.Generic;
33using System.IO; 33using System.IO;
34using Nini.Config; 34using Nini.Config;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Framework.ServiceAuth;
36using OpenSim.Server.Base; 37using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces; 38using OpenSim.Services.Interfaces;
38using OpenSim.Framework.Servers.HttpServer; 39using OpenSim.Framework.Servers.HttpServer;
@@ -40,7 +41,9 @@ using OpenSim.Server.Handlers.Base;
40using log4net; 41using log4net;
41using OpenMetaverse; 42using OpenMetaverse;
42 43
43namespace OpenSim.Server.Handlers.Asset 44using System.Threading;
45
46namespace OpenSim.Server.Handlers.Inventory
44{ 47{
45 public class XInventoryInConnector : ServiceConnector 48 public class XInventoryInConnector : ServiceConnector
46 { 49 {
@@ -71,7 +74,9 @@ namespace OpenSim.Server.Handlers.Asset
71 m_InventoryService = 74 m_InventoryService =
72 ServerUtils.LoadPlugin<IInventoryService>(inventoryService, args); 75 ServerUtils.LoadPlugin<IInventoryService>(inventoryService, args);
73 76
74 server.AddStreamHandler(new XInventoryConnectorPostHandler(m_InventoryService)); 77 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
78
79 server.AddStreamHandler(new XInventoryConnectorPostHandler(m_InventoryService, auth));
75 } 80 }
76 } 81 }
77 82
@@ -81,13 +86,13 @@ namespace OpenSim.Server.Handlers.Asset
81 86
82 private IInventoryService m_InventoryService; 87 private IInventoryService m_InventoryService;
83 88
84 public XInventoryConnectorPostHandler(IInventoryService service) : 89 public XInventoryConnectorPostHandler(IInventoryService service, IServiceAuth auth) :
85 base("POST", "/xinventory") 90 base("POST", "/xinventory", auth)
86 { 91 {
87 m_InventoryService = service; 92 m_InventoryService = service;
88 } 93 }
89 94
90 public override byte[] Handle(string path, Stream requestData, 95 protected override byte[] ProcessRequest(string path, Stream requestData,
91 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 96 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
92 { 97 {
93 StreamReader sr = new StreamReader(requestData); 98 StreamReader sr = new StreamReader(requestData);
@@ -114,14 +119,14 @@ namespace OpenSim.Server.Handlers.Asset
114 return HandleCreateUserInventory(request); 119 return HandleCreateUserInventory(request);
115 case "GETINVENTORYSKELETON": 120 case "GETINVENTORYSKELETON":
116 return HandleGetInventorySkeleton(request); 121 return HandleGetInventorySkeleton(request);
117 case "GETUSERINVENTORY":
118 return HandleGetUserInventory(request);
119 case "GETROOTFOLDER": 122 case "GETROOTFOLDER":
120 return HandleGetRootFolder(request); 123 return HandleGetRootFolder(request);
121 case "GETFOLDERFORTYPE": 124 case "GETFOLDERFORTYPE":
122 return HandleGetFolderForType(request); 125 return HandleGetFolderForType(request);
123 case "GETFOLDERCONTENT": 126 case "GETFOLDERCONTENT":
124 return HandleGetFolderContent(request); 127 return HandleGetFolderContent(request);
128 case "GETMULTIPLEFOLDERSCONTENT":
129 return HandleGetMultipleFoldersContent(request);
125 case "GETFOLDERITEMS": 130 case "GETFOLDERITEMS":
126 return HandleGetFolderItems(request); 131 return HandleGetFolderItems(request);
127 case "ADDFOLDER": 132 case "ADDFOLDER":
@@ -144,6 +149,8 @@ namespace OpenSim.Server.Handlers.Asset
144 return HandleDeleteItems(request); 149 return HandleDeleteItems(request);
145 case "GETITEM": 150 case "GETITEM":
146 return HandleGetItem(request); 151 return HandleGetItem(request);
152 case "GETMULTIPLEITEMS":
153 return HandleGetMultipleItems(request);
147 case "GETFOLDER": 154 case "GETFOLDER":
148 return HandleGetFolder(request); 155 return HandleGetFolder(request);
149 case "GETACTIVEGESTURES": 156 case "GETACTIVEGESTURES":
@@ -155,7 +162,7 @@ namespace OpenSim.Server.Handlers.Asset
155 } 162 }
156 catch (Exception e) 163 catch (Exception e)
157 { 164 {
158 m_log.DebugFormat("[XINVENTORY HANDLER]: Exception {0}", e.StackTrace); 165 m_log.Error(string.Format("[XINVENTORY HANDLER]: Exception {0} ", e.Message), e);
159 } 166 }
160 167
161 return FailureResult(); 168 return FailureResult();
@@ -190,18 +197,7 @@ namespace OpenSim.Server.Handlers.Asset
190 197
191 rootElement.AppendChild(result); 198 rootElement.AppendChild(result);
192 199
193 return DocToBytes(doc); 200 return Util.DocToBytes(doc);
194 }
195
196 private byte[] DocToBytes(XmlDocument doc)
197 {
198 MemoryStream ms = new MemoryStream();
199 XmlTextWriter xw = new XmlTextWriter(ms, null);
200 xw.Formatting = Formatting.Indented;
201 doc.WriteTo(xw);
202 xw.Flush();
203
204 return ms.ToArray();
205 } 201 }
206 202
207 byte[] HandleCreateUserInventory(Dictionary<string,object> request) 203 byte[] HandleCreateUserInventory(Dictionary<string,object> request)
@@ -250,45 +246,6 @@ namespace OpenSim.Server.Handlers.Asset
250 return Util.UTF8NoBomEncoding.GetBytes(xmlString); 246 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
251 } 247 }
252 248
253 byte[] HandleGetUserInventory(Dictionary<string, object> request)
254 {
255 Dictionary<string, object> result = new Dictionary<string, object>();
256 UUID principal = UUID.Zero;
257 UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
258
259 InventoryCollection icoll = m_InventoryService.GetUserInventory(principal);
260 if (icoll != null)
261 {
262 Dictionary<string, object> folders = new Dictionary<string, object>();
263 int i = 0;
264 if (icoll.Folders != null)
265 {
266 foreach (InventoryFolderBase f in icoll.Folders)
267 {
268 folders["folder_" + i.ToString()] = EncodeFolder(f);
269 i++;
270 }
271 result["FOLDERS"] = folders;
272 }
273 if (icoll.Items != null)
274 {
275 i = 0;
276 Dictionary<string, object> items = new Dictionary<string, object>();
277 foreach (InventoryItemBase it in icoll.Items)
278 {
279 items["item_" + i.ToString()] = EncodeItem(it);
280 i++;
281 }
282 result["ITEMS"] = items;
283 }
284 }
285
286 string xmlString = ServerUtils.BuildXmlResponse(result);
287
288 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
289 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
290 }
291
292 byte[] HandleGetRootFolder(Dictionary<string,object> request) 249 byte[] HandleGetRootFolder(Dictionary<string,object> request)
293 { 250 {
294 Dictionary<string,object> result = new Dictionary<string,object>(); 251 Dictionary<string,object> result = new Dictionary<string,object>();
@@ -312,7 +269,7 @@ namespace OpenSim.Server.Handlers.Asset
312 UUID.TryParse(request["PRINCIPAL"].ToString(), out principal); 269 UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
313 int type = 0; 270 int type = 0;
314 Int32.TryParse(request["TYPE"].ToString(), out type); 271 Int32.TryParse(request["TYPE"].ToString(), out type);
315 InventoryFolderBase folder = m_InventoryService.GetFolderForType(principal, (AssetType)type); 272 InventoryFolderBase folder = m_InventoryService.GetFolderForType(principal, (FolderType)type);
316 if (folder != null) 273 if (folder != null)
317 result["folder"] = EncodeFolder(folder); 274 result["folder"] = EncodeFolder(folder);
318 275
@@ -333,6 +290,8 @@ namespace OpenSim.Server.Handlers.Asset
333 InventoryCollection icoll = m_InventoryService.GetFolderContent(principal, folderID); 290 InventoryCollection icoll = m_InventoryService.GetFolderContent(principal, folderID);
334 if (icoll != null) 291 if (icoll != null)
335 { 292 {
293 result["FID"] = icoll.FolderID.ToString();
294 result["VERSION"] = icoll.Version.ToString();
336 Dictionary<string, object> folders = new Dictionary<string, object>(); 295 Dictionary<string, object> folders = new Dictionary<string, object>();
337 int i = 0; 296 int i = 0;
338 if (icoll.Folders != null) 297 if (icoll.Folders != null)
@@ -363,7 +322,71 @@ namespace OpenSim.Server.Handlers.Asset
363 return Util.UTF8NoBomEncoding.GetBytes(xmlString); 322 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
364 } 323 }
365 324
366 byte[] HandleGetFolderItems(Dictionary<string,object> request) 325 byte[] HandleGetMultipleFoldersContent(Dictionary<string, object> request)
326 {
327 Dictionary<string, object> resultSet = new Dictionary<string, object>();
328 UUID principal = UUID.Zero;
329 UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
330 string folderIDstr = request["FOLDERS"].ToString();
331 int count = 0;
332 Int32.TryParse(request["COUNT"].ToString(), out count);
333
334 UUID[] fids = new UUID[count];
335 string[] uuids = folderIDstr.Split(',');
336 int i = 0;
337 foreach (string id in uuids)
338 {
339 UUID fid = UUID.Zero;
340 if (UUID.TryParse(id, out fid))
341 fids[i] = fid;
342 i += 1;
343 }
344
345 count = 0;
346 InventoryCollection[] icollList = m_InventoryService.GetMultipleFoldersContent(principal, fids);
347 if (icollList != null && icollList.Length > 0)
348 {
349 foreach (InventoryCollection icoll in icollList)
350 {
351 Dictionary<string, object> result = new Dictionary<string, object>();
352 result["FID"] = icoll.FolderID.ToString();
353 result["VERSION"] = icoll.Version.ToString();
354 result["OWNER"] = icoll.OwnerID.ToString();
355 Dictionary<string, object> folders = new Dictionary<string, object>();
356 i = 0;
357 if (icoll.Folders != null)
358 {
359 foreach (InventoryFolderBase f in icoll.Folders)
360 {
361 folders["folder_" + i.ToString()] = EncodeFolder(f);
362 i++;
363 }
364 result["FOLDERS"] = folders;
365 }
366 i = 0;
367 if (icoll.Items != null)
368 {
369 Dictionary<string, object> items = new Dictionary<string, object>();
370 foreach (InventoryItemBase it in icoll.Items)
371 {
372 items["item_" + i.ToString()] = EncodeItem(it);
373 i++;
374 }
375 result["ITEMS"] = items;
376 }
377
378 resultSet["F_" + fids[count++]] = result;
379 //m_log.DebugFormat("[XXX]: Sending {0} {1}", fids[count-1], icoll.FolderID);
380 }
381 }
382
383 string xmlString = ServerUtils.BuildXmlResponse(resultSet);
384
385 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
386 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
387 }
388
389 byte[] HandleGetFolderItems(Dictionary<string, object> request)
367 { 390 {
368 Dictionary<string,object> result = new Dictionary<string,object>(); 391 Dictionary<string,object> result = new Dictionary<string,object>();
369 UUID principal = UUID.Zero; 392 UUID principal = UUID.Zero;
@@ -555,6 +578,40 @@ namespace OpenSim.Server.Handlers.Asset
555 return Util.UTF8NoBomEncoding.GetBytes(xmlString); 578 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
556 } 579 }
557 580
581 byte[] HandleGetMultipleItems(Dictionary<string, object> request)
582 {
583 Dictionary<string, object> resultSet = new Dictionary<string, object>();
584 UUID principal = UUID.Zero;
585 UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
586 string itemIDstr = request["ITEMS"].ToString();
587 int count = 0;
588 Int32.TryParse(request["COUNT"].ToString(), out count);
589
590 UUID[] fids = new UUID[count];
591 string[] uuids = itemIDstr.Split(',');
592 int i = 0;
593 foreach (string id in uuids)
594 {
595 UUID fid = UUID.Zero;
596 if (UUID.TryParse(id, out fid))
597 fids[i] = fid;
598 i += 1;
599 }
600
601 InventoryItemBase[] itemsList = m_InventoryService.GetMultipleItems(principal, fids);
602 if (itemsList != null && itemsList.Length > 0)
603 {
604 count = 0;
605 foreach (InventoryItemBase item in itemsList)
606 resultSet["item_" + count++] = (item == null) ? (object)"NULL" : EncodeItem(item);
607 }
608
609 string xmlString = ServerUtils.BuildXmlResponse(resultSet);
610
611 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
612 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
613 }
614
558 byte[] HandleGetFolder(Dictionary<string,object> request) 615 byte[] HandleGetFolder(Dictionary<string,object> request)
559 { 616 {
560 Dictionary<string, object> result = new Dictionary<string, object>(); 617 Dictionary<string, object> result = new Dictionary<string, object>();
diff --git a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
index f83a239..f2a5678 100644
--- a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
+++ b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
@@ -53,6 +53,7 @@ namespace OpenSim.Server.Handlers.Login
53 53
54 private ILoginService m_LocalService; 54 private ILoginService m_LocalService;
55 private bool m_Proxy; 55 private bool m_Proxy;
56
56 57
57 public LLLoginHandlers(ILoginService service, bool hasProxy) 58 public LLLoginHandlers(ILoginService service, bool hasProxy)
58 { 59 {
@@ -144,6 +145,17 @@ namespace OpenSim.Server.Handlers.Login
144 return FailedXMLRPCResponse(); 145 return FailedXMLRPCResponse();
145 146
146 } 147 }
148 public XmlRpcResponse HandleXMLRPCLoginBlocked(XmlRpcRequest request, IPEndPoint client)
149 {
150 XmlRpcResponse response = new XmlRpcResponse();
151 Hashtable resp = new Hashtable();
152
153 resp["reason"] = "presence";
154 resp["message"] = "Logins are currently restricted. Please try again later.";
155 resp["login"] = "false";
156 response.Value = resp;
157 return response;
158 }
147 159
148 public XmlRpcResponse HandleXMLRPCSetLoginLevel(XmlRpcRequest request, IPEndPoint remoteClient) 160 public XmlRpcResponse HandleXMLRPCSetLoginLevel(XmlRpcRequest request, IPEndPoint remoteClient)
149 { 161 {
@@ -213,6 +225,61 @@ namespace OpenSim.Server.Handlers.Login
213 return FailedOSDResponse(); 225 return FailedOSDResponse();
214 } 226 }
215 227
228 public void HandleWebSocketLoginEvents(string path, WebSocketHttpServerHandler sock)
229 {
230 sock.MaxPayloadSize = 16384; //16 kb payload
231 sock.InitialMsgTimeout = 5000; //5 second first message to trigger at least one of these events
232 sock.NoDelay_TCP_Nagle = true;
233 sock.OnData += delegate(object sender, WebsocketDataEventArgs data) { sock.Close("fail"); };
234 sock.OnPing += delegate(object sender, PingEventArgs pingdata) { sock.Close("fail"); };
235 sock.OnPong += delegate(object sender, PongEventArgs pongdata) { sock.Close("fail"); };
236 sock.OnText += delegate(object sender, WebsocketTextEventArgs text)
237 {
238 OSD request = null;
239 try
240 {
241 request = OSDParser.DeserializeJson(text.Data);
242 if (!(request is OSDMap))
243 {
244 sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse()));
245 }
246 else
247 {
248 OSDMap req = request as OSDMap;
249 string first = req["firstname"].AsString();
250 string last = req["lastname"].AsString();
251 string passwd = req["passwd"].AsString();
252 string start = req["startlocation"].AsString();
253 string version = req["version"].AsString();
254 string channel = req["channel"].AsString();
255 string mac = req["mac"].AsString();
256 string id0 = req["id0"].AsString();
257 UUID scope = UUID.Zero;
258 IPEndPoint endPoint =
259 (sender as WebSocketHttpServerHandler).GetRemoteIPEndpoint();
260 LoginResponse reply = null;
261 reply = m_LocalService.Login(first, last, passwd, start, scope, version,
262 channel, mac, id0, endPoint);
263 sock.SendMessage(OSDParser.SerializeJsonString(reply.ToOSDMap()));
264
265 }
266
267 }
268 catch (Exception)
269 {
270 sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse()));
271 }
272 finally
273 {
274 sock.Close("success");
275 }
276 };
277
278 sock.HandshakeAndUpgrade();
279
280 }
281
282
216 private XmlRpcResponse FailedXMLRPCResponse() 283 private XmlRpcResponse FailedXMLRPCResponse()
217 { 284 {
218 Hashtable hash = new Hashtable(); 285 Hashtable hash = new Hashtable();
diff --git a/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs
index 9a7ad34..f60e892 100644
--- a/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs
+++ b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs
@@ -44,6 +44,7 @@ namespace OpenSim.Server.Handlers.Login
44 44
45 private ILoginService m_LoginService; 45 private ILoginService m_LoginService;
46 private bool m_Proxy; 46 private bool m_Proxy;
47 private BasicDosProtectorOptions m_DosProtectionOptions;
47 48
48 public LLLoginServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) : 49 public LLLoginServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) :
49 base(config, server, String.Empty) 50 base(config, server, String.Empty)
@@ -60,8 +61,8 @@ namespace OpenSim.Server.Handlers.Login
60 InitializeHandlers(server); 61 InitializeHandlers(server);
61 } 62 }
62 63
63 public LLLoginServiceInConnector(IConfigSource config, IHttpServer server) : 64 public LLLoginServiceInConnector(IConfigSource config, IHttpServer server, string configName) :
64 base(config, server, String.Empty) 65 base(config, server, configName)
65 { 66 {
66 string loginService = ReadLocalServiceFromConfig(config); 67 string loginService = ReadLocalServiceFromConfig(config);
67 68
@@ -72,6 +73,11 @@ namespace OpenSim.Server.Handlers.Login
72 InitializeHandlers(server); 73 InitializeHandlers(server);
73 } 74 }
74 75
76 public LLLoginServiceInConnector(IConfigSource config, IHttpServer server) :
77 this(config, server, String.Empty)
78 {
79 }
80
75 private string ReadLocalServiceFromConfig(IConfigSource config) 81 private string ReadLocalServiceFromConfig(IConfigSource config)
76 { 82 {
77 IConfig serverConfig = config.Configs["LoginService"]; 83 IConfig serverConfig = config.Configs["LoginService"];
@@ -83,6 +89,16 @@ namespace OpenSim.Server.Handlers.Login
83 throw new Exception(String.Format("No LocalServiceModule for LoginService in config file")); 89 throw new Exception(String.Format("No LocalServiceModule for LoginService in config file"));
84 90
85 m_Proxy = serverConfig.GetBoolean("HasProxy", false); 91 m_Proxy = serverConfig.GetBoolean("HasProxy", false);
92 m_DosProtectionOptions = new BasicDosProtectorOptions();
93 // Dos Protection Options
94 m_DosProtectionOptions.AllowXForwardedFor = serverConfig.GetBoolean("DOSAllowXForwardedForHeader", false);
95 m_DosProtectionOptions.RequestTimeSpan =
96 TimeSpan.FromMilliseconds(serverConfig.GetInt("DOSRequestTimeFrameMS", 10000));
97 m_DosProtectionOptions.MaxRequestsInTimeframe = serverConfig.GetInt("DOSMaxRequestsInTimeFrame", 5);
98 m_DosProtectionOptions.ForgetTimeSpan =
99 TimeSpan.FromMilliseconds(serverConfig.GetInt("DOSForgiveClientAfterMS", 120000));
100 m_DosProtectionOptions.ReportingName = "LOGINDOSPROTECTION";
101
86 102
87 return loginService; 103 return loginService;
88 } 104 }
@@ -90,9 +106,12 @@ namespace OpenSim.Server.Handlers.Login
90 private void InitializeHandlers(IHttpServer server) 106 private void InitializeHandlers(IHttpServer server)
91 { 107 {
92 LLLoginHandlers loginHandlers = new LLLoginHandlers(m_LoginService, m_Proxy); 108 LLLoginHandlers loginHandlers = new LLLoginHandlers(m_LoginService, m_Proxy);
93 server.AddXmlRPCHandler("login_to_simulator", loginHandlers.HandleXMLRPCLogin, false); 109 server.AddXmlRPCHandler("login_to_simulator",
110 new XmlRpcBasicDOSProtector(loginHandlers.HandleXMLRPCLogin,loginHandlers.HandleXMLRPCLoginBlocked,
111 m_DosProtectionOptions).Process, false);
94 server.AddXmlRPCHandler("set_login_level", loginHandlers.HandleXMLRPCSetLoginLevel, false); 112 server.AddXmlRPCHandler("set_login_level", loginHandlers.HandleXMLRPCSetLoginLevel, false);
95 server.SetDefaultLLSDHandler(loginHandlers.HandleLLSDLogin); 113 server.SetDefaultLLSDHandler(loginHandlers.HandleLLSDLogin);
114 server.AddWebSocketHandler("/WebSocket/GridLogin", loginHandlers.HandleWebSocketLoginEvents);
96 } 115 }
97 } 116 }
98} 117}
diff --git a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
index 4a61969..649a27e 100644
--- a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
+++ b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs
@@ -38,6 +38,7 @@ using OpenMetaverse;
38using OpenSim.Framework; 38using OpenSim.Framework;
39using OpenSim.Server.Base; 39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces; 40using OpenSim.Services.Interfaces;
41using OpenSim.Framework.ServiceAuth;
41using OpenSim.Framework.Servers.HttpServer; 42using OpenSim.Framework.Servers.HttpServer;
42using OpenSim.Server.Handlers.Base; 43using OpenSim.Server.Handlers.Base;
43 44
@@ -79,7 +80,8 @@ namespace OpenSim.Server.Handlers.MapImage
79 m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is OFF"); 80 m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is OFF");
80 81
81 bool proxy = serverConfig.GetBoolean("HasProxy", false); 82 bool proxy = serverConfig.GetBoolean("HasProxy", false);
82 server.AddStreamHandler(new MapServerPostHandler(m_MapService, m_GridService, proxy)); 83 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
84 server.AddStreamHandler(new MapServerPostHandler(m_MapService, m_GridService, proxy, auth));
83 85
84 } 86 }
85 } 87 }
@@ -91,15 +93,15 @@ namespace OpenSim.Server.Handlers.MapImage
91 private IGridService m_GridService; 93 private IGridService m_GridService;
92 bool m_Proxy; 94 bool m_Proxy;
93 95
94 public MapServerPostHandler(IMapImageService service, IGridService grid, bool proxy) : 96 public MapServerPostHandler(IMapImageService service, IGridService grid, bool proxy, IServiceAuth auth) :
95 base("POST", "/map") 97 base("POST", "/map", auth)
96 { 98 {
97 m_MapService = service; 99 m_MapService = service;
98 m_GridService = grid; 100 m_GridService = grid;
99 m_Proxy = proxy; 101 m_Proxy = proxy;
100 } 102 }
101 103
102 public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 104 protected override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
103 { 105 {
104// m_log.DebugFormat("[MAP SERVICE IMAGE HANDLER]: Received {0}", path); 106// m_log.DebugFormat("[MAP SERVICE IMAGE HANDLER]: Received {0}", path);
105 StreamReader sr = new StreamReader(requestData); 107 StreamReader sr = new StreamReader(requestData);
@@ -116,9 +118,9 @@ namespace OpenSim.Server.Handlers.MapImage
116 httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest; 118 httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest;
117 return FailureResult("Bad request."); 119 return FailureResult("Bad request.");
118 } 120 }
119 int x = 0, y = 0; 121 uint x = 0, y = 0;
120 Int32.TryParse(request["X"].ToString(), out x); 122 UInt32.TryParse(request["X"].ToString(), out x);
121 Int32.TryParse(request["Y"].ToString(), out y); 123 UInt32.TryParse(request["Y"].ToString(), out y);
122 124
123 m_log.DebugFormat("[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y); 125 m_log.DebugFormat("[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y);
124 126
@@ -130,7 +132,7 @@ namespace OpenSim.Server.Handlers.MapImage
130 if (m_GridService != null) 132 if (m_GridService != null)
131 { 133 {
132 System.Net.IPAddress ipAddr = GetCallerIP(httpRequest); 134 System.Net.IPAddress ipAddr = GetCallerIP(httpRequest);
133 GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, x * (int)Constants.RegionSize, y * (int)Constants.RegionSize); 135 GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc(x), (int)Util.RegionToWorldLoc(y));
134 if (r != null) 136 if (r != null)
135 { 137 {
136 if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString()) 138 if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString())
@@ -151,7 +153,7 @@ namespace OpenSim.Server.Handlers.MapImage
151 byte[] data = Convert.FromBase64String(request["DATA"].ToString()); 153 byte[] data = Convert.FromBase64String(request["DATA"].ToString());
152 154
153 string reason = string.Empty; 155 string reason = string.Empty;
154 bool result = m_MapService.AddMapTile(x, y, data, out reason); 156 bool result = m_MapService.AddMapTile((int)x, (int)y, data, out reason);
155 157
156 if (result) 158 if (result)
157 return SuccessResult(); 159 return SuccessResult();
@@ -186,7 +188,7 @@ namespace OpenSim.Server.Handlers.MapImage
186 188
187 rootElement.AppendChild(result); 189 rootElement.AppendChild(result);
188 190
189 return DocToBytes(doc); 191 return Util.DocToBytes(doc);
190 } 192 }
191 193
192 private byte[] FailureResult(string msg) 194 private byte[] FailureResult(string msg)
@@ -213,18 +215,7 @@ namespace OpenSim.Server.Handlers.MapImage
213 215
214 rootElement.AppendChild(message); 216 rootElement.AppendChild(message);
215 217
216 return DocToBytes(doc); 218 return Util.DocToBytes(doc);
217 }
218
219 private byte[] DocToBytes(XmlDocument doc)
220 {
221 MemoryStream ms = new MemoryStream();
222 XmlTextWriter xw = new XmlTextWriter(ms, null);
223 xw.Formatting = Formatting.Indented;
224 doc.WriteTo(xw);
225 xw.Flush();
226
227 return ms.ToArray();
228 } 219 }
229 220
230 private System.Net.IPAddress GetCallerIP(IOSHttpRequest request) 221 private System.Net.IPAddress GetCallerIP(IOSHttpRequest request)
diff --git a/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs b/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs
index fb85d1c..7bb2f39 100644
--- a/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs
+++ b/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs
@@ -80,7 +80,7 @@ namespace OpenSim.Server.Handlers.MapImage
80 m_MapService = service; 80 m_MapService = service;
81 } 81 }
82 82
83 public override byte[] Handle(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 83 protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
84 { 84 {
85 byte[] result = new byte[0]; 85 byte[] result = new byte[0];
86 86
diff --git a/OpenSim/Server/Handlers/Neighbour/NeighbourHandlers.cs b/OpenSim/Server/Handlers/Neighbour/NeighbourHandlers.cs
index 8a1f824..3525a01 100644
--- a/OpenSim/Server/Handlers/Neighbour/NeighbourHandlers.cs
+++ b/OpenSim/Server/Handlers/Neighbour/NeighbourHandlers.cs
@@ -58,7 +58,7 @@ namespace OpenSim.Server.Handlers.Neighbour
58 // TODO: unused: m_AuthenticationService = authentication; 58 // TODO: unused: m_AuthenticationService = authentication;
59 } 59 }
60 60
61 public override byte[] Handle(string path, Stream request, 61 protected override byte[] ProcessRequest(string path, Stream request,
62 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 62 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
63 { 63 {
64 // Not implemented yet 64 // Not implemented yet
@@ -83,7 +83,7 @@ namespace OpenSim.Server.Handlers.Neighbour
83 // TODO: unused: m_AllowForeignGuests = foreignGuests; 83 // TODO: unused: m_AllowForeignGuests = foreignGuests;
84 } 84 }
85 85
86 public override byte[] Handle(string path, Stream request, 86 protected override byte[] ProcessRequest(string path, Stream request,
87 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 87 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
88 { 88 {
89 byte[] result = new byte[0]; 89 byte[] result = new byte[0];
@@ -176,7 +176,7 @@ namespace OpenSim.Server.Handlers.Neighbour
176 // TODO: unused: m_AuthenticationService = authentication; 176 // TODO: unused: m_AuthenticationService = authentication;
177 } 177 }
178 178
179 public override byte[] Handle(string path, Stream request, 179 protected override byte[] ProcessRequest(string path, Stream request,
180 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 180 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
181 { 181 {
182 // Not implemented yet 182 // Not implemented yet
@@ -197,7 +197,7 @@ namespace OpenSim.Server.Handlers.Neighbour
197 // TODO: unused: m_AuthenticationService = authentication; 197 // TODO: unused: m_AuthenticationService = authentication;
198 } 198 }
199 199
200 public override byte[] Handle(string path, Stream request, 200 protected override byte[] ProcessRequest(string path, Stream request,
201 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 201 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
202 { 202 {
203 // Not implemented yet 203 // Not implemented yet
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs b/OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs
index 899cd8f..7a63c36 100644
--- a/OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs
+++ b/OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs
@@ -30,6 +30,7 @@ using Nini.Config;
30using OpenSim.Server.Base; 30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces; 31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer; 32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Framework.ServiceAuth;
33using OpenSim.Server.Handlers.Base; 34using OpenSim.Server.Handlers.Base;
34 35
35namespace OpenSim.Server.Handlers.Presence 36namespace OpenSim.Server.Handlers.Presence
@@ -55,7 +56,9 @@ namespace OpenSim.Server.Handlers.Presence
55 Object[] args = new Object[] { config }; 56 Object[] args = new Object[] { config };
56 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(gridService, args); 57 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(gridService, args);
57 58
58 server.AddStreamHandler(new PresenceServerPostHandler(m_PresenceService)); 59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
60
61 server.AddStreamHandler(new PresenceServerPostHandler(m_PresenceService, auth));
59 } 62 }
60 } 63 }
61} 64}
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
index 2d67c6d..49dbcb5 100644
--- a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
@@ -40,6 +40,7 @@ using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces; 40using OpenSim.Services.Interfaces;
41using OpenSim.Framework; 41using OpenSim.Framework;
42using OpenSim.Framework.Servers.HttpServer; 42using OpenSim.Framework.Servers.HttpServer;
43using OpenSim.Framework.ServiceAuth;
43using OpenMetaverse; 44using OpenMetaverse;
44 45
45namespace OpenSim.Server.Handlers.Presence 46namespace OpenSim.Server.Handlers.Presence
@@ -50,13 +51,13 @@ namespace OpenSim.Server.Handlers.Presence
50 51
51 private IPresenceService m_PresenceService; 52 private IPresenceService m_PresenceService;
52 53
53 public PresenceServerPostHandler(IPresenceService service) : 54 public PresenceServerPostHandler(IPresenceService service, IServiceAuth auth) :
54 base("POST", "/presence") 55 base("POST", "/presence", auth)
55 { 56 {
56 m_PresenceService = service; 57 m_PresenceService = service;
57 } 58 }
58 59
59 public override byte[] Handle(string path, Stream requestData, 60 protected override byte[] ProcessRequest(string path, Stream requestData,
60 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 61 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
61 { 62 {
62 StreamReader sr = new StreamReader(requestData); 63 StreamReader sr = new StreamReader(requestData);
@@ -264,7 +265,7 @@ namespace OpenSim.Server.Handlers.Presence
264 265
265 rootElement.AppendChild(result); 266 rootElement.AppendChild(result);
266 267
267 return DocToBytes(doc); 268 return Util.DocToBytes(doc);
268 } 269 }
269 270
270 private byte[] FailureResult() 271 private byte[] FailureResult()
@@ -286,18 +287,7 @@ namespace OpenSim.Server.Handlers.Presence
286 287
287 rootElement.AppendChild(result); 288 rootElement.AppendChild(result);
288 289
289 return DocToBytes(doc); 290 return Util.DocToBytes(doc);
290 }
291
292 private byte[] DocToBytes(XmlDocument doc)
293 {
294 MemoryStream ms = new MemoryStream();
295 XmlTextWriter xw = new XmlTextWriter(ms, null);
296 xw.Formatting = Formatting.Indented;
297 doc.WriteTo(xw);
298 xw.Flush();
299
300 return ms.ToArray();
301 } 291 }
302 292
303 } 293 }
diff --git a/OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs b/OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs
new file mode 100644
index 0000000..2dfb862
--- /dev/null
+++ b/OpenSim/Server/Handlers/Profiles/UserProfilesConnector.cs
@@ -0,0 +1,109 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using Nini.Config;
31using OpenSim.Server.Base;
32using OpenSim.Services.Interfaces;
33using OpenSim.Framework.Servers.HttpServer;
34using OpenSim.Framework;
35using OpenSim.Server.Handlers.Base;
36using log4net;
37
38namespace OpenSim.Server.Handlers.Profiles
39{
40 public class UserProfilesConnector: ServiceConnector
41 {
42// static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 // Our Local Module
45 public IUserProfilesService ServiceModule
46 {
47 get; private set;
48 }
49
50 // The HTTP server.
51 public IHttpServer Server
52 {
53 get; private set;
54 }
55
56 public bool Enabled
57 {
58 get; private set;
59 }
60
61 public UserProfilesConnector(IConfigSource config, IHttpServer server, string configName) :
62 base(config, server, configName)
63 {
64 ConfigName = "UserProfilesService";
65 if(!string.IsNullOrEmpty(configName))
66 ConfigName = configName;
67
68 IConfig serverConfig = config.Configs[ConfigName];
69 if (serverConfig == null)
70 throw new Exception(String.Format("No section {0} in config file", ConfigName));
71
72 if(!serverConfig.GetBoolean("Enabled",false))
73 {
74 Enabled = false;
75 return;
76 }
77
78 Enabled = true;
79
80 Server = server;
81
82 string service = serverConfig.GetString("LocalServiceModule", String.Empty);
83
84 Object[] args = new Object[] { config, ConfigName };
85 ServiceModule = ServerUtils.LoadPlugin<IUserProfilesService>(service, args);
86
87 JsonRpcProfileHandlers handler = new JsonRpcProfileHandlers(ServiceModule);
88
89 Server.AddJsonRPCHandler("avatarclassifiedsrequest", handler.AvatarClassifiedsRequest);
90 Server.AddJsonRPCHandler("classified_update", handler.ClassifiedUpdate);
91 Server.AddJsonRPCHandler("classifieds_info_query", handler.ClassifiedInfoRequest);
92 Server.AddJsonRPCHandler("classified_delete", handler.ClassifiedDelete);
93 Server.AddJsonRPCHandler("avatarpicksrequest", handler.AvatarPicksRequest);
94 Server.AddJsonRPCHandler("pickinforequest", handler.PickInfoRequest);
95 Server.AddJsonRPCHandler("picks_update", handler.PicksUpdate);
96 Server.AddJsonRPCHandler("picks_delete", handler.PicksDelete);
97 Server.AddJsonRPCHandler("avatarnotesrequest", handler.AvatarNotesRequest);
98 Server.AddJsonRPCHandler("avatar_notes_update", handler.NotesUpdate);
99 Server.AddJsonRPCHandler("avatar_properties_request", handler.AvatarPropertiesRequest);
100 Server.AddJsonRPCHandler("avatar_properties_update", handler.AvatarPropertiesUpdate);
101 Server.AddJsonRPCHandler("avatar_interests_update", handler.AvatarInterestsUpdate);
102 Server.AddJsonRPCHandler("user_preferences_update", handler.UserPreferenecesUpdate);
103 Server.AddJsonRPCHandler("user_preferences_request", handler.UserPreferencesRequest);
104 Server.AddJsonRPCHandler("image_assets_request", handler.AvatarImageAssetsRequest);
105 Server.AddJsonRPCHandler("user_data_request", handler.RequestUserAppData);
106 Server.AddJsonRPCHandler("user_data_update", handler.UpdateUserAppData);
107 }
108 }
109} \ No newline at end of file
diff --git a/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs b/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs
new file mode 100644
index 0000000..49aa8ba
--- /dev/null
+++ b/OpenSim/Server/Handlers/Profiles/UserProfilesHandlers.cs
@@ -0,0 +1,513 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using OpenMetaverse;
31using OpenMetaverse.StructuredData;
32using log4net;
33using OpenSim.Services.Interfaces;
34using OpenSim.Framework.Servers.HttpServer;
35using OpenSim.Framework;
36
37namespace OpenSim.Server.Handlers
38{
39 public class UserProfilesHandlers
40 {
41 public UserProfilesHandlers ()
42 {
43 }
44 }
45
46 public class JsonRpcProfileHandlers
47 {
48 static readonly ILog m_log =
49 LogManager.GetLogger(
50 MethodBase.GetCurrentMethod().DeclaringType);
51
52 public IUserProfilesService Service
53 {
54 get; private set;
55 }
56
57 public JsonRpcProfileHandlers(IUserProfilesService service)
58 {
59 Service = service;
60 }
61
62 #region Classifieds
63 /// <summary>
64 /// Request avatar's classified ads.
65 /// </summary>
66 /// <returns>
67 /// An array containing all the calassified uuid and it's name created by the creator id
68 /// </returns>
69 /// <param name='json'>
70 /// Our parameters are in the OSDMap json["params"]
71 /// </param>
72 /// <param name='response'>
73 /// If set to <c>true</c> response.
74 /// </param>
75 public bool AvatarClassifiedsRequest(OSDMap json, ref JsonRpcResponse response)
76 {
77 if(!json.ContainsKey("params"))
78 {
79 response.Error.Code = ErrorCode.ParseError;
80 m_log.DebugFormat ("Classified Request");
81 return false;
82 }
83
84 OSDMap request = (OSDMap)json["params"];
85 UUID creatorId = new UUID(request["creatorId"].AsString());
86
87
88 OSDArray data = (OSDArray) Service.AvatarClassifiedsRequest(creatorId);
89 response.Result = data;
90
91 return true;
92 }
93
94 public bool ClassifiedUpdate(OSDMap json, ref JsonRpcResponse response)
95 {
96 if(!json.ContainsKey("params"))
97 {
98 response.Error.Code = ErrorCode.ParseError;
99 response.Error.Message = "Error parsing classified update request";
100 m_log.DebugFormat ("Classified Update Request");
101 return false;
102 }
103
104 string result = string.Empty;
105 UserClassifiedAdd ad = new UserClassifiedAdd();
106 object Ad = (object)ad;
107 OSD.DeserializeMembers(ref Ad, (OSDMap)json["params"]);
108 if(Service.ClassifiedUpdate(ad, ref result))
109 {
110 response.Result = OSD.SerializeMembers(ad);
111 return true;
112 }
113
114 response.Error.Code = ErrorCode.InternalError;
115 response.Error.Message = string.Format("{0}", result);
116 return false;
117 }
118
119 public bool ClassifiedDelete(OSDMap json, ref JsonRpcResponse response)
120 {
121 if(!json.ContainsKey("params"))
122 {
123 response.Error.Code = ErrorCode.ParseError;
124 m_log.DebugFormat ("Classified Delete Request");
125 return false;
126 }
127
128 OSDMap request = (OSDMap)json["params"];
129 UUID classifiedId = new UUID(request["classifiedId"].AsString());
130
131 if (Service.ClassifiedDelete(classifiedId))
132 return true;
133
134 response.Error.Code = ErrorCode.InternalError;
135 response.Error.Message = "data error removing record";
136 return false;
137 }
138
139 public bool ClassifiedInfoRequest(OSDMap json, ref JsonRpcResponse response)
140 {
141 if(!json.ContainsKey("params"))
142 {
143 response.Error.Code = ErrorCode.ParseError;
144 response.Error.Message = "no parameters supplied";
145 m_log.DebugFormat ("Classified Info Request");
146 return false;
147 }
148
149 string result = string.Empty;
150 UserClassifiedAdd ad = new UserClassifiedAdd();
151 object Ad = (object)ad;
152 OSD.DeserializeMembers(ref Ad, (OSDMap)json["params"]);
153 if(Service.ClassifiedInfoRequest(ref ad, ref result))
154 {
155 response.Result = OSD.SerializeMembers(ad);
156 return true;
157 }
158
159 response.Error.Code = ErrorCode.InternalError;
160 response.Error.Message = string.Format("{0}", result);
161 return false;
162 }
163 #endregion Classifieds
164
165 #region Picks
166 public bool AvatarPicksRequest(OSDMap json, ref JsonRpcResponse response)
167 {
168 if(!json.ContainsKey("params"))
169 {
170 response.Error.Code = ErrorCode.ParseError;
171 m_log.DebugFormat ("Avatar Picks Request");
172 return false;
173 }
174
175 OSDMap request = (OSDMap)json["params"];
176 UUID creatorId = new UUID(request["creatorId"].AsString());
177
178
179 OSDArray data = (OSDArray) Service.AvatarPicksRequest(creatorId);
180 response.Result = data;
181
182 return true;
183 }
184
185 public bool PickInfoRequest(OSDMap json, ref JsonRpcResponse response)
186 {
187 if(!json.ContainsKey("params"))
188 {
189 response.Error.Code = ErrorCode.ParseError;
190 response.Error.Message = "no parameters supplied";
191 m_log.DebugFormat ("Avatar Picks Info Request");
192 return false;
193 }
194
195 string result = string.Empty;
196 UserProfilePick pick = new UserProfilePick();
197 object Pick = (object)pick;
198 OSD.DeserializeMembers(ref Pick, (OSDMap)json["params"]);
199 if(Service.PickInfoRequest(ref pick, ref result))
200 {
201 response.Result = OSD.SerializeMembers(pick);
202 return true;
203 }
204
205 response.Error.Code = ErrorCode.InternalError;
206 response.Error.Message = string.Format("{0}", result);
207 return false;
208 }
209
210 public bool PicksUpdate(OSDMap json, ref JsonRpcResponse response)
211 {
212 if(!json.ContainsKey("params"))
213 {
214 response.Error.Code = ErrorCode.ParseError;
215 response.Error.Message = "no parameters supplied";
216 m_log.DebugFormat ("Avatar Picks Update Request");
217 return false;
218 }
219
220 string result = string.Empty;
221 UserProfilePick pick = new UserProfilePick();
222 object Pick = (object)pick;
223 OSD.DeserializeMembers(ref Pick, (OSDMap)json["params"]);
224 if(Service.PicksUpdate(ref pick, ref result))
225 {
226 response.Result = OSD.SerializeMembers(pick);
227 return true;
228 }
229
230 response.Error.Code = ErrorCode.InternalError;
231 response.Error.Message = "unable to update pick";
232
233 return false;
234 }
235
236 public bool PicksDelete(OSDMap json, ref JsonRpcResponse response)
237 {
238 if(!json.ContainsKey("params"))
239 {
240 response.Error.Code = ErrorCode.ParseError;
241 m_log.DebugFormat ("Avatar Picks Delete Request");
242 return false;
243 }
244
245 OSDMap request = (OSDMap)json["params"];
246 UUID pickId = new UUID(request["pickId"].AsString());
247 if(Service.PicksDelete(pickId))
248 return true;
249
250 response.Error.Code = ErrorCode.InternalError;
251 response.Error.Message = "data error removing record";
252 return false;
253 }
254 #endregion Picks
255
256 #region Notes
257 public bool AvatarNotesRequest(OSDMap json, ref JsonRpcResponse response)
258 {
259 if(!json.ContainsKey("params"))
260 {
261 response.Error.Code = ErrorCode.ParseError;
262 response.Error.Message = "Params missing";
263 m_log.DebugFormat ("Avatar Notes Request");
264 return false;
265 }
266
267 UserProfileNotes note = new UserProfileNotes();
268 object Note = (object)note;
269 OSD.DeserializeMembers(ref Note, (OSDMap)json["params"]);
270 if(Service.AvatarNotesRequest(ref note))
271 {
272 response.Result = OSD.SerializeMembers(note);
273 return true;
274 }
275
276 response.Error.Code = ErrorCode.InternalError;
277 response.Error.Message = "Error reading notes";
278 return false;
279 }
280
281 public bool NotesUpdate(OSDMap json, ref JsonRpcResponse response)
282 {
283 if(!json.ContainsKey("params"))
284 {
285 response.Error.Code = ErrorCode.ParseError;
286 response.Error.Message = "No parameters";
287 m_log.DebugFormat ("Avatar Notes Update Request");
288 return false;
289 }
290
291 string result = string.Empty;
292 UserProfileNotes note = new UserProfileNotes();
293 object Notes = (object) note;
294 OSD.DeserializeMembers(ref Notes, (OSDMap)json["params"]);
295 if(Service.NotesUpdate(ref note, ref result))
296 {
297 response.Result = OSD.SerializeMembers(note);
298 return true;
299 }
300 return true;
301 }
302 #endregion Notes
303
304 #region Profile Properties
305 public bool AvatarPropertiesRequest(OSDMap json, ref JsonRpcResponse response)
306 {
307 if(!json.ContainsKey("params"))
308 {
309 response.Error.Code = ErrorCode.ParseError;
310 response.Error.Message = "no parameters supplied";
311 m_log.DebugFormat ("Avatar Properties Request");
312 return false;
313 }
314
315 string result = string.Empty;
316 UserProfileProperties props = new UserProfileProperties();
317 object Props = (object)props;
318 OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
319 if(Service.AvatarPropertiesRequest(ref props, ref result))
320 {
321 response.Result = OSD.SerializeMembers(props);
322 return true;
323 }
324
325 response.Error.Code = ErrorCode.InternalError;
326 response.Error.Message = string.Format("{0}", result);
327 return false;
328 }
329
330 public bool AvatarPropertiesUpdate(OSDMap json, ref JsonRpcResponse response)
331 {
332 if(!json.ContainsKey("params"))
333 {
334 response.Error.Code = ErrorCode.ParseError;
335 response.Error.Message = "no parameters supplied";
336 m_log.DebugFormat ("Avatar Properties Update Request");
337 return false;
338 }
339
340 string result = string.Empty;
341 UserProfileProperties props = new UserProfileProperties();
342 object Props = (object)props;
343 OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
344 if(Service.AvatarPropertiesUpdate(ref props, ref result))
345 {
346 response.Result = OSD.SerializeMembers(props);
347 return true;
348 }
349
350 response.Error.Code = ErrorCode.InternalError;
351 response.Error.Message = string.Format("{0}", result);
352 return false;
353 }
354 #endregion Profile Properties
355
356 #region Interests
357 public bool AvatarInterestsUpdate(OSDMap json, ref JsonRpcResponse response)
358 {
359 if(!json.ContainsKey("params"))
360 {
361 response.Error.Code = ErrorCode.ParseError;
362 response.Error.Message = "no parameters supplied";
363 m_log.DebugFormat ("Avatar Interests Update Request");
364 return false;
365 }
366
367 string result = string.Empty;
368 UserProfileProperties props = new UserProfileProperties();
369 object Props = (object)props;
370 OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
371 if(Service.AvatarInterestsUpdate(props, ref result))
372 {
373 response.Result = OSD.SerializeMembers(props);
374 return true;
375 }
376
377 response.Error.Code = ErrorCode.InternalError;
378 response.Error.Message = string.Format("{0}", result);
379 return false;
380 }
381 #endregion Interests
382
383 #region User Preferences
384 public bool UserPreferencesRequest(OSDMap json, ref JsonRpcResponse response)
385 {
386 if(!json.ContainsKey("params"))
387 {
388 response.Error.Code = ErrorCode.ParseError;
389 m_log.DebugFormat ("User Preferences Request");
390 return false;
391 }
392
393 string result = string.Empty;
394 UserPreferences prefs = new UserPreferences();
395 object Prefs = (object)prefs;
396 OSD.DeserializeMembers(ref Prefs, (OSDMap)json["params"]);
397 if(Service.UserPreferencesRequest(ref prefs, ref result))
398 {
399 response.Result = OSD.SerializeMembers(prefs);
400 return true;
401 }
402
403 response.Error.Code = ErrorCode.InternalError;
404 response.Error.Message = string.Format("{0}", result);
405// m_log.InfoFormat("[PROFILES]: User preferences request error - {0}", response.Error.Message);
406 return false;
407 }
408
409 public bool UserPreferenecesUpdate(OSDMap json, ref JsonRpcResponse response)
410 {
411 if(!json.ContainsKey("params"))
412 {
413 response.Error.Code = ErrorCode.ParseError;
414 response.Error.Message = "no parameters supplied";
415 m_log.DebugFormat ("User Preferences Update Request");
416 return false;
417 }
418
419 string result = string.Empty;
420 UserPreferences prefs = new UserPreferences();
421 object Prefs = (object)prefs;
422 OSD.DeserializeMembers(ref Prefs, (OSDMap)json["params"]);
423 if(Service.UserPreferencesUpdate(ref prefs, ref result))
424 {
425 response.Result = OSD.SerializeMembers(prefs);
426 return true;
427 }
428
429 response.Error.Code = ErrorCode.InternalError;
430 response.Error.Message = string.Format("{0}", result);
431 m_log.InfoFormat("[PROFILES]: User preferences update error - {0}", response.Error.Message);
432 return false;
433 }
434 #endregion User Preferences
435
436 #region Utility
437 public bool AvatarImageAssetsRequest(OSDMap json, ref JsonRpcResponse response)
438 {
439 if(!json.ContainsKey("params"))
440 {
441 response.Error.Code = ErrorCode.ParseError;
442 m_log.DebugFormat ("Avatar Image Assets Request");
443 return false;
444 }
445
446 OSDMap request = (OSDMap)json["params"];
447 UUID avatarId = new UUID(request["avatarId"].AsString());
448
449 OSDArray data = (OSDArray) Service.AvatarImageAssetsRequest(avatarId);
450 response.Result = data;
451
452 return true;
453 }
454 #endregion Utiltiy
455
456 #region UserData
457 public bool RequestUserAppData(OSDMap json, ref JsonRpcResponse response)
458 {
459 if(!json.ContainsKey("params"))
460 {
461 response.Error.Code = ErrorCode.ParseError;
462 response.Error.Message = "no parameters supplied";
463 m_log.DebugFormat ("User Application Service URL Request: No Parameters!");
464 return false;
465 }
466
467 string result = string.Empty;
468 UserAppData props = new UserAppData();
469 object Props = (object)props;
470 OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
471 if(Service.RequestUserAppData(ref props, ref result))
472 {
473 OSDMap res = new OSDMap();
474 res["result"] = OSD.FromString("success");
475 res["token"] = OSD.FromString (result);
476 response.Result = res;
477
478 return true;
479 }
480
481 response.Error.Code = ErrorCode.InternalError;
482 response.Error.Message = string.Format("{0}", result);
483 return false;
484 }
485
486 public bool UpdateUserAppData(OSDMap json, ref JsonRpcResponse response)
487 {
488 if(!json.ContainsKey("params"))
489 {
490 response.Error.Code = ErrorCode.ParseError;
491 response.Error.Message = "no parameters supplied";
492 m_log.DebugFormat ("User App Data Update Request");
493 return false;
494 }
495
496 string result = string.Empty;
497 UserAppData props = new UserAppData();
498 object Props = (object)props;
499 OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
500 if(Service.SetUserAppData(props, ref result))
501 {
502 response.Result = OSD.SerializeMembers(props);
503 return true;
504 }
505
506 response.Error.Code = ErrorCode.InternalError;
507 response.Error.Message = string.Format("{0}", result);
508 return false;
509 }
510 #endregion UserData
511 }
512}
513
diff --git a/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs b/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs
index 53e9737..f0b36c1 100644
--- a/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs
+++ b/OpenSim/Server/Handlers/Properties/AssemblyInfo.cs
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
29// Build Number 29// Build Number
30// Revision 30// Revision
31// 31//
32[assembly: AssemblyVersion("0.7.5.*")] 32[assembly: AssemblyVersion("0.8.3.*")]
33[assembly: AssemblyFileVersion("1.0.0.0")] 33
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
index 012b14e..98c5312 100644
--- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
@@ -27,11 +27,14 @@
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic;
31using System.Collections.Specialized;
30using System.IO; 32using System.IO;
31using System.IO.Compression; 33using System.IO.Compression;
32using System.Reflection; 34using System.Reflection;
33using System.Net; 35using System.Net;
34using System.Text; 36using System.Text;
37using System.Web;
35 38
36using OpenSim.Server.Base; 39using OpenSim.Server.Base;
37using OpenSim.Server.Handlers.Base; 40using OpenSim.Server.Handlers.Base;
@@ -90,14 +93,13 @@ namespace OpenSim.Server.Handlers.Simulation
90 93
91 // Next, let's parse the verb 94 // Next, let's parse the verb
92 string method = (string)request["http-method"]; 95 string method = (string)request["http-method"];
93 if (method.Equals("GET")) 96 if (method.Equals("DELETE"))
94 { 97 {
95 DoAgentGet(request, responsedata, agentID, regionID); 98 string auth_token = string.Empty;
96 return responsedata; 99 if (request.ContainsKey("auth"))
97 } 100 auth_token = request["auth"].ToString();
98 else if (method.Equals("DELETE")) 101
99 { 102 DoAgentDelete(request, responsedata, agentID, action, regionID, auth_token);
100 DoAgentDelete(request, responsedata, agentID, action, regionID);
101 return responsedata; 103 return responsedata;
102 } 104 }
103 else if (method.Equals("QUERYACCESS")) 105 else if (method.Equals("QUERYACCESS"))
@@ -107,7 +109,7 @@ namespace OpenSim.Server.Handlers.Simulation
107 } 109 }
108 else 110 else
109 { 111 {
110 m_log.InfoFormat("[AGENT HANDLER]: method {0} not supported in agent message", method); 112 m_log.ErrorFormat("[AGENT HANDLER]: method {0} not supported in agent message {1} (caller is {2})", method, (string)request["uri"], Util.GetCallerIP(request));
111 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; 113 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
112 responsedata["str_response_string"] = "Method not allowed"; 114 responsedata["str_response_string"] = "Method not allowed";
113 115
@@ -116,7 +118,7 @@ namespace OpenSim.Server.Handlers.Simulation
116 118
117 } 119 }
118 120
119 protected virtual void DoQueryAccess(Hashtable request, Hashtable responsedata, UUID id, UUID regionID) 121 protected virtual void DoQueryAccess(Hashtable request, Hashtable responsedata, UUID agentID, UUID regionID)
120 { 122 {
121 if (m_SimulationService == null) 123 if (m_SimulationService == null)
122 { 124 {
@@ -131,86 +133,155 @@ namespace OpenSim.Server.Handlers.Simulation
131 // m_log.DebugFormat("[AGENT HANDLER]: Received QUERYACCESS with {0}", (string)request["body"]); 133 // m_log.DebugFormat("[AGENT HANDLER]: Received QUERYACCESS with {0}", (string)request["body"]);
132 OSDMap args = Utils.GetOSDMap((string)request["body"]); 134 OSDMap args = Utils.GetOSDMap((string)request["body"]);
133 135
136 bool viaTeleport = true;
137 if (args.ContainsKey("viaTeleport"))
138 viaTeleport = args["viaTeleport"].AsBoolean();
139
134 Vector3 position = Vector3.Zero; 140 Vector3 position = Vector3.Zero;
135 if (args.ContainsKey("position")) 141 if (args.ContainsKey("position"))
136 position = Vector3.Parse(args["position"].AsString()); 142 position = Vector3.Parse(args["position"].AsString());
137 143
138 GridRegion destination = new GridRegion(); 144 string agentHomeURI = null;
139 destination.RegionID = regionID; 145 if (args.ContainsKey("agent_home_uri"))
146 agentHomeURI = args["agent_home_uri"].AsString();
140 147
141 string reason; 148 // Decode the legacy (string) version and extract the number
142 string version; 149 float theirVersion = 0f;
143 bool result = m_SimulationService.QueryAccess(destination, id, position, out version, out reason); 150 if (args.ContainsKey("my_version"))
151 {
152 string theirVersionStr = args["my_version"].AsString();
153 string[] parts = theirVersionStr.Split(new char[] {'/'});
154 if (parts.Length > 1)
155 theirVersion = float.Parse(parts[1]);
156 }
144 157
145 responsedata["int_response_code"] = HttpStatusCode.OK; 158 // Decode the new versioning data
159 float minVersionRequired = 0f;
160 float maxVersionRequired = 0f;
161 float minVersionProvided = 0f;
162 float maxVersionProvided = 0f;
146 163
147 OSDMap resp = new OSDMap(3); 164 if (args.ContainsKey("simulation_service_supported_min"))
165 minVersionProvided = (float)args["simulation_service_supported_min"].AsReal();
166 if (args.ContainsKey("simulation_service_supported_max"))
167 maxVersionProvided = (float)args["simulation_service_supported_max"].AsReal();
148 168
149 resp["success"] = OSD.FromBoolean(result); 169 if (args.ContainsKey("simulation_service_accepted_min"))
150 resp["reason"] = OSD.FromString(reason); 170 minVersionRequired = (float)args["simulation_service_accepted_min"].AsReal();
151 resp["version"] = OSD.FromString(version); 171 if (args.ContainsKey("simulation_service_accepted_max"))
172 maxVersionRequired = (float)args["simulation_service_accepted_max"].AsReal();
152 173
153 // We must preserve defaults here, otherwise a false "success" will not be put into the JSON map! 174 responsedata["int_response_code"] = HttpStatusCode.OK;
154 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); 175 OSDMap resp = new OSDMap(3);
155 176
156// Console.WriteLine("str_response_string [{0}]", responsedata["str_response_string"]); 177 float version = 0f;
157 }
158 178
159 protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, UUID regionID) 179 float outboundVersion = 0f;
160 { 180 float inboundVersion = 0f;
161 if (m_SimulationService == null) 181
182 if (minVersionProvided == 0f) // string version or older
162 { 183 {
163 m_log.Debug("[AGENT HANDLER]: Agent GET called. Harmless but useless."); 184 // If there is no version in the packet at all we're looking at 0.6 or
164 responsedata["content_type"] = "application/json"; 185 // even more ancient. Refuse it.
165 responsedata["int_response_code"] = HttpStatusCode.NotImplemented; 186 if(theirVersion == 0f)
166 responsedata["str_response_string"] = string.Empty; 187 {
188 resp["success"] = OSD.FromBoolean(false);
189 resp["reason"] = OSD.FromString("Your region is running a old version of opensim no longer supported. Consider updating it");
190 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true);
191 return;
192 }
167 193
168 return; 194 version = theirVersion;
195
196 if (version < VersionInfo.SimulationServiceVersionAcceptedMin ||
197 version > VersionInfo.SimulationServiceVersionAcceptedMax )
198 {
199 resp["success"] = OSD.FromBoolean(false);
200 resp["reason"] = OSD.FromString(String.Format("Your region protocol version is {0} and we accept only {1} - {2}. No version overlap.", theirVersion, VersionInfo.SimulationServiceVersionAcceptedMin, VersionInfo.SimulationServiceVersionAcceptedMax));
201 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true);
202 return;
203 }
169 } 204 }
170 205 else
171 GridRegion destination = new GridRegion();
172 destination.RegionID = regionID;
173
174 IAgentData agent = null;
175 bool result = m_SimulationService.RetrieveAgent(destination, id, out agent);
176 OSDMap map = null;
177 if (result)
178 { 206 {
179 if (agent != null) // just to make sure 207 // Test for no overlap
208 if (minVersionProvided > VersionInfo.SimulationServiceVersionAcceptedMax ||
209 maxVersionProvided < VersionInfo.SimulationServiceVersionAcceptedMin)
180 { 210 {
181 map = agent.Pack(); 211 resp["success"] = OSD.FromBoolean(false);
182 string strBuffer = ""; 212 resp["reason"] = OSD.FromString(String.Format("Your region provide protocol versions {0} - {1} and we accept only {2} - {3}. No version overlap.", minVersionProvided, maxVersionProvided, VersionInfo.SimulationServiceVersionAcceptedMin, VersionInfo.SimulationServiceVersionAcceptedMax));
183 try 213 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true);
184 { 214 return;
185 strBuffer = OSDParser.SerializeJsonString(map);
186 }
187 catch (Exception e)
188 {
189 m_log.WarnFormat("[AGENT HANDLER]: Exception thrown on serialization of DoAgentGet: {0}", e.Message);
190 responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
191 // ignore. buffer will be empty, caller should check.
192 }
193
194 responsedata["content_type"] = "application/json";
195 responsedata["int_response_code"] = HttpStatusCode.OK;
196 responsedata["str_response_string"] = strBuffer;
197 } 215 }
198 else 216 if (minVersionRequired > VersionInfo.SimulationServiceVersionSupportedMax ||
217 maxVersionRequired < VersionInfo.SimulationServiceVersionSupportedMin)
199 { 218 {
200 responsedata["int_response_code"] = HttpStatusCode.InternalServerError; 219 resp["success"] = OSD.FromBoolean(false);
201 responsedata["str_response_string"] = "Internal error"; 220 resp["reason"] = OSD.FromString(String.Format("You require region protocol versions {0} - {1} and we provide only {2} - {3}. No version overlap.", minVersionRequired, maxVersionRequired, VersionInfo.SimulationServiceVersionSupportedMin, VersionInfo.SimulationServiceVersionSupportedMax));
221 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true);
222 return;
202 } 223 }
224
225 // Determine versions to use
226 // This is intentionally inverted. Inbound and Outbound refer to the direction of the transfer.
227 // Therefore outbound means from the sender to the receier and inbound means from the receiver to the sender.
228 // So outbound is what we will accept and inbound is what we will send. Confused yet?
229 outboundVersion = Math.Min(maxVersionProvided, VersionInfo.SimulationServiceVersionAcceptedMax);
230 inboundVersion = Math.Min(maxVersionRequired, VersionInfo.SimulationServiceVersionSupportedMax);
203 } 231 }
204 else 232
233 List<UUID> features = new List<UUID>();
234
235 if (args.ContainsKey("features"))
236 {
237 OSDArray array = (OSDArray)args["features"];
238
239 foreach (OSD o in array)
240 features.Add(new UUID(o.AsString()));
241 }
242
243 GridRegion destination = new GridRegion();
244 destination.RegionID = regionID;
245
246 string reason;
247 // We're sending the version numbers down to the local connector to do the varregion check.
248 EntityTransferContext ctx = new EntityTransferContext();
249 ctx.InboundVersion = inboundVersion;
250 ctx.OutboundVersion = outboundVersion;
251 if (minVersionProvided == 0f)
205 { 252 {
206 responsedata["int_response_code"] = HttpStatusCode.NotFound; 253 ctx.InboundVersion = version;
207 responsedata["str_response_string"] = "Not Found"; 254 ctx.OutboundVersion = version;
208 } 255 }
256
257 bool result = m_SimulationService.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, features, ctx, out reason);
258
259 resp["success"] = OSD.FromBoolean(result);
260 resp["reason"] = OSD.FromString(reason);
261 string legacyVersion = String.Format("SIMULATION/{0}", version);
262 resp["version"] = OSD.FromString(legacyVersion);
263 resp["negotiated_inbound_version"] = OSD.FromReal(inboundVersion);
264 resp["negotiated_outbound_version"] = OSD.FromReal(outboundVersion);
265 resp["variable_wearables_count_supported"] = OSD.FromBoolean(true);
266
267 OSDArray featuresWanted = new OSDArray();
268 foreach (UUID feature in features)
269 featuresWanted.Add(OSD.FromString(feature.ToString()));
270
271 resp["features"] = featuresWanted;
272
273 // We must preserve defaults here, otherwise a false "success" will not be put into the JSON map!
274 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true);
275
276// Console.WriteLine("str_response_string [{0}]", responsedata["str_response_string"]);
209 } 277 }
210 278
211 protected void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID) 279 protected void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID, string auth_token)
212 { 280 {
213 m_log.Debug(" >>> DoDelete action:" + action + "; RegionID:" + regionID); 281 if (string.IsNullOrEmpty(action))
282 m_log.DebugFormat("[AGENT HANDLER]: >>> DELETE <<< RegionID: {0}; from: {1}; auth_code: {2}", regionID, Util.GetCallerIP(request), auth_token);
283 else
284 m_log.DebugFormat("[AGENT HANDLER]: Release {0} to RegionID: {1}", id, regionID);
214 285
215 GridRegion destination = new GridRegion(); 286 GridRegion destination = new GridRegion();
216 destination.RegionID = regionID; 287 destination.RegionID = regionID;
@@ -218,12 +289,13 @@ namespace OpenSim.Server.Handlers.Simulation
218 if (action.Equals("release")) 289 if (action.Equals("release"))
219 ReleaseAgent(regionID, id); 290 ReleaseAgent(regionID, id);
220 else 291 else
221 m_SimulationService.CloseAgent(destination, id); 292 Util.FireAndForget(
293 o => m_SimulationService.CloseAgent(destination, id, auth_token), null, "AgentHandler.DoAgentDelete");
222 294
223 responsedata["int_response_code"] = HttpStatusCode.OK; 295 responsedata["int_response_code"] = HttpStatusCode.OK;
224 responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); 296 responsedata["str_response_string"] = "OpenSim agent " + id.ToString();
225 297
226 m_log.DebugFormat("[AGENT HANDLER]: Agent {0} Released/Deleted from region {1}", id, regionID); 298 //m_log.DebugFormat("[AGENT HANDLER]: Agent {0} Released/Deleted from region {1}", id, regionID);
227 } 299 }
228 300
229 protected virtual void ReleaseAgent(UUID regionID, UUID id) 301 protected virtual void ReleaseAgent(UUID regionID, UUID id)
@@ -251,7 +323,7 @@ namespace OpenSim.Server.Handlers.Simulation
251 m_SimulationService = null; 323 m_SimulationService = null;
252 } 324 }
253 325
254 public override byte[] Handle(string path, Stream request, 326 protected override byte[] ProcessRequest(string path, Stream request,
255 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 327 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
256 { 328 {
257// m_log.DebugFormat("[SIMULATION]: Stream handler called"); 329// m_log.DebugFormat("[SIMULATION]: Stream handler called");
@@ -280,21 +352,36 @@ namespace OpenSim.Server.Handlers.Simulation
280 httpResponse.KeepAlive = false; 352 httpResponse.KeepAlive = false;
281 Encoding encoding = Encoding.UTF8; 353 Encoding encoding = Encoding.UTF8;
282 354
283 Stream inputStream = null; 355 if (httpRequest.ContentType != "application/json")
284 if (httpRequest.ContentType == "application/x-gzip")
285 inputStream = new GZipStream(request, CompressionMode.Decompress);
286 else if (httpRequest.ContentType == "application/json")
287 inputStream = request;
288 else // no go
289 { 356 {
290 httpResponse.StatusCode = 406; 357 httpResponse.StatusCode = 406;
291 return encoding.GetBytes("false"); 358 return encoding.GetBytes("false");
292 } 359 }
293 360
294 StreamReader reader = new StreamReader(inputStream, encoding); 361 string requestBody;
362
363 Stream inputStream = request;
364 Stream innerStream = null;
365 try
366 {
367 if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
368 {
369 innerStream = inputStream;
370 inputStream = new GZipStream(innerStream, CompressionMode.Decompress);
371 }
372
373 using (StreamReader reader = new StreamReader(inputStream, encoding))
374 {
375 requestBody = reader.ReadToEnd();
376 }
377 }
378 finally
379 {
380 if (innerStream != null)
381 innerStream.Dispose();
382 inputStream.Dispose();
383 }
295 384
296 string requestBody = reader.ReadToEnd();
297 reader.Close();
298 keysvals.Add("body", requestBody); 385 keysvals.Add("body", requestBody);
299 386
300 Hashtable responsedata = new Hashtable(); 387 Hashtable responsedata = new Hashtable();
@@ -328,31 +415,16 @@ namespace OpenSim.Server.Handlers.Simulation
328 return; 415 return;
329 } 416 }
330 417
331 // retrieve the input arguments 418 AgentDestinationData data = CreateAgentDestinationData();
332 int x = 0, y = 0; 419 UnpackData(args, data, request);
333 UUID uuid = UUID.Zero;
334 string regionname = string.Empty;
335 uint teleportFlags = 0;
336 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
337 Int32.TryParse(args["destination_x"].AsString(), out x);
338 else
339 m_log.WarnFormat(" -- request didn't have destination_x");
340 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
341 Int32.TryParse(args["destination_y"].AsString(), out y);
342 else
343 m_log.WarnFormat(" -- request didn't have destination_y");
344 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
345 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
346 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
347 regionname = args["destination_name"].ToString();
348 if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
349 teleportFlags = args["teleport_flags"].AsUInteger();
350 420
351 GridRegion destination = new GridRegion(); 421 GridRegion destination = new GridRegion();
352 destination.RegionID = uuid; 422 destination.RegionID = data.uuid;
353 destination.RegionLocX = x; 423 destination.RegionLocX = data.x;
354 destination.RegionLocY = y; 424 destination.RegionLocY = data.y;
355 destination.RegionName = regionname; 425 destination.RegionName = data.name;
426
427 GridRegion gatekeeper = ExtractGatekeeper(data);
356 428
357 AgentCircuitData aCircuit = new AgentCircuitData(); 429 AgentCircuitData aCircuit = new AgentCircuitData();
358 try 430 try
@@ -367,13 +439,29 @@ namespace OpenSim.Server.Handlers.Simulation
367 return; 439 return;
368 } 440 }
369 441
442 GridRegion source = null;
443
444 if (args.ContainsKey("source_uuid"))
445 {
446 source = new GridRegion();
447 source.RegionLocX = Int32.Parse(args["source_x"].AsString());
448 source.RegionLocY = Int32.Parse(args["source_y"].AsString());
449 source.RegionName = args["source_name"].AsString();
450 source.RegionID = UUID.Parse(args["source_uuid"].AsString());
451
452 if (args.ContainsKey("source_server_uri"))
453 source.RawServerURI = args["source_server_uri"].AsString();
454 else
455 source.RawServerURI = null;
456 }
457
370 OSDMap resp = new OSDMap(2); 458 OSDMap resp = new OSDMap(2);
371 string reason = String.Empty; 459 string reason = String.Empty;
372 460
373 // This is the meaning of POST agent 461 // This is the meaning of POST agent
374 //m_regionClient.AdjustUserInformation(aCircuit); 462 //m_regionClient.AdjustUserInformation(aCircuit);
375 //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); 463 //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
376 bool result = CreateAgent(destination, aCircuit, teleportFlags, out reason); 464 bool result = CreateAgent(source, gatekeeper, destination, aCircuit, data.flags, data.fromLogin, out reason);
377 465
378 resp["reason"] = OSD.FromString(reason); 466 resp["reason"] = OSD.FromString(reason);
379 resp["success"] = OSD.FromBoolean(result); 467 resp["success"] = OSD.FromBoolean(result);
@@ -385,7 +473,36 @@ namespace OpenSim.Server.Handlers.Simulation
385 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); 473 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
386 } 474 }
387 475
388 private string GetCallerIP(Hashtable request) 476 protected virtual AgentDestinationData CreateAgentDestinationData()
477 {
478 return new AgentDestinationData();
479 }
480
481 protected virtual void UnpackData(OSDMap args, AgentDestinationData data, Hashtable request)
482 {
483 // retrieve the input arguments
484 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
485 Int32.TryParse(args["destination_x"].AsString(), out data.x);
486 else
487 m_log.WarnFormat(" -- request didn't have destination_x");
488 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
489 Int32.TryParse(args["destination_y"].AsString(), out data.y);
490 else
491 m_log.WarnFormat(" -- request didn't have destination_y");
492 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
493 UUID.TryParse(args["destination_uuid"].AsString(), out data.uuid);
494 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
495 data.name = args["destination_name"].ToString();
496 if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
497 data.flags = args["teleport_flags"].AsUInteger();
498 }
499
500 protected virtual GridRegion ExtractGatekeeper(AgentDestinationData data)
501 {
502 return null;
503 }
504
505 protected string GetCallerIP(Hashtable request)
389 { 506 {
390 if (!m_Proxy) 507 if (!m_Proxy)
391 return Util.GetCallerIP(request); 508 return Util.GetCallerIP(request);
@@ -418,9 +535,10 @@ namespace OpenSim.Server.Handlers.Simulation
418 } 535 }
419 536
420 // subclasses can override this 537 // subclasses can override this
421 protected virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) 538 protected virtual bool CreateAgent(GridRegion source, GridRegion gatekeeper, GridRegion destination,
539 AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason)
422 { 540 {
423 return m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); 541 return m_SimulationService.CreateAgent(source, destination, aCircuit, teleportFlags, out reason);
424 } 542 }
425 } 543 }
426 544
@@ -443,7 +561,7 @@ namespace OpenSim.Server.Handlers.Simulation
443 m_SimulationService = null; 561 m_SimulationService = null;
444 } 562 }
445 563
446 public override byte[] Handle(string path, Stream request, 564 protected override byte[] ProcessRequest(string path, Stream request,
447 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 565 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
448 { 566 {
449// m_log.DebugFormat("[SIMULATION]: Stream handler called"); 567// m_log.DebugFormat("[SIMULATION]: Stream handler called");
@@ -467,17 +585,31 @@ namespace OpenSim.Server.Handlers.Simulation
467 keysvals.Add("headers", headervals); 585 keysvals.Add("headers", headervals);
468 keysvals.Add("querystringkeys", querystringkeys); 586 keysvals.Add("querystringkeys", querystringkeys);
469 587
470 Stream inputStream; 588 String requestBody;
471 if (httpRequest.ContentType == "application/x-gzip")
472 inputStream = new GZipStream(request, CompressionMode.Decompress);
473 else
474 inputStream = request;
475
476 Encoding encoding = Encoding.UTF8; 589 Encoding encoding = Encoding.UTF8;
477 StreamReader reader = new StreamReader(inputStream, encoding);
478 590
479 string requestBody = reader.ReadToEnd(); 591 Stream inputStream = request;
480 reader.Close(); 592 Stream innerStream = null;
593 try
594 {
595 if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
596 {
597 innerStream = inputStream;
598 inputStream = new GZipStream(innerStream, CompressionMode.Decompress);
599 }
600
601 using (StreamReader reader = new StreamReader(inputStream, encoding))
602 {
603 requestBody = reader.ReadToEnd();
604 }
605 }
606 finally
607 {
608 if (innerStream != null)
609 innerStream.Dispose();
610 inputStream.Dispose();
611 }
612
481 keysvals.Add("body", requestBody); 613 keysvals.Add("body", requestBody);
482 614
483 httpResponse.StatusCode = 200; 615 httpResponse.StatusCode = 200;
@@ -562,7 +694,6 @@ namespace OpenSim.Server.Handlers.Simulation
562 //agent.Dump(); 694 //agent.Dump();
563 // This is one of the meanings of PUT agent 695 // This is one of the meanings of PUT agent
564 result = UpdateAgent(destination, agent); 696 result = UpdateAgent(destination, agent);
565
566 } 697 }
567 else if ("AgentPosition".Equals(messageType)) 698 else if ("AgentPosition".Equals(messageType))
568 { 699 {
@@ -593,4 +724,14 @@ namespace OpenSim.Server.Handlers.Simulation
593 return m_SimulationService.UpdateAgent(destination, agent); 724 return m_SimulationService.UpdateAgent(destination, agent);
594 } 725 }
595 } 726 }
727
728 public class AgentDestinationData
729 {
730 public int x;
731 public int y;
732 public string name;
733 public UUID uuid;
734 public uint flags;
735 public bool fromLogin;
736 }
596} 737}
diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs
index 344b513..e95e3dc 100644
--- a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs
+++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs
@@ -30,6 +30,7 @@ using Nini.Config;
30using OpenSim.Server.Base; 30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces; 31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer; 32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Framework.ServiceAuth;
33using OpenSim.Server.Handlers.Base; 34using OpenSim.Server.Handlers.Base;
34 35
35namespace OpenSim.Server.Handlers.UserAccounts 36namespace OpenSim.Server.Handlers.UserAccounts
@@ -55,7 +56,9 @@ namespace OpenSim.Server.Handlers.UserAccounts
55 Object[] args = new Object[] { config }; 56 Object[] args = new Object[] { config };
56 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(service, args); 57 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(service, args);
57 58
58 server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService, serverConfig)); 59 IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
60
61 server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService, serverConfig, auth));
59 } 62 }
60 } 63 }
61} 64}
diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs
index 72551ef..21eb790 100644
--- a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs
@@ -41,6 +41,7 @@ using OpenSim.Services.Interfaces;
41using OpenSim.Services.UserAccountService; 41using OpenSim.Services.UserAccountService;
42using OpenSim.Framework; 42using OpenSim.Framework;
43using OpenSim.Framework.Servers.HttpServer; 43using OpenSim.Framework.Servers.HttpServer;
44using OpenSim.Framework.ServiceAuth;
44using OpenMetaverse; 45using OpenMetaverse;
45 46
46namespace OpenSim.Server.Handlers.UserAccounts 47namespace OpenSim.Server.Handlers.UserAccounts
@@ -54,10 +55,10 @@ namespace OpenSim.Server.Handlers.UserAccounts
54 private bool m_AllowSetAccount = false; 55 private bool m_AllowSetAccount = false;
55 56
56 public UserAccountServerPostHandler(IUserAccountService service) 57 public UserAccountServerPostHandler(IUserAccountService service)
57 : this(service, null) {} 58 : this(service, null, null) {}
58 59
59 public UserAccountServerPostHandler(IUserAccountService service, IConfig config) : 60 public UserAccountServerPostHandler(IUserAccountService service, IConfig config, IServiceAuth auth) :
60 base("POST", "/accounts") 61 base("POST", "/accounts", auth)
61 { 62 {
62 m_UserAccountService = service; 63 m_UserAccountService = service;
63 64
@@ -68,7 +69,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
68 } 69 }
69 } 70 }
70 71
71 public override byte[] Handle(string path, Stream requestData, 72 protected override byte[] ProcessRequest(string path, Stream requestData,
72 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 73 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
73 { 74 {
74 StreamReader sr = new StreamReader(requestData); 75 StreamReader sr = new StreamReader(requestData);
@@ -256,8 +257,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
256 257
257 byte[] CreateUser(Dictionary<string, object> request) 258 byte[] CreateUser(Dictionary<string, object> request)
258 { 259 {
259 if (! 260 if (! request.ContainsKey("FirstName")
260 request.ContainsKey("FirstName")
261 && request.ContainsKey("LastName") 261 && request.ContainsKey("LastName")
262 && request.ContainsKey("Password")) 262 && request.ContainsKey("Password"))
263 return FailureResult(); 263 return FailureResult();
@@ -314,7 +314,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
314 314
315 rootElement.AppendChild(result); 315 rootElement.AppendChild(result);
316 316
317 return DocToBytes(doc); 317 return Util.DocToBytes(doc);
318 } 318 }
319 319
320 private byte[] FailureResult() 320 private byte[] FailureResult()
@@ -336,18 +336,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
336 336
337 rootElement.AppendChild(result); 337 rootElement.AppendChild(result);
338 338
339 return DocToBytes(doc); 339 return Util.DocToBytes(doc);
340 }
341
342 private byte[] DocToBytes(XmlDocument doc)
343 {
344 MemoryStream ms = new MemoryStream();
345 XmlTextWriter xw = new XmlTextWriter(ms, null);
346 xw.Formatting = Formatting.Indented;
347 doc.WriteTo(xw);
348 xw.Flush();
349
350 return ms.ToArray();
351 } 340 }
352 341
353 private byte[] ResultToBytes(Dictionary<string, object> result) 342 private byte[] ResultToBytes(Dictionary<string, object> result)