From 72f07c778ea00370f454bda53e2c1178d4a96ff9 Mon Sep 17 00:00:00 2001 From: Wouter Cloetens Date: Tue, 26 Feb 2008 05:36:17 +0000 Subject: [PATCH] Add support for specifying a list of cookies to be passed in the HTTP request. Fixes bug #518722. Original commit message from CVS: Patch by: Wouter Cloetens * ext/soup/gstsouphttpsrc.c: (gst_soup_http_src_class_init), (gst_soup_http_src_init), (gst_soup_http_src_dispose), (gst_soup_http_src_set_property), (gst_soup_http_src_get_property), (gst_soup_http_src_create): * ext/soup/gstsouphttpsrc.h: * tests/check/elements/souphttpsrc.c: (run_test), (GST_START_TEST), (souphttpsrc_suite): Add support for specifying a list of cookies to be passed in the HTTP request. Fixes bug #518722. --- ChangeLog | 14 ++++++++++++++ common | 2 +- ext/soup/gstsouphttpsrc.c | 21 +++++++++++++++++++++ ext/soup/gstsouphttpsrc.h | 1 + tests/check/elements/souphttpsrc.c | 17 +++++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 558bd49..75938e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-02-26 Sebastian Dröge + + Patch by: Wouter Cloetens + + * ext/soup/gstsouphttpsrc.c: (gst_soup_http_src_class_init), + (gst_soup_http_src_init), (gst_soup_http_src_dispose), + (gst_soup_http_src_set_property), (gst_soup_http_src_get_property), + (gst_soup_http_src_create): + * ext/soup/gstsouphttpsrc.h: + * tests/check/elements/souphttpsrc.c: (run_test), (GST_START_TEST), + (souphttpsrc_suite): + Add support for specifying a list of cookies to be passed in + the HTTP request. Fixes bug #518722. + 2008-02-25 Stefan Kost * gst/selector/gstinputselector.c: diff --git a/common b/common index a574e62..1c5138e 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit a574e6214b06fcbdfc00e952e2f3edc06997ee93 +Subproject commit 1c5138efc5679d9eaee66c84dcfabdec5b727493 diff --git a/ext/soup/gstsouphttpsrc.c b/ext/soup/gstsouphttpsrc.c index af50eaa..3e2326d 100644 --- a/ext/soup/gstsouphttpsrc.c +++ b/ext/soup/gstsouphttpsrc.c @@ -117,6 +117,7 @@ enum PROP_USER_AGENT, PROP_AUTOMATIC_REDIRECT, PROP_PROXY, + PROP_COOKIES, PROP_IRADIO_MODE, PROP_IRADIO_NAME, PROP_IRADIO_GENRE, @@ -240,6 +241,9 @@ gst_soup_http_src_class_init (GstSoupHTTPSrcClass * klass) PROP_PROXY, g_param_spec_string ("proxy", "Proxy", "HTTP proxy server URI", "", G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, + PROP_COOKIES, g_param_spec_boxed ("cookies", "Cookies", + "HTTP request cookies", G_TYPE_STRV, G_PARAM_READWRITE)); /* icecast stuff */ g_object_class_install_property (gobject_class, @@ -291,6 +295,7 @@ gst_soup_http_src_init (GstSoupHTTPSrc * src, GstSoupHTTPSrcClass * g_class) src->location = NULL; src->automatic_redirect = TRUE; src->user_agent = g_strdup (DEFAULT_USER_AGENT); + src->cookies = NULL; src->icy_caps = NULL; src->iradio_mode = FALSE; src->iradio_name = NULL; @@ -328,6 +333,7 @@ gst_soup_http_src_dispose (GObject * gobject) soup_uri_free (src->proxy); src->proxy = NULL; } + g_strfreev (src->cookies); g_free (src->iradio_name); src->iradio_name = NULL; g_free (src->iradio_genre); @@ -397,6 +403,10 @@ gst_soup_http_src_set_property (GObject * object, guint prop_id, } break; } + case PROP_COOKIES: + g_strfreev (src->cookies); + src->cookies = g_strdupv (g_value_get_boxed (value)); + break; } done: return; @@ -428,6 +438,9 @@ gst_soup_http_src_get_property (GObject * object, guint prop_id, free (proxy); } break; + case PROP_COOKIES: + g_value_set_boxed (value, g_strdupv (src->cookies)); + break; case PROP_IRADIO_MODE: g_value_set_boolean (value, src->iradio_mode); break; @@ -860,6 +873,14 @@ gst_soup_http_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) soup_message_headers_append (src->msg->request_headers, "icy-metadata", "1"); } + if (src->cookies) { + gchar **cookie; + + for (cookie = src->cookies; *cookie != NULL; cookie++) { + soup_message_headers_append (src->msg->request_headers, "Cookie", + *cookie); + } + } g_signal_connect (src->msg, "got_headers", G_CALLBACK (gst_soup_http_src_got_headers_cb), src); diff --git a/ext/soup/gstsouphttpsrc.h b/ext/soup/gstsouphttpsrc.h index 9e7d81c..5bad737 100644 --- a/ext/soup/gstsouphttpsrc.h +++ b/ext/soup/gstsouphttpsrc.h @@ -51,6 +51,7 @@ struct _GstSoupHTTPSrc { gchar *user_agent; /* User-Agent HTTP header. */ gboolean automatic_redirect; /* Follow redirects. */ SoupURI *proxy; /* HTTP proxy URI. */ + gchar **cookies; /* HTTP request cookies. */ GMainContext *context; /* I/O context. */ GMainLoop *loop; /* Event loop. */ SoupSession *session; /* Async context. */ diff --git a/tests/check/elements/souphttpsrc.c b/tests/check/elements/souphttpsrc.c index 6f5cac0..0fc9c6a 100644 --- a/tests/check/elements/souphttpsrc.c +++ b/tests/check/elements/souphttpsrc.c @@ -32,6 +32,7 @@ static int http_port = 0, https_port = 0; gboolean redirect = TRUE; +static const char **cookies = NULL; static int run_server (int *http_port, int *https_port); @@ -80,6 +81,8 @@ run_test (const char *format, ...) g_free (url); g_object_set (src, "automatic-redirect", redirect, NULL); + if (cookies != NULL) + g_object_set (src, "cookies", cookies, NULL); g_object_set (sink, "signal-handoffs", TRUE, NULL); g_signal_connect (sink, "preroll-handoff", G_CALLBACK (handoff_cb), &buf); @@ -185,6 +188,19 @@ GST_START_TEST (test_https) GST_END_TEST; +GST_START_TEST (test_cookies) +{ + static const char *biscotti[] = { "delacre=yummie", "koekje=lu", NULL }; + int rc; + + cookies = biscotti; + rc = run_test ("http://127.0.0.1:%d/", http_port); + cookies = NULL; + fail_unless (rc == 0); +} + +GST_END_TEST; + GST_START_TEST (test_icy_stream) { GstElement *pipe, *src, *sink; @@ -276,6 +292,7 @@ souphttpsrc_suite (void) tcase_add_test (tc_chain, test_redirect_no); tcase_add_test (tc_chain, test_not_found); tcase_add_test (tc_chain, test_forbidden); + tcase_add_test (tc_chain, test_cookies); tcase_add_test (tc_chain, test_icy_stream); return s; -- 2.7.4