From b923e09da08e06e737dcff2af3a491e6b14940ce Mon Sep 17 00:00:00 2001 From: Rui Seabra Date: Sun, 9 May 2010 15:06:06 +0000 Subject: [PATCH] This commit implements http auth support; in order to avoid exposing too much of curl's internal workings, I opted to have a safety parameter in order to choose between CURLAUTH_ANY and CURLAUTH_ANYSAFE. SVN revision: 48715 --- legacy/ecore/AUTHORS | 1 + legacy/ecore/src/lib/ecore_con/Ecore_Con.h | 1 + .../ecore/src/lib/ecore_con/ecore_con_url.c | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/legacy/ecore/AUTHORS b/legacy/ecore/AUTHORS index ed6a101fdc..4acdbfbb7e 100644 --- a/legacy/ecore/AUTHORS +++ b/legacy/ecore/AUTHORS @@ -28,3 +28,4 @@ Vincent Torri Lars Munch Andre Dieb Mathieu Taillefumier +Rui Miguel Silva Seabra diff --git a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h index 05efff0fb4..1fb694cd17 100644 --- a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h +++ b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h @@ -222,6 +222,7 @@ extern "C" { EAPI int ecore_con_url_url_set(Ecore_Con_Url *url_con, const char *url); EAPI void ecore_con_url_fd_set(Ecore_Con_Url *url_con, int fd); EAPI int ecore_con_url_received_bytes_get(Ecore_Con_Url *url_con); + EAPI int ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username, const char *password, Eina_Bool safe); EAPI int ecore_con_url_send(Ecore_Con_Url *url_con, const void *data, size_t length, const char *content_type); EAPI void ecore_con_url_time(Ecore_Con_Url *url_con, Ecore_Con_Url_Time condition, time_t tm); diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_url.c b/legacy/ecore/src/lib/ecore_con/ecore_con_url.c index 9d11afb6a5..c3ee928ea9 100644 --- a/legacy/ecore/src/lib/ecore_con/ecore_con_url.c +++ b/legacy/ecore/src/lib/ecore_con/ecore_con_url.c @@ -666,6 +666,41 @@ ecore_con_url_response_headers_get(Ecore_Con_Url *url_con) #endif } +/** + * Sets url_con to use http auth, with given username and password, "safely" or not. + * + * @param url_con Connection object to perform a request on, previously created + * with ecore_con_url_new() or ecore_con_url_custom_new(). + * @param username Username to use in authentication + * @param password Password to use in authentication + * @param safe Whether to use "safer" methods (eg, NOT http basic auth) + * + * @return 1 on success, 0 on error. + * + * @ingroup Ecore_Con_Url_Group + */ +EAPI int +ecore_con_url_httpauth_set(Ecore_Con_Url *url_con, const char *username, const char *password, Eina_Bool safe) +{ +#ifdef HAVE_CURL + if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL)) + { + ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, "ecore_con_url_httpauth_set"); + return 0; + } + if ((username != NULL) && (password != NULL)) + { + if (safe) + curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); + else + curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_easy_setopt(url_con->curl_easy, CURLOPT_USERNAME, username); + curl_easy_setopt(url_con->curl_easy, CURLOPT_PASSWORD, password); + } + return 0; +#endif +} + /** * Sends a request. *