Small tidy up.

This commit is contained in:
Roger A. Light 2016-02-27 07:41:50 +00:00
parent 59c80d9197
commit bd61d18e92
5 changed files with 100 additions and 90 deletions

View File

@ -417,6 +417,50 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
}
i++;
#endif
}else if(!strcmp(argv[i], "-L") || !strcmp(argv[i], "--url")){
if(i==argc-1){
fprintf(stderr, "Error: -L argument given but no URL specified.\n\n");
return 1;
} else {
char *url = argv[i+1];
char *topic;
char *tmp;
if(!strncasecmp(url, "mqtt://", 7)) {
url += 7;
} else if(!strncasecmp(url, "mqtts://", 8)) {
url += 8;
cfg->port = 8883;
} else {
fprintf(stderr, "Error: unsupported URL scheme.\n\n");
return 1;
}
topic = strchr(url, '/');
*topic++ = 0;
if(cfg_add_topic(cfg, pub_or_sub, topic))
return 1;
tmp = strchr(url, '@');
if(tmp) {
char *colon = strchr(url, ':');
*tmp++ = 0;
if(colon) {
*colon = 0;
cfg->password = colon + 1;
}
cfg->username = url;
url = tmp;
}
cfg->host = url;
tmp = strchr(url, ':');
if(tmp) {
*tmp++ = 0;
cfg->port = atoi(tmp);
}
}
i++;
}else if(!strcmp(argv[i], "-l") || !strcmp(argv[i], "--stdin-line")){
if(pub_or_sub == CLIENT_SUB){
goto unknown_option;
@ -681,50 +725,6 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
goto unknown_option;
}
cfg->hex_output = true;
}else if(!strcmp(argv[i], "-L") || !strcmp(argv[i], "--url")){
if(i==argc-1){
fprintf(stderr, "Error: -x argument given but no URL specified.\n\n");
return 1;
} else {
char *url = argv[i+1];
char *topic;
char *tmp;
if(!strncasecmp(url, "mqtt://", 7)) {
url += 7;
} else if(!strncasecmp(url, "mqtts://", 8)) {
url += 8;
cfg->port = 8883;
} else {
fprintf(stderr, "Error: unsupported URL scheme.\n\n");
return 1;
}
topic = strchr(url, '/');
*topic++ = 0;
if(cfg_add_topic(cfg, pub_or_sub, topic))
return 1;
tmp = strchr(url, '@');
if(tmp) {
char *colon = strchr(url, ':');
*tmp++ = 0;
if(colon) {
*colon = 0;
cfg->password = colon + 1;
}
cfg->username = url;
url = tmp;
}
cfg->host = url;
tmp = strchr(url, ':');
if(tmp) {
*tmp++ = 0;
cfg->port = atoi(tmp);
}
}
i++;
}else{
goto unknown_option;
}

View File

@ -205,7 +205,9 @@ void print_usage(void)
mosquitto_lib_version(&major, &minor, &revision);
printf("mosquitto_pub is a simple mqtt client that will publish a message on a single topic and exit.\n");
printf("mosquitto_pub version %s running on libmosquitto %d.%d.%d.\n\n", VERSION, major, minor, revision);
printf("Usage: mosquitto_pub [-h host] [-k keepalive] [-p port] [-q qos] [-r] {-f file | -l | -n | -m message} [-t topic]\n");
printf("Usage: mosquitto_pub {[-h host] [-p port] [-u username [-P password]] -t topic | -L URL}\n");
printf(" {-f file | -l | -n | -m message}\n");
printf(" [-k keepalive] [-q qos] [-r]\n");
#ifdef WITH_SRV
printf(" [-A bind_address] [-S]\n");
#else
@ -214,7 +216,6 @@ void print_usage(void)
printf(" [-i id] [-I id_prefix]\n");
printf(" [-d] [--quiet]\n");
printf(" [-M max_inflight]\n");
printf(" [-L URL]\n");
printf(" [-u username [-P password]]\n");
printf(" [--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]\n");
#ifdef WITH_TLS
@ -237,6 +238,8 @@ void print_usage(void)
printf(" -I : define the client id as id_prefix appended with the process id. Useful for when the\n");
printf(" broker is using the clientid_prefixes option.\n");
printf(" -k : keep alive in seconds for this client. Defaults to 60.\n");
printf(" -L : specify user, password, hostname, port and topic as a URL in the form:\n");
printf(" mqtt(s)://[username[:password]@]host[:port]/topic\n");
printf(" -l : read messages from stdin, sending a separate message for each line.\n");
printf(" -m : message payload to send.\n");
printf(" -M : the maximum inflight messages for QoS 1/2..\n");
@ -250,8 +253,6 @@ void print_usage(void)
printf(" -S : use SRV lookups to determine which host to connect to.\n");
#endif
printf(" -t : mqtt topic to publish to.\n");
printf(" -L : specify user, password, hostname, port and topic as a URL in the form:\n");
printf(" mqtt(s)://[username[:password]@]host[:port]/topic\n");
printf(" -u : provide a username (requires MQTT 3.1 broker)\n");
printf(" -V : specify the version of the MQTT protocol to use when connecting.\n");
printf(" Can be mqttv31 or mqttv311. Defaults to mqttv31.\n");

