ant-http/plugins/plugin.c

65 lines
1.3 KiB
C
Raw Normal View History

2015-10-22 11:39:11 +02:00
#include "plugin.h"
plugin_header __plugin__;
// private function
2016-03-04 11:38:08 +01:00
call __init__;
2015-10-22 11:39:11 +02:00
2016-03-04 11:38:08 +01:00
void __init_plugin__(const char* pl,const char*ph,const char* htdocs, const char* pdir,int port){
2015-10-22 11:39:11 +02:00
__plugin__.name = strdup(pl);
__plugin__.dbpath= strdup(ph);
__plugin__.htdocs = strdup(htdocs);
__plugin__.pdir = strdup(pdir);
2016-03-04 11:38:08 +01:00
__plugin__.sport = port;
2015-10-22 11:39:11 +02:00
if(__init__ != NULL) __init__();
};
2016-03-04 11:38:08 +01:00
#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);
strcat(path,__plugin__.name);
strcat(path,".db");
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
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;
2015-10-22 11:39:11 +02:00
}