From 6fd511dd41c8925e70c8e3c0ab2bcde8e1af06de Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 29 Aug 2010 21:09:48 +0200 Subject: Support for fetching files via HTTP, needs more work and fixes. --- commands.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'commands.c') diff --git a/commands.c b/commands.c index 4108cff..bde61cd 100644 --- a/commands.c +++ b/commands.c @@ -175,6 +175,31 @@ static void commands_exit(GSocketConnection *connection, const gchar *cmd, GErro g_socket_close(socket, NULL); } +static void commands_get(GSocketConnection *connection, const gchar *cmd, GError **error) { + gchar **data = g_strsplit(cmd, " ", 5); + + if(g_strv_length(data) != 5) { + g_strfreev(data); + *error = g_error_new(commands_quark(), 0, "syntax: get TYPE LOCALFILE REMOTEHOST REMOTEFILE"); + return; + } + + struct server *server = NULL; + + for(GSList *node = servers; node; node = g_slist_next(node)) { + struct server *temp = node->data; + if(g_strcasecmp(temp->host, data[3]) == 0) { + server = temp; + break; + } + } + + + server_get(server, data[1], data[2], data[4]); + + g_strfreev(data); +} + void commands_handle(GSocketConnection *connection, const gchar *cmd, GError **error) { g_debug(cmd); if(g_strncasecmp(cmd, "ping", 4) == 0) { @@ -185,6 +210,8 @@ void commands_handle(GSocketConnection *connection, const gchar *cmd, GError **e commands_find(connection, cmd, error); } else if(g_strncasecmp(cmd, "exit", 4) == 0) { commands_exit(connection, cmd, error); + } else if(g_strncasecmp(cmd, "get", 3) == 0) { + commands_get(connection, cmd, error); } else { g_debug("unknown command"); *error = g_error_new(commands_quark(), 0, "unknown command %s", cmd); -- cgit v1.2.3