From 96548165dec8715083c5156ce80d8ea623d088bb Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Thu, 11 Jan 2007 17:14:06 +0000 Subject: [PATCH] Read HTTP listener and proxy address from config file (-h and -p still override). Moved pazpar2.cfg to pazpar2.cfg.dist to facilitate local setups Only -s is still required. --- etc/pazpar2.cfg | 27 ---------------------- etc/pazpar2.cfg.dist | 27 ++++++++++++++++++++++ src/config.h | 4 +++- src/http_command.c | 13 ++++++++++- src/pazpar2.c | 61 +++++++++++++++++++++++++++++++++++++++++--------- src/pazpar2.h | 2 ++ 6 files changed, 94 insertions(+), 40 deletions(-) delete mode 100644 etc/pazpar2.cfg create mode 100644 etc/pazpar2.cfg.dist diff --git a/etc/pazpar2.cfg b/etc/pazpar2.cfg deleted file mode 100644 index 3ea7efa..0000000 --- a/etc/pazpar2.cfg +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - marc21 - - - - - diff --git a/etc/pazpar2.cfg.dist b/etc/pazpar2.cfg.dist new file mode 100644 index 0000000..04aa241 --- /dev/null +++ b/etc/pazpar2.cfg.dist @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + marc21 + + + + + diff --git a/src/config.h b/src/config.h index 56caece..3077451 100644 --- a/src/config.h +++ b/src/config.h @@ -12,6 +12,7 @@ struct conf_metadata int brief; // Is this element to be returned in the brief format? int termlist;// Is this field to be treated as a termlist for browsing? int rank; // Rank factor. 0 means don't use this field for ranking, 1 is default + // values >1 give additional significance to a field enum { Metadata_type_generic, // Generic text field @@ -23,7 +24,8 @@ struct conf_metadata Metadata_sortkey_no, // This is not to be used as a sortkey Metadata_sortkey_numeric, // Standard numerical sorting Metadata_sortkey_range, // Range sorting (pick lowest or highest) - Metadata_sortkey_skiparticle // Skip leading article when sorting + Metadata_sortkey_skiparticle, // Skip leading article when sorting + Metadata_sortkey_string } sortkey; enum { diff --git a/src/http_command.c b/src/http_command.c index 1fef304..e29a1bb 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,5 +1,5 @@ /* - * $Id: http_command.c,v 1.17 2007-01-11 10:03:01 sondberg Exp $ + * $Id: http_command.c,v 1.18 2007-01-11 17:14:06 quinn Exp $ */ #include @@ -17,6 +17,7 @@ #include +#include "config.h" #include "util.h" #include "eventl.h" #include "pazpar2.h" @@ -498,6 +499,15 @@ static void cmd_stat(struct http_channel *c) http_send_response(c); } +static void cmd_info(struct http_channel *c) +{ + struct http_request *rq = c->request; + struct http_response *rs = c->response; + struct http_session *s = locate_session(rq, rs); + + if (!s) + return; +} struct { char *name; @@ -512,6 +522,7 @@ struct { { "exit", cmd_exit }, { "ping", cmd_ping }, { "record", cmd_record }, + { "info", cmd_info }, {0,0} }; diff --git a/src/pazpar2.c b/src/pazpar2.c index 1fe17a8..e7b2b4a 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.26 2007-01-10 11:56:10 adam Exp $ */ +/* $Id: pazpar2.c,v 1.27 2007-01-11 17:14:06 quinn Exp $ */ #include #include @@ -72,6 +72,8 @@ static char *client_states[] = { // Note: Some things in this structure will eventually move to configuration struct parameters global_parameters = { + "", + "", 0, 0, 30, @@ -1397,11 +1399,53 @@ static CCL_bibset load_cclfile(const char *fn) return res; } +static void start_http_listener(void) +{ + char hp[128] = ""; + struct conf_server *ser = global_parameters.server; + + if (*global_parameters.listener_override) + strcpy(hp, global_parameters.listener_override); + else + { + strcpy(hp, ser->host ? ser->host : ""); + if (ser->port) + { + if (*hp) + strcat(hp, ":"); + sprintf(hp + strlen(hp), "%d", ser->port); + } + } + http_init(hp); +} + +static void start_proxy(void) +{ + char hp[128] = ""; + struct conf_server *ser = global_parameters.server; + + if (*global_parameters.proxy_override) + strcpy(hp, global_parameters.proxy_override); + else if (ser->proxy_host || ser->proxy_port) + { + strcpy(hp, ser->proxy_host ? ser->proxy_host : ""); + if (ser->proxy_port) + { + if (*hp) + strcat(hp, ":"); + sprintf(hp + strlen(hp), "%d", ser->proxy_port); + } + } + else + return; + + http_set_proxyaddr(hp); +} + int main(int argc, char **argv) { int ret; char *arg; - int setport = 0; if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) yaz_log(YLOG_WARN|YLOG_ERRNO, "signal"); @@ -1416,14 +1460,13 @@ int main(int argc, char **argv) exit(1); break; case 'h': - http_init(arg); - setport++; + strcpy(global_parameters.listener_override, arg); break; case 'C': global_parameters.ccl_filter = load_cclfile(arg); break; case 'p': - http_set_proxyaddr(arg); + strcpy(global_parameters.proxy_override, arg); break; case 's': load_simpletargets(arg); @@ -1449,12 +1492,8 @@ int main(int argc, char **argv) } global_parameters.server = config->servers; - if (!setport) - { - fprintf(stderr, "Set command port with -h\n"); - exit(1); - } - + start_http_listener(); + start_proxy(); global_parameters.ccl_filter = load_cclfile("../etc/default.bib"); global_parameters.yaz_marc = yaz_marc_create(); yaz_marc_subfield_str(global_parameters.yaz_marc, "\t"); diff --git a/src/pazpar2.h b/src/pazpar2.h index b075232..50b0a1b 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -169,6 +169,8 @@ struct hitsbytarget { }; struct parameters { + char proxy_override[128]; + char listener_override[128]; struct conf_server *server; int dump_records; int timeout; /* operations timeout, in seconds */ -- 1.7.10.4