summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluis <ldearquer@gmail.com>2015-05-10 18:11:16 +0200
committerluis <ldearquer@gmail.com>2015-05-10 18:11:16 +0200
commite16c61bdb14b7f30200620271b9c23b69fca608e (patch)
treec22c6e7badae9832e5f956578202bec4601a653b
parent160245626d7b0e742b7177724b029a61fdcf7148 (diff)
Reduce duplicated code, using the same code for the HEAD and GET
requests.
-rw-r--r--http-launch/src/http-launch.c59
1 files changed, 18 insertions, 41 deletions
diff --git a/http-launch/src/http-launch.c b/http-launch/src/http-launch.c
index 0921ce7..91cf8d0 100644
--- a/http-launch/src/http-launch.c
+++ b/http-launch/src/http-launch.c
@@ -125,42 +125,16 @@ send_response_404_not_found (Client * client)
static void
client_message (Client * client, const gchar * data, guint len)
{
+ gboolean http_head_request = FALSE;
+ gboolean http_get_request = FALSE;
gchar **lines = g_strsplit_set (data, "\r\n", -1);
- if (g_str_has_prefix (lines[0], "HEAD")) {
- gchar **parts = g_strsplit (lines[0], " ", -1);
- gboolean ok = FALSE;
-
- g_free (client->http_version);
+ if (g_str_has_prefix (lines[0], "HEAD"))
+ http_head_request = TRUE;
+ else if (g_str_has_prefix (lines[0], "GET"))
+ http_get_request = TRUE;
- if (parts[1] && parts[2] && *parts[2] != '\0')
- client->http_version = g_strdup (parts[2]);
- else
- client->http_version = g_strdup ("HTTP/1.0");
-
- if (parts[1] && strcmp (parts[1], "/") == 0) {
- G_LOCK (caps);
- if (caps_resolved)
- send_response_200_ok (client);
- else
- client->waiting_200_ok = TRUE;
- G_UNLOCK (caps);
- ok = TRUE;
- } else {
- send_response_404_not_found (client);
- }
- g_strfreev (parts);
-
- if (ok && !started) {
- g_print ("Starting pipeline\n");
- if (gst_element_set_state (pipeline,
- GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
- g_print ("Failed to start pipeline\n");
- g_main_loop_quit (loop);
- }
- started = TRUE;
- }
- } else if (g_str_has_prefix (lines[0], "GET")) {
+ if (http_head_request || http_get_request) {
gchar **parts = g_strsplit (lines[0], " ", -1);
gboolean ok = FALSE;
@@ -185,14 +159,17 @@ client_message (Client * client, const gchar * data, guint len)
g_strfreev (parts);
if (ok) {
- g_source_destroy (client->isource);
- g_source_unref (client->isource);
- client->isource = NULL;
- g_source_destroy (client->tosource);
- g_source_unref (client->tosource);
- client->tosource = NULL;
- g_print ("Starting to stream to %s\n", client->name);
- g_signal_emit_by_name (multisocketsink, "add", client->socket);
+ if (http_get_request) {
+ /* Start streaming to client socket */
+ g_source_destroy (client->isource);
+ g_source_unref (client->isource);
+ client->isource = NULL;
+ g_source_destroy (client->tosource);
+ g_source_unref (client->tosource);
+ client->tosource = NULL;
+ g_print ("Starting to stream to %s\n", client->name);
+ g_signal_emit_by_name (multisocketsink, "add", client->socket);
+ }
if (!started) {
g_print ("Starting pipeline\n");