summaryrefslogtreecommitdiff
path: root/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c27
1 files changed, 27 insertions, 0 deletions
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);