Skip to content

Commit

Permalink
added user:pass@host parsing, and moved junk files out of cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsiomb committed Feb 22, 2023
1 parent 8f4660a commit 7e0c9a5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
13 changes: 13 additions & 0 deletions scripts/pull.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mkdir src
rsync -v 192.168.0.4::visftp/Makefile Makefile
rsync -v 192.168.0.4::visftp/src/*.c src
rsync -v 192.168.0.4::visftp/src/*.h src

mkdir libs
rsync -rv 192.168.0.4::visftp/libs/watt32 libs

mkdir scripts
rsync -v 192.168.0.4::visftp/scripts/* scripts

mkdir doc
rsync -v 192.168.0.4::visftp/doc/* doc
58 changes: 53 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static void view_done(struct ftp *ftp, struct ftp_transfer *xfer);
static int read_servers(const char *fname);
static struct server *find_server(const char *name);
static int parse_args(int argc, char **argv);
static int parse_host(const char *str);

static struct ftp *ftp;
static struct tui_widget *uilist[2];
Expand All @@ -65,6 +66,7 @@ static unsigned int dirty;

static char *host = "localhost";
static int port = 21;
static const char *opt_user, *opt_pass;
static struct server *srvlist;

static char curdir[PATH_MAX + 1];
Expand Down Expand Up @@ -95,7 +97,11 @@ int main(int argc, char **argv)
return 1;
}

#ifdef __DOS__
read_servers("visftp.srv");
#else
read_servers(".visftp.srv");
#endif

localdir = darr_alloc(0, sizeof *localdir);
getcwd(curdir, sizeof curdir);
Expand All @@ -105,8 +111,13 @@ int main(int argc, char **argv)
return 1;
}

if((srv = find_server(host)) && srv->user) {
ftp_auth(ftp, srv->user, srv->pass ? srv->pass : "foobar");
if((srv = find_server(host)) && !opt_user && srv->user) {
opt_user = srv->user;
opt_pass = srv->pass;
}

if(opt_user) {
ftp_auth(ftp, opt_user, opt_pass ? opt_pass : "foobar");
}

if(ftp_connect(ftp, srv ? srv->host : host, port) == -1) {
Expand Down Expand Up @@ -679,10 +690,24 @@ static void view_done(struct ftp *ftp, struct ftp_transfer *xfer)

int read_servers(const char *fname)
{
const char *str;
char *path;
const char *str, *cfgdir;
struct ts_node *ts, *node;
struct server srv;

#ifdef __DOS__
cfgdir = getenv("VISFTP");
#else
cfgdir = getenv("HOME");
#endif

if(cfgdir) {
int len = strlen(fname) + strlen(cfgdir) + 1;
path = alloca(len + 1);
sprintf(path, "%s/%s", cfgdir, fname);
fname = path;
}

if(!(ts = ts_load(fname)) || strcmp(ts->name, "servers") != 0) {
return -1;
}
Expand Down Expand Up @@ -736,7 +761,7 @@ struct server *find_server(const char *name)
return 0;
}

static const char *usage = "Usage: %s [options] [hostname] [port]\n"
static const char *usage = "Usage: %s [options] [[user[:pass]@]hostname] [port]\n"
"Options:\n"
" -h: print usage information and exit\n";

Expand All @@ -761,7 +786,9 @@ int parse_args(int argc, char **argv)
} else {
switch(argidx++) {
case 0:
host = argv[i];
if(parse_host(argv[i]) == -1) {
return -1;
}
break;

case 1:
Expand All @@ -784,6 +811,27 @@ int parse_args(int argc, char **argv)
return -1;
}

static int parse_host(const char *str)
{
char *p;

if((p = strchr(str, '@'))) {
*p = 0;
opt_user = str;
host = p + 1;
if((p = strchr(str, ':'))) {
*p = 0;
opt_pass = p + 1;
} else {
opt_pass = 0;
}
} else {
opt_user = opt_pass = 0;
}

return 0;
}

#ifdef __DOS__
#include <dos.h>
#include <i86.h>
Expand Down
3 changes: 3 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ static void logmsg(const char *tag, const char *fmt, va_list ap)
char *fname;
#ifdef __DOS__
char *tmpdir = getenv("TEMP");
if(!tmpdir) {
tmpdir = getenv("VISFTP");
}
if(tmpdir) {
fname = alloca(strlen(tmpdir) + 16);
sprintf(fname, "%s\\visftp.log", tmpdir);
Expand Down
8 changes: 4 additions & 4 deletions src/viewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ void view_update(void)
int x, i, c, ts;
char *ptr, *end;
struct span *span;
static const char *bntext[] = {
"Help ", " ", " ", "Hex ", " ",
" ", "Search", " ", " ", "Quit "
};

if(!dirty) return;

Expand Down Expand Up @@ -124,6 +120,10 @@ void view_update(void)
}

if(dirty & UI_BUTTONS) {
static const char *bntext[] = {
"Help ", " ", " ", "Hex ", " ",
" ", "Search", " ", " ", "Quit "
};
x = 0;
for(i=0; i<10; i++) {
tg_fgcolor(TGFX_WHITE);
Expand Down

0 comments on commit 7e0c9a5

Please sign in to comment.