From c59d9e2970a9ca78f127e35e78dce808235c6cae Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 12 Jan 2011 00:35:28 +0100 Subject: [PATCH] client: delegate setup of auth to the manager Delegate the configuration of the authentication tokens to the manager object when configured. --- gst/rtsp-server/rtsp-auth.c | 47 +++++++++++++++++++++++++++++++++++ gst/rtsp-server/rtsp-auth.h | 7 ++++++ gst/rtsp-server/rtsp-client.c | 11 +++++--- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/gst/rtsp-server/rtsp-auth.c b/gst/rtsp-server/rtsp-auth.c index ff83c1be91..81855c2f83 100644 --- a/gst/rtsp-server/rtsp-auth.c +++ b/gst/rtsp-server/rtsp-auth.c @@ -36,6 +36,9 @@ static void gst_rtsp_auth_set_property (GObject * object, guint propid, const GValue * value, GParamSpec * pspec); static void gst_rtsp_auth_finalize (GObject * obj); +static gboolean default_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client, + GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request, + GstRTSPMessage * response); static gboolean default_check_method (GstRTSPAuth * auth, GstRTSPMethod method, GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request); @@ -53,6 +56,7 @@ gst_rtsp_auth_class_init (GstRTSPAuthClass * klass) gobject_class->set_property = gst_rtsp_auth_set_property; gobject_class->finalize = gst_rtsp_auth_finalize; + klass->setup_auth = default_setup_auth; klass->check_method = default_check_method; GST_DEBUG_CATEGORY_INIT (rtsp_auth_debug, "rtspauth", 0, "GstRTSPAuth"); @@ -135,6 +139,49 @@ gst_rtsp_auth_set_basic (GstRTSPAuth * auth, const gchar * basic) auth->basic = g_strdup (basic); } +static gboolean +default_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client, + GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request, + GstRTSPMessage * response) +{ + /* we only have Basic for now */ + gst_rtsp_message_add_header (response, GST_RTSP_HDR_WWW_AUTHENTICATE, + "Basic "); + + return TRUE; +} + +/** + * gst_rtsp_auth_setup_auth: + * @auth: a #GstRTSPAuth + * @client: the client + * @uri: the requested uri + * @session: the session + * @request: the request + * @response: the response + * + * Add authentication tokens to @response. + * + * Returns: FALSE if something is wrong. + */ +gboolean +gst_rtsp_auth_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client, + GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request, + GstRTSPMessage * response) +{ + gboolean result = FALSE; + GstRTSPAuthClass *klass; + + klass = GST_RTSP_AUTH_GET_CLASS (auth); + + GST_DEBUG_OBJECT (auth, "setup auth"); + + if (klass->setup_auth) + result = klass->setup_auth (auth, client, uri, session, request, response); + + return result; +} + static gboolean default_check_method (GstRTSPAuth * auth, GstRTSPMethod method, GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPSession * session, diff --git a/gst/rtsp-server/rtsp-auth.h b/gst/rtsp-server/rtsp-auth.h index 85ac733925..786d561e68 100644 --- a/gst/rtsp-server/rtsp-auth.h +++ b/gst/rtsp-server/rtsp-auth.h @@ -56,6 +56,10 @@ struct _GstRTSPAuth { struct _GstRTSPAuthClass { GObjectClass parent_class; + gboolean (*setup_auth) (GstRTSPAuth *auth, GstRTSPClient * client, + GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request, + GstRTSPMessage *response); + gboolean (*check_method) (GstRTSPAuth *auth, GstRTSPMethod method, GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request); @@ -67,6 +71,9 @@ GstRTSPAuth * gst_rtsp_auth_new (void); void gst_rtsp_auth_set_basic (GstRTSPAuth *auth, const gchar * basic); +gboolean gst_rtsp_auth_setup_auth (GstRTSPAuth *auth, GstRTSPClient * client, + GstRTSPUrl * uri, GstRTSPSession * session, + GstRTSPMessage * request, GstRTSPMessage *response); gboolean gst_rtsp_auth_check_method (GstRTSPAuth *auth, GstRTSPMethod method, GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request); diff --git a/gst/rtsp-server/rtsp-client.c b/gst/rtsp-server/rtsp-client.c index 8465a97324..757f08f141 100644 --- a/gst/rtsp-server/rtsp-client.c +++ b/gst/rtsp-server/rtsp-client.c @@ -252,7 +252,7 @@ send_generic_response (GstRTSPClient * client, GstRTSPStatusCode code, send_response (client, NULL, &response); } -static gboolean +static void handle_unauthorized_request (GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request) { @@ -260,11 +260,14 @@ handle_unauthorized_request (GstRTSPClient * client, GstRTSPUrl * uri, gst_rtsp_message_init_response (&response, GST_RTSP_STS_UNAUTHORIZED, gst_rtsp_status_as_text (GST_RTSP_STS_UNAUTHORIZED), request); - gst_rtsp_message_add_header (&response, GST_RTSP_HDR_WWW_AUTHENTICATE, - "Basic "); + + if (client->auth) { + /* and let the authentication manager setup the auth tokens */ + gst_rtsp_auth_setup_auth (client->auth, client, uri, session, request, + &response); + } send_response (client, session, &response); - return; }