View File

@ -151,8 +151,9 @@ void print_usage(void)
mosquitto_lib_version(&major, &minor, &revision);
printf("mosquitto_sub is a simple mqtt client that will subscribe to a single topic and print all messages it receives.\n");
printf("mosquitto_sub version %s running on libmosquitto %d.%d.%d.\n\n", VERSION, major, minor, revision);
printf("Usage: mosquitto_sub [-c] [-h host] [-k keepalive] [-p port] [-q qos] [-R] {-t topic ... | -U topic ...}\n");
printf(" [-L URL] [-C msg_count] [--retained-only] [-T filter_out]\n");
printf("Usage: mosquitto_sub {[-h host] [-p port] [-u username [-P password]] -t topic | -L URL [-t topic]}\n");
printf(" [-c] [-k keepalive] [-q qos]\n");
printf(" [-C msg_count] [-R] [--retained-only] [-T filter_out] [-U topic ...]\n");
#ifdef WITH_SRV
printf(" [-A bind_address] [-S]\n");
#else
@ -160,7 +161,6 @@ void print_usage(void)
#endif
printf(" [-i id] [-I id_prefix]\n");
printf(" [-d] [-N] [--quiet] [-v] [-x]\n");
printf(" [-u username [-P password]]\n");
printf(" [--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]\n");
#ifdef WITH_TLS
printf(" [{--cafile file | --capath dir} [--cert file] [--key file]\n");
@ -183,6 +183,8 @@ void print_usage(void)
printf(" -I : define the client id as id_prefix appended with the process id. Useful for when the\n");
printf(" broker is using the clientid_prefixes option.\n");
printf(" -k : keep alive in seconds for this client. Defaults to 60.\n");
printf(" -L : specify user, password, hostname, port and topic as a URL in the form:\n");
printf(" mqtt(s)://[username[:password]@]host[:port]/topic\n");
printf(" -N : do not add an end of line character when printing the payload.\n");
printf(" -p : network port to connect to. Defaults to 1883 for plain MQTT and 8883 for MQTT over TLS.\n");
printf(" -P : provide a password (requires MQTT 3.1 broker)\n");
@ -193,8 +195,6 @@ void print_usage(void)
#endif
printf(" -t : mqtt topic to subscribe to. May be repeated multiple times.\n");
printf(" -T : topic string to filter out of results. May be repeated.\n");
printf(" -L : specify user, password, hostname, port and topic as a URL in the form:\n");
printf(" mqtt(s)://[username[:password]@]host[:port]/topic\n");
printf(" -u : provide a username (requires MQTT 3.1 broker)\n");
printf(" -U : unsubscribe from a topic. May be repeated.\n");
printf(" -v : print published messages verbosely.\n");

View File

@ -17,15 +17,24 @@
<refsynopsisdiv>
<cmdsynopsis>
<command>mosquitto_pub</command>
<group choice='req'>
<arg choice='plain'>
<arg><option>-h</option> <replaceable>hostname</replaceable></arg>
<arg><option>-p</option> <replaceable>port number</replaceable></arg>
<arg>
<arg><option>-u</option> <replaceable>username</replaceable></arg>
<arg><option>-P</option> <replaceable>password</replaceable></arg>
</arg>
<arg choice='plain' rep='repeat'><option>-t</option> <replaceable>message-topic</replaceable></arg>
</arg>
<arg choice='plain'><option>-L</option> <replaceable>URL</replaceable></arg>
</group>
<arg><option>-A</option> <replaceable>bind_address</replaceable></arg>
<arg><option>-d</option></arg>
<arg><option>-h</option> <replaceable>hostname</replaceable></arg>
<arg><option>-i</option> <replaceable>client_id</replaceable></arg>
<arg><option>-I</option> <replaceable>client id prefix</replaceable></arg>
<arg><option>-k</option> <replaceable>keepalive time</replaceable></arg>
<arg><option>-p</option> <replaceable>port number</replaceable></arg>
<arg><option>-q</option> <replaceable>message QoS</replaceable></arg>
<arg><option>-L</option> <replaceable>URL</replaceable></arg>
<arg><option>--quiet</option></arg>
<arg><option>-r</option></arg>
<arg><option>-S</option></arg>
@ -36,10 +45,6 @@
<arg choice='plain'><option>-n</option></arg>
<arg choice='plain'><option>-s</option></arg>
</group>
<arg>
<arg><option>-u</option> <replaceable>username</replaceable></arg>
<arg><option>-P</option> <replaceable>password</replaceable></arg>
</arg>
<arg>
<option>--will-topic</option> <replaceable>topic</replaceable>
<arg><option>--will-payload</option> <replaceable>payload</replaceable></arg>
@ -68,7 +73,6 @@
<arg><option>--proxy</option> <replaceable>socks-url</replaceable></arg>
<arg><option>-V</option> <replaceable>protocol-version</replaceable></arg>
<arg choice='plain'><option>-t</option> <replaceable>message-topic</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>mosquitto_pub</command>
@ -230,6 +234,15 @@
<para>See also <option>--cert</option>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-L</option></term>
<term><option>--url</option></term>
<listitem>
<para>Specify specify user, password, hostname, port and topic at once as a URL.
The URL must be in the form:
mqtt(s)://[username[:password]@]host[:port]/topic</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-l</option></term>
<term><option>--stdin-line</option></term>
@ -369,15 +382,6 @@
broker.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-L</option></term>
<term><option>--url</option></term>
<listitem>
<para>Specify specify user, password, hostname, port and topic at once as a URL.
The URL must be in the form:
mqtt(s)://[username[:password]@]host[:port]/topic</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-u</option></term>
<term><option>--username</option></term>

