File:  [ELWIX - Embedded LightWeight unIX -] / mqtt / src / dl.c
Revision 1.1.2.3: download - view: text, annotated - select for diffs - revision graph
Wed Nov 23 08:09:40 2011 UTC (12 years, 7 months ago) by misho
Branches: mqtt1_0
fix warnz

#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)
{
	const char *str;
	void *rtlm = NULL;

	if (!cfg)
		return NULL;

	str = (const char*) 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)
{
	const char *str;

	if (!cfg)
		return -1;

	str = (const char*) cfg_GetAttribute(cfg, CFG("mqttd"), CFG("statedir"));
	if (!str)
		return -1;

	if (mkdir(str, 0600) == -1 && errno != EEXIST)
		return -1;

	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>