mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-26 21:36:43 +08:00
Add mosquitto_int_option and mosquitto_void_option
This deprecates mosquitto_opts_set().
This commit is contained in:
committed by
Roger A. Light
parent
2f54b16544
commit
0546e7bebc
@@ -947,7 +947,7 @@ int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg)
|
||||
{
|
||||
int rc;
|
||||
|
||||
mosquitto_opts_set(mosq, MOSQ_OPT_PROTOCOL_VERSION, &(cfg->protocol_version));
|
||||
mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, cfg->protocol_version);
|
||||
|
||||
if(cfg->will_topic && mosquitto_will_set_v5(mosq, cfg->will_topic,
|
||||
cfg->will_payloadlen, cfg->will_payload, cfg->will_qos,
|
||||
|
||||
@@ -99,6 +99,7 @@ MOSQ_1.6 {
|
||||
mosquitto_disconnect_v5_callback_set;
|
||||
mosquitto_disconnect_v5;
|
||||
mosquitto_message_v5_callback_set;
|
||||
mosquitto_int_option;
|
||||
mosquitto_property_add_binary;
|
||||
mosquitto_property_add_byte;
|
||||
mosquitto_property_add_int16;
|
||||
@@ -126,5 +127,6 @@ MOSQ_1.6 {
|
||||
mosquitto_subscribe_v5;
|
||||
mosquitto_unsubscribe_v5_callback_set;
|
||||
mosquitto_unsubscribe_v5;
|
||||
mosquitto_void_option;
|
||||
mosquitto_will_set_v5;
|
||||
} MOSQ_1.5;
|
||||
|
||||
@@ -1313,6 +1313,9 @@ libmosq_EXPORT int mosquitto_threaded_set(struct mosquitto *mosq, bool threaded)
|
||||
*
|
||||
* Used to set options for the client.
|
||||
*
|
||||
* This function is deprecated, the replacement <mosquitto_int_option> and
|
||||
* <mosquitto_void_option> functions should be used instead.
|
||||
*
|
||||
* Parameters:
|
||||
* mosq - a valid mosquitto instance.
|
||||
* option - the option to set.
|
||||
@@ -1345,6 +1348,57 @@ libmosq_EXPORT int mosquitto_threaded_set(struct mosquitto *mosq, bool threaded)
|
||||
*/
|
||||
libmosq_EXPORT int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t option, void *value);
|
||||
|
||||
/*
|
||||
* Function: mosquitto_int_option
|
||||
*
|
||||
* Used to set integer options for the client.
|
||||
*
|
||||
* Parameters:
|
||||
* mosq - a valid mosquitto instance.
|
||||
* option - the option to set.
|
||||
* value - the option specific value.
|
||||
*
|
||||
* Options:
|
||||
* MOSQ_OPT_PROTOCOL_VERSION
|
||||
* Value must be set to either MQTT_PROTOCOL_V31,
|
||||
* MQTT_PROTOCOL_V311, or MQTT_PROTOCOL_V5. Must be set before the
|
||||
* client connects. Defaults to MQTT_PROTOCOL_V311.
|
||||
*
|
||||
* MOSQ_OPT_SSL_CTX_WITH_DEFAULTS
|
||||
* If value is set to a non zero value, then the user specified
|
||||
* SSL_CTX passed in using MOSQ_OPT_SSL_CTX will have the default
|
||||
* options applied to it. This means that you only need to change
|
||||
* the values that are relevant to you. If you use this option then
|
||||
* you must configure the TLS options as normal, i.e. you should
|
||||
* use <mosquitto_tls_set> to configure the cafile/capath as a
|
||||
* minimum.
|
||||
* This option is only available for openssl 1.1.0 and higher.
|
||||
*/
|
||||
libmosq_EXPORT int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t option, int value);
|
||||
|
||||
/*
|
||||
* Function: mosquitto_void_option
|
||||
*
|
||||
* Used to set void* options for the client.
|
||||
*
|
||||
* Parameters:
|
||||
* mosq - a valid mosquitto instance.
|
||||
* option - the option to set.
|
||||
* value - the option specific value.
|
||||
*
|
||||
* Options:
|
||||
* MOSQ_OPT_SSL_CTX
|
||||
* Pass an openssl SSL_CTX to be used when creating TLS connections
|
||||
* rather than libmosquitto creating its own. This must be called
|
||||
* before connecting to have any effect. If you use this option, the
|
||||
* onus is on you to ensure that you are using secure settings.
|
||||
* Setting to NULL means that libmosquitto will use its own SSL_CTX
|
||||
* if TLS is to be used.
|
||||
* This option is only available for openssl 1.1.0 and higher.
|
||||
*/
|
||||
libmosq_EXPORT int mosquitto_void_option(struct mosquitto *mosq, enum mosq_opt_t option, void *value);
|
||||
|
||||
|
||||
/*
|
||||
* Function: mosquitto_reconnect_delay_set
|
||||
*
|
||||
|
||||
+57
-11
@@ -276,16 +276,7 @@ int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t option, void *val
|
||||
switch(option){
|
||||
case MOSQ_OPT_PROTOCOL_VERSION:
|
||||
ival = *((int *)value);
|
||||
if(ival == MQTT_PROTOCOL_V31){
|
||||
mosq->protocol = mosq_p_mqtt31;
|
||||
}else if(ival == MQTT_PROTOCOL_V311){
|
||||
mosq->protocol = mosq_p_mqtt311;
|
||||
}else if(ival == MQTT_PROTOCOL_V5){
|
||||
mosq->protocol = mosq_p_mqtt5;
|
||||
}else{
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
break;
|
||||
return mosquitto_int_option(mosq, option, ival);
|
||||
case MOSQ_OPT_SSL_CTX:
|
||||
#ifdef WITH_TLS
|
||||
mosq->ssl_ctx = (SSL_CTX *)value;
|
||||
@@ -300,9 +291,64 @@ int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t option, void *val
|
||||
#else
|
||||
return MOSQ_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
default:
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t option, int value)
|
||||
{
|
||||
if(!mosq) return MOSQ_ERR_INVAL;
|
||||
|
||||
switch(option){
|
||||
case MOSQ_OPT_PROTOCOL_VERSION:
|
||||
if(value == MQTT_PROTOCOL_V31){
|
||||
mosq->protocol = mosq_p_mqtt31;
|
||||
}else if(value == MQTT_PROTOCOL_V311){
|
||||
mosq->protocol = mosq_p_mqtt311;
|
||||
}else if(value == MQTT_PROTOCOL_V5){
|
||||
mosq->protocol = mosq_p_mqtt5;
|
||||
}else{
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
break;
|
||||
|
||||
case MOSQ_OPT_SSL_CTX_WITH_DEFAULTS:
|
||||
#if defined(WITH_TLS) && OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
mosq->ssl_ctx_defaults = true;
|
||||
if(value){
|
||||
mosq->ssl_ctx_defaults = true;
|
||||
}else{
|
||||
mosq->ssl_ctx_defaults = false;
|
||||
}
|
||||
break;
|
||||
#else
|
||||
return MOSQ_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int mosquitto_void_option(struct mosquitto *mosq, enum mosq_opt_t option, void *value)
|
||||
{
|
||||
if(!mosq || !value) return MOSQ_ERR_INVAL;
|
||||
|
||||
switch(option){
|
||||
case MOSQ_OPT_SSL_CTX:
|
||||
#ifdef WITH_TLS
|
||||
mosq->ssl_ctx = (SSL_CTX *)value;
|
||||
if(mosq->ssl_ctx){
|
||||
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
|
||||
SSL_CTX_up_ref(mosq->ssl_ctx);
|
||||
#else
|
||||
CRYPTO_add(&(mosq->ssl_ctx)->references, 1, CRYPTO_LOCK_SSL_CTX);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
#else
|
||||
return MOSQ_ERR_NOT_SUPPORTED;
|
||||
|
||||
Reference in New Issue
Block a user