Correct pointer types in new clipme function
[u/mdw/putty] / scp.c
diff --git a/scp.c b/scp.c
index 81f925b..3f85006 100644 (file)
--- a/scp.c
+++ b/scp.c
@@ -53,13 +53,12 @@ static int statistics = 1;
 static int portnumber = 0;
 static char *password = NULL;
 static int errs = 0;
-static int connection_open = 0;
 /* GUI Adaptation - Sept 2000 */
 #define NAME_STR_MAX 2048
 static char statname[NAME_STR_MAX+1];
 static unsigned long statsize = 0;
 static int statperct = 0;
-static time_t statelapsed = 0;
+static unsigned long statelapsed = 0;
 static int gui_mode = 0;
 static char *gui_hwnd = NULL;
 
@@ -72,7 +71,8 @@ static void tell_str(FILE *stream, char *str);
 static void tell_user(FILE *stream, char *fmt, ...);
 static void send_char_msg(unsigned int msg_id, char c);
 static void send_str_msg(unsigned int msg_id, char *str);
-static void gui_update_stats(char *name, unsigned long size, int percentage, time_t elapsed);
+static void gui_update_stats(char *name, unsigned long size,
+                             int percentage, unsigned long elapsed);
 
 void begin_session(void) { }
 void logevent(char *string) { }
@@ -183,7 +183,7 @@ static void tell_user(FILE *stream, char *fmt, ...)
     tell_str(stream, str);
 }
 
-static void gui_update_stats(char *name, unsigned long size, int percentage, time_t elapsed)
+static void gui_update_stats(char *name, unsigned long size, int percentage, unsigned long elapsed)
 {
     unsigned int i;
 
@@ -377,7 +377,7 @@ static void bump(char *fmt, ...)
     strcat(str, "\n");
     tell_str(stderr, str);
 
-    if (connection_open) {
+    if (back != NULL && back->socket() != NULL) {
        char ch;
        back->special(TS_EOF);
        ssh_scp_recv(&ch, 1);
@@ -444,6 +444,7 @@ static void do_cmd(char *host, char *user, char *cmd)
     do_defaults(host, &cfg);
     if (cfg.host[0] == '\0') {
        /* No settings for this host; use defaults */
+        do_defaults(NULL, &cfg);
        strncpy(cfg.host, host, sizeof(cfg.host)-1);
        cfg.host[sizeof(cfg.host)-1] = '\0';
        cfg.port = 22;
@@ -475,8 +476,6 @@ static void do_cmd(char *host, char *user, char *cmd)
     ssh_scp_init();
     if (verbose && realhost != NULL)
        tell_user(stderr, "Connected to %s\n", realhost);
-
-    connection_open = 1;
 }
 
 /*
@@ -492,7 +491,8 @@ static void print_stats(char *name, unsigned long size, unsigned long done,
 
     /* GUI Adaptation - Sept 2000 */
     if (gui_mode)
-       gui_update_stats(name, size, ((done *100) / size), now-start);
+       gui_update_stats(name, size, (int)(100 * (done*1.0/size)),
+                         (unsigned long)difftime(now, start));
     else {
        if (now > start)
            ratebs = (float) done / (now - start);
@@ -828,12 +828,6 @@ static void sink(char *targ, char *src)
        if (sscanf(buf+1, "%u %lu %[^\n]", &mode, &size, namebuf) != 3)
            bump("Protocol error: Illegal file descriptor format");
        /* Security fix: ensure the file ends up where we asked for it. */
-       if (src) {
-           char *p = src + strlen(src);
-           while (p > src && p[-1] != '/' && p[-1] != '\\')
-               p--;
-           strcpy(namebuf, p);
-       }
        if (targisdir) {
            char t[2048];
            char *p;
@@ -1215,6 +1209,7 @@ int main(int argc, char *argv[])
     }
     argc -= i;
     argv += i;
+    back = NULL;
 
     if (list) {
        if (argc != 1)
@@ -1234,7 +1229,7 @@ int main(int argc, char *argv[])
            tolocal(argc, argv);
     }
 
-    if (connection_open) {
+    if (back != NULL && back->socket() != NULL) {
        char ch;
        back->special(TS_EOF);
        ssh_scp_recv(&ch, 1);