mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-13 12:51:16 +00:00
client: delegate setup of auth to the manager
Delegate the configuration of the authentication tokens to the manager object when configured.
This commit is contained in:
parent
5fb5f75020
commit
c59d9e2970
3 changed files with 61 additions and 4 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue