Annotation of mqtt/src/dl.c, revision 1.2
1.2 ! misho 1: #include "global.h"
! 2: #include "rtlm.h"
! 3:
! 4:
! 5: static void *acc_rtlm, *pub_rtlm, *log_rtlm;
! 6:
! 7: struct tagCallbacks call;
! 8:
! 9:
! 10: /*
! 11: * mqttLog() Log message to syslog
! 12: *
! 13: * @fmt = format string
! 14: * @... = argument list
! 15: * return: none
! 16: */
! 17: void
! 18: mqttLog(const char *fmt, ...)
! 19: {
! 20: va_list lst;
! 21:
! 22: va_start(lst, fmt);
! 23: vsyslog(LOG_ERR, fmt, lst);
! 24: va_end(lst);
! 25: }
! 26:
! 27: void *
! 28: mqttLoadRTLM(sl_config *cfg, int modtype)
! 29: {
! 30: const char *str, *attr;
! 31: void *rtlm = NULL;
! 32: void *(*mqttOpenRTLM)(sl_config *);
! 33: void (*mqttCloseRTLM)(void *);
! 34:
! 35: if (!cfg)
! 36: return NULL;
! 37:
! 38: switch (modtype) {
! 39: case 0:
! 40: attr = "acc_file";
! 41: break;
! 42: case 1:
! 43: attr = "pub_file";
! 44: break;
! 45: default:
! 46: attr = "log_file";
! 47: break;
! 48: }
! 49:
! 50: str = (const char*) CFG(cfg_GetAttribute(cfg, CFG("mqttd"), CFG(attr)));
! 51: if (!str) {
! 52: mqttLog("Error:: RTL module not found\n");
! 53: return NULL;
! 54: }
! 55:
! 56: rtlm = dlopen(str, RTLD_LAZY);
! 57: if (!rtlm) {
! 58: mqttLog("Error:: RTL module %s not found %s\n", str, dlerror());
! 59: return NULL;
! 60: }
! 61:
! 62: mqttOpenRTLM = dlsym(rtlm, "mqtt_rtlm_open");
! 63: if (!mqttOpenRTLM) {
! 64: mqttLog("Error:: Can't found mqtt_db_open call\n");
! 65: dlclose(rtlm);
! 66: return NULL;
! 67: }
! 68: mqttCloseRTLM = dlsym(rtlm, "mqtt_rtlm_close");
! 69: if (!mqttCloseRTLM) {
! 70: mqttLog("Error:: Can't found mqtt_db_close call\n");
! 71: dlclose(rtlm);
! 72: return NULL;
! 73: }
! 74:
! 75: switch (modtype) {
! 76: case 0:
! 77: acc_rtlm = rtlm;
! 78: call.OpenACC = mqttOpenRTLM;
! 79: call.CloseACC = mqttCloseRTLM;
! 80: call.LoginACC = dlsym(rtlm, "mqtt_rtlm_login");
! 81: if (!call.LoginACC) {
! 82: mqttLog("Error:: incorrect module ...\n");
! 83: dlclose(rtlm);
! 84: return NULL;
! 85: }
! 86: break;
! 87: case 1:
! 88: pub_rtlm = rtlm;
! 89: call.OpenPUB = mqttOpenRTLM;
! 90: call.ClosePUB = mqttCloseRTLM;
! 91: call.InitSessPUB = dlsym(rtlm, "mqtt_rtlm_init_session");
! 92: call.FiniSessPUB = dlsym(rtlm, "mqtt_rtlm_fini_session");
! 93: call.ChkSessPUB = dlsym(rtlm, "mqtt_rtlm_chk_session");
! 94: call.WritePUB = dlsym(rtlm, "mqtt_rtlm_write_topic");
! 95: call.ReadPUB = dlsym(rtlm, "mqtt_rtlm_read_topic");
! 96: call.DeletePUB = dlsym(rtlm, "mqtt_rtlm_delete_topic");
! 97: if (!call.InitSessPUB || !call.FiniSessPUB || !call.ChkSessPUB ||
! 98: !call.WritePUB || !call.ReadPUB || !call.DeletePUB) {
! 99: mqttLog("Error:: incorrect module ...\n");
! 100: dlclose(rtlm);
! 101: return NULL;
! 102: }
! 103: break;
! 104: default:
! 105: log_rtlm = rtlm;
! 106: call.OpenLOG = mqttOpenRTLM;
! 107: call.CloseLOG = mqttCloseRTLM;
! 108: call.LOG = dlsym(rtlm, "mqtt_rtlm_logger");
! 109: if (!call.LOG) {
! 110: mqttLog("Error:: incorrect module ...\n");
! 111: dlclose(rtlm);
! 112: return NULL;
! 113: }
! 114: break;
! 115: }
! 116:
! 117: return rtlm;
! 118: }
! 119:
! 120: void
! 121: mqttUnloadRTLM(int modtype)
! 122: {
! 123: switch (modtype) {
! 124: case 0:
! 125: dlclose(acc_rtlm);
! 126: break;
! 127: case 1:
! 128: dlclose(pub_rtlm);
! 129: break;
! 130: default:
! 131: dlclose(log_rtlm);
! 132: break;
! 133: }
! 134: }
! 135:
! 136: inline int
! 137: mqttMkDir(sl_config *cfg)
! 138: {
! 139: const char *str;
! 140:
! 141: if (!cfg)
! 142: return -1;
! 143:
! 144: str = (const char*) cfg_GetAttribute(cfg, CFG("mqttd"), CFG("statedir"));
! 145: if (!str)
! 146: return -1;
! 147:
! 148: if (mkdir(str, 0600) == -1 && errno != EEXIST)
! 149: return -1;
! 150:
! 151: return 0;
! 152: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>