Colin's const-fixing Patch Of Death. Seems to build fine on Windows
[u/mdw/putty] / scp.c
diff --git a/scp.c b/scp.c
index ea81f01..0c7fe74 100644 (file)
--- a/scp.c
+++ b/scp.c
@@ -101,6 +101,7 @@ static int using_sftp = 0;
 
 static Backend *back;
 static void *backhandle;
+static Config cfg;
 
 static void source(char *src);
 static void rsource(char *src);
@@ -304,6 +305,16 @@ char *do_select(SOCKET skt, int startup)
 extern int select_result(WPARAM, LPARAM);
 
 /*
+ * In pscp, all agent requests should be synchronous, so this is a
+ * never-called stub.
+ */
+void agent_schedule_callback(void (*callback)(void *, void *, int),
+                            void *callback_ctx, void *data, int len)
+{
+    assert(!"We shouldn't be here");
+}
+
+/*
  * Receive a block of data from the SSH link. Block until all data
  * is available.
  *
@@ -316,7 +327,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(void *frontend, int is_stderr, char *data, int datalen)
+int from_backend(void *frontend, int is_stderr, const char *data, int datalen)
 {
     unsigned char *p = (unsigned char *) data;
     unsigned len = (unsigned) datalen;
@@ -352,8 +363,7 @@ int from_backend(void *frontend, int is_stderr, char *data, int datalen)
     if (len > 0) {
        if (pendsize < pendlen + len) {
            pendsize = pendlen + len + 4096;
-           pending = (pending ? srealloc(pending, pendsize) :
-                      smalloc(pendsize));
+           pending = sresize(pending, pendsize, unsigned char);
            if (!pending)
                fatalbox("Out of memory");
        }
@@ -466,7 +476,8 @@ static void bump(char *fmt, ...)
  */
 static void do_cmd(char *host, char *user, char *cmd)
 {
-    char *err, *realhost;
+    const char *err;
+    char *realhost;
     DWORD namelen;
 
     if (host == NULL || host[0] == '\0')
@@ -493,7 +504,7 @@ static void do_cmd(char *host, char *user, char *cmd)
     /*
      * Enact command-line overrides.
      */
-    cmdline_run_saved();
+    cmdline_run_saved(&cfg);
 
     /*
      * Trim leading whitespace off the hostname if it's there.
@@ -544,7 +555,7 @@ static void do_cmd(char *host, char *user, char *cmd)
        namelen = 0;
        if (GetUserName(user, &namelen) == FALSE)
            bump("Empty user name");
-       user = smalloc(namelen * sizeof(char));
+       user = snewn(namelen, char);
        GetUserName(user, &namelen);
        if (verbose)
            tell_user(stderr, "Guessing user name: %s", user);
@@ -574,11 +585,12 @@ static void do_cmd(char *host, char *user, char *cmd)
 
     back = &ssh_backend;
 
-    err = back->init(NULL, &backhandle, cfg.host, cfg.port, &realhost, 0);
+    err = back->init(NULL, &backhandle, &cfg, cfg.host, cfg.port, &realhost,0);
     if (err != NULL)
        bump("ssh_init: %s", err);
-    logctx = log_init(NULL);
+    logctx = log_init(NULL, &cfg);
     back->provide_logctx(backhandle, logctx);
+    console_provide_logctx(logctx);
     ssh_scp_init();
     if (verbose && realhost != NULL)
        tell_user(stderr, "Connected to %s\n", realhost);
@@ -775,8 +787,7 @@ void scp_sftp_listdir(char *dirname)
 
            if (nnames + names->nnames >= namesize) {
                namesize += names->nnames + 128;
-               ournames =
-                   srealloc(ournames, namesize * sizeof(*ournames));
+               ournames = sresize(ournames, namesize, struct fxp_name);
            }
 
            for (i = 0; i < names->nnames; i++)
@@ -1062,7 +1073,7 @@ int scp_sink_setup(char *source, int preserve, int recursive)
         * wildcardness comes before the final slash) and arrange
         * things so that a dirstack entry will be set up.
         */
-       newsource = smalloc(1+strlen(source));
+       newsource = snewn(1+strlen(source), char);
        if (!wc_unescape(newsource, source)) {
            /* Yes, here we go; it's a wildcard. Bah. */
            char *dupsource, *lastpart, *dirpart, *wildcard;
@@ -1095,7 +1106,7 @@ int scp_sink_setup(char *source, int preserve, int recursive)
             * wildcard escapes from the directory part, throwing
             * an error if it contains a real wildcard.
             */
-           dirpart = smalloc(1+strlen(dupsource));
+           dirpart = snewn(1+strlen(dupsource), char);
            if (!wc_unescape(dirpart, dupsource)) {
                tell_user(stderr, "%s: multiple-level wildcards unsupported",
                          source);
@@ -1304,8 +1315,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
                }
                if (nnames + names->nnames >= namesize) {
                    namesize += names->nnames + 128;
-                   ournames =
-                       srealloc(ournames, namesize * sizeof(*ournames));
+                   ournames = sresize(ournames, namesize, struct fxp_name);
                }
                for (i = 0; i < names->nnames; i++)
                    ournames[nnames++] = names->names[i];
@@ -1314,7 +1324,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
            }
            fxp_close(dirhandle);
 
-           newitem = smalloc(sizeof(struct scp_sftp_dirstack));
+           newitem = snew(struct scp_sftp_dirstack);
            newitem->next = scp_sftp_dirstack_head;
            newitem->names = ournames;
            newitem->namepos = 0;
@@ -1402,7 +1412,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
                    bump("Lost connection");
                if (i >= bufsize) {
                    bufsize = i + 128;
-                   act->buf = srealloc(act->buf, bufsize);
+                   act->buf = sresize(act->buf, bufsize, char);
                }
                act->buf[i++] = ch;
            } while (ch != '\n');
@@ -2078,7 +2088,7 @@ static void get_dir_list(int argc, char *argv[])
            user = NULL;
     }
 
-    cmd = smalloc(4 * strlen(src) + 100);
+    cmd = snewn(4 * strlen(src) + 100, char);
     strcpy(cmd, "ls -la '");
     p = cmd + strlen(cmd);
     for (q = src; *q; q++) {
@@ -2179,7 +2189,7 @@ int main(int argc, char *argv[])
 
     default_protocol = PROT_TELNET;
 
-    flags = FLAG_STDERR;
+    flags = FLAG_STDERR | FLAG_SYNCAGENT;
     cmdline_tooltype = TOOLTYPE_FILETRANSFER;
     ssh_get_line = &console_get_line;
     init_winsock();
@@ -2189,7 +2199,7 @@ int main(int argc, char *argv[])
        int ret;
        if (argv[i][0] != '-')
            break;
-       ret = cmdline_process_param(argv[i], i+1<argc?argv[i+1]:NULL, 1);
+       ret = cmdline_process_param(argv[i], i+1<argc?argv[i+1]:NULL, 1, &cfg);
        if (ret == -2) {
            cmdline_error("option \"%s\" requires an argument", argv[i]);
        } else if (ret == 2) {