changeset 493:527d5b926928

2004-7-6 Brian Masney <masneyb@gftp.org> * lib/sshv2.c - added sshv2_wrong_message(). Changed the wrong message log messages to call this function instead
author masneyb
date Wed, 07 Jul 2004 01:52:16 +0000
parents 015e27587f03
children 6b0bdce46b14
files ChangeLog lib/sshv2.c
diffstat 2 files changed, 35 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jul 05 16:24:57 2004 +0000
+++ b/ChangeLog	Wed Jul 07 01:52:16 2004 +0000
@@ -1,3 +1,7 @@
+2004-7-6 Brian Masney <masneyb@gftp.org>
+	* lib/sshv2.c - added sshv2_wrong_message(). Changed the wrong message
+	log messages to call this function instead
+
 2004-6-27 Brian Masney <masneyb@gftp.org>
 	* lib/sshv2.c - did more code cleanups
 
@@ -2523,7 +2527,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.273 2004/06/27 15:32:56 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.274 2004/07/07 01:52:16 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/sshv2.c	Mon Jul 05 16:24:57 2004 +0000
+++ b/lib/sshv2.c	Wed Jul 07 01:52:16 2004 +0000
@@ -140,6 +140,7 @@
 #define SSH_ERROR_BADPASS	-1
 #define SSH_ERROR_QUESTION	-2
 
+
 static char *
 sshv2_initialize_string (gftp_request * request, size_t len)
 {
@@ -178,7 +179,7 @@
   if (*path == '/')
     {
       pathlen = strlen (path);
-      *len = pathlen + 8 + *len;
+      *len += pathlen + 8;
       ret = sshv2_initialize_string (request, *len);
       sshv2_add_string_to_buf (ret + 4, path);
     }
@@ -186,7 +187,7 @@
     {
       tempstr = gftp_build_path (request->directory, path, NULL);
       pathlen = strlen (tempstr);
-      *len = pathlen + 8 + *len;
+      *len += pathlen + 8;
       ret = sshv2_initialize_string (request, *len);
       sshv2_add_string_to_buf (ret + 4, tempstr);
       g_free (tempstr);
@@ -799,6 +800,20 @@
 
 
 static int
+sshv2_wrong_response (gftp_request * request, sshv2_message * message)
+{
+  request->logging_function (gftp_logging_error, request,
+                     _("Received wrong response from server, disconnecting\n"));
+  gftp_disconnect (request);
+
+  if (message != NULL)
+    sshv2_message_free (message);
+
+  return (GFTP_EFATAL);
+}
+
+
+static int
 sshv2_read_status_response (gftp_request * request, sshv2_message * message,
                             int fd, int fxp_is_retryable, int fxp_is_wrong)
 {
@@ -814,13 +829,7 @@
       return (GFTP_ERETRYABLE);
     }
   else if (fxp_is_wrong > 0 && ret != fxp_is_wrong)
-    {
-      request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-      gftp_disconnect (request);
-      sshv2_message_free (message);
-      return (GFTP_EFATAL);
-    }
+    return (sshv2_wrong_response (request, message));
 
   return (ret);
 }
@@ -833,26 +842,14 @@
   gint32 ret;
 
   if (message->end - message->pos < 4)
-    {
-      request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-      sshv2_message_free (message);
-      gftp_disconnect (request);
-      return (GFTP_EFATAL);
-    }
+    return (sshv2_wrong_response (request, message));
 
   memcpy (&ret, message->pos, 4);
   ret = ntohl (ret);
   message->pos += 4;
 
   if (expected_response > 0 && ret != expected_response)
-    {
-      request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-      sshv2_message_free (message);
-      gftp_disconnect (request);
-      return (GFTP_EFATAL);
-    }
+    return (sshv2_wrong_response (request, message));
 
   return (ret);
 }
@@ -869,10 +866,7 @@
 
   if (len > SSH_MAX_STRING_SIZE || (message->end - message->pos < len))
     {
-      request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-      sshv2_message_free (message);
-      gftp_disconnect (request);
+      sshv2_wrong_response (request, message);
       return (NULL);
     }
 
@@ -1010,13 +1004,7 @@
       return (ret);
     }
   else if (ret != SSH_FXP_VERSION)
-    {
-      request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-      sshv2_message_free (&message);
-      gftp_disconnect (request);
-      return (GFTP_EFATAL);
-    }
+    return (sshv2_wrong_response (request, &message));
 
   sshv2_message_free (&message);
 
@@ -1259,52 +1247,28 @@
         {
           params->message.pos += 8;
           if (params->message.pos > params->message.end)
-            {
-              request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-              sshv2_message_free (&params->message);
-              gftp_disconnect (request);
-              return (GFTP_EFATAL);
-            }
+            return (sshv2_wrong_response (request, &params->message));
         }
 
       if (attrs & SSH_FILEXFER_ATTR_UIDGID)
         {
           params->message.pos += 8;
           if (params->message.pos > params->message.end)
-            {
-              request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-              sshv2_message_free (&params->message);
-              gftp_disconnect (request);
-              return (GFTP_EFATAL);
-            }
+            return (sshv2_wrong_response (request, &params->message));
         }
 
       if (attrs & SSH_FILEXFER_ATTR_PERMISSIONS)
         {
           params->message.pos += 4;
           if (params->message.pos > params->message.end)
-            {
-              request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-              sshv2_message_free (&params->message);
-              gftp_disconnect (request);
-              return (GFTP_EFATAL);
-            }
+            return (sshv2_wrong_response (request, &params->message));
         }
 
       if (attrs & SSH_FILEXFER_ATTR_ACMODTIME)
         {
           params->message.pos += 8;
           if (params->message.pos > params->message.end)
-            {
-              request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-              sshv2_message_free (&params->message);
-              gftp_disconnect (request);
-              return (GFTP_EFATAL);
-            }
+            return (sshv2_wrong_response (request, &params->message));
         }
 
       if (attrs & SSH_FILEXFER_ATTR_EXTENDED)
@@ -1354,13 +1318,7 @@
       return (0);
     }
   else
-    {
-      request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-      sshv2_message_free (&params->message);
-      gftp_disconnect (request);
-      return (GFTP_EFATAL);
-    }
+    return (sshv2_wrong_response (request, &params->message));
 
   return (retsize);
 }
@@ -1906,12 +1864,8 @@
         return (num);
       sshv2_message_free (&message);
       if (num != SSH_FX_EOF)
-        {
-          request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-          gftp_disconnect (request);
-          return (GFTP_EFATAL);
-        }
+        return (sshv2_wrong_response (request, &message));
+
       return (0);
     }
 
@@ -1992,13 +1946,7 @@
 
   params->dont_log_status = 0;
   if (ret != SSH_FXP_STATUS)
-   {
-     request->logging_function (gftp_logging_error, request,
-                     _("Received wrong response from server, disconnecting\n"));
-     sshv2_message_free (&message);
-     gftp_disconnect (request);
-     return (GFTP_EFATAL);
-   }
+    return (sshv2_wrong_response (request, &message));
 
   message.pos += 4;
   if ((num = sshv2_buffer_get_int32 (request, &message, SSH_FX_OK)) < 0)