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 pname[255];
char pfunc[255]; char pfunc[255];
void (*fn)(int, const char*,dictionary); void (*fn)(int, const char*,const char*, dictionary);
struct plugin_entry *plugin ; struct plugin_entry *plugin ;
int plen = strlen(path); int plen = strlen(path);
char * rpath = (char*) malloc((plen+1)*sizeof(char)); 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) if(delim == NULL)
{ {
strcpy(pname,rpath); strcpy(pname,rpath);
strcpy(pfunc,"execute"); strcpy(pfunc,"default");
} }
else else
{ {
@ -515,7 +515,7 @@ int execute_plugin(int client, const char *path, const char *method, const char
LOG("Path : '%s'\n", rpath); LOG("Path : '%s'\n", rpath);
LOG("Method:%s\n", method); LOG("Method:%s\n", method);
LOG("Plugin name '%s'\n",pname); LOG("Plugin name '%s'\n",pname);
LOG("Plugin func. '%s'\n", pfunc); LOG("Query path. '%s'\n", pfunc);
LOG("query :%s\n", query_string); LOG("query :%s\n", query_string);
//load the plugin //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) if((plugin= plugin_load(pname)) == NULL)
return -1; return -1;
// load the function // 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) 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; return -1;
} }
dictionary dic = decode_request(client,method,query_string); dictionary dic = decode_request(client,method,query_string);
(*fn)(client,method,dic); (*fn)(client,method,pfunc,dic);
free(dic); free(dic);
free(rpath); free(rpath);
return 1; return 1;

View File

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

View File

@ -30,3 +30,14 @@ 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); jpeg(client);
__f(client,htdocs("images/ex.jpg")); __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

@ -190,3 +190,26 @@ void pexit()
{ {
LOG("Exit file manager,plugins\n"); 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,7 +138,7 @@ void pexit()
{ {
LOG("%s","EXIT daemon"); 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); text(c);
__t(c,"This is a system plugin. It cant be acessed from the web"); __t(c,"This is a system plugin. It cant be acessed from the web");

View File

@ -251,3 +251,8 @@ char* config_dir()
mkdir(path, 0755); mkdir(path, 0755);
return path; 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); void set_cookie(int,dictionary);
/*Default function for plugin*/ /*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"); __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'; buf[i] = '\0';
return i; 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); textstream(client);
int filedes[2]; int filedes[2];