Compare commits

..

No commits in common. "13ccc1b3bd4bf2cc769603331ce74de1ff6bbdd8" and "47d7f0396d8ab94b9e297526ac3840ba3b6c4a67" have entirely different histories.

13 changed files with 38 additions and 51 deletions

View file

@ -32,7 +32,7 @@ void print_usage(void) {
puts(" --enable-reload-config-on-change"); puts(" --enable-reload-config-on-change");
} }
Args parse_args(int32_t argc, char **argv) { Args parse_args(int argc, char **argv) {
--argc; --argc;
++argv; ++argv;
@ -44,9 +44,9 @@ Args parse_args(int32_t argc, char **argv) {
while (argc > 0) { while (argc > 0) {
if ((strcmp(argv[0], "-p") == 0 || strcmp(argv[0], "--port") == 0) if ((strcmp(argv[0], "-p") == 0 || strcmp(argv[0], "--port") == 0)
&& argc > 1) { && argc > 1) {
int32_t value = atoi(argv[1]); int value = atoi(argv[1]);
if (value >= 0 && value <= 0xFFFF) { if (value >= 0 && value <= 0xFFFF) {
args.port = (uint16_t) value; args.port = (unsigned short) value;
} }
--argc; --argc;
++argv; ++argv;

View file

@ -17,9 +17,6 @@
#ifndef SEODISPARATE_COM_C_SIMPLE_HTTP_ARG_PARSE_H_ #ifndef SEODISPARATE_COM_C_SIMPLE_HTTP_ARG_PARSE_H_
#define SEODISPARATE_COM_C_SIMPLE_HTTP_ARG_PARSE_H_ #define SEODISPARATE_COM_C_SIMPLE_HTTP_ARG_PARSE_H_
// Standard library includes.
#include <stdint.h>
// Third party includes. // Third party includes.
#include <SimpleArchiver/src/data_structures/linked_list.h> #include <SimpleArchiver/src/data_structures/linked_list.h>
@ -28,8 +25,8 @@ typedef struct Args {
// xxxx xxx1 - disable peer addr print. // xxxx xxx1 - disable peer addr print.
// 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.
uint16_t flags; unsigned short flags;
uint16_t port; unsigned short 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.
const char *config_file; const char *config_file;
// Needs to be free'd. // Needs to be free'd.

View file

@ -18,14 +18,14 @@
int is_big_endian(void) { int is_big_endian(void) {
union { union {
int32_t i; int i;
char c[4]; char c[4];
} bint = {0x01020304}; } bint = {0x01020304};
return bint.c[0] == 1 ? 1 : 0; return bint.c[0] == 1 ? 1 : 0;
} }
uint16_t u16_be_swap(uint16_t value) { unsigned short u16_be_swap(unsigned short value) {
if (is_big_endian()) { if (is_big_endian()) {
return value; return value;
} else { } else {

View file

@ -17,12 +17,9 @@
#ifndef SEODISPARATE_COM_C_SIMPLE_HTTP_BIG_ENDIAN_H_ #ifndef SEODISPARATE_COM_C_SIMPLE_HTTP_BIG_ENDIAN_H_
#define SEODISPARATE_COM_C_SIMPLE_HTTP_BIG_ENDIAN_H_ #define SEODISPARATE_COM_C_SIMPLE_HTTP_BIG_ENDIAN_H_
// Standard library includes.
#include <stdint.h>
int is_big_endian(void); int is_big_endian(void);
uint16_t u16_be_swap(uint16_t value); unsigned short u16_be_swap(unsigned short value);
#endif #endif

View file

@ -237,7 +237,7 @@ typedef struct C_SIMPLE_HTTP_INTERNAL_RequiredIter {
int c_simple_http_required_iter_fn(void *data, void *ud) { int c_simple_http_required_iter_fn(void *data, void *ud) {
C_SIMPLE_HTTP_INTERNAL_RequiredIter *req_iter_struct = ud; C_SIMPLE_HTTP_INTERNAL_RequiredIter *req_iter_struct = ud;
uint32_t data_str_length = (uint32_t)strlen(data) + 1; unsigned int data_str_length = (unsigned int)strlen(data) + 1;
if (simple_archiver_hash_map_get( if (simple_archiver_hash_map_get(
req_iter_struct->hash_map, req_iter_struct->hash_map,
data, data,
@ -267,7 +267,7 @@ typedef struct C_SIMPLE_HTTP_INTERNAL_RequiredCheck {
int c_simple_http_check_required_iter_fn(void *path_void_str, void *ud) { int c_simple_http_check_required_iter_fn(void *path_void_str, void *ud) {
C_SIMPLE_HTTP_INTERNAL_RequiredCheck *req = ud; C_SIMPLE_HTTP_INTERNAL_RequiredCheck *req = ud;
uint32_t path_void_str_len = (uint32_t)strlen(path_void_str) + 1; unsigned int path_void_str_len = (unsigned int)strlen(path_void_str) + 1;
C_SIMPLE_HTTP_HashMapWrapper *wrapper = C_SIMPLE_HTTP_HashMapWrapper *wrapper =
simple_archiver_hash_map_get( simple_archiver_hash_map_get(
req->map_of_paths_and_their_vars, req->map_of_paths_and_their_vars,
@ -303,8 +303,8 @@ C_SIMPLE_HTTP_ParsedConfig c_simple_http_parse_config(
fprintf(stderr, "ERROR: separating_key argument is NULL!\n"); fprintf(stderr, "ERROR: separating_key argument is NULL!\n");
return config; return config;
} }
const uint32_t separating_key_size = const unsigned int separating_key_size =
(uint32_t)strlen(separating_key) + 1; (unsigned int)strlen(separating_key) + 1;
config.hash_map = simple_archiver_hash_map_init(); config.hash_map = simple_archiver_hash_map_init();
@ -320,21 +320,21 @@ C_SIMPLE_HTTP_ParsedConfig c_simple_http_parse_config(
} }
unsigned char key_buf[C_SIMPLE_HTTP_CONFIG_BUF_SIZE]; unsigned char key_buf[C_SIMPLE_HTTP_CONFIG_BUF_SIZE];
unsigned char value_buf[C_SIMPLE_HTTP_CONFIG_BUF_SIZE]; unsigned char value_buf[C_SIMPLE_HTTP_CONFIG_BUF_SIZE];
uint32_t key_idx = 0; unsigned int key_idx = 0;
uint32_t value_idx = 0; unsigned int value_idx = 0;
__attribute__((cleanup(simple_archiver_helper_cleanup_c_string))) __attribute__((cleanup(simple_archiver_helper_cleanup_c_string)))
char *current_separating_key_value = NULL; char *current_separating_key_value = NULL;
uint32_t current_separating_key_value_size = 0; unsigned int current_separating_key_value_size = 0;
// xxx0 - reading key // xxx0 - reading key
// xxx1 - reading value // xxx1 - reading value
// 00xx - reading value is not quoted // 00xx - reading value is not quoted
// 01xx - reading value is single quoted // 01xx - reading value is single quoted
// 10xx - reading value is double quoted // 10xx - reading value is double quoted
uint32_t state = 0; unsigned int state = 0;
unsigned char single_quote_count = 0; unsigned char single_quote_count = 0;
unsigned char double_quote_count = 0; unsigned char double_quote_count = 0;
int32_t c; int c;
while (feof(f) == 0) { while (feof(f) == 0) {
c = fgetc(f); c = fgetc(f);

View file

@ -55,7 +55,7 @@ const char *c_simple_http_response_code_error_to_response(
char *c_simple_http_request_response( char *c_simple_http_request_response(
const char *request, const char *request,
uint32_t size, unsigned int size,
const C_SIMPLE_HTTP_HTTPTemplates *templates, const C_SIMPLE_HTTP_HTTPTemplates *templates,
size_t *out_size, size_t *out_size,
enum C_SIMPLE_HTTP_ResponseCode *out_response_code) { enum C_SIMPLE_HTTP_ResponseCode *out_response_code) {
@ -63,9 +63,9 @@ char *c_simple_http_request_response(
*out_size = 0; *out_size = 0;
} }
// parse first line. // parse first line.
uint32_t idx = 0; unsigned int idx = 0;
char request_type[REQUEST_TYPE_BUFFER_SIZE] = {0}; char request_type[REQUEST_TYPE_BUFFER_SIZE] = {0};
uint32_t request_type_idx = 0; unsigned int request_type_idx = 0;
for (; idx < size for (; idx < size
&& request[idx] != ' ' && request[idx] != ' '
&& request[idx] != '\n' && request[idx] != '\n'
@ -93,7 +93,7 @@ char *c_simple_http_request_response(
++idx) {} ++idx) {}
// parse request path. // parse request path.
char request_path[REQUEST_PATH_BUFFER_SIZE] = {0}; char request_path[REQUEST_PATH_BUFFER_SIZE] = {0};
uint32_t request_path_idx = 0; unsigned int request_path_idx = 0;
for (; idx < size for (; idx < size
&& request[idx] != ' ' && request[idx] != ' '
&& request[idx] != '\n' && request[idx] != '\n'
@ -121,7 +121,7 @@ char *c_simple_http_request_response(
++idx) {} ++idx) {}
// parse request http protocol. // parse request http protocol.
char request_proto[REQUEST_PROTO_BUFFER_SIZE] = {0}; char request_proto[REQUEST_PROTO_BUFFER_SIZE] = {0};
uint32_t request_proto_idx = 0; unsigned int request_proto_idx = 0;
for (; idx < size for (; idx < size
&& request[idx] != ' ' && request[idx] != ' '
&& request[idx] != '\n' && request[idx] != '\n'
@ -222,7 +222,7 @@ SDArchiverHashMap *c_simple_http_request_to_headers_map(
// xxxx xx00 - Beginning of line. // xxxx xx00 - Beginning of line.
// xxxx xx01 - Reached end of header key. // xxxx xx01 - Reached end of header key.
// xxxx xx10 - Non-header line. // xxxx xx10 - Non-header line.
uint32_t state = 0; unsigned int state = 0;
size_t idx = 0; size_t idx = 0;
size_t header_key_idx = 0; size_t header_key_idx = 0;
__attribute__((cleanup(simple_archiver_helper_cleanup_c_string))) __attribute__((cleanup(simple_archiver_helper_cleanup_c_string)))

View file

@ -19,7 +19,6 @@
// Standard library includes. // Standard library includes.
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
// Third party includes. // Third party includes.
#include <SimpleArchiver/src/data_structures/hash_map.h> #include <SimpleArchiver/src/data_structures/hash_map.h>
@ -45,7 +44,7 @@ const char *c_simple_http_response_code_error_to_response(
/// If the request is not valid, or 404, then the buffer will be NULL. /// If the request is not valid, or 404, then the buffer will be NULL.
char *c_simple_http_request_response( char *c_simple_http_request_response(
const char *request, const char *request,
uint32_t size, unsigned int size,
const C_SIMPLE_HTTP_HTTPTemplates *templates, const C_SIMPLE_HTTP_HTTPTemplates *templates,
size_t *out_size, size_t *out_size,
enum C_SIMPLE_HTTP_ResponseCode *out_response_code enum C_SIMPLE_HTTP_ResponseCode *out_response_code

View file

@ -19,7 +19,6 @@
// Standard library includes. // Standard library includes.
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
// Third party includes. // Third party includes.
#include <SimpleArchiver/src/data_structures/linked_list.h> #include <SimpleArchiver/src/data_structures/linked_list.h>
@ -105,7 +104,7 @@ char *c_simple_http_path_to_generated(
fprintf(stderr, "ERROR: Path string is too large!\n"); fprintf(stderr, "ERROR: Path string is too large!\n");
return NULL; return NULL;
} }
uint32_t path_len = (uint32_t)path_len_size_t; unsigned int path_len = (unsigned int)path_len_size_t;
C_SIMPLE_HTTP_ParsedConfig *wrapped_hash_map = C_SIMPLE_HTTP_ParsedConfig *wrapped_hash_map =
simple_archiver_hash_map_get(templates->hash_map, path, path_len); simple_archiver_hash_map_get(templates->hash_map, path, path_len);
if (!wrapped_hash_map) { if (!wrapped_hash_map) {
@ -165,7 +164,7 @@ char *c_simple_http_path_to_generated(
// xxxx xxx0 - Initial state, no delimeter reached. // xxxx xxx0 - Initial state, no delimeter reached.
// xxxx xxx1 - Three left-curly-brace delimeters reached. // xxxx xxx1 - Three left-curly-brace delimeters reached.
uint32_t state = 0; unsigned int state = 0;
for (; idx < html_buf_size; ++idx) { for (; idx < html_buf_size; ++idx) {
if ((state & 1) == 0) { if ((state & 1) == 0) {
@ -217,7 +216,7 @@ char *c_simple_http_path_to_generated(
simple_archiver_hash_map_get( simple_archiver_hash_map_get(
wrapped_hash_map->hash_map, wrapped_hash_map->hash_map,
var, var,
(uint32_t)var_size + 1); (unsigned int)var_size + 1);
if (value_c_str) { if (value_c_str) {
if (c_simple_http_internal_ends_with_FILE(var) == 0) { if (c_simple_http_internal_ends_with_FILE(var) == 0) {
// Load from file specified by "value_c_str". // Load from file specified by "value_c_str".

View file

@ -18,7 +18,6 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
// Linux/Unix includes. // Linux/Unix includes.
#include <sys/socket.h> #include <sys/socket.h>
@ -162,9 +161,9 @@ int main(int argc, char **argv) {
socklen_t socket_len; socklen_t socket_len;
// xxxx xxx1 - config needs to be reloaded. // xxxx xxx1 - config needs to be reloaded.
uint32_t flags = 0; unsigned int flags = 0;
size_t config_try_reload_ticks_count = 0; size_t config_try_reload_ticks_count = 0;
uint32_t config_try_reload_attempts = 0; unsigned int config_try_reload_attempts = 0;
while (C_SIMPLE_HTTP_KEEP_RUNNING) { while (C_SIMPLE_HTTP_KEEP_RUNNING) {
nanosleep(&sleep_time, NULL); nanosleep(&sleep_time, NULL);
@ -308,7 +307,7 @@ int main(int argc, char **argv) {
// Received connection, handle it. // Received connection, handle it.
if ((args.flags & 1) == 0) { if ((args.flags & 1) == 0) {
printf("Peer connected: addr is "); printf("Peer connected: addr is ");
for (uint32_t idx = 0; idx < 16; ++idx) { for (unsigned int idx = 0; idx < 16; ++idx) {
if (idx % 2 == 0 && idx > 0) { if (idx % 2 == 0 && idx > 0) {
printf(":"); printf(":");
} }
@ -329,7 +328,7 @@ int main(int argc, char **argv) {
} }
#ifndef NDEBUG #ifndef NDEBUG
// DEBUG print received buf. // DEBUG print received buf.
for (uint32_t idx = 0; for (unsigned int idx = 0;
idx < C_SIMPLE_HTTP_RECV_BUF_SIZE && idx < read_ret; idx < C_SIMPLE_HTTP_RECV_BUF_SIZE && idx < read_ret;
++idx) { ++idx) {
if ((recv_buf[idx] >= 0x20 && recv_buf[idx] <= 0x7E) if ((recv_buf[idx] >= 0x20 && recv_buf[idx] <= 0x7E)
@ -356,7 +355,7 @@ int main(int argc, char **argv) {
enum C_SIMPLE_HTTP_ResponseCode response_code; enum C_SIMPLE_HTTP_ResponseCode response_code;
const char *response = c_simple_http_request_response( const char *response = c_simple_http_request_response(
(const char*)recv_buf, (const char*)recv_buf,
(uint32_t)read_ret, (unsigned int)read_ret,
&parsed_config, &parsed_config,
&response_size, &response_size,
&response_code); &response_code);
@ -369,7 +368,7 @@ int main(int argc, char **argv) {
size_t content_length_buf_size = 0; size_t content_length_buf_size = 0;
memcpy(content_length_buf, "Content-Length: ", 16); memcpy(content_length_buf, "Content-Length: ", 16);
content_length_buf_size = 16; content_length_buf_size = 16;
int32_t written = 0; int written = 0;
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,

View file

@ -30,7 +30,7 @@
// Local includes. // Local includes.
#include "big_endian.h" #include "big_endian.h"
int create_tcp_socket(uint16_t port) { int create_tcp_socket(unsigned short port) {
struct sockaddr_in6 ipv6_addr; struct sockaddr_in6 ipv6_addr;
memset(&ipv6_addr, 0, sizeof(struct sockaddr_in6)); memset(&ipv6_addr, 0, sizeof(struct sockaddr_in6));
ipv6_addr.sin6_family = AF_INET6; ipv6_addr.sin6_family = AF_INET6;

View file

@ -17,12 +17,9 @@
#ifndef SEODISPARATE_COM_C_SIMPLE_HTTP_TCP_SOCKET_H_ #ifndef SEODISPARATE_COM_C_SIMPLE_HTTP_TCP_SOCKET_H_
#define SEODISPARATE_COM_C_SIMPLE_HTTP_TCP_SOCKET_H_ #define SEODISPARATE_COM_C_SIMPLE_HTTP_TCP_SOCKET_H_
// Standard library includes.
#include <stdint.h>
#define C_SIMPLE_HTTP_TCP_SOCKET_BACKLOG 64 #define C_SIMPLE_HTTP_TCP_SOCKET_BACKLOG 64
int create_tcp_socket(uint16_t port); int create_tcp_socket(unsigned short port);
void cleanup_tcp_socket(int *tcp_socket); void cleanup_tcp_socket(int *tcp_socket);

View file

@ -2,7 +2,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
// Local includes. // Local includes.
#include "config.h" #include "config.h"
@ -13,8 +12,8 @@
#include <SimpleArchiver/src/helpers.h> #include <SimpleArchiver/src/helpers.h>
#include <SimpleArchiver/src/data_structures/hash_map.h> #include <SimpleArchiver/src/data_structures/hash_map.h>
static int32_t checks_checked = 0; static int checks_checked = 0;
static int32_t checks_passed = 0; static int checks_passed = 0;
#define RETURN() \ #define RETURN() \
do { \ do { \

@ -1 +1 @@
Subproject commit bb574d2a2c8732769329d4e760a28ead0728458f Subproject commit 6b862ab022202523606bda2fe39236c71891b304