PROP_USER_AGENT,
PROP_AUTOMATIC_REDIRECT,
PROP_PROXY,
+ PROP_USER_ID,
+ PROP_USER_PW,
+ PROP_PROXY_ID,
+ PROP_PROXY_PW,
PROP_COOKIES,
PROP_IRADIO_MODE,
PROP_IRADIO_NAME,
GstSoupHTTPSrc * src);
static void gst_soup_http_src_finished_cb (SoupMessage * msg,
GstSoupHTTPSrc * src);
-
+static void gst_soup_http_src_authenticate_cb (SoupSession * session,
+ SoupMessage * msg, SoupAuth * auth, gboolean retrying,
+ GstSoupHTTPSrc * src);
static void
_do_init (GType type)
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));
- g_object_class_install_property (gobject_class,
- PROP_IS_LIVE,
- g_param_spec_boolean ("is-live", "is-live",
- "Act like a live source", FALSE, G_PARAM_READWRITE));
+ PROP_USER_ID,
+ g_param_spec_string ("user-id", "user-id",
+ "HTTP location URI user id for authentication", "",
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_USER_PW,
+ g_param_spec_string ("user-pw", "user-pw",
+ "HTTP location URI user password for authentication", "",
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_PROXY_ID,
+ g_param_spec_string ("proxy-id", "proxy-id",
+ "HTTP proxy URI user id for authentication", "", G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_PROXY_PW,
+ g_param_spec_string ("proxy-pw", "proxy-pw",
+ "HTTP proxy URI user password for authentication", "",
+ 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));
+ g_object_class_install_property (gobject_class, PROP_IS_LIVE,
+ g_param_spec_boolean ("is-live", "is-live", "Act like a live source",
+ FALSE, G_PARAM_READWRITE));
/* icecast stuff */
g_object_class_install_property (gobject_class,
src->location = NULL;
src->automatic_redirect = TRUE;
src->user_agent = g_strdup (DEFAULT_USER_AGENT);
+ src->user_id = NULL;
+ src->user_pw = NULL;
+ src->proxy_id = NULL;
+ src->proxy_pw = NULL;
src->cookies = NULL;
src->icy_caps = NULL;
src->iradio_mode = FALSE;
soup_uri_free (src->proxy);
src->proxy = NULL;
}
+ g_free (src->user_id);
+ src->user_id = NULL;
+ g_free (src->user_pw);
+ src->user_pw = NULL;
+ g_free (src->proxy_id);
+ src->proxy_id = NULL;
+ g_free (src->proxy_pw);
+ src->proxy_pw = NULL;
g_strfreev (src->cookies);
g_free (src->iradio_name);
src->iradio_name = NULL;
case PROP_IS_LIVE:
gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
break;
+ case PROP_USER_ID:
+ if (src->user_id)
+ g_free (src->user_id);
+ src->user_id = g_value_dup_string (value);
+ break;
+ case PROP_USER_PW:
+ if (src->user_pw)
+ g_free (src->user_pw);
+ src->user_pw = g_value_dup_string (value);
+ break;
+ case PROP_PROXY_ID:
+ if (src->proxy_id)
+ g_free (src->proxy_id);
+ src->proxy_id = g_value_dup_string (value);
+ break;
+ case PROP_PROXY_PW:
+ if (src->proxy_pw)
+ g_free (src->proxy_pw);
+ src->proxy_pw = g_value_dup_string (value);
+ break;
}
done:
return;
case PROP_IRADIO_TITLE:
g_value_set_string (value, src->iradio_title);
break;
+ case PROP_USER_ID:
+ g_value_set_string (value, src->user_id);
+ break;
+ case PROP_USER_PW:
+ g_value_set_string (value, src->user_pw);
+ break;
+ case PROP_PROXY_ID:
+ g_value_set_string (value, src->proxy_id);
+ break;
+ case PROP_PROXY_PW:
+ g_value_set_string (value, src->proxy_pw);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
static void
+gst_soup_http_src_authenticate_cb (SoupSession * session, SoupMessage * msg,
+ SoupAuth * auth, gboolean retrying, GstSoupHTTPSrc * src)
+{
+ if (!retrying) {
+ /* First time authentication only, if we fail and are called again with retry true fall through */
+ if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) {
+ soup_auth_authenticate (auth, src->user_id, src->user_pw);
+ } else if (msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
+ soup_auth_authenticate (auth, src->proxy_id, src->proxy_pw);
+ }
+ }
+}
+
+static void
gst_soup_http_src_got_headers_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
{
const char *value;
return FALSE;
}
+ g_signal_connect (src->session, "authenticate",
+ G_CALLBACK (gst_soup_http_src_authenticate_cb), src);
return TRUE;
}
#include <libsoup/soup-address.h>
#include <libsoup/soup-message.h>
#include <libsoup/soup-server.h>
+#include <libsoup/soup-auth-domain.h>
+#include <libsoup/soup-auth-domain-basic.h>
+#include <libsoup/soup-auth-domain-digest.h>
#include <gst/check/gstcheck.h>
static int http_port = 0, https_port = 0;
static const char **cookies = NULL;
+/* Variables for authentication tests */
+static const char *user_id = NULL;
+static const char *user_pw = NULL;
+static const char *good_user = "good_user";
+static const char *bad_user = "bad_user";
+static const char *good_pw = "good_pw";
+static const char *bad_pw = "bad_pw";
+static const char *realm = "SOUPHTTPSRC_REALM";
+static const char *basic_auth_path = "/basic_auth";
+static const char *digest_auth_path = "/digest_auth";
+
static int run_server (int *http_port, int *https_port);
*p_outbuf = gst_buffer_ref (buf);
}
+static gboolean
+basic_auth_cb (SoupAuthDomain * domain, SoupMessage * msg,
+ const char *username, const char *password, gpointer user_data)
+{
+ /* There is only one good login for testing */
+ return (strcmp (username, good_user) == 0)
+ && (strcmp (password, good_pw) == 0);
+}
+
+
+static char *
+digest_auth_cb (SoupAuthDomain * domain, SoupMessage * msg,
+ const char *username, gpointer user_data)
+{
+ /* There is only one good login for testing */
+ if (strcmp (username, good_user) == 0)
+ return soup_auth_domain_digest_encode_password (good_user, realm, good_pw);
+ return NULL;
+}
+
int
run_test (const char *format, ...)
{
g_object_set (sink, "signal-handoffs", TRUE, NULL);
g_signal_connect (sink, "preroll-handoff", G_CALLBACK (handoff_cb), &buf);
+ if (user_id != NULL)
+ g_object_set (src, "user-id", user_id, NULL);
+ if (user_pw != NULL)
+ g_object_set (src, "user-pw", user_pw, NULL);
+
ret = gst_element_set_state (pipe, GST_STATE_PAUSED);
if (ret != GST_STATE_CHANGE_ASYNC) {
GST_DEBUG ("failed to start up soup http src, ret = %d", ret);
rc = 404;
else if (g_str_has_suffix (err->message, "Forbidden"))
rc = 403;
+ else if (g_str_has_suffix (err->message, "Unauthorized"))
+ rc = 401;
else if (g_str_has_suffix (err->message, "Found"))
rc = 302;
GST_INFO ("debug: %s", debug);
GST_END_TEST;
+GST_START_TEST (test_good_user_basic_auth)
+{
+ int res;
+
+ user_id = good_user;
+ user_pw = good_pw;
+ res = run_test ("http://127.0.0.1:%d%s", http_port, basic_auth_path);
+ GST_DEBUG ("Basic Auth user %s password %s res = %d", user_id, user_pw, res);
+ user_id = user_pw = NULL;
+ fail_unless (res == 0);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_bad_user_basic_auth)
+{
+ int res;
+
+ user_id = bad_user;
+ user_pw = good_pw;
+ res = run_test ("http://127.0.0.1:%d%s", http_port, basic_auth_path);
+ GST_DEBUG ("Basic Auth user %s password %s res = %d", user_id, user_pw, res);
+ user_id = user_pw = NULL;
+ fail_unless (res == 401);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_bad_password_basic_auth)
+{
+ int res;
+
+ user_id = good_user;
+ user_pw = bad_pw;
+ res = run_test ("http://127.0.0.1:%d%s", http_port, basic_auth_path);
+ GST_DEBUG ("Basic Auth user %s password %s res = %d", user_id, user_pw, res);
+ user_id = user_pw = NULL;
+ fail_unless (res == 401);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_good_user_digest_auth)
+{
+ int res;
+
+ user_id = good_user;
+ user_pw = good_pw;
+ res = run_test ("http://127.0.0.1:%d%s", http_port, digest_auth_path);
+ GST_DEBUG ("Digest Auth user %s password %s res = %d", user_id, user_pw, res);
+ user_id = user_pw = NULL;
+ fail_unless (res == 0);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_bad_user_digest_auth)
+{
+ int res;
+
+ user_id = bad_user;
+ user_pw = good_pw;
+ res = run_test ("http://127.0.0.1:%d%s", http_port, digest_auth_path);
+ GST_DEBUG ("Digest Auth user %s password %s res = %d", user_id, user_pw, res);
+ user_id = user_pw = NULL;
+ fail_unless (res == 401);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_bad_password_digest_auth)
+{
+ int res;
+
+ user_id = good_user;
+ user_pw = bad_pw;
+ res = run_test ("http://127.0.0.1:%d%s", http_port, digest_auth_path);
+ GST_DEBUG ("Digest Auth user %s password %s res = %d", user_id, user_pw, res);
+ user_id = user_pw = NULL;
+ fail_unless (res == 401);
+}
+
+GST_END_TEST;
+
static gboolean icy_caps = FALSE;
static void
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_good_user_basic_auth);
+ tcase_add_test (tc_chain, test_bad_user_basic_auth);
+ tcase_add_test (tc_chain, test_bad_password_basic_auth);
+ tcase_add_test (tc_chain, test_good_user_digest_auth);
+ tcase_add_test (tc_chain, test_bad_user_digest_auth);
+ tcase_add_test (tc_chain, test_bad_password_digest_auth);
suite_add_tcase (s, tc_internet);
tcase_set_timeout (tc_internet, 250);
static int server_running = 0;
+ SoupAuthDomain *domain = NULL;
+
if (server_running)
return 0;
server_running = 1;
*http_port = soup_server_get_port (server);
GST_INFO ("HTTP server listening on port %d", *http_port);
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
+ domain = soup_auth_domain_basic_new (SOUP_AUTH_DOMAIN_REALM, realm,
+ SOUP_AUTH_DOMAIN_BASIC_AUTH_CALLBACK, basic_auth_cb,
+ SOUP_AUTH_DOMAIN_ADD_PATH, basic_auth_path, NULL);
+ soup_server_add_auth_domain (server, domain);
+ g_object_unref (domain);
+ domain = soup_auth_domain_digest_new (SOUP_AUTH_DOMAIN_REALM, realm,
+ SOUP_AUTH_DOMAIN_DIGEST_AUTH_CALLBACK, digest_auth_cb,
+ SOUP_AUTH_DOMAIN_ADD_PATH, digest_auth_path, NULL);
+ soup_server_add_auth_domain (server, domain);
+ g_object_unref (domain);
soup_server_run_async (server);
if (ssl_cert_file && ssl_key_file) {