Browse Source

Split function fish_open_archive_int() to fish_open_archive_pipeopen() and fish_open_archive_talk().

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
Ilia Maslakov 14 years ago
parent
commit
3cef64306e
1 changed files with 88 additions and 69 deletions
  1. 88 69
      lib/vfs/mc-vfs/fish.c

+ 88 - 69
lib/vfs/mc-vfs/fish.c

@@ -354,90 +354,109 @@ fish_getcwd (struct vfs_class *me, struct vfs_s_super *super)
     ERRNOR (EIO, NULL);
 }
 
-static int
-fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
+
+static void
+fish_open_archive_pipeopen (struct vfs_s_super *super)
 {
+    char gbuf[10];
+    const char *argv[10];       /* All of 10 is used now */
+    const char *xsh = (SUP.flags == FISH_FLAG_RSH ? "rsh" : "ssh");
+    int i = 0;
 
-    /* hide panels */
-    pre_exec ();
+    argv[i++] = xsh;
+    if (SUP.flags == FISH_FLAG_COMPRESSED)
+        argv[i++] = "-C";
+
+    if (SUP.flags > FISH_FLAG_RSH)
     {
-        char gbuf[10];
-        const char *argv[10];   /* All of 10 is used now */
-        const char *xsh = (SUP.flags == FISH_FLAG_RSH ? "rsh" : "ssh");
-        int i = 0;
+        argv[i++] = "-p";
+        g_snprintf (gbuf, sizeof (gbuf), "%d", SUP.flags);
+        argv[i++] = gbuf;
+    }
 
-        argv[i++] = xsh;
-        if (SUP.flags == FISH_FLAG_COMPRESSED)
-            argv[i++] = "-C";
+    /*
+     * Add the user name to the ssh command line only if it was explicitly
+     * set in vfs URL. rsh/ssh will get current user by default
+     * plus we can set convenient overrides in  ~/.ssh/config (explicit -l
+     * option breaks it for some)
+     */
 
-        if (SUP.flags > FISH_FLAG_RSH)
-        {
-            argv[i++] = "-p";
-            g_snprintf (gbuf, sizeof (gbuf), "%d", SUP.flags);
-            argv[i++] = gbuf;
-        }
+    if (SUP.user)
+    {
+        argv[i++] = "-l";
+        argv[i++] = SUP.user;
+    }
+    else
+    {
+        /* The rest of the code assumes it to be a valid username */
+        SUP.user = vfs_get_local_username ();
+    }
 
-        /*
-         * Add the user name to the ssh command line only if it was explicitly
-         * set in vfs URL. rsh/ssh will get current user by default
-         * plus we can set convenient overrides in  ~/.ssh/config (explicit -l
-         * option breaks it for some)
-         */
+    argv[i++] = SUP.host;
+    argv[i++] = "echo FISH:; /bin/sh";
+    argv[i++] = NULL;
 
-        if (SUP.user)
-        {
-            argv[i++] = "-l";
-            argv[i++] = SUP.user;
-        }
-        else
-        {
-            /* The rest of the code assumes it to be a valid username */
-            SUP.user = vfs_get_local_username ();
-        }
+    fish_pipeopen (super, xsh, argv);
+}
 
-        argv[i++] = SUP.host;
-        argv[i++] = "echo FISH:; /bin/sh";
-        argv[i++] = NULL;
+static gboolean
+fish_open_archive_talk (struct vfs_class *me, struct vfs_s_super *super)
+{
+    char answer[2048];
 
-        fish_pipeopen (super, xsh, argv);
-    }
-    {
-        char answer[2048];
-        print_vfs_message (_("fish: Waiting for initial line..."));
-        if (!vfs_s_get_line (me, SUP.sockr, answer, sizeof (answer), ':'))
-            ERRNOR (E_PROTO, -1);
-        print_vfs_message ("%s", answer);
-        if (strstr (answer, "assword"))
-        {
-            /* Currently, this does not work. ssh reads passwords from
-               /dev/tty, not from stdin :-(. */
+    print_vfs_message (_("fish: Waiting for initial line..."));
 
-            message (D_ERROR, MSG_ERROR,
-                     _("Sorry, we cannot do password authenticated connections for now."));
-            ERRNOR (EPERM, -1);
-            if (!SUP.password)
-            {
-                char *p, *op;
-                p = g_strdup_printf (_("fish: Password is required for %s"), SUP.user);
-                op = vfs_get_password (p);
-                g_free (p);
-                if (op == NULL)
-                    ERRNOR (EPERM, -1);
-                SUP.password = op;
-            }
+    if (!vfs_s_get_line (me, SUP.sockr, answer, sizeof (answer), ':'))
+        return FALSE;
 
-            print_vfs_message (_("fish: Sending password..."));
+    print_vfs_message ("%s", answer);
+    if (strstr (answer, "assword"))
+    {
+        /* Currently, this does not work. ssh reads passwords from
+           /dev/tty, not from stdin :-(. */
 
+        message (D_ERROR, MSG_ERROR,
+                 _("Sorry, we cannot do password authenticated connections for now."));
+        return FALSE;
+#if 0
+        if (!SUP.password)
+        {
+            char *p, *op;
+            p = g_strdup_printf (_("fish: Password is required for %s"), SUP.user);
+            op = vfs_get_password (p);
+            g_free (p);
+            if (op == NULL)
+                return FALSE;
+            SUP.password = op;
+        }
+        print_vfs_message (_("fish: Sending password..."));
+        {
+            size_t str_len;
+            str_len = strlen (SUP.password);
+            if ((write (SUP.sockw, SUP.password, str_len) != (ssize_t) str_len)
+                || (write (SUP.sockw, "\n", 1) != 1))
             {
-                size_t str_len;
-                str_len = strlen (SUP.password);
-                if ((write (SUP.sockw, SUP.password, str_len) != (ssize_t) str_len)
-                    || (write (SUP.sockw, "\n", 1) != 1))
-                {
-                    ERRNOR (EIO, -1);
-                }
+                return FALSE;
             }
         }
+#endif
+    }
+    return TRUE;
+}
+
+static int
+fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
+{
+    /* hide panels */
+    pre_exec ();
+
+    /* open pipe */
+    fish_open_archive_pipeopen (super);
+
+    /* Start talk with ssh-server (password prompt, etc ) */
+    if (!fish_open_archive_talk (me, super))
+    {
+        ERRNOR (E_PROTO, -1);
     }
 
     print_vfs_message (_("fish: Sending initial line..."));