Skip to content

Commit

Permalink
Merge branch 'contrib/github_pr_10715' into 'master'
Browse files Browse the repository at this point in the history
Add user_data accessor and mutator to esp_http_client (GitHub PR)

Closes IDFGH-9337 and IDFGH-9221

See merge request espressif/esp-idf!22751
  • Loading branch information
mahavirj committed Mar 21, 2023
2 parents 86f83e0 + 82cdcc5 commit bdf8f1c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
22 changes: 22 additions & 0 deletions components/esp_http_client/esp_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,28 @@ esp_err_t esp_http_client_set_authtype(esp_http_client_handle_t client, esp_http
return ESP_OK;
}

esp_err_t esp_http_client_get_user_data(esp_http_client_handle_t client, void **data)
{
if (NULL == client || NULL == data) {
ESP_LOGE(TAG, "client or data must not be NULL");
return ESP_ERR_INVALID_ARG;
}

*data = client->user_data;
return ESP_OK;
}

esp_err_t esp_http_client_set_user_data(esp_http_client_handle_t client, void *data)
{
if (NULL == client) {
ESP_LOGE(TAG, "client must not be NULL");
return ESP_ERR_INVALID_ARG;
}

client->user_data = data;
return ESP_OK;
}

static esp_err_t _set_config(esp_http_client_handle_t client, const esp_http_client_config_t *config)
{
esp_err_t ret = ESP_OK;
Expand Down
28 changes: 28 additions & 0 deletions components/esp_http_client/include/esp_http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,34 @@ esp_err_t esp_http_client_set_password(esp_http_client_handle_t client, const ch
*/
esp_err_t esp_http_client_set_authtype(esp_http_client_handle_t client, esp_http_client_auth_type_t auth_type);

/**
* @brief Get http request user_data.
* The value stored from the esp_http_client_config_t will be written
* to the address passed into data.
*
* @param[in] client The esp_http_client handle
* @param[out] data A pointer to the pointer that will be set to user_data.
*
* @return
* - ESP_OK
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_http_client_get_user_data(esp_http_client_handle_t client, void **data);

/**
* @brief Set http request user_data.
* The value passed in +data+ will be available during event callbacks.
* No memory management will be performed on the user's behalf.
*
* @param[in] client The esp_http_client handle
* @param[in] data The pointer to the user data
*
* @return
* - ESP_OK
* - ESP_ERR_INVALID_ARG
*/
esp_err_t esp_http_client_set_user_data(esp_http_client_handle_t client, void *data);

/**
* @brief Get HTTP client session errno
*
Expand Down

0 comments on commit bdf8f1c

Please sign in to comment.