From c586ade2977ae5f6bf01f24cc7c8a84492c544a8 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 11 Oct 2013 13:01:22 +0200 Subject: [PATCH] GFS: Allow multiple listenrefs YAZ-554 --- doc/gfs-virtual.xml | 19 +++++++++++-------- src/session.h | 2 +- src/statserv.c | 42 +++++++++++++++++++++++++++++------------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/doc/gfs-virtual.xml b/doc/gfs-virtual.xml index 18d68dd..1250331 100644 --- a/doc/gfs-virtual.xml +++ b/doc/gfs-virtual.xml @@ -84,10 +84,11 @@ attribute listenref (optional) - Specifies listener for this server. If this attribute is not - given, the server is accessible from all listener. In order - for the server to be used for real, howeever, the virtual host - must match (if specified in the configuration). + Specifies one or more listeners for this server. Each server ID is + separated by a comma. + If this attribute is not given, the server is accessible from all + listeners. In order for the server to be used for real, however, the + virtual host must match if specified in the configuration. @@ -220,7 +221,7 @@ /var/www/s1 config.cfg - + server2.mydomain /var/www/s2 config.cfg @@ -243,9 +244,11 @@ There are three configured backend servers. The first two servers, "server1" and "server2", - can be reached by both listener addresses - since - no listenref attribute is specified. - In order to distinguish between the two a virtual host has + can be reached by both listener addresses. + "server1" is reached by all (two) since no + listenref attribute is specified. + "server2" is reached by the two listeners specified. + In order to distinguish between the two, a virtual host has been specified for each of server in the host elements. diff --git a/src/session.h b/src/session.h index 1b13364..90ee0b1 100644 --- a/src/session.h +++ b/src/session.h @@ -44,7 +44,7 @@ struct gfs_server { statserv_options_block cb; char *host; char *id; - int listen_ref; + int *listen_ref; cql_transform_t cql_transform; CCL_bibset ccl_transform; void *server_node_ptr; diff --git a/src/statserv.c b/src/statserv.c index adf1443..e3b09c5 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -286,9 +286,15 @@ int control_association(association *assoc, const char *host, int force_open) int host_match = 0; if ( !gfs->host || (host && gfs->host && !strcmp(host, gfs->host))) host_match = 1; - if (!gfs->listen_ref || - gfs->listen_ref == assoc->client_chan->chan_id) + if (!gfs->listen_ref) listen_match = 1; + else + { + int i; + for (i = 0; gfs->listen_ref[i] != -1; i++) + if (gfs->listen_ref[i] == assoc->client_chan->chan_id) + listen_match = 1; + } if (listen_match && host_match) { if (force_open || @@ -390,17 +396,27 @@ static void xml_config_read(const char *base_path) gfs->server_node_ptr = ptr_server; if (listenref) { - int id_no; - struct gfs_listen *gl = gfs_listen_list; - for (id_no = 1; gl; gl = gl->next, id_no++) - if (gl->id && !strcmp(gl->id, listenref)) - { - gfs->listen_ref = id_no; - break; - } - if (!gl) - yaz_log(YLOG_WARN, "Non-existent listenref '%s' in server " - "config element", listenref); + char **refs; + int num, i; + nmem_strsplit(gfs_nmem, ",", listenref, &refs, &num); + gfs->listen_ref = (int*) nmem_malloc(gfs_nmem, + sizeof(int) * (num + 1)); + for (i = 0; i < num; i++) + { + int id_no; + struct gfs_listen *gl = gfs_listen_list; + gfs->listen_ref[i] = 0; + for (id_no = 1; gl; gl = gl->next, id_no++) + if (gl->id && !strcmp(gl->id, refs[i])) + { + gfs->listen_ref[i] = id_no; + break; + } + if (!gl) + yaz_log(YLOG_WARN, "Non-existent listenref '%s' " + "in server config element", refs[i]); + } + gfs->listen_ref[i] = -1; } for (ptr = ptr_server->children; ptr; ptr = ptr->next) { -- 1.7.10.4