Compare commits

...

7 commits

Author SHA1 Message Date
cfa7a065b2 Version 1.5
All checks were successful
Build for Releases / ensure-release-exists (push) Successful in 3s
Build for Releases / push-build-x86_64 (push) Successful in 6s
Run Unit Tests / build-and-run-unit-tests (push) Successful in 2m9s
Build for Releases / push-build-aarch64 (push) Successful in 1m15s
Build for Releases / push-build-x86_64_debian (push) Successful in 34s
Build for Releases / push-build-aarch64_debian (push) Successful in 5m15s
2024-11-25 17:39:04 +09:00
ca5296920c Update third-party submodule SimpleArchiver
All checks were successful
Run Unit Tests / build-and-run-unit-tests (push) Successful in 20s
2024-11-25 17:23:17 +09:00
faa0c457d9 Update Changelog.md
All checks were successful
Run Unit Tests / build-and-run-unit-tests (push) Successful in 2m9s
2024-11-25 16:04:44 +09:00
d6edaa3bdd Use proper format constants for size_t/uintX_t etc
All checks were successful
Run Unit Tests / build-and-run-unit-tests (push) Successful in 22s
2024-11-25 16:01:49 +09:00
0ecb8d6801 Update README.md
All checks were successful
Run Unit Tests / build-and-run-unit-tests (push) Successful in 22s
2024-11-25 14:21:00 +09:00
8052e693e6 Update Changelog.md 2024-11-25 14:20:28 +09:00
a467cceb90 Add separate flag for generate-static overwrite
Previous implementation allowed static files to overwrite existing files
on generate if static-dir was specified and generate-enable-overwrite
was specified. Now, an additional flag
"--generate-static-enable-overwrite" determines if static-dir files
overwrite on generate.
2024-11-25 14:17:32 +09:00
8 changed files with 34 additions and 11 deletions

View file

@ -2,6 +2,14 @@
## 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
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).
- Cache served html (enabled by cmd parameter).
- Serve static files from "static-dir" (enabled by cmd parameter).
<!--
vim: textwidth=80 et sw=2 ts=2 sts=2
-->

View file

@ -17,6 +17,7 @@ A simple HTTP/1.1 server written in C.
--enable-static-dir=<DIR>
--generate-dir=<DIR>
--generate-enable-overwrite
--generate-static-enable-overwrite
## Changelog

View file

@ -46,6 +46,7 @@ void print_usage(void) {
puts(" --enable-static-dir=<DIR>");
puts(" --generate-dir=<DIR>");
puts(" --generate-enable-overwrite");
puts(" --generate-static-enable-overwrite");
}
Args parse_args(int32_t argc, char **argv) {
@ -128,7 +129,7 @@ Args parse_args(int32_t argc, char **argv) {
exit(1);
} else {
printf(
"NOTICE set cache-entry-lifetime to %lu\n",
"NOTICE set cache-entry-lifetime to %zu\n",
args.cache_lifespan_seconds);
}
} 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) {
args.flags |= 4;
} else if (strcmp(argv[0], "--generate-static-enable-overwrite") == 0) {
args.flags |= 8;
} else {
fprintf(stderr, "ERROR: Invalid args!\n");
print_usage();

View file

@ -29,6 +29,7 @@ typedef struct Args {
// xxxx xx0x - disable listen on config file for reloading.
// xxxx xx1x - enable listen on config file for reloading.
// xxxx x1xx - enable overwrite on generate.
// xxxx 1xxx - enable overwrite on generate for static dir.
uint16_t flags;
uint16_t port;
// Does not need to be free'd, this should point to a string in argv.

View file

@ -19,6 +19,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
// Linux/Unix includes.
#include <sys/socket.h>
@ -232,7 +233,7 @@ int c_simple_http_manage_connections(void *data, void *ud) {
snprintf(
content_length_buf + content_length_buf_size,
127 - content_length_buf_size,
"%lu\n%n",
"%zu\n%n",
response_size,
&written);
if (written <= 0) {
@ -304,7 +305,7 @@ int c_simple_http_manage_connections(void *data, void *ud) {
snprintf(
content_length_buf,
content_str_len + 1 + 16 + 1,
"Content-Length: %lu\n",
"Content-Length: %" PRIu64 "\n",
file_info.buf_size);
CHECK_ERROR_WRITE_NO_FD(write(
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...");
if (c_simple_http_static_copy_over_dir(args.static_dir,
args.generate_dir,
(args.flags & 4) != 0 ? 1 : 0)
(args.flags & 8) != 0 ? 1 : 0)
!= 0) {
fprintf(stderr, "ERROR during static-dir-entires copying!\n");
return 1;
@ -385,7 +386,8 @@ int main(int argc, char **argv) {
socklen_t size = sizeof(ipv6_addr);
int ret = getsockname(tcp_socket, (struct sockaddr*)&ipv6_addr, &size);
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 {
fprintf(
stderr,
@ -462,7 +464,7 @@ int main(int argc, char **argv) {
++config_try_reload_attempts;
fprintf(
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,
C_SIMPLE_HTTP_TRY_CONFIG_RELOAD_MAX_ATTEMPTS);
C_SIMPLE_HTTP_ParsedConfig new_parsed_config =
@ -532,7 +534,7 @@ int main(int argc, char **argv) {
}
} else if (read_ret > 0) {
#ifndef NDEBUG
printf("DEBUG inotify_event->mask: %x\n", inotify_event->mask);
printf("DEBUG inotify_event->mask: %" PRIx32 "\n", inotify_event->mask);
#endif
if ((inotify_event->mask & IN_MODIFY) != 0
|| (inotify_event->mask & IN_CLOSE_WRITE) != 0) {

View file

@ -421,8 +421,8 @@ int c_simple_http_static_copy_over_dir(const char *from,
if (fd) {
fprintf(
stderr,
"WARNING \"%s\" already exists and --generate-enable-overwrite not "
"specified, skipping!\n",
"WARNING \"%s\" already exists and "
"--generate-static-enable-overwrite not specified, skipping!\n",
combined_to);
continue;
}

View file

@ -3,6 +3,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
// POSIX includes.
#include <unistd.h>
@ -28,7 +29,10 @@ static int32_t checks_passed = 0;
#define RETURN() \
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; \
} while (0);

@ -1 +1 @@
Subproject commit ce7400a298a95b60d0d482058ed9eae4142f8061
Subproject commit 78a36b48dbd3888f56e26ac71115e5f775a74c2c