ninor fix

This commit is contained in:
lxsang 2016-10-30 16:14:04 +01:00
parent 88e284e12b
commit 08a29ee87e
18 changed files with 74 additions and 26 deletions

View File

@ -13,7 +13,7 @@ ifeq ($(UNAME_S),Darwin)
endif
CFLAGS=-W -Wall -g -std=c99 -D DEBUG -D USE_DB $(PF_FLAG)
#-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
PLUGINLIBS = -lsqlite3

View File

@ -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
[AUTOSTART]
plugin = nodedaemon
;plugin = nodedaemon
;plugin=ffvm
;plugin=dummy

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -37,12 +37,13 @@ char* post_url_decode(int client,int len)
dictionary decode_request(int client,const char* method,const char* query)
{
dictionary request = NULL;
dictionary cookie = NULL;
char* line;
if(strcmp(method,"GET") == 0)
{
while((line = read_line(client)) && strcmp("\r\n",line))
{
decode_cookie(line);
if(!cookie) cookie = decode_cookie(line);
}
request = decode_url_request(query);
}
@ -70,7 +71,7 @@ dictionary decode_request(int client,const char* method,const char* query)
}
else
{
decode_cookie(line);
if(!cookie) cookie = decode_cookie(line);
}
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)
{
//printf("Multi part form : %s\n", ctype);
return decode_multi_part_request(client,ctype);
request = decode_multi_part_request(client,ctype);
}
else
{
@ -96,6 +97,11 @@ dictionary decode_request(int client,const char* method,const char* query)
return NULL;
}
}
//if(cookie->key == NULL) {free(cookie);cookie= NULL;}
if(cookie && !request)
request = dict();
dput(request,"cookie",cookie);
return request;
}
void __px(const char* data,int size)
@ -119,21 +125,20 @@ dictionary decode_cookie(const char* line)
trim(token,' ');
if(token != NULL &&strcasecmp(token,"Cookie") == 0)
{
printf("%s\n", line);
token = strsep(&cpstr,":");
if(token)
while((token = strsep(&cpstr,";")))
{
while((token1 = strsep(&token,";")))
LOG("Found cookie : %s\n",token1);
}
else
token1 = strsep(&token,"=");
if(token1)
{
//free(cpstr);
return NULL;
if(dic == NULL)
dic = dict();
LOG("Found cookie : %s = %s\n",token1,token);
dput(dic,token1,token);
}
}
}
//free(cpstr);
return dic;
//free(cpstr);
}
/**
* Decode the multi-part form data from the POST request

View File

@ -27,7 +27,23 @@ void execute(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)
@ -36,6 +52,10 @@ void handler(int client, const char* method, const char* rqpth, dictionary rq)
{
execute(client,method,rq);
}
else if(EQU(rqpth,"get"))
{
get(client,method,rq);
}
else
{
unknow(client);

View File

@ -176,11 +176,13 @@ dbrecord dbselect(sqlite3* db, const char* table,const char* fstring,...)
}
int hastable(sqlite3* db,const char* table)
{
char * prefix = "select * from sqlite_master where type='table' and name='%s'";
char* sql = __s(prefix,table);
int ret = dbquery(db,sql,NULL);
free(sql);
return ~ret;
char * prefix = __s("type='table' and name='%s'",table);
dbrecord rc = dbselect(db,"sqlite_master",prefix);
free(prefix);
if(!rc) return 0;
if(!rc->fields) return 0;
free(rc);
return 1;
}
int dbupdate(sqlite3* db,const char* table,const dbfield field,const char* fstring,...)
{

Binary file not shown.

View File

@ -14,9 +14,9 @@ void __init_plugin__(const char* pl,const char*ph,const char* htdocs, const char
};
#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));
strcpy(path,__plugin__.dbpath);
strcat(path,__plugin__.name);
@ -25,6 +25,10 @@ sqldb getdb()
free(path);
return ret;
}
sqldb getdb()
{
return getdb(__plugin__.name);
}
#endif
void header_base(int client)
{
@ -243,6 +247,16 @@ void set_cookie(int client,dictionary dic)
}
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()
{
struct stat st;

View File

@ -55,9 +55,10 @@ char* route(const char*);
char* htdocs(const char*);
#ifdef USE_DB
sqldb getdb();
sqldb __getdb(char *name);
#endif
void set_cookie(int,dictionary);
void clear_cookie(int, dictionary);
/*Default function for plugin*/
void handler(int, const char*,const char*,dictionary);
void unknow(int);

Binary file not shown.

View File

@ -326,3 +326,8 @@ unsigned hash(const char* key, int hash_size)
hashval = *key + 31 * hashval;
return hashval % hash_size;
}
int is_file(const char* f)
{
struct stat st;
return !(stat(f, &st) == -1);
}

View File

@ -80,4 +80,5 @@ char *url_encode(const char *str);
char from_hex(char ch);
char to_hex(char code);
unsigned hash(const char*, int);
int is_file(const char* f);
#endif