diff options
-rw-r--r-- | control_commands.c | 25 | ||||
-rw-r--r-- | servers.c | 3 | ||||
-rw-r--r-- | servers.h | 2 |
3 files changed, 23 insertions, 7 deletions
diff --git a/control_commands.c b/control_commands.c index f5fbc64..61477ac 100644 --- a/control_commands.c +++ b/control_commands.c @@ -1,14 +1,27 @@ #include "control_commands.h" +#include "servers.h" #include <glib.h> #include <string.h> -void control_commands_handle(GSocketConnection *connection, const gchar *cmd) { - gchar *args = strchr(cmd, ' '); - if(args != NULL) { - *args = '\0'; - args++; +static void list_servers(GSocketConnection *connection, const gchar *cmd) { + GSocket *socket = g_socket_connection_get_socket(connection); + + for(GSList *node = servers; node; node = g_slist_next(node)) { + struct server *s = node->data; + gchar *buffer = g_strdup_printf("%s:%d\n", s->host, s->port); + g_socket_send(socket, buffer, strlen(buffer), NULL, NULL); } +} - g_debug("handling command %s with arguments %s", cmd, args); +void control_commands_handle(GSocketConnection *connection, const gchar *cmd) { + if(g_strcmp0(cmd, "servers") == 0) { + list_servers(connection, cmd); + } else { + g_debug("unknown command"); + gchar *buf = g_strdup_printf("error: unknown command %s\n", cmd); + GSocket *socket = g_socket_connection_get_socket(connection); + g_socket_send(socket, buf, strlen(buf), NULL, NULL); + g_free(buf); + } } @@ -1,7 +1,7 @@ #include "servers.h" #include "conf.h" -static GSList *servers = NULL; +GSList *servers = NULL; gboolean server_add(const gchar *host, const guint16 port) { struct server *server = g_new0(struct server, 1); @@ -35,6 +35,7 @@ void servers_init() { gsize length; gchar **s = conf_get_string_list("audist", "servers", &length); for(int i = 0; i < length; i++) { + server_add(s[i], 0); g_debug(" server %d: %s", i, s[i]); } } @@ -8,6 +8,8 @@ struct server { guint16 port; }; +extern GSList *servers; + gboolean server_add(const gchar *host, const guint16 port); gboolean server_remove(struct server *server); void servers_init(); |