mirror of
https://github.com/lxsang/ant-http
synced 2024-12-26 16:58:22 +01:00
ninor fix
This commit is contained in:
parent
88e284e12b
commit
08a29ee87e
2
Makefile
2
Makefile
@ -13,7 +13,7 @@ ifeq ($(UNAME_S),Darwin)
|
|||||||
endif
|
endif
|
||||||
CFLAGS=-W -Wall -g -std=c99 -D DEBUG -D USE_DB $(PF_FLAG)
|
CFLAGS=-W -Wall -g -std=c99 -D DEBUG -D USE_DB $(PF_FLAG)
|
||||||
#-lsocket
|
#-lsocket
|
||||||
PLUGINS= dummy.$(EXT) fileman.$(EXT) pluginsman.$(EXT) wterm.$(EXT) nodedaemon.$(EXT)
|
PLUGINS= dummy.$(EXT) fileman.$(EXT) pluginsman.$(EXT) wterm.$(EXT) nodedaemon.$(EXT) cookiex.$(EXT)
|
||||||
|
|
||||||
PLUGINSDEP = plugins/ini.o plugins/plugin.o plugins/dbhelper.o plugins/dictionary.o plugins/utils.o plugins/list.o
|
PLUGINSDEP = plugins/ini.o plugins/plugin.o plugins/dbhelper.o plugins/dictionary.o plugins/utils.o plugins/list.o
|
||||||
PLUGINLIBS = -lsqlite3
|
PLUGINLIBS = -lsqlite3
|
||||||
|
@ -8,6 +8,6 @@ tmpdir=/Users/mrsang/Google Drive/ushare/cwp/ant-http/build/tmp/
|
|||||||
|
|
||||||
; This enable some plugins to be initialised at server startup
|
; This enable some plugins to be initialised at server startup
|
||||||
[AUTOSTART]
|
[AUTOSTART]
|
||||||
plugin = nodedaemon
|
;plugin = nodedaemon
|
||||||
;plugin=ffvm
|
;plugin=ffvm
|
||||||
;plugin=dummy
|
;plugin=dummy
|
||||||
|
BIN
build/httpd
BIN
build/httpd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -37,12 +37,13 @@ char* post_url_decode(int client,int len)
|
|||||||
dictionary decode_request(int client,const char* method,const char* query)
|
dictionary decode_request(int client,const char* method,const char* query)
|
||||||
{
|
{
|
||||||
dictionary request = NULL;
|
dictionary request = NULL;
|
||||||
|
dictionary cookie = NULL;
|
||||||
char* line;
|
char* line;
|
||||||
if(strcmp(method,"GET") == 0)
|
if(strcmp(method,"GET") == 0)
|
||||||
{
|
{
|
||||||
while((line = read_line(client)) && strcmp("\r\n",line))
|
while((line = read_line(client)) && strcmp("\r\n",line))
|
||||||
{
|
{
|
||||||
decode_cookie(line);
|
if(!cookie) cookie = decode_cookie(line);
|
||||||
}
|
}
|
||||||
request = decode_url_request(query);
|
request = decode_url_request(query);
|
||||||
}
|
}
|
||||||
@ -70,7 +71,7 @@ dictionary decode_request(int client,const char* method,const char* query)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
decode_cookie(line);
|
if(!cookie) cookie = decode_cookie(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
line = read_line(client);
|
line = read_line(client);
|
||||||
@ -88,7 +89,7 @@ dictionary decode_request(int client,const char* method,const char* query)
|
|||||||
} else if(strstr(ctype,FORM_MULTI_PART)> 0)
|
} else if(strstr(ctype,FORM_MULTI_PART)> 0)
|
||||||
{
|
{
|
||||||
//printf("Multi part form : %s\n", ctype);
|
//printf("Multi part form : %s\n", ctype);
|
||||||
return decode_multi_part_request(client,ctype);
|
request = decode_multi_part_request(client,ctype);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -96,6 +97,11 @@ dictionary decode_request(int client,const char* method,const char* query)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//if(cookie->key == NULL) {free(cookie);cookie= NULL;}
|
||||||
|
if(cookie && !request)
|
||||||
|
request = dict();
|
||||||
|
|
||||||
|
dput(request,"cookie",cookie);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
void __px(const char* data,int size)
|
void __px(const char* data,int size)
|
||||||
@ -119,21 +125,20 @@ dictionary decode_cookie(const char* line)
|
|||||||
trim(token,' ');
|
trim(token,' ');
|
||||||
if(token != NULL &&strcasecmp(token,"Cookie") == 0)
|
if(token != NULL &&strcasecmp(token,"Cookie") == 0)
|
||||||
{
|
{
|
||||||
printf("%s\n", line);
|
while((token = strsep(&cpstr,";")))
|
||||||
token = strsep(&cpstr,":");
|
|
||||||
if(token)
|
|
||||||
{
|
{
|
||||||
while((token1 = strsep(&token,";")))
|
token1 = strsep(&token,"=");
|
||||||
LOG("Found cookie : %s\n",token1);
|
if(token1)
|
||||||
}
|
{
|
||||||
else
|
if(dic == NULL)
|
||||||
{
|
dic = dict();
|
||||||
//free(cpstr);
|
LOG("Found cookie : %s = %s\n",token1,token);
|
||||||
return NULL;
|
dput(dic,token1,token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//free(cpstr);
|
|
||||||
return dic;
|
return dic;
|
||||||
|
//free(cpstr);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Decode the multi-part form data from the POST request
|
* Decode the multi-part form data from the POST request
|
||||||
|
@ -27,7 +27,23 @@ void execute(int client,const char* method,dictionary rq)
|
|||||||
|
|
||||||
void get(int client,const char* method,dictionary rq)
|
void get(int client,const char* method,dictionary rq)
|
||||||
{
|
{
|
||||||
|
html(client);
|
||||||
|
if(rq)
|
||||||
|
{
|
||||||
|
dictionary ck = (dictionary)dvalue(rq,"cookie");
|
||||||
|
if(ck)
|
||||||
|
{
|
||||||
|
association as;
|
||||||
|
for_each_assoc(as, ck)
|
||||||
|
{
|
||||||
|
__t(client,"%s -> %s <br/>",as->key, as->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
__t(client,"noo cookie");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
__t(client,"no request");
|
||||||
|
|
||||||
}
|
}
|
||||||
void handler(int client, const char* method, const char* rqpth, dictionary rq)
|
void handler(int client, const char* method, const char* rqpth, dictionary rq)
|
||||||
@ -36,6 +52,10 @@ void handler(int client, const char* method, const char* rqpth, dictionary rq)
|
|||||||
{
|
{
|
||||||
execute(client,method,rq);
|
execute(client,method,rq);
|
||||||
}
|
}
|
||||||
|
else if(EQU(rqpth,"get"))
|
||||||
|
{
|
||||||
|
get(client,method,rq);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unknow(client);
|
unknow(client);
|
||||||
|
@ -176,11 +176,13 @@ dbrecord dbselect(sqlite3* db, const char* table,const char* fstring,...)
|
|||||||
}
|
}
|
||||||
int hastable(sqlite3* db,const char* table)
|
int hastable(sqlite3* db,const char* table)
|
||||||
{
|
{
|
||||||
char * prefix = "select * from sqlite_master where type='table' and name='%s'";
|
char * prefix = __s("type='table' and name='%s'",table);
|
||||||
char* sql = __s(prefix,table);
|
dbrecord rc = dbselect(db,"sqlite_master",prefix);
|
||||||
int ret = dbquery(db,sql,NULL);
|
free(prefix);
|
||||||
free(sql);
|
if(!rc) return 0;
|
||||||
return ~ret;
|
if(!rc->fields) return 0;
|
||||||
|
free(rc);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
int dbupdate(sqlite3* db,const char* table,const dbfield field,const char* fstring,...)
|
int dbupdate(sqlite3* db,const char* table,const dbfield field,const char* fstring,...)
|
||||||
{
|
{
|
||||||
|
Binary file not shown.
@ -14,9 +14,9 @@ void __init_plugin__(const char* pl,const char*ph,const char* htdocs, const char
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef USE_DB
|
#ifdef USE_DB
|
||||||
sqldb getdb()
|
sqldb __getdb(char *name)
|
||||||
{
|
{
|
||||||
int plen = strlen(__plugin__.name)+strlen(__plugin__.dbpath)+4;
|
int plen = strlen(name)+strlen(__plugin__.dbpath)+4;
|
||||||
char* path = (char*) malloc(plen*sizeof(char));
|
char* path = (char*) malloc(plen*sizeof(char));
|
||||||
strcpy(path,__plugin__.dbpath);
|
strcpy(path,__plugin__.dbpath);
|
||||||
strcat(path,__plugin__.name);
|
strcat(path,__plugin__.name);
|
||||||
@ -25,6 +25,10 @@ sqldb getdb()
|
|||||||
free(path);
|
free(path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
sqldb getdb()
|
||||||
|
{
|
||||||
|
return getdb(__plugin__.name);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
void header_base(int client)
|
void header_base(int client)
|
||||||
{
|
{
|
||||||
@ -243,6 +247,16 @@ void set_cookie(int client,dictionary dic)
|
|||||||
}
|
}
|
||||||
response(client,"");
|
response(client,"");
|
||||||
}
|
}
|
||||||
|
void clear_cookie(int client, dictionary dic)
|
||||||
|
{
|
||||||
|
header_base(client);
|
||||||
|
__t(client,"Content-Type: text/html; charset=utf-8");
|
||||||
|
association assoc;
|
||||||
|
for_each_assoc(assoc,dic){
|
||||||
|
__t(client,"Set-Cookie: %s=%s;expires=",assoc->key, (char*)assoc->value, server_time());
|
||||||
|
}
|
||||||
|
response(client,"");
|
||||||
|
}
|
||||||
char* config_dir()
|
char* config_dir()
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
@ -55,9 +55,10 @@ char* route(const char*);
|
|||||||
char* htdocs(const char*);
|
char* htdocs(const char*);
|
||||||
#ifdef USE_DB
|
#ifdef USE_DB
|
||||||
sqldb getdb();
|
sqldb getdb();
|
||||||
|
sqldb __getdb(char *name);
|
||||||
#endif
|
#endif
|
||||||
void set_cookie(int,dictionary);
|
void set_cookie(int,dictionary);
|
||||||
|
void clear_cookie(int, dictionary);
|
||||||
/*Default function for plugin*/
|
/*Default function for plugin*/
|
||||||
void handler(int, const char*,const char*,dictionary);
|
void handler(int, const char*,const char*,dictionary);
|
||||||
void unknow(int);
|
void unknow(int);
|
||||||
|
Binary file not shown.
@ -325,4 +325,9 @@ unsigned hash(const char* key, int hash_size)
|
|||||||
for (hashval = 0; *key != '\0'; key++)
|
for (hashval = 0; *key != '\0'; key++)
|
||||||
hashval = *key + 31 * hashval;
|
hashval = *key + 31 * hashval;
|
||||||
return hashval % hash_size;
|
return hashval % hash_size;
|
||||||
|
}
|
||||||
|
int is_file(const char* f)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
return !(stat(f, &st) == -1);
|
||||||
}
|
}
|
@ -80,4 +80,5 @@ char *url_encode(const char *str);
|
|||||||
char from_hex(char ch);
|
char from_hex(char ch);
|
||||||
char to_hex(char code);
|
char to_hex(char code);
|
||||||
unsigned hash(const char*, int);
|
unsigned hash(const char*, int);
|
||||||
|
int is_file(const char* f);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user