mirror of
https://github.com/lxsang/ant-http
synced 2024-12-26 00:38:21 +01:00
add json request support
This commit is contained in:
parent
08a29ee87e
commit
9305d4f800
2
Makefile
2
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)
|
||||
|
BIN
build/.DS_Store
vendored
BIN
build/.DS_Store
vendored
Binary file not shown.
BIN
build/plugins/.DS_Store
vendored
BIN
build/plugins/.DS_Store
vendored
Binary file not shown.
@ -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
|
||||
|
@ -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,
|
||||
|
Binary file not shown.
Binary file not shown.
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user