ant-http/libs/plugin.c

92 lines
1.8 KiB
C
Raw Permalink Normal View History

2015-10-22 11:39:11 +02:00
#include "plugin.h"
plugin_header_t __plugin__;
2015-10-22 11:39:11 +02:00
// private function
2018-02-10 11:22:41 +01:00
void __init_plugin__(const char* pl,config_t* conf){
2015-10-22 11:39:11 +02:00
__plugin__.name = strdup(pl);
2018-02-10 11:22:41 +01:00
__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;
2018-09-26 11:07:48 +02:00
init();
2015-10-22 11:39:11 +02:00
};
void use_raw_body()
{
__plugin__.raw_body = 1;
}
#ifdef USE_DB
2016-10-30 16:14:04 +01:00
sqldb __getdb(char *name)
2015-10-22 11:39:11 +02:00
{
2016-10-30 16:14:04 +01:00
int plen = strlen(name)+strlen(__plugin__.dbpath)+4;
2015-10-22 11:39:11 +02:00
char* path = (char*) malloc(plen*sizeof(char));
strcpy(path,__plugin__.dbpath);
2018-02-05 19:06:03 +01:00
strcat(path,name);
2015-10-22 11:39:11 +02:00
strcat(path,".db");
2018-02-11 00:04:24 +01:00
//LOG("database: %s\n", path);
2015-10-22 11:39:11 +02:00
sqldb ret = (sqldb)database(path);
free(path);
return ret;
}
2016-10-30 16:14:04 +01:00
sqldb getdb()
{
2017-07-30 01:00:36 +02:00
return __getdb(__plugin__.name);
2016-10-30 16:14:04 +01:00
}
#endif
2015-10-22 11:39:11 +02:00
2018-02-10 12:24:01 +01:00
/*#ifdef USE_OPENSSL
2018-02-10 11:22:41 +01:00
int usessl()
{
2018-02-10 12:24:01 +01:00
LOG("CALLED from plugin \n");
2018-02-10 11:22:41 +01:00
return __plugin__.usessl;
}
2018-02-10 12:24:01 +01:00
#endif*/
plugin_header_t* meta()
{
return &__plugin__;
}
2015-10-22 11:39:11 +02:00
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;
}
2017-07-29 22:00:34 +02:00
2015-10-22 11:39:11 +02:00
char* htdocs(const char* repath)
{
if(repath != NULL)
return __s("%s/%s",__plugin__.htdocs,repath);
else
return __s("%s",__plugin__.htdocs);
}
2017-07-29 22:00:34 +02:00
2016-03-04 11:38:08 +01:00
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;
2018-03-02 19:04:00 +01:00
}
void __release__()
2018-03-02 19:04:00 +01:00
{
destroy();
2018-10-05 19:07:14 +02:00
LOG("Releasing plugin\n");
2018-03-02 19:04:00 +01:00
if(__plugin__.name) free(__plugin__.name);
if(__plugin__.dbpath) free(__plugin__.dbpath);
if(__plugin__.htdocs) free(__plugin__.htdocs);
if(__plugin__.pdir) free(__plugin__.pdir);
2015-10-22 11:39:11 +02:00
}