rtsp-server: Pass ClientState structure arround

Pass the collected information for the ongoing request in a GstRTSPClientState
structure that we can then pass around to simplify the method arguments. This
will also be handy when we implement logging functionality.
This commit is contained in:
Wim Taymans 2011-01-12 13:16:08 +01:00
parent 9ea0346d97
commit 5773df1d52
6 changed files with 186 additions and 156 deletions

View file

@ -37,11 +37,9 @@ static void gst_rtsp_auth_set_property (GObject * object, guint propid,
static void gst_rtsp_auth_finalize (GObject * obj); static void gst_rtsp_auth_finalize (GObject * obj);
static gboolean default_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client, static gboolean default_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client,
GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request, GstRTSPClientState * state);
GstRTSPMessage * response); static gboolean default_check_method (GstRTSPAuth * auth,
static gboolean default_check_method (GstRTSPAuth * auth, GstRTSPMethod method, GstRTSPClient * client, GstRTSPClientState * state);
GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPSession * session,
GstRTSPMessage * request);
G_DEFINE_TYPE (GstRTSPAuth, gst_rtsp_auth, G_TYPE_OBJECT); G_DEFINE_TYPE (GstRTSPAuth, gst_rtsp_auth, G_TYPE_OBJECT);
@ -142,11 +140,13 @@ gst_rtsp_auth_set_basic (GstRTSPAuth * auth, const gchar * basic)
static gboolean static gboolean
default_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client, default_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client,
GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request, GstRTSPClientState * state)
GstRTSPMessage * response)
{ {
if (state->response == NULL)
return FALSE;
/* we only have Basic for now */ /* we only have Basic for now */
gst_rtsp_message_add_header (response, GST_RTSP_HDR_WWW_AUTHENTICATE, gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_WWW_AUTHENTICATE,
"Basic "); "Basic ");
return TRUE; return TRUE;
@ -167,8 +167,7 @@ default_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client,
*/ */
gboolean gboolean
gst_rtsp_auth_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client, gst_rtsp_auth_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client,
GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request, GstRTSPClientState * state)
GstRTSPMessage * response)
{ {
gboolean result = FALSE; gboolean result = FALSE;
GstRTSPAuthClass *klass; GstRTSPAuthClass *klass;
@ -178,26 +177,25 @@ gst_rtsp_auth_setup_auth (GstRTSPAuth * auth, GstRTSPClient * client,
GST_DEBUG_OBJECT (auth, "setup auth"); GST_DEBUG_OBJECT (auth, "setup auth");
if (klass->setup_auth) if (klass->setup_auth)
result = klass->setup_auth (auth, client, uri, session, request, response); result = klass->setup_auth (auth, client, state);
return result; return result;
} }
static gboolean static gboolean
default_check_method (GstRTSPAuth * auth, GstRTSPMethod method, default_check_method (GstRTSPAuth * auth, GstRTSPClient * client,
GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPClientState * state)
GstRTSPMessage * request)
{ {
gboolean result = TRUE; gboolean result = TRUE;
GstRTSPResult res; GstRTSPResult res;
if (method & auth->methods != 0) { if (state->method & auth->methods != 0) {
gchar *authorization; gchar *authorization;
result = FALSE; result = FALSE;
res = res =
gst_rtsp_message_get_header (request, GST_RTSP_HDR_AUTHORIZATION, gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_AUTHORIZATION,
&authorization, 0); &authorization, 0);
if (res < 0) if (res < 0)
goto no_auth; goto no_auth;
@ -225,31 +223,26 @@ no_auth:
/** /**
* gst_rtsp_auth_check_method: * gst_rtsp_auth_check_method:
* @auth: a #GstRTSPAuth * @auth: a #GstRTSPAuth
* @method: method to check
* @client: the client * @client: the client
* @uri: the requested uri * @state: client state
* @session: the session
* @request: the request
* *
* Check if @client is allowed to perform @method for the @uri in * Check if @client is allowed to perform the actions of @state.
* @session and with @request.
* *
* Returns: FALSE if the method is not allowed. * Returns: FALSE if the action is not allowed.
*/ */
gboolean gboolean
gst_rtsp_auth_check_method (GstRTSPAuth * auth, GstRTSPMethod method, gst_rtsp_auth_check (GstRTSPAuth * auth, GstRTSPClient * client,
GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPClientState * state)
GstRTSPMessage * request)
{ {
gboolean result = FALSE; gboolean result = FALSE;
GstRTSPAuthClass *klass; GstRTSPAuthClass *klass;
klass = GST_RTSP_AUTH_GET_CLASS (auth); klass = GST_RTSP_AUTH_GET_CLASS (auth);
GST_DEBUG_OBJECT (auth, "check method %d", method); GST_DEBUG_OBJECT (auth, "check state");
if (klass->check_method) if (klass->check_method)
result = klass->check_method (auth, method, client, uri, session, request); result = klass->check_method (auth, client, state);
return result; return result;
} }

View file

@ -56,13 +56,8 @@ struct _GstRTSPAuth {
struct _GstRTSPAuthClass { struct _GstRTSPAuthClass {
GObjectClass parent_class; GObjectClass parent_class;
gboolean (*setup_auth) (GstRTSPAuth *auth, GstRTSPClient * client, gboolean (*setup_auth) (GstRTSPAuth *auth, GstRTSPClient * client, GstRTSPClientState *state);
GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPMessage * request, gboolean (*check_method) (GstRTSPAuth *auth, GstRTSPClient * client, GstRTSPClientState *state);
GstRTSPMessage *response);
gboolean (*check_method) (GstRTSPAuth *auth, GstRTSPMethod method,
GstRTSPClient * client, GstRTSPUrl * uri,
GstRTSPSession * session, GstRTSPMessage * request);
}; };
GType gst_rtsp_auth_get_type (void); GType gst_rtsp_auth_get_type (void);
@ -72,12 +67,9 @@ GstRTSPAuth * gst_rtsp_auth_new (void);
void gst_rtsp_auth_set_basic (GstRTSPAuth *auth, const gchar * basic); void gst_rtsp_auth_set_basic (GstRTSPAuth *auth, const gchar * basic);
gboolean gst_rtsp_auth_setup_auth (GstRTSPAuth *auth, GstRTSPClient * client, gboolean gst_rtsp_auth_setup_auth (GstRTSPAuth *auth, GstRTSPClient * client,
GstRTSPUrl * uri, GstRTSPSession * session, GstRTSPClientState *state);
GstRTSPMessage * request, GstRTSPMessage *response); gboolean gst_rtsp_auth_check_method (GstRTSPAuth *auth, GstRTSPClient * client,
gboolean gst_rtsp_auth_check_method (GstRTSPAuth *auth, GstRTSPMethod method, GstRTSPClientState *state);
GstRTSPClient * client, GstRTSPUrl * uri,
GstRTSPSession * session, GstRTSPMessage * request);
/* helpers */ /* helpers */
gchar * gst_rtsp_auth_make_basic (const gchar * user, const gchar * pass); gchar * gst_rtsp_auth_make_basic (const gchar * user, const gchar * pass);

View file

@ -244,32 +244,32 @@ send_response (GstRTSPClient * client, GstRTSPSession * session,
static void static void
send_generic_response (GstRTSPClient * client, GstRTSPStatusCode code, send_generic_response (GstRTSPClient * client, GstRTSPStatusCode code,
GstRTSPMessage * request) GstRTSPClientState * state)
{ {
GstRTSPMessage response = { 0 }; GstRTSPMessage response = { 0 };
gst_rtsp_message_init_response (&response, code, gst_rtsp_message_init_response (&response, code,
gst_rtsp_status_as_text (code), request); gst_rtsp_status_as_text (code), state->request);
send_response (client, NULL, &response); send_response (client, NULL, &response);
} }
static void static void
handle_unauthorized_request (GstRTSPClient * client, GstRTSPUrl * uri, handle_unauthorized_request (GstRTSPClient * client, GstRTSPClientState * state)
GstRTSPSession * session, GstRTSPMessage * request)
{ {
GstRTSPMessage response = { 0 }; GstRTSPMessage response = { 0 };
gst_rtsp_message_init_response (&response, GST_RTSP_STS_UNAUTHORIZED, gst_rtsp_message_init_response (&response, GST_RTSP_STS_UNAUTHORIZED,
gst_rtsp_status_as_text (GST_RTSP_STS_UNAUTHORIZED), request); gst_rtsp_status_as_text (GST_RTSP_STS_UNAUTHORIZED), state->request);
state->response = &response;
if (client->auth) { if (client->auth) {
/* and let the authentication manager setup the auth tokens */ /* and let the authentication manager setup the auth tokens */
gst_rtsp_auth_setup_auth (client->auth, client, uri, session, request, gst_rtsp_auth_setup_auth (client->auth, client, state);
&response);
} }
send_response (client, session, &response); send_response (client, state->session, &response);
} }
@ -289,12 +289,12 @@ compare_uri (const GstRTSPUrl * uri1, const GstRTSPUrl * uri2)
* but is cached for when the same client (without breaking the connection) is * but is cached for when the same client (without breaking the connection) is
* doing a setup for the exact same url. */ * doing a setup for the exact same url. */
static GstRTSPMedia * static GstRTSPMedia *
find_media (GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPMessage * request) find_media (GstRTSPClient * client, GstRTSPClientState * state)
{ {
GstRTSPMediaFactory *factory; GstRTSPMediaFactory *factory;
GstRTSPMedia *media; GstRTSPMedia *media;
if (!compare_uri (client->uri, uri)) { if (!compare_uri (client->uri, state->uri)) {
/* remove any previously cached values before we try to construct a new /* remove any previously cached values before we try to construct a new
* media for uri */ * media for uri */
if (client->uri) if (client->uri)
@ -309,26 +309,31 @@ find_media (GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPMessage * request)
/* find the factory for the uri first */ /* find the factory for the uri first */
if (!(factory = if (!(factory =
gst_rtsp_media_mapping_find_factory (client->media_mapping, uri))) gst_rtsp_media_mapping_find_factory (client->media_mapping,
state->uri)))
goto no_factory; goto no_factory;
state->factory = factory;
/* prepare the media and add it to the pipeline */ /* prepare the media and add it to the pipeline */
if (!(media = gst_rtsp_media_factory_construct (factory, uri))) if (!(media = gst_rtsp_media_factory_construct (factory, state->uri)))
goto no_media; goto no_media;
/* set ipv6 on the media before preparing */ /* set ipv6 on the media before preparing */
media->is_ipv6 = client->is_ipv6; media->is_ipv6 = client->is_ipv6;
state->media = media;
/* prepare the media */ /* prepare the media */
if (!(gst_rtsp_media_prepare (media))) if (!(gst_rtsp_media_prepare (media)))
goto no_prepare; goto no_prepare;
/* now keep track of the uri and the media */ /* now keep track of the uri and the media */
client->uri = gst_rtsp_url_copy (uri); client->uri = gst_rtsp_url_copy (state->uri);
client->media = media; client->media = media;
} else { } else {
/* we have seen this uri before, used cached media */ /* we have seen this uri before, used cached media */
media = client->media; media = client->media;
state->media = media;
GST_INFO ("reusing cached media %p", media); GST_INFO ("reusing cached media %p", media);
} }
@ -340,23 +345,23 @@ find_media (GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPMessage * request)
/* ERRORS */ /* ERRORS */
no_mapping: no_mapping:
{ {
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
return NULL; return NULL;
} }
no_factory: no_factory:
{ {
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
return NULL; return NULL;
} }
no_media: no_media:
{ {
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request); send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
g_object_unref (factory); g_object_unref (factory);
return NULL; return NULL;
} }
no_prepare: no_prepare:
{ {
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request); send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
g_object_unref (media); g_object_unref (media);
g_object_unref (factory); g_object_unref (factory);
return NULL; return NULL;
@ -478,21 +483,25 @@ close_connection (GstRTSPClient * client)
} }
static gboolean static gboolean
handle_teardown_request (GstRTSPClient * client, GstRTSPUrl * uri, handle_teardown_request (GstRTSPClient * client, GstRTSPClientState * state)
GstRTSPSession * session, GstRTSPMessage * request)
{ {
GstRTSPSession *session;
GstRTSPSessionMedia *media; GstRTSPSessionMedia *media;
GstRTSPMessage response = { 0 }; GstRTSPMessage response = { 0 };
GstRTSPStatusCode code; GstRTSPStatusCode code;
if (!session) if (!state->session)
goto no_session; goto no_session;
session = state->session;
/* get a handle to the configuration of the media in the session */ /* get a handle to the configuration of the media in the session */
media = gst_rtsp_session_get_media (session, uri); media = gst_rtsp_session_get_media (session, state->uri);
if (!media) if (!media)
goto not_found; goto not_found;
state->sessmedia = media;
/* unlink the all TCP callbacks */ /* unlink the all TCP callbacks */
unlink_session_streams (client, session, media); unlink_session_streams (client, session, media);
@ -512,7 +521,7 @@ handle_teardown_request (GstRTSPClient * client, GstRTSPUrl * uri,
/* construct the response now */ /* construct the response now */
code = GST_RTSP_STS_OK; code = GST_RTSP_STS_OK;
gst_rtsp_message_init_response (&response, code, gst_rtsp_message_init_response (&response, code,
gst_rtsp_status_as_text (code), request); gst_rtsp_status_as_text (code), state->request);
gst_rtsp_message_add_header (&response, GST_RTSP_HDR_CONNECTION, "close"); gst_rtsp_message_add_header (&response, GST_RTSP_HDR_CONNECTION, "close");
@ -525,103 +534,107 @@ handle_teardown_request (GstRTSPClient * client, GstRTSPUrl * uri,
/* ERRORS */ /* ERRORS */
no_session: no_session:
{ {
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request); send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
return FALSE; return FALSE;
} }
not_found: not_found:
{ {
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
return FALSE; return FALSE;
} }
} }
static gboolean static gboolean
handle_get_param_request (GstRTSPClient * client, GstRTSPUrl * uri, handle_get_param_request (GstRTSPClient * client, GstRTSPClientState * state)
GstRTSPSession * session, GstRTSPMessage * request)
{ {
GstRTSPResult res; GstRTSPResult res;
guint8 *data; guint8 *data;
guint size; guint size;
res = gst_rtsp_message_get_body (request, &data, &size); res = gst_rtsp_message_get_body (state->request, &data, &size);
if (res != GST_RTSP_OK) if (res != GST_RTSP_OK)
goto bad_request; goto bad_request;
if (size == 0) { if (size == 0) {
/* no body, keep-alive request */ /* no body, keep-alive request */
send_generic_response (client, GST_RTSP_STS_OK, request); send_generic_response (client, GST_RTSP_STS_OK, state);
} else { } else {
/* there is a body */ /* there is a body */
GstRTSPMessage response = { 0 }; GstRTSPMessage response = { 0 };
state->response = &response;
/* there is a body, handle the params */ /* there is a body, handle the params */
res = gst_rtsp_params_get (client, uri, session, request, &response); res = gst_rtsp_params_get (client, state);
if (res != GST_RTSP_OK) if (res != GST_RTSP_OK)
goto bad_request; goto bad_request;
send_response (client, session, &response); send_response (client, state->session, &response);
} }
return TRUE; return TRUE;
/* ERRORS */ /* ERRORS */
bad_request: bad_request:
{ {
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request); send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
return FALSE; return FALSE;
} }
} }
static gboolean static gboolean
handle_set_param_request (GstRTSPClient * client, GstRTSPUrl * uri, handle_set_param_request (GstRTSPClient * client, GstRTSPClientState * state)
GstRTSPSession * session, GstRTSPMessage * request)
{ {
GstRTSPResult res; GstRTSPResult res;
guint8 *data; guint8 *data;
guint size; guint size;
res = gst_rtsp_message_get_body (request, &data, &size); res = gst_rtsp_message_get_body (state->request, &data, &size);
if (res != GST_RTSP_OK) if (res != GST_RTSP_OK)
goto bad_request; goto bad_request;
if (size == 0) { if (size == 0) {
/* no body, keep-alive request */ /* no body, keep-alive request */
send_generic_response (client, GST_RTSP_STS_OK, request); send_generic_response (client, GST_RTSP_STS_OK, state);
} else { } else {
GstRTSPMessage response = { 0 }; GstRTSPMessage response = { 0 };
state->response = &response;
/* there is a body, handle the params */ /* there is a body, handle the params */
res = gst_rtsp_params_set (client, uri, session, request, &response); res = gst_rtsp_params_set (client, state);
if (res != GST_RTSP_OK) if (res != GST_RTSP_OK)
goto bad_request; goto bad_request;
send_response (client, session, &response); send_response (client, state->session, &response);
} }
return TRUE; return TRUE;
/* ERRORS */ /* ERRORS */
bad_request: bad_request:
{ {
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request); send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
return FALSE; return FALSE;
} }
} }
static gboolean static gboolean
handle_pause_request (GstRTSPClient * client, GstRTSPUrl * uri, handle_pause_request (GstRTSPClient * client, GstRTSPClientState * state)
GstRTSPSession * session, GstRTSPMessage * request)
{ {
GstRTSPSession *session;
GstRTSPSessionMedia *media; GstRTSPSessionMedia *media;
GstRTSPMessage response = { 0 }; GstRTSPMessage response = { 0 };
GstRTSPStatusCode code; GstRTSPStatusCode code;
if (!session) if (!(session = state->session))
goto no_session; goto no_session;
/* get a handle to the configuration of the media in the session */ /* get a handle to the configuration of the media in the session */
media = gst_rtsp_session_get_media (session, uri); media = gst_rtsp_session_get_media (session, state->uri);
if (!media) if (!media)
goto not_found; goto not_found;
state->sessmedia = media;
/* the session state must be playing or recording */ /* the session state must be playing or recording */
if (media->state != GST_RTSP_STATE_PLAYING && if (media->state != GST_RTSP_STATE_PLAYING &&
media->state != GST_RTSP_STATE_RECORDING) media->state != GST_RTSP_STATE_RECORDING)
@ -636,7 +649,7 @@ handle_pause_request (GstRTSPClient * client, GstRTSPUrl * uri,
/* construct the response now */ /* construct the response now */
code = GST_RTSP_STS_OK; code = GST_RTSP_STS_OK;
gst_rtsp_message_init_response (&response, code, gst_rtsp_message_init_response (&response, code,
gst_rtsp_status_as_text (code), request); gst_rtsp_status_as_text (code), state->request);
send_response (client, session, &response); send_response (client, session, &response);
@ -648,26 +661,26 @@ handle_pause_request (GstRTSPClient * client, GstRTSPUrl * uri,
/* ERRORS */ /* ERRORS */
no_session: no_session:
{ {
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request); send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
return FALSE; return FALSE;
} }
not_found: not_found:
{ {
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
return FALSE; return FALSE;
} }
invalid_state: invalid_state:
{ {
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE, send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
request); state);
return FALSE; return FALSE;
} }
} }
static gboolean static gboolean
handle_play_request (GstRTSPClient * client, GstRTSPUrl * uri, handle_play_request (GstRTSPClient * client, GstRTSPClientState * state)
GstRTSPSession * session, GstRTSPMessage * request)
{ {
GstRTSPSession *session;
GstRTSPSessionMedia *media; GstRTSPSessionMedia *media;
GstRTSPMessage response = { 0 }; GstRTSPMessage response = { 0 };
GstRTSPStatusCode code; GstRTSPStatusCode code;
@ -678,21 +691,24 @@ handle_play_request (GstRTSPClient * client, GstRTSPUrl * uri,
GstRTSPTimeRange *range; GstRTSPTimeRange *range;
GstRTSPResult res; GstRTSPResult res;
if (!session) if (!(session = state->session))
goto no_session; goto no_session;
/* get a handle to the configuration of the media in the session */ /* get a handle to the configuration of the media in the session */
media = gst_rtsp_session_get_media (session, uri); media = gst_rtsp_session_get_media (session, state->uri);
if (!media) if (!media)
goto not_found; goto not_found;
state->sessmedia = media;
/* the session state must be playing or ready */ /* the session state must be playing or ready */
if (media->state != GST_RTSP_STATE_PLAYING && if (media->state != GST_RTSP_STATE_PLAYING &&
media->state != GST_RTSP_STATE_READY) media->state != GST_RTSP_STATE_READY)
goto invalid_state; goto invalid_state;
/* parse the range header if we have one */ /* parse the range header if we have one */
res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_RANGE, &str, 0); res =
gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_RANGE, &str, 0);
if (res == GST_RTSP_OK) { if (res == GST_RTSP_OK) {
if (gst_rtsp_range_parse (str, &range) == GST_RTSP_OK) { if (gst_rtsp_range_parse (str, &range) == GST_RTSP_OK) {
/* we have a range, seek to the position */ /* we have a range, seek to the position */
@ -741,7 +757,7 @@ handle_play_request (GstRTSPClient * client, GstRTSPUrl * uri,
if (infocount > 0) if (infocount > 0)
g_string_append (rtpinfo, ", "); g_string_append (rtpinfo, ", ");
uristr = gst_rtsp_url_get_request_uri (uri); uristr = gst_rtsp_url_get_request_uri (state->uri);
g_string_append_printf (rtpinfo, "url=%s/stream=%d;seq=%u;rtptime=%u", g_string_append_printf (rtpinfo, "url=%s/stream=%d;seq=%u;rtptime=%u",
uristr, i, seqnum, timestamp); uristr, i, seqnum, timestamp);
g_free (uristr); g_free (uristr);
@ -755,7 +771,7 @@ handle_play_request (GstRTSPClient * client, GstRTSPUrl * uri,
/* construct the response now */ /* construct the response now */
code = GST_RTSP_STS_OK; code = GST_RTSP_STS_OK;
gst_rtsp_message_init_response (&response, code, gst_rtsp_message_init_response (&response, code,
gst_rtsp_status_as_text (code), request); gst_rtsp_status_as_text (code), state->request);
/* add the RTP-Info header */ /* add the RTP-Info header */
if (infocount > 0) { if (infocount > 0) {
@ -781,18 +797,18 @@ handle_play_request (GstRTSPClient * client, GstRTSPUrl * uri,
/* ERRORS */ /* ERRORS */
no_session: no_session:
{ {
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request); send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
return FALSE; return FALSE;
} }
not_found: not_found:
{ {
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
return FALSE; return FALSE;
} }
invalid_state: invalid_state:
{ {
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE, send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
request); state);
return FALSE; return FALSE;
} }
} }
@ -805,10 +821,10 @@ do_keepalive (GstRTSPSession * session)
} }
static gboolean static gboolean
handle_setup_request (GstRTSPClient * client, GstRTSPUrl * uri, handle_setup_request (GstRTSPClient * client, GstRTSPClientState * state)
GstRTSPSession * session, GstRTSPMessage * request)
{ {
GstRTSPResult res; GstRTSPResult res;
GstRTSPUrl *uri;
gchar *transport; gchar *transport;
gchar **transports; gchar **transports;
gboolean have_transport; gboolean have_transport;
@ -817,12 +833,15 @@ handle_setup_request (GstRTSPClient * client, GstRTSPUrl * uri,
GstRTSPLowerTrans supported; GstRTSPLowerTrans supported;
GstRTSPMessage response = { 0 }; GstRTSPMessage response = { 0 };
GstRTSPStatusCode code; GstRTSPStatusCode code;
GstRTSPSession *session;
GstRTSPSessionStream *stream; GstRTSPSessionStream *stream;
gchar *trans_str, *pos; gchar *trans_str, *pos;
guint streamid; guint streamid;
GstRTSPSessionMedia *media; GstRTSPSessionMedia *media;
GstRTSPUrl *url; GstRTSPUrl *url;
uri = state->uri;
/* the uri contains the stream number we added in the SDP config, which is /* the uri contains the stream number we added in the SDP config, which is
* always /stream=%d so we need to strip that off * always /stream=%d so we need to strip that off
* parse the stream we need to configure, look for the stream in the abspath * parse the stream we need to configure, look for the stream in the abspath
@ -841,8 +860,8 @@ handle_setup_request (GstRTSPClient * client, GstRTSPUrl * uri,
/* parse the transport */ /* parse the transport */
res = res =
gst_rtsp_message_get_header (request, GST_RTSP_HDR_TRANSPORT, &transport, gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_TRANSPORT,
0); &transport, 0);
if (res != GST_RTSP_OK) if (res != GST_RTSP_OK)
goto no_transport; goto no_transport;
@ -903,6 +922,8 @@ handle_setup_request (GstRTSPClient * client, GstRTSPUrl * uri,
ct->destination = g_strdup (url->host); ct->destination = g_strdup (url->host);
} }
session = state->session;
if (session) { if (session) {
g_object_ref (session); g_object_ref (session);
/* get a handle to the configuration of the media in the session, this can /* get a handle to the configuration of the media in the session, this can
@ -914,6 +935,8 @@ handle_setup_request (GstRTSPClient * client, GstRTSPUrl * uri,
if (!(session = gst_rtsp_session_pool_create (client->session_pool))) if (!(session = gst_rtsp_session_pool_create (client->session_pool)))
goto service_unavailable; goto service_unavailable;
state->session = session;
/* we need a new media configuration in this session */ /* we need a new media configuration in this session */
media = NULL; media = NULL;
} }
@ -923,7 +946,7 @@ handle_setup_request (GstRTSPClient * client, GstRTSPUrl * uri,
GstRTSPMedia *m; GstRTSPMedia *m;
/* get a handle to the configuration of the media in the session */ /* get a handle to the configuration of the media in the session */
if ((m = find_media (client, uri, request))) { if ((m = find_media (client, state))) {
/* manage the media in our session now */ /* manage the media in our session now */
media = gst_rtsp_session_manage_media (session, uri, m); media = gst_rtsp_session_manage_media (session, uri, m);
} }
@ -933,6 +956,8 @@ handle_setup_request (GstRTSPClient * client, GstRTSPUrl * uri,
if (media == NULL) if (media == NULL)
goto not_found; goto not_found;
state->sessmedia = media;
/* fix the transports */ /* fix the transports */
if (ct->lower_transport & GST_RTSP_LOWER_TRANS_TCP) { if (ct->lower_transport & GST_RTSP_LOWER_TRANS_TCP) {
/* check if the client selected channels for TCP */ /* check if the client selected channels for TCP */
@ -958,7 +983,7 @@ handle_setup_request (GstRTSPClient * client, GstRTSPUrl * uri,
/* construct the response now */ /* construct the response now */
code = GST_RTSP_STS_OK; code = GST_RTSP_STS_OK;
gst_rtsp_message_init_response (&response, code, gst_rtsp_message_init_response (&response, code,
gst_rtsp_status_as_text (code), request); gst_rtsp_status_as_text (code), state->request);
gst_rtsp_message_add_header (&response, GST_RTSP_HDR_TRANSPORT, trans_str); gst_rtsp_message_add_header (&response, GST_RTSP_HDR_TRANSPORT, trans_str);
g_free (trans_str); g_free (trans_str);
@ -983,41 +1008,41 @@ handle_setup_request (GstRTSPClient * client, GstRTSPUrl * uri,
/* ERRORS */ /* ERRORS */
bad_request: bad_request:
{ {
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request); send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
return FALSE; return FALSE;
} }
not_found: not_found:
{ {
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
g_object_unref (session); g_object_unref (session);
return FALSE; return FALSE;
} }
no_stream: no_stream:
{ {
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request); send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
g_object_unref (media); g_object_unref (media);
g_object_unref (session); g_object_unref (session);
return FALSE; return FALSE;
} }
no_transport: no_transport:
{ {
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, request); send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
return FALSE; return FALSE;
} }
unsupported_transports: unsupported_transports:
{ {
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, request); send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
gst_rtsp_transport_free (ct); gst_rtsp_transport_free (ct);
return FALSE; return FALSE;
} }
no_pool: no_pool:
{ {
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request); send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
return FALSE; return FALSE;
} }
service_unavailable: service_unavailable:
{ {
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request); send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
return FALSE; return FALSE;
} }
} }
@ -1071,8 +1096,7 @@ no_sdp:
/* for the describe we must generate an SDP */ /* for the describe we must generate an SDP */
static gboolean static gboolean
handle_describe_request (GstRTSPClient * client, GstRTSPUrl * uri, handle_describe_request (GstRTSPClient * client, GstRTSPClientState * state)
GstRTSPSession * session, GstRTSPMessage * request)
{ {
GstRTSPMessage response = { 0 }; GstRTSPMessage response = { 0 };
GstRTSPResult res; GstRTSPResult res;
@ -1087,7 +1111,8 @@ handle_describe_request (GstRTSPClient * client, GstRTSPUrl * uri,
gchar *accept; gchar *accept;
res = res =
gst_rtsp_message_get_header (request, GST_RTSP_HDR_ACCEPT, &accept, i); gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_ACCEPT,
&accept, i);
if (res == GST_RTSP_ENOTIMPL) if (res == GST_RTSP_ENOTIMPL)
break; break;
@ -1096,7 +1121,7 @@ handle_describe_request (GstRTSPClient * client, GstRTSPUrl * uri,
} }
/* find the media object for the uri */ /* find the media object for the uri */
if (!(media = find_media (client, uri, request))) if (!(media = find_media (client, state)))
goto no_media; goto no_media;
/* create an SDP for the media object on this client */ /* create an SDP for the media object on this client */
@ -1106,13 +1131,13 @@ handle_describe_request (GstRTSPClient * client, GstRTSPUrl * uri,
g_object_unref (media); g_object_unref (media);
gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK, gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK,
gst_rtsp_status_as_text (GST_RTSP_STS_OK), request); gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
gst_rtsp_message_add_header (&response, GST_RTSP_HDR_CONTENT_TYPE, gst_rtsp_message_add_header (&response, GST_RTSP_HDR_CONTENT_TYPE,
"application/sdp"); "application/sdp");
/* content base for some clients that might screw up creating the setup uri */ /* content base for some clients that might screw up creating the setup uri */
str = gst_rtsp_url_get_request_uri (uri); str = gst_rtsp_url_get_request_uri (state->uri);
str_len = strlen (str); str_len = strlen (str);
/* check for trailing '/' and append one */ /* check for trailing '/' and append one */
@ -1137,7 +1162,7 @@ handle_describe_request (GstRTSPClient * client, GstRTSPUrl * uri,
gst_rtsp_message_take_body (&response, (guint8 *) str, strlen (str)); gst_rtsp_message_take_body (&response, (guint8 *) str, strlen (str));
gst_sdp_message_free (sdp); gst_sdp_message_free (sdp);
send_response (client, session, &response); send_response (client, state->session, &response);
return TRUE; return TRUE;
@ -1149,15 +1174,14 @@ no_media:
} }
no_sdp: no_sdp:
{ {
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request); send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
g_object_unref (media); g_object_unref (media);
return FALSE; return FALSE;
} }
} }
static gboolean static gboolean
handle_options_request (GstRTSPClient * client, GstRTSPUrl * uri, handle_options_request (GstRTSPClient * client, GstRTSPClientState * state)
GstRTSPSession * session, GstRTSPMessage * request)
{ {
GstRTSPMessage response = { 0 }; GstRTSPMessage response = { 0 };
GstRTSPMethod options; GstRTSPMethod options;
@ -1173,12 +1197,12 @@ handle_options_request (GstRTSPClient * client, GstRTSPUrl * uri,
str = gst_rtsp_options_as_text (options); str = gst_rtsp_options_as_text (options);
gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK, gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK,
gst_rtsp_status_as_text (GST_RTSP_STS_OK), request); gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
gst_rtsp_message_add_header (&response, GST_RTSP_HDR_PUBLIC, str); gst_rtsp_message_add_header (&response, GST_RTSP_HDR_PUBLIC, str);
g_free (str); g_free (str);
send_response (client, session, &response); send_response (client, state->session, &response);
return TRUE; return TRUE;
} }
@ -1255,8 +1279,11 @@ handle_request (GstRTSPClient * client, GstRTSPMessage * request)
GstRTSPVersion version; GstRTSPVersion version;
GstRTSPResult res; GstRTSPResult res;
GstRTSPSession *session; GstRTSPSession *session;
GstRTSPClientState state = { NULL };
gchar *sessid; gchar *sessid;
state.request = request;
if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) { if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
gst_rtsp_message_dump (request); gst_rtsp_message_dump (request);
} }
@ -1268,18 +1295,20 @@ handle_request (GstRTSPClient * client, GstRTSPMessage * request)
if (version != GST_RTSP_VERSION_1_0) { if (version != GST_RTSP_VERSION_1_0) {
/* we can only handle 1.0 requests */ /* we can only handle 1.0 requests */
send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED, send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED,
request); &state);
return; return;
} }
state.method = method;
/* we always try to parse the url first */ /* we always try to parse the url first */
if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK) { if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK) {
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request); send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &state);
return; return;
} }
/* sanitize the uri */ /* sanitize the uri */
sanitize_uri (uri); sanitize_uri (uri);
state.uri = uri;
/* get the session if there is any */ /* get the session if there is any */
res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0); res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
@ -1298,46 +1327,47 @@ handle_request (GstRTSPClient * client, GstRTSPMessage * request)
} else } else
session = NULL; session = NULL;
state.session = session;
if (client->auth) { if (client->auth) {
if (!gst_rtsp_auth_check_method (client->auth, method, client, uri, session, if (!gst_rtsp_auth_check (client->auth, client, &state))
request))
goto not_authorized; goto not_authorized;
} }
/* now see what is asked and dispatch to a dedicated handler */ /* now see what is asked and dispatch to a dedicated handler */
switch (method) { switch (method) {
case GST_RTSP_OPTIONS: case GST_RTSP_OPTIONS:
handle_options_request (client, uri, session, request); handle_options_request (client, &state);
break; break;
case GST_RTSP_DESCRIBE: case GST_RTSP_DESCRIBE:
handle_describe_request (client, uri, session, request); handle_describe_request (client, &state);
break; break;
case GST_RTSP_SETUP: case GST_RTSP_SETUP:
handle_setup_request (client, uri, session, request); handle_setup_request (client, &state);
break; break;
case GST_RTSP_PLAY: case GST_RTSP_PLAY:
handle_play_request (client, uri, session, request); handle_play_request (client, &state);
break; break;
case GST_RTSP_PAUSE: case GST_RTSP_PAUSE:
handle_pause_request (client, uri, session, request); handle_pause_request (client, &state);
break; break;
case GST_RTSP_TEARDOWN: case GST_RTSP_TEARDOWN:
handle_teardown_request (client, uri, session, request); handle_teardown_request (client, &state);
break; break;
case GST_RTSP_SET_PARAMETER: case GST_RTSP_SET_PARAMETER:
handle_set_param_request (client, uri, session, request); handle_set_param_request (client, &state);
break; break;
case GST_RTSP_GET_PARAMETER: case GST_RTSP_GET_PARAMETER:
handle_get_param_request (client, uri, session, request); handle_get_param_request (client, &state);
break; break;
case GST_RTSP_ANNOUNCE: case GST_RTSP_ANNOUNCE:
case GST_RTSP_RECORD: case GST_RTSP_RECORD:
case GST_RTSP_REDIRECT: case GST_RTSP_REDIRECT:
send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, request); send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, &state);
break; break;
case GST_RTSP_INVALID: case GST_RTSP_INVALID:
default: default:
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request); send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &state);
break; break;
} }
if (session) if (session)
@ -1349,17 +1379,17 @@ handle_request (GstRTSPClient * client, GstRTSPMessage * request)
/* ERRORS */ /* ERRORS */
no_pool: no_pool:
{ {
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request); send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, &state);
return; return;
} }
session_not_found: session_not_found:
{ {
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request); send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, &state);
return; return;
} }
not_authorized: not_authorized:
{ {
handle_unauthorized_request (client, uri, session, request); handle_unauthorized_request (client, &state);
return; return;
} }
} }

