Преглед изворни кода

Add user_data accessor and mutator to esp_http_client

Closes: https://github.com/espressif/esp-idf/pull/10715
Andrew Clink пре 3 година
родитељ
комит
82cdcc5de5

+ 22 - 0
components/esp_http_client/esp_http_client.c

@@ -413,6 +413,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;

+ 28 - 0
components/esp_http_client/include/esp_http_client.h

@@ -364,6 +364,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
  *