diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-09-25 02:57:21 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2016-09-25 02:57:21 +0200 |
commit | 6ac53d4c783340ae9139c7f4dcfe9bfddace5892 (patch) | |
tree | 2637740546dcf002fbfe39eb94d6f722a2c5c7d6 /src/common | |
parent | 0c916e2c8b56c320fdc81f68d445194559479041 (diff) | |
download | blogc-6ac53d4c783340ae9139c7f4dcfe9bfddace5892.tar.gz blogc-6ac53d4c783340ae9139c7f4dcfe9bfddace5892.tar.bz2 blogc-6ac53d4c783340ae9139c7f4dcfe9bfddace5892.zip |
runserver: reimplemented http server without libevent
yeah, this patch implements a "complete" http server for static files.
It is not the best code possible, and would be easily DDoS'able if used
in production, as it spawns a thread for each request, without limiting.
I'm sickish and this is the best code I can deliver now. At least it
works! ;)
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/file.c | 6 | ||||
-rw-r--r-- | src/common/file.h | 3 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/common/file.c b/src/common/file.c index 70a5631..47c97af 100644 --- a/src/common/file.c +++ b/src/common/file.c @@ -19,7 +19,7 @@ char* -bc_file_get_contents(const char *path, size_t *len, bc_error_t **err) +bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err) { if (path == NULL || err == NULL || *err != NULL) return NULL; @@ -43,7 +43,7 @@ bc_file_get_contents(const char *path, size_t *len, bc_error_t **err) tmp = buffer; - if (str->len == 0 && read_len > 0) { + if (utf8 && str->len == 0 && read_len > 0) { // skipping BOM before validation, for performance. should be safe // enough size_t skip = bc_utf8_skip_bom((uint8_t*) buffer, read_len); @@ -56,7 +56,7 @@ bc_file_get_contents(const char *path, size_t *len, bc_error_t **err) } fclose(fp); - if (!bc_utf8_validate_str(str)) { + if (utf8 && !bc_utf8_validate_str(str)) { *err = bc_error_new_printf(BC_ERROR_FILE, "File content is not valid UTF-8: %s", path); bc_string_free(str, true); diff --git a/src/common/file.h b/src/common/file.h index e095de7..498f4f4 100644 --- a/src/common/file.h +++ b/src/common/file.h @@ -10,10 +10,11 @@ #define _FILE_H #include <stddef.h> +#include <stdbool.h> #include "error.h" #define BC_FILE_CHUNK_SIZE 1024 -char* bc_file_get_contents(const char *path, size_t *len, bc_error_t **err); +char* bc_file_get_contents(const char *path, bool utf8, size_t *len, bc_error_t **err); #endif /* _FILE_H */ |