27 printf(
"\nLibrary information:\n");
30 printf(
"%s: %s\n", info->
name, info->
value);
42 printf(
"Eclipse Paho MQTT C %s\n", opts->
publisher ?
"publisher" :
"subscriber");
45 printf(
"Usage: %s [topicname] [-t topic] [-c connection] [-h host] [-p port]\n" 46 " [-q qos] [-i clientid] [-u username] [-P password] [-k keepalive_timeout]\n" 48 printf(
" [-V MQTT-version] [--quiet] [--trace trace-level]\n");
51 printf(
" [-r] [-n] [-m message] [-f filename]\n");
52 printf(
" [--maxdatalen len] [--message-expiry seconds] [--user-property name value]\n");
55 printf(
" [-R] [--no-delimiter]\n");
56 printf(
" [--will-topic topic] [--will-payload message] [--will-qos qos] [--will-retain]\n");
57 printf(
" [--cafile filename] [--capath dirname] [--cert filename] [--key filename]\n" 58 " [--keypass string] [--ciphers string] [--insecure]");
61 "\n\n -t (--topic) : MQTT topic to %s to\n" 62 " -c (--connection) : connection string, overrides host/port e.g wss://hostname:port/ws. Use this option\n" 63 " rather than host/port to connect with TLS and/or web sockets. No default.\n" 64 " -h (--host) : host to connect to. Default is %s.\n" 65 " -p (--port) : network port to connect to. Default is %s.\n" 66 " -q (--qos) : MQTT QoS to %s with (0, 1 or 2). Default is %d.\n" 67 " -V (--MQTTversion) : MQTT version (31, 311, or 5). Default is 311.\n" 68 " --quiet : do not print error messages.\n" 69 " --trace : print internal trace (\"error\", \"min\", \"max\" or \"protocol\").\n",
75 printf(
" -r (--retained) : use MQTT retain option. Default is off.\n");
76 printf(
" -n (--null-message) : send 0-length message.\n");
77 printf(
" -m (--message) : the payload to send.\n");
78 printf(
" -f (--filename) : use the contents of the named file as the payload.\n");
82 " -i (--clientid) : MQTT client id. Default is %s.\n" 83 " -u (--username) : MQTT username. No default.\n" 84 " -P (--password) : MQTT password. No default.\n" 85 " -k (--keepalive) : MQTT keepalive timeout value. Default is %d seconds.\n" 86 " --delimiter : delimiter string. Default is \\n.\n",
91 printf(
" --maxdatalen : maximum length of data to read when publishing strings (default is %d)\n",
93 printf(
" --message-expiry : MQTT 5 only. Sets the message expiry property in seconds.\n");
94 printf(
" --user-property : MQTT 5 only. Sets a user property.\n");
98 printf(
" --no-delimiter : do not use a delimiter string between messages.\n");
99 printf(
" -R (--no-retained) : do not print retained messages.\n");
103 " --will-topic : will topic on connect. No default.\n" 104 " --will-payload : will message. If the will topic is set, but not payload, a null message will be set.\n" 105 " --will-retain : set the retained flag on the will message. The default is off.\n" 106 " --will-qos : the will message QoS. The default is 0.\n" 110 " --cafile : a filename for the TLS truststore.\n" 111 " --capath : a directory name containing TLS trusted server certificates.\n" 112 " --cert : a filename for the TLS keystore containing client certificates.\n" 113 " --key : client private key file.\n" 114 " --keypass : password for the client private key file.\n" 115 " --ciphers : the list of cipher suites that the client will present to the server during\n" 116 " the TLS handshake.\n" 117 " --insecure : don't check that the server certificate common name matches the hostname.\n" 118 " --psk : pre-shared-key in hexadecimal (no leading 0x) \n" 119 " --psk-identity : client identity string for TLS-PSK mode.\n" 122 printf(
"\nSee http://eclipse.org/paho for more information about the Eclipse Paho project.\n");
132 if (argv[1][0] !=
'-')
134 opts->
topic = argv[1];
140 if (strcmp(argv[count],
"--verbose") == 0 || strcmp(argv[count],
"-v") == 0)
142 else if (strcmp(argv[count],
"--quiet") == 0)
144 else if (strcmp(argv[count],
"--qos") == 0 || strcmp(argv[count],
"-q") == 0)
148 if (strcmp(argv[count],
"0") == 0)
150 else if (strcmp(argv[count],
"1") == 0)
152 else if (strcmp(argv[count],
"2") == 0)
160 else if (strcmp(argv[count],
"--connection") == 0 || strcmp(argv[count],
"-c") == 0)
167 else if (strcmp(argv[count],
"--host") == 0 || strcmp(argv[count],
"-h") == 0)
174 else if (strcmp(argv[count],
"--port") == 0 || strcmp(argv[count],
"-p") == 0)
181 else if (strcmp(argv[count],
"--clientid") == 0 || strcmp(argv[count],
"-i") == 0)
188 else if (strcmp(argv[count],
"--username") == 0 || strcmp(argv[count],
"-u") == 0)
195 else if (strcmp(argv[count],
"--password") == 0 || strcmp(argv[count],
"-P") == 0)
202 else if (strcmp(argv[count],
"--maxdatalen") == 0)
209 else if (strcmp(argv[count],
"--delimiter") == 0)
216 else if (strcmp(argv[count],
"--no-delimiter") == 0)
218 else if (strcmp(argv[count],
"--keepalive") == 0 || strcmp(argv[count],
"-k") == 0)
225 else if (strcmp(argv[count],
"--topic") == 0 || strcmp(argv[count],
"-t") == 0)
232 else if (strcmp(argv[count],
"--will-topic") == 0)
239 else if (strcmp(argv[count],
"--will-payload") == 0)
246 else if (strcmp(argv[count],
"--will-qos") == 0)
253 else if (strcmp(argv[count],
"--will-retain") == 0)
260 else if (strcmp(argv[count],
"--insecure") == 0)
262 else if (strcmp(argv[count],
"--capath") == 0)
269 else if (strcmp(argv[count],
"--cafile") == 0)
276 else if (strcmp(argv[count],
"--cert") == 0)
283 else if (strcmp(argv[count],
"--key") == 0)
290 else if (strcmp(argv[count],
"--keypass") == 0)
297 else if (strcmp(argv[count],
"--ciphers") == 0)
304 else if (strcmp(argv[count],
"--psk") == 0)
311 else if (strcmp(argv[count],
"--psk-identity") == 0)
318 else if (strcmp(argv[count],
"-V") == 0)
322 if (strcmp(argv[count],
"mqttv31") == 0 || strcmp(argv[count],
"31") == 0)
324 else if (strcmp(argv[count],
"mqttv311") == 0 || strcmp(argv[count],
"311") == 0)
326 else if (strcmp(argv[count],
"mqttv5") == 0 || strcmp(argv[count],
"5") == 0)
334 else if (strcmp(argv[count],
"--trace") == 0)
338 if (strcmp(argv[count],
"error") == 0)
340 else if (strcmp(argv[count],
"protocol") == 0)
342 else if (strcmp(argv[count],
"min") == 0 || strcmp(argv[count],
"on") == 0)
344 else if (strcmp(argv[count],
"max") == 0)
354 if (strcmp(argv[count],
"--no-retained") == 0 || strcmp(argv[count],
"-R") == 0)
358 fprintf(stderr,
"Unknown option %s\n", argv[count]);
364 if (strcmp(argv[count],
"--retained") == 0 || strcmp(argv[count],
"-r") == 0)
366 else if (strcmp(argv[count],
"--user-property") == 0)
368 if (count + 2 < argc)
376 else if (strcmp(argv[count],
"--message-expiry") == 0)
383 else if (strcmp(argv[count],
"-m") == 0 || strcmp(argv[count],
"--message") == 0)
393 else if (strcmp(argv[count],
"-f") == 0 || strcmp(argv[count],
"--filename") == 0)
403 else if (strcmp(argv[count],
"-n") == 0 || strcmp(argv[count],
"--null-message") == 0)
410 fprintf(stderr,
"Unknown option %s\n", argv[count]);
416 fprintf(stderr,
"Unknown option %s\n", argv[count]);
423 if (opts->
topic == NULL)
434 FILE* infile = fopen(opts->
filename,
"rb");
438 fprintf(stderr,
"Can't open file %s\n", opts->
filename);
441 fseek(infile, 0, SEEK_END);
442 filesize = ftell(infile);
445 buffer =
malloc(
sizeof(
char)*filesize);
448 fprintf(stderr,
"Can't allocate buffer to read file %s\n", opts->
filename);
452 *data_len = (int)fread(buffer, 1, filesize, infile);
453 if (*data_len != filesize)
455 fprintf(stderr,
"%d bytes read of %ld expected for file %s\n", *data_len, filesize, opts->
filename);
470 for (i = 0; i < props->
count; ++i)
474 char* intformat =
"Property name %s value %d\n";
479 printf(intformat, name, props->
array[i].
value.byte);
482 printf(intformat, name, props->
array[i].
value.integer2);
485 printf(intformat, name, props->
array[i].
value.integer4);
488 printf(intformat, name, props->
array[i].
value.integer4);
492 printf(
"Property name %s value len %.*s\n", name,
496 printf(
"Property name %s key %.*s value %.*s\n", name,
char * readfile(int *data_len, struct pubsub_opts *opts)
void usage(struct pubsub_opts *opts, pubsub_opts_nameValue *name_values, const char *program_name)
int MQTTProperty_getType(enum MQTTPropertyCodes value)
int printVersionInfo(pubsub_opts_nameValue *info)
const char * MQTTPropertyName(enum MQTTPropertyCodes value)
#define MQTTVERSION_3_1_1
enum MQTTPropertyCodes identifier
void logProperties(MQTTProperties *props)
int getopts(int argc, char **argv, struct pubsub_opts *opts)
struct pubsub_opts::@69 user_property