|
|
|
@ -155,6 +155,7 @@ void init_config(struct mosq_config *cfg, int pub_or_sub)
|
|
|
|
|
}else{
|
|
|
|
|
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)
|
|
|
|
@ -366,18 +367,26 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if(cfg->protocol_version != 5 && 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(cfg->protocol_version == 5 && cfg->session_expiry_interval > 0){
|
|
|
|
|
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");
|
|
|
|
|
return 1;
|
|
|
|
|
if(cfg->protocol_version == 5){
|
|
|
|
|
if(cfg->clean_session == false && cfg->session_expiry_interval == -1){
|
|
|
|
|
/* User hasn't set session-expiry-interval, but has cleared clean
|
|
|
|
|
* session so default to persistent session. */
|
|
|
|
|
cfg->session_expiry_interval = UINT32_MAX;
|
|
|
|
|
}
|
|
|
|
|
rc = mosquitto_property_add_int32(&cfg->connect_props, MQTT_PROP_SESSION_EXPIRY_INTERVAL, cfg->session_expiry_interval);
|
|
|
|
|
if(rc){
|
|
|
|
|
fprintf(stderr, "Error adding property session-expiry-interval\n");
|
|
|
|
|
if(cfg->session_expiry_interval > 0){
|
|
|
|
|
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");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
rc = mosquitto_property_add_int32(&cfg->connect_props, MQTT_PROP_SESSION_EXPIRY_INTERVAL, cfg->session_expiry_interval);
|
|
|
|
|
if(rc){
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|