View file

@ -27,6 +27,7 @@ G_BEGIN_DECLS
typedef struct _GstRTSPClient GstRTSPClient; typedef struct _GstRTSPClient GstRTSPClient;
typedef struct _GstRTSPClientClass GstRTSPClientClass; typedef struct _GstRTSPClientClass GstRTSPClientClass;
typedef struct _GstRTSPClientState GstRTSPClientState;
#include "rtsp-server.h" #include "rtsp-server.h"
#include "rtsp-media.h" #include "rtsp-media.h"
@ -43,6 +44,29 @@ typedef struct _GstRTSPClientClass GstRTSPClientClass;
#define GST_RTSP_CLIENT_CAST(obj) ((GstRTSPClient*)(obj)) #define GST_RTSP_CLIENT_CAST(obj) ((GstRTSPClient*)(obj))
#define GST_RTSP_CLIENT_CLASS_CAST(klass) ((GstRTSPClientClass*)(klass)) #define GST_RTSP_CLIENT_CLASS_CAST(klass) ((GstRTSPClientClass*)(klass))
/**
* GstRTSPClientState:
* @request: the complete request
* @uri: the complete url parsed from @request
* @method: the parsed method of @uri
* @session: the session, can be NULL
* @sessmedia: the session media for the url can be NULL
* @factory: the media factory for the url, can be NULL.
* @media: the session media for the url can be NULL
* @response: the response
*
* Information passed around containing the client state of a request.
*/
struct _GstRTSPClientState{
GstRTSPMessage *request;
GstRTSPUrl *uri;
GstRTSPMethod method;
GstRTSPSession *session;
GstRTSPSessionMedia *sessmedia;
GstRTSPMediaFactory *factory;
GstRTSPMedia *media;
GstRTSPMessage *response;
};
/** /**
* GstRTSPClient: * GstRTSPClient:

View file

@ -21,9 +21,7 @@
#include "rtsp-params.h" #include "rtsp-params.h"
GstRTSPResult GstRTSPResult
gst_rtsp_params_set (GstRTSPClient * client, GstRTSPUrl * uri, gst_rtsp_params_set (GstRTSPClient * client, GstRTSPClientState * state)
GstRTSPSession * session, GstRTSPMessage * request,
GstRTSPMessage * response)
{ {
GstRTSPStatusCode code; GstRTSPStatusCode code;
@ -31,16 +29,14 @@ gst_rtsp_params_set (GstRTSPClient * client, GstRTSPUrl * uri,
* with a list of the parameters */ * with a list of the parameters */
code = GST_RTSP_STS_PARAMETER_NOT_UNDERSTOOD; code = GST_RTSP_STS_PARAMETER_NOT_UNDERSTOOD;
gst_rtsp_message_init_response (response, code, gst_rtsp_message_init_response (state->response, code,
gst_rtsp_status_as_text (code), request); gst_rtsp_status_as_text (code), state->request);
return GST_RTSP_OK; return GST_RTSP_OK;
} }
GstRTSPResult GstRTSPResult
gst_rtsp_params_get (GstRTSPClient * client, GstRTSPUrl * uri, gst_rtsp_params_get (GstRTSPClient * client, GstRTSPClientState * state)
GstRTSPSession * session, GstRTSPMessage * request,
GstRTSPMessage * response)
{ {
GstRTSPStatusCode code; GstRTSPStatusCode code;
@ -48,8 +44,8 @@ gst_rtsp_params_get (GstRTSPClient * client, GstRTSPUrl * uri,
* with a list of the parameters */ * with a list of the parameters */
code = GST_RTSP_STS_PARAMETER_NOT_UNDERSTOOD; code = GST_RTSP_STS_PARAMETER_NOT_UNDERSTOOD;
gst_rtsp_message_init_response (response, code, gst_rtsp_message_init_response (state->response, code,
gst_rtsp_status_as_text (code), request); gst_rtsp_status_as_text (code), state->request);
return GST_RTSP_OK; return GST_RTSP_OK;
} }

View file

@ -30,13 +30,8 @@
G_BEGIN_DECLS G_BEGIN_DECLS
GstRTSPResult gst_rtsp_params_set (GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPResult gst_rtsp_params_set (GstRTSPClient * client, GstRTSPClientState * state);
GstRTSPSession * session, GstRTSPMessage * request, GstRTSPResult gst_rtsp_params_get (GstRTSPClient * client, GstRTSPClientState * state);
GstRTSPMessage * response);
GstRTSPResult gst_rtsp_params_get (GstRTSPClient * client, GstRTSPUrl * uri,
GstRTSPSession * session, GstRTSPMessage * request,
GstRTSPMessage * response);
G_END_DECLS G_END_DECLS