diff options
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/Util.cs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index c7a7341..b133ff3 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -52,6 +52,8 @@ using OpenMetaverse; | |||
52 | using OpenMetaverse.StructuredData; | 52 | using OpenMetaverse.StructuredData; |
53 | using Amib.Threading; | 53 | using Amib.Threading; |
54 | using System.Collections.Concurrent; | 54 | using System.Collections.Concurrent; |
55 | using System.Collections.Specialized; | ||
56 | using System.Web; | ||
55 | 57 | ||
56 | namespace OpenSim.Framework | 58 | namespace OpenSim.Framework |
57 | { | 59 | { |
@@ -866,6 +868,54 @@ namespace OpenSim.Framework | |||
866 | } | 868 | } |
867 | 869 | ||
868 | /// <summary> | 870 | /// <summary> |
871 | /// Parses a foreign asset ID. | ||
872 | /// </summary> | ||
873 | /// <param name="id">A possibly-foreign asset ID: http://grid.example.com:8002/00000000-0000-0000-0000-000000000000 </param> | ||
874 | /// <param name="url">The URL: http://grid.example.com:8002</param> | ||
875 | /// <param name="assetID">The asset ID: 00000000-0000-0000-0000-000000000000. Returned even if 'id' isn't foreign.</param> | ||
876 | /// <returns>True: this is a foreign asset ID; False: it isn't</returns> | ||
877 | public static bool ParseForeignAssetID(string id, out string url, out string assetID) | ||
878 | { | ||
879 | url = String.Empty; | ||
880 | assetID = String.Empty; | ||
881 | |||
882 | UUID uuid; | ||
883 | if (UUID.TryParse(id, out uuid)) | ||
884 | { | ||
885 | assetID = uuid.ToString(); | ||
886 | return false; | ||
887 | } | ||
888 | |||
889 | if ((id.Length == 0) || (id[0] != 'h' && id[0] != 'H')) | ||
890 | return false; | ||
891 | |||
892 | Uri assetUri; | ||
893 | if (!Uri.TryCreate(id, UriKind.Absolute, out assetUri) || assetUri.Scheme != Uri.UriSchemeHttp) | ||
894 | return false; | ||
895 | |||
896 | // Simian | ||
897 | if (assetUri.Query != string.Empty) | ||
898 | { | ||
899 | NameValueCollection qscoll = HttpUtility.ParseQueryString(assetUri.Query); | ||
900 | assetID = qscoll["id"]; | ||
901 | if (assetID != null) | ||
902 | url = id.Replace(assetID, ""); // Malformed again, as simian expects | ||
903 | else | ||
904 | url = id; // !!! best effort | ||
905 | } | ||
906 | else // robust | ||
907 | { | ||
908 | url = "http://" + assetUri.Authority; | ||
909 | assetID = assetUri.LocalPath.Trim(new char[] { '/' }); | ||
910 | } | ||
911 | |||
912 | if (!UUID.TryParse(assetID, out uuid)) | ||
913 | return false; | ||
914 | |||
915 | return true; | ||
916 | } | ||
917 | |||
918 | /// <summary> | ||
869 | /// Removes all invalid path chars (OS dependent) | 919 | /// Removes all invalid path chars (OS dependent) |
870 | /// </summary> | 920 | /// </summary> |
871 | /// <param name="path">path</param> | 921 | /// <param name="path">path</param> |