client: delegate setup of auth to the manager
authorWim Taymans <wim.taymans@collabora.co.uk>
Tue, 11 Jan 2011 23:35:28 +0000 (00:35 +0100)
committerWim Taymans <wim.taymans@gmail.com>
Tue, 11 Jan 2011 23:35:28 +0000 (00:35 +0100)
Delegate the configuration of the authentication tokens to the manager object
when configured.

gst/rtsp-server/rtsp-auth.c
gst/rtsp-server/rtsp-auth.h
gst/rtsp-server/rtsp-client.c

index ff83c1b..81855c2 100644 (file)
@@ -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");
@@ -136,6 +140,49 @@ gst_rtsp_auth_set_basic (GstRTSPAuth * auth, const gchar * 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,
     GstRTSPMessage * request)
index 85ac733..786d561 100644 (file)
@@ -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);
index 8465a97..757f08f 100644 (file)
@@ -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;
 }