Yet more global-removal. The static variables in logging.c are now
[u/mdw/putty] / psftp.c
diff --git a/psftp.c b/psftp.c
index 32d24f7..e585732 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -32,6 +32,8 @@ static int do_sftp_init(void);
  */
 
 char *pwd, *homedir;
+static Backend *back;
+static void *backhandle;
 
 /* ----------------------------------------------------------------------
  * Higher-level helper functions used in commands.
@@ -1470,7 +1472,7 @@ void modalfatalbox(char *fmt, ...)
 
     cleanup_exit(1);
 }
-void connection_fatal(char *fmt, ...)
+void connection_fatal(void *frontend, char *fmt, ...)
 {
     char str[0x100];                  /* Make the size big enough */
     va_list ap;
@@ -1484,7 +1486,7 @@ void connection_fatal(char *fmt, ...)
     cleanup_exit(1);
 }
 
-void ldisc_send(char *buf, int len, int interactive)
+void ldisc_send(void *handle, char *buf, int len, int interactive)
 {
     /*
      * This is only here because of the calls to ldisc_send(NULL,
@@ -1522,7 +1524,7 @@ static unsigned char *outptr;            /* where to put the data */
 static unsigned outlen;                       /* how much data required */
 static unsigned char *pending = NULL;  /* any spare data */
 static unsigned pendlen = 0, pendsize = 0;     /* length and phys. size of buffer */
-int from_backend(int is_stderr, char *data, int datalen)
+int from_backend(void *frontend, int is_stderr, char *data, int datalen)
 {
     unsigned char *p = (unsigned char *) data;
     unsigned len = (unsigned) datalen;
@@ -1610,7 +1612,7 @@ int sftp_recvdata(char *buf, int len)
 }
 int sftp_senddata(char *buf, int len)
 {
-    back->send((unsigned char *) buf, len);
+    back->send(backhandle, (unsigned char *) buf, len);
     return 1;
 }
 
@@ -1621,7 +1623,7 @@ static void ssh_sftp_init(void)
 {
     if (sftp_ssh_socket == INVALID_SOCKET)
        return;
-    while (!back->sendok()) {
+    while (!back->sendok(backhandle)) {
        fd_set readfds;
        FD_ZERO(&readfds);
        FD_SET(sftp_ssh_socket, &readfds);
@@ -1822,11 +1824,13 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
 
     back = &ssh_backend;
 
-    err = back->init(cfg.host, cfg.port, &realhost, 0);
+    err = back->init(NULL, &backhandle, cfg.host, cfg.port, &realhost, 0);
     if (err != NULL) {
        fprintf(stderr, "ssh_init: %s\n", err);
        return 1;
     }
+    logctx = log_init(NULL);
+    back->provide_logctx(backhandle, logctx);
     ssh_sftp_init();
     if (verbose && realhost != NULL)
        printf("Connected to %s\n", realhost);
@@ -1921,9 +1925,9 @@ int main(int argc, char *argv[])
 
     do_sftp(mode, modeflags, batchfile);
 
-    if (back != NULL && back->socket() != NULL) {
+    if (back != NULL && back->socket(backhandle) != NULL) {
        char ch;
-       back->special(TS_EOF);
+       back->special(backhandle, TS_EOF);
        sftp_recvdata(&ch, 1);
     }
     WSACleanup();