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 dec238f..5cd5437 100755 Binary files a/build/.DS_Store and b/build/.DS_Store differ diff --git a/build/plugins/.DS_Store b/build/plugins/.DS_Store index 5008ddf..e3dd20b 100755 Binary files a/build/plugins/.DS_Store and b/build/plugins/.DS_Store differ 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 b392da8..bdc94b8 100644 Binary files a/plugins/fileman/fileman.c.o and b/plugins/fileman/fileman.c.o differ diff --git a/plugins/pluginsman/pluginsman.c.o b/plugins/pluginsman/pluginsman.c.o index 50b3963..002b748 100644 Binary files a/plugins/pluginsman/pluginsman.c.o and b/plugins/pluginsman/pluginsman.c.o differ 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