blob: 890f6b1576f00db1d35e8eedcf65ecae9f69e13a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include "servers.h"
#include "conf.h"
#include <gio/gio.h>
GSList *servers = NULL;
gboolean server_add(const gchar *host, const guint16 port) {
struct server *server = g_new0(struct server, 1);
if(server == NULL) {
g_warning("server_add: g_new0 returned NULL");
return FALSE;
}
server->host = g_strdup(host);
server->port = port;
servers = g_slist_prepend(servers, server);
return TRUE;
}
gboolean server_remove(struct server *server) {
gint pos = g_slist_index(servers, server);
if(pos == -1) {
return FALSE;
}
servers = g_slist_remove(servers, server);
return TRUE;
}
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], 7681);
g_debug(" server %d: %s", i, s[i]);
}
}
void servers_free() {
for(GSList *node = servers; node; node = g_slist_next(node)) {
struct server *s = node->data;
g_free(s->host);
}
g_slist_free(servers);
servers = NULL;
}
|