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
This commit is contained in:
Rui Seabra 2010-05-09 15:06:06 +00:00
parent 798e88594f
commit b923e09da0
3 changed files with 37 additions and 0 deletions

View File

@ -28,3 +28,4 @@ Vincent Torri <vincent.torri@gmail.com>
Lars Munch <lars@segv.dk>
Andre Dieb <andre.dieb@gmail.com>
Mathieu Taillefumier <mathieu.taillefumier@free.fr>
Rui Miguel Silva Seabra <rms@1407.org>

View File

@ -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);

View File

@ -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.
*