X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/181a7e4b8e98f7fbd15b0998b9d26f8e5fc2e353..514702987c9252fcb0ab98882a6603b3bd0505ce:/plink.c diff --git a/plink.c b/plink.c index ed4f1345..34fe30a9 100644 --- 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; @@ -447,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; @@ -503,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; @@ -559,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: @@ -651,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) { @@ -667,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) { @@ -680,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 */