2017-07-29 22:00:34 +02:00
|
|
|
#ifndef PLUGIN_H
|
|
|
|
#define PLUGIN_H
|
|
|
|
|
2020-08-25 17:04:17 +02:00
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2020-08-25 16:40:24 +02:00
|
|
|
#include "utils.h"
|
|
|
|
#include "handle.h"
|
2020-08-25 17:04:17 +02:00
|
|
|
#include "dbhelper.h"
|
2015-10-22 11:39:11 +02:00
|
|
|
|
|
|
|
|
2018-09-26 11:07:48 +02:00
|
|
|
//typedef void(*call)();
|
2016-02-26 14:32:13 +01:00
|
|
|
#ifdef USE_DB
|
2015-10-22 11:39:11 +02:00
|
|
|
typedef sqlite3* sqldb;
|
2016-02-26 14:32:13 +01:00
|
|
|
#endif
|
2015-10-22 11:39:11 +02:00
|
|
|
|
2017-07-29 22:00:34 +02:00
|
|
|
|
2016-02-26 14:32:13 +01:00
|
|
|
#ifdef USE_DB
|
2015-10-22 11:39:11 +02:00
|
|
|
sqldb getdb();
|
2016-10-30 16:14:04 +01:00
|
|
|
sqldb __getdb(char *name);
|
2016-02-26 14:32:13 +01:00
|
|
|
#endif
|
2017-07-29 22:00:34 +02:00
|
|
|
|
|
|
|
char* config_dir();
|
2015-10-22 11:39:11 +02:00
|
|
|
/*Default function for plugin*/
|
2018-09-26 11:07:48 +02:00
|
|
|
// init the plugin
|
2019-11-13 17:00:11 +01:00
|
|
|
void init();
|
|
|
|
void destroy();
|
2018-10-05 19:01:39 +02:00
|
|
|
void* handle(void*);
|
|
|
|
plugin_header_t* meta();
|
2018-10-08 19:32:23 +02:00
|
|
|
void use_raw_body();
|
2019-11-13 17:00:11 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
STATIC PART, should be included in any plugin
|
|
|
|
*/
|
2019-11-19 17:07:04 +01:00
|
|
|
#ifdef PLUGIN_IMPLEMENT
|
2019-11-13 17:00:11 +01:00
|
|
|
static plugin_header_t __plugin__;
|
|
|
|
// private function
|
2020-01-08 19:17:51 +01:00
|
|
|
void __init_plugin__(const char* pl){
|
|
|
|
strcpy(__plugin__.name,pl);
|
|
|
|
dbdir(__plugin__.dbpath);
|
|
|
|
plugindir(__plugin__.pdir);
|
|
|
|
tmpdir(__plugin__.tmpdir);
|
2019-11-13 17:00:11 +01:00
|
|
|
__plugin__.raw_body = 0;
|
|
|
|
init();
|
|
|
|
};
|
|
|
|
void use_raw_body()
|
|
|
|
{
|
|
|
|
__plugin__.raw_body = 1;
|
|
|
|
}
|
|
|
|
#ifdef USE_DB
|
|
|
|
sqldb __getdb(char *name)
|
|
|
|
{
|
|
|
|
int plen = strlen(name)+strlen(__plugin__.dbpath)+4;
|
|
|
|
char* path = (char*) malloc(plen*sizeof(char));
|
|
|
|
strcpy(path,__plugin__.dbpath);
|
|
|
|
strcat(path,name);
|
|
|
|
strcat(path,".db");
|
|
|
|
//LOG("database: %s\n", path);
|
|
|
|
sqldb ret = (sqldb)database(path);
|
|
|
|
free(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
sqldb getdb()
|
|
|
|
{
|
|
|
|
return __getdb(__plugin__.name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
plugin_header_t* meta()
|
|
|
|
{
|
|
|
|
return &__plugin__;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* config_dir()
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
char* path = __s("%s%s%s", __plugin__.pdir,DIR_SEP, __plugin__.name);
|
|
|
|
if (stat(path, &st) == -1)
|
|
|
|
mkdir(path, 0755);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __release__()
|
|
|
|
{
|
|
|
|
destroy();
|
|
|
|
}
|
2017-07-29 22:00:34 +02:00
|
|
|
#endif
|
2019-11-19 17:07:04 +01:00
|
|
|
#endif
|