diff options
author | Ognyan Tonchev <ognyan@axis.com> | 2015-11-17 17:07:37 +0100 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2015-11-18 00:15:32 +0000 |
commit | 7a702df863ef9155eb46aca5a2b1ad0c72459a65 (patch) | |
tree | 92b4fa6d4736451f9f47a6299e82d755dd5b762b | |
parent | 0c95b0a738eda526241fc16a7cf12106baa3bf82 (diff) |
rtspconnection: Add support for parsing custom headers
https://bugzilla.gnome.org/show_bug.cgi?id=758235
-rw-r--r-- | gst-libs/gst/rtsp/gstrtspconnection.c | 13 | ||||
-rw-r--r-- | tests/check/libs/rtspconnection.c | 64 |
2 files changed, 73 insertions, 4 deletions
diff --git a/gst-libs/gst/rtsp/gstrtspconnection.c b/gst-libs/gst/rtsp/gstrtspconnection.c index 22e1f0027..786dbcc93 100644 --- a/gst-libs/gst/rtsp/gstrtspconnection.c +++ b/gst-libs/gst/rtsp/gstrtspconnection.c @@ -1758,6 +1758,7 @@ parse_line (guint8 * buffer, GstRTSPMessage * msg) { GstRTSPHeaderField field; gchar *line = (gchar *) buffer; + gchar *field_name = NULL; gchar *value; if ((value = strchr (line, ':')) == NULL || value == line) @@ -1772,8 +1773,9 @@ parse_line (guint8 * buffer, GstRTSPMessage * msg) /* find the header */ field = gst_rtsp_find_header_field (line); + /* custom header not present in the list of pre-defined headers */ if (field == GST_RTSP_HDR_INVALID) - goto done; + field_name = line; /* split up the value in multiple key:value pairs if it contains comma(s) */ while (*value != '\0') { @@ -1861,13 +1863,16 @@ parse_line (guint8 * buffer, GstRTSPMessage * msg) *next_value++ = '\0'; /* add the key:value pair */ - if (*value != '\0') - gst_rtsp_message_add_header (msg, field, value); + if (*value != '\0') { + if (field != GST_RTSP_HDR_INVALID) + gst_rtsp_message_add_header (msg, field, value); + else + gst_rtsp_message_add_header_by_name (msg, field_name, value); + } value = next_value; } -done: return GST_RTSP_OK; /* ERRORS */ diff --git a/tests/check/libs/rtspconnection.c b/tests/check/libs/rtspconnection.c index ee3c18cdf..d24fd54c4 100644 --- a/tests/check/libs/rtspconnection.c +++ b/tests/check/libs/rtspconnection.c @@ -603,6 +603,69 @@ GST_START_TEST (test_rtspconnection_send_receive) GST_END_TEST; +GST_START_TEST (test_rtspconnection_send_receive_check_headers) +{ + GSocketConnection *input_conn = NULL; + GSocketConnection *output_conn = NULL; + GSocket *input_sock; + GSocket *output_sock; + GstRTSPConnection *rtsp_output_conn; + GstRTSPConnection *rtsp_input_conn; + GstRTSPMessage *msg; + gchar *header_val; + + create_connection (&input_conn, &output_conn); + input_sock = g_socket_connection_get_socket (input_conn); + fail_unless (input_sock != NULL); + output_sock = g_socket_connection_get_socket (output_conn); + fail_unless (output_sock != NULL); + + fail_unless (gst_rtsp_connection_create_from_socket (input_sock, "127.0.0.1", + 4444, NULL, &rtsp_input_conn) == GST_RTSP_OK); + fail_unless (rtsp_input_conn != NULL); + + fail_unless (gst_rtsp_connection_create_from_socket (output_sock, "127.0.0.1", + 4444, NULL, &rtsp_output_conn) == GST_RTSP_OK); + fail_unless (rtsp_output_conn != NULL); + + /* send request message */ + fail_unless (gst_rtsp_message_new_request (&msg, GST_RTSP_SETUP, + "rtsp://example.com/") == GST_RTSP_OK); + fail_unless (gst_rtsp_message_add_header (msg, GST_RTSP_HDR_BLOCKSIZE, + "1024") == GST_RTSP_OK); + fail_unless (gst_rtsp_message_add_header_by_name (msg, "Custom-Header", + "lol") == GST_RTSP_OK); + fail_unless (gst_rtsp_connection_send (rtsp_output_conn, msg, + NULL) == GST_RTSP_OK); + fail_unless (gst_rtsp_message_free (msg) == GST_RTSP_OK); + msg = NULL; + + /* receive request message and make sure it is correct */ + fail_unless (gst_rtsp_message_new (&msg) == GST_RTSP_OK); + fail_unless (gst_rtsp_connection_receive (rtsp_input_conn, msg, NULL) == + GST_RTSP_OK); + fail_unless (gst_rtsp_message_get_type (msg) == GST_RTSP_MESSAGE_REQUEST); + /* check headers */ + fail_unless (gst_rtsp_message_get_header (msg, GST_RTSP_HDR_BLOCKSIZE, + &header_val, 0) == GST_RTSP_OK); + fail_unless (!g_strcmp0 (header_val, "1024")); + fail_unless (gst_rtsp_message_get_header_by_name (msg, "Custom-Header", + &header_val, 0) == GST_RTSP_OK); + fail_unless (!g_strcmp0 (header_val, "lol")); + fail_unless (gst_rtsp_message_free (msg) == GST_RTSP_OK); + msg = NULL; + + fail_unless (gst_rtsp_connection_close (rtsp_input_conn) == GST_RTSP_OK); + fail_unless (gst_rtsp_connection_free (rtsp_input_conn) == GST_RTSP_OK); + fail_unless (gst_rtsp_connection_close (rtsp_output_conn) == GST_RTSP_OK); + fail_unless (gst_rtsp_connection_free (rtsp_output_conn) == GST_RTSP_OK); + + g_object_unref (input_conn); + g_object_unref (output_conn); +} + +GST_END_TEST; + GST_START_TEST (test_rtspconnection_connect) { ServiceData *data; @@ -809,6 +872,7 @@ rtspconnection_suite (void) tcase_add_test (tc_chain, test_rtspconnection_tunnel_setup); tcase_add_test (tc_chain, test_rtspconnection_tunnel_setup_post_first); tcase_add_test (tc_chain, test_rtspconnection_send_receive); + tcase_add_test (tc_chain, test_rtspconnection_send_receive_check_headers); tcase_add_test (tc_chain, test_rtspconnection_connect); tcase_add_test (tc_chain, test_rtspconnection_poll); tcase_add_test (tc_chain, test_rtspconnection_backlog); |