Hello,

The attached patch would seem to add http basic auth to ecore_con_url

I'm still testing it, but I'd like to know the opinion of others on its
addition. I'm still a bit too shy to commit real code in core EFL
libraries :)

Best,
Rui
Index: AUTHORS
===================================================================
--- AUTHORS     (revision 46658)
+++ AUTHORS     (working copy)
@@ -28,3 +28,4 @@
 Lars Munch <l...@segv.dk>
 Andre Dieb <andre.d...@gmail.com>
 Mathieu Taillefumier <mathieu.taillefum...@free.fr>
+Rui Miguel Silva Seabra <r...@1407.org>
Index: src/lib/ecore_con/ecore_con_url.c
===================================================================
--- src/lib/ecore_con/ecore_con_url.c   (revision 46658)
+++ src/lib/ecore_con/ecore_con_url.c   (working copy)
@@ -660,6 +660,43 @@
 }
 
 /**
+ * Sets url_con to use basic auth with given username and password.
+ *
+ * @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
+ *
+ * @return 1 on success, 0 on error.
+ *
+ * @ingroup Ecore_Con_Url_Group
+ */
+EAPI int
+ecore_con_url_auth_basic_set(Ecore_Con_Url *url_con, char *username, char 
*password)
+{
+#ifdef HAVE_CURL
+   char *userpwd=NULL;
+   int res=0;
+
+   if (!ECORE_MAGIC_CHECK(url_con, ECORE_MAGIC_CON_URL))
+     {
+       ECORE_MAGIC_FAIL(url_con, ECORE_MAGIC_CON_URL, 
"ecore_con_url_auth_basic_set");
+       return 0;
+     }
+   if(username != NULL && password != NULL)
+     {
+       res = asprintf(&userpwd, "%s:%s", username, password);
+       if(res != -1)
+         {
+            curl_easy_setopt(url_con->curl_easy, CURLOPT_USERPWD, userpwd);
+            return 1;
+         }
+     }
+   return 0;
+#endif
+}
+
+/**
  * Sends a request.
  *
  * @param url_con Connection object to perform a request on, previously created
Index: src/lib/ecore_con/Ecore_Con.h
===================================================================
--- src/lib/ecore_con/Ecore_Con.h       (revision 46658)
+++ src/lib/ecore_con/Ecore_Con.h       (working copy)
@@ -222,6 +222,7 @@
    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_auth_basic_set(Ecore_Con_Url *url_con, 
char *username, char *password);
    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);
 
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to