#include "global.h"
#include "rtlm.h"
static void *acc_rtlm, *pub_rtlm, *log_rtlm;
struct tagCallbacks call;
/*
* mqttLog() Log message to syslog
*
* @fmt = format string
* @... = argument list
* return: none
*/
void
mqttLog(const char *fmt, ...)
{
va_list lst;
va_start(lst, fmt);
vsyslog(LOG_ERR, fmt, lst);
va_end(lst);
}
void *
mqttLoadRTLM(sl_config *cfg, int modtype)
{
const char *str, *attr;
void *rtlm = NULL;
void *(*mqttOpenRTLM)(sl_config *);
void (*mqttCloseRTLM)(void *);
if (!cfg)
return NULL;
switch (modtype) {
case 0:
attr = "acc_file";
break;
case 1:
attr = "pub_file";
break;
default:
attr = "log_file";
break;
}
str = (const char*) CFG(cfg_GetAttribute(cfg, CFG("mqttd"), CFG(attr)));
if (!str) {
mqttLog("Error:: RTL module not found\n");
return NULL;
}
rtlm = dlopen(str, RTLD_LAZY);
if (!rtlm) {
mqttLog("Error:: RTL module not found %s\n", dlerror());
return NULL;
}
mqttOpenRTLM = dlsym(rtlm, "mqtt_rtlm_open");
if (!mqttOpenRTLM) {
mqttLog("Error:: Can't found mqtt_db_open call\n");
dlclose(rtlm);
return NULL;
}
mqttCloseRTLM = dlsym(rtlm, "mqtt_rtlm_close");
if (!mqttCloseRTLM) {
mqttLog("Error:: Can't found mqtt_db_close call\n");
dlclose(rtlm);
return NULL;
}
switch (modtype) {
case 0:
acc_rtlm = rtlm;
call.OpenACC = mqttOpenRTLM;
call.CloseACC = mqttCloseRTLM;
call.LoginACC = dlsym(rtlm, "mqtt_rtlm_login");
break;
case 1:
pub_rtlm = rtlm;
call.OpenPUB = mqttOpenRTLM;
call.ClosePUB = mqttCloseRTLM;
break;
default:
log_rtlm = rtlm;
call.OpenLOG = mqttOpenRTLM;
call.CloseLOG = mqttCloseRTLM;
call.LOG = dlsym(rtlm, "mqtt_rtlm_logger");
break;
}
return rtlm;
}
void
mqttUnloadRTLM(int modtype)
{
switch (modtype) {
case 0:
dlclose(acc_rtlm);
break;
case 1:
dlclose(pub_rtlm);
break;
default:
dlclose(log_rtlm);
break;
}
}
inline int
mqttMkDir(sl_config *cfg)
{
const char *str;
if (!cfg)
return -1;
str = (const char*) cfg_GetAttribute(cfg, CFG("mqttd"), CFG("statedir"));
if (!str)
return -1;
if (mkdir(str, 0600) == -1 && errno != EEXIST)
return -1;
return 0;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>