diff options
author | Teravus Ovares | 2008-01-05 06:05:25 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-01-05 06:05:25 +0000 |
commit | db3edff5d5f1c9a31f377db77d1ac4e1fa685623 (patch) | |
tree | 5b2066a5556b3eff8f0152bdb3ce109b428081fe /OpenSim/Framework | |
parent | * Added shell Messaging Server. Don't run the MessagingServer yet or you mig... (diff) | |
download | opensim-SC_OLD-db3edff5d5f1c9a31f377db77d1ac4e1fa685623.zip opensim-SC_OLD-db3edff5d5f1c9a31f377db77d1ac4e1fa685623.tar.gz opensim-SC_OLD-db3edff5d5f1c9a31f377db77d1ac4e1fa685623.tar.bz2 opensim-SC_OLD-db3edff5d5f1c9a31f377db77d1ac4e1fa685623.tar.xz |
* Applying jhurliman's LLSD login enablement patch.
* I'm keeping it deactivated until some issues are resolved.
* I'm patching it in deactivated so the patch doesn't get outdated
* I've deactivated it by commenting out the handler for the application/xml+llsd content type.
* While I've tested this as much as possible on my setup and found the deactivated code doesn't cause any problems, consider this update experimental (event though it's deactivated)
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/Communications/LoginResponse.cs | 161 | ||||
-rw-r--r-- | OpenSim/Framework/Communications/LoginService.cs | 132 | ||||
-rw-r--r-- | OpenSim/Framework/Communications/UserManagerBase.cs | 38 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/BaseHttpServer.cs | 75 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/LLSDMethod.cs | 33 |
5 files changed, 434 insertions, 5 deletions
diff --git a/OpenSim/Framework/Communications/LoginResponse.cs b/OpenSim/Framework/Communications/LoginResponse.cs index 954aecb..2239a9c 100644 --- a/OpenSim/Framework/Communications/LoginResponse.cs +++ b/OpenSim/Framework/Communications/LoginResponse.cs | |||
@@ -30,6 +30,7 @@ using System; | |||
30 | using System.Collections; | 30 | using System.Collections; |
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using libsecondlife; | 32 | using libsecondlife; |
33 | using libsecondlife.StructuredData; | ||
33 | using Nwc.XmlRpc; | 34 | using Nwc.XmlRpc; |
34 | using OpenSim.Framework.Console; | 35 | using OpenSim.Framework.Console; |
35 | 36 | ||
@@ -197,11 +198,31 @@ namespace OpenSim.Framework.UserManagement | |||
197 | return (xmlRpcResponse); | 198 | return (xmlRpcResponse); |
198 | } // GenerateResponse | 199 | } // GenerateResponse |
199 | 200 | ||
201 | public LLSD GenerateFailureResponseLLSD(string reason, string message, string login) | ||
202 | { | ||
203 | LLSDMap map = new LLSDMap(); | ||
204 | |||
205 | // Ensure Login Failed message/reason; | ||
206 | ErrorMessage = message; | ||
207 | ErrorReason = reason; | ||
208 | |||
209 | map["reason"] = LLSD.FromString(ErrorReason); | ||
210 | map["message"] = LLSD.FromString(ErrorMessage); | ||
211 | map["login"] = LLSD.FromString(login); | ||
212 | |||
213 | return map; | ||
214 | } | ||
215 | |||
200 | public XmlRpcResponse CreateFailedResponse() | 216 | public XmlRpcResponse CreateFailedResponse() |
201 | { | 217 | { |
202 | return (CreateLoginFailedResponse()); | 218 | return (CreateLoginFailedResponse()); |
203 | } // CreateErrorConnectingToGridResponse() | 219 | } // CreateErrorConnectingToGridResponse() |
204 | 220 | ||
221 | public LLSD CreateFailedResponseLLSD() | ||
222 | { | ||
223 | return CreateLoginFailedResponseLLSD(); | ||
224 | } | ||
225 | |||
205 | public XmlRpcResponse CreateLoginFailedResponse() | 226 | public XmlRpcResponse CreateLoginFailedResponse() |
206 | { | 227 | { |
207 | return | 228 | return |
@@ -210,6 +231,14 @@ namespace OpenSim.Framework.UserManagement | |||
210 | "false")); | 231 | "false")); |
211 | } // LoginFailedResponse | 232 | } // LoginFailedResponse |
212 | 233 | ||
234 | public LLSD CreateLoginFailedResponseLLSD() | ||
235 | { | ||
236 | return GenerateFailureResponseLLSD( | ||
237 | "key", | ||
238 | "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", | ||
239 | "false"); | ||
240 | } | ||
241 | |||
213 | public XmlRpcResponse CreateAlreadyLoggedInResponse() | 242 | public XmlRpcResponse CreateAlreadyLoggedInResponse() |
214 | { | 243 | { |
215 | return | 244 | return |
@@ -218,6 +247,14 @@ namespace OpenSim.Framework.UserManagement | |||
218 | "false")); | 247 | "false")); |
219 | } // CreateAlreadyLoggedInResponse() | 248 | } // CreateAlreadyLoggedInResponse() |
220 | 249 | ||
250 | public LLSD CreateAlreadyLoggedInResponseLLSD() | ||
251 | { | ||
252 | return GenerateFailureResponseLLSD( | ||
253 | "presence", | ||
254 | "You appear to be already logged in, if this is not the case please wait for your session to timeout, if this takes longer than a few minutes please contact the grid owner", | ||
255 | "false"); | ||
256 | } | ||
257 | |||
221 | public XmlRpcResponse CreateDeadRegionResponse() | 258 | public XmlRpcResponse CreateDeadRegionResponse() |
222 | { | 259 | { |
223 | return | 260 | return |
@@ -226,6 +263,14 @@ namespace OpenSim.Framework.UserManagement | |||
226 | "false")); | 263 | "false")); |
227 | } | 264 | } |
228 | 265 | ||
266 | public LLSD CreateDeadRegionResponseLLSD() | ||
267 | { | ||
268 | return GenerateFailureResponseLLSD( | ||
269 | "key", | ||
270 | "The region you are attempting to log into is not responding. Please select another region and try again.", | ||
271 | "false"); | ||
272 | } | ||
273 | |||
229 | public XmlRpcResponse CreateGridErrorResponse() | 274 | public XmlRpcResponse CreateGridErrorResponse() |
230 | { | 275 | { |
231 | return | 276 | return |
@@ -234,6 +279,14 @@ namespace OpenSim.Framework.UserManagement | |||
234 | "false")); | 279 | "false")); |
235 | } | 280 | } |
236 | 281 | ||
282 | public LLSD CreateGridErrorResponseLLSD() | ||
283 | { | ||
284 | return GenerateFailureResponseLLSD( | ||
285 | "key", | ||
286 | "Error connecting to grid. Could not percieve credentials from login XML.", | ||
287 | "false"); | ||
288 | } | ||
289 | |||
237 | #endregion | 290 | #endregion |
238 | 291 | ||
239 | public XmlRpcResponse ToXmlRpcResponse() | 292 | public XmlRpcResponse ToXmlRpcResponse() |
@@ -317,6 +370,112 @@ namespace OpenSim.Framework.UserManagement | |||
317 | } | 370 | } |
318 | } // ToXmlRpcResponse | 371 | } // ToXmlRpcResponse |
319 | 372 | ||
373 | public LLSD ToLLSDResponse() | ||
374 | { | ||
375 | try | ||
376 | { | ||
377 | LLSDMap map = new LLSDMap(); | ||
378 | |||
379 | map["first_name"] = LLSD.FromString(Firstname); | ||
380 | map["last_name"] = LLSD.FromString(Lastname); | ||
381 | map["agent_access"] = LLSD.FromString(agentAccess); | ||
382 | |||
383 | map["sim_port"] = LLSD.FromInteger(SimPort); | ||
384 | map["sim_ip"] = LLSD.FromString(SimAddress); | ||
385 | |||
386 | map["agent_id"] = LLSD.FromUUID(AgentID); | ||
387 | map["session_id"] = LLSD.FromUUID(SessionID); | ||
388 | map["secure_session_id"] = LLSD.FromUUID(SecureSessionID); | ||
389 | map["circuit_code"] = LLSD.FromInteger(CircuitCode); | ||
390 | map["seconds_since_epoch"] = LLSD.FromInteger((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds); | ||
391 | |||
392 | #region Login Flags | ||
393 | |||
394 | LLSDMap loginFlagsLLSD = new LLSDMap(); | ||
395 | loginFlagsLLSD["daylight_savings"] = LLSD.FromString(DST); | ||
396 | loginFlagsLLSD["stipend_since_login"] = LLSD.FromString(StipendSinceLogin); | ||
397 | loginFlagsLLSD["gendered"] = LLSD.FromString(Gendered); | ||
398 | loginFlagsLLSD["ever_logged_in"] = LLSD.FromString(EverLoggedIn); | ||
399 | map["login-flags"] = WrapLLSDMap(loginFlagsLLSD); | ||
400 | |||
401 | #endregion Login Flags | ||
402 | |||
403 | #region Global Textures | ||
404 | |||
405 | LLSDMap globalTexturesLLSD = new LLSDMap(); | ||
406 | globalTexturesLLSD["sun_texture_id"] = LLSD.FromString(SunTexture); | ||
407 | globalTexturesLLSD["cloud_texture_id"] = LLSD.FromString(CloudTexture); | ||
408 | globalTexturesLLSD["moon_texture_id"] = LLSD.FromString(MoonTexture); | ||
409 | |||
410 | map["global-textures"] = WrapLLSDMap(globalTexturesLLSD); | ||
411 | |||
412 | #endregion Global Textures | ||
413 | |||
414 | map["seed_capability"] = LLSD.FromString(seedCapability); | ||
415 | |||
416 | // FIXME: Need a function that will convert these ArrayLists in to LLSDArrays, | ||
417 | // and convert the data inside them to LLSD objects as well | ||
418 | |||
419 | //map["event_categories"] = eventCategories; | ||
420 | //map["event_notifications"] = new LLSDArray(); // todo | ||
421 | //map["classified_categories"] = classifiedCategories; | ||
422 | |||
423 | #region UI Config | ||
424 | |||
425 | LLSDMap uiConfigLLSD = new LLSDMap(); | ||
426 | uiConfigLLSD["allow_first_life"] = LLSD.FromString(allowFirstLife); | ||
427 | map["ui-config"] = WrapLLSDMap(uiConfigLLSD); | ||
428 | |||
429 | #endregion UI Config | ||
430 | |||
431 | #region Inventory | ||
432 | |||
433 | //map["inventory-skeleton"] = agentInventory; | ||
434 | //map["inventory-skel-lib"] = inventoryLibrary; | ||
435 | //map["inventory-root"] = inventoryRoot; | ||
436 | //map["inventory-lib-root"] = inventoryLibRoot; | ||
437 | //map["inventory-lib-owner"] = inventoryLibraryOwner; | ||
438 | |||
439 | #endregion Inventory | ||
440 | |||
441 | map["gestures"] = new LLSDArray(); // todo | ||
442 | |||
443 | //responseData["initial-outfit"] = initialOutfit; | ||
444 | //responseData["start_location"] = startLocation; | ||
445 | |||
446 | map["seed_capability"] = LLSD.FromString(seedCapability); | ||
447 | map["home"] = LLSD.FromString(home); | ||
448 | map["look_at"] = LLSD.FromString(lookAt); | ||
449 | map["message"] = LLSD.FromString(welcomeMessage); | ||
450 | map["region_x"] = LLSD.FromInteger(RegionX * 256); | ||
451 | map["region_y"] = LLSD.FromInteger(RegionY * 256); | ||
452 | |||
453 | if (m_buddyList != null) | ||
454 | { | ||
455 | //map["buddy-list"] = m_buddyList.ToArray(); | ||
456 | } | ||
457 | |||
458 | map["login"] = LLSD.FromString("true"); | ||
459 | |||
460 | return map; | ||
461 | } | ||
462 | catch (Exception e) | ||
463 | { | ||
464 | MainLog.Instance.Warn( | ||
465 | "CLIENT", | ||
466 | "LoginResponse: Error creating XML-RPC Response: " + e.Message | ||
467 | ); | ||
468 | return GenerateFailureResponseLLSD("Internal Error", "Error generating Login Response", "false"); | ||
469 | } | ||
470 | } | ||
471 | |||
472 | private LLSDArray WrapLLSDMap(LLSDMap wrapMe) | ||
473 | { | ||
474 | LLSDArray array = new LLSDArray(); | ||
475 | array.Add(wrapMe); | ||
476 | return array; | ||
477 | } | ||
478 | |||
320 | public void SetEventCategories(string category, string value) | 479 | public void SetEventCategories(string category, string value) |
321 | { | 480 | { |
322 | // this.eventCategoriesHash[category] = value; | 481 | // this.eventCategoriesHash[category] = value; |
@@ -591,4 +750,4 @@ namespace OpenSim.Framework.UserManagement | |||
591 | } | 750 | } |
592 | } | 751 | } |
593 | } | 752 | } |
594 | } \ No newline at end of file | 753 | } |
diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/LoginService.cs index 0531d6a..9cfac1c 100644 --- a/OpenSim/Framework/Communications/LoginService.cs +++ b/OpenSim/Framework/Communications/LoginService.cs | |||
@@ -31,6 +31,7 @@ using System.Collections; | |||
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Threading; | 32 | using System.Threading; |
33 | using libsecondlife; | 33 | using libsecondlife; |
34 | using libsecondlife.StructuredData; | ||
34 | using Nwc.XmlRpc; | 35 | using Nwc.XmlRpc; |
35 | 36 | ||
36 | using OpenSim.Framework.Communications.Cache; | 37 | using OpenSim.Framework.Communications.Cache; |
@@ -198,6 +199,132 @@ namespace OpenSim.Framework.UserManagement | |||
198 | } | 199 | } |
199 | } | 200 | } |
200 | 201 | ||
202 | public LLSD LLSDLoginMethod(LLSD request) | ||
203 | { | ||
204 | // Temporary fix | ||
205 | m_loginMutex.WaitOne(); | ||
206 | |||
207 | try | ||
208 | { | ||
209 | bool GoodLogin = false; | ||
210 | |||
211 | UserProfileData userProfile = null; | ||
212 | LoginResponse logResponse = new LoginResponse(); | ||
213 | |||
214 | if (request.Type == LLSDType.Map) | ||
215 | { | ||
216 | LLSDMap map = (LLSDMap)request; | ||
217 | |||
218 | if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd")) | ||
219 | { | ||
220 | string firstname = map["first"].AsString(); | ||
221 | string lastname = map["last"].AsString(); | ||
222 | string passwd = map["passwd"].AsString(); | ||
223 | |||
224 | userProfile = GetTheUser(firstname, lastname); | ||
225 | if (userProfile == null) | ||
226 | { | ||
227 | MainLog.Instance.Verbose( | ||
228 | "LOGIN", | ||
229 | "Could not find a profile for " + firstname + " " + lastname); | ||
230 | |||
231 | return logResponse.CreateLoginFailedResponseLLSD(); | ||
232 | } | ||
233 | |||
234 | GoodLogin = AuthenticateUser(userProfile, passwd); | ||
235 | } | ||
236 | } | ||
237 | |||
238 | if (!GoodLogin) | ||
239 | { | ||
240 | return logResponse.CreateLoginFailedResponseLLSD(); | ||
241 | } | ||
242 | else | ||
243 | { | ||
244 | // If we already have a session... | ||
245 | if (userProfile.currentAgent != null && userProfile.currentAgent.agentOnline) | ||
246 | { | ||
247 | userProfile.currentAgent = null; | ||
248 | m_userManager.CommitAgent(ref userProfile); | ||
249 | |||
250 | // Reject the login | ||
251 | return logResponse.CreateAlreadyLoggedInResponseLLSD(); | ||
252 | } | ||
253 | |||
254 | // Otherwise... | ||
255 | // Create a new agent session | ||
256 | CreateAgent(userProfile, request); | ||
257 | |||
258 | try | ||
259 | { | ||
260 | LLUUID agentID = userProfile.UUID; | ||
261 | |||
262 | // Inventory Library Section | ||
263 | InventoryData inventData = CreateInventoryData(agentID); | ||
264 | ArrayList AgentInventoryArray = inventData.InventoryArray; | ||
265 | |||
266 | Hashtable InventoryRootHash = new Hashtable(); | ||
267 | InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString(); | ||
268 | ArrayList InventoryRoot = new ArrayList(); | ||
269 | InventoryRoot.Add(InventoryRootHash); | ||
270 | userProfile.rootInventoryFolderID = inventData.RootFolderID; | ||
271 | |||
272 | // Circuit Code | ||
273 | uint circode = (uint)(Util.RandomClass.Next()); | ||
274 | |||
275 | logResponse.Lastname = userProfile.surname; | ||
276 | logResponse.Firstname = userProfile.username; | ||
277 | logResponse.AgentID = agentID.ToString(); | ||
278 | logResponse.SessionID = userProfile.currentAgent.sessionID.ToString(); | ||
279 | logResponse.SecureSessionID = userProfile.currentAgent.secureSessionID.ToString(); | ||
280 | logResponse.InventoryRoot = InventoryRoot; | ||
281 | logResponse.InventorySkeleton = AgentInventoryArray; | ||
282 | logResponse.InventoryLibrary = GetInventoryLibrary(); | ||
283 | |||
284 | Hashtable InventoryLibRootHash = new Hashtable(); | ||
285 | InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000"; | ||
286 | ArrayList InventoryLibRoot = new ArrayList(); | ||
287 | InventoryLibRoot.Add(InventoryLibRootHash); | ||
288 | logResponse.InventoryLibRoot = InventoryLibRoot; | ||
289 | |||
290 | logResponse.InventoryLibraryOwner = GetLibraryOwner(); | ||
291 | logResponse.CircuitCode = (Int32)circode; | ||
292 | //logResponse.RegionX = 0; //overwritten | ||
293 | //logResponse.RegionY = 0; //overwritten | ||
294 | logResponse.Home = "!!null temporary value {home}!!"; // Overwritten | ||
295 | //logResponse.LookAt = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n"; | ||
296 | //logResponse.SimAddress = "127.0.0.1"; //overwritten | ||
297 | //logResponse.SimPort = 0; //overwritten | ||
298 | logResponse.Message = GetMessage(); | ||
299 | logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID)); | ||
300 | |||
301 | try | ||
302 | { | ||
303 | CustomiseResponse(logResponse, userProfile); | ||
304 | } | ||
305 | catch (Exception ex) | ||
306 | { | ||
307 | MainLog.Instance.Verbose("LOGIN", ex.ToString()); | ||
308 | return logResponse.CreateDeadRegionResponseLLSD(); | ||
309 | } | ||
310 | |||
311 | CommitAgent(ref userProfile); | ||
312 | |||
313 | return logResponse.ToLLSDResponse(); | ||
314 | } | ||
315 | catch (Exception ex) | ||
316 | { | ||
317 | MainLog.Instance.Verbose("LOGIN", ex.ToString()); | ||
318 | return logResponse.CreateFailedResponseLLSD(); | ||
319 | } | ||
320 | } | ||
321 | } | ||
322 | finally | ||
323 | { | ||
324 | m_loginMutex.ReleaseMutex(); | ||
325 | } | ||
326 | } | ||
327 | |||
201 | /// <summary> | 328 | /// <summary> |
202 | /// Customises the login response and fills in missing values. | 329 | /// Customises the login response and fills in missing values. |
203 | /// </summary> | 330 | /// </summary> |
@@ -246,6 +373,11 @@ namespace OpenSim.Framework.UserManagement | |||
246 | m_userManager.CreateAgent(profile, request); | 373 | m_userManager.CreateAgent(profile, request); |
247 | } | 374 | } |
248 | 375 | ||
376 | public void CreateAgent(UserProfileData profile, LLSD request) | ||
377 | { | ||
378 | m_userManager.CreateAgent(profile, request); | ||
379 | } | ||
380 | |||
249 | /// <summary> | 381 | /// <summary> |
250 | /// | 382 | /// |
251 | /// </summary> | 383 | /// </summary> |
diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs index 5d62e5e..bea56ea 100644 --- a/OpenSim/Framework/Communications/UserManagerBase.cs +++ b/OpenSim/Framework/Communications/UserManagerBase.cs | |||
@@ -31,6 +31,7 @@ using System.Collections.Generic; | |||
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Security.Cryptography; | 32 | using System.Security.Cryptography; |
33 | using libsecondlife; | 33 | using libsecondlife; |
34 | using libsecondlife.StructuredData; | ||
34 | using Nwc.XmlRpc; | 35 | using Nwc.XmlRpc; |
35 | using OpenSim.Framework.Console; | 36 | using OpenSim.Framework.Console; |
36 | 37 | ||
@@ -394,6 +395,41 @@ namespace OpenSim.Framework.UserManagement | |||
394 | profile.currentAgent = agent; | 395 | profile.currentAgent = agent; |
395 | } | 396 | } |
396 | 397 | ||
398 | public void CreateAgent(UserProfileData profile, LLSD request) | ||
399 | { | ||
400 | UserAgentData agent = new UserAgentData(); | ||
401 | |||
402 | // User connection | ||
403 | agent.agentOnline = true; | ||
404 | |||
405 | // Generate sessions | ||
406 | RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider(); | ||
407 | byte[] randDataS = new byte[16]; | ||
408 | byte[] randDataSS = new byte[16]; | ||
409 | rand.GetBytes(randDataS); | ||
410 | rand.GetBytes(randDataSS); | ||
411 | |||
412 | agent.secureSessionID = new LLUUID(randDataSS, 0); | ||
413 | agent.sessionID = new LLUUID(randDataS, 0); | ||
414 | |||
415 | // Profile UUID | ||
416 | agent.UUID = profile.UUID; | ||
417 | |||
418 | // Current position (from Home) | ||
419 | agent.currentHandle = profile.homeRegion; | ||
420 | agent.currentPos = profile.homeLocation; | ||
421 | |||
422 | // What time did the user login? | ||
423 | agent.loginTime = Util.UnixTimeSinceEpoch(); | ||
424 | agent.logoutTime = 0; | ||
425 | |||
426 | // Current location | ||
427 | agent.regionID = LLUUID.Zero; // Fill in later | ||
428 | agent.currentRegion = LLUUID.Zero; // Fill in later | ||
429 | |||
430 | profile.currentAgent = agent; | ||
431 | } | ||
432 | |||
397 | /// <summary> | 433 | /// <summary> |
398 | /// Saves a target agent to the database | 434 | /// Saves a target agent to the database |
399 | /// </summary> | 435 | /// </summary> |
@@ -445,4 +481,4 @@ namespace OpenSim.Framework.UserManagement | |||
445 | public abstract UserProfileData SetupMasterUser(string firstName, string lastName, string password); | 481 | public abstract UserProfileData SetupMasterUser(string firstName, string lastName, string password); |
446 | public abstract UserProfileData SetupMasterUser(LLUUID uuid); | 482 | public abstract UserProfileData SetupMasterUser(LLUUID uuid); |
447 | } | 483 | } |
448 | } \ No newline at end of file | 484 | } |
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index af2b27c..b36cc8a 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs | |||
@@ -34,6 +34,7 @@ using System.Text; | |||
34 | using System.Threading; | 34 | using System.Threading; |
35 | using System.Xml; | 35 | using System.Xml; |
36 | using Nwc.XmlRpc; | 36 | using Nwc.XmlRpc; |
37 | using libsecondlife.StructuredData; | ||
37 | using OpenSim.Framework.Console; | 38 | using OpenSim.Framework.Console; |
38 | 39 | ||
39 | namespace OpenSim.Framework.Servers | 40 | namespace OpenSim.Framework.Servers |
@@ -43,6 +44,7 @@ namespace OpenSim.Framework.Servers | |||
43 | protected Thread m_workerThread; | 44 | protected Thread m_workerThread; |
44 | protected HttpListener m_httpListener; | 45 | protected HttpListener m_httpListener; |
45 | protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); | 46 | protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); |
47 | protected LLSDMethod m_llsdHandler = null; | ||
46 | protected Dictionary<string, IRequestHandler> m_streamHandlers = new Dictionary<string, IRequestHandler>(); | 48 | protected Dictionary<string, IRequestHandler> m_streamHandlers = new Dictionary<string, IRequestHandler>(); |
47 | protected uint m_port; | 49 | protected uint m_port; |
48 | protected bool m_ssl = false; | 50 | protected bool m_ssl = false; |
@@ -90,6 +92,11 @@ namespace OpenSim.Framework.Servers | |||
90 | return false; | 92 | return false; |
91 | } | 93 | } |
92 | 94 | ||
95 | public bool SetLLSDHandler(LLSDMethod handler) | ||
96 | { | ||
97 | m_llsdHandler = handler; | ||
98 | return true; | ||
99 | } | ||
93 | 100 | ||
94 | public virtual void HandleRequest(Object stateinfo) | 101 | public virtual void HandleRequest(Object stateinfo) |
95 | { | 102 | { |
@@ -136,7 +143,17 @@ namespace OpenSim.Framework.Servers | |||
136 | } | 143 | } |
137 | else | 144 | else |
138 | { | 145 | { |
139 | HandleXmlRpcRequests(request, response); | 146 | switch (request.ContentType) |
147 | { | ||
148 | //case "application/xml+llsd": | ||
149 | //HandleLLSDRequests(request, response); | ||
150 | //break; | ||
151 | case "text/xml": | ||
152 | case "application/xml": | ||
153 | default: | ||
154 | HandleXmlRpcRequests(request, response); | ||
155 | break; | ||
156 | } | ||
140 | } | 157 | } |
141 | } | 158 | } |
142 | 159 | ||
@@ -242,7 +259,7 @@ namespace OpenSim.Framework.Servers | |||
242 | } | 259 | } |
243 | } | 260 | } |
244 | 261 | ||
245 | response.AddHeader("Content-type", "text/xml"); | 262 | response.ContentType = "text/xml"; |
246 | 263 | ||
247 | byte[] buffer = Encoding.UTF8.GetBytes(responseString); | 264 | byte[] buffer = Encoding.UTF8.GetBytes(responseString); |
248 | 265 | ||
@@ -263,6 +280,58 @@ namespace OpenSim.Framework.Servers | |||
263 | } | 280 | } |
264 | } | 281 | } |
265 | 282 | ||
283 | private void HandleLLSDRequests(HttpListenerRequest request, HttpListenerResponse response) | ||
284 | { | ||
285 | Stream requestStream = request.InputStream; | ||
286 | |||
287 | Encoding encoding = Encoding.UTF8; | ||
288 | StreamReader reader = new StreamReader(requestStream, encoding); | ||
289 | |||
290 | string requestBody = reader.ReadToEnd(); | ||
291 | reader.Close(); | ||
292 | requestStream.Close(); | ||
293 | |||
294 | LLSD llsdRequest = null; | ||
295 | LLSD llsdResponse = null; | ||
296 | |||
297 | try { llsdRequest = LLSDParser.DeserializeXml(requestBody); } | ||
298 | catch (Exception ex) { MainLog.Instance.Warn("HTTPD", "Error - " + ex.Message); } | ||
299 | |||
300 | if (llsdRequest != null && m_llsdHandler != null) | ||
301 | { | ||
302 | llsdResponse = m_llsdHandler(llsdRequest); | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | LLSDMap map = new LLSDMap(); | ||
307 | map["reason"] = LLSD.FromString("LLSDRequest"); | ||
308 | map["message"] = LLSD.FromString("No handler registered for LLSD Requests"); | ||
309 | map["login"] = LLSD.FromString("false"); | ||
310 | llsdResponse = map; | ||
311 | } | ||
312 | |||
313 | response.ContentType = "application/xml+llsd"; | ||
314 | |||
315 | byte[] buffer = LLSDParser.SerializeXmlBytes(llsdResponse); | ||
316 | |||
317 | response.SendChunked = false; | ||
318 | response.ContentLength64 = buffer.Length; | ||
319 | response.ContentEncoding = Encoding.UTF8; | ||
320 | |||
321 | try | ||
322 | { | ||
323 | response.OutputStream.Write(buffer, 0, buffer.Length); | ||
324 | } | ||
325 | catch (Exception ex) | ||
326 | { | ||
327 | MainLog.Instance.Warn("HTTPD", "Error - " + ex.Message); | ||
328 | } | ||
329 | finally | ||
330 | { | ||
331 | response.OutputStream.Close(); | ||
332 | } | ||
333 | } | ||
334 | |||
266 | public void HandleHTTPRequest(Hashtable keysvals, HttpListenerRequest request, HttpListenerResponse response) | 335 | public void HandleHTTPRequest(Hashtable keysvals, HttpListenerRequest request, HttpListenerResponse response) |
267 | { | 336 | { |
268 | // This is a test. There's a workable alternative.. as this way sucks. | 337 | // This is a test. There's a workable alternative.. as this way sucks. |
@@ -436,4 +505,4 @@ namespace OpenSim.Framework.Servers | |||
436 | m_streamHandlers.Remove(GetHandlerKey(httpMethod, path)); | 505 | m_streamHandlers.Remove(GetHandlerKey(httpMethod, path)); |
437 | } | 506 | } |
438 | } | 507 | } |
439 | } \ No newline at end of file | 508 | } |
diff --git a/OpenSim/Framework/Servers/LLSDMethod.cs b/OpenSim/Framework/Servers/LLSDMethod.cs new file mode 100644 index 0000000..5cd225b --- /dev/null +++ b/OpenSim/Framework/Servers/LLSDMethod.cs | |||
@@ -0,0 +1,33 @@ | |||
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 OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using libsecondlife.StructuredData; | ||
29 | |||
30 | namespace OpenSim.Framework.Servers | ||
31 | { | ||
32 | public delegate LLSD LLSDMethod(LLSD request); | ||
33 | } | ||