Return to dl.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / mqtt / src |
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 *
1.2.2.3 misho 28: mqttLoadRTLM(cfg_root_t *cfg, int modtype)
1.2 misho 29: {
30: const char *str, *attr;
31: void *rtlm = NULL;
1.2.2.3 misho 32: void *(*mqttOpenRTLM)(cfg_root_t *);
1.2 misho 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:
1.2.2.3 misho 50: str = cfg_getAttribute(cfg, "mqttd", attr);
1.2 misho 51: if (!str) {
52: mqttLog("Error:: RTL module not found\n");
53: return NULL;
54: }
55:
1.2.2.5 misho 56: rtlm = dlopen(str, RTLD_NOW);
1.2 misho 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) {
1.2.2.4 misho 64: mqttLog("Error:: Can't found mqtt_rtlm_open call\n");
1.2 misho 65: dlclose(rtlm);
66: return NULL;
67: }
68: mqttCloseRTLM = dlsym(rtlm, "mqtt_rtlm_close");
69: if (!mqttCloseRTLM) {
1.2.2.4 misho 70: mqttLog("Error:: Can't found mqtt_rtlm_close call\n");
1.2 misho 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");
1.2.2.1 misho 94: call.WritePUB_topic = dlsym(rtlm, "mqtt_rtlm_write_topic");
95: call.ReadPUB_topic = dlsym(rtlm, "mqtt_rtlm_read_topic");
96: call.DeletePUB_topic = dlsym(rtlm, "mqtt_rtlm_delete_topic");
1.2.2.6 ! misho 97: call.WipePUB_topic = dlsym(rtlm, "mqtt_rtlm_wipe_topic");
1.2.2.1 misho 98: call.WritePUB_subscribe = dlsym(rtlm, "mqtt_rtlm_write_subscribe");
99: call.ReadPUB_subscribe = dlsym(rtlm, "mqtt_rtlm_read_subscribe");
100: call.DeletePUB_subscribe = dlsym(rtlm, "mqtt_rtlm_delete_subscribe");
1.2 misho 101: if (!call.InitSessPUB || !call.FiniSessPUB || !call.ChkSessPUB ||
1.2.2.1 misho 102: !call.WritePUB_topic || !call.ReadPUB_topic ||
1.2.2.2 misho 103: !call.DeletePUB_topic || !call.WritePUB_subscribe ||
104: !call.ReadPUB_subscribe || !call.DeletePUB_subscribe) {
1.2 misho 105: mqttLog("Error:: incorrect module ...\n");
106: dlclose(rtlm);
107: return NULL;
108: }
109: break;
110: default:
111: log_rtlm = rtlm;
112: call.OpenLOG = mqttOpenRTLM;
113: call.CloseLOG = mqttCloseRTLM;
114: call.LOG = dlsym(rtlm, "mqtt_rtlm_logger");
115: if (!call.LOG) {
116: mqttLog("Error:: incorrect module ...\n");
117: dlclose(rtlm);
118: return NULL;
119: }
120: break;
121: }
122:
123: return rtlm;
124: }
125:
126: void
127: mqttUnloadRTLM(int modtype)
128: {
129: switch (modtype) {
130: case 0:
131: dlclose(acc_rtlm);
132: break;
133: case 1:
134: dlclose(pub_rtlm);
135: break;
136: default:
137: dlclose(log_rtlm);
138: break;
139: }
140: }
141:
142: inline int
1.2.2.3 misho 143: mqttMkDir(cfg_root_t *cfg)
1.2 misho 144: {
145: const char *str;
146:
147: if (!cfg)
148: return -1;
149:
1.2.2.3 misho 150: str = (const char*) cfg_getAttribute(cfg, "mqttd", "statedir");
1.2 misho 151: if (!str)
152: return -1;
153:
154: if (mkdir(str, 0600) == -1 && errno != EEXIST)
155: return -1;
156:
157: return 0;
158: }