aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers')
-rw-r--r--OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs14
-rw-r--r--OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs61
-rw-r--r--OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs269
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs92
-rw-r--r--OpenSim/Server/Handlers/Login/LLLoginHandlers.cs149
-rw-r--r--OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs95
-rw-r--r--OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs196
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs338
-rw-r--r--OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs229
-rw-r--r--OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs33
-rw-r--r--OpenSim/Server/Handlers/Simulation/Utils.cs103
-rw-r--r--OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs61
-rw-r--r--OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs257
13 files changed, 1692 insertions, 205 deletions
diff --git a/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs
index 490a13a..47bc860 100644
--- a/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs
@@ -86,14 +86,14 @@ namespace OpenSim.Server.Handlers.Authentication
86 86
87 private byte[] DoPlainMethods(string body) 87 private byte[] DoPlainMethods(string body)
88 { 88 {
89 Dictionary<string, string> request = 89 Dictionary<string, object> request =
90 ServerUtils.ParseQueryString(body); 90 ServerUtils.ParseQueryString(body);
91 91
92 int lifetime = 30; 92 int lifetime = 30;
93 93
94 if (request.ContainsKey("LIFETIME")) 94 if (request.ContainsKey("LIFETIME"))
95 { 95 {
96 lifetime = Convert.ToInt32(request["LIFETIME"]); 96 lifetime = Convert.ToInt32(request["LIFETIME"].ToString());
97 if (lifetime > 30) 97 if (lifetime > 30)
98 lifetime = 30; 98 lifetime = 30;
99 } 99 }
@@ -103,12 +103,12 @@ namespace OpenSim.Server.Handlers.Authentication
103 if (!request.ContainsKey("PRINCIPAL")) 103 if (!request.ContainsKey("PRINCIPAL"))
104 return FailureResult(); 104 return FailureResult();
105 105
106 string method = request["METHOD"]; 106 string method = request["METHOD"].ToString();
107 107
108 UUID principalID; 108 UUID principalID;
109 string token; 109 string token;
110 110
111 if (!UUID.TryParse(request["PRINCIPAL"], out principalID)) 111 if (!UUID.TryParse(request["PRINCIPAL"].ToString(), out principalID))
112 return FailureResult(); 112 return FailureResult();
113 113
114 switch (method) 114 switch (method)
@@ -117,7 +117,7 @@ namespace OpenSim.Server.Handlers.Authentication
117 if (!request.ContainsKey("PASSWORD")) 117 if (!request.ContainsKey("PASSWORD"))
118 return FailureResult(); 118 return FailureResult();
119 119
120 token = m_AuthenticationService.Authenticate(principalID, request["PASSWORD"], lifetime); 120 token = m_AuthenticationService.Authenticate(principalID, request["PASSWORD"].ToString(), lifetime);
121 121
122 if (token != String.Empty) 122 if (token != String.Empty)
123 return SuccessResult(token); 123 return SuccessResult(token);
@@ -126,7 +126,7 @@ namespace OpenSim.Server.Handlers.Authentication
126 if (!request.ContainsKey("TOKEN")) 126 if (!request.ContainsKey("TOKEN"))
127 return FailureResult(); 127 return FailureResult();
128 128
129 if (m_AuthenticationService.Verify(principalID, request["TOKEN"], lifetime)) 129 if (m_AuthenticationService.Verify(principalID, request["TOKEN"].ToString(), lifetime))
130 return SuccessResult(); 130 return SuccessResult();
131 131
132 return FailureResult(); 132 return FailureResult();
@@ -134,7 +134,7 @@ namespace OpenSim.Server.Handlers.Authentication
134 if (!request.ContainsKey("TOKEN")) 134 if (!request.ContainsKey("TOKEN"))
135 return FailureResult(); 135 return FailureResult();
136 136
137 if (m_AuthenticationService.Release(principalID, request["TOKEN"])) 137 if (m_AuthenticationService.Release(principalID, request["TOKEN"].ToString()))
138 return SuccessResult(); 138 return SuccessResult();
139 139
140 return FailureResult(); 140 return FailureResult();
diff --git a/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs b/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs
new file mode 100644
index 0000000..9a57cd9
--- /dev/null
+++ b/OpenSim/Server/Handlers/Avatar/AvatarServerConnector.cs
@@ -0,0 +1,61 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base;
34
35namespace OpenSim.Server.Handlers.Avatar
36{
37 public class AvatarServiceConnector : ServiceConnector
38 {
39 private IAvatarService m_AvatarService;
40 private string m_ConfigName = "AvatarService";
41
42 public AvatarServiceConnector(IConfigSource config, IHttpServer server, string configName) :
43 base(config, server, configName)
44 {
45 IConfig serverConfig = config.Configs[m_ConfigName];
46 if (serverConfig == null)
47 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
48
49 string avatarService = serverConfig.GetString("LocalServiceModule",
50 String.Empty);
51
52 if (avatarService == String.Empty)
53 throw new Exception("No LocalServiceModule in config file");
54
55 Object[] args = new Object[] { config };
56 m_AvatarService = ServerUtils.LoadPlugin<IAvatarService>(avatarService, args);
57
58 server.AddStreamHandler(new AvatarServerPostHandler(m_AvatarService));
59 }
60 }
61}
diff --git a/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs
new file mode 100644
index 0000000..49c2e43
--- /dev/null
+++ b/OpenSim/Server/Handlers/Avatar/AvatarServerPostHandler.cs
@@ -0,0 +1,269 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
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.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.Avatar
46{
47 public class AvatarServerPostHandler : BaseStreamHandler
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IAvatarService m_AvatarService;
52
53 public AvatarServerPostHandler(IAvatarService service) :
54 base("POST", "/avatar")
55 {
56 m_AvatarService = service;
57 }
58
59 public override byte[] Handle(string path, Stream requestData,
60 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
61 {
62 StreamReader sr = new StreamReader(requestData);
63 string body = sr.ReadToEnd();
64 sr.Close();
65 body = body.Trim();
66
67 //m_log.DebugFormat("[XXX]: query String: {0}", body);
68
69 try
70 {
71 Dictionary<string, object> request =
72 ServerUtils.ParseQueryString(body);
73
74 if (!request.ContainsKey("METHOD"))
75 return FailureResult();
76
77 string method = request["METHOD"].ToString();
78
79 switch (method)
80 {
81 case "getavatar":
82 return GetAvatar(request);
83 case "setavatar":
84 return SetAvatar(request);
85 case "resetavatar":
86 return ResetAvatar(request);
87 case "setitems":
88 return SetItems(request);
89 case "removeitems":
90 return RemoveItems(request);
91 }
92 m_log.DebugFormat("[AVATAR HANDLER]: unknown method request: {0}", method);
93 }
94 catch (Exception e)
95 {
96 m_log.Debug("[AVATAR HANDLER]: Exception {0}" + e);
97 }
98
99 return FailureResult();
100
101 }
102
103 byte[] GetAvatar(Dictionary<string, object> request)
104 {
105 UUID user = UUID.Zero;
106
107 if (!request.ContainsKey("UserID"))
108 return FailureResult();
109
110 if (UUID.TryParse(request["UserID"].ToString(), out user))
111 {
112 AvatarData avatar = m_AvatarService.GetAvatar(user);
113 if (avatar == null)
114 return FailureResult();
115
116 Dictionary<string, object> result = new Dictionary<string, object>();
117 if (avatar == null)
118 result["result"] = "null";
119 else
120 result["result"] = avatar.ToKeyValuePairs();
121
122 string xmlString = ServerUtils.BuildXmlResponse(result);
123
124 UTF8Encoding encoding = new UTF8Encoding();
125 return encoding.GetBytes(xmlString);
126 }
127
128 return FailureResult();
129 }
130
131 byte[] SetAvatar(Dictionary<string, object> request)
132 {
133 UUID user = UUID.Zero;
134
135 if (!request.ContainsKey("UserID"))
136 return FailureResult();
137
138 if (!UUID.TryParse(request["UserID"].ToString(), out user))
139 return FailureResult();
140
141 AvatarData avatar = new AvatarData(request);
142 if (m_AvatarService.SetAvatar(user, avatar))
143 return SuccessResult();
144
145 return FailureResult();
146 }
147
148 byte[] ResetAvatar(Dictionary<string, object> request)
149 {
150 UUID user = UUID.Zero;
151 if (!request.ContainsKey("UserID"))
152 return FailureResult();
153
154 if (!UUID.TryParse(request["UserID"].ToString(), out user))
155 return FailureResult();
156
157 if (m_AvatarService.ResetAvatar(user))
158 return SuccessResult();
159
160 return FailureResult();
161 }
162
163 byte[] SetItems(Dictionary<string, object> request)
164 {
165 UUID user = UUID.Zero;
166 string[] names, values;
167
168 if (!request.ContainsKey("UserID") || !request.ContainsKey("Names") || !request.ContainsKey("Values"))
169 return FailureResult();
170
171 if (!UUID.TryParse(request["UserID"].ToString(), out user))
172 return FailureResult();
173
174 if (!(request["Names"] is List<string> || request["Values"] is List<string>))
175 return FailureResult();
176
177 List<string> _names = (List<string>)request["Names"];
178 names = _names.ToArray();
179 List<string> _values = (List<string>)request["Values"];
180 values = _values.ToArray();
181
182 if (m_AvatarService.SetItems(user, names, values))
183 return SuccessResult();
184
185 return FailureResult();
186 }
187
188 byte[] RemoveItems(Dictionary<string, object> request)
189 {
190 UUID user = UUID.Zero;
191 string[] names;
192
193 if (!request.ContainsKey("UserID") || !request.ContainsKey("Names"))
194 return FailureResult();
195
196 if (!UUID.TryParse(request["UserID"].ToString(), out user))
197 return FailureResult();
198
199 if (!(request["Names"] is List<string>))
200 return FailureResult();
201
202 List<string> _names = (List<string>)request["Names"];
203 names = _names.ToArray();
204
205 if (m_AvatarService.RemoveItems(user, names))
206 return SuccessResult();
207
208 return FailureResult();
209 }
210
211
212
213 private byte[] SuccessResult()
214 {
215 XmlDocument doc = new XmlDocument();
216
217 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
218 "", "");
219
220 doc.AppendChild(xmlnode);
221
222 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
223 "");
224
225 doc.AppendChild(rootElement);
226
227 XmlElement result = doc.CreateElement("", "result", "");
228 result.AppendChild(doc.CreateTextNode("Success"));
229
230 rootElement.AppendChild(result);
231
232 return DocToBytes(doc);
233 }
234
235 private byte[] FailureResult()
236 {
237 XmlDocument doc = new XmlDocument();
238
239 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
240 "", "");
241
242 doc.AppendChild(xmlnode);
243
244 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
245 "");
246
247 doc.AppendChild(rootElement);
248
249 XmlElement result = doc.CreateElement("", "result", "");
250 result.AppendChild(doc.CreateTextNode("Failure"));
251
252 rootElement.AppendChild(result);
253
254 return DocToBytes(doc);
255 }
256
257 private byte[] DocToBytes(XmlDocument doc)
258 {
259 MemoryStream ms = new MemoryStream();
260 XmlTextWriter xw = new XmlTextWriter(ms, null);
261 xw.Formatting = Formatting.Indented;
262 doc.WriteTo(xw);
263 xw.Flush();
264
265 return ms.ToArray();
266 }
267
268 }
269}
diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
index 433ed0b..d99b791 100644
--- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs
@@ -69,13 +69,13 @@ namespace OpenSim.Server.Handlers.Grid
69 69
70 try 70 try
71 { 71 {
72 Dictionary<string, string> request = 72 Dictionary<string, object> request =
73 ServerUtils.ParseQueryString(body); 73 ServerUtils.ParseQueryString(body);
74 74
75 if (!request.ContainsKey("METHOD")) 75 if (!request.ContainsKey("METHOD"))
76 return FailureResult(); 76 return FailureResult();
77 77
78 string method = request["METHOD"]; 78 string method = request["METHOD"].ToString();
79 79
80 switch (method) 80 switch (method)
81 { 81 {
@@ -117,22 +117,22 @@ namespace OpenSim.Server.Handlers.Grid
117 117
118 #region Method-specific handlers 118 #region Method-specific handlers
119 119
120 byte[] Register(Dictionary<string, string> request) 120 byte[] Register(Dictionary<string, object> request)
121 { 121 {
122 UUID scopeID = UUID.Zero; 122 UUID scopeID = UUID.Zero;
123 if (request.ContainsKey("SCOPEID")) 123 if (request.ContainsKey("SCOPEID"))
124 UUID.TryParse(request["SCOPEID"], out scopeID); 124 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
125 else 125 else
126 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region"); 126 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to register region");
127 127
128 int versionNumberMin = 0, versionNumberMax = 0; 128 int versionNumberMin = 0, versionNumberMax = 0;
129 if (request.ContainsKey("VERSIONMIN")) 129 if (request.ContainsKey("VERSIONMIN"))
130 Int32.TryParse(request["VERSIONMIN"], out versionNumberMin); 130 Int32.TryParse(request["VERSIONMIN"].ToString(), out versionNumberMin);
131 else 131 else
132 m_log.WarnFormat("[GRID HANDLER]: no minimum protocol version in request to register region"); 132 m_log.WarnFormat("[GRID HANDLER]: no minimum protocol version in request to register region");
133 133
134 if (request.ContainsKey("VERSIONMAX")) 134 if (request.ContainsKey("VERSIONMAX"))
135 Int32.TryParse(request["VERSIONMAX"], out versionNumberMax); 135 Int32.TryParse(request["VERSIONMAX"].ToString(), out versionNumberMax);
136 else 136 else
137 m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region"); 137 m_log.WarnFormat("[GRID HANDLER]: no maximum protocol version in request to register region");
138 138
@@ -147,8 +147,8 @@ namespace OpenSim.Server.Handlers.Grid
147 GridRegion rinfo = null; 147 GridRegion rinfo = null;
148 try 148 try
149 { 149 {
150 foreach (KeyValuePair<string, string> kvp in request) 150 foreach (KeyValuePair<string, object> kvp in request)
151 rinfoData[kvp.Key] = kvp.Value; 151 rinfoData[kvp.Key] = kvp.Value.ToString();
152 rinfo = new GridRegion(rinfoData); 152 rinfo = new GridRegion(rinfoData);
153 } 153 }
154 catch (Exception e) 154 catch (Exception e)
@@ -166,11 +166,11 @@ namespace OpenSim.Server.Handlers.Grid
166 return FailureResult(); 166 return FailureResult();
167 } 167 }
168 168
169 byte[] Deregister(Dictionary<string, string> request) 169 byte[] Deregister(Dictionary<string, object> request)
170 { 170 {
171 UUID regionID = UUID.Zero; 171 UUID regionID = UUID.Zero;
172 if (request["REGIONID"] != null) 172 if (request.ContainsKey("REGIONID"))
173 UUID.TryParse(request["REGIONID"], out regionID); 173 UUID.TryParse(request["REGIONID"].ToString(), out regionID);
174 else 174 else
175 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region"); 175 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to deregister region");
176 176
@@ -183,17 +183,17 @@ namespace OpenSim.Server.Handlers.Grid
183 183
184 } 184 }
185 185
186 byte[] GetNeighbours(Dictionary<string, string> request) 186 byte[] GetNeighbours(Dictionary<string, object> request)
187 { 187 {
188 UUID scopeID = UUID.Zero; 188 UUID scopeID = UUID.Zero;
189 if (request["SCOPEID"] != null) 189 if (request.ContainsKey("SCOPEID"))
190 UUID.TryParse(request["SCOPEID"], out scopeID); 190 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
191 else 191 else
192 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours"); 192 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
193 193
194 UUID regionID = UUID.Zero; 194 UUID regionID = UUID.Zero;
195 if (request["REGIONID"] != null) 195 if (request.ContainsKey("REGIONID"))
196 UUID.TryParse(request["REGIONID"], out regionID); 196 UUID.TryParse(request["REGIONID"].ToString(), out regionID);
197 else 197 else
198 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours"); 198 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
199 199
@@ -221,17 +221,17 @@ namespace OpenSim.Server.Handlers.Grid
221 221
222 } 222 }
223 223
224 byte[] GetRegionByUUID(Dictionary<string, string> request) 224 byte[] GetRegionByUUID(Dictionary<string, object> request)
225 { 225 {
226 UUID scopeID = UUID.Zero; 226 UUID scopeID = UUID.Zero;
227 if (request["SCOPEID"] != null) 227 if (request.ContainsKey("SCOPEID"))
228 UUID.TryParse(request["SCOPEID"], out scopeID); 228 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
229 else 229 else
230 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours"); 230 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get neighbours");
231 231
232 UUID regionID = UUID.Zero; 232 UUID regionID = UUID.Zero;
233 if (request["REGIONID"] != null) 233 if (request.ContainsKey("REGIONID"))
234 UUID.TryParse(request["REGIONID"], out regionID); 234 UUID.TryParse(request["REGIONID"].ToString(), out regionID);
235 else 235 else
236 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours"); 236 m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
237 237
@@ -250,21 +250,21 @@ namespace OpenSim.Server.Handlers.Grid
250 return encoding.GetBytes(xmlString); 250 return encoding.GetBytes(xmlString);
251 } 251 }
252 252
253 byte[] GetRegionByPosition(Dictionary<string, string> request) 253 byte[] GetRegionByPosition(Dictionary<string, object> request)
254 { 254 {
255 UUID scopeID = UUID.Zero; 255 UUID scopeID = UUID.Zero;
256 if (request["SCOPEID"] != null) 256 if (request.ContainsKey("SCOPEID"))
257 UUID.TryParse(request["SCOPEID"], out scopeID); 257 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
258 else 258 else
259 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position"); 259 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by position");
260 260
261 int x = 0, y = 0; 261 int x = 0, y = 0;
262 if (request["X"] != null) 262 if (request.ContainsKey("X"))
263 Int32.TryParse(request["X"], out x); 263 Int32.TryParse(request["X"].ToString(), out x);
264 else 264 else
265 m_log.WarnFormat("[GRID HANDLER]: no X in request to get region by position"); 265 m_log.WarnFormat("[GRID HANDLER]: no X in request to get region by position");
266 if (request["Y"] != null) 266 if (request.ContainsKey("Y"))
267 Int32.TryParse(request["Y"], out y); 267 Int32.TryParse(request["Y"].ToString(), out y);
268 else 268 else
269 m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position"); 269 m_log.WarnFormat("[GRID HANDLER]: no Y in request to get region by position");
270 270
@@ -283,17 +283,17 @@ namespace OpenSim.Server.Handlers.Grid
283 return encoding.GetBytes(xmlString); 283 return encoding.GetBytes(xmlString);
284 } 284 }
285 285
286 byte[] GetRegionByName(Dictionary<string, string> request) 286 byte[] GetRegionByName(Dictionary<string, object> request)
287 { 287 {
288 UUID scopeID = UUID.Zero; 288 UUID scopeID = UUID.Zero;
289 if (request["SCOPEID"] != null) 289 if (request.ContainsKey("SCOPEID"))
290 UUID.TryParse(request["SCOPEID"], out scopeID); 290 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
291 else 291 else
292 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by name"); 292 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region by name");
293 293
294 string regionName = string.Empty; 294 string regionName = string.Empty;
295 if (request["NAME"] != null) 295 if (request.ContainsKey("NAME"))
296 regionName = request["NAME"]; 296 regionName = request["NAME"].ToString();
297 else 297 else
298 m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name"); 298 m_log.WarnFormat("[GRID HANDLER]: no name in request to get region by name");
299 299
@@ -312,23 +312,23 @@ namespace OpenSim.Server.Handlers.Grid
312 return encoding.GetBytes(xmlString); 312 return encoding.GetBytes(xmlString);
313 } 313 }
314 314
315 byte[] GetRegionsByName(Dictionary<string, string> request) 315 byte[] GetRegionsByName(Dictionary<string, object> request)
316 { 316 {
317 UUID scopeID = UUID.Zero; 317 UUID scopeID = UUID.Zero;
318 if (request["SCOPEID"] != null) 318 if (request.ContainsKey("SCOPEID"))
319 UUID.TryParse(request["SCOPEID"], out scopeID); 319 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
320 else 320 else
321 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get regions by name"); 321 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get regions by name");
322 322
323 string regionName = string.Empty; 323 string regionName = string.Empty;
324 if (request["NAME"] != null) 324 if (request.ContainsKey("NAME"))
325 regionName = request["NAME"]; 325 regionName = request["NAME"].ToString();
326 else 326 else
327 m_log.WarnFormat("[GRID HANDLER]: no NAME in request to get regions by name"); 327 m_log.WarnFormat("[GRID HANDLER]: no NAME in request to get regions by name");
328 328
329 int max = 0; 329 int max = 0;
330 if (request["MAX"] != null) 330 if (request.ContainsKey("MAX"))
331 Int32.TryParse(request["MAX"], out max); 331 Int32.TryParse(request["MAX"].ToString(), out max);
332 else 332 else
333 m_log.WarnFormat("[GRID HANDLER]: no MAX in request to get regions by name"); 333 m_log.WarnFormat("[GRID HANDLER]: no MAX in request to get regions by name");
334 334
@@ -355,30 +355,30 @@ namespace OpenSim.Server.Handlers.Grid
355 return encoding.GetBytes(xmlString); 355 return encoding.GetBytes(xmlString);
356 } 356 }
357 357
358 byte[] GetRegionRange(Dictionary<string, string> request) 358 byte[] GetRegionRange(Dictionary<string, object> request)
359 { 359 {
360 //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange"); 360 //m_log.DebugFormat("[GRID HANDLER]: GetRegionRange");
361 UUID scopeID = UUID.Zero; 361 UUID scopeID = UUID.Zero;
362 if (request.ContainsKey("SCOPEID")) 362 if (request.ContainsKey("SCOPEID"))
363 UUID.TryParse(request["SCOPEID"], out scopeID); 363 UUID.TryParse(request["SCOPEID"].ToString(), out scopeID);
364 else 364 else
365 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range"); 365 m_log.WarnFormat("[GRID HANDLER]: no scopeID in request to get region range");
366 366
367 int xmin = 0, xmax = 0, ymin = 0, ymax = 0; 367 int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
368 if (request.ContainsKey("XMIN")) 368 if (request.ContainsKey("XMIN"))
369 Int32.TryParse(request["XMIN"], out xmin); 369 Int32.TryParse(request["XMIN"].ToString(), out xmin);
370 else 370 else
371 m_log.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range"); 371 m_log.WarnFormat("[GRID HANDLER]: no XMIN in request to get region range");
372 if (request.ContainsKey("XMAX")) 372 if (request.ContainsKey("XMAX"))
373 Int32.TryParse(request["XMAX"], out xmax); 373 Int32.TryParse(request["XMAX"].ToString(), out xmax);
374 else 374 else
375 m_log.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range"); 375 m_log.WarnFormat("[GRID HANDLER]: no XMAX in request to get region range");
376 if (request.ContainsKey("YMIN")) 376 if (request.ContainsKey("YMIN"))
377 Int32.TryParse(request["YMIN"], out ymin); 377 Int32.TryParse(request["YMIN"].ToString(), out ymin);
378 else 378 else
379 m_log.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range"); 379 m_log.WarnFormat("[GRID HANDLER]: no YMIN in request to get region range");
380 if (request.ContainsKey("YMAX")) 380 if (request.ContainsKey("YMAX"))
381 Int32.TryParse(request["YMAX"], out ymax); 381 Int32.TryParse(request["YMAX"].ToString(), out ymax);
382 else 382 else
383 m_log.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range"); 383 m_log.WarnFormat("[GRID HANDLER]: no YMAX in request to get region range");
384 384
diff --git a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
new file mode 100644
index 0000000..aaa958b
--- /dev/null
+++ b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
@@ -0,0 +1,149 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.IO;
31using System.Reflection;
32using System.Net;
33using System.Text;
34
35using OpenSim.Server.Base;
36using OpenSim.Server.Handlers.Base;
37using OpenSim.Services.Interfaces;
38using OpenSim.Framework;
39using OpenSim.Framework.Servers.HttpServer;
40
41using OpenMetaverse;
42using OpenMetaverse.StructuredData;
43using Nwc.XmlRpc;
44using Nini.Config;
45using log4net;
46
47
48namespace OpenSim.Server.Handlers.Login
49{
50 public class LLLoginHandlers
51 {
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53
54 private ILoginService m_LocalService;
55
56 public LLLoginHandlers(ILoginService service)
57 {
58 m_LocalService = service;
59 }
60
61 public XmlRpcResponse HandleXMLRPCLogin(XmlRpcRequest request, IPEndPoint remoteClient)
62 {
63 Hashtable requestData = (Hashtable)request.Params[0];
64
65 if (requestData != null)
66 {
67 if (requestData.ContainsKey("first") && requestData["first"] != null &&
68 requestData.ContainsKey("last") && requestData["last"] != null &&
69 requestData.ContainsKey("passwd") && requestData["passwd"] != null)
70 {
71 string first = requestData["first"].ToString();
72 string last = requestData["last"].ToString();
73 string passwd = requestData["passwd"].ToString();
74 string startLocation = string.Empty;
75 if (requestData.ContainsKey("start"))
76 startLocation = requestData["start"].ToString();
77
78 string clientVersion = "Unknown";
79 if (requestData.Contains("version"))
80 clientVersion = requestData["version"].ToString();
81 // We should do something interesting with the client version...
82
83 m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion);
84
85 LoginResponse reply = null;
86 reply = m_LocalService.Login(first, last, passwd, startLocation, remoteClient);
87
88 XmlRpcResponse response = new XmlRpcResponse();
89 response.Value = reply.ToHashtable();
90 return response;
91
92 }
93 }
94
95 return FailedXMLRPCResponse();
96
97 }
98
99 public OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient)
100 {
101 if (request.Type == OSDType.Map)
102 {
103 OSDMap map = (OSDMap)request;
104
105 if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd"))
106 {
107 string startLocation = string.Empty;
108
109 if (map.ContainsKey("start"))
110 startLocation = map["start"].AsString();
111
112 m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation);
113
114 LoginResponse reply = null;
115 reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, remoteClient);
116 return reply.ToOSDMap();
117
118 }
119 }
120
121 return FailedOSDResponse();
122 }
123
124 private XmlRpcResponse FailedXMLRPCResponse()
125 {
126 Hashtable hash = new Hashtable();
127 hash["reason"] = "key";
128 hash["message"] = "Incomplete login credentials. Check your username and password.";
129 hash["login"] = "false";
130
131 XmlRpcResponse response = new XmlRpcResponse();
132 response.Value = hash;
133
134 return response;
135 }
136
137 private OSD FailedOSDResponse()
138 {
139 OSDMap map = new OSDMap();
140
141 map["reason"] = OSD.FromString("key");
142 map["message"] = OSD.FromString("Invalid login credentials. Check your username and passwd.");
143 map["login"] = OSD.FromString("false");
144
145 return map;
146 }
147 }
148
149}
diff --git a/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs
new file mode 100644
index 0000000..e24055b
--- /dev/null
+++ b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs
@@ -0,0 +1,95 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using log4net;
32using Nini.Config;
33using OpenSim.Server.Base;
34using OpenSim.Services.Interfaces;
35using OpenSim.Framework;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Server.Handlers.Base;
38
39namespace OpenSim.Server.Handlers.Login
40{
41 public class LLLoginServiceInConnector : ServiceConnector
42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44
45 private ILoginService m_LoginService;
46
47 public LLLoginServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) :
48 base(config, server, String.Empty)
49 {
50 m_log.Debug("[LLLOGIN IN CONNECTOR]: Starting...");
51 string loginService = ReadLocalServiceFromConfig(config);
52
53 ISimulationService simService = scene.RequestModuleInterface<ISimulationService>();
54 ILibraryService libService = scene.RequestModuleInterface<ILibraryService>();
55
56 Object[] args = new Object[] { config, simService, libService };
57 m_LoginService = ServerUtils.LoadPlugin<ILoginService>(loginService, args);
58
59 InitializeHandlers(server);
60 }
61
62 public LLLoginServiceInConnector(IConfigSource config, IHttpServer server) :
63 base(config, server, String.Empty)
64 {
65 string loginService = ReadLocalServiceFromConfig(config);
66
67 Object[] args = new Object[] { config };
68
69 m_LoginService = ServerUtils.LoadPlugin<ILoginService>(loginService, args);
70
71 InitializeHandlers(server);
72 }
73
74 private string ReadLocalServiceFromConfig(IConfigSource config)
75 {
76 IConfig serverConfig = config.Configs["LoginService"];
77 if (serverConfig == null)
78 throw new Exception(String.Format("No section LoginService in config file"));
79
80 string loginService = serverConfig.GetString("LocalServiceModule", String.Empty);
81 if (loginService == string.Empty)
82 throw new Exception(String.Format("No LocalServiceModule for LoginService in config file"));
83
84 return loginService;
85 }
86
87 private void InitializeHandlers(IHttpServer server)
88 {
89 LLLoginHandlers loginHandlers = new LLLoginHandlers(m_LoginService);
90 server.AddXmlRPCHandler("login_to_simulator", loginHandlers.HandleXMLRPCLogin, false);
91 server.SetDefaultLLSDHandler(loginHandlers.HandleLLSDLogin);
92 }
93
94 }
95}
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
index 2558fa0..6e47b22 100644
--- a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
@@ -68,18 +68,30 @@ namespace OpenSim.Server.Handlers.Presence
68 68
69 try 69 try
70 { 70 {
71 Dictionary<string, string> request = 71 Dictionary<string, object> request =
72 ServerUtils.ParseQueryString(body); 72 ServerUtils.ParseQueryString(body);
73 73
74 if (!request.ContainsKey("METHOD")) 74 if (!request.ContainsKey("METHOD"))
75 return FailureResult(); 75 return FailureResult();
76 76
77 string method = request["METHOD"]; 77 string method = request["METHOD"].ToString();
78 78
79 switch (method) 79 switch (method)
80 { 80 {
81 case "login":
82 return LoginAgent(request);
83 case "logout":
84 return LogoutAgent(request);
85 case "logoutregion":
86 return LogoutRegionAgents(request);
81 case "report": 87 case "report":
82 return Report(request); 88 return Report(request);
89 case "getagent":
90 return GetAgent(request);
91 case "getagents":
92 return GetAgents(request);
93 case "sethome":
94 return SetHome(request);
83 } 95 }
84 m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); 96 m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method);
85 } 97 }
@@ -92,38 +104,153 @@ namespace OpenSim.Server.Handlers.Presence
92 104
93 } 105 }
94 106
95 byte[] Report(Dictionary<string, string> request) 107 byte[] LoginAgent(Dictionary<string, object> request)
96 { 108 {
97 PresenceInfo info = new PresenceInfo(); 109 string user = String.Empty;
98 info.Data = new Dictionary<string, string>(); 110 UUID session = UUID.Zero;
111 UUID ssession = UUID.Zero;
99 112
100 if (request["PrincipalID"] == null || request["RegionID"] == null) 113 if (!request.ContainsKey("UserID") || !request.ContainsKey("SessionID"))
101 return FailureResult(); 114 return FailureResult();
102 115
103 if (!UUID.TryParse(request["PrincipalID"].ToString(), 116 user = request["UserID"].ToString();
104 out info.PrincipalID)) 117
118 if (!UUID.TryParse(request["SessionID"].ToString(), out session))
105 return FailureResult(); 119 return FailureResult();
106 120
107 if (!UUID.TryParse(request["RegionID"].ToString(), 121 if (request.ContainsKey("SecureSessionID"))
108 out info.RegionID)) 122 // If it's malformed, we go on with a Zero on it
123 UUID.TryParse(request["SecureSessionID"].ToString(), out ssession);
124
125 if (m_PresenceService.LoginAgent(user, session, ssession))
126 return SuccessResult();
127
128 return FailureResult();
129 }
130
131 byte[] LogoutAgent(Dictionary<string, object> request)
132 {
133 UUID session = UUID.Zero;
134
135 if (!request.ContainsKey("SessionID"))
109 return FailureResult(); 136 return FailureResult();
110 137
111 foreach (KeyValuePair<string, string> kvp in request) 138 if (!UUID.TryParse(request["SessionID"].ToString(), out session))
112 { 139 return FailureResult();
113 if (kvp.Key == "METHOD" ||
114 kvp.Key == "PrincipalID" ||
115 kvp.Key == "RegionID")
116 continue;
117 140
118 info.Data[kvp.Key] = kvp.Value; 141 if (m_PresenceService.LogoutAgent(session))
119 } 142 return SuccessResult();
143
144 return FailureResult();
145 }
146
147 byte[] LogoutRegionAgents(Dictionary<string, object> request)
148 {
149 UUID region = UUID.Zero;
150
151 if (!request.ContainsKey("RegionID"))
152 return FailureResult();
120 153
121 if (m_PresenceService.Report(info)) 154 if (!UUID.TryParse(request["RegionID"].ToString(), out region))
155 return FailureResult();
156
157 if (m_PresenceService.LogoutRegionAgents(region))
122 return SuccessResult(); 158 return SuccessResult();
123 159
124 return FailureResult(); 160 return FailureResult();
125 } 161 }
162
163 byte[] Report(Dictionary<string, object> request)
164 {
165 UUID session = UUID.Zero;
166 UUID region = UUID.Zero;
167 Vector3 position = new Vector3(128, 128, 70);
168 Vector3 look = Vector3.Zero;
169
170 if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID"))
171 return FailureResult();
172
173 if (!UUID.TryParse(request["SessionID"].ToString(), out session))
174 return FailureResult();
175
176 if (!UUID.TryParse(request["RegionID"].ToString(), out region))
177 return FailureResult();
178
179 if (request.ContainsKey("position"))
180 Vector3.TryParse(request["position"].ToString(), out position);
181
182 if (request.ContainsKey("lookAt"))
183 Vector3.TryParse(request["lookAt"].ToString(), out look);
184
185 if (m_PresenceService.ReportAgent(session, region, position, look))
186 return SuccessResult();
187
188 return FailureResult();
189 }
190
191 byte[] GetAgent(Dictionary<string, object> request)
192 {
193 UUID session = UUID.Zero;
194
195 if (!request.ContainsKey("SessionID"))
196 return FailureResult();
126 197
198 if (!UUID.TryParse(request["SessionID"].ToString(), out session))
199 return FailureResult();
200
201 PresenceInfo pinfo = m_PresenceService.GetAgent(session);
202
203 Dictionary<string, object> result = new Dictionary<string, object>();
204 if (pinfo == null)
205 result["result"] = "null";
206 else
207 result["result"] = pinfo.ToKeyValuePairs();
208
209 string xmlString = ServerUtils.BuildXmlResponse(result);
210 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
211 UTF8Encoding encoding = new UTF8Encoding();
212 return encoding.GetBytes(xmlString);
213 }
214
215 byte[] GetAgents(Dictionary<string, object> request)
216 {
217
218 string[] userIDs;
219
220 if (!request.ContainsKey("uuids"))
221 return FailureResult();
222
223 if (!(request["uuids"] is List<string>))
224 {
225 m_log.DebugFormat("[PRESENCE HANDLER]: GetAgents input argument was of unexpected type {0}", request["uuids"].GetType().ToString());
226 return FailureResult();
227 }
228
229 userIDs = ((List<string>)request["uuids"]).ToArray();
230
231 PresenceInfo[] pinfos = m_PresenceService.GetAgents(userIDs);
232
233 Dictionary<string, object> result = new Dictionary<string, object>();
234 if ((pinfos == null) || ((pinfos != null) && (pinfos.Length == 0)))
235 result["result"] = "null";
236 else
237 {
238 int i = 0;
239 foreach (PresenceInfo pinfo in pinfos)
240 {
241 Dictionary<string, object> rinfoDict = pinfo.ToKeyValuePairs();
242 result["presence" + i] = rinfoDict;
243 i++;
244 }
245 }
246
247 string xmlString = ServerUtils.BuildXmlResponse(result);
248 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
249 UTF8Encoding encoding = new UTF8Encoding();
250 return encoding.GetBytes(xmlString);
251 }
252
253
127 private byte[] SuccessResult() 254 private byte[] SuccessResult()
128 { 255 {
129 XmlDocument doc = new XmlDocument(); 256 XmlDocument doc = new XmlDocument();
@@ -138,7 +265,7 @@ namespace OpenSim.Server.Handlers.Presence
138 265
139 doc.AppendChild(rootElement); 266 doc.AppendChild(rootElement);
140 267
141 XmlElement result = doc.CreateElement("", "Result", ""); 268 XmlElement result = doc.CreateElement("", "result", "");
142 result.AppendChild(doc.CreateTextNode("Success")); 269 result.AppendChild(doc.CreateTextNode("Success"));
143 270
144 rootElement.AppendChild(result); 271 rootElement.AppendChild(result);
@@ -160,7 +287,7 @@ namespace OpenSim.Server.Handlers.Presence
160 287
161 doc.AppendChild(rootElement); 288 doc.AppendChild(rootElement);
162 289
163 XmlElement result = doc.CreateElement("", "Result", ""); 290 XmlElement result = doc.CreateElement("", "result", "");
164 result.AppendChild(doc.CreateTextNode("Failure")); 291 result.AppendChild(doc.CreateTextNode("Failure"));
165 292
166 rootElement.AppendChild(result); 293 rootElement.AppendChild(result);
@@ -178,5 +305,32 @@ namespace OpenSim.Server.Handlers.Presence
178 305
179 return ms.ToArray(); 306 return ms.ToArray();
180 } 307 }
308
309 byte[] SetHome(Dictionary<string, object> request)
310 {
311 UUID region = UUID.Zero;
312 Vector3 position = new Vector3(128, 128, 70);
313 Vector3 look = Vector3.Zero;
314
315 if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID"))
316 return FailureResult();
317
318 string user = request["UserID"].ToString();
319
320 if (!UUID.TryParse(request["RegionID"].ToString(), out region))
321 return FailureResult();
322
323 if (request.ContainsKey("position"))
324 Vector3.TryParse(request["position"].ToString(), out position);
325
326 if (request.ContainsKey("lookAt"))
327 Vector3.TryParse(request["lookAt"].ToString(), out look);
328
329 if (m_PresenceService.SetHomeLocation(user, region, position, look))
330 return SuccessResult();
331
332 return FailureResult();
333 }
334
181 } 335 }
182} 336}
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
index 3da72c7..ccb4c70 100644
--- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections;
29using System.IO; 30using System.IO;
30using System.Reflection; 31using System.Reflection;
31using System.Net; 32using System.Net;
@@ -34,6 +35,7 @@ using System.Text;
34using OpenSim.Server.Base; 35using OpenSim.Server.Base;
35using OpenSim.Server.Handlers.Base; 36using OpenSim.Server.Handlers.Base;
36using OpenSim.Services.Interfaces; 37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
37using OpenSim.Framework; 39using OpenSim.Framework;
38using OpenSim.Framework.Servers.HttpServer; 40using OpenSim.Framework.Servers.HttpServer;
39 41
@@ -45,93 +47,111 @@ using log4net;
45 47
46namespace OpenSim.Server.Handlers.Simulation 48namespace OpenSim.Server.Handlers.Simulation
47{ 49{
48 public class AgentGetHandler : BaseStreamHandler 50 public class AgentHandler
49 { 51 {
50 // TODO: unused: private ISimulationService m_SimulationService; 52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 // TODO: unused: private IAuthenticationService m_AuthenticationService; 53 private ISimulationService m_SimulationService;
52 54
53 public AgentGetHandler(ISimulationService service, IAuthenticationService authentication) : 55 public AgentHandler(ISimulationService sim)
54 base("GET", "/agent")
55 { 56 {
56 // TODO: unused: m_SimulationService = service; 57 m_SimulationService = sim;
57 // TODO: unused: m_AuthenticationService = authentication;
58 } 58 }
59 59
60 public override byte[] Handle(string path, Stream request, 60 public Hashtable Handler(Hashtable request)
61 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
62 { 61 {
63 // Not implemented yet 62 //m_log.Debug("[CONNECTION DEBUGGING]: AgentHandler Called");
64 httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
65 return new byte[] { };
66 }
67 }
68 63
69 public class AgentPostHandler : BaseStreamHandler 64 m_log.Debug("---------------------------");
70 { 65 m_log.Debug(" >> uri=" + request["uri"]);
71 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 66 m_log.Debug(" >> content-type=" + request["content-type"]);
72 private ISimulationService m_SimulationService; 67 m_log.Debug(" >> http-method=" + request["http-method"]);
73 private IAuthenticationService m_AuthenticationService; 68 m_log.Debug("---------------------------\n");
74 // TODO: unused: private bool m_AllowForeignGuests;
75 69
76 public AgentPostHandler(ISimulationService service, IAuthenticationService authentication, bool foreignGuests) : 70 Hashtable responsedata = new Hashtable();
77 base("POST", "/agent") 71 responsedata["content_type"] = "text/html";
78 { 72 responsedata["keepalive"] = false;
79 m_SimulationService = service;
80 m_AuthenticationService = authentication;
81 // TODO: unused: m_AllowForeignGuests = foreignGuests;
82 }
83 73
84 public override byte[] Handle(string path, Stream request,
85 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
86 {
87 byte[] result = new byte[0];
88 74
89 UUID agentID; 75 UUID agentID;
76 UUID regionID;
90 string action; 77 string action;
91 ulong regionHandle; 78 if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action))
92 if (!RestHandlerUtils.GetParams(path, out agentID, out regionHandle, out action))
93 { 79 {
94 m_log.InfoFormat("[AgentPostHandler]: Invalid parameters for agent message {0}", path); 80 m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]);
95 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; 81 responsedata["int_response_code"] = 404;
96 httpResponse.StatusDescription = "Invalid parameters for agent message " + path; 82 responsedata["str_response_string"] = "false";
97 83
98 return result; 84 return responsedata;
99 } 85 }
100 86
101 if (m_AuthenticationService != null) 87 // Next, let's parse the verb
88 string method = (string)request["http-method"];
89 if (method.Equals("PUT"))
102 { 90 {
103 // Authentication 91 DoAgentPut(request, responsedata);
104 string authority = string.Empty; 92 return responsedata;
105 string authToken = string.Empty; 93 }
106 if (!RestHandlerUtils.GetAuthentication(httpRequest, out authority, out authToken)) 94 else if (method.Equals("POST"))
107 { 95 {
108 m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path); 96 DoAgentPost(request, responsedata, agentID);
109 httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized; 97 return responsedata;
110 return result; 98 }
111 } 99 else if (method.Equals("GET"))
112 // TODO: Rethink this 100 {
113 //if (!m_AuthenticationService.VerifyKey(agentID, authToken)) 101 DoAgentGet(request, responsedata, agentID, regionID);
114 //{ 102 return responsedata;
115 // m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path); 103 }
116 // httpResponse.StatusCode = (int)HttpStatusCode.Forbidden; 104 else if (method.Equals("DELETE"))
117 // return result; 105 {
118 //} 106 DoAgentDelete(request, responsedata, agentID, action, regionID);
119 m_log.DebugFormat("[AgentPostHandler]: Authentication succeeded for {0}", agentID); 107 return responsedata;
120 } 108 }
109 else
110 {
111 m_log.InfoFormat("[AGENT HANDLER]: method {0} not supported in agent message", method);
112 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
113 responsedata["str_response_string"] = "Method not allowed";
114
115 return responsedata;
116 }
117
118 }
121 119
122 OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength); 120 protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
121 {
122 OSDMap args = Utils.GetOSDMap((string)request["body"]);
123 if (args == null) 123 if (args == null)
124 { 124 {
125 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; 125 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
126 httpResponse.StatusDescription = "Unable to retrieve data"; 126 responsedata["str_response_string"] = "Bad request";
127 m_log.DebugFormat("[AgentPostHandler]: Unable to retrieve data for post {0}", path); 127 return;
128 return result;
129 } 128 }
130 129
131 // retrieve the regionhandle 130 // retrieve the input arguments
132 ulong regionhandle = 0; 131 int x = 0, y = 0;
133 if (args["destination_handle"] != null) 132 UUID uuid = UUID.Zero;
134 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); 133 string regionname = string.Empty;
134 uint teleportFlags = 0;
135 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
136 Int32.TryParse(args["destination_x"].AsString(), out x);
137 else
138 m_log.WarnFormat(" -- request didn't have destination_x");
139 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
140 Int32.TryParse(args["destination_y"].AsString(), out y);
141 else
142 m_log.WarnFormat(" -- request didn't have destination_y");
143 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
144 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
145 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
146 regionname = args["destination_name"].ToString();
147 if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
148 teleportFlags = args["teleport_flags"].AsUInteger();
149
150 GridRegion destination = new GridRegion();
151 destination.RegionID = uuid;
152 destination.RegionLocX = x;
153 destination.RegionLocY = y;
154 destination.RegionName = regionname;
135 155
136 AgentCircuitData aCircuit = new AgentCircuitData(); 156 AgentCircuitData aCircuit = new AgentCircuitData();
137 try 157 try
@@ -140,70 +160,168 @@ namespace OpenSim.Server.Handlers.Simulation
140 } 160 }
141 catch (Exception ex) 161 catch (Exception ex)
142 { 162 {
143 m_log.InfoFormat("[AgentPostHandler]: exception on unpacking CreateAgent message {0}", ex.Message); 163 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
144 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; 164 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
145 httpResponse.StatusDescription = "Problems with data deserialization"; 165 responsedata["str_response_string"] = "Bad request";
146 return result; 166 return;
147 } 167 }
148 168
149 string reason = string.Empty; 169 OSDMap resp = new OSDMap(2);
170 string reason = String.Empty;
150 171
151 // We need to clean up a few things in the user service before I can do this 172 // This is the meaning of POST agent
152 //if (m_AllowForeignGuests) 173 //m_regionClient.AdjustUserInformation(aCircuit);
153 // m_regionClient.AdjustUserInformation(aCircuit); 174 bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
154 175
155 // Finally! 176 resp["reason"] = OSD.FromString(reason);
156 bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, out reason); 177 resp["success"] = OSD.FromBoolean(result);
157 178
158 OSDMap resp = new OSDMap(1); 179 // TODO: add reason if not String.Empty?
180 responsedata["int_response_code"] = HttpStatusCode.OK;
181 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
182 }
159 183
160 resp["success"] = OSD.FromBoolean(success); 184 protected virtual void DoAgentPut(Hashtable request, Hashtable responsedata)
185 {
186 OSDMap args = Utils.GetOSDMap((string)request["body"]);
187 if (args == null)
188 {
189 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
190 responsedata["str_response_string"] = "Bad request";
191 return;
192 }
161 193
162 httpResponse.StatusCode = (int)HttpStatusCode.OK; 194 // retrieve the input arguments
195 int x = 0, y = 0;
196 UUID uuid = UUID.Zero;
197 string regionname = string.Empty;
198 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
199 Int32.TryParse(args["destination_x"].AsString(), out x);
200 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
201 Int32.TryParse(args["destination_y"].AsString(), out y);
202 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
203 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
204 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
205 regionname = args["destination_name"].ToString();
163 206
164 return Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp)); 207 GridRegion destination = new GridRegion();
165 } 208 destination.RegionID = uuid;
166 } 209 destination.RegionLocX = x;
210 destination.RegionLocY = y;
211 destination.RegionName = regionname;
167 212
168 public class AgentPutHandler : BaseStreamHandler 213 string messageType;
169 { 214 if (args["message_type"] != null)
170 // TODO: unused: private ISimulationService m_SimulationService; 215 messageType = args["message_type"].AsString();
171 // TODO: unused: private IAuthenticationService m_AuthenticationService; 216 else
217 {
218 m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. ");
219 messageType = "AgentData";
220 }
172 221
173 public AgentPutHandler(ISimulationService service, IAuthenticationService authentication) : 222 bool result = true;
174 base("PUT", "/agent") 223 if ("AgentData".Equals(messageType))
175 { 224 {
176 // TODO: unused: m_SimulationService = service; 225 AgentData agent = new AgentData();
177 // TODO: unused: m_AuthenticationService = authentication; 226 try
227 {
228 agent.Unpack(args);
229 }
230 catch (Exception ex)
231 {
232 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
233 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
234 responsedata["str_response_string"] = "Bad request";
235 return;
236 }
237
238 //agent.Dump();
239 // This is one of the meanings of PUT agent
240 result = m_SimulationService.UpdateAgent(destination, agent);
241
242 }
243 else if ("AgentPosition".Equals(messageType))
244 {
245 AgentPosition agent = new AgentPosition();
246 try
247 {
248 agent.Unpack(args);
249 }
250 catch (Exception ex)
251 {
252 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
253 return;
254 }
255 //agent.Dump();
256 // This is one of the meanings of PUT agent
257 result = m_SimulationService.UpdateAgent(destination, agent);
258
259 }
260
261 responsedata["int_response_code"] = HttpStatusCode.OK;
262 responsedata["str_response_string"] = result.ToString();
263 //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead
178 } 264 }
179 265
180 public override byte[] Handle(string path, Stream request, 266 protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, UUID regionID)
181 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
182 { 267 {
183 // Not implemented yet 268 GridRegion destination = new GridRegion();
184 httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; 269 destination.RegionID = regionID;
185 return new byte[] { };
186 }
187 }
188 270
189 public class AgentDeleteHandler : BaseStreamHandler 271 IAgentData agent = null;
190 { 272 bool result = m_SimulationService.RetrieveAgent(destination, id, out agent);
191 // TODO: unused: private ISimulationService m_SimulationService; 273 OSDMap map = null;
192 // TODO: unused: private IAuthenticationService m_AuthenticationService; 274 if (result)
275 {
276 if (agent != null) // just to make sure
277 {
278 map = agent.Pack();
279 string strBuffer = "";
280 try
281 {
282 strBuffer = OSDParser.SerializeJsonString(map);
283 }
284 catch (Exception e)
285 {
286 m_log.WarnFormat("[AGENT HANDLER]: Exception thrown on serialization of DoAgentGet: {0}", e.Message);
287 responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
288 // ignore. buffer will be empty, caller should check.
289 }
193 290
194 public AgentDeleteHandler(ISimulationService service, IAuthenticationService authentication) : 291 responsedata["content_type"] = "application/json";
195 base("DELETE", "/agent") 292 responsedata["int_response_code"] = HttpStatusCode.OK;
196 { 293 responsedata["str_response_string"] = strBuffer;
197 // TODO: unused: m_SimulationService = service; 294 }
198 // TODO: unused: m_AuthenticationService = authentication; 295 else
296 {
297 responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
298 responsedata["str_response_string"] = "Internal error";
299 }
300 }
301 else
302 {
303 responsedata["int_response_code"] = HttpStatusCode.NotFound;
304 responsedata["str_response_string"] = "Not Found";
305 }
199 } 306 }
200 307
201 public override byte[] Handle(string path, Stream request, 308 protected virtual void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID)
202 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
203 { 309 {
204 // Not implemented yet 310 //m_log.Debug(" >>> DoDelete action:" + action + "; regionHandle:" + regionHandle);
205 httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented; 311
206 return new byte[] { }; 312 GridRegion destination = new GridRegion();
313 destination.RegionID = regionID;
314
315 if (action.Equals("release"))
316 m_SimulationService.ReleaseAgent(destination, id, "");
317 else
318 m_SimulationService.CloseAgent(destination, id);
319
320 responsedata["int_response_code"] = HttpStatusCode.OK;
321 responsedata["str_response_string"] = "OpenSim agent " + id.ToString();
322
323 m_log.Debug("[AGENT HANDLER]: Agent Deleted.");
207 } 324 }
208 } 325 }
326
209} 327}
diff --git a/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs
new file mode 100644
index 0000000..995a3c4
--- /dev/null
+++ b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs
@@ -0,0 +1,229 @@
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.Collections;
30using System.IO;
31using System.Reflection;
32using System.Net;
33using System.Text;
34
35using OpenSim.Server.Base;
36using OpenSim.Server.Handlers.Base;
37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenSim.Framework;
40using OpenSim.Framework.Servers.HttpServer;
41
42using OpenMetaverse;
43using OpenMetaverse.StructuredData;
44using Nini.Config;
45using log4net;
46
47
48namespace OpenSim.Server.Handlers.Simulation
49{
50 public class ObjectHandler
51 {
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 private ISimulationService m_SimulationService;
54
55 public ObjectHandler(ISimulationService sim)
56 {
57 m_SimulationService = sim;
58 }
59
60 public Hashtable Handler(Hashtable request)
61 {
62 m_log.Debug("[CONNECTION DEBUGGING]: ObjectHandler Called");
63
64 m_log.Debug("---------------------------");
65 m_log.Debug(" >> uri=" + request["uri"]);
66 m_log.Debug(" >> content-type=" + request["content-type"]);
67 m_log.Debug(" >> http-method=" + request["http-method"]);
68 m_log.Debug("---------------------------\n");
69
70 Hashtable responsedata = new Hashtable();
71 responsedata["content_type"] = "text/html";
72
73 UUID objectID;
74 UUID regionID;
75 string action;
76 if (!Utils.GetParams((string)request["uri"], out objectID, out regionID, out action))
77 {
78 m_log.InfoFormat("[REST COMMS]: Invalid parameters for object message {0}", request["uri"]);
79 responsedata["int_response_code"] = 404;
80 responsedata["str_response_string"] = "false";
81
82 return responsedata;
83 }
84
85 // Next, let's parse the verb
86 string method = (string)request["http-method"];
87 if (method.Equals("POST"))
88 {
89 DoObjectPost(request, responsedata, regionID);
90 return responsedata;
91 }
92 else if (method.Equals("PUT"))
93 {
94 DoObjectPut(request, responsedata, regionID);
95 return responsedata;
96 }
97 //else if (method.Equals("DELETE"))
98 //{
99 // DoObjectDelete(request, responsedata, agentID, action, regionHandle);
100 // return responsedata;
101 //}
102 else
103 {
104 m_log.InfoFormat("[REST COMMS]: method {0} not supported in object message", method);
105 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
106 responsedata["str_response_string"] = "Mthod not allowed";
107
108 return responsedata;
109 }
110
111 }
112
113 protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, UUID regionID)
114 {
115 OSDMap args = Utils.GetOSDMap((string)request["body"]);
116 if (args == null)
117 {
118 responsedata["int_response_code"] = 400;
119 responsedata["str_response_string"] = "false";
120 return;
121 }
122 // retrieve the input arguments
123 int x = 0, y = 0;
124 UUID uuid = UUID.Zero;
125 string regionname = string.Empty;
126 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
127 Int32.TryParse(args["destination_x"].AsString(), out x);
128 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
129 Int32.TryParse(args["destination_y"].AsString(), out y);
130 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
131 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
132 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
133 regionname = args["destination_name"].ToString();
134
135 GridRegion destination = new GridRegion();
136 destination.RegionID = uuid;
137 destination.RegionLocX = x;
138 destination.RegionLocY = y;
139 destination.RegionName = regionname;
140
141 string sogXmlStr = "", extraStr = "", stateXmlStr = "";
142 if (args.ContainsKey("sog") && args["sog"] != null)
143 sogXmlStr = args["sog"].AsString();
144 if (args.ContainsKey("extra") && args["extra"] != null)
145 extraStr = args["extra"].AsString();
146
147 IScene s = m_SimulationService.GetScene(destination.RegionHandle);
148 ISceneObject sog = null;
149 try
150 {
151 //sog = SceneObjectSerializer.FromXml2Format(sogXmlStr);
152 sog = s.DeserializeObject(sogXmlStr);
153 sog.ExtraFromXmlString(extraStr);
154 }
155 catch (Exception ex)
156 {
157 m_log.InfoFormat("[REST COMMS]: exception on deserializing scene object {0}", ex.Message);
158 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
159 responsedata["str_response_string"] = "Bad request";
160 return;
161 }
162
163 if ((args["state"] != null) && s.AllowScriptCrossings)
164 {
165 stateXmlStr = args["state"].AsString();
166 if (stateXmlStr != "")
167 {
168 try
169 {
170 sog.SetState(stateXmlStr, s);
171 }
172 catch (Exception ex)
173 {
174 m_log.InfoFormat("[REST COMMS]: exception on setting state for scene object {0}", ex.Message);
175 // ignore and continue
176 }
177 }
178 }
179 // This is the meaning of POST object
180 bool result = m_SimulationService.CreateObject(destination, sog, false);
181
182 responsedata["int_response_code"] = HttpStatusCode.OK;
183 responsedata["str_response_string"] = result.ToString();
184 }
185
186 protected virtual void DoObjectPut(Hashtable request, Hashtable responsedata, UUID regionID)
187 {
188 OSDMap args = Utils.GetOSDMap((string)request["body"]);
189 if (args == null)
190 {
191 responsedata["int_response_code"] = 400;
192 responsedata["str_response_string"] = "false";
193 return;
194 }
195
196 // retrieve the input arguments
197 int x = 0, y = 0;
198 UUID uuid = UUID.Zero;
199 string regionname = string.Empty;
200 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
201 Int32.TryParse(args["destination_x"].AsString(), out x);
202 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
203 Int32.TryParse(args["destination_y"].AsString(), out y);
204 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
205 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
206 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
207 regionname = args["destination_name"].ToString();
208
209 GridRegion destination = new GridRegion();
210 destination.RegionID = uuid;
211 destination.RegionLocX = x;
212 destination.RegionLocY = y;
213 destination.RegionName = regionname;
214
215 UUID userID = UUID.Zero, itemID = UUID.Zero;
216 if (args.ContainsKey("userid") && args["userid"] != null)
217 userID = args["userid"].AsUUID();
218 if (args.ContainsKey("itemid") && args["itemid"] != null)
219 itemID = args["itemid"].AsUUID();
220
221 // This is the meaning of PUT object
222 bool result = m_SimulationService.CreateObject(destination, userID, itemID);
223
224 responsedata["int_response_code"] = 200;
225 responsedata["str_response_string"] = result.ToString();
226 }
227
228 }
229} \ No newline at end of file
diff --git a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
index fe93fa5..55a575c 100644
--- a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
+++ b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
@@ -37,22 +37,15 @@ namespace OpenSim.Server.Handlers.Simulation
37{ 37{
38 public class SimulationServiceInConnector : ServiceConnector 38 public class SimulationServiceInConnector : ServiceConnector
39 { 39 {
40 private ISimulationService m_SimulationService; 40 private ISimulationService m_LocalSimulationService;
41 private IAuthenticationService m_AuthenticationService; 41 private IAuthenticationService m_AuthenticationService;
42 42
43 public SimulationServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) : 43 public SimulationServiceInConnector(IConfigSource config, IHttpServer server, IScene scene) :
44 base(config, server, String.Empty) 44 base(config, server, String.Empty)
45 { 45 {
46 IConfig serverConfig = config.Configs["SimulationService"]; 46 //IConfig serverConfig = config.Configs["SimulationService"];
47 if (serverConfig == null) 47 //if (serverConfig == null)
48 throw new Exception("No section 'SimulationService' in config file"); 48 // throw new Exception("No section 'SimulationService' in config file");
49
50 bool authentication = serverConfig.GetBoolean("RequireAuthentication", false);
51
52 if (authentication)
53 m_AuthenticationService = scene.RequestModuleInterface<IAuthenticationService>();
54
55 bool foreignGuests = serverConfig.GetBoolean("AllowForeignGuests", false);
56 49
57 //string simService = serverConfig.GetString("LocalServiceModule", 50 //string simService = serverConfig.GetString("LocalServiceModule",
58 // String.Empty); 51 // String.Empty);
@@ -61,20 +54,18 @@ namespace OpenSim.Server.Handlers.Simulation
61 // throw new Exception("No SimulationService in config file"); 54 // throw new Exception("No SimulationService in config file");
62 55
63 //Object[] args = new Object[] { config }; 56 //Object[] args = new Object[] { config };
64 m_SimulationService = scene.RequestModuleInterface<ISimulationService>(); 57 m_LocalSimulationService = scene.RequestModuleInterface<ISimulationService>();
65 //ServerUtils.LoadPlugin<ISimulationService>(simService, args); 58 //ServerUtils.LoadPlugin<ISimulationService>(simService, args);
66 if (m_SimulationService == null)
67 throw new Exception("No Local ISimulationService Module");
68
69
70 59
71 //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no")); 60 //System.Console.WriteLine("XXXXXXXXXXXXXXXXXXX m_AssetSetvice == null? " + ((m_AssetService == null) ? "yes" : "no"));
72 server.AddStreamHandler(new AgentGetHandler(m_SimulationService, m_AuthenticationService)); 61 //server.AddStreamHandler(new AgentGetHandler(m_SimulationService, m_AuthenticationService));
73 server.AddStreamHandler(new AgentPostHandler(m_SimulationService, m_AuthenticationService, foreignGuests)); 62 //server.AddStreamHandler(new AgentPostHandler(m_SimulationService, m_AuthenticationService));
74 server.AddStreamHandler(new AgentPutHandler(m_SimulationService, m_AuthenticationService)); 63 //server.AddStreamHandler(new AgentPutHandler(m_SimulationService, m_AuthenticationService));
75 server.AddStreamHandler(new AgentDeleteHandler(m_SimulationService, m_AuthenticationService)); 64 //server.AddStreamHandler(new AgentDeleteHandler(m_SimulationService, m_AuthenticationService));
65 server.AddHTTPHandler("/agent/", new AgentHandler(m_LocalSimulationService).Handler);
66 server.AddHTTPHandler("/object/", new ObjectHandler(m_LocalSimulationService).Handler);
67
76 //server.AddStreamHandler(new ObjectPostHandler(m_SimulationService, authentication)); 68 //server.AddStreamHandler(new ObjectPostHandler(m_SimulationService, authentication));
77 //server.AddStreamHandler(new NeighborPostHandler(m_SimulationService, authentication));
78 } 69 }
79 } 70 }
80} 71}
diff --git a/OpenSim/Server/Handlers/Simulation/Utils.cs b/OpenSim/Server/Handlers/Simulation/Utils.cs
new file mode 100644
index 0000000..ed379da
--- /dev/null
+++ b/OpenSim/Server/Handlers/Simulation/Utils.cs
@@ -0,0 +1,103 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31
32using OpenMetaverse;
33using OpenMetaverse.StructuredData;
34
35using log4net;
36
37namespace OpenSim.Server.Handlers.Simulation
38{
39 public class Utils
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 /// <summary>
44 /// Extract the param from an uri.
45 /// </summary>
46 /// <param name="uri">Something like this: /agent/uuid/ or /agent/uuid/handle/release</param>
47 /// <param name="uri">uuid on uuid field</param>
48 /// <param name="action">optional action</param>
49 public static bool GetParams(string uri, out UUID uuid, out UUID regionID, out string action)
50 {
51 uuid = UUID.Zero;
52 regionID = UUID.Zero;
53 action = "";
54
55 uri = uri.Trim(new char[] { '/' });
56 string[] parts = uri.Split('/');
57 if (parts.Length <= 1)
58 {
59 return false;
60 }
61 else
62 {
63 if (!UUID.TryParse(parts[1], out uuid))
64 return false;
65
66 if (parts.Length >= 3)
67 UUID.TryParse(parts[2], out regionID);
68 if (parts.Length >= 4)
69 action = parts[3];
70
71 return true;
72 }
73 }
74
75 public static OSDMap GetOSDMap(string data)
76 {
77 OSDMap args = null;
78 try
79 {
80 OSD buffer;
81 // We should pay attention to the content-type, but let's assume we know it's Json
82 buffer = OSDParser.DeserializeJson(data);
83 if (buffer.Type == OSDType.Map)
84 {
85 args = (OSDMap)buffer;
86 return args;
87 }
88 else
89 {
90 // uh?
91 m_log.Debug(("[REST COMMS]: Got OSD of unexpected type " + buffer.Type.ToString()));
92 return null;
93 }
94 }
95 catch (Exception ex)
96 {
97 m_log.Debug("[REST COMMS]: exception on parse of REST message " + ex.Message);
98 return null;
99 }
100 }
101
102 }
103}
diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs
new file mode 100644
index 0000000..f17a8de
--- /dev/null
+++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs
@@ -0,0 +1,61 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base;
34
35namespace OpenSim.Server.Handlers.UserAccounts
36{
37 public class UserAccountServiceConnector : ServiceConnector
38 {
39 private IUserAccountService m_UserAccountService;
40 private string m_ConfigName = "UserAccountService";
41
42 public UserAccountServiceConnector(IConfigSource config, IHttpServer server, string configName) :
43 base(config, server, configName)
44 {
45 IConfig serverConfig = config.Configs[m_ConfigName];
46 if (serverConfig == null)
47 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
48
49 string service = serverConfig.GetString("LocalServiceModule",
50 String.Empty);
51
52 if (service == String.Empty)
53 throw new Exception("No LocalServiceModule in config file");
54
55 Object[] args = new Object[] { config };
56 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(service, args);
57
58 server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService));
59 }
60 }
61}
diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs
new file mode 100644
index 0000000..b54b63e
--- /dev/null
+++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs
@@ -0,0 +1,257 @@
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.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.UserAccounts
46{
47 public class UserAccountServerPostHandler : BaseStreamHandler
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IUserAccountService m_UserAccountService;
52
53 public UserAccountServerPostHandler(IUserAccountService service) :
54 base("POST", "/accounts")
55 {
56 m_UserAccountService = service;
57 }
58
59 public override byte[] Handle(string path, Stream requestData,
60 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
61 {
62 StreamReader sr = new StreamReader(requestData);
63 string body = sr.ReadToEnd();
64 sr.Close();
65 body = body.Trim();
66
67 // We need to check the authorization header
68 //httpRequest.Headers["authorization"] ...
69
70 //m_log.DebugFormat("[XXX]: query String: {0}", body);
71
72 try
73 {
74 Dictionary<string, object> request =
75 ServerUtils.ParseQueryString(body);
76
77 if (!request.ContainsKey("METHOD"))
78 return FailureResult();
79
80 string method = request["METHOD"].ToString();
81
82 switch (method)
83 {
84 case "getaccount":
85 return GetAccount(request);
86 case "getaccounts":
87 return GetAccounts(request);
88 case "setaccount":
89 return StoreAccount(request);
90 }
91 m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method);
92 }
93 catch (Exception e)
94 {
95 m_log.Debug("[PRESENCE HANDLER]: Exception {0}" + e);
96 }
97
98 return FailureResult();
99
100 }
101
102 byte[] GetAccount(Dictionary<string, object> request)
103 {
104 UserAccount account = null;
105 UUID scopeID = UUID.Zero;
106 Dictionary<string, object> result = new Dictionary<string, object>();
107
108 if (!request.ContainsKey("ScopeID"))
109 {
110 result["result"] = "null";
111 return ResultToBytes(result);
112 }
113
114 if (!UUID.TryParse(request["ScopeID"].ToString(), out scopeID))
115 {
116 result["result"] = "null";
117 return ResultToBytes(result);
118 }
119
120 if (request.ContainsKey("UserID") && request["UserID"] != null)
121 {
122 UUID userID;
123 if (UUID.TryParse(request["UserID"].ToString(), out userID))
124 account = m_UserAccountService.GetUserAccount(scopeID, userID);
125 }
126
127 else if (request.ContainsKey("Email") && request["Email"] != null)
128 account = m_UserAccountService.GetUserAccount(scopeID, request["Email"].ToString());
129
130 else if (request.ContainsKey("FirstName") && request.ContainsKey("LastName") &&
131 request["FirstName"] != null && request["LastName"] != null)
132 account = m_UserAccountService.GetUserAccount(scopeID, request["FirstName"].ToString(), request["LastName"].ToString());
133
134 if (account == null)
135 result["result"] = "null";
136 else
137 result["result"] = account.ToKeyValuePairs();
138
139 return ResultToBytes(result);
140 }
141
142 byte[] GetAccounts(Dictionary<string, object> request)
143 {
144 if (!request.ContainsKey("ScopeID") || !request.ContainsKey("query"))
145 return FailureResult();
146
147 UUID scopeID = UUID.Zero;
148 if (!UUID.TryParse(request["ScopeID"].ToString(), out scopeID))
149 return FailureResult();
150
151 string query = request["query"].ToString();
152
153 List<UserAccount> accounts = m_UserAccountService.GetUserAccounts(scopeID, query);
154
155 Dictionary<string, object> result = new Dictionary<string, object>();
156 if ((accounts == null) || ((accounts != null) && (accounts.Count == 0)))
157 result["result"] = "null";
158 else
159 {
160 int i = 0;
161 foreach (UserAccount acc in accounts)
162 {
163 Dictionary<string, object> rinfoDict = acc.ToKeyValuePairs();
164 result["account" + i] = rinfoDict;
165 i++;
166 }
167 }
168
169 string xmlString = ServerUtils.BuildXmlResponse(result);
170 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
171 UTF8Encoding encoding = new UTF8Encoding();
172 return encoding.GetBytes(xmlString);
173 }
174
175 byte[] StoreAccount(Dictionary<string, object> request)
176 {
177 //if (!request.ContainsKey("account"))
178 // return FailureResult();
179 //if (request["account"] == null)
180 // return FailureResult();
181 //if (!(request["account"] is Dictionary<string, object>))
182 // return FailureResult();
183
184 UserAccount account = new UserAccount(request);
185
186 if (m_UserAccountService.StoreUserAccount(account))
187 return SuccessResult();
188
189 return FailureResult();
190 }
191
192 private byte[] SuccessResult()
193 {
194 XmlDocument doc = new XmlDocument();
195
196 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
197 "", "");
198
199 doc.AppendChild(xmlnode);
200
201 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
202 "");
203
204 doc.AppendChild(rootElement);
205
206 XmlElement result = doc.CreateElement("", "result", "");
207 result.AppendChild(doc.CreateTextNode("Success"));
208
209 rootElement.AppendChild(result);
210
211 return DocToBytes(doc);
212 }
213
214 private byte[] FailureResult()
215 {
216 XmlDocument doc = new XmlDocument();
217
218 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
219 "", "");
220
221 doc.AppendChild(xmlnode);
222
223 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
224 "");
225
226 doc.AppendChild(rootElement);
227
228 XmlElement result = doc.CreateElement("", "result", "");
229 result.AppendChild(doc.CreateTextNode("Failure"));
230
231 rootElement.AppendChild(result);
232
233 return DocToBytes(doc);
234 }
235
236 private byte[] DocToBytes(XmlDocument doc)
237 {
238 MemoryStream ms = new MemoryStream();
239 XmlTextWriter xw = new XmlTextWriter(ms, null);
240 xw.Formatting = Formatting.Indented;
241 doc.WriteTo(xw);
242 xw.Flush();
243
244 return ms.ToArray();
245 }
246
247 private byte[] ResultToBytes(Dictionary<string, object> result)
248 {
249 string xmlString = ServerUtils.BuildXmlResponse(result);
250 //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
251 UTF8Encoding encoding = new UTF8Encoding();
252 return encoding.GetBytes(xmlString);
253 }
254
255
256 }
257}