#include "global.h" #include "rtlm.h" static void *acc_rtlm, *pub_rtlm; /* * 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) { char *str; void *rtlm = NULL; if (!cfg) return NULL; str = CFG(cfg_GetAttribute(cfg, CFG("mqttd"), CFG(modtype ? "pub_file" : "acc_file"))); 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; } mqttOpenDB = dlsym(rtlm, "mqtt_db_open"); if (!mqttOpenDB) { mqttLog("Error:: Can't found mqtt_db_open call\n"); dlclose(rtlm); return NULL; } mqttCloseDB = dlsym(rtlm, "mqtt_db_close"); if (!mqttCloseDB) { mqttLog("Error:: Can't found mqtt_db_close call\n"); dlclose(rtlm); return NULL; } if (modtype) { pub_rtlm = rtlm; } else { acc_rtlm = rtlm; } return rtlm; } void mqttUnloadRTLM(int modtype) { dlclose((modtype ? pub_rtlm : acc_rtlm)); } inline int mqttMkDir(sl_config *cfg) { char *str; if (!cfg) return -1; str = CFG(cfg_GetAttribute(cfg, CFG("mqttd"), CFG("statedir"))); if (!str) return -1; if (mkdir(str, 0600) == -1 && errno != EEXIST) return -1; return 0; }