From 8b7ce3394483a2b1229045ad065615234bfbf699 Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Sat, 22 Jul 2017 17:26:05 +0200 Subject: [PATCH] minor fix --- ._Makefile | Bin 4096 -> 0 bytes plugin_manager.c | 18 +++++++++++------- plugins/plugin.c | 14 ++++++-------- plugins/plugin.h | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) delete mode 100644 ._Makefile diff --git a/._Makefile b/._Makefile deleted file mode 100644 index f4c2e6ad2ba8411c4fe9ceddc086c90a90d4e79c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4096 zcmeH~v1$TA5Qcvh(KME+Y{k4HAFqBG+r(!0`h&8-~d;?nhpyA&-0hJ`YAH-*xPJr6z&w)c| zZ{Atr^jNP0iE>#dlPY(aEXa2}8B&FIb|UQ$mA+%p8qmJ$-Dt1phQ91KZGrdxN3Yu( z^h*y56JP>NfC(@GCcp%k025#WOn?bI8G%aJH|B37=~8=vMshx10C>hV+5i9m diff --git a/plugin_manager.c b/plugin_manager.c index 89f3186..0ec0873 100644 --- a/plugin_manager.c +++ b/plugin_manager.c @@ -38,6 +38,7 @@ dictionary decode_request(int client,const char* method,const char* query) { dictionary request = NULL; dictionary cookie = NULL; + dictionary xheader = dict(); char* line; char * token; if(strcmp(method,"GET") == 0) @@ -47,8 +48,12 @@ dictionary decode_request(int client,const char* method,const char* query) char* ws_key = NULL; while((line = read_line(client)) && strcmp("\r\n",line)) { + trim(line, '\n'); + trim(line, '\r'); token = strsep(&line,":"); trim(token,' '); + trim(line,' '); + dput(xheader,token,line); if(token != NULL &&strcasecmp(token,"Cookie") == 0) { if(!cookie) cookie = decode_cookie(line); @@ -57,16 +62,12 @@ dictionary decode_request(int client,const char* method,const char* query) { // verify that the connection is upgrade to websocket trim(line, ' '); - trim(line, '\n'); - trim(line, '\r'); if(line != NULL && strcasecmp(line,"websocket") == 0) ws = 1; } else if(token != NULL && strcasecmp(token,"Sec-WebSocket-Key") == 0) { // get the key from the client trim(line, ' '); - trim(line, '\n'); - trim(line, '\r'); ws_key = strdup(line); } } @@ -90,14 +91,16 @@ dictionary decode_request(int client,const char* method,const char* query) while (line && strcmp("\r\n",line)) { //printf("%s\n",line); + trim(line, '\n'); + trim(line, '\r'); token = strsep(&line,":"); trim(token,' '); + trim(line, ' '); + dput(xheader,token,line); if(token != NULL &&strcasecmp(token,"Content-Type") == 0) { ctype = strsep(&line,":"); trim(ctype,' '); - trim(ctype,'\n'); - trim(ctype,'\r'); } else if(token != NULL &&strcasecmp(token,"Content-Length") == 0) { token = strsep(&line,":"); @@ -140,10 +143,11 @@ dictionary decode_request(int client,const char* method,const char* query) } } //if(cookie->key == NULL) {free(cookie);cookie= NULL;} - if(cookie && !request) + if(!request) request = dict(); dput(request,"cookie",cookie); + dput(request,"__xheader__",xheader); return request; } void __px(const char* data,int size) diff --git a/plugins/plugin.c b/plugins/plugin.c index e7cc3fc..54c96c2 100644 --- a/plugins/plugin.c +++ b/plugins/plugin.c @@ -30,12 +30,10 @@ sqldb getdb() return getdb(__plugin__.name); } #endif -void header_base(int client) +void set_status(int client,int code,const char* msg) { - - response(client, "HTTP/1.0 200 OK"); + response(client, __s("HTTP/1.0 %d %s", code, msg)); response(client, __s("Server: %s ", SERVER_NAME)); - } void redirect(int client,const char*path) { @@ -60,7 +58,7 @@ void textstream(int client) } void octstream(int client, char* name) { - header_base(client); + set_status(client,200,"OK"); __t(client,"Content-Type: application/octet-stream"); __t(client,"Content-Disposition: attachment; filename=\"%s\"", name); response(client,""); @@ -72,7 +70,7 @@ void jpeg(int client) } void header(int client, const char* type) { - header_base(client); + set_status(client,200,"OK"); __t(client,"Content-Type: %s",type); response(client,""); } @@ -240,7 +238,7 @@ int upload(const char* tmp, const char* path) } void set_cookie(int client,const char* type, dictionary dic) { - header_base(client); + set_status(client,200,"OK"); __t(client,"Content-Type: %s",type); association assoc; for_each_assoc(assoc,dic){ @@ -250,7 +248,7 @@ void set_cookie(int client,const char* type, dictionary dic) } void clear_cookie(int client, dictionary dic) { - header_base(client); + set_status(client,200,"OK"); __t(client,"Content-Type: text/html; charset=utf-8"); association assoc; for_each_assoc(assoc,dic){ diff --git a/plugins/plugin.h b/plugins/plugin.h index 26bf0fc..cf59d87 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -36,7 +36,6 @@ extern plugin_header __plugin__; extern call __init__; int response(int, const char*); -void header_base(int); void header(int,const char*); void redirect(int,const char*); void html(int); @@ -59,6 +58,7 @@ sqldb getdb(); sqldb __getdb(char *name); #endif void set_cookie(int, const char*,dictionary); +void set_status(int,int,const char*); void clear_cookie(int, dictionary); /*Default function for plugin*/ void handler(int, const char*,const char*,dictionary);