fix readme

This commit is contained in:
lxsang 2019-11-13 17:00:11 +01:00
parent b82e992ef2
commit 97228be9e6
2 changed files with 106 additions and 10 deletions

View File

@ -3,15 +3,16 @@ AUTOMAKE_OPTIONS = foreign
# check for system # check for system
if LINUX #if LINUX
AM_CPPFLAGS = -Wl,--no-as-needed # AM_CPPFLAGS = -Wl,--no-as-needed
else #else
AM_CPPFLAGS = -Wl,-undefined,dynamic_lookup # AM_CPPFLAGS = -Wl,-undefined,dynamic_lookup
endif #endif
AM_CPPFLAGS += -W -Wall -g -std=c99 -DCONFIG_FILE=\"$(sysconfdir)/antd-config.ini\" AM_CPPFLAGS = -W -Wall -g -std=c99 -DCONFIG_FILE=\"$(sysconfdir)/antd-config.ini\"
# dynamic library
lib_LTLIBRARIES = libantd.la lib_LTLIBRARIES = libantd.la
libantd_la_SOURCES = lib/ini.c \ libantd_la_SOURCES = lib/ini.c \
lib/handle.c \ lib/handle.c \
@ -21,8 +22,8 @@ libantd_la_SOURCES = lib/ini.c \
lib/ws.c \ lib/ws.c \
lib/sha1.c \ lib/sha1.c \
lib/list.c \ lib/list.c \
lib/scheduler.c\ lib/scheduler.c
lib/plugin.c
pkginclude_HEADERS = lib/ini.h \ pkginclude_HEADERS = lib/ini.h \
lib/handle.h \ lib/handle.h \
lib/dictionary.h \ lib/dictionary.h \
@ -34,6 +35,7 @@ pkginclude_HEADERS = lib/ini.h \
lib/scheduler.h \ lib/scheduler.h \
lib/plugin.h lib/plugin.h
EXTRA_DIST = plugin_manager.h http_server.h README.md LICENSE antd-config.ini EXTRA_DIST = plugin_manager.h http_server.h README.md LICENSE antd-config.ini
# check for db # check for db
if DB if DB

View File

@ -25,9 +25,103 @@ char* htdocs(const char*);
char* config_dir(); char* config_dir();
/*Default function for plugin*/ /*Default function for plugin*/
// init the plugin // init the plugin
void __attribute__((weak)) init(); void init();
void __attribute__((weak)) destroy(); void destroy();
void* handle(void*); void* handle(void*);
plugin_header_t* meta(); plugin_header_t* meta();
void use_raw_body(); void use_raw_body();
/*
STATIC PART, should be included in any plugin
*/
static plugin_header_t __plugin__;
// private function
void __init_plugin__(const char* pl,config_t* conf){
__plugin__.name = strdup(pl);
__plugin__.dbpath= strdup(conf->db_path);
__plugin__.htdocs = strdup(conf->htdocs);
__plugin__.pdir = strdup(conf->plugins_dir);
__plugin__.sport = conf->port;
#ifdef USE_OPENSSL
__plugin__.usessl = conf->usessl;
#endif
__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
/*#ifdef USE_OPENSSL
int usessl()
{
LOG("CALLED from plugin \n");
return __plugin__.usessl;
}
#endif*/
plugin_header_t* meta()
{
return &__plugin__;
}
char* route(const char* repath)
{
int len = strlen(__plugin__.name) + 2;
if(repath != NULL)
len += strlen(repath)+1;
char * path = (char*) malloc(len*sizeof(char));
strcpy(path,"/");
strcat(path,__plugin__.name);
if(repath != NULL)
{
strcat(path,"/");
strcat(path,repath);
}
return path;
}
char* htdocs(const char* repath)
{
if(repath != NULL)
return __s("%s/%s",__plugin__.htdocs,repath);
else
return __s("%s",__plugin__.htdocs);
}
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();
LOG("Releasing plugin\n");
if(__plugin__.name) free(__plugin__.name);
if(__plugin__.dbpath) free(__plugin__.dbpath);
if(__plugin__.htdocs) free(__plugin__.htdocs);
if(__plugin__.pdir) free(__plugin__.pdir);
}
#endif #endif