From 952aa309dcfc8389fc51b119d984407d7f75f34f Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 16 Sep 2013 16:47:40 +0200 Subject: [PATCH] mount-points: make vmethod to make path from uri Make a vmethod to transform an url into a path. The path is then used to lookup the factory. This makes it possible to also use other bits of the url, such as the query parameters, to locate the factory. --- gst/rtsp-server/rtsp-client.c | 16 +++++++++++- gst/rtsp-server/rtsp-mount-points.c | 39 +++++++++++++++++++++++++++++ gst/rtsp-server/rtsp-mount-points.h | 6 +++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/gst/rtsp-server/rtsp-client.c b/gst/rtsp-server/rtsp-client.c index 4ea5289843..c82d4a2479 100644 --- a/gst/rtsp-server/rtsp-client.c +++ b/gst/rtsp-server/rtsp-client.c @@ -491,7 +491,8 @@ find_media (GstRTSPClient * client, GstRTSPContext * ctx, gint * matched) if (!priv->mount_points) goto no_mount_points; - path = ctx->uri->abspath; + if (!(path = gst_rtsp_mount_points_make_path (priv->mount_points, ctx->uri))) + goto no_path; /* find the longest matching factory for the uri first */ if (!(factory = gst_rtsp_mount_points_match (priv->mount_points, @@ -552,6 +553,7 @@ find_media (GstRTSPClient * client, GstRTSPContext * ctx, gint * matched) g_object_unref (factory); ctx->factory = NULL; + g_free (path); if (media) g_object_ref (media); @@ -565,20 +567,29 @@ no_mount_points: send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx); return NULL; } +no_path: + { + GST_ERROR ("client %p: can't find path for url", client); + send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx); + return NULL; + } no_factory: { GST_ERROR ("client %p: no factory for uri %s", client, path); + g_free (path); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx); return NULL; } no_factory_access: { GST_ERROR ("client %p: not authorized to see factory uri %s", client, path); + g_free (path); return NULL; } not_authorized: { GST_ERROR ("client %p: not authorized for factory uri %s", client, path); + g_free (path); return NULL; } no_media: @@ -587,6 +598,7 @@ no_media: send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx); g_object_unref (factory); ctx->factory = NULL; + g_free (path); return NULL; } no_thread: @@ -597,6 +609,7 @@ no_thread: ctx->media = NULL; g_object_unref (factory); ctx->factory = NULL; + g_free (path); return NULL; } no_prepare: @@ -607,6 +620,7 @@ no_prepare: ctx->media = NULL; g_object_unref (factory); ctx->factory = NULL; + g_free (path); return NULL; } } diff --git a/gst/rtsp-server/rtsp-mount-points.c b/gst/rtsp-server/rtsp-mount-points.c index 2cf09ae34e..de23bc13c6 100644 --- a/gst/rtsp-server/rtsp-mount-points.c +++ b/gst/rtsp-server/rtsp-mount-points.c @@ -102,6 +102,8 @@ G_DEFINE_TYPE (GstRTSPMountPoints, gst_rtsp_mount_points, G_TYPE_OBJECT); GST_DEBUG_CATEGORY_STATIC (rtsp_media_debug); #define GST_CAT_DEFAULT rtsp_media_debug +static gchar *default_make_path (GstRTSPMountPoints * mounts, + const GstRTSPUrl * url); static void gst_rtsp_mount_points_finalize (GObject * obj); static void @@ -115,6 +117,8 @@ gst_rtsp_mount_points_class_init (GstRTSPMountPointsClass * klass) gobject_class->finalize = gst_rtsp_mount_points_finalize; + klass->make_path = default_make_path; + GST_DEBUG_CATEGORY_INIT (rtsp_media_debug, "rtspmountpoints", 0, "GstRTSPMountPoints"); } @@ -164,6 +168,41 @@ gst_rtsp_mount_points_new (void) return result; } +static gchar * +default_make_path (GstRTSPMountPoints * mounts, const GstRTSPUrl * url) +{ + return g_strdup (url->abspath); +} + +/** + * gst_rtsp_mount_points_make_path: + * @mounts: a #GstRTSPMountPoints + * @url: a #GstRTSPUrl + * + * Make a path string from @url. + * + * Returns: a path string for @url, g_free() after usage. + */ +gchar * +gst_rtsp_mount_points_make_path (GstRTSPMountPoints * mounts, + const GstRTSPUrl * url) +{ + GstRTSPMountPointsClass *klass; + gchar *result; + + g_return_val_if_fail (GST_IS_RTSP_MOUNT_POINTS (mounts), NULL); + g_return_val_if_fail (url != NULL, NULL); + + klass = GST_RTSP_MOUNT_POINTS_GET_CLASS (mounts); + + if (klass->make_path) + result = klass->make_path (mounts, url); + else + result = NULL; + + return result; +} + static gboolean has_prefix (DataItem * str, DataItem * prefix) { diff --git a/gst/rtsp-server/rtsp-mount-points.h b/gst/rtsp-server/rtsp-mount-points.h index 3f9b5b7b2f..18a691a133 100644 --- a/gst/rtsp-server/rtsp-mount-points.h +++ b/gst/rtsp-server/rtsp-mount-points.h @@ -53,11 +53,15 @@ struct _GstRTSPMountPoints { /** * GstRTSPMountPointsClass: + * @make_path: make a path from the given url. * * The class for the media mounts object. */ struct _GstRTSPMountPointsClass { GObjectClass parent_class; + + gchar * (*make_path) (GstRTSPMountPoints *mounts, + const GstRTSPUrl *url); }; GType gst_rtsp_mount_points_get_type (void); @@ -65,6 +69,8 @@ GType gst_rtsp_mount_points_get_type (void); /* creating a mount points */ GstRTSPMountPoints * gst_rtsp_mount_points_new (void); +gchar * gst_rtsp_mount_points_make_path (GstRTSPMountPoints *mounts, + const GstRTSPUrl * url); /* finding a media factory */ GstRTSPMediaFactory * gst_rtsp_mount_points_match (GstRTSPMountPoints *mounts, const gchar *path,