File:  [ELWIX - Embedded LightWeight unIX -] / mqtt / src / Attic / mqtt.c
Revision 1.1.1.1.2.21: download - view: text, annotated - select for diffs - revision graph
Mon Dec 12 09:45:16 2011 UTC (12 years, 6 months ago) by misho
Branches: mqtt1_0
Diff to: branchpoint 1.1.1.1: preferred, unified
add argument structure

    1: #include "global.h"
    2: #include "rtlm.h"
    3: #include "mqtt.h"
    4: 
    5: 
    6: sl_config cfg;
    7: sqlite3 *acc, *pub;
    8: FILE *logg;
    9: extern char compiled[], compiledby[], compilehost[];
   10: static char szCfgName[MAXPATHLEN];
   11: int Verbose, Kill;
   12: 
   13: struct tagArgs *args;
   14: 
   15: 
   16: static void
   17: Usage(void)
   18: {
   19: 	printf(	" -= MQTT Client =- Publisher/Subscriber from ELWIX\n"
   20: 		"=== %s@%s === Compiled: %s ===\n\n"
   21: 		" Syntax: mqtt [options] <connect_to_broker[:port]> [value_for_publish]\n\n"
   22: 		"\t-p <topic>\tPublish topic\n"
   23: 		"\t-s <topic[|QoS]>\tSubscribe for this topic, if wish add different |QoS to topic\n"
   24: 		"\t-q <QoS>\tQoS level (0-at most 1, 1-at least 1, 2-explicit 1)\n"
   25: 		"\t-d\t\tSend duplicate message\n"
   26: 		"\t-r\t\tRetain message from broker\n"
   27: 		"\t-c <config>\tService config\n"
   28: 		"\t-f\t\t'value_for_publish' is file instead text\n"
   29: 		"\t-D\t\tDaemon mode\n"
   30: 		"\t-v\t\tVerbose (more -vvv, more verbose)\n"
   31: 		"\t-h\t\tHelp! This screen\n\n", 
   32: 		compiledby, compilehost, compiled);
   33: }
   34: 
   35: 
   36: int
   37: main(int argc, char **argv)
   38: {
   39: 	char ch, batch = 1, szStr[STRSIZ] = { 0 };
   40: 
   41: 	if (!(args = malloc(sizeof(struct tagArgs)))) {
   42: 		printf("Error:: in arguments #%d - %s\n", errno, strerror(errno));
   43: 		return 1;
   44: 	}
   45: 
   46: 	strlcpy(szCfgName, DEFAULT_CONFIG, sizeof szCfgName);
   47: 	while ((ch = getopt(argc, argv, "p:s:q:drc:fDvh")) != -1)
   48: 		switch (ch) {
   49: 			case 'p':
   50: 				break;
   51: 			case 's':
   52: 				break;
   53: 			case 'q':
   54: 				break;
   55: 			case 'd':
   56: 				break;
   57: 			case 'r':
   58: 				break;
   59: 			case 'f':
   60: 				break;
   61: 			case 'c':
   62: 				strlcpy(szCfgName, optarg, sizeof szCfgName);
   63: 				break;
   64: 			case 'D':
   65: 				batch = 0;
   66: 				break;
   67: 			case 'v':
   68: 				Verbose++;
   69: 				break;
   70: 			case 'h':
   71: 			default:
   72: 				free(args);
   73: 				Usage();
   74: 				return 1;
   75: 		}
   76: 	argc -= optind;
   77: 	argv += optind;
   78: 
   79: 	if (LoadConfig(szCfgName, &cfg)) {
   80: 		printf("Error:: can't load #%d - %s\n", cfg_GetErrno(), cfg_GetError());
   81: 		free(args);
   82: 		return 1;
   83: 	}
   84: 
   85: 	UnloadConfig(&cfg);
   86: 	free(args);
   87: 	return 0;
   88: }

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