Add -c to mosquitto_pub.

This commit is contained in:
Roger A. Light 2017-07-17 20:43:06 +01:00
parent e74203de2c
commit ef7a7850ac
6 changed files with 25 additions and 12 deletions

View File

@ -60,6 +60,7 @@ Client library:
Client:
- Add -F to mosquitto_sub to allow the user to choose the output format.
- Add -U to mosquitto_sub for unsubscribing from topics.
- Add -c (clean session) to mosquitto_pub.
- Add --retained-only to mosquitto_sub to exit after receiving all retained
messages.
- Connections now default to using MQTT v3.1.1.

View File

@ -317,11 +317,12 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
}
#endif
if(cfg->clean_session == false && (cfg->id_prefix || !cfg->id)){
if(!cfg->quiet) fprintf(stderr, "Error: You must provide a client id if you are using the -c option.\n");
return 1;
}
if(pub_or_sub == CLIENT_SUB){
if(cfg->clean_session == false && (cfg->id_prefix || !cfg->id)){
if(!cfg->quiet) fprintf(stderr, "Error: You must provide a client id if you are using the -c option.\n");
return 1;
}
if(cfg->topic_count == 0){
if(!cfg->quiet) fprintf(stderr, "Error: You must specify a topic to subscribe to.\n");
return 1;
@ -834,9 +835,6 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
}
i++;
}else if(!strcmp(argv[i], "-c") || !strcmp(argv[i], "--disable-clean-session")){
if(pub_or_sub == CLIENT_PUB){
goto unknown_option;
}
cfg->clean_session = false;
}else if(!strcmp(argv[i], "-N")){
if(pub_or_sub == CLIENT_PUB){

View File

@ -71,7 +71,7 @@ struct mosq_config {
char *psk_identity;
# endif
#endif
bool clean_session; /* sub */
bool clean_session;
char **topics; /* sub */
int topic_count; /* sub */
bool no_retain; /* sub */

View File

@ -207,7 +207,7 @@ void print_usage(void)
printf("mosquitto_pub version %s running on libmosquitto %d.%d.%d.\n\n", VERSION, major, minor, revision);
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");
printf(" [-c] [-k keepalive] [-q qos] [-r]\n");
#ifdef WITH_SRV
printf(" [-A bind_address] [-S]\n");
#else

View File

@ -30,6 +30,7 @@
<arg choice='plain'><option>-L</option> <replaceable>URL</replaceable></arg>
</group>
<arg><option>-A</option> <replaceable>bind_address</replaceable></arg>
<arg><option>-c</option></arg>
<arg><option>-d</option></arg>
<arg><option>-i</option> <replaceable>client_id</replaceable></arg>
<arg><option>-I</option> <replaceable>client id prefix</replaceable></arg>
@ -113,6 +114,19 @@
interface.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-c</option></term>
<term><option>--disable-clean-session</option></term>
<listitem>
<para>Disable the 'clean session' flag. This means that all
of the subscriptions for the client will be maintained
after it disconnects, along with subsequent QoS 1 and QoS 2
messages that arrive. When the client reconnects, it will
receive all of the queued messages.</para>
<para>If using this option, the client id must be set
manually with <option>--id</option></para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--cafile</option></term>
<listitem>

View File

@ -23,7 +23,7 @@
<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>
earg><option>-P</option> <replaceable>password</replaceable></arg>
</arg>
<arg choice='plain' rep='repeat'><option>-t</option> <replaceable>message-topic</replaceable></arg>
</arg>
@ -131,8 +131,8 @@
after it disconnects, along with subsequent QoS 1 and QoS 2
messages that arrive. When the client reconnects, it will
receive all of the queued messages.</para>
<para>If using this option, it is recommended that the
client id is set manually with <option>--id</option></para>
<para>If using this option, the client id must be set
manually with <option>--id</option></para>
</listitem>
</varlistentry>
<varlistentry>