diff options
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/fileserv.8 | 5 | ||||
-rw-r--r-- | src/fileserv.c | 57 |
3 files changed, 44 insertions, 20 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index d871c86..e943d6c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ -bin_PROGRAMS=fileserv +sbin_PROGRAMS=fileserv fileserv_SOURCES=fileserv.c runas.c fileserv.h logger.c pidfile.c\ wordsplit.c wordsplit.h catfile.c config.c idx.c defidx.h\ mem.c remoteip.c icon.c dirls.c dirls.h lang.c httperr.c BUILT_SOURCES=defidx.h if FSRV_WRAP fileserv_SOURCES += wrapacl.c diff --git a/src/fileserv.8 b/src/fileserv.8 index a0204a3..11129f0 100644 --- a/src/fileserv.8 +++ b/src/fileserv.8 @@ -10,13 +10,13 @@ .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public License .\" along with fileserv. If not, see <http://www.gnu.org/licenses/>. -.TH FILESERV 8 "April 20, 2018" "FILESERV" "User Commands" +.TH FILESERV 8 "April 21, 2018" "FILESERV" "User Commands" .SH NAME fileserv \- simple http server for static files .SH SYNOPSIS \fBfileserv\fR\ [\fB\-fhsv\fR]\ [\fB\-a\fR [\fIIP\fR][\fB:\fIPORT\fR]]\ @@ -81,12 +81,15 @@ name of a user listed in the system user database, or a numeric UID prefixed with a plus sign. .sp This option overrides the \fBuser\fR configuration setting. .TP .B \-v Increase verbosity level. Multiple options accumulate. +.TP +.B \-V +Show program version, license and copyright information. .SH CONFIGURATION FILE The server reads most of its settings from the configuration file \fB/etc/fileserv.conf\fR (the default location can be overridden using the \fB\-c\fR command line option). The file has a traditional UNIX configuration file syntax. Each statement occupies a single line and consists of configuration keyword followed by one or more diff --git a/src/fileserv.c b/src/fileserv.c index fb9811d..58262c3 100644 --- a/src/fileserv.c +++ b/src/fileserv.c @@ -32,21 +32,54 @@ #endif #ifndef DEFAULT_SERVICE # define DEFAULT_SERVICE "8080" #endif char const *progname; -int verbose; /* reserved for future use */ +int verbose; /* increase diagnostic verbosity */ char *address = DEFAULT_ADDRESS; char *forwarded_header = "X-Forwarded-For"; char *index_css; char *tmpdir; char *user; char *group; char *mime_types_file; + +void +usage(void) +{ + printf("usage: %s [OPTIONS] [HOST:]URL:DIR...\n", progname); + printf("Simple HTTP server.\n"); + printf("OPTIONS are:\n\n"); + printf(" -a [IP]:PORT listen on this IP and PORT\n"); + printf(" -c FILE read configuration from FILE\n"); + printf(" -f remain in the foreground\n"); + printf(" -g GROUP run with this group privileges\n"); + printf(" -h show this help summary\n"); + printf(" -s don't start sentinel process\n"); + printf(" -u USER run with this user privileges\n"); + printf(" -v increase verbosity\n"); + printf(" -V show program version\n"); + printf("\n"); +} +const char version_copyright[] = "Copyright (C) 2017-2018 Sergey Poznyakoff"; +const char gplv3[] = "\ +License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\ +This is free software: you are free to change and redistribute it.\n\ +There is NO WARRANTY, to the extent permitted by law.\ +"; + +static void +show_version(void) +{ + printf("%s\n", PACKAGE_STRING); + printf("%s\n", version_copyright); + printf("\n%s\n\n", gplv3); +} + static void fileserv_panic(void *cls, const char *file, unsigned int line, const char *reason) { if (reason) error("%s:%d: MHD PANIC: %s", file, line, reason); @@ -81,28 +114,13 @@ errno_to_http_code(int ec) case ENOENT: return MHD_HTTP_NOT_FOUND; default: return MHD_HTTP_FORBIDDEN; } } - -void -usage(void) -{ - printf("usage: %s [OPTIONS] [HOST:]URL:DIR...\n", progname); - printf("OPTIONS are:\n\n"); - printf(" -a [IP]:PORT listen on this IP and PORT\n"); - printf(" -c FILE read configuration from FILE\n"); - printf(" -f remain in the foreground\n"); - printf(" -g GROUP run with this group privileges\n"); - printf(" -h show this help summary\n"); - printf(" -s don't start sentinel process\n"); - printf(" -u USER run with this user privileges\n"); - printf(" -v increase verbosity\n"); -} - + int open_node(char const *node, char const *serv, struct sockaddr **saddr) { struct addrinfo hints; struct addrinfo *res; int reuse; @@ -778,13 +796,13 @@ main(int argc, char **argv) mimetypes_error_printer = fileserv_error_printer; tmpdir = getenv("TMP"); if (!tmpdir) tmpdir = "/tmp"; - while ((c = getopt(argc, argv, "a:c:fg:hsu:v")) != EOF) { + while ((c = getopt(argc, argv, "a:c:fg:hsu:vV")) != EOF) { switch (c) { case 'a': opt_address = optarg; break; case 'c': config_file = optarg; @@ -804,12 +822,15 @@ main(int argc, char **argv) case 'u': opt_user = optarg; break; case 'v': verbose++; break; + case 'V': + show_version(); + exit(0); default: exit(1); } } readconfig(); |