From 0aa3153f05fe8cd51d76fd5dee9011a7d2296b7d Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Wed, 26 Jun 2019 00:37:25 +0800
Subject: [PATCH] update mqttd, add command line options parser
---
mqttd/etc/conf.c | 28 ++++++++++++++++++++--------
1 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/mqttd/etc/conf.c b/mqttd/etc/conf.c
index b66d22a..c78e24d 100644
--- a/mqttd/etc/conf.c
+++ b/mqttd/etc/conf.c
@@ -25,28 +25,42 @@
if( !conf_file )
{
- fprintf(stderr, "\nWARNNING: Use default MQTT configure\n");
/* logger settings */
strncpy(ctx->logfile, DBG_LOG_FILE, sizeof(ctx->logfile));
ctx->loglevel = LOG_LEVEL_DEBUG;
ctx->logsize = 1024;
+ if( logger_init(ctx->logfile, ctx->loglevel, ctx->logsize) < 0 )
+ {
+ fprintf(stderr, "Logger system initialise failure\n");
+ return -2;
+ }
+ log_nrml("Logger system initialise ok\n");
+ log_warn("WARNNING: Use default MQTT configure\n");
+
/* Broker settings */
strncpy(ctx->host, DEF_BORKER_HOSTNAME, sizeof(ctx->host));
ctx->port = DEF_BROKER_PORT;
+ log_nrml("Use default broker server [%s:%d]\n", ctx->host, ctx->port);
+
strncpy(ctx->uid, DEF_BROKER_USERNAME, sizeof(ctx->uid));
strncpy(ctx->pwd, DEF_BROKER_PASSWD, sizeof(ctx->pwd));
+ log_nrml("Use default broker author by [%s:%s]\n", ctx->uid, ctx->pwd);
+
ctx->keepalive = DEF_BROKER_KEEPALIVE;
+ log_nrml("Use default broker keepalive timeout [%d] seconds\n", ctx->keepalive);
/* Publisher settings */
strncpy(ctx->pubTopic, DEF_PUBTOPIC, sizeof(ctx->pubTopic));
ctx->pubQos = DEF_PUBQOS;
ctx->interval = DEF_PUBINTERVAL;
+ log_nrml("Use default publisher topic \"%s\" with Qos[%d] interval[%d]\n", ctx->pubTopic, ctx->pubQos, ctx->interval);
/* Subscriber settings */
strncpy(ctx->subTopic, DEF_SUBTOPIC, sizeof(ctx->subTopic));
ctx->subQos = DEF_SUBQOS;
+ log_nrml("Use default subscriber topic \"%s\" with Qos[%d]\n", ctx->subTopic, ctx->subQos);
return 0;
}
@@ -103,7 +117,7 @@
return -2;
}
ctx->port = val;
- log_nrml("Parser and get broker server [%s:%d]\n", ctx->host, ctx->port);
+ log_nrml("Parser broker server [%s:%d]\n", ctx->host, ctx->port);
str=iniparser_getstring(ini, "broker:username", DEF_BROKER_USERNAME);
strncpy(ctx->uid, str, sizeof(ctx->uid) );
@@ -111,10 +125,10 @@
str=iniparser_getstring(ini, "broker:password", DEF_BROKER_PASSWD);
strncpy(ctx->pwd, str, sizeof(ctx->pwd) );
- log_nrml("Parser and get broker author by [%s:%s]\n", ctx->uid, ctx->pwd);
+ log_nrml("Parser broker author by [%s:%s]\n", ctx->uid, ctx->pwd);
ctx->keepalive = iniparser_getint(ini, "broker:keepalive", DEF_BROKER_KEEPALIVE);
- log_nrml("Parser and get broker keepalive timeout [%d] seconds\n", ctx->keepalive);
+ log_nrml("Parser broker keepalive timeout [%d] seconds\n", ctx->keepalive);
/*+------------------------------------------------------+
*| parser publisher settings |
@@ -122,11 +136,10 @@
str=iniparser_getstring(ini, "publisher:pubTopic", DEF_PUBTOPIC);
strncpy(ctx->pubTopic, str, sizeof(ctx->pubTopic) );
- log_nrml("Parser and get publisher topic \"%s\"\n", ctx->pubTopic);
ctx->pubQos = iniparser_getint(ini, "publisher:pubQos", DEF_PUBQOS);
ctx->interval = iniparser_getint(ini, "publisher:interval", DEF_PUBINTERVAL);
- log_nrml("Parser and get publisher Qos[%d] and interval [%d] seconds\n", ctx->pubQos, ctx->interval);
+ log_nrml("Parser publisher topic \"%s\" with Qos[%d] interval[%d]\n", ctx->pubTopic, ctx->pubQos, ctx->interval);
/*+------------------------------------------------------+
*| parser subscriber settings |
@@ -134,10 +147,9 @@
str=iniparser_getstring(ini, "subsciber:subTopic", DEF_SUBTOPIC);
strncpy(ctx->subTopic, str, sizeof(ctx->subTopic) );
- log_nrml("Parser and get subscriber topic \"%s\"\n", ctx->subTopic);
ctx->subQos = iniparser_getint(ini, "subsciber:subQos", DEF_SUBQOS);
- log_nrml("Parser and get subscriber Qos[%d]\n", ctx->subQos);
+ log_nrml("Parser subscriber topic \"%s\" with Qos[%d]\n", ctx->subTopic, ctx->subQos);
return 0;
}
--
Gitblit v1.9.1