Fix session-expiry-interval for v5 clients using -c.

Default behaviour for v5 clients using `-c` is now to use infinite length
sessions, as with v3 clients.

Closes #1546. Thanks to Kiran Pradeep.
pull/1597/head
Roger A. Light 6 years ago
parent 3671a6dfdb
commit 019d4214b8

@ -42,6 +42,8 @@ Clients:
option. option.
- Add `-x` to all clients to all the session-expiry-interval property to be - Add `-x` to all clients to all the session-expiry-interval property to be
easily set for MQTT v5 clients. easily set for MQTT v5 clients.
- Default behaviour for v5 clients using `-c` is now to use infinite length
sessions, as with v3 clients. Closes #1546.
1.6.8 - 20191128 1.6.8 - 20191128

@ -45,7 +45,7 @@ v - RR,SUB (verbose)
W - SUB (timeout) W - SUB (timeout)
w w
X X
x x - PUB,RR,SUB (session-expiry-interval)
Y Y
y y
Z Z

@ -155,6 +155,7 @@ void init_config(struct mosq_config *cfg, int pub_or_sub)
}else{ }else{
cfg->protocol_version = MQTT_PROTOCOL_V311; cfg->protocol_version = MQTT_PROTOCOL_V311;
} }
cfg->session_expiry_interval = -1; /* -1 means unset here, the user can't set it to -1. */
} }
void client_config_cleanup(struct mosq_config *cfg) void client_config_cleanup(struct mosq_config *cfg)
@ -366,11 +367,13 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
} }
#endif #endif
if(cfg->protocol_version != 5 && cfg->clean_session == false && (cfg->id_prefix || !cfg->id)){ if(cfg->protocol_version == 5){
fprintf(stderr, "Error: You must provide a client id if you are using the -c option.\n"); if(cfg->clean_session == false && cfg->session_expiry_interval == -1){
return 1; /* User hasn't set session-expiry-interval, but has cleared clean
* session so default to persistent session. */
cfg->session_expiry_interval = UINT32_MAX;
} }
if(cfg->protocol_version == 5 && cfg->session_expiry_interval > 0){ if(cfg->session_expiry_interval > 0){
if(cfg->session_expiry_interval == UINT32_MAX && (cfg->id_prefix || !cfg->id)){ if(cfg->session_expiry_interval == UINT32_MAX && (cfg->id_prefix || !cfg->id)){
fprintf(stderr, "Error: You must provide a client id if you are using an infinite session expiry interval.\n"); fprintf(stderr, "Error: You must provide a client id if you are using an infinite session expiry interval.\n");
return 1; return 1;
@ -380,6 +383,12 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
fprintf(stderr, "Error adding property session-expiry-interval\n"); fprintf(stderr, "Error adding property session-expiry-interval\n");
} }
} }
}else{
if(cfg->clean_session == false && (cfg->id_prefix || !cfg->id)){
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(pub_or_sub == CLIENT_SUB){
if(cfg->topic_count == 0){ if(cfg->topic_count == 0){

Loading…
Cancel
Save