View File

@ -17,16 +17,28 @@
<refsynopsisdiv>
<cmdsynopsis>
<command>mosquitto_sub</command>
<group choice='req'>
<arg choice='plain'>
<arg><option>-h</option> <replaceable>hostname</replaceable></arg>
<arg><option>-p</option> <replaceable>port number</replaceable></arg>
<arg>
<arg><option>-u</option> <replaceable>username</replaceable></arg>
<arg><option>-P</option> <replaceable>password</replaceable></arg>
</arg>
<arg choice='plain' rep='repeat'><option>-t</option> <replaceable>message-topic</replaceable></arg>
</arg>
<arg choice='plain'>
<arg choice='plain'><option>-L</option> <replaceable>URL</replaceable></arg>
<arg choice='opt' rep='repeat'><option>-t</option> <replaceable>message-topic</replaceable></arg>
</arg>
</group>
<arg><option>-A</option> <replaceable>bind_address</replaceable></arg>
<arg><option>-c</option></arg>
<arg><option>-C</option> <replaceable>msg count</replaceable></arg>
<arg><option>-d</option></arg>
<arg><option>-h</option> <replaceable>hostname</replaceable></arg>
<arg><option>-i</option> <replaceable>client_id</replaceable></arg>
<arg><option>-I</option> <replaceable>client id prefix</replaceable></arg>
<arg><option>-k</option> <replaceable>keepalive time</replaceable></arg>
<arg><option>-L</option> <replaceable>URL</replaceable></arg>
<arg><option>-p</option> <replaceable>port number</replaceable></arg>
<arg><option>-q</option> <replaceable>message QoS</replaceable></arg>
<group choice='opt'>
<arg choice='plain'><option>-R</option></arg>
@ -37,10 +49,6 @@
<arg><option>--quiet</option></arg>
<arg><option>-v</option></arg>
<arg><option>-x</option></arg>
<arg>
<arg><option>-u</option> <replaceable>username</replaceable></arg>
<arg><option>-P</option> <replaceable>password</replaceable></arg>
</arg>
<arg>
<option>--will-topic</option> <replaceable>topic</replaceable>
<arg><option>--will-payload</option> <replaceable>payload</replaceable></arg>
@ -67,10 +75,7 @@
<arg><option>--proxy</option> <replaceable>socks-url</replaceable></arg>
<arg><option>-V</option> <replaceable>protocol-version</replaceable></arg>
<arg choice='opt' rep='repeat'><option>-T</option> <replaceable>filter-out</replaceable></arg>
<group choice='req'>
<arg choice='plain' rep='repeat'><option>-U</option> <replaceable>unsub-topic</replaceable></arg>
<arg choice='plain' rep='repeat'><option>-t</option> <replaceable>message-topic</replaceable></arg>
</group>
<arg choice='opt' rep='repeat'><option>-U</option> <replaceable>unsub-topic</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>mosquitto_sub</command>
@ -258,6 +263,15 @@
<para>See also <option>--cert</option>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-L</option></term>
<term><option>--url</option></term>
<listitem>
<para>Specify specify user, password, hostname, port and topic at once as a URL.
The URL must be in the form:
mqtt(s)://[username[:password]@]host[:port]/topic</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-N</option></term>
<listitem>
@ -421,15 +435,6 @@
broker.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-L</option></term>
<term><option>--url</option></term>
<listitem>
<para>Specify specify user, password, hostname, port and topic at once as a URL.
The URL must be in the form:
mqtt(s)://[username[:password]@]host[:port]/topic</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-u</option></term>
<term><option>--username</option></term>