aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server')
-rw-r--r--OpenSim/Server/Base/ServerUtils.cs71
-rw-r--r--OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs14
-rw-r--r--OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs92
-rw-r--r--OpenSim/Server/Handlers/Login/LLLoginHandlers.cs139
-rw-r--r--OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs93
-rw-r--r--OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs196
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs244
-rw-r--r--OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs191
-rw-r--r--OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs27
-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
12 files changed, 1381 insertions, 107 deletions
diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs
index 0964caa..a5d28a4 100644
--- a/OpenSim/Server/Base/ServerUtils.cs
+++ b/OpenSim/Server/Base/ServerUtils.cs
@@ -160,9 +160,9 @@ namespace OpenSim.Server.Base
160 } 160 }
161 } 161 }
162 162
163 public static Dictionary<string, string> ParseQueryString(string query) 163 public static Dictionary<string, object> ParseQueryString(string query)
164 { 164 {
165 Dictionary<string, string> result = new Dictionary<string, string>(); 165 Dictionary<string, object> result = new Dictionary<string, object>();
166 string[] terms = query.Split(new char[] {'&'}); 166 string[] terms = query.Split(new char[] {'&'});
167 167
168 if (terms.Length == 0) 168 if (terms.Length == 0)
@@ -180,33 +180,76 @@ namespace OpenSim.Server.Base
180 if (elems.Length > 1) 180 if (elems.Length > 1)
181 value = System.Web.HttpUtility.UrlDecode(elems[1]); 181 value = System.Web.HttpUtility.UrlDecode(elems[1]);
182 182
183 result[name] = value; 183 if (name.EndsWith("[]"))
184 {
185 if (result.ContainsKey(name))
186 {
187 if (!(result[name] is List<string>))
188 continue;
189
190 List<string> l = (List<string>)result[name];
191
192 l.Add(value);
193 }
194 else
195 {
196 List<string> newList = new List<string>();
197
198 newList.Add(value);
199
200 result[name] = newList;
201 }
202 }
203 else
204 {
205 if (!result.ContainsKey(name))
206 result[name] = value;
207 }
184 } 208 }
185 209
186 return result; 210 return result;
187 } 211 }
188 212
189 public static string BuildQueryString(Dictionary<string, string> data) 213 public static string BuildQueryString(Dictionary<string, object> data)
190 { 214 {
191 string qstring = String.Empty; 215 string qstring = String.Empty;
192 216
193 foreach (KeyValuePair<string, string> kvp in data) 217 string part;
218
219 foreach (KeyValuePair<string, object> kvp in data)
194 { 220 {
195 string part; 221 if (kvp.Value is List<string>)
196 if (kvp.Value != String.Empty)
197 { 222 {
198 part = System.Web.HttpUtility.UrlEncode(kvp.Key) + 223 List<string> l = (List<String>)kvp.Value;
199 "=" + System.Web.HttpUtility.UrlEncode(kvp.Value); 224
225 foreach (string s in l)
226 {
227 part = System.Web.HttpUtility.UrlEncode(kvp.Key) +
228 "[]=" + System.Web.HttpUtility.UrlEncode(s);
229
230 if (qstring != String.Empty)
231 qstring += "&";
232
233 qstring += part;
234 }
200 } 235 }
201 else 236 else
202 { 237 {
203 part = System.Web.HttpUtility.UrlEncode(kvp.Key); 238 if (kvp.Value.ToString() != String.Empty)
204 } 239 {
240 part = System.Web.HttpUtility.UrlEncode(kvp.Key) +
241 "=" + System.Web.HttpUtility.UrlEncode(kvp.Value.ToString());
242 }
243 else
244 {
245 part = System.Web.HttpUtility.UrlEncode(kvp.Key);
246 }
205 247
206 if (qstring != String.Empty) 248 if (qstring != String.Empty)
207 qstring += "&"; 249 qstring += "&";
208 250
209 qstring += part; 251 qstring += part;
252 }
210 } 253 }
211 254
212 return qstring; 255 return qstring;
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/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..b973c11
--- /dev/null
+++ b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs
@@ -0,0 +1,139 @@
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 startLocation = string.Empty;
72 if (requestData.ContainsKey("start"))
73 startLocation = requestData["start"].ToString();
74
75 LoginResponse reply = null;
76 reply = m_LocalService.Login(requestData["first"].ToString(), requestData["last"].ToString(), requestData["passwd"].ToString(), startLocation);
77
78 XmlRpcResponse response = new XmlRpcResponse();
79 response.Value = reply.ToHashtable();
80 return response;
81
82 }
83 }
84
85 return FailedXMLRPCResponse();
86
87 }
88
89 public OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient)
90 {
91 if (request.Type == OSDType.Map)
92 {
93 OSDMap map = (OSDMap)request;
94
95 if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd"))
96 {
97 string startLocation = string.Empty;
98
99 if (map.ContainsKey("start"))
100 startLocation = map["start"].AsString();
101
102 m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation);
103
104 LoginResponse reply = null;
105 reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation);
106 return reply.ToOSDMap();
107
108 }
109 }
110
111 return FailedOSDResponse();
112 }
113
114 private XmlRpcResponse FailedXMLRPCResponse()
115 {
116 Hashtable hash = new Hashtable();
117 hash["reason"] = "key";
118 hash["message"] = "Incomplete login credentials. Check your username and password.";
119 hash["login"] = "false";
120
121 XmlRpcResponse response = new XmlRpcResponse();
122 response.Value = hash;
123
124 return response;
125 }
126
127 private OSD FailedOSDResponse()
128 {
129 OSDMap map = new OSDMap();
130
131 map["reason"] = OSD.FromString("key");
132 map["message"] = OSD.FromString("Invalid login credentials. Check your username and passwd.");
133 map["login"] = OSD.FromString("false");
134
135 return map;
136 }
137 }
138
139}
diff --git a/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs
new file mode 100644
index 0000000..42ecd4d
--- /dev/null
+++ b/OpenSim/Server/Handlers/Login/LLLoginServiceInConnector.cs
@@ -0,0 +1,93 @@
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 string loginService = ReadLocalServiceFromConfig(config);
51
52 ISimulationService simService = scene.RequestModuleInterface<ISimulationService>();
53
54 Object[] args = new Object[] { config, simService };
55 m_LoginService = ServerUtils.LoadPlugin<ILoginService>(loginService, args);
56
57 InitializeHandlers(server);
58 }
59
60 public LLLoginServiceInConnector(IConfigSource config, IHttpServer server) :
61 base(config, server, String.Empty)
62 {
63 string loginService = ReadLocalServiceFromConfig(config);
64
65 Object[] args = new Object[] { config };
66
67 m_LoginService = ServerUtils.LoadPlugin<ILoginService>(loginService, args);
68
69 InitializeHandlers(server);
70 }
71
72 private string ReadLocalServiceFromConfig(IConfigSource config)
73 {
74 IConfig serverConfig = config.Configs["LoginService"];
75 if (serverConfig == null)
76 throw new Exception(String.Format("No section LoginService in config file"));
77
78 string loginService = serverConfig.GetString("LocalServiceModule", String.Empty);
79 if (loginService == string.Empty)
80 throw new Exception(String.Format("No LocalServiceModule for LoginService in config file"));
81
82 return loginService;
83 }
84
85 private void InitializeHandlers(IHttpServer server)
86 {
87 LLLoginHandlers loginHandlers = new LLLoginHandlers(m_LoginService);
88 server.AddXmlRPCHandler("Login_to_simulator", loginHandlers.HandleXMLRPCLogin, false);
89 server.SetDefaultLLSDHandler(loginHandlers.HandleLLSDLogin);
90 }
91
92 }
93}
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
index 2558fa0..11adc4a 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("SessionID") || !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..4966f66 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;
@@ -45,6 +46,247 @@ using log4net;
45 46
46namespace OpenSim.Server.Handlers.Simulation 47namespace OpenSim.Server.Handlers.Simulation
47{ 48{
49 public class AgentHandler
50 {
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private ISimulationService m_SimulationService;
53
54 public AgentHandler(ISimulationService sim)
55 {
56 m_SimulationService = sim;
57 }
58
59 public Hashtable Handler(Hashtable request)
60 {
61 //m_log.Debug("[CONNECTION DEBUGGING]: AgentHandler Called");
62
63 m_log.Debug("---------------------------");
64 m_log.Debug(" >> uri=" + request["uri"]);
65 m_log.Debug(" >> content-type=" + request["content-type"]);
66 m_log.Debug(" >> http-method=" + request["http-method"]);
67 m_log.Debug("---------------------------\n");
68
69 Hashtable responsedata = new Hashtable();
70 responsedata["content_type"] = "text/html";
71 responsedata["keepalive"] = false;
72
73
74 UUID agentID;
75 string action;
76 ulong regionHandle;
77 if (!Utils.GetParams((string)request["uri"], out agentID, out regionHandle, out action))
78 {
79 m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]);
80 responsedata["int_response_code"] = 404;
81 responsedata["str_response_string"] = "false";
82
83 return responsedata;
84 }
85
86 // Next, let's parse the verb
87 string method = (string)request["http-method"];
88 if (method.Equals("PUT"))
89 {
90 DoAgentPut(request, responsedata);
91 return responsedata;
92 }
93 else if (method.Equals("POST"))
94 {
95 DoAgentPost(request, responsedata, agentID);
96 return responsedata;
97 }
98 else if (method.Equals("GET"))
99 {
100 DoAgentGet(request, responsedata, agentID, regionHandle);
101 return responsedata;
102 }
103 else if (method.Equals("DELETE"))
104 {
105 DoAgentDelete(request, responsedata, agentID, action, regionHandle);
106 return responsedata;
107 }
108 else
109 {
110 m_log.InfoFormat("[AGENT HANDLER]: method {0} not supported in agent message", method);
111 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
112 responsedata["str_response_string"] = "Method not allowed";
113
114 return responsedata;
115 }
116
117 }
118
119 protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
120 {
121 OSDMap args = Utils.GetOSDMap((string)request["body"]);
122 if (args == null)
123 {
124 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
125 responsedata["str_response_string"] = "Bad request";
126 return;
127 }
128
129 // retrieve the regionhandle
130 ulong regionhandle = 0;
131 if (args["destination_handle"] != null)
132 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
133
134 AgentCircuitData aCircuit = new AgentCircuitData();
135 try
136 {
137 aCircuit.UnpackAgentCircuitData(args);
138 }
139 catch (Exception ex)
140 {
141 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
142 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
143 responsedata["str_response_string"] = "Bad request";
144 return;
145 }
146
147 OSDMap resp = new OSDMap(2);
148 string reason = String.Empty;
149 uint teleportFlags = 0;
150 if (args.ContainsKey("teleport_flags"))
151 {
152 teleportFlags = args["teleport_flags"].AsUInteger();
153 }
154
155 // This is the meaning of POST agent
156 //m_regionClient.AdjustUserInformation(aCircuit);
157 bool result = m_SimulationService.CreateAgent(regionhandle, aCircuit, teleportFlags, out reason);
158
159 resp["reason"] = OSD.FromString(reason);
160 resp["success"] = OSD.FromBoolean(result);
161
162 // TODO: add reason if not String.Empty?
163 responsedata["int_response_code"] = HttpStatusCode.OK;
164 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
165 }
166
167 protected virtual void DoAgentPut(Hashtable request, Hashtable responsedata)
168 {
169 OSDMap args = Utils.GetOSDMap((string)request["body"]);
170 if (args == null)
171 {
172 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
173 responsedata["str_response_string"] = "Bad request";
174 return;
175 }
176
177 // retrieve the regionhandle
178 ulong regionhandle = 0;
179 if (args["destination_handle"] != null)
180 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
181
182 string messageType;
183 if (args["message_type"] != null)
184 messageType = args["message_type"].AsString();
185 else
186 {
187 m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. ");
188 messageType = "AgentData";
189 }
190
191 bool result = true;
192 if ("AgentData".Equals(messageType))
193 {
194 AgentData agent = new AgentData();
195 try
196 {
197 agent.Unpack(args);
198 }
199 catch (Exception ex)
200 {
201 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
202 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
203 responsedata["str_response_string"] = "Bad request";
204 return;
205 }
206
207 //agent.Dump();
208 // This is one of the meanings of PUT agent
209 result = m_SimulationService.UpdateAgent(regionhandle, agent);
210
211 }
212 else if ("AgentPosition".Equals(messageType))
213 {
214 AgentPosition agent = new AgentPosition();
215 try
216 {
217 agent.Unpack(args);
218 }
219 catch (Exception ex)
220 {
221 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
222 return;
223 }
224 //agent.Dump();
225 // This is one of the meanings of PUT agent
226 result = m_SimulationService.UpdateAgent(regionhandle, agent);
227
228 }
229
230 responsedata["int_response_code"] = HttpStatusCode.OK;
231 responsedata["str_response_string"] = result.ToString();
232 //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead
233 }
234
235 protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, ulong regionHandle)
236 {
237 IAgentData agent = null;
238 bool result = m_SimulationService.RetrieveAgent(regionHandle, id, out agent);
239 OSDMap map = null;
240 if (result)
241 {
242 if (agent != null) // just to make sure
243 {
244 map = agent.Pack();
245 string strBuffer = "";
246 try
247 {
248 strBuffer = OSDParser.SerializeJsonString(map);
249 }
250 catch (Exception e)
251 {
252 m_log.WarnFormat("[AGENT HANDLER]: Exception thrown on serialization of DoAgentGet: {0}", e.Message);
253 responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
254 // ignore. buffer will be empty, caller should check.
255 }
256
257 responsedata["content_type"] = "application/json";
258 responsedata["int_response_code"] = HttpStatusCode.OK;
259 responsedata["str_response_string"] = strBuffer;
260 }
261 else
262 {
263 responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
264 responsedata["str_response_string"] = "Internal error";
265 }
266 }
267 else
268 {
269 responsedata["int_response_code"] = HttpStatusCode.NotFound;
270 responsedata["str_response_string"] = "Not Found";
271 }
272 }
273
274 protected virtual void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, ulong regionHandle)
275 {
276 //m_log.Debug(" >>> DoDelete action:" + action + "; regionHandle:" + regionHandle);
277
278 if (action.Equals("release"))
279 m_SimulationService.ReleaseAgent(regionHandle, id, "");
280 else
281 m_SimulationService.CloseAgent(regionHandle, id);
282
283 responsedata["int_response_code"] = HttpStatusCode.OK;
284 responsedata["str_response_string"] = "OpenSim agent " + id.ToString();
285
286 m_log.Debug("[AGENT HANDLER]: Agent Deleted.");
287 }
288 }
289
48 public class AgentGetHandler : BaseStreamHandler 290 public class AgentGetHandler : BaseStreamHandler
49 { 291 {
50 // TODO: unused: private ISimulationService m_SimulationService; 292 // TODO: unused: private ISimulationService m_SimulationService;
@@ -153,7 +395,7 @@ namespace OpenSim.Server.Handlers.Simulation
153 // m_regionClient.AdjustUserInformation(aCircuit); 395 // m_regionClient.AdjustUserInformation(aCircuit);
154 396
155 // Finally! 397 // Finally!
156 bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, out reason); 398 bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, /*!!!*/0, out reason);
157 399
158 OSDMap resp = new OSDMap(1); 400 OSDMap resp = new OSDMap(1);
159 401
diff --git a/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs
new file mode 100644
index 0000000..8c3af72
--- /dev/null
+++ b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs
@@ -0,0 +1,191 @@
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 Nini.Config;
44using log4net;
45
46
47namespace OpenSim.Server.Handlers.Simulation
48{
49 public class ObjectHandler
50 {
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private ISimulationService m_SimulationService;
53
54 public ObjectHandler(ISimulationService sim)
55 {
56 m_SimulationService = sim;
57 }
58
59 public Hashtable Handler(Hashtable request)
60 {
61 m_log.Debug("[CONNECTION DEBUGGING]: ObjectHandler Called");
62
63 m_log.Debug("---------------------------");
64 m_log.Debug(" >> uri=" + request["uri"]);
65 m_log.Debug(" >> content-type=" + request["content-type"]);
66 m_log.Debug(" >> http-method=" + request["http-method"]);
67 m_log.Debug("---------------------------\n");
68
69 Hashtable responsedata = new Hashtable();
70 responsedata["content_type"] = "text/html";
71
72 UUID objectID;
73 string action;
74 ulong regionHandle;
75 if (!Utils.GetParams((string)request["uri"], out objectID, out regionHandle, out action))
76 {
77 m_log.InfoFormat("[REST COMMS]: Invalid parameters for object message {0}", request["uri"]);
78 responsedata["int_response_code"] = 404;
79 responsedata["str_response_string"] = "false";
80
81 return responsedata;
82 }
83
84 // Next, let's parse the verb
85 string method = (string)request["http-method"];
86 if (method.Equals("POST"))
87 {
88 DoObjectPost(request, responsedata, regionHandle);
89 return responsedata;
90 }
91 else if (method.Equals("PUT"))
92 {
93 DoObjectPut(request, responsedata, regionHandle);
94 return responsedata;
95 }
96 //else if (method.Equals("DELETE"))
97 //{
98 // DoObjectDelete(request, responsedata, agentID, action, regionHandle);
99 // return responsedata;
100 //}
101 else
102 {
103 m_log.InfoFormat("[REST COMMS]: method {0} not supported in object message", method);
104 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
105 responsedata["str_response_string"] = "Mthod not allowed";
106
107 return responsedata;
108 }
109
110 }
111
112 protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, ulong regionhandle)
113 {
114 OSDMap args = Utils.GetOSDMap((string)request["body"]);
115 if (args == null)
116 {
117 responsedata["int_response_code"] = 400;
118 responsedata["str_response_string"] = "false";
119 return;
120 }
121
122 string sogXmlStr = "", extraStr = "", stateXmlStr = "";
123 if (args["sog"] != null)
124 sogXmlStr = args["sog"].AsString();
125 if (args["extra"] != null)
126 extraStr = args["extra"].AsString();
127
128 IScene s = m_SimulationService.GetScene(regionhandle);
129 ISceneObject sog = null;
130 try
131 {
132 //sog = SceneObjectSerializer.FromXml2Format(sogXmlStr);
133 sog = s.DeserializeObject(sogXmlStr);
134 sog.ExtraFromXmlString(extraStr);
135 }
136 catch (Exception ex)
137 {
138 m_log.InfoFormat("[REST COMMS]: exception on deserializing scene object {0}", ex.Message);
139 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
140 responsedata["str_response_string"] = "Bad request";
141 return;
142 }
143
144 if ((args["state"] != null) && s.AllowScriptCrossings)
145 {
146 stateXmlStr = args["state"].AsString();
147 if (stateXmlStr != "")
148 {
149 try
150 {
151 sog.SetState(stateXmlStr, s);
152 }
153 catch (Exception ex)
154 {
155 m_log.InfoFormat("[REST COMMS]: exception on setting state for scene object {0}", ex.Message);
156 // ignore and continue
157 }
158 }
159 }
160 // This is the meaning of POST object
161 bool result = m_SimulationService.CreateObject(regionhandle, sog, false);
162
163 responsedata["int_response_code"] = HttpStatusCode.OK;
164 responsedata["str_response_string"] = result.ToString();
165 }
166
167 protected virtual void DoObjectPut(Hashtable request, Hashtable responsedata, ulong regionhandle)
168 {
169 OSDMap args = Utils.GetOSDMap((string)request["body"]);
170 if (args == null)
171 {
172 responsedata["int_response_code"] = 400;
173 responsedata["str_response_string"] = "false";
174 return;
175 }
176
177 UUID userID = UUID.Zero, itemID = UUID.Zero;
178 if (args["userid"] != null)
179 userID = args["userid"].AsUUID();
180 if (args["itemid"] != null)
181 itemID = args["itemid"].AsUUID();
182
183 // This is the meaning of PUT object
184 bool result = m_SimulationService.CreateObject(regionhandle, userID, itemID);
185
186 responsedata["int_response_code"] = 200;
187 responsedata["str_response_string"] = result.ToString();
188 }
189
190 }
191} \ No newline at end of file
diff --git a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
index fe93fa5..8611228 100644
--- a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
+++ b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
@@ -37,7 +37,7 @@ 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) :
@@ -47,13 +47,6 @@ namespace OpenSim.Server.Handlers.Simulation
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 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
57 //string simService = serverConfig.GetString("LocalServiceModule", 50 //string simService = serverConfig.GetString("LocalServiceModule",
58 // String.Empty); 51 // String.Empty);
59 52
@@ -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..1f2f851
--- /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 ulong regionHandle, out string action)
50 {
51 uuid = UUID.Zero;
52 action = "";
53 regionHandle = 0;
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 UInt64.TryParse(parts[2], out regionHandle);
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..544ffea
--- /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((Dictionary<string, object>)request["account"]);
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}