mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-29 21:14:47 +00:00
rtsp: Added support for HTTP messages
This commit is contained in:
parent
dd7d0cfc45
commit
ca154010fe
5 changed files with 100 additions and 27 deletions
|
@ -1350,6 +1350,21 @@ message_to_string (GstRTSPConnection * conn, GstRTSPMessage * message)
|
|||
g_string_append_printf (str, "RTSP/1.0 %d %s\r\n",
|
||||
message->type_data.response.code, message->type_data.response.reason);
|
||||
break;
|
||||
case GST_RTSP_MESSAGE_HTTP_REQUEST:
|
||||
/* create request string */
|
||||
g_string_append_printf (str, "%s %s HTTP/%s\r\n",
|
||||
gst_rtsp_method_as_text (message->type_data.request.method),
|
||||
message->type_data.request.uri,
|
||||
gst_rtsp_version_as_text (message->type_data.request.version));
|
||||
/* add any authentication headers */
|
||||
add_auth_header (conn, message);
|
||||
break;
|
||||
case GST_RTSP_MESSAGE_HTTP_RESPONSE:
|
||||
/* create response string */
|
||||
g_string_append_printf (str, "HTTP/%s %d %s\r\n",
|
||||
gst_rtsp_version_as_text (message->type_data.request.version),
|
||||
message->type_data.response.code, message->type_data.response.reason);
|
||||
break;
|
||||
case GST_RTSP_MESSAGE_DATA:
|
||||
{
|
||||
guint8 data_header[4];
|
||||
|
|
|
@ -101,6 +101,8 @@ static const gchar *rtsp_methods[] = {
|
|||
"SETUP",
|
||||
"SET_PARAMETER",
|
||||
"TEARDOWN",
|
||||
"GET",
|
||||
"POST",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -184,9 +186,12 @@ static const gchar *rtsp_headers[] = {
|
|||
"X-Receding-PlaylistChange", /* X-Receding-PlaylistChange */
|
||||
"X-RTP-Info", /* X-RTP-Info */
|
||||
"X-StartupProfile", /* X-StartupProfile */
|
||||
|
||||
"Timestamp", /* Timestamp */
|
||||
|
||||
"Authentication-Info", /* Authentication-Info */
|
||||
"Host", /* Host */
|
||||
"X-Sessioncookie", /* X-Sessioncookie */
|
||||
|
||||
NULL
|
||||
};
|
||||
|
@ -339,6 +344,9 @@ gst_rtsp_version_as_text (GstRTSPVersion version)
|
|||
case GST_RTSP_VERSION_1_0:
|
||||
return "1.0";
|
||||
|
||||
case GST_RTSP_VERSION_1_1:
|
||||
return "1.1";
|
||||
|
||||
default:
|
||||
return "0.0";
|
||||
}
|
||||
|
|
|
@ -157,12 +157,14 @@ typedef enum {
|
|||
* GstRTSPVersion:
|
||||
* @GST_RTSP_VERSION_INVALID: unknown/invalid version
|
||||
* @GST_RTSP_VERSION_1_0: version 1.0
|
||||
* @GST_RTSP_VERSION_1_1: version 1.1
|
||||
*
|
||||
* The supported RTSP versions.
|
||||
*/
|
||||
typedef enum {
|
||||
GST_RTSP_VERSION_INVALID = 0x00,
|
||||
GST_RTSP_VERSION_1_0 = 0x10
|
||||
GST_RTSP_VERSION_1_0 = 0x10,
|
||||
GST_RTSP_VERSION_1_1 = 0x11
|
||||
} GstRTSPVersion;
|
||||
|
||||
/**
|
||||
|
@ -179,6 +181,8 @@ typedef enum {
|
|||
* @GST_RTSP_SETUP: the SETUP method
|
||||
* @GST_RTSP_SET_PARAMETER: the SET_PARAMETER method
|
||||
* @GST_RTSP_TEARDOWN: the TEARDOWN method
|
||||
* @GST_RTSP_GET: the GET method (HTTP)
|
||||
* @GST_RTSP_POST: the POST method (HTTP)
|
||||
*
|
||||
* The different supported RTSP methods.
|
||||
*/
|
||||
|
@ -194,7 +198,9 @@ typedef enum {
|
|||
GST_RTSP_REDIRECT = (1 << 7),
|
||||
GST_RTSP_SETUP = (1 << 8),
|
||||
GST_RTSP_SET_PARAMETER = (1 << 9),
|
||||
GST_RTSP_TEARDOWN = (1 << 10)
|
||||
GST_RTSP_TEARDOWN = (1 << 10),
|
||||
GST_RTSP_GET = (1 << 11),
|
||||
GST_RTSP_POST = (1 << 12)
|
||||
} GstRTSPMethod;
|
||||
|
||||
/**
|
||||
|
@ -315,6 +321,8 @@ typedef enum {
|
|||
|
||||
/* Since 0.10.25 */
|
||||
GST_RTSP_HDR_AUTHENTICATION_INFO, /* Authentication-Info */
|
||||
GST_RTSP_HDR_HOST, /* Host */
|
||||
GST_RTSP_HDR_X_SESSIONCOOKIE, /* X-Sessioncookie */
|
||||
|
||||
GST_RTSP_HDR_LAST
|
||||
} GstRTSPHeaderField;
|
||||
|
|
|
@ -214,7 +214,8 @@ gst_rtsp_message_parse_request (GstRTSPMessage * msg,
|
|||
GstRTSPMethod * method, const gchar ** uri, GstRTSPVersion * version)
|
||||
{
|
||||
g_return_val_if_fail (msg != NULL, GST_RTSP_EINVAL);
|
||||
g_return_val_if_fail (msg->type == GST_RTSP_MESSAGE_REQUEST, GST_RTSP_EINVAL);
|
||||
g_return_val_if_fail (msg->type == GST_RTSP_MESSAGE_REQUEST ||
|
||||
msg->type == GST_RTSP_MESSAGE_HTTP_REQUEST, GST_RTSP_EINVAL);
|
||||
|
||||
if (method)
|
||||
*method = msg->type_data.request.method;
|
||||
|
@ -292,34 +293,41 @@ gst_rtsp_message_init_response (GstRTSPMessage * msg, GstRTSPStatusCode code,
|
|||
msg->hdr_fields = g_array_new (FALSE, FALSE, sizeof (RTSPKeyValue));
|
||||
|
||||
if (request) {
|
||||
gchar *header;
|
||||
if (request->type == GST_RTSP_MESSAGE_HTTP_REQUEST) {
|
||||
msg->type = GST_RTSP_MESSAGE_HTTP_RESPONSE;
|
||||
if (request->type_data.request.version != GST_RTSP_VERSION_INVALID)
|
||||
msg->type_data.response.version = request->type_data.request.version;
|
||||
else
|
||||
msg->type_data.response.version = GST_RTSP_VERSION_1_1;
|
||||
} else {
|
||||
gchar *header;
|
||||
|
||||
/* copy CSEQ */
|
||||
if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_CSEQ, &header,
|
||||
0) == GST_RTSP_OK) {
|
||||
gst_rtsp_message_add_header (msg, GST_RTSP_HDR_CSEQ, header);
|
||||
}
|
||||
|
||||
/* copy session id */
|
||||
if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &header,
|
||||
0) == GST_RTSP_OK) {
|
||||
char *pos;
|
||||
|
||||
header = g_strdup (header);
|
||||
if ((pos = strchr (header, ';'))) {
|
||||
*pos = '\0';
|
||||
/* copy CSEQ */
|
||||
if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_CSEQ, &header,
|
||||
0) == GST_RTSP_OK) {
|
||||
gst_rtsp_message_add_header (msg, GST_RTSP_HDR_CSEQ, header);
|
||||
}
|
||||
g_strchomp (header);
|
||||
gst_rtsp_message_take_header (msg, GST_RTSP_HDR_SESSION, header);
|
||||
}
|
||||
|
||||
/* FIXME copy more headers? */
|
||||
/* copy session id */
|
||||
if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &header,
|
||||
0) == GST_RTSP_OK) {
|
||||
char *pos;
|
||||
|
||||
header = g_strdup (header);
|
||||
if ((pos = strchr (header, ';'))) {
|
||||
*pos = '\0';
|
||||
}
|
||||
g_strchomp (header);
|
||||
gst_rtsp_message_take_header (msg, GST_RTSP_HDR_SESSION, header);
|
||||
}
|
||||
|
||||
/* FIXME copy more headers? */
|
||||
}
|
||||
}
|
||||
|
||||
return GST_RTSP_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gst_rtsp_message_parse_response:
|
||||
* @msg: a #GstRTSPMessage
|
||||
|
@ -340,8 +348,8 @@ gst_rtsp_message_parse_response (GstRTSPMessage * msg,
|
|||
GstRTSPStatusCode * code, const gchar ** reason, GstRTSPVersion * version)
|
||||
{
|
||||
g_return_val_if_fail (msg != NULL, GST_RTSP_EINVAL);
|
||||
g_return_val_if_fail (msg->type == GST_RTSP_MESSAGE_RESPONSE,
|
||||
GST_RTSP_EINVAL);
|
||||
g_return_val_if_fail (msg->type == GST_RTSP_MESSAGE_RESPONSE ||
|
||||
msg->type == GST_RTSP_MESSAGE_HTTP_RESPONSE, GST_RTSP_EINVAL);
|
||||
|
||||
if (code)
|
||||
*code = msg->type_data.response.code;
|
||||
|
@ -440,9 +448,11 @@ gst_rtsp_message_unset (GstRTSPMessage * msg)
|
|||
case GST_RTSP_MESSAGE_INVALID:
|
||||
break;
|
||||
case GST_RTSP_MESSAGE_REQUEST:
|
||||
case GST_RTSP_MESSAGE_HTTP_REQUEST:
|
||||
g_free (msg->type_data.request.uri);
|
||||
break;
|
||||
case GST_RTSP_MESSAGE_RESPONSE:
|
||||
case GST_RTSP_MESSAGE_HTTP_RESPONSE:
|
||||
g_free (msg->type_data.response.reason);
|
||||
break;
|
||||
case GST_RTSP_MESSAGE_DATA:
|
||||
|
@ -794,6 +804,33 @@ gst_rtsp_message_dump (GstRTSPMessage * msg)
|
|||
g_print (" body: length %d\n", size);
|
||||
gst_util_dump_mem (data, size);
|
||||
break;
|
||||
case GST_RTSP_MESSAGE_HTTP_REQUEST:
|
||||
g_print ("HTTP request message %p\n", msg);
|
||||
g_print (" request line:\n");
|
||||
g_print (" method: '%s'\n",
|
||||
gst_rtsp_method_as_text (msg->type_data.request.method));
|
||||
g_print (" uri: '%s'\n", msg->type_data.request.uri);
|
||||
g_print (" version: '%s'\n",
|
||||
gst_rtsp_version_as_text (msg->type_data.request.version));
|
||||
g_print (" headers:\n");
|
||||
key_value_foreach (msg->hdr_fields, dump_key_value, NULL);
|
||||
g_print (" body:\n");
|
||||
gst_rtsp_message_get_body (msg, &data, &size);
|
||||
gst_util_dump_mem (data, size);
|
||||
break;
|
||||
case GST_RTSP_MESSAGE_HTTP_RESPONSE:
|
||||
g_print ("HTTP response message %p\n", msg);
|
||||
g_print (" status line:\n");
|
||||
g_print (" code: '%d'\n", msg->type_data.response.code);
|
||||
g_print (" reason: '%s'\n", msg->type_data.response.reason);
|
||||
g_print (" version: '%s'\n",
|
||||
gst_rtsp_version_as_text (msg->type_data.response.version));
|
||||
g_print (" headers:\n");
|
||||
key_value_foreach (msg->hdr_fields, dump_key_value, NULL);
|
||||
gst_rtsp_message_get_body (msg, &data, &size);
|
||||
g_print (" body: length %d\n", size);
|
||||
gst_util_dump_mem (data, size);
|
||||
break;
|
||||
case GST_RTSP_MESSAGE_DATA:
|
||||
g_print ("RTSP data message %p\n", msg);
|
||||
g_print (" channel: '%d'\n", msg->type_data.data.channel);
|
||||
|
|
|
@ -52,8 +52,10 @@ G_BEGIN_DECLS
|
|||
/**
|
||||
* GstRTSPMsgType:
|
||||
* @GST_RTSP_MESSAGE_INVALID: invalid message type
|
||||
* @GST_RTSP_MESSAGE_REQUEST: request message
|
||||
* @GST_RTSP_MESSAGE_RESPONSE: response message
|
||||
* @GST_RTSP_MESSAGE_REQUEST: RTSP request message
|
||||
* @GST_RTSP_MESSAGE_RESPONSE: RTSP response message
|
||||
* @GST_RTSP_MESSAGE_HTTP_REQUEST: HTTP request message
|
||||
* @GST_RTSP_MESSAGE_HTTP_RESPONSE: HTTP response message
|
||||
* @GST_RTSP_MESSAGE_DATA: data message
|
||||
*
|
||||
* The type of a message.
|
||||
|
@ -63,6 +65,8 @@ typedef enum
|
|||
GST_RTSP_MESSAGE_INVALID,
|
||||
GST_RTSP_MESSAGE_REQUEST,
|
||||
GST_RTSP_MESSAGE_RESPONSE,
|
||||
GST_RTSP_MESSAGE_HTTP_REQUEST,
|
||||
GST_RTSP_MESSAGE_HTTP_RESPONSE,
|
||||
GST_RTSP_MESSAGE_DATA
|
||||
} GstRTSPMsgType;
|
||||
|
||||
|
@ -135,6 +139,7 @@ GstRTSPResult gst_rtsp_message_parse_response (GstRTSPMessage *msg,
|
|||
GstRTSPStatusCode *code,
|
||||
const gchar **reason,
|
||||
GstRTSPVersion *version);
|
||||
|
||||
/* data */
|
||||
GstRTSPResult gst_rtsp_message_new_data (GstRTSPMessage **msg,
|
||||
guint8 channel);
|
||||
|
|
Loading…
Reference in a new issue