From 53d70d3c1ffda05aedc8826709ad6550b309e216 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: Sat, 11 Sep 2021 23:16:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=8F=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=B0=8F=E9=94=99=E8=AF=AF=EF=BC=8C=E4=BC=98=E5=8C=96=E4=B8=80?= =?UTF-8?q?=E7=82=B9=E7=82=B9=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmoe.c | 19 ++++++++++--------- cmoe.h | 2 ++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cmoe.c b/cmoe.c index 4b68dea..dc0675f 100644 --- a/cmoe.c +++ b/cmoe.c @@ -16,20 +16,21 @@ static void write2stdo(char* buf, uint32_t size, uint32_t content_len) { fflush(stdout); } -#define ADD_HERDER(h)\ +#define ADD_HERDER(h) {\ strcpy(buf + offset, (h));\ - offset += sizeof((h)) - 1; -#define ADD_HERDER_PARAM(h, p)\ + offset += sizeof((h)) - 1;\ +} +#define ADD_HERDER_PARAM(h, p) {\ sprintf(buf + offset, (h), (p));\ - offset += strlen(buf + offset); -#define EXTNM_IS_NOT(name) (strcmp(filepath+extpos, name)) + offset += strlen(buf + offset);\ +} -static void headers(uint32_t content_len, const char* content_type, int no_cache) { +static void headers(uint32_t content_len, const char* content_type) { char buf[1024]; uint32_t offset = 0; ADD_HERDER(HTTP200 SERVER_STRING); - if(no_cache) ADD_HERDER(CACHE_CTRL); + ADD_HERDER(CACHE_CTRL); ADD_HERDER_PARAM(CONTENT_TYPE, content_type); ADD_HERDER_PARAM(CONTENT_LEN "\r\n", content_len); write2stdo(buf, offset, content_len); @@ -145,7 +146,7 @@ static void return_count(char* name, char* theme) { h = H_SMALL; head = svg_small; } - headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml", 1); + headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml"); fwrite(head, sizeof(svg_small)-1, 1, stdout); for(int i = 0; i < 10; i++) { printf(img_slot_front, w * i, w, h); @@ -213,7 +214,7 @@ int main(int argc, char **argv) { add_user(name, 0, fp); fclose(fp); char* msg = "
Success.\r\n"; - headers(strlen(msg), "text/html", 1); + headers(strlen(msg), "text/html"); fwrite(msg, strlen(msg), 1, stdout); } else http_error(HTTP500, "Open File Error."); } else http_error(HTTP400, "Name Exist."); diff --git a/cmoe.h b/cmoe.h index 2cb00af..05633cd 100644 --- a/cmoe.h +++ b/cmoe.h @@ -3,6 +3,7 @@ #define DATFILE "dat.sp" #define TOKEN "fumiama" + #define COUNTER_NAME_LEN 64 struct COUNTER { char name[COUNTER_NAME_LEN]; @@ -31,6 +32,7 @@ const uint16_t gbhl[] = {1550, 1702, 1870, 1778, 1618, 2370, 1830, 2234, 1914, 1 #define H_SMALL 100 #define W_BIG 68 #define H_BIG 150 + const char svg_small[] = "