From bd61d18e92df659f403b99b6e00cb05570945e43 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sat, 27 Feb 2016 07:41:50 +0000 Subject: [PATCH] Small tidy up. --- client/client_shared.c | 88 ++++++++++++++++++++--------------------- client/pub_client.c | 9 +++-- client/sub_client.c | 10 ++--- man/mosquitto_pub.1.xml | 38 ++++++++++-------- man/mosquitto_sub.1.xml | 45 +++++++++++---------- 5 files changed, 100 insertions(+), 90 deletions(-) diff --git a/client/client_shared.c b/client/client_shared.c index 2ec57fb9..486d4164 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -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; } diff --git a/client/pub_client.c b/client/pub_client.c index bd550bfb..7873be16 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -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"); diff --git a/client/sub_client.c b/client/sub_client.c index 523936d5..e394d063 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -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"); diff --git a/man/mosquitto_pub.1.xml b/man/mosquitto_pub.1.xml index f2896951..9b78fbf9 100644 --- a/man/mosquitto_pub.1.xml +++ b/man/mosquitto_pub.1.xml @@ -17,15 +17,24 @@ mosquitto_pub + + + hostname + port number + + username + password + + message-topic + + URL + bind_address - hostname client_id client id prefix keepalive time - port number message QoS - URL @@ -36,10 +45,6 @@ - - username - password - topic payload @@ -68,7 +73,6 @@ socks-url protocol-version - message-topic mosquitto_pub @@ -230,6 +234,15 @@ See also . + + + + + 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 + + @@ -369,15 +382,6 @@ broker. - - - - - 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 - - diff --git a/man/mosquitto_sub.1.xml b/man/mosquitto_sub.1.xml index bb068f09..616cfbde 100644 --- a/man/mosquitto_sub.1.xml +++ b/man/mosquitto_sub.1.xml @@ -17,16 +17,28 @@ mosquitto_sub + + + hostname + port number + + username + password + + message-topic + + + URL + message-topic + + bind_address msg count - hostname client_id client id prefix keepalive time - URL - port number message QoS @@ -37,10 +49,6 @@ - - username - password - topic payload @@ -67,10 +75,7 @@ socks-url protocol-version filter-out - - unsub-topic - message-topic - + unsub-topic mosquitto_sub @@ -258,6 +263,15 @@ See also . + + + + + 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 + + @@ -421,15 +435,6 @@ broker. - - - - - 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 - -