client: map URL to path in requests

This commit is contained in:
Wim Taymans 2013-09-16 17:16:49 +02:00
parent 952aa309dc
commit e3fded2cec

View file

@ -740,18 +740,20 @@ handle_teardown_request (GstRTSPClient * client, GstRTSPContext * ctx)
GstRTSPSession *session; GstRTSPSession *session;
GstRTSPSessionMedia *sessmedia; GstRTSPSessionMedia *sessmedia;
GstRTSPStatusCode code; GstRTSPStatusCode code;
const gchar *path; gchar *path;
gint matched; gint matched;
if (!ctx->session) if (!(session = ctx->session))
goto no_session; goto no_session;
session = ctx->session;
if (!ctx->uri) if (!ctx->uri)
goto no_uri; goto no_uri;
path = ctx->uri->abspath; if (!priv->mount_points)
goto no_mount_points;
if (!(path = gst_rtsp_mount_points_make_path (priv->mount_points, ctx->uri)))
goto no_path;
/* get a handle to the configuration of the media in the session */ /* get a handle to the configuration of the media in the session */
sessmedia = gst_rtsp_session_get_media (session, path, &matched); sessmedia = gst_rtsp_session_get_media (session, path, &matched);
@ -762,6 +764,8 @@ handle_teardown_request (GstRTSPClient * client, GstRTSPContext * ctx)
if (path[matched] != '\0') if (path[matched] != '\0')
goto no_aggregate; goto no_aggregate;
g_free (path);
ctx->sessmedia = sessmedia; ctx->sessmedia = sessmedia;
/* we emit the signal before closing the connection */ /* we emit the signal before closing the connection */
@ -804,15 +808,29 @@ no_uri:
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx); send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
return FALSE; return FALSE;
} }
no_mount_points:
{
GST_ERROR ("client %p: no mount points configured", client);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE;
}
no_path:
{
GST_ERROR ("client %p: can't find path for url", client);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE;
}
not_found: not_found:
{ {
GST_ERROR ("client %p: no media for uri", client); GST_ERROR ("client %p: no media for uri", client);
g_free (path);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE; return FALSE;
} }
no_aggregate: no_aggregate:
{ {
GST_ERROR ("client %p: no aggregate path %s", client, path); GST_ERROR ("client %p: no aggregate path %s", client, path);
g_free (path);
send_generic_response (client, send_generic_response (client,
GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx); GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
return FALSE; return FALSE;
@ -916,11 +934,12 @@ bad_request:
static gboolean static gboolean
handle_pause_request (GstRTSPClient * client, GstRTSPContext * ctx) handle_pause_request (GstRTSPClient * client, GstRTSPContext * ctx)
{ {
GstRTSPClientPrivate *priv = client->priv;
GstRTSPSession *session; GstRTSPSession *session;
GstRTSPSessionMedia *sessmedia; GstRTSPSessionMedia *sessmedia;
GstRTSPStatusCode code; GstRTSPStatusCode code;
GstRTSPState rtspstate; GstRTSPState rtspstate;
const gchar *path; gchar *path;
gint matched; gint matched;
if (!(session = ctx->session)) if (!(session = ctx->session))
@ -929,7 +948,11 @@ handle_pause_request (GstRTSPClient * client, GstRTSPContext * ctx)
if (!ctx->uri) if (!ctx->uri)
goto no_uri; goto no_uri;
path = ctx->uri->abspath; if (!priv->mount_points)
goto no_mount_points;
if (!(path = gst_rtsp_mount_points_make_path (priv->mount_points, ctx->uri)))
goto no_path;
/* get a handle to the configuration of the media in the session */ /* get a handle to the configuration of the media in the session */
sessmedia = gst_rtsp_session_get_media (session, path, &matched); sessmedia = gst_rtsp_session_get_media (session, path, &matched);
@ -939,6 +962,8 @@ handle_pause_request (GstRTSPClient * client, GstRTSPContext * ctx)
if (path[matched] != '\0') if (path[matched] != '\0')
goto no_aggregate; goto no_aggregate;
g_free (path);
ctx->sessmedia = sessmedia; ctx->sessmedia = sessmedia;
rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia); rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
@ -980,15 +1005,29 @@ no_uri:
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx); send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
return FALSE; return FALSE;
} }
no_mount_points:
{
GST_ERROR ("client %p: no mount points configured", client);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE;
}
no_path:
{
GST_ERROR ("client %p: can't find path for url", client);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE;
}
not_found: not_found:
{ {
GST_ERROR ("client %p: no media for uri", client); GST_ERROR ("client %p: no media for uri", client);
g_free (path);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE; return FALSE;
} }
no_aggregate: no_aggregate:
{ {
GST_ERROR ("client %p: no aggregate path %s", client, path); GST_ERROR ("client %p: no aggregate path %s", client, path);
g_free (path);
send_generic_response (client, send_generic_response (client,
GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx); GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
return FALSE; return FALSE;
@ -1005,6 +1044,7 @@ invalid_state:
static gboolean static gboolean
handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx) handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx)
{ {
GstRTSPClientPrivate *priv = client->priv;
GstRTSPSession *session; GstRTSPSession *session;
GstRTSPSessionMedia *sessmedia; GstRTSPSessionMedia *sessmedia;
GstRTSPMedia *media; GstRTSPMedia *media;
@ -1016,7 +1056,7 @@ handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx)
GstRTSPResult res; GstRTSPResult res;
GstRTSPState rtspstate; GstRTSPState rtspstate;
GstRTSPRangeUnit unit = GST_RTSP_RANGE_NPT; GstRTSPRangeUnit unit = GST_RTSP_RANGE_NPT;
const gchar *path; gchar *path;
gint matched; gint matched;
if (!(session = ctx->session)) if (!(session = ctx->session))
@ -1025,7 +1065,11 @@ handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx)
if (!ctx->uri) if (!ctx->uri)
goto no_uri; goto no_uri;
path = ctx->uri->abspath; if (!priv->mount_points)
goto no_mount_points;
if (!(path = gst_rtsp_mount_points_make_path (priv->mount_points, ctx->uri)))
goto no_path;
/* get a handle to the configuration of the media in the session */ /* get a handle to the configuration of the media in the session */
sessmedia = gst_rtsp_session_get_media (session, path, &matched); sessmedia = gst_rtsp_session_get_media (session, path, &matched);
@ -1035,6 +1079,8 @@ handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx)
if (path[matched] != '\0') if (path[matched] != '\0')
goto no_aggregate; goto no_aggregate;
g_free (path);
ctx->sessmedia = sessmedia; ctx->sessmedia = sessmedia;
ctx->media = media = gst_rtsp_session_media_get_media (sessmedia); ctx->media = media = gst_rtsp_session_media_get_media (sessmedia);
@ -1136,15 +1182,29 @@ no_uri:
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx); send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
return FALSE; return FALSE;
} }
no_mount_points:
{
GST_ERROR ("client %p: no mount points configured", client);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE;
}
no_path:
{
GST_ERROR ("client %p: can't find path for url", client);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE;
}
not_found: not_found:
{ {
GST_ERROR ("client %p: media not found", client); GST_ERROR ("client %p: media not found", client);
g_free (path);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE; return FALSE;
} }
no_aggregate: no_aggregate:
{ {
GST_ERROR ("client %p: no aggregate path %s", client, path); GST_ERROR ("client %p: no aggregate path %s", client, path);
g_free (path);
send_generic_response (client, send_generic_response (client,
GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx); GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
return FALSE; return FALSE;
@ -1380,11 +1440,14 @@ handle_setup_request (GstRTSPClient * client, GstRTSPContext * ctx)
gchar *path, *control; gchar *path, *control;
gint matched; gint matched;
if (!ctx->uri) if (!(uri = ctx->uri))
goto no_uri; goto no_uri;
uri = ctx->uri; if (!priv->mount_points)
path = uri->abspath; goto no_mount_points;
if (!(path = gst_rtsp_mount_points_make_path (priv->mount_points, uri)))
goto no_path;
/* parse the transport */ /* parse the transport */
res = res =
@ -1422,7 +1485,7 @@ handle_setup_request (GstRTSPClient * client, GstRTSPContext * ctx)
if (media == NULL) if (media == NULL)
goto media_not_found; goto media_not_found;
/* path is what matched. We can modify the parsed uri in place */ /* path is what matched */
path[matched] = '\0'; path[matched] = '\0';
/* control is remainder */ /* control is remainder */
control = &path[matched + 1]; control = &path[matched + 1];
@ -1461,6 +1524,7 @@ handle_setup_request (GstRTSPClient * client, GstRTSPContext * ctx)
} else { } else {
g_object_unref (media); g_object_unref (media);
} }
g_free (path);
ctx->sessmedia = sessmedia; ctx->sessmedia = sessmedia;
@ -1530,27 +1594,43 @@ no_uri:
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx); send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
return FALSE; return FALSE;
} }
no_mount_points:
{
GST_ERROR ("client %p: no mount points configured", client);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE;
}
no_path:
{
GST_ERROR ("client %p: can't find path for url", client);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE;
}
no_transport: no_transport:
{ {
GST_ERROR ("client %p: no transport", client); GST_ERROR ("client %p: no transport", client);
g_free (path);
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx); send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
return FALSE; return FALSE;
} }
no_pool: no_pool:
{ {
GST_ERROR ("client %p: no session pool configured", client); GST_ERROR ("client %p: no session pool configured", client);
g_free (path);
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx); send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
return FALSE; return FALSE;
} }
media_not_found: media_not_found:
{ {
GST_ERROR ("client %p: media '%s' not found", client, path); GST_ERROR ("client %p: media '%s' not found", client, path);
g_free (path);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
return FALSE; return FALSE;
} }
stream_not_found: stream_not_found:
{ {
GST_ERROR ("client %p: stream '%s' not found", client, control); GST_ERROR ("client %p: stream '%s' not found", client, control);
g_free (path);
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
g_object_unref (media); g_object_unref (media);
return FALSE; return FALSE;
@ -1558,6 +1638,7 @@ stream_not_found:
service_unavailable: service_unavailable:
{ {
GST_ERROR ("client %p: can't create session", client); GST_ERROR ("client %p: can't create session", client);
g_free (path);
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx); send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
g_object_unref (media); g_object_unref (media);
return FALSE; return FALSE;
@ -1566,6 +1647,7 @@ sessmedia_unavailable:
{ {
GST_ERROR ("client %p: can't create session media", client); GST_ERROR ("client %p: can't create session media", client);
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx); send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
g_free (path);
g_object_unref (media); g_object_unref (media);
g_object_unref (session); g_object_unref (session);
return FALSE; return FALSE;