Annotation of mqtt/src/dl.c, revision 1.4
1.4 ! misho 1: /*************************************************************************
! 2: * (C) 2011 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
! 3: * by Michael Pounov <misho@openbsd-bg.org>
! 4: *
! 5: * $Author: misho $
! 6: * $Id: dl.c,v 1.3.2.1 2012/07/03 12:22:56 misho Exp $
! 7: *
! 8: **************************************************************************
! 9: The ELWIX and AITNET software is distributed under the following
! 10: terms:
! 11:
! 12: All of the documentation and software included in the ELWIX and AITNET
! 13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
! 14:
! 15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
! 16: by Michael Pounov <misho@elwix.org>. All rights reserved.
! 17:
! 18: Redistribution and use in source and binary forms, with or without
! 19: modification, are permitted provided that the following conditions
! 20: are met:
! 21: 1. Redistributions of source code must retain the above copyright
! 22: notice, this list of conditions and the following disclaimer.
! 23: 2. Redistributions in binary form must reproduce the above copyright
! 24: notice, this list of conditions and the following disclaimer in the
! 25: documentation and/or other materials provided with the distribution.
! 26: 3. All advertising materials mentioning features or use of this software
! 27: must display the following acknowledgement:
! 28: This product includes software developed by Michael Pounov <misho@elwix.org>
! 29: ELWIX - Embedded LightWeight unIX and its contributors.
! 30: 4. Neither the name of AITNET nor the names of its contributors
! 31: may be used to endorse or promote products derived from this software
! 32: without specific prior written permission.
! 33:
! 34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
! 35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 44: SUCH DAMAGE.
! 45: */
1.2 misho 46: #include "global.h"
47: #include "rtlm.h"
48:
49:
50: struct tagCallbacks call;
51:
52:
53: /*
54: * mqttLog() Log message to syslog
55: *
56: * @fmt = format string
57: * @... = argument list
58: * return: none
59: */
60: void
61: mqttLog(const char *fmt, ...)
62: {
63: va_list lst;
64:
65: va_start(lst, fmt);
66: vsyslog(LOG_ERR, fmt, lst);
67: va_end(lst);
68: }
69:
70: void *
1.3 misho 71: mqttLoadRTLM(cfg_root_t *cfg, int modtype)
1.2 misho 72: {
73: const char *str, *attr;
74: void *rtlm = NULL;
1.3 misho 75: void *(*mqttOpenRTLM)(cfg_root_t *);
1.2 misho 76: void (*mqttCloseRTLM)(void *);
77:
78: if (!cfg)
79: return NULL;
80:
81: switch (modtype) {
82: case 0:
83: attr = "acc_file";
84: break;
85: case 1:
86: attr = "pub_file";
87: break;
88: default:
89: attr = "log_file";
90: break;
91: }
92:
1.3 misho 93: str = cfg_getAttribute(cfg, "mqttd", attr);
1.2 misho 94: if (!str) {
95: mqttLog("Error:: RTL module not found\n");
96: return NULL;
97: }
98:
1.3 misho 99: rtlm = dlopen(str, RTLD_NOW);
1.2 misho 100: if (!rtlm) {
101: mqttLog("Error:: RTL module %s not found %s\n", str, dlerror());
102: return NULL;
103: }
104:
105: mqttOpenRTLM = dlsym(rtlm, "mqtt_rtlm_open");
106: if (!mqttOpenRTLM) {
1.3 misho 107: mqttLog("Error:: Can't found mqtt_rtlm_open call\n");
1.2 misho 108: dlclose(rtlm);
109: return NULL;
110: }
111: mqttCloseRTLM = dlsym(rtlm, "mqtt_rtlm_close");
112: if (!mqttCloseRTLM) {
1.3 misho 113: mqttLog("Error:: Can't found mqtt_rtlm_close call\n");
1.2 misho 114: dlclose(rtlm);
115: return NULL;
116: }
117:
118: switch (modtype) {
119: case 0:
120: call.OpenACC = mqttOpenRTLM;
121: call.CloseACC = mqttCloseRTLM;
122: call.LoginACC = dlsym(rtlm, "mqtt_rtlm_login");
123: if (!call.LoginACC) {
124: mqttLog("Error:: incorrect module ...\n");
125: dlclose(rtlm);
126: return NULL;
127: }
128: break;
129: case 1:
130: call.OpenPUB = mqttOpenRTLM;
131: call.ClosePUB = mqttCloseRTLM;
132: call.InitSessPUB = dlsym(rtlm, "mqtt_rtlm_init_session");
133: call.FiniSessPUB = dlsym(rtlm, "mqtt_rtlm_fini_session");
134: call.ChkSessPUB = dlsym(rtlm, "mqtt_rtlm_chk_session");
1.3 misho 135: call.WritePUB_topic = dlsym(rtlm, "mqtt_rtlm_write_topic");
136: call.ReadPUB_topic = dlsym(rtlm, "mqtt_rtlm_read_topic");
137: call.DeletePUB_topic = dlsym(rtlm, "mqtt_rtlm_delete_topic");
138: call.WipePUB_topic = dlsym(rtlm, "mqtt_rtlm_wipe_topic");
139: call.WritePUB_subscribe = dlsym(rtlm, "mqtt_rtlm_write_subscribe");
140: call.ReadPUB_subscribe = dlsym(rtlm, "mqtt_rtlm_read_subscribe");
141: call.DeletePUB_subscribe = dlsym(rtlm, "mqtt_rtlm_delete_subscribe");
1.2 misho 142: if (!call.InitSessPUB || !call.FiniSessPUB || !call.ChkSessPUB ||
1.3 misho 143: !call.WritePUB_topic || !call.ReadPUB_topic ||
144: !call.DeletePUB_topic || !call.WritePUB_subscribe ||
145: !call.ReadPUB_subscribe || !call.DeletePUB_subscribe) {
1.2 misho 146: mqttLog("Error:: incorrect module ...\n");
147: dlclose(rtlm);
148: return NULL;
149: }
150: break;
151: default:
152: call.OpenLOG = mqttOpenRTLM;
153: call.CloseLOG = mqttCloseRTLM;
154: call.LOG = dlsym(rtlm, "mqtt_rtlm_logger");
155: if (!call.LOG) {
156: mqttLog("Error:: incorrect module ...\n");
157: dlclose(rtlm);
158: return NULL;
159: }
160: break;
161: }
162:
163: return rtlm;
164: }
165:
166: void
1.3 misho 167: mqttUnloadRTLM(void *rtlm)
1.2 misho 168: {
1.3 misho 169: if (rtlm)
170: dlclose(rtlm);
1.2 misho 171: }
172:
173: inline int
1.3 misho 174: mqttMkDir(cfg_root_t *cfg)
1.2 misho 175: {
176: const char *str;
177:
178: if (!cfg)
179: return -1;
180:
1.3 misho 181: str = (const char*) cfg_getAttribute(cfg, "mqttd", "statedir");
1.2 misho 182: if (!str)
183: return -1;
184:
185: if (mkdir(str, 0600) == -1 && errno != EEXIST)
186: return -1;
187:
188: return 0;
189: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>