From a1c8aa4050b7f7a94e02dd40d8cd456f258b4e2b Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 1 May 2008 15:36:39 +0000 Subject: * Cleaned namespaces of entire solution. OpenSim directories now correspond with namespaces. --- .../Framework/Communications/Capabilities/Caps.cs | 11 +- .../Communications/Capabilities/CapsHandlers.cs | 4 +- .../Framework/Communications/Capabilities/LLSD.cs | 4 +- .../Communications/Capabilities/LLSDArray.cs | 4 +- .../Capabilities/LLSDAssetUploadComplete.cs | 4 +- .../Capabilities/LLSDAssetUploadRequest.cs | 4 +- .../Capabilities/LLSDAssetUploadResponse.cs | 2 +- .../Communications/Capabilities/LLSDCapEvent.cs | 4 +- .../Communications/Capabilities/LLSDEmpty.cs | 4 +- .../Communications/Capabilities/LLSDHelpers.cs | 4 +- .../Capabilities/LLSDInventoryItem.cs | 13 +- .../Communications/Capabilities/LLSDItemUpdate.cs | 4 +- .../Communications/Capabilities/LLSDMapLayer.cs | 4 +- .../Capabilities/LLSDMapLayerResponse.cs | 4 +- .../Communications/Capabilities/LLSDMapRequest.cs | 4 +- .../Communications/Capabilities/LLSDMethod.cs | 4 +- .../Capabilities/LLSDParcelVoiceInfoResponse.cs | 2 +- .../Capabilities/LLSDStreamHandler.cs | 4 +- .../LLSDTaskInventoryUploadComplete.cs | 4 +- .../Capabilities/LLSDTaskScriptUpdate.cs | 4 +- .../Communications/Capabilities/LLSDTest.cs | 4 +- .../Communications/Capabilities/LLSDType.cs | 4 +- .../Capabilities/LLSDVoiceAccountResponse.cs | 2 +- .../Framework/Communications/GenericAsyncResult.cs | 156 +++++++++ OpenSim/Framework/Communications/IUserService.cs | 2 +- OpenSim/Framework/Communications/LoginResponse.cs | 4 +- OpenSim/Framework/Communications/LoginService.cs | 30 +- OpenSim/Framework/Communications/RestClient.cs | 368 +++++++++++++++++++++ .../Framework/Communications/UserManagerBase.cs | 10 +- 29 files changed, 593 insertions(+), 79 deletions(-) create mode 100644 OpenSim/Framework/Communications/GenericAsyncResult.cs create mode 100644 OpenSim/Framework/Communications/RestClient.cs (limited to 'OpenSim/Framework/Communications') diff --git a/OpenSim/Framework/Communications/Capabilities/Caps.cs b/OpenSim/Framework/Communications/Capabilities/Caps.cs index c07744c..b6ee04d 100644 --- a/OpenSim/Framework/Communications/Capabilities/Caps.cs +++ b/OpenSim/Framework/Communications/Capabilities/Caps.cs @@ -32,11 +32,10 @@ using System.IO; using System.Reflection; using libsecondlife; using log4net; -using OpenSim.Framework; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Servers; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { public delegate void UpLoadedAsset( string assetName, string description, LLUUID assetID, LLUUID inventoryItem, LLUUID parentFolder, @@ -54,8 +53,8 @@ namespace OpenSim.Region.Capabilities bool isScriptRunning, byte[] data); public delegate List FetchInventoryDescendentsCAPS(LLUUID agentID, LLUUID folderID, LLUUID ownerID, - bool fetchFolders, bool fetchItems, int sortOrder); - + bool fetchFolders, bool fetchItems, int sortOrder); + /// /// XXX Probably not a particularly nice way of allow us to get the scene presence from the scene (chiefly so that /// we can popup a message on the user's client if the inventory service has permanently failed). But I didn't want @@ -397,7 +396,7 @@ namespace OpenSim.Region.Capabilities /// public string RequestTexture(string request, string path, string param) { - Console.WriteLine("texture request " + request); + System.Console.WriteLine("texture request " + request); // Needs implementing (added to remove compiler warning) return String.Empty; } @@ -961,4 +960,4 @@ namespace OpenSim.Region.Capabilities } } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs b/OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs index f101131..e76a5c5 100644 --- a/OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs +++ b/OpenSim/Framework/Communications/Capabilities/CapsHandlers.cs @@ -29,7 +29,7 @@ using System.Collections; using System.Collections.Generic; using OpenSim.Framework.Servers; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { /// /// CapsHandlers is a cap handler container but also takes @@ -141,4 +141,4 @@ namespace OpenSim.Region.Capabilities } } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSD.cs b/OpenSim/Framework/Communications/Capabilities/LLSD.cs index b3e841c..13361c7 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSD.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSD.cs @@ -34,7 +34,7 @@ using System.Text; using System.Xml; using libsecondlife; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { /// /// Borrowed from (a older version of ) libsl for now, as their new llsd code doesn't work we our decoding code. @@ -676,4 +676,4 @@ namespace OpenSim.Region.Capabilities } } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDArray.cs b/OpenSim/Framework/Communications/Capabilities/LLSDArray.cs index a5cdd73..3579cc2 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDArray.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDArray.cs @@ -27,7 +27,7 @@ using System.Collections; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDType("ARRAY")] public class LLSDArray @@ -38,4 +38,4 @@ namespace OpenSim.Region.Capabilities { } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadComplete.cs b/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadComplete.cs index 1393523..6c4db4b 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadComplete.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadComplete.cs @@ -28,7 +28,7 @@ using System; using libsecondlife; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDType("MAP")] public class LLSDAssetUploadComplete @@ -42,4 +42,4 @@ namespace OpenSim.Region.Capabilities { } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadRequest.cs b/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadRequest.cs index e71a73e..289cc93 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadRequest.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadRequest.cs @@ -28,7 +28,7 @@ using System; using libsecondlife; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDMap] public class LLSDAssetUploadRequest @@ -43,4 +43,4 @@ namespace OpenSim.Region.Capabilities { } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadResponse.cs b/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadResponse.cs index bb293ba..63b3351 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadResponse.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDAssetUploadResponse.cs @@ -27,7 +27,7 @@ using System; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDMap] public class LLSDAssetUploadResponse diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDCapEvent.cs b/OpenSim/Framework/Communications/Capabilities/LLSDCapEvent.cs index c1b15b4..5ff21b8 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDCapEvent.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDCapEvent.cs @@ -25,7 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDType("MAP")] public class LLSDCapEvent @@ -37,4 +37,4 @@ namespace OpenSim.Region.Capabilities { } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDEmpty.cs b/OpenSim/Framework/Communications/Capabilities/LLSDEmpty.cs index 5a44e26..4abdb59 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDEmpty.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDEmpty.cs @@ -25,7 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDType("MAP")] public class LLSDEmpty @@ -34,4 +34,4 @@ namespace OpenSim.Region.Capabilities { } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs b/OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs index a39f5aa..409d2e0 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs @@ -31,7 +31,7 @@ using System.IO; using System.Reflection; using System.Xml; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { public class LLSDHelpers { @@ -160,4 +160,4 @@ namespace OpenSim.Region.Capabilities return obj; } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDInventoryItem.cs b/OpenSim/Framework/Communications/Capabilities/LLSDInventoryItem.cs index d402579..31896c2 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDInventoryItem.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDInventoryItem.cs @@ -27,7 +27,7 @@ using libsecondlife; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDMap] public class LLSDInventoryItem @@ -68,15 +68,6 @@ namespace OpenSim.Region.Capabilities public string sale_type; } - /* [LLSDMap] - public class LLSDFolderItem - { - public LLUUID folder_id; - public LLUUID parent_id; - public int type; - public string name; - }*/ - [LLSDMap] public class LLSDInventoryDescendents { @@ -103,4 +94,4 @@ namespace OpenSim.Region.Capabilities public LLUUID owner___id; // and of course we can't have field names with "-" in public int version; } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDItemUpdate.cs b/OpenSim/Framework/Communications/Capabilities/LLSDItemUpdate.cs index 6211c4f..2c4b68f 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDItemUpdate.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDItemUpdate.cs @@ -27,7 +27,7 @@ using libsecondlife; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDMap] public class LLSDItemUpdate @@ -38,4 +38,4 @@ namespace OpenSim.Region.Capabilities { } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDMapLayer.cs b/OpenSim/Framework/Communications/Capabilities/LLSDMapLayer.cs index 0cf82a8..50f5241 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDMapLayer.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDMapLayer.cs @@ -27,7 +27,7 @@ using libsecondlife; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDType("MAP")] public class LLSDMapLayer @@ -42,4 +42,4 @@ namespace OpenSim.Region.Capabilities { } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDMapLayerResponse.cs b/OpenSim/Framework/Communications/Capabilities/LLSDMapLayerResponse.cs index 205a645..7dabbec 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDMapLayerResponse.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDMapLayerResponse.cs @@ -25,7 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDType("MAP")] public class LLSDMapLayerResponse @@ -37,4 +37,4 @@ namespace OpenSim.Region.Capabilities { } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDMapRequest.cs b/OpenSim/Framework/Communications/Capabilities/LLSDMapRequest.cs index 748c5ea..317e35d 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDMapRequest.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDMapRequest.cs @@ -25,7 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDType("MAP")] public class LLSDMapRequest @@ -36,4 +36,4 @@ namespace OpenSim.Region.Capabilities { } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDMethod.cs b/OpenSim/Framework/Communications/Capabilities/LLSDMethod.cs index deb9223..55d62ac 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDMethod.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDMethod.cs @@ -25,7 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { public delegate TResponse LLSDMethod(TRequest request); -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDParcelVoiceInfoResponse.cs b/OpenSim/Framework/Communications/Capabilities/LLSDParcelVoiceInfoResponse.cs index 4439346..fb5eaa8 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDParcelVoiceInfoResponse.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDParcelVoiceInfoResponse.cs @@ -28,7 +28,7 @@ using System.Collections; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDMap] public class LLSDParcelVoiceInfoResponse diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDStreamHandler.cs b/OpenSim/Framework/Communications/Capabilities/LLSDStreamHandler.cs index 545643a..5e8a08f 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDStreamHandler.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDStreamHandler.cs @@ -30,7 +30,7 @@ using System.IO; using System.Text; using OpenSim.Framework.Servers; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { public class LLSDStreamhandler : BaseStreamHandler where TRequest : new() @@ -65,4 +65,4 @@ namespace OpenSim.Region.Capabilities return encoding.GetBytes(LLSDHelpers.SerialiseLLSDReply(response)); } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDTaskInventoryUploadComplete.cs b/OpenSim/Framework/Communications/Capabilities/LLSDTaskInventoryUploadComplete.cs index 22e45f4..ee9ff1b 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDTaskInventoryUploadComplete.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDTaskInventoryUploadComplete.cs @@ -27,7 +27,7 @@ using libsecondlife; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDMap] public class LLSDTaskInventoryUploadComplete @@ -47,4 +47,4 @@ namespace OpenSim.Region.Capabilities /// public string state; } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDTaskScriptUpdate.cs b/OpenSim/Framework/Communications/Capabilities/LLSDTaskScriptUpdate.cs index ed7e824..df32d1a 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDTaskScriptUpdate.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDTaskScriptUpdate.cs @@ -27,7 +27,7 @@ using libsecondlife; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDMap] public class LLSDTaskScriptUpdate @@ -47,4 +47,4 @@ namespace OpenSim.Region.Capabilities /// public int is_script_running; } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDTest.cs b/OpenSim/Framework/Communications/Capabilities/LLSDTest.cs index d050176..91db060 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDTest.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDTest.cs @@ -25,7 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDType("MAP")] public class LLSDTest @@ -37,4 +37,4 @@ namespace OpenSim.Region.Capabilities { } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDType.cs b/OpenSim/Framework/Communications/Capabilities/LLSDType.cs index bdc8e79..181a465 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDType.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDType.cs @@ -27,7 +27,7 @@ using System; -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [AttributeUsage(AttributeTargets.Class)] public class LLSDType : Attribute @@ -52,4 +52,4 @@ namespace OpenSim.Region.Capabilities { } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDVoiceAccountResponse.cs b/OpenSim/Framework/Communications/Capabilities/LLSDVoiceAccountResponse.cs index 941e70e..67064b0 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDVoiceAccountResponse.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDVoiceAccountResponse.cs @@ -26,7 +26,7 @@ * */ -namespace OpenSim.Region.Capabilities +namespace OpenSim.Framework.Communications.Capabilities { [LLSDMap] public class LLSDVoiceAccountResponse diff --git a/OpenSim/Framework/Communications/GenericAsyncResult.cs b/OpenSim/Framework/Communications/GenericAsyncResult.cs new file mode 100644 index 0000000..ed41614 --- /dev/null +++ b/OpenSim/Framework/Communications/GenericAsyncResult.cs @@ -0,0 +1,156 @@ +using System; +using System.Threading; + +namespace OpenSim.Framework.Communications +{ + internal class SimpleAsyncResult : IAsyncResult + { + private readonly AsyncCallback m_callback; + + /// + /// Is process completed? + /// + /// Should really be boolean, but VolatileRead has no boolean method + private byte m_completed; + + /// + /// Did process complete synchroneously? + /// + /// I have a hard time imagining a scenario where this is the case, again, same issue about + /// booleans and VolatileRead as m_completed + /// + private byte m_completedSynchronously; + + private readonly object m_asyncState; + private ManualResetEvent m_waitHandle; + private Exception m_exception; + + internal SimpleAsyncResult(AsyncCallback cb, object state) + { + m_callback = cb; + m_asyncState = state; + m_completed = 0; + m_completedSynchronously = 1; + } + + #region IAsyncResult Members + + public object AsyncState + { + get { return m_asyncState; } + } + + public WaitHandle AsyncWaitHandle + { + get + { + if (m_waitHandle == null) + { + bool done = IsCompleted; + ManualResetEvent mre = new ManualResetEvent(done); + if (Interlocked.CompareExchange(ref m_waitHandle, mre, null) != null) + { + mre.Close(); + } + else + { + if (!done && IsCompleted) + { + m_waitHandle.Set(); + } + } + } + return m_waitHandle; + } + } + + + public bool CompletedSynchronously + { + get { return Thread.VolatileRead(ref m_completedSynchronously) == 1; } + } + + + public bool IsCompleted + { + get { return Thread.VolatileRead(ref m_completed) == 1; } + } + + #endregion + + #region class Methods + + internal void SetAsCompleted(bool completedSynchronously) + { + m_completed = 1; + if (completedSynchronously) + m_completedSynchronously = 1; + else + m_completedSynchronously = 0; + + SignalCompletion(); + } + + internal void HandleException(Exception e, bool completedSynchronously) + { + m_completed = 1; + if (completedSynchronously) + m_completedSynchronously = 1; + else + m_completedSynchronously = 0; + m_exception = e; + + SignalCompletion(); + } + + private void SignalCompletion() + { + if (m_waitHandle != null) m_waitHandle.Set(); + + if (m_callback != null) m_callback(this); + } + + public void EndInvoke() + { + // This method assumes that only 1 thread calls EndInvoke + if (!IsCompleted) + { + // If the operation isn't done, wait for it + AsyncWaitHandle.WaitOne(); + AsyncWaitHandle.Close(); + m_waitHandle = null; // Allow early GC + } + + // Operation is done: if an exception occured, throw it + if (m_exception != null) throw m_exception; + } + + #endregion + } + + internal class AsyncResult : SimpleAsyncResult + { + private T m_result = default(T); + + public AsyncResult(AsyncCallback asyncCallback, Object state) : + base(asyncCallback, state) + { + } + + public void SetAsCompleted(T result, bool completedSynchronously) + { + // Save the asynchronous operation's result + m_result = result; + + // Tell the base class that the operation completed + // sucessfully (no exception) + base.SetAsCompleted(completedSynchronously); + } + + public new T EndInvoke() + { + base.EndInvoke(); + return m_result; + } + } +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/IUserService.cs b/OpenSim/Framework/Communications/IUserService.cs index 2b6e0d5..7c243c6 100644 --- a/OpenSim/Framework/Communications/IUserService.cs +++ b/OpenSim/Framework/Communications/IUserService.cs @@ -28,7 +28,7 @@ using System.Collections.Generic; using libsecondlife; -namespace OpenSim.Framework +namespace OpenSim.Framework.Communications { public interface IUserService { diff --git a/OpenSim/Framework/Communications/LoginResponse.cs b/OpenSim/Framework/Communications/LoginResponse.cs index a379253..f7989ab 100644 --- a/OpenSim/Framework/Communications/LoginResponse.cs +++ b/OpenSim/Framework/Communications/LoginResponse.cs @@ -34,7 +34,7 @@ using libsecondlife.StructuredData; using log4net; using Nwc.XmlRpc; -namespace OpenSim.Framework.UserManagement +namespace OpenSim.Framework.Communications { /// /// A temp class to handle login response. @@ -777,4 +777,4 @@ namespace OpenSim.Framework.UserManagement } } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/LoginService.cs index 37c0bd8..db4e2ec 100644 --- a/OpenSim/Framework/Communications/LoginService.cs +++ b/OpenSim/Framework/Communications/LoginService.cs @@ -40,7 +40,7 @@ using Nwc.XmlRpc; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Statistics; -namespace OpenSim.Framework.UserManagement +namespace OpenSim.Framework.Communications { public abstract class LoginService { @@ -122,8 +122,8 @@ namespace OpenSim.Framework.UserManagement lastname = (string) requestData["last"]; m_log.InfoFormat( - "[LOGIN BEGIN]: Received login request message from user {0} {1}", - firstname, lastname); + "[LOGIN BEGIN]: Received login request message from user {0} {1}", + firstname, lastname); string clientVersion = "Unknown"; @@ -138,7 +138,7 @@ namespace OpenSim.Framework.UserManagement } m_log.DebugFormat( - "[LOGIN]: Client is {0}, start location is {1}", clientVersion, startLocationRequest); + "[LOGIN]: Client is {0}, start location is {1}", clientVersion, startLocationRequest); userProfile = GetTheUser(firstname, lastname); if (userProfile == null) @@ -163,8 +163,8 @@ namespace OpenSim.Framework.UserManagement catch (Exception e) { m_log.InfoFormat( - "[LOGIN END]: Bad web_login_key: {0} for user {1} {2}, exception {3}", - requestData["web_login_key"], firstname, lastname, e); + "[LOGIN END]: Bad web_login_key: {0} for user {1} {2}, exception {3}", + requestData["web_login_key"], firstname, lastname, e); return logResponse.CreateFailedResponse(); } @@ -201,8 +201,8 @@ namespace OpenSim.Framework.UserManagement // Reject the login m_log.InfoFormat( - "[LOGIN END]: Notifying user {0} {1} that they are already logged in", - firstname, lastname); + "[LOGIN END]: Notifying user {0} {1} that they are already logged in", + firstname, lastname); return logResponse.CreateAlreadyLoggedInResponse(); } @@ -286,8 +286,8 @@ namespace OpenSim.Framework.UserManagement StatsManager.UserStats.AddSuccessfulLogin(); m_log.DebugFormat( - "[LOGIN END]: Authentication of user {0} {1} successful. Sending response to client.", - firstname, lastname); + "[LOGIN END]: Authentication of user {0} {1} successful. Sending response to client.", + firstname, lastname); return logResponse.ToXmlRpcResponse(); } @@ -516,9 +516,9 @@ namespace OpenSim.Framework.UserManagement statuscode = 301; string redirectURL = "about:blank?redirect-http-hack=" + - HttpUtility.UrlEncode("secondlife:///app/login?first_name=" + firstname + "&last_name=" + - lastname + - "&location=" + location + "&grid=Other&web_login_key=" + webloginkey.ToString()); + HttpUtility.UrlEncode("secondlife:///app/login?first_name=" + firstname + "&last_name=" + + lastname + + "&location=" + location + "&grid=Other&web_login_key=" + webloginkey.ToString()); //m_log.Info("[WEB]: R:" + redirectURL); returnactions["int_response_code"] = statuscode; returnactions["str_redirect_location"] = redirectURL; @@ -677,7 +677,7 @@ namespace OpenSim.Framework.UserManagement //m_log.Info("[LOGIN]: userprofile:" + profile.passwordHash + " SubCT:" + password); passwordSuccess = (profile.PasswordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase) - || profile.PasswordHash.Equals(password, StringComparison.InvariantCultureIgnoreCase)); + || profile.PasswordHash.Equals(password, StringComparison.InvariantCultureIgnoreCase)); return passwordSuccess; } @@ -792,4 +792,4 @@ namespace OpenSim.Framework.UserManagement } } } -} +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/RestClient.cs b/OpenSim/Framework/Communications/RestClient.cs new file mode 100644 index 0000000..91284e8 --- /dev/null +++ b/OpenSim/Framework/Communications/RestClient.cs @@ -0,0 +1,368 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Web; +using log4net; + +namespace OpenSim.Framework.Communications +{ + /// + /// Implementation of a generic REST client + /// + /// + /// This class is a generic implementation of a REST (Representational State Transfer) web service. This + /// class is designed to execute both synchroneously and asynchroneously. + /// + /// Internally the implementation works as a two stage asynchroneous web-client. + /// When the request is initiated, RestClient will query asynchroneously for for a web-response, + /// sleeping until the initial response is returned by the server. Once the initial response is retrieved + /// the second stage of asynchroneous requests will be triggered, in an attempt to read of the response + /// object into a memorystream as a sequence of asynchroneous reads. + /// + /// The asynchronisity of RestClient is designed to move as much processing into the back-ground, allowing + /// other threads to execute, while it waits for a response from the web-service. RestClient it self, can be + /// invoked by the caller in either synchroneous mode or asynchroneous mode. + /// + public class RestClient + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private string realuri; + + #region member variables + + /// + /// The base Uri of the web-service e.g. http://www.google.com + /// + private string _url; + + /// + /// Path elements of the query + /// + private List _pathElements = new List(); + + /// + /// Parameter elements of the query, e.g. min=34 + /// + private Dictionary _parameterElements = new Dictionary(); + + /// + /// Request method. E.g. GET, POST, PUT or DELETE + /// + private string _method; + + /// + /// Temporary buffer used to store bytes temporarily as they come in from the server + /// + private byte[] _readbuf; + + /// + /// MemoryStream representing the resultiong resource + /// + private Stream _resource; + + /// + /// WebRequest object, held as a member variable + /// + private HttpWebRequest _request; + + /// + /// WebResponse object, held as a member variable, so we can close it + /// + private HttpWebResponse _response; + + /// + /// This flag will help block the main synchroneous method, in case we run in synchroneous mode + /// + public static ManualResetEvent _allDone = new ManualResetEvent(false); + + /// + /// Default time out period + /// + private const int DefaultTimeout = 10*1000; // 10 seconds timeout + + /// + /// Default Buffer size of a block requested from the web-server + /// + private const int BufferSize = 4096; // Read blocks of 4 KB. + + + /// + /// if an exception occours during async processing, we need to save it, so it can be + /// rethrown on the primary thread; + /// + private Exception _asyncException; + + #endregion member variables + + #region constructors + + /// + /// Instantiate a new RestClient + /// + /// Web-service to query, e.g. http://osgrid.org:8003 + public RestClient(string url) + { + _url = url; + _readbuf = new byte[BufferSize]; + _resource = new MemoryStream(); + _request = null; + _response = null; + _lock = new object(); + } + + private object _lock; + + #endregion constructors + + /// + /// Add a path element to the query, e.g. assets + /// + /// path entry + public void AddResourcePath(string element) + { + if (isSlashed(element)) + _pathElements.Add(element.Substring(0, element.Length - 1)); + else + _pathElements.Add(element); + } + + /// + /// Add a query parameter to the Url + /// + /// Name of the parameter, e.g. min + /// Value of the parameter, e.g. 42 + public void AddQueryParameter(string name, string value) + { + _parameterElements.Add(HttpUtility.UrlEncode(name), HttpUtility.UrlEncode(value)); + } + + /// + /// Add a query parameter to the Url + /// + /// Name of the parameter, e.g. min + public void AddQueryParameter(string name) + { + _parameterElements.Add(HttpUtility.UrlEncode(name), null); + } + + /// + /// Web-Request method, e.g. GET, PUT, POST, DELETE + /// + public string RequestMethod + { + get { return _method; } + set { _method = value; } + } + + /// + /// True if string contains a trailing slash '/' + /// + /// string to be examined + /// true if slash is present + private bool isSlashed(string s) + { + return s.Substring(s.Length - 1, 1) == "/"; + } + + /// + /// Build a Uri based on the initial Url, path elements and parameters + /// + /// fully constructed Uri + private Uri buildUri() + { + StringBuilder sb = new StringBuilder(); + sb.Append(_url); + + foreach (string e in _pathElements) + { + sb.Append("/"); + sb.Append(e); + } + + bool firstElement = true; + foreach (KeyValuePair kv in _parameterElements) + { + if (firstElement) + { + sb.Append("?"); + firstElement = false; + } + else + sb.Append("&"); + + sb.Append(kv.Key); + if (kv.Value != null && kv.Value.Length != 0) + { + sb.Append("="); + sb.Append(kv.Value); + } + } + realuri = sb.ToString(); + //m_log.InfoFormat("[REST CLIENT]: RestURL: {0}", realuri); + return new Uri(sb.ToString()); + } + + #region Async communications with server + + /// + /// Async method, invoked when a block of data has been received from the service + /// + /// + private void StreamIsReadyDelegate(IAsyncResult ar) + { + try + { + Stream s = (Stream) ar.AsyncState; + int read = s.EndRead(ar); + + if (read > 0) + { + _resource.Write(_readbuf, 0, read); + IAsyncResult asynchronousResult = + s.BeginRead(_readbuf, 0, BufferSize, new AsyncCallback(StreamIsReadyDelegate), s); + + // TODO! Implement timeout, without killing the server + //ThreadPool.RegisterWaitForSingleObject(asynchronousResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true); + } + else + { + s.Close(); + _allDone.Set(); + } + } + catch (Exception e) + { + _allDone.Set(); + _asyncException = e; + } + } + + #endregion Async communications with server + + /// + /// Perform synchroneous request + /// + public Stream Request() + { + lock (_lock) + { + _request = (HttpWebRequest) WebRequest.Create(buildUri()); + _request.KeepAlive = false; + _request.ContentType = "application/xml"; + _request.Timeout = 200000; + _asyncException = null; + +// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); + _response = (HttpWebResponse) _request.GetResponse(); + Stream src = _response.GetResponseStream(); + int length = src.Read(_readbuf, 0, BufferSize); + while (length > 0) + { + _resource.Write(_readbuf, 0, length); + length = src.Read(_readbuf, 0, BufferSize); + } + + + // TODO! Implement timeout, without killing the server + // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted + //ThreadPool.RegisterWaitForSingleObject(responseAsyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true); + +// _allDone.WaitOne(); + if (_response != null) + _response.Close(); + if (_asyncException != null) + throw _asyncException; + + if (_resource != null) + { + _resource.Flush(); + _resource.Seek(0, SeekOrigin.Begin); + } + + return _resource; + } + } + + public Stream Request(Stream src) + { + _request = (HttpWebRequest) WebRequest.Create(buildUri()); + _request.KeepAlive = false; + _request.ContentType = "application/xml"; + _request.Timeout = 900000; + _request.Method = RequestMethod; + _asyncException = null; + _request.ContentLength = src.Length; + + m_log.InfoFormat("[REST]: Request Length {0}", _request.ContentLength); + m_log.InfoFormat("[REST]: Sending Web Request {0}", buildUri()); + src.Seek(0, SeekOrigin.Begin); + m_log.Info("[REST]: Seek is ok"); + Stream dst = _request.GetRequestStream(); + m_log.Info("[REST]: GetRequestStream is ok"); + + byte[] buf = new byte[1024]; + int length = src.Read(buf, 0, 1024); + m_log.Info("[REST]: First Read is ok"); + while (length > 0) + { + dst.Write(buf, 0, length); + length = src.Read(buf, 0, 1024); + } + + _response = (HttpWebResponse) _request.GetResponse(); + +// IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); + + // TODO! Implement timeout, without killing the server + // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted + //ThreadPool.RegisterWaitForSingleObject(responseAsyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true); + + return null; + } + + #region Async Invocation + + public IAsyncResult BeginRequest(AsyncCallback callback, object state) + { + /// + /// In case, we are invoked asynchroneously this object will keep track of the state + /// + AsyncResult ar = new AsyncResult(callback, state); + ThreadPool.QueueUserWorkItem(RequestHelper, ar); + return ar; + } + + public Stream EndRequest(IAsyncResult asyncResult) + { + AsyncResult ar = (AsyncResult) asyncResult; + + // Wait for operation to complete, then return result or + // throw exception + return ar.EndInvoke(); + } + + private void RequestHelper(Object asyncResult) + { + // We know that it's really an AsyncResult object + AsyncResult ar = (AsyncResult) asyncResult; + try + { + // Perform the operation; if sucessful set the result + Stream s = Request(); + ar.SetAsCompleted(s, false); + } + catch (Exception e) + { + // If operation fails, set the exception + ar.HandleException(e, false); + } + } + + #endregion Async Invocation + } +} \ No newline at end of file diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs index 0f7dc44..e4d8ca2 100644 --- a/OpenSim/Framework/Communications/UserManagerBase.cs +++ b/OpenSim/Framework/Communications/UserManagerBase.cs @@ -36,7 +36,7 @@ using log4net; using Nwc.XmlRpc; using OpenSim.Framework.Statistics; -namespace OpenSim.Framework.UserManagement +namespace OpenSim.Framework.Communications { /// /// Base class for user management (create, read, etc) @@ -245,7 +245,7 @@ namespace OpenSim.Framework.UserManagement { try { - plugin.Value.RemoveUserFriend(friendlistowner, friend); + plugin.Value.RemoveUserFriend(friendlistowner, friend); } catch (Exception e) { @@ -370,7 +370,7 @@ namespace OpenSim.Framework.UserManagement if ((profile.CurrentAgent.Position.X > 0) && (profile.CurrentAgent.Position.Y > 0) && (profile.CurrentAgent.Position.Z > 0) - ) + ) { // TODO: Right now, currentRegion has not been used in GridServer for requesting region. // TODO: It is only using currentHandle. @@ -564,7 +564,7 @@ namespace OpenSim.Framework.UserManagement catch (Exception e) { m_log.Info("[USERSTORAGE]: Unable to update user " + UserProfile.ID.ToString() - + " via " + plugin.Key + "(" + e.ToString() + ")"); + + " via " + plugin.Key + "(" + e.ToString() + ")"); return false; } } @@ -596,4 +596,4 @@ namespace OpenSim.Framework.UserManagement return false; } } -} +} \ No newline at end of file -- cgit v1.1