From 9305d4f800a8fca7af467a9877b7e6c3dc234539 Mon Sep 17 00:00:00 2001 From: lxsang Date: Mon, 31 Oct 2016 17:34:20 +0100 Subject: [PATCH] add json request support --- Makefile | 2 +- build/.DS_Store | Bin 6148 -> 6148 bytes build/plugins/.DS_Store | Bin 6148 -> 6148 bytes plugin_manager.c | 24 +++++++++++++++++++++++- plugin_manager.h | 2 ++ plugins/fileman/fileman.c.o | Bin 14652 -> 14652 bytes plugins/pluginsman/pluginsman.c.o | Bin 9508 -> 9500 bytes plugins/utils.c | 7 ++++++- plugins/utils.h | 1 + 9 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index afa45a3..fd17953 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ ifeq ($(UNAME_S),Linux) PF_FLAG=-D_GNU_SOURCE endif ifeq ($(UNAME_S),Darwin) - BUILDIRD=./build + BUILDIRD=../ant-build PF_FLAG= endif CFLAGS=-W -Wall -g -std=c99 -D DEBUG -D USE_DB $(PF_FLAG) diff --git a/build/.DS_Store b/build/.DS_Store index dec238fa12d4ce8f3e0baf19645a0e3082787013..5cd543776f708ee805dfbe6cf1803212d8ff838e 100755 GIT binary patch delta 163 zcmZoMXfc@JFUrHfz`)4BAi%(o#E{5P%#g}ZTo%09ka;nttMR_^- zdFddHlX;k$CD|AOV delta 68 zcmZoMXfc=|&Zs)EP;8=}A_oHyFfuR*Y`kd3KJh`-W_At%4o20D7r!%4<`+>E1WGX^ QfYbm1h~2Q+QRFZ)066Lo1poj5 diff --git a/plugin_manager.c b/plugin_manager.c index 931192b..f276b35 100644 --- a/plugin_manager.c +++ b/plugin_manager.c @@ -91,9 +91,16 @@ dictionary decode_request(int client,const char* method,const char* query) //printf("Multi part form : %s\n", ctype); request = decode_multi_part_request(client,ctype); } + else if(strstr(ctype,APP_JSON) > 0) + { + char* query = json_data_decode(client,clen); + request = dict(); + dput(request,"json", strdup(query)); + free(query); + } else { - LOG("Un supported yet%s\n",ctype); + LOG("Un supported yet %s\n",ctype); return NULL; } } @@ -306,6 +313,21 @@ dictionary decode_url_request(const char* query) free(str_copy); return dic; } +/** +* Decode JSON query string to string +*/ +char* json_data_decode(int client,int len) +{ + char *query = (char*) malloc((len+1)*sizeof(char)); + for (int i = 0; i < len; i++) { + recv(client, (query+i), 1, 0); + } + query[len]='\0'; + //query = url_decode(query); + LOG("JSON Query %s\n", query); + return query; +} + /** * read the request as a string line format * @param sock socket diff --git a/plugin_manager.h b/plugin_manager.h index 740ea2c..0aec589 100644 --- a/plugin_manager.h +++ b/plugin_manager.h @@ -5,6 +5,7 @@ #define FORM_URL_ENCODE "application/x-www-form-urlencoded" #define FORM_MULTI_PART "multipart/form-data" +#define APP_JSON "application/json" #define PLUGIN_HANDLER "handler" struct plugin_entry { @@ -26,6 +27,7 @@ dictionary decode_url_request(const char* query); dictionary decode_request(int client,const char* method,const char* query); dictionary decode_multi_part_request(int,const char*); dictionary decode_cookie(const char*); +char* json_data_decode(int,int); char* read_line(int sock); int read_buf(int sock,char* buf,int i); int execute_plugin(int client, const char *path, diff --git a/plugins/fileman/fileman.c.o b/plugins/fileman/fileman.c.o index b392da8c1bad32c07bbf387f2967e2181dd5f6cc..bdc94b82c997a711ce6e9971ab18e9f30bc2348e 100644 GIT binary patch delta 2966 zcmZ8j3v3is6rJDhPTT40ZYj0DUE19RiX2U0th!{gOMuQS1fQd##@k9JZ&zZR+yS}7-_ndp)o%iP5 zduMZfxxUevx_;1|r7w!*%C&;A&)ucB{Kv+0-?`5{5B9?eJ}S5U`LH|HXo-DQTM$4y z?)K-g5&-P`U@waHiYz(dR+}xc({(;f3p?Vj1N+VY*fZ`?uuj|;g+l&()h)7GVzFdl zgzIB#tY6BC7WQ;)dg9S1H$FACreb%_-TbteQtE=X21<)h<3{GKVsP~A6+e}T1 z7(?C1h)Ozq)cH4&Ln(Z#O}Disp%=MpYZBSr^dxjf*yiA@dSWgZ#+%?F#sliE@sMVD z5jrn&RsBjIt^S9;h9x*q#2h-4d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hz#o}zh`T6i`LXMvo zapTA(#Q`l8D~}Z0Oel^xQk;4Xka$?|q}T`I#o8u?IT2C(?MN!m2A4>*almoXNhGHL z-8dYCVvCYu=L*H{CdH-~iqn`BC$ywzvyoyCM!Ag1A;*Ct90vp4I4dNw*FQUT{!pf| GCiNe9UuaYS diff --git a/plugins/pluginsman/pluginsman.c.o b/plugins/pluginsman/pluginsman.c.o index 50b396372233ce3ee502d0f29b724b7938446b80..002b7487e041c7a4d82d8e6692caa5ee1534c762 100644 GIT binary patch delta 2560 zcmZ9OYiJx*6vyYa+1b0d+udy3rZrs~CN^o(M_SOtS2y@-Y@0S|AjS`d_y|N$8|lL+ zwPX818nl>YR4izW&_rlOQbOyaQW`PZqKHJ0R;sNCQvF~-MXZSW|IeN&TL&`t{D1e{ zbMM@H?%5n%|JwS|w#_#$dI%E>o{cJbK525wmcGo)a7o z&YFdVcCsWtl2|{aOZrr>+G@$nii#pl1W#FoE7TM`5u677M0~dkoeUP*h0M*FlB^TD zD0l?4?|*b{@IL5Xp;J!D`N1IJ6f$daS4XG}?sEzYdxiE(+}0YyuwhpRN1T?-d(t~9 zy{`tBF{XV%N$#X0o`%JxwmImEtxB|dhLHsroF0k2Q<1oH>q9#p8+d&Cw&^?cSB^i7 zo|xm@g2vv3SA{7XW*A?~KA1gw&|$_*v%)IwIuP2c=xP;*#zQp;PpHASLNx^yw~GB| zs9f6$Rqp{%Gw~OdT|BkB0fwo@6Ie3z$GiUy#xje$M>wRuG?9tjGV7y>>`+}bQGGN~ zjD5>)#8^z*tEtwA>dXbH%Dj19u%a^W7a6^y>@zx|=;L8e6upiSIz;t{AJxIR4CgT3 z3GS6T4(kvMtI;_LQ+l-k;d)_{~U4I9YtF-U2F#JbY6L7HCbNHW;+JNEO!YmAJZ?wE>orDU< zby(gKT?IAabKoY+YtVU0s?Cd!RlQ z<>(zy--@cx&p}-j<@$OI@;8xbJqL9yZX3f?>0h9tpw;>hsMXT9L^okwk!sehWvWfz zRi-+157YxPu3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3)4S5#JBg2SDw1!LqzfiO1oR_g3gH-yl239H4rtAuIisClW{P1<~l{ z&v(;iQ)NY=5n?z#rSCv}00|JE;*@%zJ{9HZL8yzOVtNSbil{)3L;WTysn0^)jF*N{ zD)lc=#h6w4DpZrSWpyJa0#yiIm+00=hAOX@%~0LC2dYmx_Uc!lhD7!2NvJnO4e0Yw zaZ#J~cQe$W{t@a!ndo-?2h{uUEX1e6V^>GfbPr}2WE8#fFiY-MOs_7O{%z_j&_0+d zqj)_1ba*HCMHFJ2u%+~+FZSfCElc7%LBymL zFD5q;@4X=20wP`xLHt7?;-63&>u2EwAmbY$ZpCu)i^v@I5mbudN9F1%B!%ZvX%Q diff --git a/plugins/utils.c b/plugins/utils.c index a4edd32..f13dae2 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -320,11 +320,16 @@ char to_hex(char code) { return hex[code & 15]; } unsigned hash(const char* key, int hash_size) +{ + unsigned hashval = simple_hash(key); + return hashval % hash_size; +} +unsigned simple_hash(const char* key) { unsigned hashval; for (hashval = 0; *key != '\0'; key++) hashval = *key + 31 * hashval; - return hashval % hash_size; + return hashval; } int is_file(const char* f) { diff --git a/plugins/utils.h b/plugins/utils.h index 7109ea7..4631743 100644 --- a/plugins/utils.h +++ b/plugins/utils.h @@ -80,5 +80,6 @@ char *url_encode(const char *str); char from_hex(char ch); char to_hex(char code); unsigned hash(const char*, int); +unsigned simple_hash(const char*); int is_file(const char* f); #endif