1
0
mirror of https://github.com/lxsang/ant-http synced 2024-07-01 12:59:47 +02:00

major change for plugin handle

This commit is contained in:
lxsang 2016-10-29 15:02:16 +02:00
parent ccbf742713
commit 88e284e12b
19 changed files with 89 additions and 11 deletions

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

@ -487,7 +487,7 @@ int execute_plugin(int client, const char *path, const char *method, const char
{
char pname[255];
char pfunc[255];
void (*fn)(int, const char*,dictionary);
void (*fn)(int, const char*,const char*, dictionary);
struct plugin_entry *plugin ;
int plen = strlen(path);
char * rpath = (char*) malloc((plen+1)*sizeof(char));
@ -499,7 +499,7 @@ int execute_plugin(int client, const char *path, const char *method, const char
if(delim == NULL)
{
strcpy(pname,rpath);
strcpy(pfunc,"execute");
strcpy(pfunc,"default");
}
else
{
@ -515,7 +515,7 @@ int execute_plugin(int client, const char *path, const char *method, const char
LOG("Path : '%s'\n", rpath);
LOG("Method:%s\n", method);
LOG("Plugin name '%s'\n",pname);
LOG("Plugin func. '%s'\n", pfunc);
LOG("Query path. '%s'\n", pfunc);
LOG("query :%s\n", query_string);
//load the plugin
@ -523,14 +523,14 @@ int execute_plugin(int client, const char *path, const char *method, const char
if((plugin= plugin_load(pname)) == NULL)
return -1;
// load the function
fn = (void (*)(int, const char *, dictionary))dlsym(plugin->handle, pfunc);
fn = (void (*)(int, const char *, const char*, dictionary))dlsym(plugin->handle, PLUGIN_HANDLER);
if ((error = dlerror()) != NULL)
{
LOG("Problem when finding %s method from %s : %s \n", pfunc, pname,error);
LOG("Problem when finding %s method from %s : %s \n", PLUGIN_HANDLER, pname,error);
return -1;
}
dictionary dic = decode_request(client,method,query_string);
(*fn)(client,method,dic);
(*fn)(client,method,pfunc,dic);
free(dic);
free(rpath);
return 1;

View File

@ -5,7 +5,7 @@
#define FORM_URL_ENCODE "application/x-www-form-urlencoded"
#define FORM_MULTI_PART "multipart/form-data"
#define PLUGIN_HANDLER "handler"
struct plugin_entry {
struct plugin_entry *next;

View File

@ -29,4 +29,15 @@ void get(int client,const char* method,dictionary rq)
{
}
void handler(int client, const char* method, const char* rqpth, dictionary rq)
{
if(EQU(rqpth,"default"))
{
execute(client,method,rq);
}
else
{
unknow(client);
}
}

View File

@ -128,3 +128,26 @@ void jsonex(int client,const char* method,dictionary rq)
jpeg(client);
__f(client,htdocs("images/ex.jpg"));
}
void handler(int client, const char* method, const char* rqpth, dictionary rq)
{
if(EQU(rqpth,"default"))
{
execute(client,method,rq);
}
else if(EQU(rqpth,"delete"))
{
delete(client,method,rq);
}
else if(EQU(rqpth,"update"))
{
execute(client,method,rq);
}
else if(EQU(rqpth,"jsonex"))
{
execute(client,method,rq);
}
else
{
unknow(client);
}
}

View File

@ -189,4 +189,27 @@ void rmfolder(int c, const char* m, dictionary rq)
void pexit()
{
LOG("Exit file manager,plugins\n");
}
void handler(int client, const char* method, const char* rqpth, dictionary rq)
{
if(EQU(rqpth,"default"))
{
execute(client,method,rq);
}
else if(EQU(rqpth,"add"))
{
add(client,method,rq);
}
else if(EQU(rqpth,"rmfolder"))
{
rmfolder(client,method,rq);
}
else if(EQU(rqpth,"mkfolder"))
{
mkfolder(client,method,rq);
}
else
{
unknow(client);
}
}

Binary file not shown.

View File

@ -138,8 +138,8 @@ void pexit()
{
LOG("%s","EXIT daemon");
}
void execute(int c, const char* m, dictionary d)
void handler(int c, const char* m, const char* rqp, dictionary d)
{
text(c);
__t(c,"This is a system plugin. It cant be acessed from the web");
}
}

View File

@ -250,4 +250,9 @@ char* config_dir()
if (stat(path, &st) == -1)
mkdir(path, 0755);
return path;
}
void unknow(int client)
{
html(client);
__t(client,"404 API not found");
}

View File

@ -59,4 +59,5 @@ sqldb getdb();
void set_cookie(int,dictionary);
/*Default function for plugin*/
void execute(int, const char*,dictionary);
void handler(int, const char*,const char*,dictionary);
void unknow(int);

View File

@ -74,3 +74,18 @@ void install(int c, const char* m, dictionary rq)
__t(c,result,0,"This is not a plugin file");
}
void handler(int client, const char* method, const char* rqpth, dictionary rq)
{
if(EQU(rqpth,"default"))
{
execute(client,method,rq);
}
else if(EQU(rqpth,"install"))
{
install(client,method,rq);
}
else
{
unknow(client);
}
}

Binary file not shown.

View File

@ -37,7 +37,7 @@ int read_buf(int fd, char*buf,int size)
buf[i] = '\0';
return i;
}
void execute(int client, const char* m, dictionary rq)
void handler(int client, const char* m, const char* rqp, dictionary rq)
{
textstream(client);
int filedes[2];