summaryrefslogtreecommitdiff
path: root/network
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
commitfdf0d5814318103bf34aaf80d32184797232e987 (patch)
treef9e824760e01cff1092443ec45996a21bac36d4e /network
parent82c788e77f286afe4916f5e86d8594b687e679ad (diff)
network/http-launch: Reduce duplicated code, using the same code for the HEAD and GET
requests.
Diffstat (limited to 'network')
-rw-r--r--network/http-launch/http-launch.c59
1 files changed, 18 insertions, 41 deletions
diff --git a/network/http-launch/http-launch.c b/network/http-launch/http-launch.c
index 0921ce7..91cf8d0 100644
--- a/network/http-launch/http-launch.c
+++ b/network/http-launch/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");