diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-04-05 22:35:25 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-04-05 22:35:35 +0200 |
commit | c43b487246fdfd2ddc5c794763b18255ac6a318e (patch) | |
tree | c5b2b5ef837e9e796842155a6f7943745c61d135 /src/blogc-runserver/httpd.c | |
parent | 0a7f6a2659b363e1d68202b9fd863b57f7420f4f (diff) | |
download | blogc-c43b487246fdfd2ddc5c794763b18255ac6a318e.tar.gz blogc-c43b487246fdfd2ddc5c794763b18255ac6a318e.tar.bz2 blogc-c43b487246fdfd2ddc5c794763b18255ac6a318e.zip |
*: use squareball
yeah, changed my mind again :)
Diffstat (limited to 'src/blogc-runserver/httpd.c')
-rw-r--r-- | src/blogc-runserver/httpd.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/blogc-runserver/httpd.c b/src/blogc-runserver/httpd.c index 9680229..b08a915 100644 --- a/src/blogc-runserver/httpd.c +++ b/src/blogc-runserver/httpd.c @@ -19,9 +19,8 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <pthread.h> -#include "../common/error.h" -#include "../common/file.h" -#include "../common/utils.h" +#include <squareball.h> + #include "mime.h" #include "httpd-utils.h" @@ -43,7 +42,7 @@ typedef struct { static void error(int socket, int status_code, const char *error) { - char *str = bc_strdup_printf( + char *str = sb_strdup_printf( "HTTP/1.0 %d %s\r\n" "Content-Type: text/html\r\n" "Content-Length: %zu\r\n" @@ -74,8 +73,8 @@ handle_request(void *arg) unsigned short status_code = 200; - char **pieces = bc_str_split(conn_line, ' ', 3); - if (bc_strv_length(pieces) != 3) { + char **pieces = sb_str_split(conn_line, ' ', 3); + if (sb_strv_length(pieces) != 3) { status_code = 400; error(client_socket, 400, "Bad Request"); goto point1; @@ -87,9 +86,9 @@ handle_request(void *arg) goto point1; } - char **pieces2 = bc_str_split(pieces[1], '?', 2); + char **pieces2 = sb_str_split(pieces[1], '?', 2); char *path = br_urldecode(pieces2[0]); - bc_strv_free(pieces2); + sb_strv_free(pieces2); if (path == NULL) { status_code = 400; @@ -97,7 +96,7 @@ handle_request(void *arg) goto point2; } - char *abs_path = bc_strdup_printf("%s/%s", docroot, path); + char *abs_path = sb_strdup_printf("%s/%s", docroot, path); char *real_path = realpath(abs_path, NULL); free(abs_path); @@ -155,7 +154,7 @@ handle_request(void *arg) if (add_slash) { // production webservers usually returns 301 in such cases, but 302 is // better for development/testing. - char *tmp = bc_strdup_printf( + char *tmp = sb_strdup_printf( "HTTP/1.0 302 Found\r\n" "Location: %s/\r\n" "Content-Length: 0\r\n" @@ -171,16 +170,16 @@ handle_request(void *arg) } size_t len; - bc_error_t *err = NULL; - char* contents = bc_file_get_contents(real_path, false, &len, &err); + sb_error_t *err = NULL; + char* contents = sb_file_get_contents(real_path, &len, &err); if (err != NULL) { status_code = 500; error(client_socket, 500, "Internal Server Error"); - bc_error_free(err); + sb_error_free(err); goto point4; } - char *out = bc_strdup_printf( + char *out = sb_strdup_printf( "HTTP/1.0 200 OK\r\n" "Content-Type: %s\r\n" "Content-Length: %zu\r\n" @@ -207,7 +206,7 @@ point1: fprintf(stderr, "[Thread-%zu] %s - - \"%s\" %d\n", thread_id + 1, ip, conn_line, status_code); free(conn_line); - bc_strv_free(pieces); + sb_strv_free(pieces); point0: free(ip); close(client_socket); @@ -227,7 +226,7 @@ br_httpd_get_ip(int af, const struct sockaddr *addr) struct sockaddr_in *a = (struct sockaddr_in*) addr; inet_ntop(af, &(a->sin_addr), host, INET6_ADDRSTRLEN); } - return bc_strdup(host); + return sb_strdup(host); } |