Compare commits
7 commits
8e58873ea9
...
cfa7a065b2
Author | SHA1 | Date | |
---|---|---|---|
cfa7a065b2 | |||
ca5296920c | |||
faa0c457d9 | |||
d6edaa3bdd | |||
0ecb8d6801 | |||
8052e693e6 | |||
a467cceb90 |
8 changed files with 34 additions and 11 deletions
12
Changelog.md
12
Changelog.md
|
@ -2,6 +2,14 @@
|
||||||
|
|
||||||
## Upcoming Changes
|
## Upcoming Changes
|
||||||
|
|
||||||
|
## Version 1.5
|
||||||
|
|
||||||
|
Add flag `--generate-static-enable-overwrite`. This flag enables overwriting of
|
||||||
|
files from static-dir to generate-dir (if static-dir was specified). Previous
|
||||||
|
implementation relied on `--generate-enable-ovewrite` for this behavior.
|
||||||
|
|
||||||
|
Minor refactorings related to `printf` and `uintX_t`/`size_t` types.
|
||||||
|
|
||||||
## Version 1.4
|
## Version 1.4
|
||||||
|
|
||||||
Implemented "IF", "ELSEIF", "ELSE", "ENDIF", and "INDEX" for templates.
|
Implemented "IF", "ELSEIF", "ELSE", "ENDIF", and "INDEX" for templates.
|
||||||
|
@ -79,3 +87,7 @@ Features:
|
||||||
- Reload configuration on SIGUSR1 or by listening (enabled by cmd parameter).
|
- Reload configuration on SIGUSR1 or by listening (enabled by cmd parameter).
|
||||||
- Cache served html (enabled by cmd parameter).
|
- Cache served html (enabled by cmd parameter).
|
||||||
- Serve static files from "static-dir" (enabled by cmd parameter).
|
- Serve static files from "static-dir" (enabled by cmd parameter).
|
||||||
|
|
||||||
|
<!--
|
||||||
|
vim: textwidth=80 et sw=2 ts=2 sts=2
|
||||||
|
-->
|
||||||
|
|
|
@ -17,6 +17,7 @@ A simple HTTP/1.1 server written in C.
|
||||||
--enable-static-dir=<DIR>
|
--enable-static-dir=<DIR>
|
||||||
--generate-dir=<DIR>
|
--generate-dir=<DIR>
|
||||||
--generate-enable-overwrite
|
--generate-enable-overwrite
|
||||||
|
--generate-static-enable-overwrite
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ void print_usage(void) {
|
||||||
puts(" --enable-static-dir=<DIR>");
|
puts(" --enable-static-dir=<DIR>");
|
||||||
puts(" --generate-dir=<DIR>");
|
puts(" --generate-dir=<DIR>");
|
||||||
puts(" --generate-enable-overwrite");
|
puts(" --generate-enable-overwrite");
|
||||||
|
puts(" --generate-static-enable-overwrite");
|
||||||
}
|
}
|
||||||
|
|
||||||
Args parse_args(int32_t argc, char **argv) {
|
Args parse_args(int32_t argc, char **argv) {
|
||||||
|
@ -128,7 +129,7 @@ Args parse_args(int32_t argc, char **argv) {
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
printf(
|
printf(
|
||||||
"NOTICE set cache-entry-lifetime to %lu\n",
|
"NOTICE set cache-entry-lifetime to %zu\n",
|
||||||
args.cache_lifespan_seconds);
|
args.cache_lifespan_seconds);
|
||||||
}
|
}
|
||||||
} else if (strncmp(argv[0], "--enable-static-dir=", 20) == 0) {
|
} else if (strncmp(argv[0], "--enable-static-dir=", 20) == 0) {
|
||||||
|
@ -189,6 +190,8 @@ Args parse_args(int32_t argc, char **argv) {
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[0], "--generate-enable-overwrite") == 0) {
|
} else if (strcmp(argv[0], "--generate-enable-overwrite") == 0) {
|
||||||
args.flags |= 4;
|
args.flags |= 4;
|
||||||
|
} else if (strcmp(argv[0], "--generate-static-enable-overwrite") == 0) {
|
||||||
|
args.flags |= 8;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "ERROR: Invalid args!\n");
|
fprintf(stderr, "ERROR: Invalid args!\n");
|
||||||
print_usage();
|
print_usage();
|
||||||
|
|
|
@ -29,6 +29,7 @@ typedef struct Args {
|
||||||
// xxxx xx0x - disable listen on config file for reloading.
|
// xxxx xx0x - disable listen on config file for reloading.
|
||||||
// xxxx xx1x - enable listen on config file for reloading.
|
// xxxx xx1x - enable listen on config file for reloading.
|
||||||
// xxxx x1xx - enable overwrite on generate.
|
// xxxx x1xx - enable overwrite on generate.
|
||||||
|
// xxxx 1xxx - enable overwrite on generate for static dir.
|
||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
// Does not need to be free'd, this should point to a string in argv.
|
// Does not need to be free'd, this should point to a string in argv.
|
||||||
|
|
14
src/main.c
14
src/main.c
|
@ -19,6 +19,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
// Linux/Unix includes.
|
// Linux/Unix includes.
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
@ -232,7 +233,7 @@ int c_simple_http_manage_connections(void *data, void *ud) {
|
||||||
snprintf(
|
snprintf(
|
||||||
content_length_buf + content_length_buf_size,
|
content_length_buf + content_length_buf_size,
|
||||||
127 - content_length_buf_size,
|
127 - content_length_buf_size,
|
||||||
"%lu\n%n",
|
"%zu\n%n",
|
||||||
response_size,
|
response_size,
|
||||||
&written);
|
&written);
|
||||||
if (written <= 0) {
|
if (written <= 0) {
|
||||||
|
@ -304,7 +305,7 @@ int c_simple_http_manage_connections(void *data, void *ud) {
|
||||||
snprintf(
|
snprintf(
|
||||||
content_length_buf,
|
content_length_buf,
|
||||||
content_str_len + 1 + 16 + 1,
|
content_str_len + 1 + 16 + 1,
|
||||||
"Content-Length: %lu\n",
|
"Content-Length: %" PRIu64 "\n",
|
||||||
file_info.buf_size);
|
file_info.buf_size);
|
||||||
CHECK_ERROR_WRITE_NO_FD(write(
|
CHECK_ERROR_WRITE_NO_FD(write(
|
||||||
citem->fd, content_length_buf, content_str_len + 1 + 16));
|
citem->fd, content_length_buf, content_str_len + 1 + 16));
|
||||||
|
@ -363,7 +364,7 @@ int main(int argc, char **argv) {
|
||||||
puts("Static dir option specified, copying over static dir entries...");
|
puts("Static dir option specified, copying over static dir entries...");
|
||||||
if (c_simple_http_static_copy_over_dir(args.static_dir,
|
if (c_simple_http_static_copy_over_dir(args.static_dir,
|
||||||
args.generate_dir,
|
args.generate_dir,
|
||||||
(args.flags & 4) != 0 ? 1 : 0)
|
(args.flags & 8) != 0 ? 1 : 0)
|
||||||
!= 0) {
|
!= 0) {
|
||||||
fprintf(stderr, "ERROR during static-dir-entires copying!\n");
|
fprintf(stderr, "ERROR during static-dir-entires copying!\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -385,7 +386,8 @@ int main(int argc, char **argv) {
|
||||||
socklen_t size = sizeof(ipv6_addr);
|
socklen_t size = sizeof(ipv6_addr);
|
||||||
int ret = getsockname(tcp_socket, (struct sockaddr*)&ipv6_addr, &size);
|
int ret = getsockname(tcp_socket, (struct sockaddr*)&ipv6_addr, &size);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
printf("Listening on port: %u\n", u16_be_swap(ipv6_addr.sin6_port));
|
printf("Listening on port: %" PRIu16 "\n",
|
||||||
|
u16_be_swap(ipv6_addr.sin6_port));
|
||||||
} else {
|
} else {
|
||||||
fprintf(
|
fprintf(
|
||||||
stderr,
|
stderr,
|
||||||
|
@ -462,7 +464,7 @@ int main(int argc, char **argv) {
|
||||||
++config_try_reload_attempts;
|
++config_try_reload_attempts;
|
||||||
fprintf(
|
fprintf(
|
||||||
stderr,
|
stderr,
|
||||||
"Attempting to reload config now (try %u of %u)...\n",
|
"Attempting to reload config now (try %" PRIu32 " of %u)...\n",
|
||||||
config_try_reload_attempts,
|
config_try_reload_attempts,
|
||||||
C_SIMPLE_HTTP_TRY_CONFIG_RELOAD_MAX_ATTEMPTS);
|
C_SIMPLE_HTTP_TRY_CONFIG_RELOAD_MAX_ATTEMPTS);
|
||||||
C_SIMPLE_HTTP_ParsedConfig new_parsed_config =
|
C_SIMPLE_HTTP_ParsedConfig new_parsed_config =
|
||||||
|
@ -532,7 +534,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
} else if (read_ret > 0) {
|
} else if (read_ret > 0) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
printf("DEBUG inotify_event->mask: %x\n", inotify_event->mask);
|
printf("DEBUG inotify_event->mask: %" PRIx32 "\n", inotify_event->mask);
|
||||||
#endif
|
#endif
|
||||||
if ((inotify_event->mask & IN_MODIFY) != 0
|
if ((inotify_event->mask & IN_MODIFY) != 0
|
||||||
|| (inotify_event->mask & IN_CLOSE_WRITE) != 0) {
|
|| (inotify_event->mask & IN_CLOSE_WRITE) != 0) {
|
||||||
|
|
|
@ -421,8 +421,8 @@ int c_simple_http_static_copy_over_dir(const char *from,
|
||||||
if (fd) {
|
if (fd) {
|
||||||
fprintf(
|
fprintf(
|
||||||
stderr,
|
stderr,
|
||||||
"WARNING \"%s\" already exists and --generate-enable-overwrite not "
|
"WARNING \"%s\" already exists and "
|
||||||
"specified, skipping!\n",
|
"--generate-static-enable-overwrite not specified, skipping!\n",
|
||||||
combined_to);
|
combined_to);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
// POSIX includes.
|
// POSIX includes.
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -28,7 +29,10 @@ static int32_t checks_passed = 0;
|
||||||
|
|
||||||
#define RETURN() \
|
#define RETURN() \
|
||||||
do { \
|
do { \
|
||||||
fprintf(stderr, "checked %d\npassed %d\n", checks_checked, checks_passed);\
|
fprintf(stderr, \
|
||||||
|
"checked %" PRId32 "\npassed %" PRId32 "\n", \
|
||||||
|
checks_checked, \
|
||||||
|
checks_passed); \
|
||||||
return checks_checked == checks_passed ? 0 : 1; \
|
return checks_checked == checks_passed ? 0 : 1; \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
|
|
2
third_party/SimpleArchiver
vendored
2
third_party/SimpleArchiver
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit ce7400a298a95b60d0d482058ed9eae4142f8061
|
Subproject commit 78a36b48dbd3888f56e26ac71115e5f775a74c2c
|
Loading…
Reference in a new issue