Major destabilisation, phase 2. This time it's the backends' turn:
[u/mdw/putty] / plink.c
diff --git a/plink.c b/plink.c
index 91484c6..34fe30a 100644 (file)
--- a/plink.c
+++ b/plink.c
@@ -29,6 +29,17 @@ void fatalbox(char *p, ...)
     WSACleanup();
     cleanup_exit(1);
 }
+void modalfatalbox(char *p, ...)
+{
+    va_list ap;
+    fprintf(stderr, "FATAL ERROR: ");
+    va_start(ap, p);
+    vfprintf(stderr, p, ap);
+    va_end(ap);
+    fputc('\n', stderr);
+    WSACleanup();
+    cleanup_exit(1);
+}
 void connection_fatal(char *p, ...)
 {
     va_list ap;
@@ -58,7 +69,7 @@ DWORD orig_console_mode;
 
 WSAEVENT netevent;
 
-int term_ldisc(int mode)
+int term_ldisc(Terminal *term, int mode)
 {
     return FALSE;
 }
@@ -153,7 +164,7 @@ void try_output(int is_stderr)
     }
 }
 
-int from_backend(int is_stderr, char *data, int len)
+int from_backend(void *frontend_handle, int is_stderr, char *data, int len)
 {
     HANDLE h = (is_stderr ? errhandle : outhandle);
     int osize, esize;
@@ -185,14 +196,25 @@ static void usage(void)
     printf("       (\"host\" can also be a PuTTY saved session name)\n");
     printf("Options:\n");
     printf("  -v        show verbose messages\n");
-    printf("  -ssh      force use of ssh protocol\n");
+    printf("  -load sessname  Load settings from saved session\n");
+    printf("  -ssh -telnet -rlogin -raw\n");
+    printf("            force use of a particular protocol (default SSH)\n");
     printf("  -P port   connect to specified port\n");
-    printf("  -pw passw login with specified password\n");
+    printf("  -l user   connect with specified username\n");
     printf("  -m file   read remote command(s) from file\n");
+    printf("  -batch    disable all interactive prompts\n");
+    printf("The following options only apply to SSH connections:\n");
+    printf("  -pw passw login with specified password\n");
     printf("  -L listen-port:host:port   Forward local port to "
           "remote address\n");
     printf("  -R listen-port:host:port   Forward remote port to"
           " local address\n");
+    printf("  -X -x     enable / disable X11 forwarding\n");
+    printf("  -A -a     enable / disable agent forwarding\n");
+    printf("  -t -T     enable / disable pty allocation\n");
+    printf("  -1 -2     force use of particular protocol version\n");
+    printf("  -C        enable compression\n");
+    printf("  -i key    private key file for authentication\n");
     exit(1);
 }
 
@@ -280,8 +302,6 @@ int main(int argc, char **argv)
                continue;
            } else if (!strcmp(p, "-batch")) {
                console_batch_mode = 1;
-           } else if (!strcmp(p, "-log")) {
-               logfile = "putty.log";
            }
        } else if (*p) {
            if (!*cfg.host) {
@@ -438,6 +458,21 @@ int main(int argc, char **argv)
      */
     cfg.host[strcspn(cfg.host, ":")] = '\0';
 
+    /*
+     * Remove any remaining whitespace from the hostname.
+     */
+    {
+       int p1 = 0, p2 = 0;
+       while (cfg.host[p2] != '\0') {
+           if (cfg.host[p2] != ' ' && cfg.host[p2] != '\t') {
+               cfg.host[p1] = cfg.host[p2];
+               p1++;
+           }
+           p2++;
+       }
+       cfg.host[p1] = '\0';
+    }
+
     if (!*cfg.remote_cmd_ptr)
        flags |= FLAG_INTERACTIVE;
 
@@ -494,7 +529,8 @@ int main(int argc, char **argv)
        int nodelay = cfg.tcp_nodelay &&
            (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR);
 
-       error = back->init(cfg.host, cfg.port, &realhost, nodelay);
+       error = back->init(NULL, &backhandle, cfg.host, cfg.port,
+                          &realhost, nodelay);
        if (error) {
            fprintf(stderr, "Unable to open connection:\n%s", error);
            return 1;
@@ -550,7 +586,7 @@ int main(int argc, char **argv)
     while (1) {
        int n;
 
-       if (!sending && back->sendok()) {
+       if (!sending && back->sendok(backhandle)) {
            /*
             * Create a separate thread to read from stdin. This is
             * a total pain, but I can't find another way to do it:
@@ -642,11 +678,11 @@ int main(int argc, char **argv)
        } else if (n == 1) {
            reading = 0;
            noise_ultralight(idata.len);
-           if (connopen && back->socket() != NULL) {
+           if (connopen && back->socket(backhandle) != NULL) {
                if (idata.len > 0) {
-                   back->send(idata.buffer, idata.len);
+                   back->send(backhandle, idata.buffer, idata.len);
                } else {
-                   back->special(TS_EOF);
+                   back->special(backhandle, TS_EOF);
                }
            }
        } else if (n == 2) {
@@ -658,8 +694,8 @@ int main(int argc, char **argv)
            bufchain_consume(&stdout_data, odata.lenwritten);
            if (bufchain_size(&stdout_data) > 0)
                try_output(0);
-           if (connopen && back->socket() != NULL) {
-               back->unthrottle(bufchain_size(&stdout_data) +
+           if (connopen && back->socket(backhandle) != NULL) {
+               back->unthrottle(backhandle, bufchain_size(&stdout_data) +
                                 bufchain_size(&stderr_data));
            }
        } else if (n == 3) {
@@ -671,22 +707,22 @@ int main(int argc, char **argv)
            bufchain_consume(&stderr_data, edata.lenwritten);
            if (bufchain_size(&stderr_data) > 0)
                try_output(1);
-           if (connopen && back->socket() != NULL) {
-               back->unthrottle(bufchain_size(&stdout_data) +
+           if (connopen && back->socket(backhandle) != NULL) {
+               back->unthrottle(backhandle, bufchain_size(&stdout_data) +
                                 bufchain_size(&stderr_data));
            }
        }
-       if (!reading && back->sendbuffer() < MAX_STDIN_BACKLOG) {
+       if (!reading && back->sendbuffer(backhandle) < MAX_STDIN_BACKLOG) {
            SetEvent(idata.eventback);
            reading = 1;
        }
-       if ((!connopen || back->socket() == NULL) &&
+       if ((!connopen || back->socket(backhandle) == NULL) &&
            bufchain_size(&stdout_data) == 0 &&
            bufchain_size(&stderr_data) == 0)
            break;                     /* we closed the connection */
     }
     WSACleanup();
-    exitcode = back->exitcode();
+    exitcode = back->exitcode(backhandle);
     if (exitcode < 0) {
        fprintf(stderr, "Remote process exit code unavailable\n");
        exitcode = 1;                  /* this is an error condition */