From 9719875b8736951c4a984d9b4e091794e4756ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Wed, 23 Nov 2022 14:45:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=B1=BB=E5=9E=8B=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmoe.c | 18 +++++++++--------- cmoe.h | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmoe.c b/cmoe.c index 8067f42..155b176 100644 --- a/cmoe.c +++ b/cmoe.c @@ -8,7 +8,7 @@ #include "cmoe.h" static uint32_t* items_len; -static COUNTER counter; +static counter_t counter; static char* DATFILE = "dat.sp"; static char* TOKEN = "fumiama"; @@ -28,7 +28,7 @@ static void _headers(uint32_t content_len, const char* h, size_t hlen) { writev(1, &iov, 3); } -static void http_error(ERRCODE code, char* msg) { +static void http_error(errcode_enum_t code, char* msg) { uint32_t len = strlen(msg) + typel[code]; char* str = malloc(len); sprintf(str, types[code], msg); @@ -48,7 +48,7 @@ static char* get_arg(const char* query) { } static int del_user(FILE* fp, SIMPLE_PB* spb) { - COUNTER *d = (COUNTER *)spb->target; + counter_t *d = (counter_t *)spb->target; uint32_t next = ftell(fp); uint32_t this = next - spb->real_len; fseek(fp, 0, SEEK_END); @@ -77,7 +77,7 @@ static int add_user(char* name, uint32_t count, FILE* fp) { counter.count = count; strncpy(counter.name, name, COUNTER_NAME_LEN-1); fseek(fp, 0, SEEK_END); - return !set_pb(fp, items_len, sizeof(COUNTER), &counter); + return !set_pb(fp, items_len, sizeof(counter_t), &counter); } static uint32_t get_content_len(int isbig, uint16_t* len_type, char* cntstr) { @@ -105,10 +105,10 @@ static void return_count(char* name, char* theme) { } flock(fileno(fp), LOCK_EX); int ch, exist = 0, user_exist = 0; - char buf[sizeof(SIMPLE_PB)+sizeof(COUNTER)]; + char buf[sizeof(SIMPLE_PB)+sizeof(counter_t)]; while(has_next(fp, ch)) { SIMPLE_PB *spb = read_pb_into(fp, (SIMPLE_PB*)buf); - COUNTER *d = (COUNTER *)spb->target; + counter_t *d = (counter_t *)spb->target; if (strcmp(name, d->name)) continue; if(del_user(fp, spb)) { http_error(HTTP500, "Unable to Delete Old Data."); @@ -171,11 +171,11 @@ static int name_exist(char* name) { exit(EXIT_FAILURE); } int ch, exist = 0; - char buf[sizeof(SIMPLE_PB)+sizeof(COUNTER)]; + char buf[sizeof(SIMPLE_PB)+sizeof(counter_t)]; flock(fileno(fp), LOCK_EX); while(has_next(fp, ch)) { SIMPLE_PB *spb = read_pb_into(fp, (SIMPLE_PB*)buf); - COUNTER *d = (COUNTER *)spb->target; + counter_t *d = (counter_t *)spb->target; if (!strcmp(name, d->name)) { fclose(fp); return 1; @@ -197,7 +197,7 @@ int main(int argc, char **argv) { str = getenv("TOKEN"); if(str != NULL) TOKEN = str; char* name = strstr(QS, "name="); - items_len = align_struct(sizeof(COUNTER), 2, &counter.name, &counter.count); + items_len = align_struct(sizeof(counter_t), 2, &counter.name, &counter.count); if(!items_len) { http_error(HTTP500, "Align Struct Error."); return 2; diff --git a/cmoe.h b/cmoe.h index 0c9a554..78983aa 100644 --- a/cmoe.h +++ b/cmoe.h @@ -4,11 +4,11 @@ #include #define COUNTER_NAME_LEN 64 -struct COUNTER { +struct counter_t { char name[COUNTER_NAME_LEN]; uint32_t count; }; -typedef struct COUNTER COUNTER; +typedef struct counter_t counter_t; #define SERVER_STRING "Server: CMoe Counter by Fumiama/1.0\r\n" @@ -18,8 +18,8 @@ typedef struct COUNTER COUNTER; #define H500 "HTTP/1.0 500 Internal Server Error\r\nContent-Type: text/html\r\n\r\n

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