2007-11-04 Miguel de Icaza <miguel@novell.com>
authorMiguel de Icaza <miguel@gnome.org>
Sun, 4 Nov 2007 16:11:04 +0000 (16:11 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Sun, 4 Nov 2007 16:11:04 +0000 (16:11 -0000)
* FtpWebRequest.cs (GetResponseStatus): Fix this routine
propertly, refactor, and make it follow Mono coding conventions.

svn path=/trunk/mcs/; revision=88820

mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/FtpWebRequest.cs

index d064f26835e1057ebbbed8a76c2c826314362644..b12e7ad98fa30e8876f03a2e4a3fbc0962b80938 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-04  Miguel de Icaza  <miguel@novell.com>
+
+       * FtpWebRequest.cs (GetResponseStatus): Fix this routine
+       propertly, refactor, and make it follow Mono coding conventions.
+
 2007-10-30  Jerome Haltom  (wasabi@larvalstage.net)
 
        * FtpWebRequest.cs: adds support for ftp multiline results, fixes
index 4daee58a35fe364f1b49236f5277c2adbc894fbb..8d4f30de273617b217889296dfaee417bdb31132 100644 (file)
@@ -917,7 +917,8 @@ namespace System.Net
                        ftpResponse.UpdateStatus (status);
                }
 
-               void Authenticate () {
+               void Authenticate ()
+               {
                        string username = null;
                        string password = null;
                        string domain = null;
@@ -991,40 +992,50 @@ namespace System.Net
                        return GetResponseStatus ();
                }
 
+               internal static FtpStatus ServiceNotAvailable ()
+               {
+                       return new FtpStatus (FtpStatusCode.ServiceNotAvailable, Locale.GetText ("Invalid response from server"));
+               }
+               
                internal FtpStatus GetResponseStatus ()
                {
                        while (true) {
-                               string responseString = null;
+                               string response = null;
 
                                try {
-                                       responseString = controlReader.ReadLine ();
+                                       response = controlReader.ReadLine ();
+                               } catch (IOException) {
                                }
-                               catch (IOException) {
-                                       // controlReader.Close ();
-                               }
-
-                               if (responseString == null || responseString.Length < 3)
-                                       return new FtpStatus(FtpStatusCode.ServiceNotAvailable, "Invalid response from server");
 
-                               string codeString = responseString.Substring (0, 3);
+                               if (response == null || response.Length < 3)
+                                       return ServiceNotAvailable ();
 
-                               int code;
-                               if (!Int32.TryParse (codeString, out code))
-                                       return new FtpStatus (FtpStatusCode.ServiceNotAvailable, "Invalid response from server");
+                               int code, fcode;
+                               if (!Int32.TryParse (response.Substring (0, 3), out code))
+                                       return ServiceNotAvailable ();
 
-                               if (responseString.Length < 4 || responseString [3] != '-')
-                                       return new FtpStatus ((FtpStatusCode) code, responseString);
-
-                               if (responseString [3] == '-') {
+                               if (response [3] == '-'){
                                        string line = null;
-                                       do {
-                                               line = controlReader.ReadLine();
-                                               responseString += Environment.NewLine + line;
-                                       } while (line.Length < 3 || (line [3] != ' ' && line.Substring (0, 3) != codeString));
-                                       return new FtpStatus ((FtpStatusCode) code, responseString);
+                                       while (true){
+                                               try {
+                                                       line = controlReader.ReadLine();
+                                               } catch (IOException) {
+                                               }
+                                               if (line == null || response.Length < 3)
+                                                       return ServiceNotAvailable ();
+                                               
+                                               response += Environment.NewLine + line;
+                                               if (line.Length < 3)
+                                                       break;
+
+                                               if (!Int32.TryParse (line.Substring (0, 3), out fcode))
+                                                       return ServiceNotAvailable ();
+
+                                               if (code == fcode && line[3] == ' ')
+                                                       break;
+                                       } 
                                }
-
-                               return new FtpStatus (FtpStatusCode.ServiceNotAvailable, "Invalid response from server");
+                               return new FtpStatus ((FtpStatusCode) code, response);
                        }
                }