config: allow to set options as application arguments

This commit is contained in:
Hiltjo Posthuma 2014-08-14 16:56:07 +00:00 committed by FRIGN
parent 3962978bdd
commit 8aa3e3f48f
2 changed files with 48 additions and 14 deletions

View file

@ -1,25 +1,26 @@
/* quark configuration */
static const char servername[] = "127.0.0.1";
static const char serverport[] = "80";
static const char docroot[] = ".";
static const char docindex[] = "index.html";
static const char *user = "nobody";
static const char *group = "nogroup";
static const char cgi_dir[] = "/var/www/werc-dev/bin";
static const char cgi_script[] = "./werc.rc";
static const int cgi_mode = 0;
static const char *servername = "127.0.0.1";
static const char *serverport = "80";
static const char *docroot = ".";
static const char *docindex = "index.html";
static const char *user = "nobody";
static const char *group = "nobody";
static const char *cgi_dir = ".";
static const char *cgi_script = "/werc.rc";
static int cgi_mode = 0;
static const MimeType servermimes[] = {
{ "html", "text/html; charset=UTF-8" },
{ "htm", "text/html; charset=UTF-8" },
{ "css", "text/css" },
{ "js", "application/javascript" },
{ "txt", "text/plain" },
{ "text", "text/plain" },
{ "md", "text/plain" },
{ "png", "image/png" },
{ "gif", "image/gif" },
{ "jpg", "image/jpg" },
{ "jpeg", "image/jpeg" },
{ "jpg", "image/jpeg" },
{ "iso", "application/x-iso9660-image" },
{ "gz", "application/x-gtar" },
{ "pdf", "application/x-pdf" },

39
quark.c
View file

@ -505,6 +505,12 @@ sighandler(int sig) {
}
}
void
usage(void) {
die("usage: %s [-c] [-d cgidir] [-e cgiscript] [-u user] [-g group] "
"[-i index] [-r docroot] [-s server] [-p port] [-v]\n", argv0);
}
int
main(int argc, char *argv[]) {
struct addrinfo hints, *ai = NULL;
@ -513,16 +519,43 @@ main(int argc, char *argv[]) {
int i;
ARGBEGIN {
case 'c':
cgi_mode = 1;
break;
case 'd':
cgi_dir = EARGF(usage());
break;
case 'e':
cgi_script = EARGF(usage());
break;
case 'u':
user = EARGF(usage());
break;
case 'g':
group = EARGF(usage());
break;
case 'i':
docindex = EARGF(usage());
break;
case 'r':
docroot = EARGF(usage());
break;
case 'p':
serverport = EARGF(usage());
break;
case 's':
servername = EARGF(usage());
break;
case 'v':
die("quark-"VERSION"\n");
default:
die("usage: %s [-v]\n", argv0);
usage();
} ARGEND;
/* sanity checks */
if (user && !(upwd = getpwnam(user)))
if (*user && !(upwd = getpwnam(user)))
die("error\tinvalid user %s\n", user);
if (group && !(gpwd = getgrnam(group)))
if (*group && !(gpwd = getgrnam(group)))
die("error\tinvalid group %s\n", group);
signal(SIGCHLD, sighandler);