Return to dl.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / mqtt / src |
1.1.2.1 misho 1: #include "global.h"
2: #include "rtlm.h"
3:
4:
1.1.2.4 misho 5: static void *acc_rtlm, *pub_rtlm, *log_rtlm;
1.1.2.1 misho 6:
1.1.2.5 misho 7: struct tagCallbacks call;
8:
1.1.2.1 misho 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: {
1.1.2.4 misho 30: const char *str, *attr;
1.1.2.1 misho 31: void *rtlm = NULL;
1.1.2.4 misho 32: void *(*mqttOpenRTLM)(sl_config *);
33: void (*mqttCloseRTLM)(void *);
1.1.2.1 misho 34:
35: if (!cfg)
36: return NULL;
37:
1.1.2.4 misho 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)));
1.1.2.1 misho 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 not found %s\n", dlerror());
59: return NULL;
60: }
61:
1.1.2.4 misho 62: mqttOpenRTLM = dlsym(rtlm, "mqtt_rtlm_open");
63: if (!mqttOpenRTLM) {
1.1.2.1 misho 64: mqttLog("Error:: Can't found mqtt_db_open call\n");
65: dlclose(rtlm);
66: return NULL;
67: }
1.1.2.4 misho 68: mqttCloseRTLM = dlsym(rtlm, "mqtt_rtlm_close");
69: if (!mqttCloseRTLM) {
1.1.2.1 misho 70: mqttLog("Error:: Can't found mqtt_db_close call\n");
71: dlclose(rtlm);
72: return NULL;
73: }
74:
1.1.2.4 misho 75: switch (modtype) {
76: case 0:
77: acc_rtlm = rtlm;
1.1.2.5 misho 78: call.OpenACC = mqttOpenRTLM;
79: call.CloseACC = mqttCloseRTLM;
1.1.2.6 misho 80: call.LoginACC = dlsym(rtlm, "mqtt_rtlm_login");
1.1.2.4 misho 81: break;
82: case 1:
83: pub_rtlm = rtlm;
1.1.2.5 misho 84: call.OpenPUB = mqttOpenRTLM;
85: call.ClosePUB = mqttCloseRTLM;
1.1.2.7 misho 86: call.InitSessPUB = dlsym(rtlm, "mqtt_rtlm_init_session");
1.1.2.8 misho 87: call.FiniSessPUB = dlsym(rtlm, "mqtt_rtlm_fini_session");
1.1.2.9 ! misho 88: call.ChkSessPUB = dlsym(rtlm, "mqtt_rtlm_chk_session");
1.1.2.4 misho 89: break;
90: default:
91: log_rtlm = rtlm;
1.1.2.5 misho 92: call.OpenLOG = mqttOpenRTLM;
93: call.CloseLOG = mqttCloseRTLM;
94: call.LOG = dlsym(rtlm, "mqtt_rtlm_logger");
1.1.2.4 misho 95: break;
1.1.2.1 misho 96: }
97:
98: return rtlm;
99: }
100:
101: void
102: mqttUnloadRTLM(int modtype)
103: {
1.1.2.4 misho 104: switch (modtype) {
105: case 0:
106: dlclose(acc_rtlm);
107: break;
108: case 1:
109: dlclose(pub_rtlm);
110: break;
111: default:
112: dlclose(log_rtlm);
113: break;
114: }
1.1.2.1 misho 115: }
1.1.2.2 misho 116:
117: inline int
118: mqttMkDir(sl_config *cfg)
119: {
1.1.2.3 misho 120: const char *str;
1.1.2.2 misho 121:
122: if (!cfg)
123: return -1;
124:
1.1.2.3 misho 125: str = (const char*) cfg_GetAttribute(cfg, CFG("mqttd"), CFG("statedir"));
1.1.2.2 misho 126: if (!str)
127: return -1;
128:
129: if (mkdir(str, 0600) == -1 && errno != EEXIST)
130: return -1;
131:
132: return 0;
133: }