puts(" --enable-reload-config-on-change");
}
-Args parse_args(int argc, char **argv) {
+Args parse_args(int32_t argc, char **argv) {
--argc;
++argv;
while (argc > 0) {
if ((strcmp(argv[0], "-p") == 0 || strcmp(argv[0], "--port") == 0)
&& argc > 1) {
- int value = atoi(argv[1]);
+ int32_t value = atoi(argv[1]);
if (value >= 0 && value <= 0xFFFF) {
- args.port = (unsigned short) value;
+ args.port = (uint16_t) value;
}
--argc;
++argv;
#ifndef 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.
#include <SimpleArchiver/src/data_structures/linked_list.h>
// xxxx xxx1 - disable peer addr print.
// xxxx xx0x - disable listen on config file for reloading.
// xxxx xx1x - enable listen on config file for reloading.
- unsigned short flags;
- unsigned short port;
+ uint16_t flags;
+ uint16_t port;
// Does not need to be free'd, this should point to a string in argv.
const char *config_file;
// Needs to be free'd.
int is_big_endian(void) {
union {
- int i;
+ int32_t i;
char c[4];
} bint = {0x01020304};
return bint.c[0] == 1 ? 1 : 0;
}
-unsigned short u16_be_swap(unsigned short value) {
+uint16_t u16_be_swap(uint16_t value) {
if (is_big_endian()) {
return value;
} else {
#ifndef 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);
-unsigned short u16_be_swap(unsigned short value);
+uint16_t u16_be_swap(uint16_t value);
#endif
int c_simple_http_required_iter_fn(void *data, void *ud) {
C_SIMPLE_HTTP_INTERNAL_RequiredIter *req_iter_struct = ud;
- unsigned int data_str_length = (unsigned int)strlen(data) + 1;
+ uint32_t data_str_length = (uint32_t)strlen(data) + 1;
if (simple_archiver_hash_map_get(
req_iter_struct->hash_map,
data,
int c_simple_http_check_required_iter_fn(void *path_void_str, void *ud) {
C_SIMPLE_HTTP_INTERNAL_RequiredCheck *req = ud;
- unsigned int path_void_str_len = (unsigned int)strlen(path_void_str) + 1;
+ uint32_t path_void_str_len = (uint32_t)strlen(path_void_str) + 1;
C_SIMPLE_HTTP_HashMapWrapper *wrapper =
simple_archiver_hash_map_get(
req->map_of_paths_and_their_vars,
fprintf(stderr, "ERROR: separating_key argument is NULL!\n");
return config;
}
- const unsigned int separating_key_size =
- (unsigned int)strlen(separating_key) + 1;
+ const uint32_t separating_key_size =
+ (uint32_t)strlen(separating_key) + 1;
config.hash_map = simple_archiver_hash_map_init();
}
unsigned char key_buf[C_SIMPLE_HTTP_CONFIG_BUF_SIZE];
unsigned char value_buf[C_SIMPLE_HTTP_CONFIG_BUF_SIZE];
- unsigned int key_idx = 0;
- unsigned int value_idx = 0;
+ uint32_t key_idx = 0;
+ uint32_t value_idx = 0;
__attribute__((cleanup(simple_archiver_helper_cleanup_c_string)))
char *current_separating_key_value = NULL;
- unsigned int current_separating_key_value_size = 0;
+ uint32_t current_separating_key_value_size = 0;
// xxx0 - reading key
// xxx1 - reading value
// 00xx - reading value is not quoted
// 01xx - reading value is single quoted
// 10xx - reading value is double quoted
- unsigned int state = 0;
+ uint32_t state = 0;
unsigned char single_quote_count = 0;
unsigned char double_quote_count = 0;
- int c;
+ int32_t c;
while (feof(f) == 0) {
c = fgetc(f);
char *c_simple_http_request_response(
const char *request,
- unsigned int size,
+ uint32_t size,
const C_SIMPLE_HTTP_HTTPTemplates *templates,
size_t *out_size,
enum C_SIMPLE_HTTP_ResponseCode *out_response_code) {
*out_size = 0;
}
// parse first line.
- unsigned int idx = 0;
+ uint32_t idx = 0;
char request_type[REQUEST_TYPE_BUFFER_SIZE] = {0};
- unsigned int request_type_idx = 0;
+ uint32_t request_type_idx = 0;
for (; idx < size
&& request[idx] != ' '
&& request[idx] != '\n'
++idx) {}
// parse request path.
char request_path[REQUEST_PATH_BUFFER_SIZE] = {0};
- unsigned int request_path_idx = 0;
+ uint32_t request_path_idx = 0;
for (; idx < size
&& request[idx] != ' '
&& request[idx] != '\n'
++idx) {}
// parse request http protocol.
char request_proto[REQUEST_PROTO_BUFFER_SIZE] = {0};
- unsigned int request_proto_idx = 0;
+ uint32_t request_proto_idx = 0;
for (; idx < size
&& request[idx] != ' '
&& request[idx] != '\n'
// xxxx xx00 - Beginning of line.
// xxxx xx01 - Reached end of header key.
// xxxx xx10 - Non-header line.
- unsigned int state = 0;
+ uint32_t state = 0;
size_t idx = 0;
size_t header_key_idx = 0;
__attribute__((cleanup(simple_archiver_helper_cleanup_c_string)))
// Standard library includes.
#include <stddef.h>
+#include <stdint.h>
// Third party includes.
#include <SimpleArchiver/src/data_structures/hash_map.h>
/// If the request is not valid, or 404, then the buffer will be NULL.
char *c_simple_http_request_response(
const char *request,
- unsigned int size,
+ uint32_t size,
const C_SIMPLE_HTTP_HTTPTemplates *templates,
size_t *out_size,
enum C_SIMPLE_HTTP_ResponseCode *out_response_code
// Standard library includes.
#include <string.h>
#include <stdlib.h>
+#include <stdint.h>
// Third party includes.
#include <SimpleArchiver/src/data_structures/linked_list.h>
fprintf(stderr, "ERROR: Path string is too large!\n");
return NULL;
}
- unsigned int path_len = (unsigned int)path_len_size_t;
+ uint32_t path_len = (uint32_t)path_len_size_t;
C_SIMPLE_HTTP_ParsedConfig *wrapped_hash_map =
simple_archiver_hash_map_get(templates->hash_map, path, path_len);
if (!wrapped_hash_map) {
// xxxx xxx0 - Initial state, no delimeter reached.
// xxxx xxx1 - Three left-curly-brace delimeters reached.
- unsigned int state = 0;
+ uint32_t state = 0;
for (; idx < html_buf_size; ++idx) {
if ((state & 1) == 0) {
simple_archiver_hash_map_get(
wrapped_hash_map->hash_map,
var,
- (unsigned int)var_size + 1);
+ (uint32_t)var_size + 1);
if (value_c_str) {
if (c_simple_http_internal_ends_with_FILE(var) == 0) {
// Load from file specified by "value_c_str".
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <stdint.h>
// Linux/Unix includes.
#include <sys/socket.h>
socklen_t socket_len;
// xxxx xxx1 - config needs to be reloaded.
- unsigned int flags = 0;
+ uint32_t flags = 0;
size_t config_try_reload_ticks_count = 0;
- unsigned int config_try_reload_attempts = 0;
+ uint32_t config_try_reload_attempts = 0;
while (C_SIMPLE_HTTP_KEEP_RUNNING) {
nanosleep(&sleep_time, NULL);
// Received connection, handle it.
if ((args.flags & 1) == 0) {
printf("Peer connected: addr is ");
- for (unsigned int idx = 0; idx < 16; ++idx) {
+ for (uint32_t idx = 0; idx < 16; ++idx) {
if (idx % 2 == 0 && idx > 0) {
printf(":");
}
}
#ifndef NDEBUG
// DEBUG print received buf.
- for (unsigned int idx = 0;
+ for (uint32_t idx = 0;
idx < C_SIMPLE_HTTP_RECV_BUF_SIZE && idx < read_ret;
++idx) {
if ((recv_buf[idx] >= 0x20 && recv_buf[idx] <= 0x7E)
enum C_SIMPLE_HTTP_ResponseCode response_code;
const char *response = c_simple_http_request_response(
(const char*)recv_buf,
- (unsigned int)read_ret,
+ (uint32_t)read_ret,
&parsed_config,
&response_size,
&response_code);
size_t content_length_buf_size = 0;
memcpy(content_length_buf, "Content-Length: ", 16);
content_length_buf_size = 16;
- int written = 0;
+ int32_t written = 0;
snprintf(
content_length_buf + content_length_buf_size,
127 - content_length_buf_size,
// Local includes.
#include "big_endian.h"
-int create_tcp_socket(unsigned short port) {
+int create_tcp_socket(uint16_t port) {
struct sockaddr_in6 ipv6_addr;
memset(&ipv6_addr, 0, sizeof(struct sockaddr_in6));
ipv6_addr.sin6_family = AF_INET6;
#ifndef 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
-int create_tcp_socket(unsigned short port);
+int create_tcp_socket(uint16_t port);
void cleanup_tcp_socket(int *tcp_socket);
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <stdint.h>
// Local includes.
#include "config.h"
#include <SimpleArchiver/src/helpers.h>
#include <SimpleArchiver/src/data_structures/hash_map.h>
-static int checks_checked = 0;
-static int checks_passed = 0;
+static int32_t checks_checked = 0;
+static int32_t checks_passed = 0;
#define RETURN() \
do { \