mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-07-30 02:38:19 +02:00
Merge branch 'bugfix/mqtt_add_null_check' into 'master'
esp-mqtt: Add null checks for public APIs See merge request espressif/esp-mqtt!94
This commit is contained in:
@ -242,6 +242,7 @@ esp_err_t esp_mqtt_client_start(esp_mqtt_client_handle_t client);
|
||||
* @param client mqtt client handle
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* ESP_ERR_INVALID_ARG on wrong initialization
|
||||
* ESP_FAIL if client is in invalid state
|
||||
*/
|
||||
esp_err_t esp_mqtt_client_reconnect(esp_mqtt_client_handle_t client);
|
||||
@ -252,6 +253,7 @@ esp_err_t esp_mqtt_client_reconnect(esp_mqtt_client_handle_t client);
|
||||
* @param client mqtt client handle
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* ESP_ERR_INVALID_ARG on wrong initialization
|
||||
*/
|
||||
esp_err_t esp_mqtt_client_disconnect(esp_mqtt_client_handle_t client);
|
||||
|
||||
@ -264,6 +266,7 @@ esp_err_t esp_mqtt_client_disconnect(esp_mqtt_client_handle_t client);
|
||||
* @param client mqtt client handle
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* ESP_ERR_INVALID_ARG on wrong initialization
|
||||
* ESP_FAIL if client is in invalid state
|
||||
*/
|
||||
esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client);
|
||||
@ -357,6 +360,7 @@ int esp_mqtt_client_enqueue(esp_mqtt_client_handle_t client, const char *topic,
|
||||
* @param client mqtt client handle
|
||||
*
|
||||
* @return ESP_OK
|
||||
* ESP_ERR_INVALID_ARG on wrong initialization
|
||||
*/
|
||||
esp_err_t esp_mqtt_client_destroy(esp_mqtt_client_handle_t client);
|
||||
|
||||
@ -381,6 +385,7 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl
|
||||
* @param event_handler_arg handlers context
|
||||
*
|
||||
* @return ESP_ERR_NO_MEM if failed to allocate
|
||||
* ESP_ERR_INVALID_ARG on wrong initialization
|
||||
* ESP_OK on success
|
||||
*/
|
||||
esp_err_t esp_mqtt_client_register_event(esp_mqtt_client_handle_t client, esp_mqtt_event_id_t event, esp_event_handler_t event_handler, void* event_handler_arg);
|
||||
@ -390,6 +395,7 @@ esp_err_t esp_mqtt_client_register_event(esp_mqtt_client_handle_t client, esp_mq
|
||||
*
|
||||
* @param client mqtt client handle
|
||||
* @return outbox size
|
||||
* 0 on wrong initialization
|
||||
*/
|
||||
int esp_mqtt_client_get_outbox_size(esp_mqtt_client_handle_t client);
|
||||
|
||||
|
@ -322,6 +322,10 @@ static bool set_if_config(char const *const new_config, char **old_config)
|
||||
|
||||
esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_client_config_t *config)
|
||||
{
|
||||
if (!client) {
|
||||
ESP_LOGE(TAG, "Client was not initialized");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
MQTT_API_LOCK(client);
|
||||
//Copy user configurations to client context
|
||||
esp_err_t err = ESP_OK;
|
||||
@ -1487,6 +1491,10 @@ esp_err_t esp_mqtt_client_start(esp_mqtt_client_handle_t client)
|
||||
|
||||
esp_err_t esp_mqtt_client_disconnect(esp_mqtt_client_handle_t client)
|
||||
{
|
||||
if (!client) {
|
||||
ESP_LOGE(TAG, "Client was not initialized");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_LOGI(TAG, "Client asked to disconnect");
|
||||
xEventGroupSetBits(client->status_bits, DISCONNECT_BIT);
|
||||
return ESP_OK;
|
||||
@ -1494,8 +1502,11 @@ esp_err_t esp_mqtt_client_disconnect(esp_mqtt_client_handle_t client)
|
||||
|
||||
esp_err_t esp_mqtt_client_reconnect(esp_mqtt_client_handle_t client)
|
||||
{
|
||||
if (!client) {
|
||||
ESP_LOGE(TAG, "Client was not initialized");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_LOGI(TAG, "Client force reconnect requested");
|
||||
|
||||
if (client->state != MQTT_STATE_WAIT_RECONNECT) {
|
||||
ESP_LOGD(TAG, "The client is not waiting for reconnection. Ignore the request");
|
||||
return ESP_FAIL;
|
||||
@ -1507,6 +1518,10 @@ esp_err_t esp_mqtt_client_reconnect(esp_mqtt_client_handle_t client)
|
||||
|
||||
esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client)
|
||||
{
|
||||
if (!client) {
|
||||
ESP_LOGE(TAG, "Client was not initialized");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
MQTT_API_LOCK(client);
|
||||
if (client->run) {
|
||||
/* A running client cannot be stopped from the MQTT task/event handler */
|
||||
@ -1561,6 +1576,10 @@ static esp_err_t esp_mqtt_client_ping(esp_mqtt_client_handle_t client)
|
||||
|
||||
int esp_mqtt_client_subscribe(esp_mqtt_client_handle_t client, const char *topic, int qos)
|
||||
{
|
||||
if (!client) {
|
||||
ESP_LOGE(TAG, "Client was not initialized");
|
||||
return -1;
|
||||
}
|
||||
MQTT_API_LOCK(client);
|
||||
if (client->state != MQTT_STATE_CONNECTED) {
|
||||
ESP_LOGE(TAG, "Client has not connected");
|
||||
@ -1594,6 +1613,10 @@ int esp_mqtt_client_subscribe(esp_mqtt_client_handle_t client, const char *topic
|
||||
|
||||
int esp_mqtt_client_unsubscribe(esp_mqtt_client_handle_t client, const char *topic)
|
||||
{
|
||||
if (!client) {
|
||||
ESP_LOGE(TAG, "Client was not initialized");
|
||||
return -1;
|
||||
}
|
||||
MQTT_API_LOCK(client);
|
||||
if (client->state != MQTT_STATE_CONNECTED) {
|
||||
MQTT_API_UNLOCK(client);
|
||||
@ -1670,6 +1693,10 @@ static inline int mqtt_client_enqueue_priv(esp_mqtt_client_handle_t client, cons
|
||||
|
||||
int esp_mqtt_client_publish(esp_mqtt_client_handle_t client, const char *topic, const char *data, int len, int qos, int retain)
|
||||
{
|
||||
if (!client) {
|
||||
ESP_LOGE(TAG, "Client was not initialized");
|
||||
return -1;
|
||||
}
|
||||
MQTT_API_LOCK(client);
|
||||
#if MQTT_SKIP_PUBLISH_IF_DISCONNECTED
|
||||
if (client->state != MQTT_STATE_CONNECTED) {
|
||||
@ -1759,6 +1786,10 @@ cannot_publish:
|
||||
|
||||
int esp_mqtt_client_enqueue(esp_mqtt_client_handle_t client, const char *topic, const char *data, int len, int qos, int retain, bool store)
|
||||
{
|
||||
if (!client) {
|
||||
ESP_LOGE(TAG, "Client was not initialized");
|
||||
return -1;
|
||||
}
|
||||
MQTT_API_LOCK(client);
|
||||
int ret = mqtt_client_enqueue_priv(client, topic, data, len, qos, retain, store);
|
||||
MQTT_API_UNLOCK(client);
|
||||
|
Reference in New Issue
Block a user