fix: even more night fixes (seems like a friday)
This commit is contained in:
parent
7633ac9de5
commit
c675e3253b
18 changed files with 111 additions and 44 deletions
|
|
@ -3,8 +3,10 @@
|
|||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../server/server.h"
|
||||
#include "../utils/files/files.h"
|
||||
|
||||
static struct config *config;
|
||||
|
||||
|
|
@ -42,8 +44,24 @@ void stop_daemon(void)
|
|||
}
|
||||
|
||||
int start_daemon(void)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (!pid) // Daemon
|
||||
{
|
||||
start_server("localhost", config->servers->port);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write pid
|
||||
int err = write_pid(config->pid_file, pid);
|
||||
if (err != 0)
|
||||
{
|
||||
kill(pid, SIGINT);
|
||||
return 1;
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -326,10 +326,6 @@ struct string *format_response(struct http_response *resp)
|
|||
|
||||
string_concat_str(res, "\r\n", 2);
|
||||
|
||||
// Time
|
||||
char *time = get_time();
|
||||
string_concat_str(res, time, strlen(time));
|
||||
|
||||
// Headers
|
||||
struct http_header *cur_header = resp->headers;
|
||||
while (cur_header != NULL)
|
||||
|
|
@ -337,6 +333,11 @@ struct string *format_response(struct http_response *resp)
|
|||
string_concat_str(res, cur_header->field->data,
|
||||
cur_header->field->size);
|
||||
|
||||
string_concat_str(res, ": ", 2);
|
||||
|
||||
string_concat_str(res, cur_header->value->data,
|
||||
cur_header->value->size);
|
||||
|
||||
string_concat_str(res, "\r\n", 2);
|
||||
|
||||
cur_header = cur_header->next;
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@
|
|||
|
||||
// === Includes
|
||||
|
||||
#include "../utils/string/string.h"
|
||||
#include "../config/config.h"
|
||||
#include "../utils/string/string.h"
|
||||
|
||||
// === Enums
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,7 @@ void log_request(char* request_type, char* target, char* client_ip);
|
|||
* @param target
|
||||
* @param client_ip
|
||||
*/
|
||||
void log_response(int status_code, char* request_type, char* target, char* client_ip);
|
||||
|
||||
|
||||
void log_response(int status_code, char *request_type, char *target,
|
||||
char *client_ip);
|
||||
|
||||
#endif // ! LOGS_H
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ int main(int argc, char **argv)
|
|||
// Initialize modules
|
||||
log_init(config); // Ignore ret val
|
||||
http_init(config);
|
||||
daemon_init(config);
|
||||
|
||||
// Start server
|
||||
switch (config->daemon)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "files.h"
|
||||
|
||||
#include <stdio.h>
|
||||
// #include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
// #include "../string/string.h"
|
||||
|
|
@ -59,3 +58,33 @@ ssize_t get_file_content_size(const char *path)
|
|||
|
||||
return res;
|
||||
}
|
||||
|
||||
int write_to_file(const char *path, struct string *buf)
|
||||
{
|
||||
FILE *stream = fopen(path, "w");
|
||||
if (stream == NULL)
|
||||
return 1;
|
||||
|
||||
fwrite(buf->data, sizeof(char), buf->size, stream);
|
||||
|
||||
fclose(stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int write_pid(const char *filepath, int pid)
|
||||
{
|
||||
FILE *stream = fopen(filepath, "w");
|
||||
if (stream == NULL)
|
||||
return 1;
|
||||
|
||||
if (fprintf(stream, "%d", pid) <= 0)
|
||||
{
|
||||
fclose(stream);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fclose(stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ int is_directory(const char* path);
|
|||
*/
|
||||
char *get_file(const char *path);
|
||||
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*
|
||||
|
|
@ -68,7 +67,7 @@ bool check_filename(struct string* path);
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
bool sanitize_filename(struct string* filename);
|
||||
// bool sanitize_filename(struct string *filename);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
|
|
@ -79,4 +78,22 @@ bool sanitize_filename(struct string* filename);
|
|||
*/
|
||||
ssize_t get_file_content_size(const char *path);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*
|
||||
* @param path
|
||||
*
|
||||
* @return 0 on success, the corresponding error code otherwise
|
||||
*/
|
||||
int write_to_file(const char *path, struct string* buf);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*
|
||||
* @param path
|
||||
*
|
||||
* @return 0 on success, the corresponding error code otherwise
|
||||
*/
|
||||
int write_pid(const char *filepath, int pid);
|
||||
|
||||
#endif // ! FILES_H
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@
|
|||
// === Includes
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "../string/string.h"
|
||||
|
||||
// === Functions
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
#ifndef WORDS_H
|
||||
#define WORDS_H
|
||||
|
||||
|
||||
// === Includes
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "../string/string.h"
|
||||
|
||||
// === Functions
|
||||
|
|
@ -30,8 +30,8 @@ ssize_t read_word_delim(struct string *str, size_t offset, struct string **res,
|
|||
/*
|
||||
* Doc: TODO
|
||||
*/
|
||||
ssize_t read_word_restrict(struct string *str, size_t offset, struct string **res,
|
||||
const char *restr);
|
||||
ssize_t read_word_restrict(struct string *str, size_t offset,
|
||||
struct string **res, const char *restr);
|
||||
|
||||
/*
|
||||
* Doc: TODO
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
[global]
|
||||
log = true
|
||||
pid_file = /tmp/HTTPd.pid
|
||||
daemon = start
|
||||
|
||||
[[vhosts]]
|
||||
server_name = my_server
|
||||
Loading…
Add table
Add a link
Reference in a new issue