summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-21 13:18:36 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-21 13:18:36 +0200
commit9558cc7031e84afc00eea62de22a494b34d653e9 (patch)
tree24f760701600c109e4c751a82aec4893abd1ace2
parentd57e4b1dd22b7243ff3ee44036ff17af966a200b (diff)
Added a server list command to the control service.
-rw-r--r--control_commands.c25
-rw-r--r--servers.c3
-rw-r--r--servers.h2
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);
+ }
}
diff --git a/servers.c b/servers.c
index f46eaae..22e431d 100644
--- a/servers.c
+++ b/servers.c
@@ -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]);
}
}
diff --git a/servers.h b/servers.h
index b6e809b..f727bbd 100644
--- a/servers.h
+++ b/servers.h
@@ -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();