From 26b208d738c1e33140442b27ab71bdac685b4c2c Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sat, 9 Jun 2007 01:21:53 +0000 Subject: * Sugilite user server can now return user profile information by account name (Hi MingChen) - uses the REST GET /user/name/ method. --- OpenGridServices.suo | Bin 139776 -> 139776 bytes .../OpenGridServices.UserServer/Main.cs | 8 ++-- .../OpenGridServices.UserServer/UserManager.cs | 51 +++++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/OpenGridServices.suo b/OpenGridServices.suo index 460303a..acde093 100644 Binary files a/OpenGridServices.suo and b/OpenGridServices.suo differ diff --git a/OpenGridServices/OpenGridServices.UserServer/Main.cs b/OpenGridServices/OpenGridServices.UserServer/Main.cs index bb20576..f2cefe5 100644 --- a/OpenGridServices/OpenGridServices.UserServer/Main.cs +++ b/OpenGridServices/OpenGridServices.UserServer/Main.cs @@ -53,9 +53,7 @@ namespace OpenGridServices.UserServer private UserConfig Cfg; protected IGenericConfig localXMLConfig; - public UserManager m_userManager; // Replaces below. - - //private UserProfileManager m_userProfileManager; // Depreciated + public UserManager m_userManager; public Dictionary UserSessions = new Dictionary(); @@ -64,7 +62,7 @@ namespace OpenGridServices.UserServer [STAThread] public static void Main(string[] args) { - Console.WriteLine("Starting...\n"); + Console.WriteLine("Launching UserServer..."); OpenUser_Main userserver = new OpenUser_Main(); @@ -108,9 +106,11 @@ namespace OpenGridServices.UserServer BaseHttpServer httpServer = new BaseHttpServer(8002); httpServer.AddXmlRPCHandler("login_to_simulator", m_userManager.XmlRpcLoginMethod); + httpServer.AddRestHandler("GET", "/user/name/", m_userManager.RestGetUserMethodName); httpServer.AddRestHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod); httpServer.Start(); + m_console.Status("Userserver 0.3 - Startup complete"); } diff --git a/OpenGridServices/OpenGridServices.UserServer/UserManager.cs b/OpenGridServices/OpenGridServices.UserServer/UserManager.cs index 913d0fc..773fa71 100644 --- a/OpenGridServices/OpenGridServices.UserServer/UserManager.cs +++ b/OpenGridServices/OpenGridServices.UserServer/UserManager.cs @@ -655,5 +655,56 @@ namespace OpenGridServices.UserServer return "OK"; } + public string CreateUnknownUserErrorResponse() + { + return "Unknown user"; + } + + /// + /// Converts a user profile to an XML element which can be returned + /// + /// The user profile + /// A string containing an XML Document of the user profile + public string ProfileToXml(UserProfileData profile) + { + System.IO.StringWriter sw = new System.IO.StringWriter(); + XmlTextWriter xw = new XmlTextWriter(sw); + + // Header + xw.Formatting = Formatting.Indented; + xw.WriteStartDocument(); + xw.WriteDocType("userprofile", null, null, null); + xw.WriteComment("Found user profiles matching the request"); + xw.WriteStartElement("users"); + + // User + xw.WriteStartElement("user"); + xw.WriteAttributeString("firstname", profile.username); + xw.WriteAttributeString("lastname", profile.surname); + xw.WriteAttributeString("uuid", profile.UUID.ToStringHyphenated()); + xw.WriteAttributeString("inventory", profile.userInventoryURI); + xw.WriteAttributeString("asset", profile.userAssetURI); + xw.WriteEndElement(); + + // Footer + xw.WriteEndElement(); + xw.Flush(); + xw.Close(); + + return sw.ToString(); + } + + public string RestGetUserMethodName(string request, string path, string param) + { + UserProfileData userProfile = getUserProfile(param.Trim()); + + if (userProfile == null) + { + return CreateUnknownUserErrorResponse(); + } + + return ProfileToXml(userProfile); + } + } } -- cgit v1.1