summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-30 22:12:45 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-30 22:12:45 +0200
commit651ebc75e6dae751bdebffe018701618afcc49df (patch)
treef707d3b3f47f2800f19744c87cf68de100cfe027
parenta15c8f6e8a20d60d1097ede16a63b7f350af052c (diff)
Added separate http and command ports in server struct.
-rw-r--r--server_communication.c77
-rw-r--r--servers.c15
-rw-r--r--servers.h6
3 files changed, 43 insertions, 55 deletions
diff --git a/server_communication.c b/server_communication.c
index ffe6942..e8ab7b8 100644
--- a/server_communication.c
+++ b/server_communication.c
@@ -4,7 +4,12 @@
#include <gio/gio.h>
#include <string.h>
-static GSocket *server_connect(struct server *server) {
+enum connection_type {
+ SERVER_CONNECTION_TYPE_HTTP,
+ SERVER_CONNECTION_TYPE_COMMAND,
+};
+
+static GSocket *server_connect(struct server *server, const enum connection_type type) {
GError *error = NULL, *conn_error = NULL;
GSocketConnectable *addr;
GSocketAddressEnumerator *enumerator;
@@ -12,7 +17,17 @@ static GSocket *server_connect(struct server *server) {
GSocketConnection *conn = NULL;
GSocketClient *client;
- addr = g_network_address_new(server->host, server->port);
+ guint16 port;
+ switch(type) {
+ case SERVER_CONNECTION_TYPE_HTTP:
+ port = server->http_port;
+ break;
+ case SERVER_CONNECTION_TYPE_COMMAND:
+ port = server->command_port;
+ break;
+ }
+
+ addr = g_network_address_new(server->host, port);
enumerator = g_socket_connectable_enumerate(addr);
g_object_unref(addr);
@@ -47,9 +62,17 @@ static GSocket *server_connect(struct server *server) {
return socket;
}
+static GSocket *server_connect_http(struct server *server) {
+ return server_connect(server, SERVER_CONNECTION_TYPE_HTTP);
+}
+
+static GSocket *server_connect_command(struct server *server) {
+ return server_connect(server, SERVER_CONNECTION_TYPE_COMMAND);
+}
+
gboolean server_ping(struct server *server) {
GTimer *timer = g_timer_new();
- GSocket *socket = server_connect(server);
+ GSocket *socket = server_connect_command(server);
if(socket == NULL) {
return FALSE;
@@ -72,7 +95,7 @@ gboolean server_ping(struct server *server) {
}
static gchar **server_get_stringlist(struct server *server, const gchar *cmd) {
- GSocket *socket = server_connect(server);
+ GSocket *socket = server_connect_command(server);
if(socket == NULL) {
return NULL;
@@ -111,54 +134,10 @@ gchar **server_list(struct server *server, const gchar *directory) {
return data;
}
-/* TODO: remove temporary function */
-static GSocket *server_connect_port(struct server *server, gushort port) {
- GError *error = NULL, *conn_error = NULL;
- GSocketConnectable *addr;
- GSocketAddressEnumerator *enumerator;
- GSocketAddress *sockaddr;
- GSocketConnection *conn = NULL;
- GSocketClient *client;
-
- addr = g_network_address_new(server->host, port);
- enumerator = g_socket_connectable_enumerate(addr);
- g_object_unref(addr);
-
- client = g_socket_client_new();
-
- while(conn == NULL && (sockaddr = g_socket_address_enumerator_next(enumerator, NULL, &error))) {
- conn = g_socket_client_connect(client, (GSocketConnectable*)sockaddr, NULL, &conn_error);
- g_object_unref(sockaddr);
- }
-
- if(sockaddr == NULL) {
- if(error != NULL) {
- g_warning(error->message);
- g_error_free(error);
- } else {
- g_warning("server_connect: no connectable addresses found for host %s",
- server->host);
- }
- return NULL;
- }
-
- if(conn == NULL) {
- g_warning(conn_error->message);
- g_error_free(conn_error);
- return NULL;
- }
-
- GSocket *socket = g_socket_connection_get_socket(conn);
-
- g_debug("connected");
-
- return socket;
-}
-
gboolean server_get(struct server *server, const gchar *type,
const gchar *localfile, const gchar *remotefile) {
GError *error = NULL;
- GSocket *socket = server_connect_port(server, 8000);
+ GSocket *socket = server_connect_http(server);
if(socket == NULL) {
return FALSE;
diff --git a/servers.c b/servers.c
index 890f6b1..2101395 100644
--- a/servers.c
+++ b/servers.c
@@ -5,7 +5,8 @@
GSList *servers = NULL;
-gboolean server_add(const gchar *host, const guint16 port) {
+gboolean server_add(const gchar *host, const guint16 http_port,
+ const guint16 command_port) {
struct server *server = g_new0(struct server, 1);
if(server == NULL) {
@@ -14,7 +15,8 @@ gboolean server_add(const gchar *host, const guint16 port) {
}
server->host = g_strdup(host);
- server->port = port;
+ server->http_port = http_port;
+ server->command_port = command_port;
servers = g_slist_prepend(servers, server);
@@ -37,8 +39,13 @@ 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]);
+ gchar *section = g_strdup_printf("server/%s", s[i]);
+ guint16 http_port = conf_get_int(section, "http_port");
+ guint16 command_port = conf_get_int(section, "command_port");
+ g_free(section);
+
+ server_add(s[i], http_port, command_port);
+ g_debug(" server %d: %s (%d, %d)", i, s[i], http_port, command_port);
}
}
diff --git a/servers.h b/servers.h
index f727bbd..694e8a2 100644
--- a/servers.h
+++ b/servers.h
@@ -5,12 +5,14 @@
struct server {
gchar *host;
- guint16 port;
+ guint16 http_port;
+ guint16 command_port;
};
extern GSList *servers;
-gboolean server_add(const gchar *host, const guint16 port);
+gboolean server_add(const gchar *host, const guint16 http_port,
+ const guint16 command_port);
gboolean server_remove(struct server *server);
void servers_init();
void servers_free();