diff --git a/cmoe.c b/cmoe.c index f5a53d4..c54eb9b 100644 --- a/cmoe.c +++ b/cmoe.c @@ -22,8 +22,7 @@ static void headers(uint32_t content_len, const char* content_type) { char buf[1024]; uint32_t offset = 0; - ADD_HERDER(H200 SERVER_STRING); - ADD_HERDER(CACHE_CTRL); + ADD_HERDER(HTTP200 SERVER_STRING CACHE_CTRL); ADD_HERDER_PARAM(CONTENT_TYPE, content_type); ADD_HERDER_PARAM(CONTENT_LEN "\r\n", content_len); content_len += offset; @@ -31,7 +30,7 @@ static void headers(uint32_t content_len, const char* content_type) { write(1, buf, offset); } -static void http_error(RESPCODE code, char* msg) { +static void http_error(ERRCODE code, char* msg) { uint32_t len = strlen(msg) + typel[code]; char* str = malloc(len); sprintf(str, types[code], msg); @@ -156,11 +155,12 @@ static void return_count(char* name, char* theme) { } free(spb); user_exist = 1; - break; + return; } } else free(spb); } if(!user_exist) http_error(HTTP404, "No Such User."); + fclose(fp); } else http_error(HTTP500, "Open File Error."); } diff --git a/cmoe.h b/cmoe.h index c06cb48..6d4dfb0 100644 --- a/cmoe.h +++ b/cmoe.h @@ -15,14 +15,14 @@ typedef struct COUNTER COUNTER; #define SERVER_STRING "Server: CMoe Counter by Fumiama/1.0\r\n" -#define H200 "HTTP/1.0 200 OK\r\n" +#define HTTP200 "HTTP/1.0 200 OK\r\n" #define H400 "HTTP/1.0 400 BAD REQUEST\r\nContent-Type: text/html\r\n\r\n

%s\r\n" #define H404 "HTTP/1.0 404 NOT FOUND\r\nContent-Type: text/html\r\n\r\nNot Found\r\n

%s\r\n\r\n" #define H500 "HTTP/1.0 500 Internal Server Error\r\nContent-Type: text/html\r\n\r\n

%s\r\n" -const char* types[] = {H200, H400, H404, H500}; -const uint8_t typel[] = {18, 59, 111, 69}; -enum RESPCODE {HTTP200, HTTP400, HTTP404, HTTP500}; -typedef enum RESPCODE RESPCODE; +const char* types[] = {H400, H404, H500}; +const uint8_t typel[] = {59, 111, 69}; +enum ERRCODE {HTTP400, HTTP404, HTTP500}; +typedef enum ERRCODE ERRCODE; #define CONTENT_TYPE "Content-Type: %s\r\n" #define CONTENT_LEN "Content-Length: %d\r\n"