commit 6d62a876c40a885b373144952d15344ec82dcf6b
parent 12c16735ffa28a0c873ae55df969995f475049a5
Author: hhvn <dev@hhvn.uk>
Date: Mon, 17 Jan 2022 18:40:42 +0000
zygo.c zygo.h zygo.1 tls.c: cli flags
Diffstat:
4 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/tls.c b/tls.c
@@ -31,7 +31,7 @@ net_connect(Elem *e) {
goto fail;
}
- if (!config[CONF_TLS_VERIFY]) {
+ if (insecure) {
tls_config_insecure_noverifycert(conf);
tls_config_insecure_noverifyname(conf);
}
diff --git a/zygo.1 b/zygo.1
@@ -22,6 +22,7 @@
.Nd ncurses gopher client
.Sh SYNOPSIS
.Nm
+.Op Fl kv
.Op Ar uri
.Sh DESCRIPTION
.Nm
@@ -32,6 +33,12 @@ and has pager functionality using ncurses.
.Nm
supports gopher over tls, although it may be buggy.
The user may attempt to downgrade any tls connection if it fails.
+.Sh OPTIONS
+.Bl -compact -tag
+.It Fl v
+Print version info.
+.It Fl k
+Turn off certificate checking for TLS.
.Sh INPUT
.Nm
is constantly reading input.
diff --git a/zygo.c b/zygo.c
@@ -36,10 +36,7 @@
List *history = NULL;
List *page = NULL;
Elem *current = NULL;
-
-int config[] = {
- [CONF_TLS_VERIFY] = 1,
-};
+int insecure = 0;
struct {
int scroll;
@@ -993,9 +990,16 @@ sighandler(int signal) {
}
}
+void
+usage(char *argv0) {
+ fprintf(stderr, "usage: %s [-kv] [uri]\n", basename(argv0));
+ exit(EXIT_FAILURE);
+}
+
int
main(int argc, char *argv[]) {
- Elem *target;
+ Elem *target = NULL;
+ char *s;
int i;
Elem start[] = {
{0, '3', "No URI specified, or unable to locate URI."},
@@ -1014,15 +1018,31 @@ main(int argc, char *argv[]) {
for (i = 0; start[i].desc; i++)
list_append(&page, &start[i]);
- switch (argc) {
- case 2:
- target = uritoelem(argv[1]);
- go(target, 1);
- case 1:
- break;
- default:
- fprintf(stderr, "usage: %s [uri]\n", basename(argv[0]));
- exit(EXIT_FAILURE);
+ for (i = 1; i < argc; i++) {
+ if ((*argv[i] == '-' && *(argv[i]+1) == '\0') ||
+ (*argv[i] != '-' && target)) {
+ usage(argv[0]);
+ } else if (*argv[i] == '-') {
+ for (s = argv[i]+1; *s; s++) {
+ switch (*s) {
+ case 'k':
+#ifdef TLS
+ insecure = 1;
+#else
+ error("TLS support not compiled");
+#endif /* TLS */
+ break;
+ case 'v':
+ fprintf(stderr, "zygo %s\n", COMMIT);
+ exit(EXIT_SUCCESS);
+ default:
+ usage(argv[0]);
+ }
+ }
+ } else {
+ target = uritoelem(argv[argc-1]);
+ go(target, 1);
+ }
}
setlocale(LC_ALL, "");
diff --git a/zygo.h b/zygo.h
@@ -50,10 +50,6 @@ struct Scheme {
};
enum {
- CONF_TLS_VERIFY = 'k',
-};
-
-enum {
PAIR_BAR = 1,
PAIR_URI = 2,
PAIR_CMD = 3,
@@ -66,7 +62,7 @@ enum {
extern List *history;
extern List *page;
extern Elem *current;
-extern int config[];
+extern int insecure;
/* Memory functions */
void *emalloc(size_t size);