From 856d06997c1494ed13ddad8eed3531d0852290c9 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 5 Oct 2011 15:18:35 +0200 Subject: [PATCH] Pazpar2 honors pz:url setting --- doc/pazpar2_conf.xml | 20 ++++++++ src/database.c | 5 +- src/database.h | 3 +- src/session.c | 6 ++- src/settings.c | 1 + src/settings.h | 3 +- test/Makefile.am | 3 +- test/test_url.cfg | 53 ++++++++++++++++++++++ test/test_url.sh | 14 ++++++ test/test_url.urls | 3 ++ test/test_url_1.res | 2 + test/test_url_2.res | 2 + test/test_url_3.res | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 232 insertions(+), 6 deletions(-) create mode 100644 test/test_url.cfg create mode 100755 test/test_url.sh create mode 100644 test/test_url.urls create mode 100644 test/test_url_1.res create mode 100644 test/test_url_2.res create mode 100644 test/test_url_3.res diff --git a/doc/pazpar2_conf.xml b/doc/pazpar2_conf.xml index ef4cdb9..1120185 100644 --- a/doc/pazpar2_conf.xml +++ b/doc/pazpar2_conf.xml @@ -750,6 +750,11 @@ multiple overlapping settings with the same name and target value, the 'precedence' attribute determines what happens. + + For Pazpar2 1.6.4 or later, the target ID may be user-defined, in + which case, the actual host, port, etc is given by setting + . + @@ -1233,6 +1238,21 @@ + + + pz:url + + + Specifies URL for the target and overrides the target ID. + + + + pz:url is only recognized for + Pazpar2 1.6.4 and later. + + + + diff --git a/src/database.c b/src/database.c index 873c7eb..ef3ae25 100644 --- a/src/database.c +++ b/src/database.c @@ -101,12 +101,13 @@ static struct host *find_host(database_hosts_t hosts, return p; } -int resolve_database(struct conf_service *service, struct database *db) +int resolve_database(struct conf_service *service, struct database *db, + const char *hostport) { if (db->host == 0) { struct host *host; - if (!(host = find_host(service->server->database_hosts, db->url))) + if (!(host = find_host(service->server->database_hosts, hostport))) return -1; db->host = host; } diff --git a/src/database.h b/src/database.h index 4b27826..3d9bfbf 100644 --- a/src/database.h +++ b/src/database.h @@ -30,7 +30,8 @@ int session_grep_databases(struct session *se, const char *filter, int predef_grep_databases(void *context, struct conf_service *service, void (*fun)(void *context, struct database *db)); int match_zurl(const char *zurl, const char *pattern); -int resolve_database(struct conf_service *service, struct database *db); +int resolve_database(struct conf_service *service, struct database *db, + const char *hostport); struct database *new_database(const char *id, NMEM nmem); database_hosts_t database_hosts_create(void); diff --git a/src/session.c b/src/session.c index 06e49e8..3567ab6 100644 --- a/src/session.c +++ b/src/session.c @@ -526,8 +526,12 @@ static void select_targets_callback(struct session *se, { struct client *cl = client_create(); struct client_list *l; + const char *url = session_setting_oneval(db, PZ_URL); + + if (!url || !*url) + url = db->database->url; - resolve_database(se->service, db->database); + resolve_database(se->service, db->database, url); client_set_database(cl, db); diff --git a/src/settings.c b/src/settings.c index 4d68651..fe1b8c4 100644 --- a/src/settings.c +++ b/src/settings.c @@ -76,6 +76,7 @@ static char *hard_settings[] = { "pz:query_syntax", "pz:facetmap:", "pz:limitmap:", + "pz:url", 0 }; diff --git a/src/settings.h b/src/settings.h index a71eea2..5a56750 100644 --- a/src/settings.h +++ b/src/settings.h @@ -49,7 +49,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define PZ_QUERY_SYNTAX 26 #define PZ_FACETMAP 27 #define PZ_LIMITMAP 28 -#define PZ_MAX_EOF 29 +#define PZ_URL 29 +#define PZ_MAX_EOF 30 struct setting { diff --git a/test/Makefile.am b/test/Makefile.am index e2121e8..e6521da 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,7 +1,7 @@ # This file is part of Pazpar2. check_SCRIPTS = test_http.sh test_icu.sh test_post.sh \ test_settings.sh test_turbomarcxml.sh test_facets.sh \ - test_solr.sh + test_solr.sh test_url.sh EXTRA_DIST = run_pazpar2.sh marc21_test.xsl tmarc.xsl solr-pz2.xsl \ z3950_indexdata_com_marc.xml \ @@ -13,6 +13,7 @@ EXTRA_DIST = run_pazpar2.sh marc21_test.xsl tmarc.xsl solr-pz2.xsl \ test_settings.cfg test_settings.urls \ test_solr.cfg test_solr.urls \ test_turbomarcxml.cfg test_turbomarcxml.urls \ + test_url.cfg test_url.urls \ $(check_SCRIPTS) TESTS = $(check_SCRIPTS) diff --git a/test/test_url.cfg b/test/test_url.cfg new file mode 100644 index 0000000..881ee65 --- /dev/null +++ b/test/test_url.cfg @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/test_url.sh b/test/test_url.sh new file mode 100755 index 0000000..dd6b88f --- /dev/null +++ b/test/test_url.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# + +# srcdir might be set by make +srcdir=${srcdir:-"."} + +# Test using test_http.cfg +exec ${srcdir}/run_pazpar2.sh test_url + +# Local Variables: +# mode:shell-script +# sh-indentation: 2 +# sh-basic-offset: 4 +# End: diff --git a/test/test_url.urls b/test/test_url.urls new file mode 100644 index 0000000..e2874fd --- /dev/null +++ b/test/test_url.urls @@ -0,0 +1,3 @@ +http://localhost:9763/search.pz2?command=init&clear=1&pz:elements%5Bmy%5D=F&pz:requestsyntax%5Bmy%5D=usmarc&pz:nativesyntax%5Bmy%5D=iso2709&pz:xslt%5Bmy%5D=marc21_test.xsl&pz:name%5Bmy%5D=marcserver&pz:url%5Bmy%5D=z3950.indexdata.com%2Fmarc +http://localhost:9763/search.pz2?session=1&command=search&query=computer +2 http://localhost:9763/search.pz2?session=1&command=show&block=1 diff --git a/test/test_url_1.res b/test/test_url_1.res new file mode 100644 index 0000000..81ff9ff --- /dev/null +++ b/test/test_url_1.res @@ -0,0 +1,2 @@ + +OK11 \ No newline at end of file diff --git a/test/test_url_2.res b/test/test_url_2.res new file mode 100644 index 0000000..ab63fe6 --- /dev/null +++ b/test/test_url_2.res @@ -0,0 +1,2 @@ + +OK \ No newline at end of file diff --git a/test/test_url_3.res b/test/test_url_3.res new file mode 100644 index 0000000..ca6ceb2 --- /dev/null +++ b/test/test_url_3.res @@ -0,0 +1,123 @@ + +OK +0 +9 +10 +0 +9 + + +How to program a computer +Jack Collins +How to program a computer +Jack Collins + +How to program a computer +Jack Collins +2 +25286 +title how to program a computer author jack collins medium book + + + +The Computer Bible +1973-1980 +Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates +The Computer Bible +1973-1980 +Hebrew and Greek; introductions in English +Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates +21072 +title the computer bible author medium book + + + +Computer science & technology +proceedings of a workshop held at the National Bureau of Standards, Gaithersburg, MD, June 3-4, 1976 +1977 +Computer science & technology +proceedings of a workshop held at the National Bureau of Standards, Gaithersburg, MD, June 3-4, 1976 +1977 +15804 +title computer science technology author medium book + + + +A plan for community college computer development +1971 +Cover title +A plan for community college computer development +1971 +Cover title +9030 +title a plan for community college computer development author medium book + + + +Washington metropolitan area rail computer feasibility study; +final report +1971 +Englund, Carl R +"Contract DOT-UT-10003." +Washington metropolitan area rail computer feasibility study; +final report +1971 +Englund, Carl R +"Contract DOT-UT-10003." +9030 +title washington metropolitan area rail computer feasibility study author englund carl r medium book + + + +The Puget Sound Region +a portfolio of thematic computer maps +1974 +Mairs, John W +Scale of maps ca. 1:1,000,000 +The Puget Sound Region +a portfolio of thematic computer maps +1974 +Mairs, John W +Scale of maps ca. 1:1,000,000 +Bibliography: p. 4 +8780 +title the puget sound region author mairs john w medium book + + + +Computer processing of dynamic images from an Anger scintillation camera +the proceedings of a workshop +1974 +Includes bibliographical references and index +Computer processing of dynamic images from an Anger scintillation camera +the proceedings of a workshop +1974 +Includes bibliographical references and index +6321 +title computer processing of dynamic images from an anger scintillation camera author medium book + + + +The use of passwords for controlled access to computer resources +1977 +Wood, Helen M +The use of passwords for controlled access to computer resources +1977 +Wood, Helen M +6321 +title the use of passwords for controlled access to computer resources author wood helen m medium book + + + +Reconstruction tomography in diagnostic radiology and nuclear medicine +proceedings of the workshop +1977 +Includes bibliographical references and index +Reconstruction tomography in diagnostic radiology and nuclear medicine +proceedings of the workshop +1977 +Includes bibliographical references and index +0 +title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book + + \ No newline at end of file -- 1.7.10.4