From f43cd305004f347e27d2bc6f9a9214fcada8aeff Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 24 Sep 2009 15:06:35 +0200 Subject: [PATCH] POST of target settings. Command settings now looks for posted content , content-type=text/xml, in which case that is XML parsed in the same way as "static" target settings. --- src/http_command.c | 40 ++++++++++++++++++-- src/settings.c | 36 +++++++++--------- src/settings.h | 4 ++ src/util.h | 26 ------------- test/test_post_10.res | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ test/test_post_11.res | 8 ++++ test/test_post_5.res | 27 +------------ test/test_post_6.res | 101 +------------------------------------------------ test/test_post_8.res | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ test/test_post_9.res | 26 +++++++++++++ test/test_post_urls | 9 ++++- 11 files changed, 303 insertions(+), 174 deletions(-) delete mode 100644 src/util.h create mode 100644 test/test_post_10.res create mode 100644 test/test_post_11.res create mode 100644 test/test_post_8.res create mode 100644 test/test_post_9.res diff --git a/src/http_command.c b/src/http_command.c index 616a48c..e9d1ff8 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -249,9 +249,10 @@ static void cmd_init(struct http_channel *c) unsigned int sesid; struct http_session *s; struct http_response *rs = c->response; - struct conf_service *service; + struct conf_service *service = 0; /* no service (yet) */ - if (content_type && !yaz_strcmp_del("text/xml", content_type, "; ")) + if (r->content_len && content_type && + !yaz_strcmp_del("text/xml", content_type, "; ")) { xmlDoc *doc = xmlParseMemory(r->content_buf, r->content_len); xmlNode *root_n; @@ -263,8 +264,14 @@ static void cmd_init(struct http_channel *c) root_n = xmlDocGetRootElement(doc); service = service_create(c->server, root_n); xmlFreeDoc(doc); + if (!service) + { + error(rs, PAZPAR2_MALFORMED_SETTING, 0); + return; + } } - else + + if (!service) { const char *service_name = http_argbyname(c->request, "service"); service = locate_service(c->server, service_name); @@ -293,15 +300,42 @@ static void cmd_init(struct http_channel *c) http_send_response(c); } +static void apply_local_setting(void *client_data, + struct setting *set) +{ + struct session *se = (struct session *) client_data; + + session_apply_setting(se, nmem_strdup(se->session_nmem, set->target), + nmem_strdup(se->session_nmem, set->name), + nmem_strdup(se->session_nmem, set->value)); +} + static void cmd_settings(struct http_channel *c) { struct http_response *rs = c->response; struct http_request *rq = c->request; struct http_session *s = locate_session(rq, rs); + const char *content_type = http_lookup_header(rq->headers, "Content-Type"); if (!s) return; + if (rq->content_len && content_type && + !yaz_strcmp_del("text/xml", content_type, "; ")) + { + xmlDoc *doc = xmlParseMemory(rq->content_buf, rq->content_len); + xmlNode *root_n; + if (!doc) + { + error(rs, PAZPAR2_MALFORMED_SETTING, 0); + return; + } + root_n = xmlDocGetRootElement(doc); + + settings_read_node_x(root_n, s->psession, apply_local_setting); + + xmlFreeDoc(doc); + } if (process_settings(s->psession, rq, rs) < 0) return; rs->payload = "OK"; diff --git a/src/settings.c b/src/settings.c index 3b7a923..a829e6d 100644 --- a/src/settings.c +++ b/src/settings.c @@ -133,10 +133,10 @@ static int isdir(const char *path) } // Read settings from an XML file, calling handler function for each setting -static void read_settings_node(xmlNode *n, - struct conf_service *service, - void (*fun)(struct conf_service *service, - struct setting *set)) +void settings_read_node_x(xmlNode *n, + void *client_data, + void (*fun)(void *client_data, + struct setting *set)) { xmlChar *namea, *targeta, *valuea, *usera, *precedencea; @@ -195,7 +195,7 @@ static void read_settings_node(xmlNode *n, strcpy(valueb, (const char *) valuea); set.value = valueb; set.next = 0; - (*fun)(service, &set); + (*fun)(client_data, &set); } xmlFree(name); xmlFree(precedence); @@ -217,8 +217,8 @@ static void read_settings_node(xmlNode *n, } static void read_settings_file(const char *path, - struct conf_service *service, - void (*fun)(struct conf_service *service, + void *client_data, + void (*fun)(void *client_data, struct setting *set)) { xmlDoc *doc = xmlParseFile(path); @@ -230,7 +230,7 @@ static void read_settings_file(const char *path, exit(1); } n = xmlDocGetRootElement(doc); - read_settings_node(n, service, fun); + settings_read_node_x(n, client_data, fun); xmlFreeDoc(doc); } @@ -239,8 +239,8 @@ static void read_settings_file(const char *path, // Recursively read files or directories, invoking a // callback for each one static void read_settings(const char *path, - struct conf_service *service, - void (*fun)(struct conf_service *service, + void *client_data, + void (*fun)(void *client_data, struct setting *set)) { DIR *d; @@ -260,12 +260,12 @@ static void read_settings(const char *path, if (*de->d_name == '.' || !strcmp(de->d_name, "CVS")) continue; sprintf(tmp, "%s/%s", path, de->d_name); - read_settings(tmp, service, fun); + read_settings(tmp, client_data, fun); } closedir(d); } else if ((dot = strrchr(path, '.')) && !strcmp(dot + 1, "xml")) - read_settings_file(path, service, fun); + read_settings_file(path, client_data, fun); } // Determines if a ZURL is a wildcard, and what kind @@ -380,9 +380,9 @@ static void update_database(void *context, struct database *db) // Callback -- updates database records with dictionary entries as appropriate // This is used in pass 2 to assign name/value pairs to databases -static void update_databases(struct conf_service *service, - struct setting *set) +static void update_databases(void *client_data, struct setting *set) { + struct conf_service *service = (struct conf_service *) client_data; struct update_database_context context; context.set = set; context.service = service; @@ -423,9 +423,9 @@ static void initialize_soft_settings(struct conf_service *service) } } -static void prepare_target_dictionary(struct conf_service *service, - struct setting *set) +static void prepare_target_dictionary(void *client_data, struct setting *set) { + struct conf_service *service = (struct conf_service *) client_data; struct setting_dictionary *dictionary = service->dictionary; int i; @@ -470,9 +470,9 @@ void settings_read_node(struct conf_service *service, xmlNode *n, int pass) { if (pass == 1) - read_settings_node(n, service, prepare_target_dictionary); + settings_read_node_x(n, service, prepare_target_dictionary); else - read_settings_node(n, service, update_databases); + settings_read_node_x(n, service, update_databases); } /* diff --git a/src/settings.h b/src/settings.h index 623a477..42ac11a 100644 --- a/src/settings.h +++ b/src/settings.h @@ -58,6 +58,10 @@ int settings_offset(struct conf_service *service, const char *name); int settings_offset_cprefix(struct conf_service *service, const char *name); void init_settings(struct conf_service *service); void resolve_databases(struct conf_service *service); +void settings_read_node_x(xmlNode *n, + void *client_data, + void (*fun)(void *client_data, + struct setting *set)); #endif diff --git a/src/util.h b/src/util.h deleted file mode 100644 index f8ea2ea..0000000 --- a/src/util.h +++ /dev/null @@ -1,26 +0,0 @@ -/* This file is part of Pazpar2. - Copyright (C) 2006-2009 Index Data - -Pazpar2 is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#ifndef UTIL_H -#define UTIL_H - -void die(char *string, char *add); - - -#endif diff --git a/test/test_post_10.res b/test/test_post_10.res new file mode 100644 index 0000000..2fee40b --- /dev/null +++ b/test/test_post_10.res @@ -0,0 +1,100 @@ + +OK +0 +9 +10 +0 +9 + + +The Computer Bible +1973-1980 +The Computer Bible +1973-1980 +title the computer bible author medium book + + + +How to program a computer +Jack Collins +How to program a computer +Jack Collins + +How to program a computer +Jack Collins +2 +title how to program a computer author jack collins medium book + + + +A plan for community college computer development +1971 +A plan for community college computer development +1971 +title a plan for community college computer development author medium book + + + +Washington metropolitan area rail computer feasibility study; +final report +1971 +Englund, Carl R +Washington metropolitan area rail computer feasibility study; +final report +1971 +Englund, Carl R +title washington metropolitan area rail computer feasibility study author englund carl r 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 +title the use of passwords for controlled access to computer resources author wood helen m medium book + + + +The Puget Sound Region +a portfolio of thematic computer maps +1974 +Mairs, John W +The Puget Sound Region +a portfolio of thematic computer maps +1974 +Mairs, John W +title the puget sound region author mairs john w 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 +title computer science technology author medium book + + + +Computer processing of dynamic images from an Anger scintillation camera +the proceedings of a workshop +1974 +Computer processing of dynamic images from an Anger scintillation camera +the proceedings of a workshop +1974 +title computer processing of dynamic images from an anger scintillation camera author medium book + + + +Reconstruction tomography in diagnostic radiology and nuclear medicine +proceedings of the workshop +1977 +Reconstruction tomography in diagnostic radiology and nuclear medicine +proceedings of the workshop +1977 +title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book + + diff --git a/test/test_post_11.res b/test/test_post_11.res new file mode 100644 index 0000000..e8e6e48 --- /dev/null +++ b/test/test_post_11.res @@ -0,0 +1,8 @@ +OK +z3950.indexdata.com/marc +Index Data MARC test server +10 +0 +10 +Client_Idle + \ No newline at end of file diff --git a/test/test_post_5.res b/test/test_post_5.res index 4a230d3..c610a3b 100644 --- a/test/test_post_5.res +++ b/test/test_post_5.res @@ -1,26 +1 @@ - -OK -0 -3 -3 -0 -3 - - -OIL/GAS DRILLING -OIL/GAS DRILLING -title oil gas drilling author medium book - - - -GROUNDWATER RESOURCE MAPS - COUNTY SERIES -GROUNDWATER RESOURCE MAPS - COUNTY SERIES -title groundwater resource maps county series author medium book - - - -BIBLIOGRAPHY OF MAINE GEOLOGY -BIBLIOGRAPHY OF MAINE GEOLOGY -title bibliography of maine geology author medium book - - +OK31 \ No newline at end of file diff --git a/test/test_post_6.res b/test/test_post_6.res index 2fee40b..523d190 100644 --- a/test/test_post_6.res +++ b/test/test_post_6.res @@ -1,100 +1 @@ - -OK -0 -9 -10 -0 -9 - - -The Computer Bible -1973-1980 -The Computer Bible -1973-1980 -title the computer bible author medium book - - - -How to program a computer -Jack Collins -How to program a computer -Jack Collins - -How to program a computer -Jack Collins -2 -title how to program a computer author jack collins medium book - - - -A plan for community college computer development -1971 -A plan for community college computer development -1971 -title a plan for community college computer development author medium book - - - -Washington metropolitan area rail computer feasibility study; -final report -1971 -Englund, Carl R -Washington metropolitan area rail computer feasibility study; -final report -1971 -Englund, Carl R -title washington metropolitan area rail computer feasibility study author englund carl r 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 -title the use of passwords for controlled access to computer resources author wood helen m medium book - - - -The Puget Sound Region -a portfolio of thematic computer maps -1974 -Mairs, John W -The Puget Sound Region -a portfolio of thematic computer maps -1974 -Mairs, John W -title the puget sound region author mairs john w 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 -title computer science technology author medium book - - - -Computer processing of dynamic images from an Anger scintillation camera -the proceedings of a workshop -1974 -Computer processing of dynamic images from an Anger scintillation camera -the proceedings of a workshop -1974 -title computer processing of dynamic images from an anger scintillation camera author medium book - - - -Reconstruction tomography in diagnostic radiology and nuclear medicine -proceedings of the workshop -1977 -Reconstruction tomography in diagnostic radiology and nuclear medicine -proceedings of the workshop -1977 -title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book - - +OK \ No newline at end of file diff --git a/test/test_post_8.res b/test/test_post_8.res new file mode 100644 index 0000000..2fee40b --- /dev/null +++ b/test/test_post_8.res @@ -0,0 +1,100 @@ + +OK +0 +9 +10 +0 +9 + + +The Computer Bible +1973-1980 +The Computer Bible +1973-1980 +title the computer bible author medium book + + + +How to program a computer +Jack Collins +How to program a computer +Jack Collins + +How to program a computer +Jack Collins +2 +title how to program a computer author jack collins medium book + + + +A plan for community college computer development +1971 +A plan for community college computer development +1971 +title a plan for community college computer development author medium book + + + +Washington metropolitan area rail computer feasibility study; +final report +1971 +Englund, Carl R +Washington metropolitan area rail computer feasibility study; +final report +1971 +Englund, Carl R +title washington metropolitan area rail computer feasibility study author englund carl r 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 +title the use of passwords for controlled access to computer resources author wood helen m medium book + + + +The Puget Sound Region +a portfolio of thematic computer maps +1974 +Mairs, John W +The Puget Sound Region +a portfolio of thematic computer maps +1974 +Mairs, John W +title the puget sound region author mairs john w 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 +title computer science technology author medium book + + + +Computer processing of dynamic images from an Anger scintillation camera +the proceedings of a workshop +1974 +Computer processing of dynamic images from an Anger scintillation camera +the proceedings of a workshop +1974 +title computer processing of dynamic images from an anger scintillation camera author medium book + + + +Reconstruction tomography in diagnostic radiology and nuclear medicine +proceedings of the workshop +1977 +Reconstruction tomography in diagnostic radiology and nuclear medicine +proceedings of the workshop +1977 +title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book + + diff --git a/test/test_post_9.res b/test/test_post_9.res new file mode 100644 index 0000000..4a230d3 --- /dev/null +++ b/test/test_post_9.res @@ -0,0 +1,26 @@ + +OK +0 +3 +3 +0 +3 + + +OIL/GAS DRILLING +OIL/GAS DRILLING +title oil gas drilling author medium book + + + +GROUNDWATER RESOURCE MAPS - COUNTY SERIES +GROUNDWATER RESOURCE MAPS - COUNTY SERIES +title groundwater resource maps county series author medium book + + + +BIBLIOGRAPHY OF MAINE GEOLOGY +BIBLIOGRAPHY OF MAINE GEOLOGY +title bibliography of maine geology author medium book + + diff --git a/test/test_post_urls b/test/test_post_urls index 0152785..4a96ddc 100644 --- a/test/test_post_urls +++ b/test/test_post_urls @@ -4,6 +4,13 @@ http://localhost:9763/search.pz1?session=1&command=search&query=computer gils_service.xml http://localhost:9763/search.pz2?command=init http://localhost:9763/search.pz1?session=2&command=search&query=computer +gils_service.xml +http://localhost:9763/search.pz2?command=init&clear=1 +z3950_indexdata_com_marc.xml +http://localhost:9763/search.pz1?session=3&command=settings +http://localhost:9763/search.pz1?session=3&command=search&query=computer 2 -http://localhost:9763/search.pz1?session=2&command=show http://localhost:9763/search.pz1?session=1&command=show +http://localhost:9763/search.pz1?session=2&command=show +http://localhost:9763/search.pz1?session=3&command=show +http://localhost:9763/search.pz1?session=3&command=bytarget -- 1.7.10.4