From bee543300fc812277e9a9478dc05b986e00ed44e Mon Sep 17 00:00:00 2001
From: mingchen
Date: Thu, 28 Jun 2007 14:45:46 +0000
Subject: *User Profile requests on OGS UserServer now uses XMLRPC instead of
REST *Added base support for setting up a master user
---
OpenSim/Framework/Communications/IUserServices.cs | 5 +-
OpenSim/Framework/UserManager/UserManagerBase.cs | 126 ++++++++++-----------
OpenSim/Grid/UserServer/Main.cs | 4 +-
.../Communications/Local/LocalUserServices.cs | 25 ++++
.../Region/Communications/OGS1/OGSUserServices.cs | 17 ++-
5 files changed, 107 insertions(+), 70 deletions(-)
(limited to 'OpenSim')
diff --git a/OpenSim/Framework/Communications/IUserServices.cs b/OpenSim/Framework/Communications/IUserServices.cs
index 6790651..37f4942 100644
--- a/OpenSim/Framework/Communications/IUserServices.cs
+++ b/OpenSim/Framework/Communications/IUserServices.cs
@@ -39,6 +39,9 @@ namespace OpenSim.Framework.Communications
UserProfileData GetUserProfile(string firstName, string lastName);
UserProfileData GetUserProfile(string name);
UserProfileData GetUserProfile(LLUUID avatarID);
-
+
+ UserProfileData SetupMasterUser(string firstName, string lastName);
+ UserProfileData SetupMasterUser(string firstName, string lastName, string password);
+
}
}
diff --git a/OpenSim/Framework/UserManager/UserManagerBase.cs b/OpenSim/Framework/UserManager/UserManagerBase.cs
index eb46c14..bc35164 100644
--- a/OpenSim/Framework/UserManager/UserManagerBase.cs
+++ b/OpenSim/Framework/UserManager/UserManagerBase.cs
@@ -537,27 +537,15 @@ namespace OpenSim.Framework.UserManagement
/// Returns an error message that the user could not be found in the database
///
/// XML string consisting of a error element containing individual error(s)
- public string CreateUnknownUserErrorResponse()
+ public XmlRpcResponse CreateUnknownUserErrorResponse()
{
- System.IO.StringWriter sw = new System.IO.StringWriter();
- XmlTextWriter xw = new XmlTextWriter(sw);
-
- // Header
- xw.Formatting = Formatting.Indented;
- xw.WriteStartDocument();
- xw.WriteDocType("error", null, null, null);
- xw.WriteComment("An error occured");
- xw.WriteStartElement("error");
-
- // User
- xw.WriteElementString("unknownuser", "Unable to find a user with that name");
-
- // Footer
- xw.WriteEndElement();
- xw.Flush();
- xw.Close();
+ XmlRpcResponse response = new XmlRpcResponse();
+ Hashtable responseData = new Hashtable();
+ responseData["error_type"] = "unknown_user";
+ responseData["error_desc"] = "The user requested is not in the database";
- return sw.ToString();
+ response.Value = responseData;
+ return response;
}
///
@@ -565,75 +553,81 @@ namespace OpenSim.Framework.UserManagement
///
/// The user profile
/// A string containing an XML Document of the user profile
- public string ProfileToXml(UserProfileData profile)
+ public XmlRpcResponse ProfileToXmlRPCResponse(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");
+ XmlRpcResponse response = new XmlRpcResponse();
+ Hashtable responseData = new Hashtable();
+
// Account information
- xw.WriteAttributeString("firstname", profile.username);
- xw.WriteAttributeString("lastname", profile.surname);
- xw.WriteAttributeString("uuid", profile.UUID.ToStringHyphenated());
+ responseData["firstname"] = profile.username;
+ responseData["lastname"] = profile.surname;
+ responseData["uuid"] = profile.UUID.ToStringHyphenated();
// Server Information
- xw.WriteAttributeString("server_inventory", profile.userInventoryURI);
- xw.WriteAttributeString("server_asset", profile.userAssetURI);
+ responseData["server_inventory"] = profile.userInventoryURI;
+ responseData["server_asset"] = profile.userAssetURI;
// Profile Information
- xw.WriteAttributeString("profile_about", profile.profileAboutText);
- xw.WriteAttributeString("profile_firstlife_about", profile.profileFirstText);
- xw.WriteAttributeString("profile_firstlife_image", profile.profileFirstImage.ToStringHyphenated());
- xw.WriteAttributeString("profile_can_do", profile.profileCanDoMask.ToString());
- xw.WriteAttributeString("profile_want_do", profile.profileWantDoMask.ToString());
- xw.WriteAttributeString("profile_image", profile.profileImage.ToStringHyphenated());
- xw.WriteAttributeString("profile_created",profile.created.ToString());
- xw.WriteAttributeString("profile_lastlogin",profile.lastLogin.ToString());
+ responseData["profile_about"] = profile.profileAboutText;
+ responseData["profile_firstlife_about"] = profile.profileFirstText;
+ responseData["profile_firstlife_image"] = profile.profileFirstImage.ToStringHyphenated();
+ responseData["profile_can_do"] = profile.profileCanDoMask.ToString();
+ responseData["profile_want_do"] = profile.profileWantDoMask.ToString();
+ responseData["profile_image"] = profile.profileImage.ToStringHyphenated();
+ responseData["profile_created"] = profile.created.ToString();
+ responseData["profile_lastlogin"] = profile.lastLogin.ToString();
// Home region information
- xw.WriteAttributeString("home_coordinates", profile.homeLocation.ToString());
- xw.WriteAttributeString("home_region", profile.homeRegion.ToString());
- xw.WriteAttributeString("home_look", profile.homeLookAt.ToString());
+ responseData["home_coordinates"] = profile.homeLocation.ToString();
+ responseData["home_region"] = profile.homeRegion.ToString();
+ responseData["home_look"] = profile.homeLookAt.ToString();
- xw.WriteEndElement();
-
- // Footer
- xw.WriteEndElement();
- xw.Flush();
- xw.Close();
-
- return sw.ToString();
+ response.Value = responseData;
+ return response;
}
- #region REST Methods
+ #region XMLRPC User Methods
//should most likely move out of here and into the grid's userserver sub class
- public string RestGetUserMethodName(string request, string path, string param)
+ public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request)
{
- UserProfileData userProfile = getUserProfile(param.Trim());
+ XmlRpcResponse response = new XmlRpcResponse();
+ Hashtable requestData = (Hashtable)request.Params[0];
+ UserProfileData userProfile;
- if (userProfile == null)
+ if (requestData.Contains("avatar_name"))
+ {
+ userProfile = getUserProfile((string)requestData["avatar_name"]);
+ if (userProfile == null)
+ {
+ return CreateUnknownUserErrorResponse();
+ }
+ }
+ else
{
return CreateUnknownUserErrorResponse();
}
+
- return ProfileToXml(userProfile);
+ return ProfileToXmlRPCResponse(userProfile);
}
- public string RestGetUserMethodUUID(string request, string path, string param)
+ public XmlRpcResponse XmlRPCGetUserMethodUUID(XmlRpcRequest request)
{
- UserProfileData userProfile = getUserProfile(new LLUUID(param));
-
- if (userProfile == null)
+ XmlRpcResponse response = new XmlRpcResponse();
+ Hashtable requestData = (Hashtable)request.Params[0];
+ UserProfileData userProfile;
+ if (requestData.Contains("avatar_uuid"))
+ {
+ userProfile = getUserProfile((LLUUID)requestData["avatar_uuid"]);
+ if (userProfile == null)
+ {
+ return CreateUnknownUserErrorResponse();
+ }
+ }
+ else
{
return CreateUnknownUserErrorResponse();
}
- return ProfileToXml(userProfile);
+
+ return ProfileToXmlRPCResponse(userProfile);
}
#endregion
diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs
index 8ae4dbf..640f91a 100644
--- a/OpenSim/Grid/UserServer/Main.cs
+++ b/OpenSim/Grid/UserServer/Main.cs
@@ -107,8 +107,8 @@ namespace OpenSim.Grid.UserServer
httpServer.AddXmlRPCHandler("login_to_simulator", m_userManager.XmlRpcLoginMethod);
- httpServer.AddRestHandler("GET", "/user/name/", m_userManager.RestGetUserMethodName);
- httpServer.AddRestHandler("GET", "/user/uuid/", m_userManager.RestGetUserMethodUUID);
+ httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName);
+ httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID);
httpServer.AddRestHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod);
diff --git a/OpenSim/Region/Communications/Local/LocalUserServices.cs b/OpenSim/Region/Communications/Local/LocalUserServices.cs
index 1eb574c..2097870 100644
--- a/OpenSim/Region/Communications/Local/LocalUserServices.cs
+++ b/OpenSim/Region/Communications/Local/LocalUserServices.cs
@@ -114,5 +114,30 @@ namespace OpenSim.Region.Communications.Local
}
+ public UserProfileData SetupMasterUser(string firstName, string lastName)
+ {
+ return SetupMasterUser(firstName, lastName, "");
+ }
+ public UserProfileData SetupMasterUser(string firstName, string lastName, string password)
+ {
+ UserProfileData profile = getUserProfile(firstName, lastName);
+ if (profile != null)
+ {
+
+ return profile;
+ }
+
+ Console.WriteLine("Unknown Master User. Sandbox Mode: Creating Account");
+ this.AddUserProfile(firstName, lastName, password, defaultHomeX, defaultHomeY);
+
+ profile = getUserProfile(firstName, lastName);
+
+ if (profile == null)
+ {
+ Console.WriteLine("Unknown Master User after creation attempt. No clue what to do here.");
+ }
+
+ return profile;
+ }
}
}
diff --git a/OpenSim/Region/Communications/OGS1/OGSUserServices.cs b/OpenSim/Region/Communications/OGS1/OGSUserServices.cs
index 012774d..48d3018 100644
--- a/OpenSim/Region/Communications/OGS1/OGSUserServices.cs
+++ b/OpenSim/Region/Communications/OGS1/OGSUserServices.cs
@@ -11,7 +11,7 @@ namespace OpenSim.Region.Communications.OGS1
{
public UserProfileData GetUserProfile(string firstName, string lastName)
{
- return null;
+ return GetUserProfile(firstName + " " + lastName);
}
public UserProfileData GetUserProfile(string name)
{
@@ -21,5 +21,20 @@ namespace OpenSim.Region.Communications.OGS1
{
return null;
}
+
+ public UserProfileData SetupMasterUser(string firstName, string lastName)
+ {
+ return SetupMasterUser(firstName, lastName, "");
+ }
+
+ public UserProfileData SetupMasterUser(string firstName, string lastName, string password)
+ {
+ UserProfileData profile = GetUserProfile(firstName, lastName);
+ if (profile == null)
+ {
+ Console.WriteLine("Unknown Master User. Grid Mode: No clue what I should do. Probably would choose the grid owner UUID when that is implemented");
+ }
+ return null;
+ }
}
}
--
cgit v1.1