tlsgate

TLS reverse proxy
git clone git://git.akobets.xyz/tlsgate
Log | Files | Refs | README | LICENSE

commit 09d51900482fdd8494ea54ac30133366059ac338
parent 985365b3b47033c359b2535d5e481250dbca3d5b
Author: Artem Kobets <artem@akobets.xyz>
Date:   Wed,  2 Sep 2020 15:24:36 +0300

replace arg.h with getopt

Diffstat:
Darg.h | 49-------------------------------------------------
Mmain.c | 34+++++++++++++++++++---------------
2 files changed, 19 insertions(+), 64 deletions(-)

diff --git a/arg.h b/arg.h @@ -1,49 +0,0 @@ -/* - * Copy me if you can. - * by 20h - */ - -#ifndef ARG_H__ -#define ARG_H__ - -extern char *argv0; - -/* use main(int argc, char *argv[]) */ -#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ - argv[0] && argv[0][0] == '-'\ - && argv[0][1];\ - argc--, argv++) {\ - char argc_;\ - char **argv_;\ - int brk_;\ - if (argv[0][1] == '-' && argv[0][2] == '\0') {\ - argv++;\ - argc--;\ - break;\ - }\ - for (brk_ = 0, argv[0]++, argv_ = argv;\ - argv[0][0] && !brk_;\ - argv[0]++) {\ - if (argv_ != argv)\ - break;\ - argc_ = argv[0][0];\ - switch (argc_) - -#define ARGEND }\ - } - -#define ARGC() argc_ - -#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ - ((x), abort(), (char *)0) :\ - (brk_ = 1, (argv[0][1] != '\0')?\ - (&argv[0][1]) :\ - (argc--, argv++, argv[0]))) - -#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\ - (char *)0 :\ - (brk_ = 1, (argv[0][1] != '\0')?\ - (&argv[0][1]) :\ - (argc--, argv++, argv[0]))) - -#endif diff --git a/main.c b/main.c @@ -11,17 +11,16 @@ #include <sys/socket.h> #include <tls.h> -#include "arg.h" #include "serve.h" #include "sock.h" #include "util.h" #define SOCK_TIMEOUT_SECS 30 -char *argv0; +static void sigchld(int unused); +static void usage(); -void sigchld(int unused); -void usage(); +static char *argv0; void sigchld(int unused) @@ -43,6 +42,7 @@ usage() int main(int argc, char **argv) { + int opt; char *cert_file = NULL; char *key_file = NULL; char *ca_file = NULL; @@ -60,38 +60,42 @@ main(int argc, char **argv) struct sigaction act; sigset_t sigmask; - ARGBEGIN { + argv0 = argv[0]; + + while ((opt = getopt(argc, argv, "c:k:C:h:p:H:P:U:"))) { + switch (opt) { case 'c': - cert_file = EARGF(usage()); + cert_file = optarg; break; case 'k': - key_file = EARGF(usage()); + key_file = optarg; break; case 'C': - ca_file = EARGF(usage()); + ca_file = optarg; break; case 'n': - maxnprocs = atol(EARGF(usage())); + maxnprocs = atol(optarg); break; case 'h': - server_host = EARGF(usage()); + server_host = optarg; break; case 'p': - server_port = EARGF(usage()); + server_port = optarg; break; case 'H': - client_host = EARGF(usage()); + client_host = optarg; break; case 'P': - client_port = EARGF(usage()); + client_port = optarg; break; case 'U': - client_udsfile = EARGF(usage()); + client_udsfile = optarg; break; default: usage(); break; - } ARGEND + } + } /* cert and private key files are required */ if (cert_file == NULL || key_file == NULL)