Răsfoiți Sursa

2002-10-02 Gonzalo Paniagua Javier <[email protected]>

	* HttpMethodNotAllowedHandler.cs:
	* HttpRuntime.cs:
	* StaticFileHandler.cs: Modified file.

	* HttpUtility.cs: implemented all missing methods.

svn path=/trunk/mcs/; revision=7934
Gonzalo Paniagua Javier 23 ani în urmă
părinte
comite
714798c14d

+ 9 - 0
mcs/class/System.Web/System.Web/ChangeLog

@@ -1,3 +1,12 @@
+2002-10-02  Gonzalo Paniagua Javier <[email protected]>
+
+	* HttpMethodNotAllowedHandler.cs:
+	* HttpRuntime.cs:
+	* StaticFileHandler.cs: Modified file.
+
+	* HttpUtility.cs: implemented all missing methods.
+
+
 2002-09-30  Gonzalo Paniagua Javier <[email protected]>
 
 	* System.Web/HttpApplication.cs: use the static file handler.

+ 2 - 2
mcs/class/System.Web/System.Web/HttpMethodNotAllowedHandler.cs

@@ -11,13 +11,13 @@ namespace System.Web
 {
 	class HttpMethodNotAllowedHandler : IHttpHandler
 	{
-		public virtual void ProcessRequest (HttpContext context)
+		public void ProcessRequest (HttpContext context)
 		{
 			throw new HttpException (405, "Forbidden");
 		}
 
 
-		public virtual bool IsReusable
+		public bool IsReusable
 		{
 			get {
 				return true;

+ 20 - 9
mcs/class/System.Web/System.Web/HttpRuntime.cs

@@ -16,7 +16,6 @@ using System.Web.Caching;
 
 namespace System.Web {
 
-	[MonoTODO ("Make corrent right now this is a simple impl to give us a base for testing... the methods here are not complete or valid")]	
 	public sealed class HttpRuntime {
 
 		// Security permission helper objects
@@ -28,6 +27,10 @@ namespace System.Web {
 		private static IStackWalk reflectionStackWalk;
 
 		private static HttpRuntime _runtime;
+		private static string appDomainAppId;
+		private static string appDomainId;
+		private static string appDomainAppPath;
+		private static string appDomainAppVirtualPath;
 		private Cache _cache;
 
 		private int _activeRequests;
@@ -237,31 +240,39 @@ namespace System.Web {
 			}
 		}      
 
-		[MonoTODO]
 		public static string AppDomainAppId {
 			get {
-				throw new NotImplementedException ();
+				if (appDomainAppId == null)
+					appDomainAppId = (string) AppDomain.CurrentDomain.GetData (".appId");
+
+				return appDomainAppId;
 			}
 		}
 
-		[MonoTODO]
 		public static string AppDomainAppPath {
 			get {
-				throw new NotImplementedException ();
+				if (appDomainAppPath == null)
+					appDomainAppPath = (string) AppDomain.CurrentDomain.GetData (".appPath");
+
+				return appDomainAppPath;
 			}
 		}
 
-		[MonoTODO]
 		public static string AppDomainAppVirtualPath {
 			get {
-				throw new NotImplementedException ();
+				if (appDomainAppVirtualPath == null)
+					appDomainAppPath = (string) AppDomain.CurrentDomain.GetData (".appVPath");
+
+				return appDomainAppVirtualPath;
 			}
 		}
 
-		[MonoTODO]
 		public static string AppDomainId {
 			get {
-				throw new NotImplementedException ();
+				if (appDomainId == null)
+					appDomainId = (string) AppDomain.CurrentDomain.GetData (".domainId");
+
+				return appDomainId;
 			}
 		}
 

+ 196 - 24
mcs/class/System.Web/System.Web/HttpUtility.cs

@@ -5,7 +5,7 @@
 //   Patrik Torstensson ([email protected])
 //   Wictor Wilén (decode/encode functions) ([email protected])
 //   Tim Coleman ([email protected])
-//   Gonzalo Paniagua Javuer ([email protected])
+//   Gonzalo Paniagua Javier ([email protected])
 //
 using System;
 using System.Collections;
@@ -401,13 +401,17 @@ namespace System.Web {
 			if (c >= '0' && c <= '9')
 				return c - '0';
 
+			if (c < 'A' || c > 'F')
+				return 0;
+
 			return (c - 'A' + 10);
 		}
 
 		private static char GetChar (byte [] bytes, int offset, int length)
 		{
 			int value = 0;
-			for (int i = offset; i < length; i++)
+			int end = length + offset;
+			for (int i = offset; i < end; i++)
 				value = (value << 4) + GetInt (bytes [offset]);
 
 			return (char) value;
@@ -421,19 +425,20 @@ namespace System.Web {
 			if (bytes == null)
 				throw new ArgumentNullException ("bytes");
 
-			if (offset < 0 || offset > (int) bytes.Length)
+			if (offset < 0 || offset > bytes.Length)
 				throw new ArgumentOutOfRangeException ("offset");
 
-			if (count < 0 || offset + count > (int) bytes.Length)
+			if (count < 0 || offset + count > bytes.Length)
 				throw new ArgumentOutOfRangeException ("count");
 
 			StringBuilder output = new StringBuilder ();
 			ArrayList byteArray = new ArrayList ();
 			char [] chars;
 
-			for (int i = offset; i < count; i++) {
+			int end = count + offset;
+			for (int i = offset; i < end; i++) {
 				if (bytes [i] == '%' && i + 2 < count) {
-					if (bytes [i + 1] == (byte) 'u' && i + 5 < count) {
+					if (bytes [i + 1] == (byte) 'u' && i + 5 < end) {
 						if (byteArray.Count > 0) {
 							chars = GetChars (byteArray, e);
 							output.Append (chars);
@@ -468,34 +473,201 @@ namespace System.Web {
 			return output.ToString ();
 		}
 	
+		public static byte [] UrlDecodeToBytes (byte [] bytes)
+		{
+			if (bytes == null)
+				return null;
+
+			return UrlDecodeToBytes (bytes, 0, bytes.Length);
+		}
+
+		public static byte [] UrlDecodeToBytes (string str)
+		{
+			return UrlDecodeToBytes (str, Encoding.UTF8);
+		}
+
+		public static byte [] UrlDecodeToBytes (string str, Encoding e)
+		{
+			if (str == null)
+				return null;
+
+			if (e == null)
+				throw new ArgumentNullException ("e");
+
+			return UrlDecodeToBytes (e.GetBytes (str));
+		}
+
+		public static byte [] UrlDecodeToBytes (byte [] bytes, int offset, int count)
+		{
+			if (bytes == null)
+				return null;
+
+			int len = bytes.Length;
+			if (offset < 0 || offset >= len)
+				throw new ArgumentOutOfRangeException("offset");
+
+			if (count < 0 || offset <= len - count)
+				throw new ArgumentOutOfRangeException("count");
+
+			ArrayList result = new ArrayList ();
+			int end = offset + count;
+			for (int i = offset; i < end; i++){
+				char c = (char) bytes [i];
+				if (c == '+')
+					c = ' ';
+				else if (c == '%' && i < end - 2) {
+					c = GetChar (bytes, i, 2);
+					i += 2;
+				}
+				result.Add ((byte) c);
+			}
+
+			return (byte []) result.ToArray (typeof (byte));
+		}
+
 		public static string UrlEncode(string str) 
 		{
 			return UrlEncode(str, Encoding.UTF8);
 		}
 	
-		[MonoTODO("Use encoding")]
-		public static string UrlEncode(string s, Encoding Enc) 
+		public static string UrlEncode (string s, Encoding Enc) 
 		{
-			if (null == s) 
+			if (s == null)
 				return null;
-	
-			StringBuilder output = new StringBuilder ();
-			int h1, h2;
-	
-			foreach (char c in s) {
-				if (c == ' ') // space character is replaced with '+'
-					output.Append ('+');
-				else if ( _chars.IndexOf (c) >= 0 ) {
-					output.Append ('%');
-					output.Append (_hex [((int) c) % 16].ToString ());
-					output.Append (_hex [((int) c) / 16].ToString ());
+
+			byte [] bytes = Enc.GetBytes (s);
+			return Encoding.ASCII.GetString (UrlEncodeToBytes (bytes, 0, bytes.Length));
+		}
+	  
+		public static string UrlEncode (byte [] bytes)
+		{
+			if (bytes == null)
+				return null;
+
+			return Encoding.ASCII.GetString (UrlEncodeToBytes (bytes, 0, bytes.Length));
+		}
+
+		public static string UrlEncode (byte [] bytes, int offset, int count)
+		{
+			if (bytes == null)
+				return null;
+
+			return Encoding.ASCII.GetString (UrlEncodeToBytes (bytes, offset, count));
+		}
+
+		public static byte [] UrlEncodeToBytes (string str)
+		{
+			return UrlEncodeToBytes (str, Encoding.UTF8);
+		}
+
+		public static byte [] UrlEncodeToBytes (string str, Encoding e)
+		{
+			if (str == null)
+				return null;
+
+			byte [] bytes = e.GetBytes (str);
+			return UrlEncodeToBytes (bytes, 0, bytes.Length);
+		}
+
+		public static byte [] UrlEncodeToBytes (byte [] bytes)
+		{
+			if (bytes == null)
+				return null;
+
+			return UrlEncodeToBytes (bytes, 0, bytes.Length);
+		}
+
+		static char [] hexChars = "012456789ABCDEF".ToCharArray ();
+
+		public static byte [] UrlEncodeToBytes (byte [] bytes, int offset, int count)
+		{
+			if (bytes == null)
+				return null;
+
+			int len = bytes.Length;
+			if (offset < 0 || offset >= len)
+				throw new ArgumentOutOfRangeException("offset");
+
+			if (count < 0 || offset <= len - count)
+				throw new ArgumentOutOfRangeException("count");
+
+			ArrayList result = new ArrayList ();
+			int end = offset + count;
+			for (int i = offset; i < end; i++) {
+				char c = (char) bytes [i];
+				if (c == ' ')
+					result.Add ((byte) '+');
+				else if ((c < '0' && c != '-' && c != '.') ||
+					 (c < 'A' && c > '9') ||
+					 (c > 'Z' && c < 'a' && c != '_') ||
+					 (c > 'z')) {
+					result.Add ((byte) '%');
+					int idx = ((int) c) >> 4;
+					result.Add ((byte) hexChars [idx]);
+					idx = ((int) c) & 0x0F;
+					result.Add ((byte) hexChars [idx]);
+				} else {
+					result.Add ((byte) c);
 				}
-				else
-					output.Append (c);
 			}
-			return output.ToString ();
+
+			return (byte []) result.ToArray (typeof (byte));
 		}
-	  
+
+		public static string UrlEncodeUnicode (string str)
+		{
+			if (str == null)
+				return null;
+
+			StringBuilder result = new StringBuilder ();
+			int end = str.Length;
+			for (int i = 0; i < end; i++) {
+				int idx;
+				char c = str [i];
+				if (c == ' ') {
+					result.Append ('+');
+					continue;
+				} 
+
+				if (c > 255) {
+					result.Append ("%u");
+					idx = ((int) c) >> 24;
+					result.Append (hexChars [idx]);
+					idx = (((int) c) >> 16) & 0x0F;
+					result.Append (hexChars [idx]);
+					idx = (((int) c) >> 8) & 0x0F;
+					result.Append (hexChars [idx]);
+					idx = ((int) c) & 0x0F;
+					result.Append (hexChars [idx]);
+					continue;
+				}
+				
+				if ((c < '0' && c != '-' && c != '.') ||
+				    (c < 'A' && c > '9') ||
+				    (c > 'Z' && c < 'a' && c != '_') ||
+				    (c > 'z')) {
+					result.Append ('%');
+					idx = ((int) c) >> 4;
+					result.Append (hexChars [idx]);
+					idx = ((int) c) & 0x0F;
+					result.Append (hexChars [idx]);
+					continue;
+				}
+
+				result.Append (c);
+			}
+
+			return result.ToString ();
+		}
+
+		public static byte [] UrlEncodeUnicodeToBytes (string str)
+		{
+			if (str == null)
+				return null;
+
+			return Encoding.ASCII.GetBytes (UrlEncodeUnicode (str));
+		}
+
 		/// <summary>
 		/// Decodes an HTML-encoded string and returns the decoded string.
 		/// </summary>

+ 1 - 1
mcs/class/System.Web/System.Web/StaticFileHandler.cs

@@ -37,7 +37,7 @@ namespace System.Web
 			}
 		}
 
-		public virtual bool IsReusable
+		public bool IsReusable
 		{
 			get {
 				return true;