This commit implements http auth support; in order to avoid exposing too much of...
authorrui <rui@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sun, 9 May 2010 15:06:06 +0000 (15:06 +0000)
committerrui <rui@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sun, 9 May 2010 15:06:06 +0000 (15:06 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/ecore@48715 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

AUTHORS
src/lib/ecore_con/Ecore_Con.h
src/lib/ecore_con/ecore_con_url.c

diff --git a/AUTHORS b/AUTHORS
index ed6a101..4acdbfb 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -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>
index 05efff0..1fb694c 100644 (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);
 
index 9d11afb..c3ee928 100644 (file)
@@ -667,6 +667,41 @@ ecore_con_url_response_headers_get(Ecore_Con_Url *url_con)
 }
 
 /**
+ * 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.
  *
  * @param url_con Connection object to perform a request on, previously created