auth: add locking

This commit is contained in:
Wim Taymans 2012-11-12 16:03:21 +01:00
parent 06cadebe71
commit e61c84c9bb
2 changed files with 20 additions and 0 deletions

View file

@ -63,6 +63,7 @@ gst_rtsp_auth_class_init (GstRTSPAuthClass * klass)
static void
gst_rtsp_auth_init (GstRTSPAuth * auth)
{
g_mutex_init (&auth->lock);
/* bitwise or of all methods that need authentication */
auth->methods = GST_RTSP_DESCRIBE |
GST_RTSP_ANNOUNCE |
@ -79,6 +80,7 @@ gst_rtsp_auth_finalize (GObject * obj)
GST_INFO ("finalize auth %p", auth);
g_free (auth->basic);
g_mutex_clear (&auth->lock);
G_OBJECT_CLASS (gst_rtsp_auth_parent_class)->finalize (obj);
}
@ -130,8 +132,12 @@ gst_rtsp_auth_new (void)
void
gst_rtsp_auth_set_basic (GstRTSPAuth * auth, const gchar * basic)
{
g_return_if_fail (GST_IS_RTSP_AUTH (auth));
g_mutex_lock (&auth->lock);
g_free (auth->basic);
auth->basic = g_strdup (basic);
g_mutex_unlock (&auth->lock);
}
static gboolean
@ -166,6 +172,10 @@ gst_rtsp_auth_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client,
gboolean result = FALSE;
GstRTSPAuthClass *klass;
g_return_val_if_fail (GST_IS_RTSP_AUTH (auth), FALSE);
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), FALSE);
g_return_val_if_fail (state != NULL, FALSE);
klass = GST_RTSP_AUTH_GET_CLASS (auth);
GST_DEBUG_OBJECT (auth, "setup auth");
@ -197,8 +207,10 @@ default_check_method (GstRTSPAuth * auth, GstRTSPClient * client,
/* parse type */
if (g_ascii_strncasecmp (authorization, "basic ", 6) == 0) {
GST_DEBUG_OBJECT (auth, "check Basic auth");
g_mutex_lock (&auth->lock);
if (auth->basic && strcmp (&authorization[6], auth->basic) == 0)
result = TRUE;
g_mutex_unlock (&auth->lock);
} else if (g_ascii_strncasecmp (authorization, "digest ", 7) == 0) {
GST_DEBUG_OBJECT (auth, "check Digest auth");
/* not implemented yet */
@ -232,6 +244,10 @@ gst_rtsp_auth_check (GstRTSPAuth * auth, GstRTSPClient * client,
gboolean result = FALSE;
GstRTSPAuthClass *klass;
g_return_val_if_fail (GST_IS_RTSP_AUTH (auth), FALSE);
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), FALSE);
g_return_val_if_fail (state != NULL, FALSE);
klass = GST_RTSP_AUTH_GET_CLASS (auth);
GST_DEBUG_OBJECT (auth, "check state");
@ -258,6 +274,9 @@ gst_rtsp_auth_make_basic (const gchar * user, const gchar * pass)
gchar *user_pass;
gchar *result;
g_return_val_if_fail (user != NULL, NULL);
g_return_val_if_fail (pass != NULL, NULL);
user_pass = g_strjoin (":", user, pass, NULL);
result = g_base64_encode ((guchar *) user_pass, strlen (user_pass));
g_free (user_pass);

View file

@ -49,6 +49,7 @@ struct _GstRTSPAuth {
GObject parent;
/*< private >*/
GMutex lock;
gchar *basic;
GstRTSPMethod methods;
};