diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-08-23 23:11:41 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-08-23 23:11:41 +0200 |
commit | 03b8bec204e909f28ddafb282414e5392ba172ed (patch) | |
tree | 92ce5834ce3268fba1ce9266b97474a4c488d818 | |
parent | 2fb4e229bc21e7686d28179420bbead35701a558 (diff) | |
parent | 59c6f7d3f5b4d62be569c5bddc6a9306cba0627d (diff) |
Merge branch 'master' of /mnt/komachi/audist
-rw-r--r-- | command_service.c | 19 | ||||
-rw-r--r-- | commands.c | 7 |
2 files changed, 16 insertions, 10 deletions
diff --git a/command_service.c b/command_service.c index 562c7f4..5d357da 100644 --- a/command_service.c +++ b/command_service.c @@ -25,17 +25,16 @@ static gboolean service_incoming(GSocketService *service, g_debug("size == %ld", size); g_debug(buffer); - gchar *pos = g_strstr_len(buffer, size, "\r"); - if(pos == NULL) { - pos = g_strstr_len(buffer, size, "\n"); - } - if(pos == NULL) { - g_warning("EOL not found"); - return FALSE; - } - *pos = '\0'; + gchar *pos, *eol; + pos = buffer; + while((eol = g_strstr_len(pos, size, "\n")) != NULL || (eol = g_strstr_len(pos, size, "\r")) != NULL) { + *eol = '\0'; - commands_handle(connection, buffer); + commands_handle(connection, pos); + + size -= eol - pos + 1; + pos = eol + 1; + } } return FALSE; @@ -103,6 +103,11 @@ static void commands_ping(GSocketConnection *connection, const gchar *cmd) { } } +static void commands_exit(GSocketConnection *connection, const gchar *cmd) { + GSocket *socket = g_socket_connection_get_socket(connection); + g_socket_close(socket, NULL); +} + void commands_handle(GSocketConnection *connection, const gchar *cmd) { g_debug(cmd); if(g_strncasecmp(cmd, "ping", 4) == 0) { @@ -111,6 +116,8 @@ void commands_handle(GSocketConnection *connection, const gchar *cmd) { commands_list(connection, cmd); } else if(g_strncasecmp(cmd, "find", 4) == 0) { commands_find(connection, cmd); + } else if(g_strncasecmp(cmd, "exit", 4) == 0) { + commands_exit(connection, cmd); } else { g_debug("unknown command"); gchar *buf = g_strdup_printf("error: unknown command %s\n", cmd); |