Hello,

This new version of the patch also enables ecore_con_url to make custom HTTP
requests (such as HEAD, SUBSCRIBE, UNSUBSCRIBE and other obscure stuff).

On Thu, Aug 6, 2009 at 5:59 PM, Andre Dieb <[email protected]>wrote:

> This patch adds to ecore_con_url the ability to insert additional headers
> for POST messages. It is basically two functions (add() and clear()) because
> that's what I need for now, but I think the correct API should be add(),
> del(), clear() (which I'll try to contribute in the near future, but not
> high priority).
>
> PS: one thing you might wonder when reading the patch is why I didn't use
> url_con->headers directly. I did this way because that list gets cleaned up
> (free and =NULL) on the begginning of every send(), and I would lose the
> additional headers. Maybe if this cleanup is moved someplace else, I can use
> url_con->headers directly.
>
> --
> André Dieb Martins
>
> Embedded Systems and Pervasive Computing Lab (Embedded)
> Electrical Engineering Department (DEE)
> Center of Electrical Engineering and Informatics (CEEI)
> Federal University of Campina Grande (UFCG)
>
> Blog: http://genuinepulse.blogspot.com/
>



-- 
André Dieb Martins

Embedded Systems and Pervasive Computing Lab (Embedded)
Electrical Engineering Department (DEE)
Center of Electrical Engineering and Informatics (CEEI)
Federal University of Campina Grande (UFCG)

Blog: http://genuinepulse.blogspot.com/
Index: src/lib/ecore_con/ecore_con_url.c
===================================================================
--- src/lib/ecore_con/ecore_con_url.c	(revision 41572)
+++ src/lib/ecore_con/ecore_con_url.c	(working copy)
@@ -234,6 +234,7 @@
 
    url_con->fd = -1;
    url_con->write_fd = -1;
+   url_con->additional_headers = NULL;
 
    return url_con;
 #else
@@ -243,6 +244,37 @@
 }
 
 /**
+ * Creates and initializes a new Ecore_Con_Url for a custom request (e.g. HEAD,
+ * SUBSCRIBE and other obscure HTTP requests). This object should be used like
+ * one created with ecore_con_url_new().
+ *
+ * @return  NULL on error, a new Ecore_Con_Url on success.
+ * @ingroup Ecore_Con_Url_Group
+ */
+EAPI Ecore_Con_Url *
+ecore_con_url_custom_new(const char *url, const char *custom_request)
+{
+#ifdef HAVE_CURL
+   if (!url) return NULL;
+   if (!custom_request) return NULL;
+
+   Ecore_Con_Url *url_con;
+
+   url_con = ecore_con_url_new(url);
+
+   if (!url_con) return NULL;
+
+   curl_easy_setopt(url_con->curl_easy, CURLOPT_CUSTOMREQUEST, custom_request);
+
+   return url_con;
+#else
+   return NULL;
+   url = NULL;
+   custom_request = NULL;
+#endif
+}
+
+/**
  * Frees the Ecore_Con_Url.
  * @return  FIXME: To be documented.
  * @ingroup Ecore_Con_Url_Group
@@ -276,6 +308,7 @@
      }
    _url_con_list = eina_list_remove(_url_con_list, url_con);
    curl_slist_free_all(url_con->headers);
+   curl_slist_free_all(url_con->additional_headers);
    free(url_con->url);
    free(url_con);
 #else
@@ -337,6 +370,46 @@
 #endif
 }
 
+EAPI void
+ecore_con_url_additional_header_add(Ecore_Con_Url *url_con, const char *key, const char *value)
+{
+#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_additional_header_add");
+	return;
+     }
+
+   char tmp[256];
+   sprintf(tmp, "%s: %s", key, value);
+   url_con->additional_headers = curl_slist_append(url_con->additional_headers, tmp);
+#else
+   return;
+   url_con = NULL;
+   key = NULL;
+   value = NULL;
+#endif
+}
+
+EAPI void
+ecore_con_url_additional_headers_clear(Ecore_Con_Url *url_con)
+{
+#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_additional_headers_clear");
+	return;
+     }
+
+   if (url_con->additional_headers)
+      curl_slist_free_all(url_con->additional_headers);
+   url_con->additional_headers = NULL;
+#else
+   return;
+   url_con = NULL;
+#endif
+}
+
 /**
  * FIXME: To be documented.
  * @return  FIXME: To be documented.
@@ -478,9 +551,18 @@
 	 break;
      }
 
+   /* Additional headers */
+   struct curl_slist *s;
+   for (s = url_con->additional_headers; s; s = s->next)
+     {
+	fprintf(stderr, "ECORE appending header %s\n", s->data);
+	url_con->headers = curl_slist_append(url_con->headers, s->data);
+     }
+
    curl_easy_setopt(url_con->curl_easy, CURLOPT_HTTPHEADER, url_con->headers);
 
    url_con->received = 0;
+   url_con->headers = NULL;
 
    return _ecore_con_url_perform(url_con);
 #else
Index: src/lib/ecore_con/Ecore_Con.h
===================================================================
--- src/lib/ecore_con/Ecore_Con.h	(revision 41572)
+++ src/lib/ecore_con/Ecore_Con.h	(working copy)
@@ -208,9 +208,12 @@
    EAPI int               ecore_con_url_init(void);
    EAPI int               ecore_con_url_shutdown(void);
    EAPI Ecore_Con_Url    *ecore_con_url_new(const char *url);
+   EAPI Ecore_Con_Url    *ecore_con_url_custom_new(const char *url, const char *custom_request);
    EAPI void              ecore_con_url_destroy(Ecore_Con_Url *url_con);
    EAPI void              ecore_con_url_data_set(Ecore_Con_Url *url_con, void *data);
    EAPI void             *ecore_con_url_data_get(Ecore_Con_Url *url_con);
+   EAPI void              ecore_con_url_additional_header_add(Ecore_Con_Url *url_con, const char *key, const char *value);
+   EAPI void              ecore_con_url_additional_headers_clear(Ecore_Con_Url *url_con);
    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);
Index: src/lib/ecore_con/ecore_con_private.h
===================================================================
--- src/lib/ecore_con/ecore_con_private.h	(revision 41572)
+++ src/lib/ecore_con/ecore_con_private.h	(working copy)
@@ -102,6 +102,7 @@
    ECORE_MAGIC;
    CURL              *curl_easy;
    struct curl_slist *headers;
+   struct curl_slist *additional_headers;
    char              *url;
 
    Ecore_Con_Url_Time condition;
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to