static char *gui_hwnd = NULL;
static int using_sftp = 0;
+static Backend *back;
+static void *backhandle;
+static Config cfg;
+
static void source(char *src);
static void rsource(char *src);
static void sink(char *targ, char *src);
*/
#define MAX_SCP_BUFSIZE 16384
-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,
static void tell_user(FILE * stream, char *fmt, ...)
{
- char str[0x100]; /* Make the size big enough */
+ char *str, *str2;
va_list ap;
va_start(ap, fmt);
- vsprintf(str, fmt, ap);
+ str = dupvprintf(fmt, ap);
va_end(ap);
- strcat(str, "\n");
- tell_str(stream, str);
+ str2 = dupcat(str, "\n", NULL);
+ sfree(str);
+ tell_str(stream, str2);
+ sfree(str2);
}
static void gui_update_stats(char *name, unsigned long size,
*/
void fatalbox(char *fmt, ...)
{
- char str[0x100]; /* Make the size big enough */
+ char *str, *str2;
va_list ap;
va_start(ap, fmt);
- strcpy(str, "Fatal: ");
- vsprintf(str + strlen(str), fmt, ap);
+ str = dupvprintf(fmt, ap);
+ str2 = dupcat("Fatal: ", str, "\n", NULL);
+ sfree(str);
va_end(ap);
- strcat(str, "\n");
- tell_str(stderr, str);
+ tell_str(stderr, str2);
+ sfree(str2);
errs++;
if (gui_mode) {
}
void modalfatalbox(char *fmt, ...)
{
- char str[0x100]; /* Make the size big enough */
+ char *str, *str2;
va_list ap;
va_start(ap, fmt);
- strcpy(str, "Fatal: ");
- vsprintf(str + strlen(str), fmt, ap);
+ str = dupvprintf(fmt, ap);
+ str2 = dupcat("Fatal: ", str, "\n", NULL);
+ sfree(str);
va_end(ap);
- strcat(str, "\n");
- tell_str(stderr, str);
+ tell_str(stderr, str2);
+ sfree(str2);
errs++;
if (gui_mode) {
cleanup_exit(1);
}
-void connection_fatal(char *fmt, ...)
+void connection_fatal(void *frontend, char *fmt, ...)
{
- char str[0x100]; /* Make the size big enough */
+ char *str, *str2;
va_list ap;
va_start(ap, fmt);
- strcpy(str, "Fatal: ");
- vsprintf(str + strlen(str), fmt, ap);
+ str = dupvprintf(fmt, ap);
+ str2 = dupcat("Fatal: ", str, "\n", NULL);
+ sfree(str);
va_end(ap);
- strcat(str, "\n");
- tell_str(stderr, str);
+ tell_str(stderr, str2);
+ sfree(str2);
errs++;
if (gui_mode) {
{
if (scp_ssh_socket == INVALID_SOCKET)
return;
- while (!back->sendok()) {
+ while (!back->sendok(backhandle)) {
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(scp_ssh_socket, &readfds);
return; /* doom */
select_result((WPARAM) scp_ssh_socket, (LPARAM) FD_READ);
}
- using_sftp = !ssh_fallback_cmd;
+ using_sftp = !ssh_fallback_cmd(backhandle);
}
/*
*/
static void bump(char *fmt, ...)
{
- char str[0x100]; /* Make the size big enough */
+ char *str, *str2;
va_list ap;
va_start(ap, fmt);
- strcpy(str, "Fatal: ");
- vsprintf(str + strlen(str), fmt, ap);
+ str = dupvprintf(fmt, ap);
va_end(ap);
- strcat(str, "\n");
- tell_str(stderr, str);
+ str2 = dupcat(str, "\n", NULL);
+ sfree(str);
+ tell_str(stderr, str2);
+ sfree(str2);
errs++;
- if (back != NULL && back->socket() != NULL) {
+ if (back != NULL && back->socket(backhandle) != NULL) {
char ch;
- back->special(TS_EOF);
+ back->special(backhandle, TS_EOF);
ssh_scp_recv(&ch, 1);
}
/*
* Enact command-line overrides.
*/
- cmdline_run_saved();
+ cmdline_run_saved(&cfg);
/*
* Trim leading whitespace off the hostname if it's there.
back = &ssh_backend;
- err = back->init(NULL, 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, &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);
}
int sftp_senddata(char *buf, int len)
{
- back->send((unsigned char *) buf, len);
+ back->send(backhandle, (unsigned char *) buf, len);
return 1;
}
if (!fxp_init()) {
tell_user(stderr, "unable to initialise SFTP: %s", fxp_error());
errs++;
- return 1;
+ return;
}
if (!fxp_stat(target, &attrs) ||
if (using_sftp) {
/* do nothing; we never need to send our errors to the server */
} else {
- back->send("\001", 1); /* scp protocol error prefix */
- back->send(str, strlen(str));
+ back->send(backhandle, "\001", 1);/* scp protocol error prefix */
+ back->send(backhandle, str, strlen(str));
}
return 0; /* can't fail */
}
} else {
char buf[80];
sprintf(buf, "T%lu 0 %lu 0\n", mtime, atime);
- back->send(buf, strlen(buf));
+ back->send(backhandle, buf, strlen(buf));
return response();
}
}
} else {
char buf[40];
sprintf(buf, "C%04o %lu ", modes, size);
- back->send(buf, strlen(buf));
- back->send(name, strlen(name));
- back->send("\n", 1);
+ back->send(backhandle, buf, strlen(buf));
+ back->send(backhandle, name, strlen(name));
+ back->send(backhandle, "\n", 1);
return response();
}
}
scp_sftp_fileoffset = uint64_add32(scp_sftp_fileoffset, len);
return 0;
} else {
- int bufsize = back->send(data, len);
+ int bufsize = back->send(backhandle, data, len);
/*
* If the network transfer is backing up - that is, the
while (bufsize > MAX_SCP_BUFSIZE) {
if (!scp_process_network_event())
return 1;
- bufsize = back->sendbuffer();
+ bufsize = back->sendbuffer(backhandle);
}
return 0;
scp_has_times = 0;
return 0;
} else {
- back->send("", 1);
+ back->send(backhandle, "", 1);
return response();
}
}
} else {
char buf[40];
sprintf(buf, "D%04o 0 ", modes);
- back->send(buf, strlen(buf));
- back->send(name, strlen(name));
- back->send("\n", 1);
+ back->send(backhandle, buf, strlen(buf));
+ back->send(backhandle, name, strlen(name));
+ back->send(backhandle, "\n", 1);
return response();
}
}
sfree(scp_sftp_remotepath);
return 0;
} else {
- back->send("E\n", 2);
+ back->send(backhandle, "E\n", 2);
return response();
}
}
int scp_sink_init(void)
{
if (!using_sftp) {
- back->send("", 1);
+ back->send(backhandle, "", 1);
}
return 0;
}
case '\02': /* fatal error */
bump("%s", act->buf);
case 'E':
- back->send("", 1);
+ back->send(backhandle, "", 1);
act->action = SCP_SINK_ENDDIR;
return 0;
case 'T':
if (sscanf(act->buf, "%ld %*d %ld %*d",
&act->mtime, &act->atime) == 2) {
act->settime = 1;
- back->send("", 1);
+ back->send(backhandle, "", 1);
continue; /* go round again */
}
bump("Protocol error: Illegal time format");
sfree(scp_sftp_currentname);
return 0;
} else {
- back->send("", 1);
+ back->send(backhandle, "", 1);
return 0; /* can't fail */
}
}
fxp_close(scp_sftp_filehandle);
return 0;
} else {
- back->send("", 1);
+ back->send(backhandle, "", 1);
return response();
}
}
*/
static void run_err(const char *fmt, ...)
{
- char str[2048];
+ char *str, *str2;
va_list ap;
va_start(ap, fmt);
errs++;
- strcpy(str, "scp: ");
- vsprintf(str + strlen(str), fmt, ap);
- strcat(str, "\n");
- scp_send_errmsg(str);
- tell_user(stderr, "%s", str);
+ str = dupvprintf(fmt, ap);
+ str2 = dupcat("scp: ", str, "\n", NULL);
+ sfree(str);
+ scp_send_errmsg(str2);
+ tell_user(stderr, "%s", str2);
va_end(ap);
+ sfree(str2);
}
/*
FindClose(fh);
}
- cmd = smalloc(strlen(targ) + 100);
- sprintf(cmd, "scp%s%s%s%s -t %s",
- verbose ? " -v" : "",
- recursive ? " -r" : "",
- preserve ? " -p" : "",
- targetshouldbedirectory ? " -d" : "", targ);
+ cmd = dupprintf("scp%s%s%s%s -t %s",
+ verbose ? " -v" : "",
+ recursive ? " -r" : "",
+ preserve ? " -p" : "",
+ targetshouldbedirectory ? " -d" : "", targ);
do_cmd(host, user, cmd);
sfree(cmd);
user = NULL;
}
- cmd = smalloc(strlen(src) + 100);
- sprintf(cmd, "scp%s%s%s%s -f %s",
- verbose ? " -v" : "",
- recursive ? " -r" : "",
- preserve ? " -p" : "",
- targetshouldbedirectory ? " -d" : "", src);
+ cmd = dupprintf("scp%s%s%s%s -f %s",
+ verbose ? " -v" : "",
+ recursive ? " -r" : "",
+ preserve ? " -p" : "",
+ targetshouldbedirectory ? " -d" : "", src);
do_cmd(host, user, cmd);
sfree(cmd);
va_start(ap, p);
vfprintf(stderr, p, ap);
va_end(ap);
- fputc('\n', stderr);
+ fprintf(stderr, "\n try typing just \"pscp\" for help\n");
exit(1);
}
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) {
} else if (strcmp(argv[i], "--") == 0) {
i++;
break;
- } else
- usage();
+ } else {
+ cmdline_error("unknown option \"%s\"", argv[i]);
+ }
}
argc -= i;
argv += i;
tolocal(argc, argv);
}
- if (back != NULL && back->socket() != NULL) {
+ if (back != NULL && back->socket(backhandle) != NULL) {
char ch;
- back->special(TS_EOF);
+ back->special(backhandle, TS_EOF);
ssh_scp_recv(&ch, 1);
}
WSACleanup();