From 73f37c91c144b070020df2f27472c09b62367acf Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 19 Sep 2012 15:38:37 +0200 Subject: [PATCH] Reformat: delete trailing whitespace --- example-module/filter_myfilter.cpp | 12 +- include/metaproxy/filter.hpp | 4 +- include/metaproxy/origin.hpp | 10 +- include/metaproxy/package.hpp | 18 +-- include/metaproxy/router.hpp | 6 +- include/metaproxy/session.hpp | 30 ++-- include/metaproxy/util.hpp | 30 ++-- include/metaproxy/xmlutil.hpp | 10 +- src/ex_filter_frontend_net.cpp | 18 +-- src/ex_router_flexml.cpp | 6 +- src/factory_filter.cpp | 10 +- src/factory_filter.hpp | 8 +- src/factory_static.cpp | 2 +- src/filter_auth_simple.cpp | 10 +- src/filter_backend_test.cpp | 40 +++--- src/filter_bounce.cpp | 22 +-- src/filter_bounce.hpp | 2 +- src/filter_cgi.cpp | 14 +- src/filter_cql_to_rpn.cpp | 18 +-- src/filter_frontend_net.cpp | 80 +++++------ src/filter_http_file.cpp | 18 +-- src/filter_limit.cpp | 16 +-- src/filter_load_balance.cpp | 66 ++++----- src/filter_log.cpp | 100 ++++++------- src/filter_multi.cpp | 134 +++++++++--------- src/filter_query_rewrite.cpp | 22 +-- src/filter_record_transform.cpp | 64 ++++----- src/filter_session_shared.cpp | 126 ++++++++--------- src/filter_sort.cpp | 74 +++++----- src/filter_sru_to_z3950.cpp | 254 +++++++++++++++++----------------- src/filter_template.cpp | 4 +- src/filter_template.hpp | 2 +- src/filter_virt_db.cpp | 98 ++++++------- src/filter_z3950_client.cpp | 52 +++---- src/filter_zeerex_explain.cpp | 38 ++--- src/filter_zeerex_explain.hpp | 2 +- src/filter_zoom.cpp | 172 +++++++++++------------ src/gduutil.cpp | 60 ++++---- src/gduutil.hpp | 6 +- src/metaproxy_prog.cpp | 20 +-- src/origin.cpp | 2 +- src/package.cpp | 8 +- src/pipe.cpp | 10 +- src/pipe.hpp | 2 +- src/plainfile.cpp | 2 +- src/router_flexml.cpp | 38 ++--- src/router_flexml.hpp | 8 +- src/sru_util.cpp | 120 ++++++++-------- src/sru_util.hpp | 44 +++--- src/test_boost_threads.cpp | 16 +-- src/test_filter1.cpp | 4 +- src/test_filter2.cpp | 46 +++--- src/test_filter_auth_simple.cpp | 28 ++-- src/test_filter_backend_test.cpp | 74 +++++----- src/test_filter_bounce.cpp | 54 ++++---- src/test_filter_factory.cpp | 16 +-- src/test_filter_frontend_net.cpp | 20 +-- src/test_filter_log.cpp | 28 ++-- src/test_filter_multi.cpp | 28 ++-- src/test_filter_query_rewrite.cpp | 92 ++++++------ src/test_filter_record_transform.cpp | 32 ++--- src/test_filter_sru_to_z3950.cpp | 30 ++-- src/test_filter_virt_db.cpp | 96 ++++++------- src/test_filter_z3950_client.cpp | 72 +++++----- src/test_pipe.cpp | 4 +- src/test_router_flexml.cpp | 12 +- src/test_ses_map.cpp | 6 +- src/test_session1.cpp | 4 +- src/test_session2.cpp | 22 +-- src/test_thread_pool_observer.cpp | 6 +- src/test_xmlutil.cpp | 4 +- src/thread_pool_observer.cpp | 4 +- src/torus.cpp | 6 +- src/url_recipe.cpp | 2 +- src/util.cpp | 104 +++++++------- src/xmlutil.cpp | 30 ++-- 76 files changed, 1376 insertions(+), 1376 deletions(-) diff --git a/example-module/filter_myfilter.cpp b/example-module/filter_myfilter.cpp index 2e6c5e5..1bc2297 100644 --- a/example-module/filter_myfilter.cpp +++ b/example-module/filter_myfilter.cpp @@ -36,7 +36,7 @@ namespace metaproxy_1 { } void mp::filter::Filter_myfilter::process(mp::Package & package) const -{ // See src/filter_backend_test.cpp for a more comprehensive +{ // See src/filter_backend_test.cpp for a more comprehensive // example of a dummy Z-server Z_GDU *gdu = package.request().get(); Z_APDU *apdu_res = 0; @@ -49,14 +49,14 @@ void mp::filter::Filter_myfilter::process(mp::Package & package) const return; } Z_APDU *apdu_req = gdu->u.z3950; - if (apdu_req->which == Z_APDU_initRequest) + if (apdu_req->which == Z_APDU_initRequest) { yaz_log(YLOG_LOG, "myfilter::process: Init request"); - apdu_res= odr.create_initResponse( apdu_req, + apdu_res= odr.create_initResponse( apdu_req, YAZ_BIB1_PERMANENT_SYSTEM_ERROR, "Not implemented!"); package.response() = apdu_res; } - else + else { yaz_log(YLOG_LOG, "myfilter::process: Unknown request type"); package.move(); // Send on to other filters @@ -66,7 +66,7 @@ void mp::filter::Filter_myfilter::process(mp::Package & package) const void mp::filter::Filter_myfilter::configure(const xmlNode *ptr, bool test_only) { yaz_log(YLOG_LOG, "myfilter::configure"); - for (ptr = ptr->children; ptr; ptr = ptr->next) + for (ptr = ptr->children; ptr; ptr = ptr->next) { if (ptr->type != XML_ELEMENT_NODE) continue; @@ -76,7 +76,7 @@ void mp::filter::Filter_myfilter::configure(const xmlNode *ptr, bool test_only) yaz_log(YLOG_LOG, "myfilter::configure: %s", msg.c_str() ); } - else + else { throw mp::filter::FilterException("Bad element " + std::string((const char *) ptr->name)); diff --git a/include/metaproxy/filter.hpp b/include/metaproxy/filter.hpp index 2d5495f..a3b2115 100644 --- a/include/metaproxy/filter.hpp +++ b/include/metaproxy/filter.hpp @@ -32,11 +32,11 @@ namespace metaproxy_1 { class Base { public: virtual ~Base(){}; - + ///sends Package off to next Filter, returns altered Package virtual void process(Package & package) const = 0; - /// configuration during filter load + /// configuration during filter load virtual void configure(const xmlNode * ptr, bool test_only, const char *path) = 0; diff --git a/include/metaproxy/origin.hpp b/include/metaproxy/origin.hpp index eb6ac08..2304221 100644 --- a/include/metaproxy/origin.hpp +++ b/include/metaproxy/origin.hpp @@ -31,11 +31,11 @@ namespace std { } namespace metaproxy_1 { - + class Origin { public: Origin(); - + /// set client IP info - left val in assignment void set_tcpip_address(std::string addr, unsigned long id); @@ -44,15 +44,15 @@ namespace metaproxy_1 { /// set max sockets (for outgoing connections to a given target) int get_max_sockets(); - + /// get tcpip address std::string get_address(); void set_custom_session(const std::string &s); private: - friend std::ostream& + friend std::ostream& std::operator<<(std::ostream& os, const metaproxy_1::Origin& o); - + std::string m_address; unsigned int m_origin_id; int m_max_sockets; diff --git a/include/metaproxy/package.hpp b/include/metaproxy/package.hpp index e3aef40..ffb1f6e 100644 --- a/include/metaproxy/package.hpp +++ b/include/metaproxy/package.hpp @@ -34,7 +34,7 @@ namespace metaproxy_1 { } -namespace std +namespace std { std::ostream& operator<<(std::ostream& os, const metaproxy_1::Package& p); } @@ -46,8 +46,8 @@ namespace metaproxy_1 { Package(); ~Package(); - - Package(metaproxy_1::Session &session, + + Package(metaproxy_1::Session &session, const metaproxy_1::Origin &origin); /// copy constructor which copies route pos + logger @@ -61,23 +61,23 @@ namespace metaproxy_1 { /// send Package to other route void move(std::string route); - + /// access session - left val in assignment metaproxy_1::Session & session(); - + /// get function - right val in assignment Origin origin() const; - + /// set function - left val in assignment Origin & origin(); - + /// set function - can be chained Package & router(const Router &router); yazpp_1::GDU &request(); yazpp_1::GDU &response(); - + /// get function - right val in assignment Session session() const; @@ -96,7 +96,7 @@ namespace metaproxy_1 { RoutePos *m_route_pos; PackageLoggerPtr p_logger; - + yazpp_1::GDU m_request_gdu; yazpp_1::GDU m_response_gdu; }; diff --git a/include/metaproxy/router.hpp b/include/metaproxy/router.hpp index 25db0cd..114eb03 100644 --- a/include/metaproxy/router.hpp +++ b/include/metaproxy/router.hpp @@ -23,19 +23,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -namespace metaproxy_1 +namespace metaproxy_1 { namespace filter { class Base; } class RoutePos; - + class RouterException : public std::runtime_error { public: RouterException(const std::string message) : std::runtime_error("RouterException: " + message){}; }; - + class Router : boost::noncopyable { public: Router(){}; diff --git a/include/metaproxy/session.hpp b/include/metaproxy/session.hpp index 71c3910..903d5d0 100644 --- a/include/metaproxy/session.hpp +++ b/include/metaproxy/session.hpp @@ -24,12 +24,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include namespace metaproxy_1 { - + class Session { //typedef unsigned long type; public: - + /// create new session with new unique id Session() { boost::mutex::scoped_lock scoped_lock(m_mutex); @@ -37,11 +37,11 @@ namespace metaproxy_1 { m_id = m_global_id; m_close = false; } - + /// copy session including old id Session(const Session &s) : m_id(s.m_id), m_close(s.m_close) {}; - - Session& operator=(const Session &s) { + + Session& operator=(const Session &s) { if (this != &s) { m_id = s.m_id; @@ -53,15 +53,15 @@ namespace metaproxy_1 { bool operator<(const Session &s) const { return m_id < s.m_id ? true : false; } - + unsigned long id() const { return m_id; } - + bool is_closed() const { return m_close; } - + /// mark session closed, can not be unset void close() { m_close = true; @@ -70,23 +70,23 @@ namespace metaproxy_1 { bool operator == (Session &ses) const { return ses.m_id == m_id; } - + private: - + unsigned long int m_id; bool m_close; - + /// static mutex to lock static m_id static boost::mutex m_mutex; - + /// static m_id to make sure that there is only one id counter static unsigned long int m_global_id; - + }; template class session_map { public: - void create(T &t, const metaproxy_1::Session &s) { + void create(T &t, const metaproxy_1::Session &s) { boost::mutex::scoped_lock lock(m_map_mutex); m_map[s] = SessionItem(t); }; @@ -133,7 +133,7 @@ namespace metaproxy_1 { boost::mutex m_map_mutex; std::mapm_map; }; - + } #endif diff --git a/include/metaproxy/util.hpp b/include/metaproxy/util.hpp index ea43910..ab0834b 100644 --- a/include/metaproxy/util.hpp +++ b/include/metaproxy/util.hpp @@ -35,26 +35,26 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA namespace metaproxy_1 { namespace util { - - template + + template std::string to_string(const T& t) { std::ostringstream o; if(o << t) - return o.str(); + return o.str(); return std::string(); }; - const char * + const char * record_composition_to_esn(Z_RecordComposition *comp); - std::string http_header_value(const Z_HTTP_Header* header, + std::string http_header_value(const Z_HTTP_Header* header, const std::string name); - std::string http_headers_debug(const Z_HTTP_Request &http_req); + std::string http_headers_debug(const Z_HTTP_Request &http_req); - void http_response(metaproxy_1::Package &package, - const std::string &content, + void http_response(metaproxy_1::Package &package, + const std::string &content, int http_code = 200); @@ -77,16 +77,16 @@ namespace metaproxy_1 { void split_zurl(std::string zurl, std::string &host, std::list &db); - + void get_vhost_otherinfo(Z_OtherInformation *otherInformation, std::list &vhosts); - + int remove_vhost_otherinfo(Z_OtherInformation **otherInformation, std::list &vhosts); - void set_vhost_otherinfo(Z_OtherInformation **otherInformation, + void set_vhost_otherinfo(Z_OtherInformation **otherInformation, ODR odr, - const std::string vhost, + const std::string vhost, const int cat); void set_vhost_otherinfo(Z_OtherInformation **otherInformation, @@ -134,9 +134,9 @@ namespace metaproxy_1 { odr(); ~odr(); operator ODR() const; - Z_APDU *create_close(const Z_APDU *in_apdu, + Z_APDU *create_close(const Z_APDU *in_apdu, int reason, const char *addinfo); - Z_APDU *create_initResponse(const Z_APDU *in_apdu, + Z_APDU *create_initResponse(const Z_APDU *in_apdu, int error, const char *addinfo); Z_APDU *create_searchResponse(const Z_APDU *in_apdu, int error, const char *addinfo); @@ -163,7 +163,7 @@ namespace metaproxy_1 { private: WRBUF m_wrbuf; }; - + class PlainFile { class Rep; boost::scoped_ptr m_p; diff --git a/include/metaproxy/xmlutil.hpp b/include/metaproxy/xmlutil.hpp index f673211..945a4ba 100644 --- a/include/metaproxy/xmlutil.hpp +++ b/include/metaproxy/xmlutil.hpp @@ -29,17 +29,17 @@ namespace metaproxy_1 { std::string get_text(const xmlNode *ptr); bool get_bool(const xmlNode *ptr, bool default_value); int get_int(const xmlNode *ptr, int default_value); - bool check_attribute(const _xmlAttr *ptr, + bool check_attribute(const _xmlAttr *ptr, const std::string &ns, const std::string &name); - bool is_attribute(const _xmlAttr *ptr, + bool is_attribute(const _xmlAttr *ptr, const std::string &ns, const std::string &name); - bool is_element(const xmlNode *ptr, + bool is_element(const xmlNode *ptr, const std::string &ns, const std::string &name); bool is_element_mp(const xmlNode *ptr, const std::string &name); - bool check_element_mp(const xmlNode *ptr, + bool check_element_mp(const xmlNode *ptr, const std::string &name); std::string get_route(const xmlNode *node); std::string get_route(const xmlNode *node, std::string &auth); @@ -47,7 +47,7 @@ namespace metaproxy_1 { const xmlNode* jump_to(const xmlNode* node, int node_type); const xmlNode* jump_to_next(const xmlNode* node, int node_type); - + const xmlNode* jump_to_children(const xmlNode* node, int node_type); void check_empty(const xmlNode *node); diff --git a/src/ex_filter_frontend_net.cpp b/src/ex_filter_frontend_net.cpp index 0a7940f..6aed281 100644 --- a/src/ex_filter_frontend_net.cpp +++ b/src/ex_filter_frontend_net.cpp @@ -42,21 +42,21 @@ public: { // std::cout << "Got Close.\n"; } - + Z_GDU *gdu = package.request().get(); if (gdu && gdu->which == Z_GDU_HTTP_Request) { mp::odr odr; Z_GDU *gdu = z_get_HTTP_Response(odr, 200); Z_HTTP_Response *http_res = gdu->u.HTTP_Response; - + z_HTTP_header_add(odr, &http_res->headers, "Content-Type", "text/plain"); - - http_res->content_buf = + + http_res->content_buf = odr_strdup(odr, "Welcome to Metaproxy"); http_res->content_len = strlen(http_res->content_buf); - + package.response() = gdu; } return package.move(); @@ -67,14 +67,14 @@ public: int main(int argc, char **argv) { - try + try { std::vector ports; int duration = -1; int ret; char *arg; - while ((ret = options("h{help}d{duration}:p{port}:", + while ((ret = options("h{help}d{duration}:p{port}:", argv, argc, &arg)) != -2) { switch(ret) @@ -142,8 +142,8 @@ int main(int argc, char **argv) mp::Session session; mp::Origin origin; mp::Package pack(session, origin); - - pack.router(router).move(); + + pack.router(router).move(); } } catch ( ... ) { diff --git a/src/ex_router_flexml.cpp b/src/ex_router_flexml.cpp index 8b9d612..6efa19a 100644 --- a/src/ex_router_flexml.cpp +++ b/src/ex_router_flexml.cpp @@ -32,13 +32,13 @@ namespace mp = metaproxy_1; int main(int argc, char **argv) { - try + try { int ret; char *arg; char *fname = 0; - while ((ret = options("h{help}c{config}:", + while ((ret = options("h{help}c{config}:", argv, argc, &arg)) != -2) { switch(ret) @@ -77,7 +77,7 @@ int main(int argc, char **argv) mp::RouterFleXML router(doc, factory, false, 0); mp::Package pack; - + pack.router(router).move(); xmlFreeDoc(doc); diff --git a/src/factory_filter.cpp b/src/factory_filter.cpp index 5a05b3e..5fec9dd 100644 --- a/src/factory_filter.cpp +++ b/src/factory_filter.cpp @@ -33,7 +33,7 @@ namespace mp = metaproxy_1; namespace metaproxy_1 { class FactoryFilter::Rep { typedef std::map CallbackMap; - typedef std::map::iterator + typedef std::map::iterator CallbackMapIt; public: friend class FactoryFilter; @@ -81,7 +81,7 @@ bool mp::FactoryFilter::drop_creator(std::string fi) bool mp::FactoryFilter::exist(std::string fi) { Rep::CallbackMap::const_iterator it = m_p->m_fcm.find(fi); - + if (it == m_p->m_fcm.end()) { return false; @@ -92,7 +92,7 @@ bool mp::FactoryFilter::exist(std::string fi) mp::filter::Base* mp::FactoryFilter::create(std::string fi) { Rep::CallbackMap::const_iterator it = m_p->m_fcm.find(fi); - + if (it == m_p->m_fcm.end()){ std::string msg = "filter type '" + fi + "' not found"; throw NotFound(msg); @@ -124,13 +124,13 @@ bool mp::FactoryFilter::add_creator_dl(const std::string &fi, if (!dl_handle) { const char *dl = dlerror(); - std::cout << "dlopen " << full_path << " failed. dlerror=" << dl << + std::cout << "dlopen " << full_path << " failed. dlerror=" << dl << std::endl; return false; } std::string full_name = "metaproxy_1_filter_" + fi; - + void *dlsym_ptr = dlsym(dl_handle, full_name.c_str()); if (!dlsym_ptr) { diff --git a/src/factory_filter.hpp b/src/factory_filter.hpp index 9c0050b..eee155d 100644 --- a/src/factory_filter.hpp +++ b/src/factory_filter.hpp @@ -37,17 +37,17 @@ namespace metaproxy_1 { class Rep; public: /// true if registration ok - + FactoryFilter(); ~FactoryFilter(); bool add_creator(const std::string &fi, CreateFilterCallback cfc); - + bool drop_creator(std::string fi); - + metaproxy_1::filter::Base* create(std::string fi); bool exist(std::string fi); - + bool add_creator_dl(const std::string &fi, const std::string &path); bool have_dl_support(); diff --git a/src/factory_static.cpp b/src/factory_static.cpp index fb82b74..d2d8797 100644 --- a/src/factory_static.cpp +++ b/src/factory_static.cpp @@ -63,7 +63,7 @@ mp::FactoryStatic::FactoryStatic() &metaproxy_1_filter_cgi, #endif &metaproxy_1_filter_cql_to_rpn, - &metaproxy_1_filter_frontend_net, + &metaproxy_1_filter_frontend_net, &metaproxy_1_filter_http_file, &metaproxy_1_filter_limit, &metaproxy_1_filter_load_balance, diff --git a/src/filter_auth_simple.cpp b/src/filter_auth_simple.cpp index b8b3548..74d17a7 100644 --- a/src/filter_auth_simple.cpp +++ b/src/filter_auth_simple.cpp @@ -257,10 +257,10 @@ void yf::AuthSimple::process_init(mp::Package &package) const static bool contains(std::list list, std::string thing) { std::list::const_iterator i; for (i = list.begin(); i != list.end(); i++) - if (mp::util::database_name_normalize(*i) == + if (mp::util::database_name_normalize(*i) == mp::util::database_name_normalize(thing)) return true; - + return false; } @@ -283,7 +283,7 @@ void yf::AuthSimple::process_search(mp::Package &package) const // Make an Search rejection APDU mp::odr odr; Z_APDU *apdu = odr.create_searchResponse( - package.request().get()->u.z3950, + package.request().get()->u.z3950, YAZ_BIB1_ACCESS_TO_SPECIFIED_DATABASE_DENIED, req->databaseNames[i]); package.response() = apdu; @@ -315,7 +315,7 @@ void yf::AuthSimple::process_scan(mp::Package &package) const // Make an Scan rejection APDU mp::odr odr; Z_APDU *apdu = odr.create_scanResponse( - package.request().get()->u.z3950, + package.request().get()->u.z3950, YAZ_BIB1_ACCESS_TO_SPECIFIED_DATABASE_DENIED, req->databaseNames[i]); package.response() = apdu; @@ -329,7 +329,7 @@ void yf::AuthSimple::process_scan(mp::Package &package) const } -static void reject_init(mp::Package &package, int err, const char *addinfo) { +static void reject_init(mp::Package &package, int err, const char *addinfo) { if (err == 0) err = YAZ_BIB1_INIT_AC_AUTHENTICATION_SYSTEM_ERROR; // Make an Init rejection APDU diff --git a/src/filter_backend_test.cpp b/src/filter_backend_test.cpp index b79651a..f0c10d3 100644 --- a/src/filter_backend_test.cpp +++ b/src/filter_backend_test.cpp @@ -107,7 +107,7 @@ Z_Records *yf::BackendTest::Rep::fetch( int *number_returned, int *next_position) { const char *element_set_name = "F"; // default to use - + if (number + start - 1 > result_set_size || start < 1) { error_code = YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE; @@ -135,24 +135,24 @@ Z_Records *yf::BackendTest::Rep::fetch( { if (esn->which != Z_ElementSetNames_generic) { - error_code + error_code = YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_; return 0; } element_set_name = esn->u.generic; } - if (!strcmp(element_set_name, "B") + if (!strcmp(element_set_name, "B") && !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_usmarc)) ; // Brief - else if (!strcmp(element_set_name, "F") + else if (!strcmp(element_set_name, "F") && !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_usmarc)) ; // Full - else if (!strncmp(element_set_name, "FF", 2) + else if (!strncmp(element_set_name, "FF", 2) && !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml)) ; // Huge XML test record else { - error_code + error_code = YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_; addinfo = std::string(element_set_name); return 0; @@ -219,8 +219,8 @@ void yf::BackendTest::process(Package &package) const Z_APDU *apdu_req = gdu->u.z3950; Z_APDU *apdu_res = 0; mp::odr odr; - - if (apdu_req->which != Z_APDU_initRequest && + + if (apdu_req->which != Z_APDU_initRequest && !m_p->m_sessions.exist(package.session())) { apdu_res = odr.create_close(apdu_req, @@ -237,11 +237,11 @@ void yf::BackendTest::process(Package &package) const resp->implementationName = odr_strdup(odr, "backend_test"); if (ODR_MASK_GET(req->options, Z_Options_namedResultSets)) m_p->m_support_named_result_sets = true; - + int i; static const int masks[] = { Z_Options_search, Z_Options_present, - Z_Options_namedResultSets, -1 + Z_Options_namedResultSets, -1 }; for (i = 0; masks[i] != -1; i++) if (ODR_MASK_GET(req->options, masks[i])) @@ -267,11 +267,11 @@ void yf::BackendTest::process(Package &package) const else if (apdu_req->which == Z_APDU_searchRequest) { Z_SearchRequest *req = apdu_req->u.searchRequest; - - if (!m_p->m_support_named_result_sets && + + if (!m_p->m_support_named_result_sets && strcmp(req->resultSetName, "default")) { - apdu_res = + apdu_res = odr.create_searchResponse( apdu_req, YAZ_BIB1_RESULT_SET_NAMING_UNSUPP, 0); } @@ -283,13 +283,13 @@ void yf::BackendTest::process(Package &package) const int error_code = 0; std::string addinfo; const char *element_set_name = 0; - + Odr_int number = 0; mp::util::piggyback_sr(req, result_set_size, number, &element_set_name); - - if (number) - { // not a large set for sure + + if (number) + { // not a large set for sure Z_ElementSetNames *esn; if (number > *req->smallSetUpperBound) esn = req->mediumSetElementSetNames; @@ -304,7 +304,7 @@ void yf::BackendTest::process(Package &package) const } if (error_code) { - apdu_res = + apdu_res = odr.create_searchResponse( apdu_req, error_code, addinfo.c_str()); Z_SearchResponse *resp = apdu_res->u.searchResponse; @@ -312,7 +312,7 @@ void yf::BackendTest::process(Package &package) const } else { - apdu_res = + apdu_res = odr.create_searchResponse(apdu_req, 0, 0); Z_SearchResponse *resp = apdu_res->u.searchResponse; *resp->resultCount = result_set_size; @@ -323,7 +323,7 @@ void yf::BackendTest::process(Package &package) const } } else if (apdu_req->which == Z_APDU_presentRequest) - { + { Z_PresentRequest *req = apdu_req->u.presentRequest; int number_returned = 0; int next_position = 0; diff --git a/src/filter_bounce.cpp b/src/filter_bounce.cpp index 503dd65..4296b1a 100644 --- a/src/filter_bounce.cpp +++ b/src/filter_bounce.cpp @@ -54,18 +54,18 @@ void yf::Bounce::process(mp::Package &package) const return; } package.session().close(); - + Z_GDU *zgdu = package.request().get(); - + if (!zgdu) return; - + //std::string message("BOUNCE "); - std::ostringstream message; + std::ostringstream message; message << "BOUNCE " << *zgdu; - - metaproxy_1::odr odr; - + + metaproxy_1::odr odr; + if (zgdu->which == Z_GDU_Z3950) { Z_APDU *apdu_res = 0; @@ -77,16 +77,16 @@ void yf::Bounce::process(mp::Package &package) const else if (zgdu->which == Z_GDU_HTTP_Request) { Z_GDU *zgdu_res = 0; - zgdu_res - = odr.create_HTTP_Response(package.session(), + zgdu_res + = odr.create_HTTP_Response(package.session(), zgdu->u.HTTP_Request, 400); - + package.response() = zgdu_res; } else if (zgdu->which == Z_GDU_HTTP_Response) { } - + return; } diff --git a/src/filter_bounce.hpp b/src/filter_bounce.hpp index 4a3c358..1143069 100644 --- a/src/filter_bounce.hpp +++ b/src/filter_bounce.hpp @@ -17,7 +17,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // Filter that bounces all requests packages -// No packages are ever passed to later filters in the chain +// No packages are ever passed to later filters in the chain #ifndef FILTER_BOUNCE_HPP #define FILTER_BOUNCE_HPP diff --git a/src/filter_cgi.cpp b/src/filter_cgi.cpp index d2f1423..e0b1411 100644 --- a/src/filter_cgi.cpp +++ b/src/filter_cgi.cpp @@ -54,14 +54,14 @@ namespace metaproxy_1 { yf::CGI::CGI() : m_p(new Rep) { - + } yf::CGI::Rep::~Rep() { std::map::const_iterator it; boost::mutex::scoped_lock lock(m_mutex); - + for (it = children.begin(); it != children.end(); it++) kill(it->second, SIGTERM); } @@ -74,10 +74,10 @@ void yf::CGI::process(mp::Package &package) const { Z_GDU *zgdu_req = package.request().get(); Z_GDU *zgdu_res = 0; - + if (!zgdu_req) return; - + if (zgdu_req->which != Z_GDU_HTTP_Request) { package.move(); @@ -105,7 +105,7 @@ void yf::CGI::process(mp::Package &package) const int r; pid_t pid; int status; - + pid = ::fork(); switch (pid) { @@ -165,7 +165,7 @@ void yf::CGI::configure(const xmlNode *ptr, bool test_only, const char *path) exec.program = mp::xml::get_text(attr->children); else throw mp::filter::FilterException - ("Bad attribute " + ("Bad attribute " + std::string((const char *) attr->name) + " in cgi section"); } @@ -173,7 +173,7 @@ void yf::CGI::configure(const xmlNode *ptr, bool test_only, const char *path) } else { - throw mp::filter::FilterException("Bad element " + throw mp::filter::FilterException("Bad element " + std::string((const char *) ptr->name)); } diff --git a/src/filter_cql_to_rpn.cpp b/src/filter_cql_to_rpn.cpp index 225ee82..aa57cad 100644 --- a/src/filter_cql_to_rpn.cpp +++ b/src/filter_cql_to_rpn.cpp @@ -51,7 +51,7 @@ namespace metaproxy_1 { // define Pimpl wrapper forwarding to Impl - + yf::CQLtoRPN::CQLtoRPN() : m_p(new Impl) { } @@ -79,7 +79,7 @@ yf::CQLtoRPN::Impl::Impl() } yf::CQLtoRPN::Impl::~Impl() -{ +{ } void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode) @@ -90,7 +90,7 @@ void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode) */ - + std::string fname; for (xmlnode = xmlnode->children; xmlnode; xmlnode = xmlnode->next) { @@ -111,7 +111,7 @@ void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode) } else { - throw mp::filter::FilterException("Bad element " + throw mp::filter::FilterException("Bad element " + std::string((const char *) xmlnode->name)); } @@ -146,15 +146,15 @@ void yf::CQLtoRPN::Impl::process(mp::Package &package) char *addinfo = 0; Z_RPNQuery *rpnquery = 0; mp::odr odr; - + int r = m_cql2rpn.query_transform(sr->query->u.type_104->u.cql, &rpnquery, odr, &addinfo); if (r == -3) { - Z_APDU *f_apdu = + Z_APDU *f_apdu = odr.create_searchResponse( - apdu_req, + apdu_req, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, "Missing CQL to RPN configuration"); package.response() = f_apdu; @@ -164,14 +164,14 @@ void yf::CQLtoRPN::Impl::process(mp::Package &package) { int error_code = yaz_diag_srw_to_bib1(r); - Z_APDU *f_apdu = + Z_APDU *f_apdu = odr.create_searchResponse(apdu_req, error_code, addinfo); package.response() = f_apdu; return; } else { // conversion OK - + sr->query->which = Z_Query_type_1; sr->query->u.type_1 = rpnquery; package.request() = gdu; diff --git a/src/filter_frontend_net.cpp b/src/filter_frontend_net.cpp index 7f448a2..d4867ad 100644 --- a/src/filter_frontend_net.cpp +++ b/src/filter_frontend_net.cpp @@ -120,7 +120,7 @@ namespace metaproxy_1 { ZAssocChild *m_assoc_child; mp::Package *m_package; Rep *m_p; - }; + }; class FrontendNet::ZAssocServer : public yazpp_1::Z_Assoc { public: ~ZAssocServer(); @@ -134,7 +134,7 @@ namespace metaproxy_1 { yazpp_1::IPDU_Observable *the_PDU_Observable, int fd); void recv_GDU(Z_GDU *apdu, int len); - + void failNotify(); void timeoutNotify(); void connectNotify(); @@ -182,7 +182,7 @@ void yf::FrontendNet::ThreadPoolPackage::result(const char *t_info) yaz_timing_stop(timer); double duration = yaz_timing_get_real(timer); - + size_t ent = 0; while (m_p->m_duration_lim[ent] != 0.0 && duration > m_p->m_duration_lim[ent]) ent++; @@ -192,24 +192,24 @@ void yf::FrontendNet::ThreadPoolPackage::result(const char *t_info) if (m_p->m_duration_max < duration) m_p->m_duration_max = duration; - + if (m_p->m_duration_min == 0.0 || m_p->m_duration_min > duration) m_p->m_duration_min = duration; - + if (m_p->m_msg_config.length()) { Z_GDU *z_gdu = gdu->get(); - + std::ostringstream os; os << m_p->m_msg_config << " " << *m_package << " " << std::fixed << std::setprecision (6) << duration << " "; - - if (z_gdu) + + if (z_gdu) os << *z_gdu; else os << "-"; - + yaz_log(YLOG_LOG, "%s %s", os.str().c_str(), t_info); } } @@ -225,7 +225,7 @@ void yf::FrontendNet::ThreadPoolPackage::result(const char *t_info) mp::odr odr; int len; Z_APDU *apdu_response = odr.create_close( - z_gdu->u.z3950, Z_Close_systemProblem, + z_gdu->u.z3950, Z_Close_systemProblem, "unhandled Z39.50 request"); m_assoc_child->send_Z_PDU(apdu_response, &len); @@ -235,8 +235,8 @@ void yf::FrontendNet::ThreadPoolPackage::result(const char *t_info) // For HTTP, respond with Server Error int len; mp::odr odr; - Z_GDU *zgdu_res - = odr.create_HTTP_Response(m_package->session(), + Z_GDU *zgdu_res + = odr.create_HTTP_Response(m_package->session(), z_gdu->u.HTTP_Request, 500); m_assoc_child->send_GDU(zgdu_res, &len); } @@ -247,12 +247,12 @@ void yf::FrontendNet::ThreadPoolPackage::result(const char *t_info) { m_assoc_child->close(); } - + delete this; } -mp::IThreadPoolMsg *yf::FrontendNet::ThreadPoolPackage::handle() +mp::IThreadPoolMsg *yf::FrontendNet::ThreadPoolPackage::handle() { m_package->move(m_assoc_child->m_route); return this; @@ -290,19 +290,19 @@ yf::FrontendNet::ZAssocChild::~ZAssocChild() void yf::FrontendNet::ZAssocChild::report(Z_HTTP_Request *hreq) { mp::odr o; - + Z_GDU *gdu_res = o.create_HTTP_Response(m_session, hreq, 200); - + Z_HTTP_Response *hres = gdu_res->u.HTTP_Response; - + mp::wrbuf w; size_t i; int number_total = 0; - + for (i = 0; m_p->m_duration_lim[i] != 0.0; i++) number_total += m_p->m_duration_freq[i]; number_total += m_p->m_duration_freq[i]; - + wrbuf_puts(w, "\n"); wrbuf_puts(w, "\n"); wrbuf_printf(w, " \n", number_total); @@ -315,7 +315,7 @@ void yf::FrontendNet::ZAssocChild::report(Z_HTTP_Request *hreq) i > 0 ? m_p->m_duration_lim[i - 1] : 0.0, m_p->m_duration_lim[i], m_p->m_duration_freq[i]); } - + if (m_p->m_duration_freq[i] > 0) wrbuf_printf( w, " \n", @@ -333,21 +333,21 @@ void yf::FrontendNet::ZAssocChild::report(Z_HTTP_Request *hreq) wrbuf_printf( w, " \n", m_p->m_duration_total / number_total); - + wrbuf_puts(w, " \n"); - + int thread_busy; int thread_total; m_thread_pool_observer->get_thread_info(thread_busy, thread_total); - + wrbuf_printf(w, " \n", thread_busy, thread_total); - + wrbuf_puts(w, "\n"); - + hres->content_len = w.len(); hres->content_buf = (char *) w.buf(); - + int len; send_GDU(gdu_res, &len); } @@ -380,17 +380,17 @@ void yf::FrontendNet::ZAssocChild::recv_GDU(Z_GDU *z_pdu, int len) if (m_p->m_msg_config.length()) { - if (z_pdu) + if (z_pdu) { std::ostringstream os; os << m_p->m_msg_config << " " << *p << " " - << "0.000000" << " " + << "0.000000" << " " << *z_pdu; yaz_log(YLOG_LOG, "%s", os.str().c_str()); } } - m_thread_pool_observer->put(tp); + m_thread_pool_observer->put(tp); } void yf::FrontendNet::ZAssocChild::failNotify() @@ -428,7 +428,7 @@ yf::FrontendNet::ZAssocServer::ZAssocServer( yazpp_1::IPDU_Observable *PDU_Observable, std::string route, Rep *rep) - : + : Z_Assoc(PDU_Observable), m_route(route), m_p(rep) { m_package = 0; @@ -555,7 +555,7 @@ bool yf::FrontendNet::My_Timer_Thread::timeout() yf::FrontendNet::My_Timer_Thread::My_Timer_Thread( yazpp_1::ISocketObservable *obs, - int duration) : + int duration) : m_obs(obs), m_pipe(9123), m_timeout(false) { obs->addObserver(m_pipe.read_fd(), this); @@ -579,7 +579,7 @@ void yf::FrontendNet::process(Package &package) const if (m_p->m_listen_duration) tt = new My_Timer_Thread(&m_p->mySocketManager, m_p->m_listen_duration); - + ThreadPoolSocketObserver tp(&m_p->mySocketManager, m_p->m_no_threads); for (i = 0; im_ports.size(); i++) @@ -631,14 +631,14 @@ void yf::FrontendNet::configure(const xmlNode * ptr, bool test_only, } port.port = mp::xml::get_text(ptr); ports.push_back(port); - + } else if (!strcmp((const char *) ptr->name, "threads")) { std::string threads_str = mp::xml::get_text(ptr); int threads = atoi(threads_str.c_str()); if (threads < 1) - throw yf::FilterException("Bad value for threads: " + throw yf::FilterException("Bad value for threads: " + threads_str); m_p->m_no_threads = threads; } @@ -647,7 +647,7 @@ void yf::FrontendNet::configure(const xmlNode * ptr, bool test_only, std::string timeout_str = mp::xml::get_text(ptr); int timeout = atoi(timeout_str.c_str()); if (timeout < 1) - throw yf::FilterException("Bad value for timeout: " + throw yf::FilterException("Bad value for timeout: " + timeout_str); m_p->m_session_timeout = timeout; } @@ -665,7 +665,7 @@ void yf::FrontendNet::configure(const xmlNode * ptr, bool test_only, } else { - throw yf::FilterException("Bad element " + throw yf::FilterException("Bad element " + std::string((const char *) ptr->name)); } @@ -695,22 +695,22 @@ void yf::FrontendNet::set_ports(std::vector &ports) void yf::FrontendNet::set_ports(std::vector &ports) { m_p->m_ports = ports; - + m_p->az = new yf::FrontendNet::ZAssocServer *[m_p->m_ports.size()]; - + // Create yf::FrontendNet::ZAssocServer for each port size_t i; for (i = 0; im_ports.size(); i++) { // create a PDU assoc object (one per yf::FrontendNet::ZAssocServer) yazpp_1::PDU_Assoc *as = new yazpp_1::PDU_Assoc(&m_p->mySocketManager); - + // create ZAssoc with PDU Assoc m_p->az[i] = new yf::FrontendNet::ZAssocServer( as, m_p->m_ports[i].route, m_p.get()); if (m_p->az[i]->server(m_p->m_ports[i].port.c_str())) { - throw yf::FilterException("Unable to bind to address " + throw yf::FilterException("Unable to bind to address " + std::string(m_p->m_ports[i].port)); } } diff --git a/src/filter_http_file.cpp b/src/filter_http_file.cpp index 25ad1b9..58ec810 100644 --- a/src/filter_http_file.cpp +++ b/src/filter_http_file.cpp @@ -105,7 +105,7 @@ std::string yf::HttpFile::Rep::get_mime_type(std::string &fname) { std::string file_part = fname; std::string::size_type p = fname.find_last_of('/'); - + if (p != std::string::npos) file_part = fname.substr(p+1); @@ -129,7 +129,7 @@ void yf::HttpFile::Rep::fetch_file(mp::Session &session, std::string &fname, mp::Package &package) { mp::odr o; - + FILE *f = fopen(fname.c_str(), "rb"); if (!f) { @@ -170,7 +170,7 @@ void yf::HttpFile::Rep::fetch_file(mp::Session &session, } } fclose(f); - + std::string content_type = get_mime_type(fname); z_HTTP_header_add(o, &hres->headers, @@ -184,7 +184,7 @@ void yf::HttpFile::Rep::fetch_uri(mp::Session &session, bool sane = true; std::string::size_type p; std::string path = req->path; - + p = path.find("#"); if (p != std::string::npos) path = path.erase(p); @@ -218,7 +218,7 @@ void yf::HttpFile::Rep::fetch_uri(mp::Session &session, } package.move(); } - + void yf::HttpFile::process(mp::Package &package) const { Z_GDU *gdu = package.request().get(); @@ -246,7 +246,7 @@ void mp::filter::HttpFile::configure(const xmlNode * ptr, bool test_only, throw mp::filter::FilterException ("Can not open mime types file " + fname); } - + std::vector args; while (f.getline(args)) { @@ -263,14 +263,14 @@ void mp::filter::HttpFile::configure(const xmlNode * ptr, bool test_only, { if (a_node->type != XML_ELEMENT_NODE) continue; - + if (mp::xml::is_element_mp(a_node, "documentroot")) a.m_file_root = mp::xml::get_text(a_node); else if (mp::xml::is_element_mp(a_node, "prefix")) a.m_url_path_prefix = mp::xml::get_text(a_node); else throw mp::filter::FilterException - ("Bad element " + ("Bad element " + std::string((const char *) a_node->name) + " in area section" ); @@ -283,7 +283,7 @@ void mp::filter::HttpFile::configure(const xmlNode * ptr, bool test_only, else { throw mp::filter::FilterException - ("Bad element " + ("Bad element " + std::string((const char *) ptr->name) + " in virt_db filter"); } diff --git a/src/filter_limit.cpp b/src/filter_limit.cpp index 0117bf9..ef6f727 100644 --- a/src/filter_limit.cpp +++ b/src/filter_limit.cpp @@ -59,7 +59,7 @@ namespace metaproxy_1 { } // define Pimpl wrapper forwarding to Impl - + yf::Limit::Limit() : m_p(new Impl) { } @@ -88,7 +88,7 @@ yf::Limit::Impl::Impl() : m_bw_max(0), m_pdu_max(0), m_search_max(0), } yf::Limit::Impl::~Impl() -{ +{ } void yf::Limit::Impl::configure(const xmlNode *ptr) @@ -119,7 +119,7 @@ void yf::Limit::Impl::configure(const xmlNode *ptr) } else { - throw mp::filter::FilterException("Bad element " + throw mp::filter::FilterException("Bad element " + std::string((const char *) ptr->name)); } @@ -134,7 +134,7 @@ void yf::Limit::Impl::process(mp::Package &package) yf::Limit::Ses *ses = 0; - std::map::iterator it = + std::map::iterator it = m_sessions.find(package.session()); if (it != m_sessions.end()) ses = it->second; @@ -172,7 +172,7 @@ void yf::Limit::Impl::process(mp::Package &package) yf::Limit::Ses *ses = 0; - std::map::iterator it = + std::map::iterator it = m_sessions.find(package.session()); if (it != m_sessions.end()) ses = it->second; @@ -183,14 +183,14 @@ void yf::Limit::Impl::process(mp::Package &package) } sz += package.response().get_size(); - + ses->bw_stat.add_bytes(sz); ses->pdu_stat.add_bytes(1); - + int bw_total = ses->bw_stat.get_total(); int pdu_total = ses->pdu_stat.get_total(); int search_total = ses->search_stat.get_total(); - + if (m_search_max) reduce += search_total / m_search_max; if (m_bw_max) diff --git a/src/filter_load_balance.cpp b/src/filter_load_balance.cpp index e4ca3fb..d729889 100644 --- a/src/filter_load_balance.cpp +++ b/src/filter_load_balance.cpp @@ -53,7 +53,7 @@ namespace metaproxy_1 void process(metaproxy_1::Package & package); void configure(const xmlNode * ptr); private: - // statistic manipulating functions, + // statistic manipulating functions, void add_dead(unsigned long session_id); //void clear_dead(unsigned long session_id); void add_package(unsigned long session_id); @@ -87,7 +87,7 @@ namespace metaproxy_1 } // define Pimpl wrapper forwarding to Impl - + yf::LoadBalance::LoadBalance() : m_p(new Impl) { } @@ -113,7 +113,7 @@ yf::LoadBalance::Impl::Impl() } yf::LoadBalance::Impl::~Impl() -{ +{ } void yf::LoadBalance::Impl::configure(const xmlNode *xmlnode) @@ -123,12 +123,12 @@ void yf::LoadBalance::Impl::configure(const xmlNode *xmlnode) void yf::LoadBalance::Impl::process(mp::Package &package) { bool is_closed_front = false; - + // checking for closed front end packages if (package.session().is_closed()) { is_closed_front = true; - } + } Z_GDU *gdu_req = package.request().get(); @@ -157,14 +157,14 @@ void yf::LoadBalance::Impl::process(mp::Package &package) init_pkg.copy_filter(package); unsigned int cost = std::numeric_limits::max(); - { + { boost::mutex::scoped_lock scoped_lock(m_mutex); - + for (; ivh != vhosts.end(); ) { if ((*ivh).size() != 0) { - unsigned int vhcost + unsigned int vhcost = yf::LoadBalance::Impl::cost(*ivh); yaz_log(YLOG_LOG, "Consider %s cost=%u vhcost=%u", (*ivh).c_str(), cost, vhcost); @@ -184,18 +184,18 @@ void yf::LoadBalance::Impl::process(mp::Package &package) if (target.length() == 0) break; // copying new target into init package - + yazpp_1::GDU init_gdu(base_req); Z_InitRequest *init_req = init_gdu.get()->u.z3950->u.initRequest; - - mp::util::set_vhost_otherinfo(&(init_req->otherInfo), + + mp::util::set_vhost_otherinfo(&(init_req->otherInfo), odr_en, target, 1); - + init_pkg.request() = init_gdu; - - // moving all package types + + // moving all package types init_pkg.move(); - + // checking for closed back end packages if (!init_pkg.session().is_closed()) { @@ -216,18 +216,18 @@ void yf::LoadBalance::Impl::process(mp::Package &package) else if (gdu_req->u.z3950->which == Z_APDU_close) { is_closed_front = true; - boost::mutex::scoped_lock scoped_lock(m_mutex); + boost::mutex::scoped_lock scoped_lock(m_mutex); add_package(package.session().id()); - } + } // any other Z39.50 package is added to statistics else { - boost::mutex::scoped_lock scoped_lock(m_mutex); + boost::mutex::scoped_lock scoped_lock(m_mutex); add_package(package.session().id()); } } - // moving all package types + // moving all package types package.move(); bool is_closed_back = false; @@ -247,7 +247,7 @@ void yf::LoadBalance::Impl::process(mp::Package &package) is_closed_back = true; boost::mutex::scoped_lock scoped_lock(m_mutex); remove_package(package.session().id()); - } + } // any other Z39.50 package is removed from statistics else { @@ -261,7 +261,7 @@ void yf::LoadBalance::Impl::process(mp::Package &package) { boost::mutex::scoped_lock scoped_lock(m_mutex); - // marking backend dead if backend closed without fronted close + // marking backend dead if backend closed without fronted close if (is_closed_front == false) add_dead(package.session().id()); @@ -271,21 +271,21 @@ void yf::LoadBalance::Impl::process(mp::Package &package) package.session().close(); } } - -// statistic manipulating functions, + +// statistic manipulating functions, void yf::LoadBalance::Impl::add_dead(unsigned long session_id) { std::string target = find_session_target(session_id); if (target.size() != 0) { - std::map::iterator itarg; + std::map::iterator itarg; itarg = m_target_stat.find(target); if (itarg != m_target_stat.end() && itarg->second.deads < std::numeric_limits::max()) { itarg->second.deads += 1; - // std:.cout << "add_dead " << session_id << " " << target + // std:.cout << "add_dead " << session_id << " " << target // << " d:" << itarg->second.deads << "\n"; } } @@ -297,10 +297,10 @@ void yf::LoadBalance::Impl::add_package(unsigned long session_id) if (target.size() != 0) { - std::map::iterator itarg; + std::map::iterator itarg; itarg = m_target_stat.find(target); if (itarg != m_target_stat.end() - && itarg->second.packages + && itarg->second.packages < std::numeric_limits::max()) { itarg->second.packages += 1; @@ -314,7 +314,7 @@ void yf::LoadBalance::Impl::remove_package(unsigned long session_id) if (target.size() != 0) { - std::map::iterator itarg; + std::map::iterator itarg; itarg = m_target_stat.find(target); if (itarg != m_target_stat.end() && itarg->second.packages > 0) @@ -324,7 +324,7 @@ void yf::LoadBalance::Impl::remove_package(unsigned long session_id) } } -void yf::LoadBalance::Impl::add_session(unsigned long session_id, +void yf::LoadBalance::Impl::add_session(unsigned long session_id, std::string target) { // finding and adding session @@ -345,7 +345,7 @@ void yf::LoadBalance::Impl::add_session(unsigned long session_id, stat.packages = 0; stat.deads = 0; m_target_stat.insert(std::make_pair(target, stat)); - } + } else if (itarg->second.sessions < std::numeric_limits::max()) { itarg->second.sessions += 1; @@ -372,7 +372,7 @@ void yf::LoadBalance::Impl::remove_session(unsigned long session_id) m_session_target.erase(isess); return; } - + // counting session down if (itarg->second.sessions > 0) itarg->second.sessions -= 1; @@ -402,7 +402,7 @@ unsigned int yf::LoadBalance::Impl::cost(std::string target) if (target.size() != 0) { - std::map::iterator itarg; + std::map::iterator itarg; itarg = m_target_stat.find(target); if (itarg != m_target_stat.end()) cost = itarg->second.cost(); @@ -416,7 +416,7 @@ unsigned int yf::LoadBalance::Impl::dead(std::string target) if (target.size() != 0) { - std::map::iterator itarg; + std::map::iterator itarg; itarg = m_target_stat.find(target); if (itarg != m_target_stat.end()) dead = itarg->second.deads; diff --git a/src/filter_log.cpp b/src/filter_log.cpp index 7b3a2aa..091faa1 100644 --- a/src/filter_log.cpp +++ b/src/filter_log.cpp @@ -56,7 +56,7 @@ namespace metaproxy_1 { private: void openfile(const std::string &fname); // needs to be static to be called by C pointer-to-function-syntax - static void stream_write(ODR o, void *handle, int type, + static void stream_write(ODR o, void *handle, int type, const char *buf, int len); // needs to be static to be called by C pointer-to-function-syntax static void option_write(const char *name, void *handle); @@ -72,8 +72,8 @@ namespace metaproxy_1 { bool m_init_options; LFilePtr m_file; std::string m_time_format; - // Only used during confiqgure stage (no threading), - // for performance avoid opening files which other log filter + // Only used during confiqgure stage (no threading), + // for performance avoid opening files which other log filter // instances already have opened static std::list filter_log_files; @@ -93,12 +93,12 @@ namespace metaproxy_1 { std::ostringstream &os); void flush(); }; - + } } // define Pimpl wrapper forwarding to Impl - + yf::Log::Log() : m_p(new Impl) { } @@ -143,7 +143,7 @@ yf::Log::Impl::Impl(const std::string &x) } -yf::Log::Impl::~Impl() +yf::Log::Impl::~Impl() { } @@ -245,7 +245,7 @@ static void log_1line_Z_APDU(Z_APDU *z_req, Z_APDU *z_res, WRBUF w) wrbuf_puts(w, "-"); } wrbuf_printf(w, " ID:%s Name:%s Version:%s", - req->implementationId ? req->implementationId :"-", + req->implementationId ? req->implementationId :"-", req->implementationName ?req->implementationName : "-", req->implementationVersion ? req->implementationVersion : "-"); @@ -289,7 +289,7 @@ static void log_1line_Z_APDU(Z_APDU *z_req, Z_APDU *z_res, WRBUF w) { wrbuf_puts(w, "ERROR "); log_DiagRecs( - w, + w, res->records->u.multipleNonSurDiagnostics->num_diagRecs, res->records->u.multipleNonSurDiagnostics->diagRecs); } @@ -330,14 +330,14 @@ static void log_1line_Z_APDU(Z_APDU *z_req, Z_APDU *z_res, WRBUF w) { wrbuf_puts(w, "ERROR "); log_DiagRecs( - w, + w, res->records->u.multipleNonSurDiagnostics->num_diagRecs, res->records->u.multipleNonSurDiagnostics->diagRecs); } wrbuf_puts(w, " "); assert(req->preferredRecordSyntax); log_syntax(w, req->preferredRecordSyntax); - + wrbuf_printf(w, " %s " ODR_INT_PRINTF "+" ODR_INT_PRINTF " ", req->resultSetId, *req->resultSetStartPoint, *req->numberOfRecordsRequested); @@ -382,8 +382,8 @@ static void log_1line_Z_APDU(Z_APDU *z_req, Z_APDU *z_res, WRBUF w) wrbuf_puts(w, "ERROR"); else wrbuf_printf(w, "PARTIAL" ODR_INT_PRINTF, *res->scanStatus); - - wrbuf_printf(w, " " ODR_INT_PRINTF " " ODR_INT_PRINTF "+" + + wrbuf_printf(w, " " ODR_INT_PRINTF " " ODR_INT_PRINTF "+" ODR_INT_PRINTF "+" ODR_INT_PRINTF " ", res->numberOfEntriesReturned ? *res->numberOfEntriesReturned : 0, @@ -391,8 +391,8 @@ static void log_1line_Z_APDU(Z_APDU *z_req, Z_APDU *z_res, WRBUF w) *req->preferredPositionInResponse : 1, *req->numberOfTermsRequested, res->stepSize ? *res->stepSize : 1); - - yaz_scan_to_wrbuf(w, req->termListAndStartPoint, + + yaz_scan_to_wrbuf(w, req->termListAndStartPoint, req->attributeSet); } break; @@ -410,7 +410,7 @@ static void log_1line_Z_APDU(Z_APDU *z_req, Z_APDU *z_res, WRBUF w) if (*res->sortStatus == Z_SortResponse_success) wrbuf_puts(w, "OK"); - else if (*res->sortStatus == Z_SortResponse_partial_1) + else if (*res->sortStatus == Z_SortResponse_partial_1) wrbuf_puts(w, "PARTIAL"); else if (*res->sortStatus == Z_SortResponse_failure) wrbuf_puts(w, "ERROR"); @@ -460,7 +460,7 @@ static void log_1line_Z_APDU(Z_APDU *z_req, Z_APDU *z_res, WRBUF w) if (res->diagnostics && res->num_diagnostics >= 1) log_DiagRecs(w, res->num_diagnostics,res->diagnostics); else - wrbuf_puts(w, "-"); + wrbuf_puts(w, "-"); } break; case Z_APDU_close: @@ -507,7 +507,7 @@ static void log_1line_Z_GDU(Z_GDU *gdu_req, Z_GDU *gdu_res, WRBUF w) { if (gdu_req && gdu_req->which == Z_GDU_Z3950) { - log_1line_Z_APDU(gdu_req->u.z3950, + log_1line_Z_APDU(gdu_req->u.z3950, (gdu_res && gdu_res->which == Z_GDU_Z3950) ? gdu_res->u.z3950 : 0, w); } @@ -558,26 +558,26 @@ void yf::Log::Impl::configure(const xmlNode *ptr) } else if (!strcmp((const char *) attr->name, "request-session")) - m_req_session = + m_req_session = mp::xml::get_bool(attr->children, true); - else if (!strcmp((const char *) attr->name, + else if (!strcmp((const char *) attr->name, "response-session")) - m_res_session = + m_res_session = mp::xml::get_bool(attr->children, true); else if (!strcmp((const char *) attr->name, "session")) { - m_req_session = + m_req_session = mp::xml::get_bool(attr->children, true); m_res_session = m_req_session; } - else if (!strcmp((const char *) attr->name, + else if (!strcmp((const char *) attr->name, "init-options")) - m_init_options = + m_init_options = mp::xml::get_bool(attr->children, true); - else if (!strcmp((const char *) attr->name, + else if (!strcmp((const char *) attr->name, "init-options")) - m_init_options = + m_init_options = mp::xml::get_bool(attr->children, true); else throw mp::filter::FilterException( @@ -587,7 +587,7 @@ void yf::Log::Impl::configure(const xmlNode *ptr) } else { - throw mp::filter::FilterException("Bad element " + throw mp::filter::FilterException("Bad element " + std::string((const char *) ptr->name)); } @@ -604,7 +604,7 @@ void yf::Log::Impl::process(mp::Package &package) // scope for session lock { boost::mutex::scoped_lock scoped_lock(m_session_mutex); - + if (gdu_req && gdu_req->which == Z_GDU_Z3950) { Z_APDU *apdu_req = gdu_req->u.z3950; @@ -618,31 +618,31 @@ void yf::Log::Impl::process(mp::Package &package) user = a->u.idPass->userId; else if (a->which == Z_IdAuthentication_open) user = a->u.open; - + m_sessions[package.session()] = user; } } } - std::map::iterator it = + std::map::iterator it = m_sessions.find(package.session()); if (it != m_sessions.end()) user = it->second; - + if (package.session().is_closed()) m_sessions.erase(package.session()); } // scope for locking Ostream - { + { boost::mutex::scoped_lock scoped_lock(m_file->m_mutex); - + if (m_access) { - if (gdu_req) + if (gdu_req) { std::ostringstream os; os << m_msg_config << " " << package << " " - << "0.000000" << " " + << "0.000000" << " " << *gdu_req; m_file->log(m_time_format, os); } @@ -650,12 +650,12 @@ void yf::Log::Impl::process(mp::Package &package) if (m_user_access) { - if (gdu_req) + if (gdu_req) { std::ostringstream os; os << m_msg_config << " " << user << " " << package << " " - << "0.000000" << " " + << "0.000000" << " " << *gdu_req; m_file->log(m_time_format, os); } @@ -666,7 +666,7 @@ void yf::Log::Impl::process(mp::Package &package) std::ostringstream os; os << m_msg_config; os << " request id=" << package.session().id(); - os << " close=" + os << " close=" << (package.session().is_closed() ? "yes" : "no"); m_file->log(m_time_format, os); } @@ -683,7 +683,7 @@ void yf::Log::Impl::process(mp::Package &package) m_file->log(m_time_format, os); } } - + if (m_req_apdu) { if (gdu_req) @@ -694,7 +694,7 @@ void yf::Log::Impl::process(mp::Package &package) } } } - + // unlocked during move package.move(); @@ -703,14 +703,14 @@ void yf::Log::Impl::process(mp::Package &package) yaz_timing_stop(timer); double duration = yaz_timing_get_real(timer); - // scope for locking Ostream - { + // scope for locking Ostream + { boost::mutex::scoped_lock scoped_lock(m_file->m_mutex); - + if (m_1line) { mp::wrbuf w; - + log_1line_Z_GDU(gdu_req, gdu_res, w); if (w.len() > 0) { @@ -748,7 +748,7 @@ void yf::Log::Impl::process(mp::Package &package) << std::fixed << std::setprecision (6) << duration << " " << *gdu_res; m_file->log(m_time_format, os); - } + } } if (m_res_session) @@ -756,9 +756,9 @@ void yf::Log::Impl::process(mp::Package &package) std::ostringstream os; os << m_msg_config; os << " response id=" << package.session().id(); - os << " close=" + os << " close=" << (package.session().is_closed() ? "yes " : "no ") - << "duration=" + << "duration=" << std::fixed << std::setprecision (6) << duration; m_file->log(m_time_format, os); } @@ -776,7 +776,7 @@ void yf::Log::Impl::process(mp::Package &package) m_file->log(m_time_format, os); } } - + if (m_res_apdu) { if (gdu_res) @@ -823,9 +823,9 @@ void yf::Log::Impl::option_write(const char *name, void *handle) } -yf::Log::Impl::LFile::LFile(std::string fname) : +yf::Log::Impl::LFile::LFile(std::string fname) : m_fname(fname) - + { if (fname.c_str()) fhandle = fopen(fname.c_str(), "a"); @@ -857,7 +857,7 @@ void yf::Log::Impl::LFile::log(const std::string &date_format, } fputs(os.str().c_str(), fhandle); fputc('\n', fhandle); - } + } else yaz_log(YLOG_LOG, "%s", os.str().c_str()); } diff --git a/src/filter_multi.cpp b/src/filter_multi.cpp index b32c115..4eb1988 100644 --- a/src/filter_multi.cpp +++ b/src/filter_multi.cpp @@ -70,7 +70,7 @@ namespace metaproxy_1 { BackendPtr m_backend; int m_pos; // position for backend (1=first, 2=second,.. int m_start; // present request start - PresentJob(BackendPtr ptr, int pos) : + PresentJob(BackendPtr ptr, int pos) : m_backend(ptr), m_pos(pos), m_start(0) {}; }; FrontendSet(std::string setname); @@ -108,13 +108,13 @@ namespace metaproxy_1 { void scan2(Package &package, Z_APDU *apdu); void relay_apdu(Package &package, Z_APDU *apdu); Rep *m_p; - }; + }; class Multi::Map { std::string m_target_pattern; std::string m_route; std::string m_auth; public: - Map(std::string pattern, std::string route, std::string auth) : + Map(std::string pattern, std::string route, std::string auth) : m_target_pattern(pattern), m_route(route), m_auth(auth) {}; bool match(const std::string target, std::string *ret, std::string *auth) const { @@ -130,7 +130,7 @@ namespace metaproxy_1 { class Multi::Rep { friend class Multi; friend struct Frontend; - + Rep(); FrontendPtr get_frontend(Package &package); void release_frontend(Package &package); @@ -173,13 +173,13 @@ yf::Multi::FrontendPtr yf::Multi::Rep::get_frontend(mp::Package &package) boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + while(true) { it = m_clients.find(package.session()); if (it == m_clients.end()) break; - + if (!it->second->m_in_use) { it->second->m_in_use = true; @@ -197,7 +197,7 @@ void yf::Multi::Rep::release_frontend(mp::Package &package) { boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + it = m_clients.find(package.session()); if (it != m_clients.end()) { @@ -237,7 +237,7 @@ yf::Multi::~Multi() { } -void yf::Multi::Backend::operator() (void) +void yf::Multi::Backend::operator() (void) { m_package->move(m_route); } @@ -277,7 +277,7 @@ void yf::Multi::FrontendSet::serve_order(int start, int number, std::list::const_iterator bsit; int voffset = 0; int offset = start + i - 1; - for (bsit = m_backend_sets.begin(); bsit != m_backend_sets.end(); + for (bsit = m_backend_sets.begin(); bsit != m_backend_sets.end(); bsit++) { if (offset >= voffset && offset < voffset + bsit->m_count) @@ -327,7 +327,7 @@ void yf::Multi::FrontendSet::round_robin(int start, int number, // Yes. skip until start.. Rounding off is deliberate! min = (start-p) / no_left; p += no_left * min; - + // update positions in each set.. std::list::iterator psit = pos.begin(); for (psit = pos.begin(); psit != pos.end(); psit++) @@ -336,11 +336,11 @@ void yf::Multi::FrontendSet::round_robin(int start, int number, } // skip on each set.. before "present range".. p = p + skip; - + std::list::iterator psit = pos.begin(); for (psit = pos.begin(); psit != pos.end(); psit++) *psit += min; - + omin = min; // update so we consider next class (with higher count) } #endif @@ -411,14 +411,14 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu) } m_is_multi = true; - // create init request + // create init request std::list::iterator bit; for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++) { mp::odr odr; BackendPtr b = *bit; Z_APDU *init_apdu = zget_APDU(odr, Z_APDU_initRequest); - + std::listvhost_one; vhost_one.push_back(b->m_vhost); mp::util::set_vhost_otherinfo(&init_apdu->u.initRequest->otherInfo, @@ -437,7 +437,7 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu) } else breq->idAuthentication = req->idAuthentication; - + *breq->preferredMessageSize = *req->preferredMessageSize; *breq->maximumRecordSize = *req->maximumRecordSize; @@ -445,11 +445,11 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu) ODR_MASK_SET(breq->options, Z_Options_present); ODR_MASK_SET(breq->options, Z_Options_namedResultSets); ODR_MASK_SET(breq->options, Z_Options_scan); - + ODR_MASK_SET(breq->protocolVersion, Z_ProtocolVersion_1); ODR_MASK_SET(breq->protocolVersion, Z_ProtocolVersion_2); ODR_MASK_SET(breq->protocolVersion, Z_ProtocolVersion_3); - + b->m_package->request() = init_apdu; b->m_package->copy_filter(package); @@ -466,7 +466,7 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu) ODR_MASK_SET(f_resp->options, Z_Options_present); ODR_MASK_SET(f_resp->options, Z_Options_namedResultSets); ODR_MASK_SET(f_resp->options, Z_Options_scan); - + ODR_MASK_SET(f_resp->protocolVersion, Z_ProtocolVersion_1); ODR_MASK_SET(f_resp->protocolVersion, Z_ProtocolVersion_2); ODR_MASK_SET(f_resp->protocolVersion, Z_ProtocolVersion_3); @@ -479,7 +479,7 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu) for (bit = m_backend_list.begin(); bit != m_backend_list.end(); ) { PackagePtr p = (*bit)->m_package; - + if (p->session().is_closed()) { // failed. Remove from list and increment number of failed @@ -515,7 +515,7 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu) } else { - if (!f_resp->userInformationField + if (!f_resp->userInformationField && b_resp->userInformationField) f_resp->userInformationField = b_resp->userInformationField; no_failed++; @@ -549,14 +549,14 @@ void yf::Multi::Frontend::init(mp::Package &package, Z_GDU *gdu) void yf::Multi::Frontend::search(mp::Package &package, Z_APDU *apdu_req) { - // create search request + // create search request Z_SearchRequest *req = apdu_req->u.searchRequest; // save these for later Odr_int smallSetUpperBound = *req->smallSetUpperBound; Odr_int largeSetLowerBound = *req->largeSetLowerBound; Odr_int mediumSetPresentNumber = *req->mediumSetPresentNumber; - + // they are altered now - to disable piggyback *req->smallSetUpperBound = 0; *req->largeSetLowerBound = 1; @@ -570,7 +570,7 @@ void yf::Multi::Frontend::search(mp::Package &package, Z_APDU *apdu_req) { PackagePtr p = (*bit)->m_package; mp::odr odr; - + if (!mp::util::set_databases_from_zurl(odr, (*bit)->m_vhost, &req->num_databaseNames, &req->databaseNames)) @@ -595,9 +595,9 @@ void yf::Multi::Frontend::search(mp::Package &package, Z_APDU *apdu_req) for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++) { PackagePtr p = (*bit)->m_package; - + // save closing package for at least one target - if (p->session().is_closed()) + if (p->session().is_closed()) close_p = p; Z_GDU *gdu = p->response().get(); @@ -606,7 +606,7 @@ void yf::Multi::Frontend::search(mp::Package &package, Z_APDU *apdu_req) { Z_APDU *b_apdu = gdu->u.z3950; Z_SearchResponse *b_resp = b_apdu->u.searchResponse; - + // see we get any errors (AKA diagnstics) if (b_resp->records) { @@ -705,24 +705,24 @@ void yf::Multi::Frontend::search(mp::Package &package, Z_APDU *apdu_req) *p_req->numberOfRecordsRequested = number; pp.request() = p_apdu; present(pp, p_apdu); - + if (pp.session().is_closed()) package.session().close(); - + Z_GDU *gdu = pp.response().get(); if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_presentResponse) { Z_PresentResponse *p_res = gdu->u.z3950->u.presentResponse; f_resp->records = p_res->records; - *f_resp->numberOfRecordsReturned = + *f_resp->numberOfRecordsReturned = *p_res->numberOfRecordsReturned; - *f_resp->nextResultSetPosition = + *f_resp->nextResultSetPosition = *p_res->nextResultSetPosition; } - else + else { - package.response() = pp.response(); + package.response() = pp.response(); return; } } @@ -731,7 +731,7 @@ void yf::Multi::Frontend::search(mp::Package &package, Z_APDU *apdu_req) void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req) { - // create present request + // create present request Z_PresentRequest *req = apdu_req->u.presentRequest; Sets_it it; @@ -739,7 +739,7 @@ void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req) if (it == m_sets.end()) { mp::odr odr; - Z_APDU *apdu = + Z_APDU *apdu = odr.create_presentResponse( apdu_req, YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST, @@ -802,7 +802,7 @@ void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req) *req->resultSetStartPoint = start; *req->numberOfRecordsRequested = end - start + 1; - + p->request() = apdu_req; p->copy_filter(package); @@ -818,17 +818,17 @@ void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req) for (; pbit != present_backend_list.end(); pbit++) { PackagePtr p = (*pbit)->m_package; - + if (p->session().is_closed()) // if any backend closes, close frontend package.session().close(); - + Z_GDU *gdu = p->response().get(); if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_presentResponse) { Z_APDU *b_apdu = gdu->u.z3950; Z_PresentResponse *b_resp = b_apdu->u.presentResponse; - + // see we get any errors (AKA diagnstics) if (b_resp->records) { @@ -839,7 +839,7 @@ void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req) } else { - // if any target does not return present response - return that + // if any target does not return present response - return that package.response() = p->response(); return; } @@ -856,7 +856,7 @@ void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req) } else if (number < 0 || (size_t) number > jobs.size()) { - f_apdu = + f_apdu = odr.create_presentResponse( apdu_req, YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE, @@ -879,7 +879,7 @@ void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req) for (jit = jobs.begin(); jit != jobs.end(); jit++, i++) { PackagePtr p = jit->m_backend->m_package; - + Z_GDU *gdu = p->response().get(); Z_APDU *b_apdu = gdu->u.z3950; Z_PresentResponse *b_resp = b_apdu->u.presentResponse; @@ -907,7 +907,7 @@ void yf::Multi::Frontend::scan1(mp::Package &package, Z_APDU *apdu_req) if (m_backend_list.size() > 1) { mp::odr odr; - Z_APDU *f_apdu = + Z_APDU *f_apdu = odr.create_scanResponse( apdu_req, YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP, 0); package.response() = f_apdu; @@ -923,7 +923,7 @@ void yf::Multi::Frontend::scan1(mp::Package &package, Z_APDU *apdu_req) { PackagePtr p = (*bit)->m_package; mp::odr odr; - + if (!mp::util::set_databases_from_zurl(odr, (*bit)->m_vhost, &req->num_databaseNames, &req->databaseNames)) @@ -939,10 +939,10 @@ void yf::Multi::Frontend::scan1(mp::Package &package, Z_APDU *apdu_req) for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++) { PackagePtr p = (*bit)->m_package; - + if (p->session().is_closed()) // if any backend closes, close frontend package.session().close(); - + Z_GDU *gdu = p->response().get(); if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_scanResponse) @@ -952,7 +952,7 @@ void yf::Multi::Frontend::scan1(mp::Package &package, Z_APDU *apdu_req) } else { - // if any target does not return scan response - return that + // if any target does not return scan response - return that package.response() = p->response(); return; } @@ -1000,7 +1000,7 @@ void yf::Multi::Frontend::relay_apdu(mp::Package &package, Z_APDU *apdu_req) { PackagePtr p = (*bit)->m_package; mp::odr odr; - + p->request() = apdu_req; p->copy_filter(package); } @@ -1008,10 +1008,10 @@ void yf::Multi::Frontend::relay_apdu(mp::Package &package, Z_APDU *apdu_req) for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++) { PackagePtr p = (*bit)->m_package; - + if (p->session().is_closed()) // if any backend closes, close frontend package.session().close(); - + package.response() = p->response(); } } @@ -1029,7 +1029,7 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req) { PackagePtr p = (*bit)->m_package; mp::odr odr; - + if (!mp::util::set_databases_from_zurl(odr, (*bit)->m_vhost, &req->num_databaseNames, &req->databaseNames)) @@ -1050,10 +1050,10 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req) for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++) { PackagePtr p = (*bit)->m_package; - + if (p->session().is_closed()) // if any backend closes, close frontend package.session().close(); - + Z_GDU *gdu = p->response().get(); if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_scanResponse) @@ -1067,9 +1067,9 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req) Z_APDU *f_apdu = odr.create_scanResponse(apdu_req, 1, 0); Z_ScanResponse *f_res = f_apdu->u.scanResponse; - f_res->entries->nonsurrogateDiagnostics = + f_res->entries->nonsurrogateDiagnostics = res->entries->nonsurrogateDiagnostics; - f_res->entries->num_nonsurrogateDiagnostics = + f_res->entries->num_nonsurrogateDiagnostics = res->entries->num_nonsurrogateDiagnostics; package.response() = f_apdu; @@ -1108,7 +1108,7 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req) } if (my.m_norm_term.length()) { - ScanTermInfoList::iterator it = + ScanTermInfoList::iterator it = entries_before.begin(); while (it != entries_before.end() && my <*it) it++; @@ -1149,7 +1149,7 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req) } if (my.m_norm_term.length()) { - ScanTermInfoList::iterator it = + ScanTermInfoList::iterator it = entries_after.begin(); while (it != entries_after.end() && *it < my) it++; @@ -1166,11 +1166,11 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req) } } - } + } } else { - // if any target does not return scan response - return that + // if any target does not return scan response - return that package.response() = p->response(); return; } @@ -1184,7 +1184,7 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req) { std::cout << " " << it->m_norm_term << " " << it->m_count << "\n"; } - + std::cout << "AFTER\n"; it = entries_after.begin(); for(; it != entries_after.end(); it++) @@ -1204,10 +1204,10 @@ void yf::Multi::Frontend::scan2(mp::Package &package, Z_APDU *apdu_req) mp::odr odr; Z_APDU *f_apdu = odr.create_scanResponse(apdu_req, 0, 0); Z_ScanResponse *resp = f_apdu->u.scanResponse; - + int number_returned = *req->numberOfTermsRequested; int position_returned = *req->preferredPositionInResponse; - + resp->entries->num_entries = number_returned; resp->entries->entries = (Z_Entry**) odr_malloc(odr, sizeof(Z_Entry*) * number_returned); @@ -1250,7 +1250,7 @@ void yf::Multi::process(mp::Package &package) const FrontendPtr f = m_p->get_frontend(package); Z_GDU *gdu = package.request().get(); - + if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_initRequest && !f->m_is_multi) { @@ -1264,12 +1264,12 @@ void yf::Multi::process(mp::Package &package) const if (apdu->which == Z_APDU_initRequest) { mp::odr odr; - + package.response() = odr.create_close( apdu, Z_Close_protocolError, "double init"); - + package.session().close(); } else if (apdu->which == Z_APDU_searchRequest) @@ -1291,11 +1291,11 @@ void yf::Multi::process(mp::Package &package) const else { mp::odr odr; - + package.response() = odr.create_close( apdu, Z_Close_protocolError, "unsupported APDU in filter multi"); - + package.session().close(); } } @@ -1341,7 +1341,7 @@ void mp::filter::Multi::configure(const xmlNode * ptr, bool test_only, else { throw mp::filter::FilterException - ("Bad element " + ("Bad element " + std::string((const char *) ptr->name) + " in multi filter"); } diff --git a/src/filter_query_rewrite.cpp b/src/filter_query_rewrite.cpp index f979ba4..6e77295 100644 --- a/src/filter_query_rewrite.cpp +++ b/src/filter_query_rewrite.cpp @@ -85,7 +85,7 @@ void yf::QueryRewrite::process(mp::Package &package) const void yf::QueryRewrite::Rep::process(mp::Package &package) const { Z_GDU *gdu = package.request().get(); - + if (gdu && gdu->which == Z_GDU_Z3950) { Z_APDU *apdu_req = gdu->u.z3950; @@ -95,12 +95,12 @@ void yf::QueryRewrite::Rep::process(mp::Package &package) const const char *addinfo = 0; mp::odr odr; Z_SearchRequest *req = apdu_req->u.searchRequest; - + if (m_stylesheet) { xmlDocPtr doc_input = 0; yaz_query2xml(req->query, &doc_input); - + if (!doc_input) { error_code = YAZ_BIB1_MALFORMED_QUERY; @@ -145,13 +145,13 @@ void yf::QueryRewrite::Rep::process(mp::Package &package) const } if (error_code) { - Z_APDU *f_apdu = + Z_APDU *f_apdu = odr.create_searchResponse(apdu_req, error_code, addinfo); package.response() = f_apdu; return; } package.request() = gdu; - } + } } package.move(); } @@ -174,16 +174,16 @@ void mp::filter::QueryRewrite::Rep::configure(const xmlNode *ptr, std::string fname; - for (struct _xmlAttr *attr = ptr->properties; + for (struct _xmlAttr *attr = ptr->properties; attr; attr = attr->next) { mp::xml::check_attribute(attr, "", "stylesheet"); - fname = mp::xml::get_text(attr); + fname = mp::xml::get_text(attr); } if (0 == fname.size()) throw mp::filter::FilterException - ("Attribute needs XSLT stylesheet path content" + " in query_rewrite filter"); @@ -199,14 +199,14 @@ void mp::filter::QueryRewrite::Rep::configure(const xmlNode *ptr, if (!m_stylesheet) { throw mp::filter::FilterException - ("Failed to read XSLT stylesheet '" + ("Failed to read XSLT stylesheet '" + fname + "' in query_rewrite filter"); } } else if (mp::xml::is_element_mp(ptr, "charset")) { - for (struct _xmlAttr *attr = ptr->properties; + for (struct _xmlAttr *attr = ptr->properties; attr; attr = attr->next) { if (!strcmp((const char *) attr->name, "from")) @@ -226,7 +226,7 @@ void mp::filter::QueryRewrite::Rep::configure(const xmlNode *ptr, else { throw mp::filter::FilterException - ("Bad element " + ("Bad element " + std::string((const char *) ptr->name) + " in query_rewrite filter"); } diff --git a/src/filter_record_transform.cpp b/src/filter_record_transform.cpp index a7cb28c..a6e3163 100644 --- a/src/filter_record_transform.cpp +++ b/src/filter_record_transform.cpp @@ -84,11 +84,11 @@ static int convert_usemarcon(void *info, WRBUF record, WRBUF wr_error) return -1; } p->usemarcon1->GetMarcRecord(converted, convlen); - + if (p->usemarcon2) { p->usemarcon2->SetMarcRecord(converted, convlen); - + res = p->usemarcon2->Convert(); free(converted); if (res != 0) @@ -170,7 +170,7 @@ static void type_usemarcon(struct yaz_record_conv_type *t) #endif // define Pimpl wrapper forwarding to Impl - + yf::RecordTransform::RecordTransform() : m_p(new Impl) { } @@ -191,14 +191,14 @@ void yf::RecordTransform::process(mp::Package &package) const } -yf::RecordTransform::Impl::Impl() +yf::RecordTransform::Impl::Impl() { m_retrieval = yaz_retrieval_create(); assert(m_retrieval); } yf::RecordTransform::Impl::~Impl() -{ +{ if (m_retrieval) yaz_retrieval_destroy(m_retrieval); } @@ -213,8 +213,8 @@ void yf::RecordTransform::Impl::configure(const xmlNode *xml_node, // parsing down to retrieval node, which can be any of the children nodes xmlNode *retrieval_node; - for (retrieval_node = xml_node->children; - retrieval_node; + for (retrieval_node = xml_node->children; + retrieval_node; retrieval_node = retrieval_node->next) { if (retrieval_node->type != XML_ELEMENT_NODE) @@ -270,20 +270,20 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const // the effective element set name.. Therefore we can only allow // two cases.. Both equal or absent.. If not, we'll just have to // disable the piggyback! - if (sr_req->smallSetElementSetNames + if (sr_req->smallSetElementSetNames && sr_req->mediumSetElementSetNames && sr_req->smallSetElementSetNames->which == Z_ElementSetNames_generic - && + && sr_req->mediumSetElementSetNames->which == Z_ElementSetNames_generic - && + && !strcmp(sr_req->smallSetElementSetNames->u.generic, sr_req->mediumSetElementSetNames->u.generic)) { input_schema = sr_req->smallSetElementSetNames->u.generic; } - else if (!sr_req->smallSetElementSetNames && + else if (!sr_req->smallSetElementSetNames && !sr_req->mediumSetElementSetNames) ; // input_schema is 0 already else @@ -302,7 +302,7 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const package.move(); return; } - + mp::odr odr_en(ODR_ENCODE); // setting up variables for conversion state @@ -314,7 +314,7 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const const char *backend_schema = 0; Odr_oid *backend_syntax = 0; - int ret_code + int ret_code = yaz_retrieval_request(m_retrieval, input_schema, input_syntax, &match_schema, &match_syntax, @@ -369,7 +369,7 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const if (sr_req) { - if (backend_syntax) + if (backend_syntax) sr_req->preferredRecordSyntax = odr_oiddup(odr_en, backend_syntax); else sr_req->preferredRecordSyntax = 0; @@ -380,7 +380,7 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const = (Z_ElementSetNames *) odr_malloc(odr_en, sizeof(Z_ElementSetNames)); sr_req->smallSetElementSetNames->which = Z_ElementSetNames_generic; - sr_req->smallSetElementSetNames->u.generic + sr_req->smallSetElementSetNames->u.generic = odr_strdup(odr_en, backend_schema); sr_req->mediumSetElementSetNames = sr_req->smallSetElementSetNames; } @@ -392,23 +392,23 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const } else if (pr_req) { - if (backend_syntax) + if (backend_syntax) pr_req->preferredRecordSyntax = odr_oiddup(odr_en, backend_syntax); else pr_req->preferredRecordSyntax = 0; - + if (backend_schema) { - pr_req->recordComposition - = (Z_RecordComposition *) + pr_req->recordComposition + = (Z_RecordComposition *) odr_malloc(odr_en, sizeof(Z_RecordComposition)); - pr_req->recordComposition->which + pr_req->recordComposition->which = Z_RecordComp_simple; - pr_req->recordComposition->u.simple + pr_req->recordComposition->u.simple = (Z_ElementSetNames *) odr_malloc(odr_en, sizeof(Z_ElementSetNames)); pr_req->recordComposition->u.simple->which = Z_ElementSetNames_generic; - pr_req->recordComposition->u.simple->u.generic + pr_req->recordComposition->u.simple->u.generic = odr_strdup(odr_en, backend_schema); } else @@ -419,7 +419,7 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const package.request() = gdu_req; package.move(); - + Z_GDU *gdu_res = package.response().get(); // see if we have a records list to patch! @@ -428,9 +428,9 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const gdu_res->u.z3950->which == Z_APDU_presentResponse) { Z_PresentResponse * pr_res = gdu_res->u.z3950->u.presentResponse; - - if (rc && pr_res - && pr_res->numberOfRecordsReturned + + if (rc && pr_res + && pr_res->numberOfRecordsReturned && *(pr_res->numberOfRecordsReturned) > 0 && pr_res->records && pr_res->records->which == Z_Records_DBOSD) @@ -442,9 +442,9 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const gdu_res->u.z3950->which == Z_APDU_searchResponse) { Z_SearchResponse *sr_res = gdu_res->u.z3950->u.searchResponse; - - if (rc && sr_res - && sr_res->numberOfRecordsReturned + + if (rc && sr_res + && sr_res->numberOfRecordsReturned && *(sr_res->numberOfRecordsReturned) > 0 && sr_res->records && sr_res->records->which == Z_Records_DBOSD) @@ -452,7 +452,7 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const records = sr_res->records->u.databaseOrSurDiagnostics; } } - + if (records) { int i; @@ -470,11 +470,11 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const yaz_record_conv_opac_record(rc, r->u.opac, output_record); } - else if (r->which == Z_External_octet) + else if (r->which == Z_External_octet) { ret_trans = yaz_record_conv_record(rc, (const char *) - r->u.octet_aligned->buf, + r->u.octet_aligned->buf, r->u.octet_aligned->len, output_record); } diff --git a/src/filter_session_shared.cpp b/src/filter_session_shared.cpp index cccaee8..b2e00d7 100644 --- a/src/filter_session_shared.cpp +++ b/src/filter_session_shared.cpp @@ -169,12 +169,12 @@ namespace metaproxy_1 { Rep *m_p; BackendClassPtr m_backend_class; FrontendSets m_frontend_sets; - }; + }; // representation class SessionShared::Rep { friend class SessionShared; friend struct Frontend; - + FrontendPtr get_frontend(Package &package); void release_frontend(Package &package); Rep(); @@ -208,7 +208,7 @@ yf::SessionShared::FrontendSet::FrontendSet( { } -const yf::SessionShared::Databases & +const yf::SessionShared::Databases & yf::SessionShared::FrontendSet::get_databases() { return m_databases; @@ -222,7 +222,7 @@ const yazpp_1::Yaz_Z_Query& yf::SessionShared::FrontendSet::get_query() yf::SessionShared::InitKey::InitKey(const InitKey &k) { m_odr = odr_createmem(ODR_ENCODE); - + m_idAuthentication_size = k.m_idAuthentication_size; m_idAuthentication_buf = (char*)odr_malloc(m_odr, m_idAuthentication_size); memcpy(m_idAuthentication_buf, k.m_idAuthentication_buf, @@ -254,7 +254,7 @@ yf::SessionShared::InitKey::~InitKey() } bool yf::SessionShared::InitKey::operator < (const SessionShared::InitKey &k) - const + const { int c; c = mp::util::memcmp2( @@ -284,7 +284,7 @@ void yf::SessionShared::BackendClass::release_backend(BackendInstancePtr b) void yf::SessionShared::BackendClass::remove_backend(BackendInstancePtr b) { BackendInstanceList::iterator it = m_backend_list.begin(); - + while (it != m_backend_list.end()) { if (*it == b) @@ -294,7 +294,7 @@ void yf::SessionShared::BackendClass::remove_backend(BackendInstancePtr b) 0, Z_Close_lackOfActivity, 0); (*it)->m_close_package->session().close(); (*it)->m_close_package->move(); - + it = m_backend_list.erase(it); } else @@ -304,22 +304,22 @@ void yf::SessionShared::BackendClass::remove_backend(BackendInstancePtr b) -yf::SessionShared::BackendInstancePtr +yf::SessionShared::BackendInstancePtr yf::SessionShared::BackendClass::get_backend( const mp::Package &frontend_package) { { boost::mutex::scoped_lock lock(m_mutex_backend_class); - + BackendInstanceList::const_iterator it = m_backend_list.begin(); - + BackendInstancePtr backend1; // null - + for (; it != m_backend_list.end(); it++) { if (!(*it)->m_in_use) { - if (!backend1 + if (!backend1 || (*it)->m_sequence_this < backend1->m_sequence_this) backend1 = *it; } @@ -395,7 +395,7 @@ yf::SessionShared::BackendInstancePtr yf::SessionShared::BackendClass::create_ba /* already closed. We don't know why */ return null; } - else if (gdu && gdu->which == Z_GDU_Z3950 + else if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_initResponse && *gdu->u.z3950->u.initResponse->result) { @@ -460,7 +460,7 @@ void yf::SessionShared::Rep::init(mp::Package &package, const Z_GDU *gdu, } else { - frontend->m_backend_class = it->second; + frontend->m_backend_class = it->second; } } BackendClassPtr bc = frontend->m_backend_class; @@ -489,11 +489,11 @@ void yf::SessionShared::Rep::init(mp::Package &package, const Z_GDU *gdu, Z_GDU *response_gdu = init_response.get(); mp::util::transfer_referenceId(odr, gdu->u.z3950, response_gdu->u.z3950); - + Z_Options *server_options = response_gdu->u.z3950->u.initResponse->options; Z_Options *client_options = &frontend->m_init_options; - + int i; for (i = 0; i < 30; i++) if (!ODR_MASK_GET(client_options, i)) @@ -515,7 +515,7 @@ yf::SessionShared::BackendSet::BackendSet( const Databases &databases, const yazpp_1::Yaz_Z_Query &query) : m_result_set_id(result_set_id), - m_databases(databases), m_result_set_size(0), m_query(query) + m_databases(databases), m_result_set_size(0), m_query(query) { timestamp(); } @@ -540,7 +540,7 @@ bool yf::SessionShared::BackendSet::search( req->query = m_query.get_Z_Query(); req->num_databaseNames = m_databases.size(); - req->databaseNames = (char**) + req->databaseNames = (char**) odr_malloc(odr, req->num_databaseNames * sizeof(char *)); Databases::const_iterator it = m_databases.begin(); size_t i = 0; @@ -557,7 +557,7 @@ bool yf::SessionShared::BackendSet::search( Z_GDU *gdu = search_package.response().get(); if (!search_package.session().is_closed() - && gdu && gdu->which == Z_GDU_Z3950 + && gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_searchResponse) { Z_SearchResponse *b_resp = gdu->u.z3950->u.searchResponse; @@ -620,7 +620,7 @@ void yf::SessionShared::Frontend::override_set( if (bc->m_named_result_sets) { result_set_id = boost::io::str( - boost::format("%1%") % + boost::format("%1%") % found_backend->m_result_set_sequence); found_backend->m_result_set_sequence++; } @@ -649,7 +649,7 @@ restart: if ((int) bc->m_backend_list.size() >= m_p->m_session_max) out_of_sessions = true; - + if (m_p->m_optimize_search) { // look at each backend and see if we have a similar search @@ -689,7 +689,7 @@ restart: Z_APDU *f_apdu = 0; mp::odr odr; const char *addinfo = 0; - + if (out_of_sessions) addinfo = "session_shared: all sessions in use"; if (apdu_req->which == Z_APDU_searchRequest) @@ -733,7 +733,7 @@ restart: apdu_req, found_backend, &z_records)) { bc->remove_backend(found_backend); - return; // search error + return; // search error } if (z_records) @@ -747,14 +747,14 @@ restart: else if (z_records->which == Z_Records_multipleNSD) { if (z_records->u.multipleNonSurDiagnostics->num_diagRecs >= 1 - && - + && + z_records->u.multipleNonSurDiagnostics->diagRecs[0]->which == Z_DiagRec_defaultFormat) { condition = get_diagnostic( z_records->u.multipleNonSurDiagnostics->diagRecs[0]->u.defaultFormat); - + } } if (m_p->m_restart && !session_restarted && @@ -773,7 +773,7 @@ restart: mp::odr odr; if (apdu_req->which == Z_APDU_searchRequest) { - Z_APDU *f_apdu = odr.create_searchResponse(apdu_req, + Z_APDU *f_apdu = odr.create_searchResponse(apdu_req, 0, 0); Z_SearchResponse *f_resp = f_apdu->u.searchResponse; *f_resp->searchStatus = Z_SearchResponse_none; @@ -782,14 +782,14 @@ restart: } if (apdu_req->which == Z_APDU_presentRequest) { - Z_APDU *f_apdu = odr.create_presentResponse(apdu_req, + Z_APDU *f_apdu = odr.create_presentResponse(apdu_req, 0, 0); Z_PresentResponse *f_resp = f_apdu->u.presentResponse; f_resp->records = z_records; package.response() = f_apdu; } bc->release_backend(found_backend); - return; // search error + return; // search error } } if (m_p->m_restart && !session_restarted && new_set->m_result_set_size < 0) @@ -810,28 +810,28 @@ void yf::SessionShared::Frontend::search(mp::Package &package, Z_APDU *apdu_req) { Z_SearchRequest *req = apdu_req->u.searchRequest; - FrontendSets::iterator fset_it = + FrontendSets::iterator fset_it = m_frontend_sets.find(req->resultSetName); if (fset_it != m_frontend_sets.end()) { - // result set already exist + // result set already exist // if replace indicator is off: we return diagnostic if // result set already exist. if (*req->replaceIndicator == 0) { mp::odr odr; - Z_APDU *apdu = + Z_APDU *apdu = odr.create_searchResponse( apdu_req, YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF, 0); package.response() = apdu; - + return; } m_frontend_sets.erase(fset_it); } - + yazpp_1::Yaz_Z_Query query; query.set_Z_Query(req->query); Databases databases; @@ -864,12 +864,12 @@ void yf::SessionShared::Frontend::present(mp::Package &package, mp::odr odr; Z_PresentRequest *req = apdu_req->u.presentRequest; - FrontendSets::iterator fset_it = + FrontendSets::iterator fset_it = m_frontend_sets.find(req->resultSetId); if (fset_it == m_frontend_sets.end()) { - Z_APDU *apdu = + Z_APDU *apdu = odr.create_presentResponse( apdu_req, YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST, @@ -891,7 +891,7 @@ void yf::SessionShared::Frontend::present(mp::Package &package, return; Z_NamePlusRecordList *npr_res = 0; - if (found_set->m_record_cache.lookup(odr, &npr_res, + if (found_set->m_record_cache.lookup(odr, &npr_res, *req->resultSetStartPoint, *req->numberOfRecordsRequested, req->preferredRecordSyntax, @@ -900,14 +900,14 @@ void yf::SessionShared::Frontend::present(mp::Package &package, Z_APDU *f_apdu_res = odr.create_presentResponse(apdu_req, 0, 0); Z_PresentResponse *f_resp = f_apdu_res->u.presentResponse; - yaz_log(YLOG_LOG, "Found " ODR_INT_PRINTF "+" ODR_INT_PRINTF + yaz_log(YLOG_LOG, "Found " ODR_INT_PRINTF "+" ODR_INT_PRINTF " records in cache %p", - *req->resultSetStartPoint, + *req->resultSetStartPoint, *req->numberOfRecordsRequested, - &found_set->m_record_cache); + &found_set->m_record_cache); *f_resp->numberOfRecordsReturned = *req->numberOfRecordsRequested; - *f_resp->nextResultSetPosition = + *f_resp->nextResultSetPosition = *req->resultSetStartPoint + *req->numberOfRecordsRequested; // f_resp->presentStatus assumed OK. f_resp->records = (Z_Records *) odr_malloc(odr, sizeof(Z_Records)); @@ -919,7 +919,7 @@ void yf::SessionShared::Frontend::present(mp::Package &package, } found_backend->timestamp(); - + Z_APDU *p_apdu = zget_APDU(odr, Z_APDU_presentRequest); Z_PresentRequest *p_req = p_apdu->u.presentRequest; p_req->preferredRecordSyntax = req->preferredRecordSyntax; @@ -938,7 +938,7 @@ void yf::SessionShared::Frontend::present(mp::Package &package, Z_GDU *gdu = present_package.response().get(); if (!present_package.session().is_closed() - && gdu && gdu->which == Z_GDU_Z3950 + && gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_presentResponse) { Z_PresentResponse *b_resp = gdu->u.z3950->u.presentResponse; @@ -956,13 +956,13 @@ void yf::SessionShared::Frontend::present(mp::Package &package, { yaz_log(YLOG_LOG, "Adding " ODR_INT_PRINTF "+" ODR_INT_PRINTF " records to cache %p", - *req->resultSetStartPoint, + *req->resultSetStartPoint, *f_resp->numberOfRecordsReturned, - &found_set->m_record_cache); + &found_set->m_record_cache); found_set->m_record_cache.add( odr, b_resp->records->u.databaseOrSurDiagnostics, - *req->resultSetStartPoint, + *req->resultSetStartPoint, *f_resp->numberOfRecordsReturned); } bc->release_backend(found_backend); @@ -970,7 +970,7 @@ void yf::SessionShared::Frontend::present(mp::Package &package, else { bc->remove_backend(found_backend); - Z_APDU *f_apdu_res = + Z_APDU *f_apdu_res = odr.create_presentResponse( apdu_req, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, 0); package.response() = f_apdu_res; @@ -1025,7 +1025,7 @@ void yf::SessionShared::BackendClass::expire_class() while (bit != m_backend_list.end()) { time_t last_use = (*bit)->m_time_last_use; - + if ((*bit)->m_in_use) { bit++; @@ -1055,7 +1055,7 @@ void yf::SessionShared::Rep::expire() boost::xtime_get(&xt, boost::TIME_UTC); xt.sec += m_session_ttl / 3; boost::thread::sleep(xt); - + BackendClassMap::const_iterator b_it = m_backend_map.begin(); for (; b_it != m_backend_map.end(); b_it++) b_it->second->expire_class(); @@ -1103,13 +1103,13 @@ yf::SessionShared::FrontendPtr yf::SessionShared::Rep::get_frontend(mp::Package boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + while(true) { it = m_clients.find(package.session()); if (it == m_clients.end()) break; - + if (!it->second->m_in_use) { it->second->m_in_use = true; @@ -1127,7 +1127,7 @@ void yf::SessionShared::Rep::release_frontend(mp::Package &package) { boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + it = m_clients.find(package.session()); if (it != m_clients.end()) { @@ -1149,7 +1149,7 @@ void yf::SessionShared::process(mp::Package &package) const FrontendPtr f = m_p->get_frontend(package); Z_GDU *gdu = package.request().get(); - + if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_initRequest && !f->m_is_virtual) { @@ -1163,18 +1163,18 @@ void yf::SessionShared::process(mp::Package &package) const if (apdu->which == Z_APDU_initRequest) { mp::odr odr; - + package.response() = odr.create_close( apdu, Z_Close_protocolError, "double init"); - + package.session().close(); } else if (apdu->which == Z_APDU_close) { mp::odr odr; - + package.response() = odr.create_close( apdu, Z_Close_peerAbort, "received close from client"); @@ -1195,11 +1195,11 @@ void yf::SessionShared::process(mp::Package &package) const else { mp::odr odr; - + package.response() = odr.create_close( apdu, Z_Close_protocolError, "unsupported APDU in filter_session_shared"); - + package.session().close(); } } @@ -1219,11 +1219,11 @@ void yf::SessionShared::configure(const xmlNode *ptr, bool test_only, for (attr = ptr->properties; attr; attr = attr->next) { if (!strcmp((const char *) attr->name, "ttl")) - m_p->m_resultset_ttl = + m_p->m_resultset_ttl = mp::xml::get_int(attr->children, 30); else if (!strcmp((const char *) attr->name, "max")) { - m_p->m_resultset_max = + m_p->m_resultset_max = mp::xml::get_int(attr->children, 10); } else if (!strcmp((const char *) attr->name, "optimizesearch")) @@ -1247,10 +1247,10 @@ void yf::SessionShared::configure(const xmlNode *ptr, bool test_only, for (attr = ptr->properties; attr; attr = attr->next) { if (!strcmp((const char *) attr->name, "ttl")) - m_p->m_session_ttl = + m_p->m_session_ttl = mp::xml::get_int(attr->children, 90); else if (!strcmp((const char *) attr->name, "max")) - m_p->m_session_max = + m_p->m_session_max = mp::xml::get_int(attr->children, 100); else throw mp::filter::FilterException( @@ -1260,7 +1260,7 @@ void yf::SessionShared::configure(const xmlNode *ptr, bool test_only, } else { - throw mp::filter::FilterException("Bad element " + throw mp::filter::FilterException("Bad element " + std::string((const char *) ptr->name)); } diff --git a/src/filter_sort.cpp b/src/filter_sort.cpp index 784c6f9..5f56451 100644 --- a/src/filter_sort.cpp +++ b/src/filter_sort.cpp @@ -124,37 +124,37 @@ static void print_xpath_nodes(xmlNodeSetPtr nodes, FILE* output) xmlNodePtr cur; int size; int i; - + assert(output); size = nodes ? nodes->nodeNr : 0; - + fprintf(output, "Result (%d nodes):\n", size); for (i = 0; i < size; ++i) { assert(nodes->nodeTab[i]); - + if (nodes->nodeTab[i]->type == XML_NAMESPACE_DECL) { xmlNsPtr ns = (xmlNsPtr)nodes->nodeTab[i]; cur = (xmlNodePtr)ns->next; if (cur->ns) - fprintf(output, "= namespace \"%s\"=\"%s\" for node %s:%s\n", + fprintf(output, "= namespace \"%s\"=\"%s\" for node %s:%s\n", ns->prefix, ns->href, cur->ns->href, cur->name); else - fprintf(output, "= namespace \"%s\"=\"%s\" for node %s\n", + fprintf(output, "= namespace \"%s\"=\"%s\" for node %s\n", ns->prefix, ns->href, cur->name); } else if (nodes->nodeTab[i]->type == XML_ELEMENT_NODE) { - cur = nodes->nodeTab[i]; + cur = nodes->nodeTab[i]; if (cur->ns) - fprintf(output, "= element node \"%s:%s\"\n", + fprintf(output, "= element node \"%s:%s\"\n", cur->ns->href, cur->name); else fprintf(output, "= element node \"%s\"\n", cur->name); } else { - cur = nodes->nodeTab[i]; + cur = nodes->nodeTab[i]; fprintf(output, "= node \"%s\": type %d\n", cur->name, cur->type); } } @@ -167,15 +167,15 @@ bool yf::Sort::Record::register_namespaces(xmlXPathContextPtr xpathCtx, xmlChar* prefix; xmlChar* href; xmlChar* next; - + assert(xpathCtx); assert(nsList); nsListDup = xmlStrdup((const xmlChar *) nsList); if (!nsListDup) return false; - - next = nsListDup; + + next = nsListDup; while (next) { /* skip spaces */ @@ -192,13 +192,13 @@ bool yf::Sort::Record::register_namespaces(xmlXPathContextPtr xpathCtx, xmlFree(nsListDup); return false; } - *next++ = '\0'; - + *next++ = '\0'; + /* find href */ href = next; next = (xmlChar*)xmlStrchr(next, ' '); if (next) - *next++ = '\0'; + *next++ = '\0'; /* do register namespace */ if (xmlXPathRegisterNs(xpathCtx, prefix, href) != 0) @@ -207,7 +207,7 @@ bool yf::Sort::Record::register_namespaces(xmlXPathContextPtr xpathCtx, return false; } } - + xmlFree(nsListDup); return true; } @@ -219,7 +219,7 @@ void yf::Sort::Record::get_xpath(xmlDoc *doc, const char *namespaces, { xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); if (xpathCtx) - { + { register_namespaces(xpathCtx, namespaces); xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression((const xmlChar *) expr, xpathCtx); @@ -260,7 +260,7 @@ void yf::Sort::Record::get_xpath(xmlDoc *doc, const char *namespaces, yf::Sort::Record::Record(Z_NamePlusRecord *n, const char *namespaces, const char *expr, - bool debug) : npr(n) + bool debug) : npr(n) { if (npr->which == Z_NamePlusRecord_databaseRecord) { @@ -307,9 +307,9 @@ yf::Sort::RecordList::RecordList(Odr_oid *syntax, yf::Sort::RecordList::~RecordList() { - + } - + bool yf::Sort::RecordList::cmp(Odr_oid *syntax) { if ((!this->syntax && !syntax) @@ -371,7 +371,7 @@ void yf::Sort::process(mp::Package &package) const } -yf::Sort::Frontend::Frontend(Impl *impl) : +yf::Sort::Frontend::Frontend(Impl *impl) : m_p(impl), m_is_virtual(false), m_in_use(true) { } @@ -386,7 +386,7 @@ yf::Sort::Impl::Impl() : m_prefetch(20), m_ascending(true), m_debug(false) } yf::Sort::Impl::~Impl() -{ +{ } yf::Sort::FrontendPtr yf::Sort::Impl::get_frontend(mp::Package &package) @@ -394,13 +394,13 @@ yf::Sort::FrontendPtr yf::Sort::Impl::get_frontend(mp::Package &package) boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + while(true) { it = m_clients.find(package.session()); if (it == m_clients.end()) break; - + if (!it->second->m_in_use) { it->second->m_in_use = true; @@ -418,7 +418,7 @@ void yf::Sort::Impl::release_frontend(mp::Package &package) { boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + it = m_clients.find(package.session()); if (it != m_clients.end()) { @@ -442,7 +442,7 @@ void yf::Sort::Impl::configure(const xmlNode *ptr, bool test_only, if (ptr->type != XML_ELEMENT_NODE) continue; if (!strcmp((const char *) ptr->name, "sort")) - { + { const struct _xmlAttr *attr; for (attr = ptr->properties; attr; attr = attr->next) { @@ -452,7 +452,7 @@ void yf::Sort::Impl::configure(const xmlNode *ptr, bool test_only, if (m_prefetch < 0) { throw mp::filter::FilterException( - "Bad or missing value for attribute " + + "Bad or missing value for attribute " + std::string((const char *) attr->name)); } } @@ -481,7 +481,7 @@ void yf::Sort::Impl::configure(const xmlNode *ptr, bool test_only, else { throw mp::filter::FilterException - ("Bad element " + ("Bad element " + std::string((const char *) ptr->name) + " in sort filter"); } @@ -568,7 +568,7 @@ void yf::Sort::Frontend::handle_records(mp::Package &package, void yf::Sort::Frontend::handle_search(mp::Package &package, Z_APDU *apdu_req) { - Z_SearchRequest *req = apdu_req->u.searchRequest; + Z_SearchRequest *req = apdu_req->u.searchRequest; std::string resultSetId = req->resultSetName; Package b_package(package.session(), package.origin()); mp::odr odr; @@ -581,19 +581,19 @@ void yf::Sort::Frontend::handle_search(mp::Package &package, Z_APDU *apdu_req) Sets_it sets_it = m_sets.find(req->resultSetName); if (sets_it != m_sets.end()) { - // result set already exist + // result set already exist // if replace indicator is off: we return diagnostic if // result set already exist. if (*req->replaceIndicator == 0) { - Z_APDU *apdu = + Z_APDU *apdu = odr.create_searchResponse( apdu_req, YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF, 0); package.response() = apdu; return; - } + } m_sets.erase(resultSetId); } ResultSetPtr s(new ResultSet); @@ -613,7 +613,7 @@ void yf::Sort::Frontend::handle_search(mp::Package &package, Z_APDU *apdu_req) void yf::Sort::Frontend::handle_present(mp::Package &package, Z_APDU *apdu_req) { - Z_PresentRequest *req = apdu_req->u.presentRequest; + Z_PresentRequest *req = apdu_req->u.presentRequest; std::string resultSetId = req->resultSetId; Package b_package(package.session(), package.origin()); mp::odr odr; @@ -627,7 +627,7 @@ void yf::Sort::Frontend::handle_present(mp::Package &package, Z_APDU *apdu_req) Sets_it sets_it = m_sets.find(resultSetId); if (sets_it == m_sets.end()) { - Z_APDU *apdu = + Z_APDU *apdu = odr.create_presentResponse( apdu_req, YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST, @@ -640,7 +640,7 @@ void yf::Sort::Frontend::handle_present(mp::Package &package, Z_APDU *apdu_req) for (; it != rset->record_lists.end(); it++) if ((*it)->cmp(req->preferredRecordSyntax)) { - if (*req->resultSetStartPoint - 1 + *req->numberOfRecordsRequested + if (*req->resultSetStartPoint - 1 + *req->numberOfRecordsRequested <= (*it)->size()) { int i; @@ -649,9 +649,9 @@ void yf::Sort::Frontend::handle_present(mp::Package &package, Z_APDU *apdu_req) *p_res->nextResultSetPosition = *req->resultSetStartPoint + *req->numberOfRecordsRequested; - *p_res->numberOfRecordsReturned = + *p_res->numberOfRecordsReturned = *req->numberOfRecordsRequested; - p_res->records = (Z_Records *) + p_res->records = (Z_Records *) odr_malloc(odr, sizeof(*p_res->records)); p_res->records->which = Z_Records_DBOSD; Z_NamePlusRecordList *nprl = (Z_NamePlusRecordList *) @@ -676,7 +676,7 @@ void yf::Sort::Frontend::handle_present(mp::Package &package, Z_APDU *apdu_req) Z_APDU_presentResponse) { Z_PresentResponse *res = gdu_res->u.z3950->u.presentResponse; - handle_records(b_package, apdu_req, res->records, + handle_records(b_package, apdu_req, res->records, start, rset, syntax, resultSetId.c_str()); package.response() = gdu_res; } diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 65481bd..6590d4d 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -73,16 +73,16 @@ namespace metaproxy_1 { boost::mutex m_mutex_session; boost::condition m_cond_session_ready; - std::map m_clients; + std::map m_clients; private: void sru(metaproxy_1::Package &package, Z_GDU *zgdu_req); int z3950_build_query( - mp::odr &odr_en, Z_Query *z_query, + mp::odr &odr_en, Z_Query *z_query, const Z_SRW_searchRetrieveRequest *req ) const; - + bool z3950_init_request( - mp::Package &package, + mp::Package &package, mp::odr &odr_en, std::string zurl, Z_SRW_PDU *sru_pdu_res, @@ -105,15 +105,15 @@ namespace metaproxy_1 { Z_SRW_PDU *sru_pdu_res, Z_SRW_searchRetrieveRequest const *sr_req ) const; - + bool z3950_to_srw_diagnostics_ok( - mp::odr &odr_en, + mp::odr &odr_en, Z_SRW_searchRetrieveResponse *srw_res, Z_Records *records ) const; - + int z3950_to_srw_diag( - mp::odr &odr_en, + mp::odr &odr_en, Z_SRW_searchRetrieveResponse *srw_res, Z_DefaultDiagFormat *ddf ) const; @@ -144,24 +144,24 @@ void yf::SRUtoZ3950::process(mp::Package &package) const void yf::SRUtoZ3950::Impl::configure(const xmlNode *confignode) { const xmlNode * dbnode; - + for (dbnode = confignode->children; dbnode; dbnode = dbnode->next) { if (dbnode->type != XML_ELEMENT_NODE) continue; - + std::string database; mp::xml::check_element_mp(dbnode, "database"); - for (struct _xmlAttr *attr = dbnode->properties; + for (struct _xmlAttr *attr = dbnode->properties; attr; attr = attr->next) { - + mp::xml::check_attribute(attr, "", "name"); database = mp::xml::get_text(attr); - + const xmlNode *explainnode; - for (explainnode = dbnode->children; + for (explainnode = dbnode->children; explainnode; explainnode = explainnode->next) { if (explainnode->type != XML_ELEMENT_NODE) @@ -169,7 +169,7 @@ void yf::SRUtoZ3950::Impl::configure(const xmlNode *confignode) if (explainnode) break; } - // assigning explain node to database name - no check yet + // assigning explain node to database name - no check yet m_database_explain.insert(std::make_pair(database, explainnode)); } } @@ -177,7 +177,7 @@ void yf::SRUtoZ3950::Impl::configure(const xmlNode *confignode) void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) { - bool ok = true; + bool ok = true; mp::odr odr_de(ODR_DECODE); Z_SRW_PDU *sru_pdu_req = 0; @@ -203,28 +203,28 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) char *stylesheet = 0; // filter acts as sink for non-valid SRU requests - if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en, + if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en, sru_pdu_res, &soap, charset, stylesheet))) { if (soap) { - mp_util::build_sru_explain(package, odr_en, sru_pdu_res, + mp_util::build_sru_explain(package, odr_en, sru_pdu_res, sruinfo, explainnode); - mp_util::build_sru_response(package, odr_en, soap, + mp_util::build_sru_response(package, odr_en, soap, sru_pdu_res, charset, stylesheet); } else { - metaproxy_1::odr odr; - Z_GDU *zgdu_res = - odr.create_HTTP_Response(package.session(), + metaproxy_1::odr odr; + Z_GDU *zgdu_res = + odr.create_HTTP_Response(package.session(), zgdu_req->u.HTTP_Request, 400); package.response() = zgdu_res; } return; } - + bool enable_package_log = false; std::string zurl; Z_SRW_extra_arg *arg; @@ -256,19 +256,19 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) if (sru_pdu_req->which == Z_SRW_explain_request) { Z_SRW_explainRequest *er_req = sru_pdu_req->u.explain_request; - mp_util::build_sru_explain(package, odr_en, sru_pdu_res, + mp_util::build_sru_explain(package, odr_en, sru_pdu_res, sruinfo, explainnode, er_req); } else if (sru_pdu_req->which == Z_SRW_searchRetrieve_request && sru_pdu_req->u.request) { // searchRetrieve - Z_SRW_searchRetrieveRequest *sr_req = sru_pdu_req->u.request; - + Z_SRW_searchRetrieveRequest *sr_req = sru_pdu_req->u.request; + sru_pdu_res = yaz_srw_get_pdu(odr_en, Z_SRW_searchRetrieve_response, sru_pdu_req->srw_version); // checking that we have a query - ok = mp_util::check_sru_query_exists(package, odr_en, + ok = mp_util::check_sru_query_exists(package, odr_en, sru_pdu_res, sr_req); if (ok && z3950_init_request(package, odr_en, @@ -276,8 +276,8 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) { ok = z3950_search_request(package, odr_en, sru_pdu_res, sr_req, zurl); - - if (ok + + if (ok && sru_pdu_res->u.response->numberOfRecords && *(sru_pdu_res->u.response->numberOfRecords)) @@ -294,20 +294,20 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) { sru_pdu_res = yaz_srw_get_pdu(odr_en, Z_SRW_scan_response, sru_pdu_req->srw_version); - + // we do not do scan at the moment, therefore issuing a diagnostic yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.scan_response->diagnostics), - &(sru_pdu_res->u.scan_response->num_diagnostics), + &(sru_pdu_res->u.scan_response->diagnostics), + &(sru_pdu_res->u.scan_response->num_diagnostics), YAZ_SRW_UNSUPP_OPERATION, "scan"); } else { sru_pdu_res = yaz_srw_get(odr_en, Z_SRW_explain_response); - + yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.explain_response->diagnostics), - &(sru_pdu_res->u.explain_response->num_diagnostics), + &(sru_pdu_res->u.explain_response->diagnostics), + &(sru_pdu_res->u.explain_response->num_diagnostics), YAZ_SRW_UNSUPP_OPERATION, "unknown"); } @@ -318,19 +318,19 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req) if (l.length()) { mp::wrbuf w; - + wrbuf_puts(w, "\n"); wrbuf_xmlputs(w, l.c_str()); wrbuf_puts(w, ""); - + sru_pdu_res->extraResponseData_len = w.len(); sru_pdu_res->extraResponseData_buf = odr_strdup(odr_en, wrbuf_cstr(w)); } } - + // build and send SRU response - mp_util::build_sru_response(package, odr_en, soap, + mp_util::build_sru_response(package, odr_en, soap, sru_pdu_res, charset, stylesheet); } @@ -350,13 +350,13 @@ yf::SRUtoZ3950::FrontendPtr yf::SRUtoZ3950::Impl::get_frontend( boost::mutex::scoped_lock lock(m_mutex_session); std::map::iterator it; - + while (true) { it = m_clients.find(package.session()); if (it == m_clients.end()) break; - + if (!it->second->m_in_use) { it->second->m_in_use = true; @@ -374,7 +374,7 @@ void yf::SRUtoZ3950::Impl::release_frontend(mp::Package &package) { boost::mutex::scoped_lock lock(m_mutex_session); std::map::iterator it; - + it = m_clients.find(package.session()); if (it != m_clients.end()) { @@ -419,9 +419,9 @@ void yf::SRUtoZ3950::Impl::process(mp::Package &package) { const char *path = zgdu_req->u.HTTP_Request->path; boost::mutex::scoped_lock lock(m_url_mutex); - + ActiveUrlMap::iterator it = m_active_urls.find(path); - + m_active_urls.erase(it); m_cond_url_ready.notify_all(); } @@ -433,8 +433,8 @@ void yf::SRUtoZ3950::Impl::process(mp::Package &package) release_frontend(package); } -bool -yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package, +bool +yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package, mp::odr &odr_en, std::string zurl, Z_SRW_PDU *sru_pdu_res, @@ -469,7 +469,7 @@ yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package, *init_req->preferredMessageSize = 10*1024*1024; *init_req->maximumRecordSize = 10*1024*1024; - + ODR_MASK_SET(init_req->options, Z_Options_search); ODR_MASK_SET(init_req->options, Z_Options_present); ODR_MASK_SET(init_req->options, Z_Options_namedResultSets); @@ -480,7 +480,7 @@ yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package, ODR_MASK_SET(init_req->protocolVersion, Z_ProtocolVersion_3); if (zurl.length()) - { + { std::string host; std::list dblist; mp_util::split_zurl(zurl, host, dblist); @@ -505,11 +505,11 @@ yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package, // check successful initResponse Z_GDU *z3950_gdu = z3950_package.response().get(); - if (z3950_gdu && z3950_gdu->which == Z_GDU_Z3950 - && z3950_gdu->u.z3950->which == Z_APDU_initResponse + if (z3950_gdu && z3950_gdu->which == Z_GDU_Z3950 + && z3950_gdu->u.z3950->which == Z_APDU_initResponse && *z3950_gdu->u.z3950->u.initResponse->result) return true; - + yaz_add_srw_diagnostic(odr_en, &(sru_pdu_res->u.response->diagnostics), &(sru_pdu_res->u.response->num_diagnostics), @@ -532,10 +532,10 @@ bool yf::SRUtoZ3950::Impl::z3950_close_request(mp::Package &package) const return false; } -bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, +bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, mp::odr &odr_en, Z_SRW_PDU *sru_pdu_res, - Z_SRW_searchRetrieveRequest + Z_SRW_searchRetrieveRequest const *sr_req, std::string zurl) const { @@ -561,34 +561,34 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, odr_malloc(odr_en, sizeof(char *)); if (sr_req->database) - z_searchRequest->databaseNames[0] + z_searchRequest->databaseNames[0] = odr_strdup(odr_en, const_cast(sr_req->database)); else - z_searchRequest->databaseNames[0] + z_searchRequest->databaseNames[0] = odr_strdup(odr_en, "Default"); } Z_Query *z_query = (Z_Query *) odr_malloc(odr_en, sizeof(Z_Query)); z_searchRequest->query = z_query; - + int sru_diagnostic = z3950_build_query(odr_en, z_query, sr_req); if (sru_diagnostic) - { + { yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.response->diagnostics), - &(sru_pdu_res->u.response->num_diagnostics), + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), sru_diagnostic, "query"); return false; } z3950_package.request() = apdu; - + z3950_package.move(); Z_GDU *z3950_gdu = z3950_package.response().get(); - if (!z3950_gdu || z3950_gdu->which != Z_GDU_Z3950 + if (!z3950_gdu || z3950_gdu->which != Z_GDU_Z3950 || z3950_gdu->u.z3950->which != Z_APDU_searchResponse || !z3950_gdu->u.z3950->u.searchResponse || !z3950_gdu->u.z3950->u.searchResponse->searchStatus) @@ -599,10 +599,10 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, YAZ_SRW_SYSTEM_TEMPORARILY_UNAVAILABLE, 0); return false; } - + Z_SearchResponse *sr = z3950_gdu->u.z3950->u.searchResponse; - if (!z3950_to_srw_diagnostics_ok(odr_en, sru_pdu_res->u.response, + if (!z3950_to_srw_diagnostics_ok(odr_en, sru_pdu_res->u.response, sr->records)) { return false; @@ -614,7 +614,7 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package, } bool yf::SRUtoZ3950::Impl::z3950_present_request( - mp::Package &package, + mp::Package &package, mp::odr &odr_en, Z_SRW_PDU *sru_pdu_res, const Z_SRW_searchRetrieveRequest *sr_req) @@ -643,57 +643,57 @@ bool yf::SRUtoZ3950::Impl::z3950_present_request( { send_z3950_present = false; yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.response->diagnostics), - &(sru_pdu_res->u.response->num_diagnostics), + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), YAZ_SRW_XPATH_RETRIEVAL_UNSUPP, 0); } - + // resultSetTTL unsupported. // resultSetIdleTime in response if (sr_req->resultSetTTL) { send_z3950_present = false; yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.response->diagnostics), - &(sru_pdu_res->u.response->num_diagnostics), + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), YAZ_SRW_RESULT_SETS_UNSUPP, 0); } - + // sort unsupported if (sr_req->sort_type != Z_SRW_sort_type_none) { send_z3950_present = false; yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.response->diagnostics), - &(sru_pdu_res->u.response->num_diagnostics), + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), YAZ_SRW_SORT_UNSUPP, 0); } - + // start record requested negative, or larger than number of records if (start < 0 || start > *sru_pdu_res->u.response->numberOfRecords) { send_z3950_present = false; yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.response->diagnostics), - &(sru_pdu_res->u.response->num_diagnostics), + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), YAZ_SRW_FIRST_RECORD_POSITION_OUT_OF_RANGE, 0); - } - + } + // maximumRecords requested negative if (max_recs < 0) { send_z3950_present = false; yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.response->diagnostics), - &(sru_pdu_res->u.response->num_diagnostics), + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), YAZ_SRW_UNSUPP_PARAMETER_VALUE, "maximumRecords"); - } + } // exit on all these above diagnostics if (!send_z3950_present) return false; - + if (max_recs > *sru_pdu_res->u.response->numberOfRecords - start) max_recs = *sru_pdu_res->u.response->numberOfRecords - start + 1; @@ -705,65 +705,65 @@ bool yf::SRUtoZ3950::Impl::z3950_present_request( { // now packaging the z3950 present request Package z3950_package(package.session(), package.origin()); - z3950_package.copy_filter(package); + z3950_package.copy_filter(package); Z_APDU *apdu = zget_APDU(odr_en, Z_APDU_presentRequest); - + assert(apdu->u.presentRequest); - + *apdu->u.presentRequest->resultSetStartPoint = start + num; *apdu->u.presentRequest->numberOfRecordsRequested = max_recs - num; - + // set response packing to be same as "request" packing.. int record_packing = Z_SRW_recordPacking_XML; if (sr_req->recordPacking && 's' == *(sr_req->recordPacking)) record_packing = Z_SRW_recordPacking_string; - + // RecordSyntax will always be XML apdu->u.presentRequest->preferredRecordSyntax = odr_oiddup(odr_en, yaz_oid_recsyn_xml); - + // z3950'fy record schema if (sr_req->recordSchema) { - apdu->u.presentRequest->recordComposition - = (Z_RecordComposition *) + apdu->u.presentRequest->recordComposition + = (Z_RecordComposition *) odr_malloc(odr_en, sizeof(Z_RecordComposition)); - apdu->u.presentRequest->recordComposition->which + apdu->u.presentRequest->recordComposition->which = Z_RecordComp_simple; - apdu->u.presentRequest->recordComposition->u.simple + apdu->u.presentRequest->recordComposition->u.simple = mp_util::build_esn_from_schema(odr_en, - (const char *) - sr_req->recordSchema); + (const char *) + sr_req->recordSchema); } - + // attaching Z3950 package to filter chain z3950_package.request() = apdu; - - // sending Z30.50 present request + + // sending Z30.50 present request z3950_package.move(); - + //check successful Z3950 present response Z_GDU *z3950_gdu = z3950_package.response().get(); - if (!z3950_gdu || z3950_gdu->which != Z_GDU_Z3950 + if (!z3950_gdu || z3950_gdu->which != Z_GDU_Z3950 || z3950_gdu->u.z3950->which != Z_APDU_presentResponse || !z3950_gdu->u.z3950->u.presentResponse) - + { yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.response->diagnostics), - &(sru_pdu_res->u.response->num_diagnostics), + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), YAZ_SRW_SYSTEM_TEMPORARILY_UNAVAILABLE, 0); return false; } // everything fine, continuing - + Z_PresentResponse *pr = z3950_gdu->u.z3950->u.presentResponse; - + // checking non surrogate diagnostics in Z3950 present response package - if (!z3950_to_srw_diagnostics_ok(odr_en, sru_pdu_res->u.response, + if (!z3950_to_srw_diagnostics_ok(odr_en, sru_pdu_res->u.response, pr->records)) return false; - + // if anything but database or surrogate diagnostics, stop if (!pr->records || pr->records->which != Z_Records_DBOSD) break; @@ -775,11 +775,11 @@ bool yf::SRUtoZ3950::Impl::z3950_present_request( for (int i = 0; i < returned_recs; i++) { int position = i + *apdu->u.presentRequest->resultSetStartPoint; - Z_NamePlusRecord *npr + Z_NamePlusRecord *npr = pr->records->u.databaseOrSurDiagnostics->records[i]; - + sru_res->records[i + num].recordPacking = record_packing; - + if (npr->which == Z_NamePlusRecord_surrogateDiagnostic) { Z_DiagRec *p = npr->u.surrogateDiagnostic; @@ -800,20 +800,20 @@ bool yf::SRUtoZ3950::Impl::z3950_present_request( } } else if (npr->which == Z_NamePlusRecord_databaseRecord && - npr->u.databaseRecord->direct_reference + npr->u.databaseRecord->direct_reference && !oid_oidcmp(npr->u.databaseRecord->direct_reference, yaz_oid_recsyn_xml)) { // got XML record back Z_External *r = npr->u.databaseRecord; - sru_res->records[i + num].recordPosition = + sru_res->records[i + num].recordPosition = odr_intdup(odr_en, position); sru_res->records[i + num].recordSchema = sr_req->recordSchema; sru_res->records[i + num].recordData_buf - = odr_strdupn(odr_en, - (const char *)r->u.octet_aligned->buf, + = odr_strdupn(odr_en, + (const char *)r->u.octet_aligned->buf, r->u.octet_aligned->len); - sru_res->records[i + num].recordData_len + sru_res->records[i + num].recordData_len = r->u.octet_aligned->len; } else @@ -835,21 +835,21 @@ bool yf::SRUtoZ3950::Impl::z3950_present_request( } int yf::SRUtoZ3950::Impl::z3950_build_query( - mp::odr &odr_en, Z_Query *z_query, + mp::odr &odr_en, Z_Query *z_query, const Z_SRW_searchRetrieveRequest *req ) const -{ +{ if (req->query_type == Z_SRW_query_type_cql) { - Z_External *ext = (Z_External *) + Z_External *ext = (Z_External *) odr_malloc(odr_en, sizeof(*ext)); - ext->direct_reference = + ext->direct_reference = odr_getoidbystr(odr_en, "1.2.840.10003.16.2"); ext->indirect_reference = 0; ext->descriptor = 0; ext->which = Z_External_CQL; ext->u.cql = odr_strdup(odr_en, req->query.cql); - + z_query->which = Z_Query_type_104; z_query->u.type_104 = ext; return 0; @@ -859,9 +859,9 @@ int yf::SRUtoZ3950::Impl::z3950_build_query( { Z_RPNQuery *RPNquery; YAZ_PQF_Parser pqf_parser; - + pqf_parser = yaz_pqf_create (); - + RPNquery = yaz_pqf_parse (pqf_parser, odr_en, req->query.pqf); yaz_pqf_destroy(pqf_parser); @@ -871,24 +871,24 @@ int yf::SRUtoZ3950::Impl::z3950_build_query( z_query->which = Z_Query_type_1; z_query->u.type_1 = RPNquery; - + return 0; } return YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED; } bool yf::SRUtoZ3950::Impl::z3950_to_srw_diagnostics_ok( - mp::odr &odr_en, - Z_SRW_searchRetrieveResponse + mp::odr &odr_en, + Z_SRW_searchRetrieveResponse *sru_res, Z_Records *records) const { // checking non surrogate diagnostics in Z3950 present response package - if (records + if (records && records->which == Z_Records_NSD && records->u.nonSurrogateDiagnostic) { - z3950_to_srw_diag(odr_en, sru_res, + z3950_to_srw_diag(odr_en, sru_res, records->u.nonSurrogateDiagnostic); return false; } @@ -896,7 +896,7 @@ bool yf::SRUtoZ3950::Impl::z3950_to_srw_diagnostics_ok( } int yf::SRUtoZ3950::Impl::z3950_to_srw_diag( - mp::odr &odr_en, + mp::odr &odr_en, Z_SRW_searchRetrieveResponse *sru_res, Z_DefaultDiagFormat *ddf) const { @@ -905,7 +905,7 @@ int yf::SRUtoZ3950::Impl::z3950_to_srw_diag( sru_res->diagnostics = (Z_SRW_diagnostic *) odr_malloc(odr_en, sizeof(*sru_res->diagnostics)); yaz_mk_std_diagnostic(odr_en, sru_res->diagnostics, - yaz_diag_bib1_to_srw(bib1_code), + yaz_diag_bib1_to_srw(bib1_code), ddf->u.v2Addinfo); return 0; } diff --git a/src/filter_template.cpp b/src/filter_template.cpp index c026184..3a4523d 100644 --- a/src/filter_template.cpp +++ b/src/filter_template.cpp @@ -44,7 +44,7 @@ namespace metaproxy_1 { } // define Pimpl wrapper forwarding to Impl - + yf::Template::Template() : m_p(new Impl) { } @@ -75,7 +75,7 @@ yf::Template::Impl::Impl() } yf::Template::Impl::~Impl() -{ +{ } void yf::Template::Impl::configure(const xmlNode *xmlnode, bool test_only, diff --git a/src/filter_template.hpp b/src/filter_template.hpp index 99860c4..d5457be 100644 --- a/src/filter_template.hpp +++ b/src/filter_template.hpp @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -// Filter that does nothing. Use as template for new filters +// Filter that does nothing. Use as template for new filters #ifndef FILTER_TEMPLATE_HPP #define FILTER_TEMPLATE_HPP diff --git a/src/filter_virt_db.cpp b/src/filter_virt_db.cpp index b84e087..896ae47 100644 --- a/src/filter_virt_db.cpp +++ b/src/filter_virt_db.cpp @@ -90,23 +90,23 @@ namespace metaproxy_1 { BackendPtr b); void fixup_npr_records(ODR odr, Z_Records *records, BackendPtr b); - + BackendPtr lookup_backend_from_databases( std::list databases); BackendPtr create_backend_from_databases( std::list databases, int &error_code, std::string &failing_database); - + BackendPtr init_backend(std::list database, Package &package, int &error_code, std::string &addinfo); Rep *m_p; - }; + }; class VirtualDB::Rep { friend class VirtualDB; friend struct Frontend; - + FrontendPtr get_frontend(Package &package); void release_frontend(Package &package); void refresh_torus(); @@ -228,8 +228,8 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend( ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3); init_package.request() = init_apdu; - - init_package.move(b->m_route); // sending init + + init_package.move(b->m_route); // sending init Z_GDU *gdu = init_package.response().get(); // we hope to get an init response @@ -264,7 +264,7 @@ yf::VirtualDB::BackendPtr yf::VirtualDB::Frontend::init_backend( close_package.move(b->m_route); // closing it } BackendPtr null; - return null; + return null; } void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req) @@ -283,20 +283,20 @@ void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req) Sets_it sets_it = m_sets.find(req->resultSetName); if (sets_it != m_sets.end()) { - // result set already exist + // result set already exist // if replace indicator is off: we return diagnostic if // result set already exist. if (*req->replaceIndicator == 0) { - Z_APDU *apdu = + Z_APDU *apdu = odr.create_searchResponse( apdu_req, YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF, 0); package.response() = apdu; - + return; - } + } sets_it->second.m_backend->m_number_of_sets--; } // pick up any existing database with named result sets .. @@ -323,8 +323,8 @@ void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req) if (!b) { // did not get a backend (unavailable somehow?) - - Z_APDU *apdu = + + Z_APDU *apdu = odr.create_searchResponse( apdu_req, error_code, addinfo.c_str()); package.response() = apdu; @@ -385,7 +385,7 @@ yf::VirtualDB::Frontend::Frontend(Rep *rep) void yf::VirtualDB::Frontend::close(mp::Package &package) { std::list::const_iterator b_it; - + for (b_it = m_backend_list.begin(); b_it != m_backend_list.end(); b_it++) { (*b_it)->m_backend_session.close(); @@ -405,13 +405,13 @@ yf::VirtualDB::FrontendPtr yf::VirtualDB::Rep::get_frontend(mp::Package &package boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + while(true) { it = m_clients.find(package.session()); if (it == m_clients.end()) break; - + if (!it->second->m_in_use) { it->second->m_in_use = true; @@ -429,7 +429,7 @@ void yf::VirtualDB::Rep::release_frontend(mp::Package &package) { boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + it = m_clients.find(package.session()); if (it != m_clients.end()) { @@ -462,15 +462,15 @@ yf::VirtualDB::Set::~Set() { } -yf::VirtualDB::Map::Map(std::string database, +yf::VirtualDB::Map::Map(std::string database, std::list targets, std::string route) - : m_dbpattern(database), m_targets(targets), m_route(route) + : m_dbpattern(database), m_targets(targets), m_route(route) { } -yf::VirtualDB::Map::Map(std::string database, +yf::VirtualDB::Map::Map(std::string database, std::string target, std::string route) - : m_dbpattern(database), m_route(route) + : m_dbpattern(database), m_route(route) { m_targets.push_back(target); } @@ -505,7 +505,7 @@ void yf::VirtualDB::Frontend::fixup_npr_record(ODR odr, Z_NamePlusRecord *npr, // consider each of the frontend databases.. std::list::const_iterator db_it; - for (db_it = b->m_frontend_databases.begin(); + for (db_it = b->m_frontend_databases.begin(); db_it != b->m_frontend_databases.end(); db_it++) { // see which target it corresponds to.. (if any) @@ -518,7 +518,7 @@ void yf::VirtualDB::Frontend::fixup_npr_record(ODR odr, Z_NamePlusRecord *npr, map_it++; } if (map_it != m_p->m_maps.end()) - { + { std::list::const_iterator t = map_it->m_targets.begin(); while (t != map_it->m_targets.end()) @@ -531,7 +531,7 @@ void yf::VirtualDB::Frontend::fixup_npr_record(ODR odr, Z_NamePlusRecord *npr, t++; } } - + } db_it = b->m_frontend_databases.begin(); if (db_it != b->m_frontend_databases.end()) @@ -587,7 +587,7 @@ void yf::VirtualDB::Frontend::present(mp::Package &package, Z_APDU *apdu_req) Sets_it sets_it = m_sets.find(resultSetId); if (sets_it == m_sets.end()) { - Z_APDU *apdu = + Z_APDU *apdu = odr.create_presentResponse( apdu_req, YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST, @@ -597,13 +597,13 @@ void yf::VirtualDB::Frontend::present(mp::Package &package, Z_APDU *apdu_req) } Session *id = new mp::Session(sets_it->second.m_backend->m_backend_session); - + // sending present to backend Package present_package(*id, package.origin()); present_package.copy_filter(package); req->resultSetId = odr_strdup(odr, sets_it->second.m_setname.c_str()); - + present_package.request() = ngdu; present_package.move(sets_it->second.m_backend->m_route); @@ -631,7 +631,7 @@ int yf::VirtualDB::Frontend::relay_apdu(mp::Package &package, Z_APDU *apdu_req) for (; map_it != m_backend_list.end(); map_it++) { BackendPtr b = *map_it; - + Package relay_package(b->m_backend_session, package.origin()); relay_package.copy_filter(package); @@ -666,7 +666,7 @@ void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req) if (tmp->m_frontend_databases == databases) break; } - if (map_it != m_backend_list.end()) + if (map_it != m_backend_list.end()) b = *map_it; if (!b) // no backend yet. Must create a new one { @@ -680,7 +680,7 @@ void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req) odr.create_scanResponse( apdu_req, error_code, addinfo.c_str()); package.response() = apdu; - + return; } } @@ -699,7 +699,7 @@ void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req) } scan_package.request() = ngdu; - + scan_package.move(b->m_route); if (scan_package.session().is_closed()) @@ -712,7 +712,7 @@ void yf::VirtualDB::Frontend::scan(mp::Package &package, Z_APDU *apdu_req) } -void yf::VirtualDB::add_map_db2targets(std::string db, +void yf::VirtualDB::add_map_db2targets(std::string db, std::list targets, std::string route) { @@ -721,7 +721,7 @@ void yf::VirtualDB::add_map_db2targets(std::string db, } -void yf::VirtualDB::add_map_db2target(std::string db, +void yf::VirtualDB::add_map_db2target(std::string db, std::string target, std::string route) @@ -735,12 +735,12 @@ void yf::VirtualDB::process(mp::Package &package) const FrontendPtr f = m_p->get_frontend(package); Z_GDU *gdu = package.request().get(); - + if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_initRequest && !f->m_is_virtual) { Z_InitRequest *req = gdu->u.z3950->u.initRequest; - + std::list vhosts; mp::util::get_vhost_otherinfo(req->otherInfo, vhosts); @@ -751,23 +751,23 @@ void yf::VirtualDB::process(mp::Package &package) const else { f->m_init_gdu = gdu; - + mp::odr odr; Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0); Z_InitResponse *resp = apdu->u.initResponse; - + int i; static const int masks[] = { Z_Options_search, Z_Options_present, Z_Options_namedResultSets, Z_Options_scan, - -1 + -1 }; for (i = 0; masks[i] != -1; i++) if (ODR_MASK_GET(req->options, masks[i])) ODR_MASK_SET(resp->options, masks[i]); - + static const int versions[] = { Z_ProtocolVersion_1, Z_ProtocolVersion_2, @@ -779,7 +779,7 @@ void yf::VirtualDB::process(mp::Package &package) const ODR_MASK_SET(resp->protocolVersion, versions[i]); else break; - + *resp->preferredMessageSize = *req->preferredMessageSize; *resp->maximumRecordSize = *req->maximumRecordSize; @@ -795,12 +795,12 @@ void yf::VirtualDB::process(mp::Package &package) const if (apdu->which == Z_APDU_initRequest) { mp::odr odr; - + package.response() = odr.create_close( apdu, Z_Close_protocolError, "double init"); - + package.session().close(); } else if (apdu->which == Z_APDU_searchRequest) @@ -820,21 +820,21 @@ void yf::VirtualDB::process(mp::Package &package) const if (f->relay_apdu(package, apdu) == 0) { mp::odr odr; - + package.response() = odr.create_close( apdu, Z_Close_finished, "virt_db"); - + package.session().close(); } } else { mp::odr odr; - + package.response() = odr.create_close( apdu, Z_Close_protocolError, "unsupported APDU in filter_virt_db"); - + package.session().close(); } } @@ -861,14 +861,14 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only, { if (v_node->type != XML_ELEMENT_NODE) continue; - + if (mp::xml::is_element_mp(v_node, "database")) database = mp::xml::get_text(v_node); else if (mp::xml::is_element_mp(v_node, "target")) targets.push_back(mp::xml::get_text(v_node)); else throw mp::filter::FilterException - ("Bad element " + ("Bad element " + std::string((const char *) v_node->name) + " in virtual section" ); @@ -882,7 +882,7 @@ void mp::filter::VirtualDB::configure(const xmlNode * ptr, bool test_only, else { throw mp::filter::FilterException - ("Bad element " + ("Bad element " + std::string((const char *) ptr->name) + " in virt_db filter"); } diff --git a/src/filter_z3950_client.cpp b/src/filter_z3950_client.cpp index b988728..2241503 100644 --- a/src/filter_z3950_client.cpp +++ b/src/filter_z3950_client.cpp @@ -102,7 +102,7 @@ yf::Z3950Client::Assoc::Assoc(yazpp_1::SocketManager *socket_manager, std::string host, int timeout_sec) : Z_Assoc(PDU_Observable), m_socket_manager(socket_manager), m_PDU_Observable(PDU_Observable), - m_package(0), m_in_use(true), m_waiting(false), + m_package(0), m_in_use(true), m_waiting(false), m_destroyed(false), m_connected(false), m_has_closed(false), m_queue_len(1), m_time_elapsed(0), m_time_max(timeout_sec), m_time_connect_max(10), @@ -135,7 +135,7 @@ void yf::Z3950Client::Assoc::failNotify() Z_APDU *apdu = 0; if (gdu && gdu->which == Z_GDU_Z3950) apdu = gdu->u.z3950; - + m_package->response() = odr.create_close(apdu, Z_Close_peerAbort, 0); m_package->session().close(); } @@ -150,21 +150,21 @@ void yf::Z3950Client::Assoc::timeoutNotify() m_waiting = false; mp::odr odr; - + if (m_package) { Z_GDU *gdu = m_package->request().get(); Z_APDU *apdu = 0; if (gdu && gdu->which == Z_GDU_Z3950) apdu = gdu->u.z3950; - + if (m_connected) m_package->response() = odr.create_close(apdu, Z_Close_lackOfActivity, 0); else - m_package->response() = + m_package->response() = odr.create_close(apdu, Z_Close_peerAbort, 0); - + m_package->session().close(); } } @@ -176,7 +176,7 @@ void yf::Z3950Client::Assoc::fixup_nsd(ODR odr, Z_Records *records) { Z_DefaultDiagFormat *nsd = records->u.nonSurrogateDiagnostic; std::string addinfo; - + // should really check for nsd->which.. But union has two members // containing almost same data const char *v2Addinfo = nsd->u.v2Addinfo; @@ -206,7 +206,7 @@ void yf::Z3950Client::Assoc::fixup_init(ODR odr, Z_InitResponse *initrs) if (unit->which == Z_OtherInfo_externallyDefinedInfo && unit->information.externallyDefinedInfo && unit->information.externallyDefinedInfo->which == - Z_External_diag1) + Z_External_diag1) { Z_DiagnosticFormat *diag = unit->information.externallyDefinedInfo->u.diag1; @@ -234,7 +234,7 @@ void yf::Z3950Client::Assoc::fixup_init(ODR odr, Z_InitResponse *initrs) r->u.v2Addinfo = naddinfo; } } - } + } } } } @@ -244,7 +244,7 @@ void yf::Z3950Client::Assoc::recv_GDU(Z_GDU *gdu, int len) m_waiting = false; if (m_package) - { + { mp::odr odr; // must be in scope for response() = assignment if (gdu && gdu->which == Z_GDU_Z3950) { @@ -284,19 +284,19 @@ yf::Z3950Client::Z3950Client() : m_p(new yf::Z3950Client::Rep) yf::Z3950Client::~Z3950Client() { } -yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) +yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) { // only one thread messes with the clients list at a time boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + Z_GDU *gdu = package.request().get(); - + int max_sockets = package.origin().get_max_sockets(); if (max_sockets == 0) max_sockets = m_max_sockets; - + it = m_clients.find(package.session()); if (it != m_clients.end()) { @@ -334,7 +334,7 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) if (apdu->which != Z_APDU_initRequest) { mp::odr odr; - + package.response() = odr.create_close(apdu, Z_Close_protocolError, "First PDU was not an " @@ -365,7 +365,7 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) apdu, YAZ_BIB1_INIT_NEGOTIATION_OPTION_REQUIRED, "z3950_client: No vhost given"); - + package.session().close(); return 0; } @@ -381,7 +381,7 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) return 0; } } - + // see if we have reached max number of clients (max-sockets) while (max_sockets) @@ -406,7 +406,7 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) if (no_not_in_use == 0) // all in use.. { mp::odr odr; - + package.response() = odr.create_initResponse( apdu, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, "max sessions"); package.session().close(); @@ -414,12 +414,12 @@ yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package) } boost::xtime xt; xtime_get(&xt, boost::TIME_UTC); - + xt.sec += 15; if (!m_cond_session_ready.timed_wait(lock, xt)) { mp::odr odr; - + package.response() = odr.create_initResponse( apdu, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, "max sessions"); package.session().close(); @@ -448,7 +448,7 @@ void yf::Z3950Client::Rep::send_and_receive(Package &package, && m_force_close) { mp::odr odr; - + package.request() = odr.create_close( 0, Z_Close_finished, "z3950_client"); c->m_package = 0; // don't inspect response @@ -475,9 +475,9 @@ void yf::Z3950Client::Rep::send_and_receive(Package &package, return; } c->timeout(1); // so timeoutNotify gets called once per second - - while (!c->m_destroyed && c->m_waiting + + while (!c->m_destroyed && c->m_waiting && c->m_socket_manager->processEvent() > 0) ; } @@ -489,7 +489,7 @@ void yf::Z3950Client::Rep::send_and_receive(Package &package, // prepare response c->m_time_elapsed = 0; c->m_waiting = true; - + // relay the package .. int len; c->send_GDU(gdu, &len); @@ -512,7 +512,7 @@ void yf::Z3950Client::Rep::release_assoc(Package &package) { boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + it = m_clients.find(package.session()); if (it != m_clients.end()) { @@ -574,7 +574,7 @@ void yf::Z3950Client::configure(const xmlNode *ptr, bool test_only, } else { - throw mp::filter::FilterException("Bad element " + throw mp::filter::FilterException("Bad element " + std::string((const char *) ptr->name)); } diff --git a/src/filter_zeerex_explain.cpp b/src/filter_zeerex_explain.cpp index e98d65a..0ff7864 100644 --- a/src/filter_zeerex_explain.cpp +++ b/src/filter_zeerex_explain.cpp @@ -75,31 +75,31 @@ void yf::ZeeRexExplain::process(mp::Package &package) const void yf::ZeeRexExplain::Impl::configure(const xmlNode *confignode) { const xmlNode * dbnode; - + for (dbnode = confignode->children; dbnode; dbnode = dbnode->next){ if (dbnode->type != XML_ELEMENT_NODE) continue; - + std::string database; mp::xml::check_element_mp(dbnode, "database"); - for (struct _xmlAttr *attr = dbnode->properties; + for (struct _xmlAttr *attr = dbnode->properties; attr; attr = attr->next){ - + mp::xml::check_attribute(attr, "", "name"); database = mp::xml::get_text(attr); - + std::cout << database << "\n"; - + const xmlNode *explainnode; - for (explainnode = dbnode->children; + for (explainnode = dbnode->children; explainnode; explainnode = explainnode->next){ if (explainnode->type != XML_ELEMENT_NODE) continue; if (explainnode) break; } - // assigning explain node to database name - no check yet + // assigning explain node to database name - no check yet m_database_explain.insert(std::make_pair(database, explainnode)); } } @@ -115,7 +115,7 @@ void yf::ZeeRexExplain::Impl::process(mp::Package &package) package.move(); return; } - + // only working on HTTP_Request packages now mp::odr odr_de(ODR_DECODE); @@ -143,7 +143,7 @@ void yf::ZeeRexExplain::Impl::process(mp::Package &package) package.move(); return; } - + // if SRU package could not be decoded, send minimal explain and // close connection @@ -151,18 +151,18 @@ void yf::ZeeRexExplain::Impl::process(mp::Package &package) Z_SOAP *soap = 0; char *charset = 0; char *stylesheet = 0; - if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en, + if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en, sru_pdu_res, &soap, charset, stylesheet))) { - mp_util::build_sru_explain(package, odr_en, sru_pdu_res, + mp_util::build_sru_explain(package, odr_en, sru_pdu_res, sruinfo, explainnode); - mp_util::build_sru_response(package, odr_en, soap, + mp_util::build_sru_response(package, odr_en, soap, sru_pdu_res, charset, stylesheet); package.session().close(); return; } - + if (sru_pdu_req->which != Z_SRW_explain_request) { @@ -171,21 +171,21 @@ void yf::ZeeRexExplain::Impl::process(mp::Package &package) return; } // except valid SRU explain request, construct ZeeRex Explain response - else + else { Z_SRW_explainRequest *er_req = sru_pdu_req->u.explain_request; - //mp_util::build_simple_explain(package, odr_en, sru_pdu_res, + //mp_util::build_simple_explain(package, odr_en, sru_pdu_res, // sruinfo, er_req); - mp_util::build_sru_explain(package, odr_en, sru_pdu_res, + mp_util::build_sru_explain(package, odr_en, sru_pdu_res, sruinfo, explainnode, er_req); - mp_util::build_sru_response(package, odr_en, soap, + mp_util::build_sru_response(package, odr_en, soap, sru_pdu_res, charset, stylesheet); return; } // should never arrive here package.session().close(); - return; + return; } diff --git a/src/filter_zeerex_explain.hpp b/src/filter_zeerex_explain.hpp index 1f46b74..10e5e89 100644 --- a/src/filter_zeerex_explain.hpp +++ b/src/filter_zeerex_explain.hpp @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -// Filter that constructs valid ZeeRex Explain SRU responses +// Filter that constructs valid ZeeRex Explain SRU responses #ifndef FILTER_ZEEREX_EXPLAIN_HPP #define FILTER_ZEEREX_EXPLAIN_HPP diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index 9de8e6b..95a444b 100644 --- a/src/filter_zoom.cpp +++ b/src/filter_zoom.cpp @@ -153,7 +153,7 @@ namespace metaproxy_1 { std::string authentication, std::string proxy, std::string realm); - + void prepare_elements(BackendPtr b, Odr_oid *preferredRecordSyntax, const char *element_set_name, @@ -182,7 +182,7 @@ namespace metaproxy_1 { const char *element_set_name); bool retry(mp::Package &package, mp::odr &odr, - BackendPtr b, + BackendPtr b, int &error, char **addinfo, int &proxy_step, int &same_retries, int &proxy_retries); @@ -210,7 +210,7 @@ namespace metaproxy_1 { void release_frontend(mp::Package &package); SearchablePtr parse_torus_record(const xmlNode *ptr); struct cql_node *convert_cql_fields(struct cql_node *cn, ODR odr); - std::map m_clients; + std::map m_clients; boost::mutex m_mutex; boost::condition m_cond_session_ready; std::string torus_searchable_url; @@ -250,7 +250,7 @@ static xmlNode *xml_node_search(xmlNode *ptr, int *num, int m) return ptr; } else // else: we don't want to find nested nodes - { + { xmlNode *ret_node = xml_node_search(ptr->children, num, m); if (ret_node) return ret_node; @@ -261,7 +261,7 @@ static xmlNode *xml_node_search(xmlNode *ptr, int *num, int m) } // define Pimpl wrapper forwarding to Impl - + yf::Zoom::Zoom() : m_p(new Impl) { } @@ -320,14 +320,14 @@ void yf::Zoom::Backend::get_zoom_error(int *error, char **addinfo, { if (!dset) dset = "Unknown"; - + if (!strcmp(dset, "info:srw/diagnostic/1")) *error = yaz_diag_srw_to_bib1(error0); else if (!strcmp(dset, "Bib-1")) *error = error0; else if (!strcmp(dset, "ZOOM")) { - *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR; + *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR; if (error0 == ZOOM_ERROR_INIT) *error = YAZ_BIB1_INIT_AC_AUTHENTICATION_SYSTEM_ERROR; else if (error0 == ZOOM_ERROR_DECODE) @@ -342,7 +342,7 @@ void yf::Zoom::Backend::get_zoom_error(int *error, char **addinfo, } else *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR; - + *addinfo = (char *) odr_malloc( odr, 30 + strlen(dset) + strlen(msg) + (zoom_addinfo ? strlen(zoom_addinfo) : 0)); @@ -365,7 +365,7 @@ void yf::Zoom::Backend::connect(std::string zurl, zurl.erase(h); ZOOM_connection_connect(m_connection, zurl.length() ? zurl.c_str() : 0, 0); get_zoom_error(error, addinfo, odr); - + } void yf::Zoom::Backend::search(ZOOM_query q, Odr_int *hits, @@ -418,7 +418,7 @@ yf::Zoom::Searchable::~Searchable() ccl_qual_rm(&ccl_bibset); } -yf::Zoom::Frontend::Frontend(Impl *impl) : +yf::Zoom::Frontend::Frontend(Impl *impl) : m_p(impl), m_is_virtual(false), m_in_use(true) { } @@ -432,13 +432,13 @@ yf::Zoom::FrontendPtr yf::Zoom::Impl::get_frontend(mp::Package &package) boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + while(true) { it = m_clients.find(package.session()); if (it == m_clients.end()) break; - + if (!it->second->m_in_use) { it->second->m_in_use = true; @@ -456,7 +456,7 @@ void yf::Zoom::Impl::release_frontend(mp::Package &package) { boost::mutex::scoped_lock lock(m_mutex); std::map::iterator it; - + it = m_clients.find(package.session()); if (it != m_clients.end()) { @@ -493,7 +493,7 @@ yf::Zoom::Impl::~Impl() yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr) { Zoom::SearchablePtr s(new Searchable(bibset)); - + for (ptr = ptr->children; ptr; ptr = ptr->next) { if (ptr->type != XML_ELEMENT_NODE) @@ -509,22 +509,22 @@ yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr) "cfAuth")) { s->cfAuth = mp::xml::get_text(ptr); - } + } else if (!strcmp((const char *) ptr->name, "cfProxy")) { s->cfProxy = mp::xml::get_text(ptr); - } + } else if (!strcmp((const char *) ptr->name, "cfSubDB")) { s->cfSubDB = mp::xml::get_text(ptr); - } + } else if (!strcmp((const char *) ptr->name, "contentConnector")) { s->contentConnector = mp::xml::get_text(ptr); - } + } else if (!strcmp((const char *) ptr->name, "udb")) { s->udb = mp::xml::get_text(ptr); @@ -623,7 +623,7 @@ void yf::Zoom::Impl::configure_local_records(const xmlNode *ptr, bool test_only) { while (ptr && ptr->type != XML_ELEMENT_NODE) ptr = ptr->next; - + if (ptr) { if (!strcmp((const char *) ptr->name, "records")) @@ -650,7 +650,7 @@ void yf::Zoom::Impl::configure_local_records(const xmlNode *ptr, bool test_only) else { throw mp::filter::FilterException - ("Bad element " + ("Bad element " + std::string((const char *) ptr->name) + " in zoom filter inside element " ""); @@ -660,7 +660,7 @@ void yf::Zoom::Impl::configure_local_records(const xmlNode *ptr, bool test_only) else { throw mp::filter::FilterException - ("Bad element " + ("Bad element " + std::string((const char *) ptr->name) + " in zoom filter inside element "); } @@ -750,9 +750,9 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only, { yaz_log(YLOG_WARN, "contentProxy's server attribute is deprecated"); - yaz_log(YLOG_LOG, + yaz_log(YLOG_LOG, "Specify config_file instead. For example:"); - yaz_log(YLOG_LOG, + yaz_log(YLOG_LOG, " content_file=\"/etc/cf-proxy/cproxy.cfg\""); content_proxy_server = mp::xml::get_text(attr->children); } @@ -767,7 +767,7 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only, } } else if (!strcmp((const char *) ptr->name, "log")) - { + { const struct _xmlAttr *attr; for (attr = ptr->properties; attr; attr = attr->next) { @@ -797,7 +797,7 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only, else { throw mp::filter::FilterException - ("Bad element " + ("Bad element " + std::string((const char *) ptr->name) + " in zoom filter"); } @@ -806,12 +806,12 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only, if (explain_xslt_fname.length()) { const char *path = 0; - + if (xsldir.length()) path = xsldir.c_str(); else path = file_path.c_str(); - + char fullpath[1024]; char *cp = yaz_filepath_resolve(explain_xslt_fname.c_str(), path, 0, fullpath); @@ -834,19 +834,19 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only, xmlFreeDoc(xsp_doc); throw mp::filter::FilterException ("Cannot parse XSLT " + explain_xslt_fname); - + } } if (record_xslt_fname.length()) { const char *path = 0; - + if (xsldir.length()) path = xsldir.c_str(); else path = file_path.c_str(); - + char fullpath[1024]; char *cp = yaz_filepath_resolve(record_xslt_fname.c_str(), path, 0, fullpath); @@ -869,7 +869,7 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only, xmlFreeDoc(xsp_doc); throw mp::filter::FilterException ("Cannot parse XSLT " + record_xslt_fname); - + } } } @@ -893,7 +893,7 @@ bool yf::Zoom::Frontend::create_content_session(mp::Package &package, proxyhostname = m_p->content_proxy_server; legacy_format = true; } - + if (m_p->content_tmp_file.length()) tmp_file = m_p->content_tmp_file; @@ -923,7 +923,7 @@ bool yf::Zoom::Frontend::create_content_session(mp::Package &package, while (*cp == ' ') cp++; if (!strcmp(buf, "proxyhostname")) - proxyhostname = cp; + proxyhostname = cp; if (!strcmp(buf, "sessiondir") && *cp) { if (cp[strlen(cp)-1] == '/') @@ -1015,7 +1015,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( std::string proxy; std::list::const_iterator map_it; - if (m_backend && !m_backend->enable_explain && + if (m_backend && !m_backend->enable_explain && m_backend->m_frontend_database == database) { connection_reuse = true; @@ -1058,7 +1058,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( odr_malloc(odr, (10 + no_parms) * sizeof(*out_names)); const char **out_values = (const char **) odr_malloc(odr, (10 + no_parms) * sizeof(*out_values)); - + // may be changed if it's a content connection std::string torus_url = m_p->torus_searchable_url; int i; @@ -1105,7 +1105,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( else { proxy = dstr[*proxy_step]; - + (*proxy_step)++; if (*proxy_step == dnum) *proxy_step = 0; @@ -1136,7 +1136,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( *addinfo = msg; return notfound; } - } + } if (proxy.length()) package.log("zoom", YLOG_LOG, "proxy: %s", proxy.c_str()); @@ -1162,7 +1162,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( if (torus_db.compare("IR-Explain---1") == 0) return explain_search(package, database, error, addinfo, odr, torus_url, torus_db, realm); - + SearchablePtr sptr; std::map::iterator it; @@ -1233,7 +1233,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( BackendPtr b; return b; } - + xsltStylesheetPtr xsp = 0; if (sptr->transform_xsl_content.length()) { @@ -1277,7 +1277,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR; *addinfo = (char *) odr_malloc(odr, 40 + sptr->transform_xsl_fname.length()); - sprintf(*addinfo, "File could not be read: %s", + sprintf(*addinfo, "File could not be read: %s", sptr->transform_xsl_fname.c_str()); BackendPtr b; return b; @@ -1340,8 +1340,8 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( b->set_option("extraArgs", sptr->extraArgs); b->set_option("timeout", m_p->zoom_timeout.c_str()); - - if (m_p->apdu_log) + + if (m_p->apdu_log) b->set_option("apdulog", "1"); if (sptr->piggyback && sptr->sru.length()) @@ -1355,7 +1355,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( if (proxy.length() == 0) proxy = sptr->cfProxy; b->m_proxy = proxy; - + if (sptr->cfAuth.length()) { // A CF target @@ -1378,7 +1378,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( out_names[no_out_args] = "user"; out_values[no_out_args++] = odr_strdup(odr, authentication.c_str()); - } + } } if (proxy.length()) { @@ -1399,7 +1399,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( else { size_t found = authentication.find('/'); - + if (sptr->sru.length() && found != std::string::npos) { b->set_option("user", authentication.substr(0, found)); @@ -1428,7 +1428,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( { char *x_args = 0; out_names[no_out_args] = 0; // terminate list - + yaz_array_to_uri(&x_args, odr, (char **) out_names, (char **) out_values); url += "," + std::string(x_args); @@ -1456,7 +1456,7 @@ void yf::Zoom::Frontend::prepare_elements(BackendPtr b, { char oid_name_str[OID_STR_MAX]; const char *syntax_name = 0; - + if (preferredRecordSyntax && !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml)) { @@ -1466,7 +1466,7 @@ void yf::Zoom::Frontend::prepare_elements(BackendPtr b, enable_pz2_retrieval = true; enable_pz2_transform = true; } - else if (element_set_name && + else if (element_set_name && !strcmp(element_set_name, m_p->element_raw.c_str())) { enable_pz2_retrieval = true; @@ -1478,14 +1478,14 @@ void yf::Zoom::Frontend::prepare_elements(BackendPtr b, enable_record_transform = true; } } - + if (enable_pz2_retrieval) { std::string configured_request_syntax = b->sptr->request_syntax; if (configured_request_syntax.length()) { syntax_name = configured_request_syntax.c_str(); - const Odr_oid *syntax_oid = + const Odr_oid *syntax_oid = yaz_string_to_oid(yaz_oid_std(), CLASS_RECSYN, syntax_name); if (!oid_oidcmp(syntax_oid, yaz_oid_recsyn_usmarc) || !oid_oidcmp(syntax_oid, yaz_oid_recsyn_opac)) @@ -1536,12 +1536,12 @@ Z_Records *yf::Zoom::Frontend::get_explain_records( number_to_present = 10000; xmlNode *ptr = xmlDocGetRootElement(b->explain_doc); - + Z_NamePlusRecordList *npl = (Z_NamePlusRecordList *) odr_malloc(odr, sizeof(*npl)); npl->records = (Z_NamePlusRecord **) odr_malloc(odr, number_to_present * sizeof(*npl->records)); - + for (i = 0; i < number_to_present; i++) { int num = 0; @@ -1604,7 +1604,7 @@ Z_Records *yf::Zoom::Frontend::get_records(mp::Package &package, if (start < 0 || number_to_present <=0) return records; - + if (number_to_present > 10000) number_to_present = 10000; @@ -1625,7 +1625,7 @@ Z_Records *yf::Zoom::Frontend::get_records(mp::Package &package, const char *xsl_parms[3]; mp::wrbuf cproxy_host; - + if (b->enable_cproxy && b->cproxy_host.length()) { wrbuf_puts(cproxy_host, "\""); @@ -1656,7 +1656,7 @@ Z_Records *yf::Zoom::Frontend::get_records(mp::Package &package, int sur_error = ZOOM_record_error(recs[i], 0 /* msg */, &addinfo, 0 /* diagset */); - + if (sur_error) { log_diagnostic(package, sur_error, addinfo); @@ -1714,7 +1714,7 @@ Z_Records *yf::Zoom::Frontend::get_records(mp::Package &package, odr, odr_database, error, addinfo); } else - { + { // first stage XSLT - per target xsltStylesheetPtr xsp = b->xsp; xmlDoc *rec_res = xsltApplyStylesheet(xsp, rec_doc, @@ -1722,7 +1722,7 @@ Z_Records *yf::Zoom::Frontend::get_records(mp::Package &package, // insert generated-url if (rec_res) { - std::string res = + std::string res = mp::xml::url_recipe_handle(rec_res, b->sptr->urlRecipe); if (res.length()) @@ -1730,7 +1730,7 @@ Z_Records *yf::Zoom::Frontend::get_records(mp::Package &package, xmlNode *ptr = xmlDocGetRootElement(rec_res); while (ptr && ptr->type != XML_ELEMENT_NODE) ptr = ptr->next; - xmlNode *c = + xmlNode *c = xmlNewChild(ptr, 0, BAD_CAST "metadata", 0); xmlNewProp(c, BAD_CAST "type", BAD_CAST "generated-url"); @@ -1779,7 +1779,7 @@ Z_Records *yf::Zoom::Frontend::get_records(mp::Package &package, { if (!rec_buf) npr = zget_surrogateDiagRec( - odr, odr_database, + odr, odr_database, YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS, rec_type_str); else @@ -1809,7 +1809,7 @@ Z_Records *yf::Zoom::Frontend::get_records(mp::Package &package, else { npr = zget_surrogateDiagRec( - odr, odr_database, + odr, odr_database, YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS, "ZOOM_record, type ext"); } @@ -1883,7 +1883,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::explain_search(mp::Package &package, b->m_frontend_database = database; b->enable_explain = true; - + Z_GDU *gdu = package.request().get(); Z_APDU *apdu_req = gdu->u.z3950; Z_SearchRequest *sr = apdu_req->u.searchRequest; @@ -1921,7 +1921,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::explain_search(mp::Package &package, { xmlNode *ptr = xmlDocGetRootElement(doc); int hits = 0; - + xml_node_search(ptr, &hits, 0); Z_APDU *apdu_res = odr.create_searchResponse(apdu_req, 0, 0); @@ -1954,7 +1954,7 @@ static bool wait_conn(COMSTACK cs, int secs) pfd.fd = cs_fileno(cs); pfd.client_data = 0; - + int ret = yaz_poll(&pfd, 1, secs, 0); return ret > 0; } @@ -1973,12 +1973,12 @@ bool yf::Zoom::Impl::check_proxy(const char *proxy) Z_GDU *gdu = z_get_HTTP_Request_uri(odr, uri, 0, 1); gdu->u.HTTP_Request->method = odr_strdup(odr, "GET"); - + if (z_GDU(odr, &gdu, 0, 0)) { int len; char *buf = odr_getbuf(odr, &len, 0); - + int ret = cs_connect(conn, add); if (ret > 0 || (ret == 0 && wait_conn(conn, 1))) { @@ -2000,7 +2000,7 @@ bool yf::Zoom::Impl::check_proxy(const char *proxy) bool yf::Zoom::Frontend::retry(mp::Package &package, mp::odr &odr, - BackendPtr b, + BackendPtr b, int &error, char **addinfo, int &proxy_step, int &same_retries, int &proxy_retries) @@ -2117,7 +2117,7 @@ next_proxy: error = YAZ_BIB1_MALFORMED_QUERY; const char *addinfo = "CQL syntax error"; log_diagnostic(package, error, addinfo); - apdu_res = + apdu_res = odr.create_searchResponse(apdu_req, error, addinfo); package.response() = apdu_res; return; @@ -2131,7 +2131,7 @@ next_proxy: addinfo = 0; if (cn_error->which == CQL_NODE_ST) addinfo = cn_error->u.st.index; - + log_diagnostic(package, error, addinfo); apdu_res = odr.create_searchResponse(apdu_req, error, addinfo); package.response() = apdu_res; @@ -2170,7 +2170,7 @@ next_proxy: yaz_tok_parse_t tp = yaz_tok_parse_buf(tc, wrbuf_cstr(sort_spec_wrbuf)); yaz_tok_cfg_destroy(tc); - + /* go through sortspec and map fields */ int token = yaz_tok_move(tp); while (token != YAZ_TOK_EOF) @@ -2227,7 +2227,7 @@ next_proxy: switch (cerror) { case CCL_ERR_UNKNOWN_QUAL: - case CCL_ERR_TRUNC_NOT_LEFT: + case CCL_ERR_TRUNC_NOT_LEFT: case CCL_ERR_TRUNC_NOT_RIGHT: case CCL_ERR_TRUNC_NOT_BOTH: #ifdef CCL_ERR_TRUNC_NOT_EMBED @@ -2248,7 +2248,7 @@ next_proxy: package.log("zoom", YLOG_LOG, "RPN: %s", wrbuf_cstr(pqf_wrbuf)); ccl_rpn_delete(cn); } - + assert(pqf_wrbuf.len()); ZOOM_query q = ZOOM_query_create(); @@ -2260,13 +2260,13 @@ next_proxy: Z_RPNQuery *zquery; zquery = p_query_rpn(odr, wrbuf_cstr(pqf_wrbuf)); mp::wrbuf wrb; - + if (!strcmp(b->get_option("sru"), "solr")) { solr_transform_t cqlt = solr_transform_create(); - + status = solr_transform_rpn2solr_wrbuf(cqlt, wrb, zquery); - + solr_transform_close(cqlt); } else @@ -2280,7 +2280,7 @@ next_proxy: b->search(q, &hits, &error, &addinfo, odr); } ZOOM_query_destroy(q); - + if (status) { error = YAZ_BIB1_MALFORMED_QUERY; @@ -2310,7 +2310,7 @@ next_proxy: Odr_int number_to_present = 0; if (!error) mp::util::piggyback_sr(sr, hits, number_to_present, &element_set_name); - + Odr_int number_of_records_returned = 0; Z_Records *records = get_records( package, @@ -2349,7 +2349,7 @@ void yf::Zoom::Frontend::handle_present(mp::Package &package) if (comp && comp->which != Z_RecordComp_simple) { package.response() = odr.create_presentResponse( - apdu_req, + apdu_req, YAZ_BIB1_PRESENT_COMP_SPEC_PARAMETER_UNSUPP, 0); return; } @@ -2367,7 +2367,7 @@ void yf::Zoom::Frontend::handle_present(mp::Package &package) *pr->resultSetStartPoint - 1, *pr->numberOfRecordsRequested, &error, &addinfo, &number_of_records_returned, odr, m_backend, pr->preferredRecordSyntax, element_set_name); - + apdu_res = odr.create_presentResponse(apdu_req, error, addinfo); if (records) { @@ -2384,7 +2384,7 @@ void yf::Zoom::Frontend::handle_present(mp::Package &package) *pr->resultSetStartPoint - 1, *pr->numberOfRecordsRequested, &error, &addinfo, &number_of_records_returned, odr, m_backend, pr->preferredRecordSyntax, element_set_name); - + apdu_res = odr.create_presentResponse(apdu_req, error, addinfo); if (records) { @@ -2504,7 +2504,7 @@ void yf::Zoom::Frontend::auth(mp::Package &package, Z_InitRequest *req, failure_code = YAZ_BIB1_INIT_AC_BAD_USERID_AND_OR_PASSWORD; } else - { + { const char *ip_cstr = ip.c_str(); const char *cp = strchr(ip_cstr, ':'); if (cp) @@ -2555,7 +2555,7 @@ void yf::Zoom::Frontend::auth(mp::Package &package, Z_InitRequest *req, !strcmp((const char *) ptr->name, "identityId")) break; ptr = ptr->next; - } + } } if (!ptr) { @@ -2579,21 +2579,21 @@ void yf::Zoom::Impl::process(mp::Package &package) { Z_InitRequest *req = gdu->u.z3950->u.initRequest; f->m_init_gdu = gdu; - + mp::odr odr; Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0); Z_InitResponse *resp = apdu->u.initResponse; - + int i; static const int masks[] = { Z_Options_search, Z_Options_present, - -1 + -1 }; for (i = 0; masks[i] != -1; i++) if (ODR_MASK_GET(req->options, masks[i])) ODR_MASK_SET(resp->options, masks[i]); - + static const int versions[] = { Z_ProtocolVersion_1, Z_ProtocolVersion_2, @@ -2605,7 +2605,7 @@ void yf::Zoom::Impl::process(mp::Package &package) ODR_MASK_SET(resp->protocolVersion, versions[i]); else break; - + *resp->preferredMessageSize = *req->preferredMessageSize; *resp->maximumRecordSize = *req->maximumRecordSize; diff --git a/src/gduutil.cpp b/src/gduutil.cpp index c2ebef7..8fe1ac4 100644 --- a/src/gduutil.cpp +++ b/src/gduutil.cpp @@ -58,14 +58,14 @@ std::ostream& std::operator<<(std::ostream& os, Z_GDU& zgdu) std::ostream& std::operator<<(std::ostream& os, Z_HTTP_Request& httpreq) { os << httpreq.method << " "; - os << httpreq.path; + os << httpreq.path; return os; } std::ostream& std::operator<<(std::ostream& os, Z_HTTP_Response& httpres) { os << httpres.code << " "; - os << httpres.content_len; + os << httpres.content_len; return os; } @@ -86,7 +86,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_Records & rs) default: os << "Z_Records" ; } - + return os; } @@ -104,7 +104,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_DiagRec& dr) default: os << "Z_DiagRec" ; } - + return os; } @@ -128,7 +128,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_DefaultDiagFormat& ddf) default: os << "-"; } - + return os; } @@ -161,9 +161,9 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) case Z_APDU_initRequest: os << " " << "initRequest"; - + { - Z_InitRequest *ir + Z_InitRequest *ir = zapdu.u.initRequest; Z_IdAuthentication *a = ir->idAuthentication; @@ -173,17 +173,17 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) dump_opt_string(os, a->u.open); else dump_opt_string(os, 0); - + os << " "; std::list vhosts; mp::util::get_vhost_otherinfo(ir->otherInfo, vhosts); if (vhosts.size()){ - copy(vhosts.begin(), vhosts.end(), + copy(vhosts.begin(), vhosts.end(), ostream_iterator(os, " ")); } else os << "-" ; - + dump_opt_string(os, ir->implementationId); dump_opt_string(os, ir->implementationName); dump_opt_string(os, ir->implementationVersion); @@ -192,7 +192,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) case Z_APDU_initResponse: os << " " << "initResponse "; { - Z_InitResponse *ir + Z_InitResponse *ir = zapdu.u.initResponse; if (ir->result && *(ir->result)) { @@ -209,10 +209,10 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) break; case Z_APDU_searchRequest: os << " " << "searchRequest" << " "; - { - Z_SearchRequest *sr + { + Z_SearchRequest *sr = zapdu.u.searchRequest; - + for (int i = 0; i < sr->num_databaseNames; i++) { os << sr->databaseNames[i]; @@ -272,7 +272,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) char oid_name_str[OID_STR_MAX]; const char *oid_name = yaz_oid_to_string_buf( pr->preferredRecordSyntax, 0, oid_name_str); - + os << " " << oid_name; } else @@ -286,7 +286,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) case Z_APDU_presentResponse: os << " " << "presentResponse" << " "; { - Z_PresentResponse *pr + Z_PresentResponse *pr = zapdu.u.presentResponse; if (!pr->presentStatus) os << "Unknown"; @@ -348,9 +348,9 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) break; case Z_APDU_scanRequest: os << " " << "scanRequest" << " "; - { + { Z_ScanRequest *sr = zapdu.u.scanRequest; - + if (sr) { for (int i = 0; i < sr->num_databaseNames; i++) @@ -367,7 +367,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) if (sr->termListAndStartPoint) { mp::wrbuf wr; - yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint, + yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint, sr->attributeSet); os << wrbuf_cstr(wr); } @@ -430,8 +430,8 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) break; case Z_APDU_extendedServicesRequest: os << " " << "extendedServicesRequest"; - { - Z_ExtendedServicesRequest *er + { + Z_ExtendedServicesRequest *er = zapdu.u.extendedServicesRequest; if (er) { @@ -455,18 +455,18 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) } else os << " -"; - - + + if (er->userId) os << " " << er->userId ; else os << " -"; - + if (er->packageName) os << " " << er->packageName; else os << " -"; - + if (er->description) os << " " << er->description; else @@ -476,8 +476,8 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) break; case Z_APDU_extendedServicesResponse: os << " " << "extendedServicesResponse"; - { - Z_ExtendedServicesResponse *er + { + Z_ExtendedServicesResponse *er = zapdu.u.extendedServicesResponse; if (er) { @@ -509,7 +509,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) break; case Z_APDU_close: os << " " << "close" << " "; - { + { Z_Close *c = zapdu.u.close; if (c) { @@ -553,7 +553,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) os << "unknown"; } } - + if (c->diagnosticInformation) os << " " << c->diagnosticInformation; } @@ -565,7 +565,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) case Z_APDU_duplicateDetectionResponse: os << " " << "duplicateDetectionResponse"; break; - default: + default: os << " " << "Z_APDU " << "UNKNOWN"; } diff --git a/src/gduutil.hpp b/src/gduutil.hpp index 1902a1c..89a4503 100644 --- a/src/gduutil.hpp +++ b/src/gduutil.hpp @@ -25,10 +25,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include -namespace std +namespace std { std::ostream& operator<<(std::ostream& os, Z_GDU& zgdu); - std::ostream& operator<<(std::ostream& os, Z_APDU& zapdu); + std::ostream& operator<<(std::ostream& os, Z_APDU& zapdu); std::ostream& operator<<(std::ostream& os, Z_HTTP_Request& httpreq); std::ostream& operator<<(std::ostream& os, Z_HTTP_Response& httpres); std::ostream& operator<<(std::ostream& os, Z_Records & rs); @@ -41,7 +41,7 @@ namespace metaproxy_1 { namespace gdu { - } + } } #endif diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index d082124..5a50f44 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -87,7 +87,7 @@ static void work_debug(void *data) { work_common(data); } - + static void work_normal(void *data) { #if HAVE_UNISTD_H @@ -108,8 +108,8 @@ static int sc_main( unsigned mode = 0; const char *pidfile = 0; const char *uid = 0; - - while ((ret = options("c{config}:Dh{help}l:p:tu:V{version}w:X", + + while ((ret = options("c{config}:Dh{help}l:p:tu:V{version}w:X", argv, argc, &arg)) != -2) { switch (ret) @@ -136,7 +136,7 @@ static int sc_main( " -install install windows service\n" " -remove remove windows service\n" #endif - + << std::endl; break; case 'l': @@ -166,7 +166,7 @@ static int sc_main( #else chdir(arg) #endif - ) + ) { std::cerr << "chdir " << arg << " failed" << std::endl; return 1; @@ -184,7 +184,7 @@ static int sc_main( std::cerr << "No configuration given; use -h for help\n"; return 1; } - + if (!test_config) yaz_log(YLOG_LOG, "metaproxy start " VERSION #ifdef VERSION_SHA1 @@ -194,10 +194,10 @@ static int sc_main( yaz_log_xml_errors(0, YLOG_LOG); xmlDocPtr doc = xmlReadFile(fname, - NULL, + NULL, XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS + XML_PARSE_NSCLEAN + XML_PARSE_NONET ); - + if (!doc) { yaz_log(YLOG_FATAL,"XML parsing failed"); @@ -229,9 +229,9 @@ static int sc_main( new mp::RouterFleXML(doc, factory, test_config, wrbuf_cstr(base_path)); if (!test_config) { - + yaz_sc_running(s); - + yaz_daemon("metaproxy", mode, mode == YAZ_DAEMON_DEBUG ? work_debug : work_normal, router, pidfile, uid); } diff --git a/src/origin.cpp b/src/origin.cpp index 0e500df..88d362b 100644 --- a/src/origin.cpp +++ b/src/origin.cpp @@ -64,7 +64,7 @@ std::ostream& std::operator<<(std::ostream& os, const mp::Origin& o) os << ":" << o.m_custom_session; return os; } - + /* * Local variables: * c-basic-offset: 4 diff --git a/src/package.cpp b/src/package.cpp index 3d4e021..586eda1 100644 --- a/src/package.cpp +++ b/src/package.cpp @@ -32,7 +32,7 @@ namespace metaproxy_1 { }; } -mp::Package::Package() +mp::Package::Package() : m_route_pos(0) { } @@ -42,7 +42,7 @@ mp::Package::~Package() delete m_route_pos; } -mp::Package::Package(mp::Session &session, const mp::Origin &origin) +mp::Package::Package(mp::Session &session, const mp::Origin &origin) : m_session(session), m_origin(origin), m_route_pos(0) { @@ -88,11 +88,11 @@ mp::Session & mp::Package::session() return m_session; } -mp::Origin mp::Package::origin() const +mp::Origin mp::Package::origin() const { return m_origin; } - + mp::Origin & mp::Package::origin() { return m_origin; diff --git a/src/pipe.cpp b/src/pipe.cpp index 083d1f1..2f2538b 100644 --- a/src/pipe.cpp +++ b/src/pipe.cpp @@ -123,7 +123,7 @@ Pipe::Pipe(int port_to_use) : m_p(new Rep) throw Pipe::Error("could not create socket"); #ifndef WIN32 unsigned long one = 1; - if (setsockopt(m_p->m_socket, SOL_SOCKET, SO_REUSEADDR, (char*) + if (setsockopt(m_p->m_socket, SOL_SOCKET, SO_REUSEADDR, (char*) &one, sizeof(one)) < 0) throw Pipe::Error("setsockopt error"); #endif @@ -133,10 +133,10 @@ Pipe::Pipe(int port_to_use) : m_p(new Rep) add.sin_port = htons(port_to_use); add.sin_addr.s_addr = INADDR_ANY; struct sockaddr *addr = ( struct sockaddr *) &add; - + if (bind(m_p->m_socket, addr, sizeof(struct sockaddr_in))) throw Pipe::Error("could not bind on socket"); - + if (listen(m_p->m_socket, 3) < 0) throw Pipe::Error("could not listen on socket"); @@ -147,11 +147,11 @@ Pipe::Pipe(int port_to_use) : m_p(new Rep) memcpy(&add.sin_addr.s_addr, &tmpadd, sizeof(struct in_addr)); else throw Pipe::Error("inet_addr failed"); - + m_p->m_fd[1] = socket(AF_INET, SOCK_STREAM, 0); if (m_p->m_fd[1] < 0) throw Pipe::Error("could not create socket"); - + m_p->nonblock(m_p->m_fd[1]); if (connect(m_p->m_fd[1], addr, sizeof(*addr)) < 0) diff --git a/src/pipe.hpp b/src/pipe.hpp index f2e4a31..db57499 100644 --- a/src/pipe.hpp +++ b/src/pipe.hpp @@ -29,7 +29,7 @@ namespace metaproxy_1 { class Pipe { class Error : public std::runtime_error { public: - Error(const std::string msg) + Error(const std::string msg) : std::runtime_error("Pipe error: " + msg) {}; }; class Rep; diff --git a/src/plainfile.cpp b/src/plainfile.cpp index 78d9897..8dbd0eb 100644 --- a/src/plainfile.cpp +++ b/src/plainfile.cpp @@ -89,7 +89,7 @@ bool mp::PlainFile::getline(std::vector &args) m_p->close(); // might as well close it now return false; } - + m_p->lineno++; m_p->fh->getline(line_cstr, PLAINFILE_MAX_LINE-1); char first = line_cstr[0]; diff --git a/src/router_flexml.cpp b/src/router_flexml.cpp index 29e468b..987a9d9 100644 --- a/src/router_flexml.cpp +++ b/src/router_flexml.cpp @@ -88,7 +88,7 @@ namespace metaproxy_1 { virtual ~Pos(); mp::RouterFleXML::Rep *m_p; - std::map::iterator m_route_it; std::list >::iterator m_filter_it; }; @@ -168,10 +168,10 @@ void mp::RouterFleXML::Rep::parse_xml_filters1(xmlDocPtr doc, { std::string name = std::string((const char *) attr->name); std::string value; - + if (attr->children && attr->children->type == XML_TEXT_NODE) value = std::string((const char *)attr->children->content); - + if (name == "refid") refid_value = value; else if (name == "type") @@ -201,13 +201,13 @@ void mp::RouterFleXML::Rep::parse_xml_filters1(xmlDocPtr doc, m_factory->add_creator_dl(type_value, m_dl_path); } mp::filter::Base* filter_base = m_factory->create(type_value); - + filter_base->configure(node, test_only, file_include_path); - + route.m_list.push_back( boost::shared_ptr(filter_base)); } - + } node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE); } @@ -232,10 +232,10 @@ void mp::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc, { std::string name = std::string((const char *) attr->name); std::string value; - + if (attr->children && attr->children->type == XML_TEXT_NODE) value = std::string((const char *)attr->children->content); - + if (name == "id") id_value = value; else @@ -285,10 +285,10 @@ void mp::RouterFleXML::Rep::check_routes_in_filters(const xmlNode *node) if (!strcmp((const char *) attr->name, "route")) { std::string value; - + if (attr->children && attr->children->type == XML_TEXT_NODE) value = std::string((const char *)attr->children->content); - + std::map::iterator it; it = m_routes.find(value); if (it == m_routes.end()) @@ -310,7 +310,7 @@ void mp::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc, { if (!doc) throw mp::XMLError("Empty XML Document"); - + const xmlNode* root = xmlDocGetRootElement(doc); if (file_include_path) @@ -319,7 +319,7 @@ void mp::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc, if (r) throw mp::XMLError("YAZ XML Include failed"); } - + mp::xml::check_element_mp(root, "metaproxy"); const xmlNode* node = mp::xml::jump_to_children(root, XML_ELEMENT_NODE); @@ -355,19 +355,19 @@ void mp::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc, parse_xml_filters(doc, mp::xml::jump_to_children(node, XML_ELEMENT_NODE), test_only, file_include_path); - + node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE); } // process node which is expected third element node mp::xml::check_element_mp(node, "routes"); - + parse_xml_routes(doc, mp::xml::jump_to_children(node, XML_ELEMENT_NODE), test_only, file_include_path); node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE); if (node) { - throw mp::XMLError("Unexpected element " + throw mp::XMLError("Unexpected element " + std::string((const char *)node->name)); } @@ -388,7 +388,7 @@ void mp::RouterFleXML::Rep::parse_xml_config_dom(xmlDocPtr doc, { check_routes_in_filters( mp::xml::jump_to_children(n, XML_ELEMENT_NODE)); - + } n = mp::xml::jump_to_next(n, XML_ELEMENT_NODE); } @@ -417,11 +417,11 @@ mp::RouterFleXML::RouterFleXML(xmlDocPtr doc, mp::FactoryFilter &factory, } mp::RouterFleXML::RouterFleXML(std::string xmlconf, mp::FactoryFilter &factory, - bool test_only) + bool test_only) : m_p(new Rep) -{ +{ LIBXML_TEST_VERSION; - + xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(), xmlconf.size()); if (!doc) diff --git a/src/router_flexml.hpp b/src/router_flexml.hpp index 2a385d7..5d56b8f 100644 --- a/src/router_flexml.hpp +++ b/src/router_flexml.hpp @@ -27,9 +27,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include -namespace metaproxy_1 +namespace metaproxy_1 { - class RouterFleXML : public metaproxy_1::Router + class RouterFleXML : public metaproxy_1::Router { class Rep; class Route; @@ -39,7 +39,7 @@ namespace metaproxy_1 bool test_only); RouterFleXML(xmlDocPtr doc, metaproxy_1::FactoryFilter &factory, bool test_only, const char *file_include_path); - + ~RouterFleXML(); virtual RoutePos *createpos() const; @@ -48,7 +48,7 @@ namespace metaproxy_1 private: boost::scoped_ptr m_p; }; - + }; #endif diff --git a/src/sru_util.cpp b/src/sru_util.cpp index 8c9cfb4..a02cc64 100644 --- a/src/sru_util.cpp +++ b/src/sru_util.cpp @@ -33,10 +33,10 @@ bool mp_util::build_sru_debug_package(mp::Package &package) { Z_GDU *zgdu_req = package.request().get(); if (zgdu_req && zgdu_req->which == Z_GDU_HTTP_Request) - { + { Z_HTTP_Request* http_req = zgdu_req->u.HTTP_Request; std::string content = mp_util::http_headers_debug(*http_req); - int http_code = 400; + int http_code = 400; mp_util::http_response(package, content, http_code); return true; } @@ -60,7 +60,7 @@ mp_util::SRUServerInfo mp_util::get_sru_server_info(mp::Package &package) if (http_req) { std::string http_path = http_req->path; - + // taking out GET parameters std::string::size_type ipath = http_path.rfind("?"); if (ipath != std::string::npos) @@ -69,7 +69,7 @@ mp_util::SRUServerInfo mp_util::get_sru_server_info(mp::Package &package) // assign to database name if (http_path.size() > 1) sruinfo.database.assign(http_path, 1, std::string::npos); - + std::string http_host_address = mp_util::http_header_value(http_req->headers, "Host"); @@ -77,12 +77,12 @@ mp_util::SRUServerInfo mp_util::get_sru_server_info(mp::Package &package) if (iaddress != std::string::npos) { sruinfo.host.assign(http_host_address, 0, iaddress); - sruinfo.port.assign(http_host_address, iaddress + 1, + sruinfo.port.assign(http_host_address, iaddress + 1, std::string::npos); } } } - + //std::cout << "sruinfo.database " << sruinfo.database << "\n"; //std::cout << "sruinfo.host " << sruinfo.host << "\n"; //std::cout << "sruinfo.port " << sruinfo.port << "\n"; @@ -91,7 +91,7 @@ mp_util::SRUServerInfo mp_util::get_sru_server_info(mp::Package &package) } -bool mp_util::build_sru_explain(metaproxy_1::Package &package, +bool mp_util::build_sru_explain(metaproxy_1::Package &package, metaproxy_1::odr &odr_en, Z_SRW_PDU *sru_pdu_res, SRUServerInfo sruinfo, @@ -100,11 +100,11 @@ bool mp_util::build_sru_explain(metaproxy_1::Package &package, { // building SRU explain record - std::string explain_xml; + std::string explain_xml; if (explain == 0) { - explain_xml + explain_xml = mp_util::to_string( "\n" " \n" @@ -137,31 +137,31 @@ bool mp_util::build_sru_explain(metaproxy_1::Package &package, // z3950'fy recordPacking int record_packing = Z_SRW_recordPacking_XML; if (er_req && er_req->recordPacking && 's' == *(er_req->recordPacking)) - record_packing = Z_SRW_recordPacking_string; - + record_packing = Z_SRW_recordPacking_string; + // preparing explain record insert Z_SRW_explainResponse *sru_res = sru_pdu_res->u.explain_response; - + // inserting one and only explain record - + sru_res->record.recordPosition = odr_intdup(odr_en, 1); sru_res->record.recordPacking = record_packing; sru_res->record.recordSchema = (char *)xmlns_explain.c_str(); sru_res->record.recordData_len = 1 + explain_xml.size(); sru_res->record.recordData_buf - = odr_strdupn(odr_en, (const char *)explain_xml.c_str(), + = odr_strdupn(odr_en, (const char *)explain_xml.c_str(), 1 + explain_xml.size()); return true; } -bool mp_util::build_sru_response(mp::Package &package, +bool mp_util::build_sru_response(mp::Package &package, mp::odr &odr_en, Z_SOAP *soap, const Z_SRW_PDU *sru_pdu_res, char *charset, - const char *stylesheet) + const char *stylesheet) { // SRU request package translation to Z3950 package @@ -170,19 +170,19 @@ bool mp_util::build_sru_response(mp::Package &package, //else // std::cout << "SRU empty\n"; - + Z_GDU *zgdu_req = package.request().get(); if (zgdu_req && zgdu_req->which == Z_GDU_HTTP_Request) - { + { Z_GDU *zgdu_res //= z_get_HTTP_Response(odr_en, 200); - = odr_en.create_HTTP_Response(package.session(), - zgdu_req->u.HTTP_Request, + = odr_en.create_HTTP_Response(package.session(), + zgdu_req->u.HTTP_Request, 200); // adding HTTP response code and headers Z_HTTP_Response * http_res = zgdu_res->u.HTTP_Response; //http_res->code = http_code; - + std::string ctype("text/xml"); if (charset) { @@ -190,7 +190,7 @@ bool mp_util::build_sru_response(mp::Package &package, ctype += charset; } - z_HTTP_header_add(odr_en, + z_HTTP_header_add(odr_en, &http_res->headers, "Content-Type", ctype.c_str()); // packaging Z_SOAP into HTML response @@ -205,15 +205,15 @@ bool mp_util::build_sru_response(mp::Package &package, // empty stylesheet means NO stylesheet if (stylesheet && *stylesheet == '\0') stylesheet = 0; - + // encoding SRU package - - soap->u.generic->p = (void*) sru_pdu_res; - //int ret = - z_soap_codec_enc_xsl(odr_en, &soap, + + soap->u.generic->p = (void*) sru_pdu_res; + //int ret = + z_soap_codec_enc_xsl(odr_en, &soap, &http_res->content_buf, &http_res->content_len, soap_handlers, charset, stylesheet); - + package.response() = zgdu_res; return true; @@ -230,28 +230,28 @@ Z_SRW_PDU * mp_util::decode_sru_request(mp::Package &package, Z_SRW_PDU *sru_pdu_res, Z_SOAP **soap, char *charset, - char *stylesheet) + char *stylesheet) { Z_GDU *zgdu_req = package.request().get(); Z_SRW_PDU *sru_pdu_req = 0; //assert((zgdu_req->which == Z_GDU_HTTP_Request)); - + //ignoring all non HTTP_Request packages if (!zgdu_req || !(zgdu_req->which == Z_GDU_HTTP_Request)) { return 0; } - + Z_HTTP_Request* http_req = zgdu_req->u.HTTP_Request; if (! http_req) return 0; // checking if we got a SRU GET/POST/SOAP HTTP package // closing connection if we did not ... - if (0 == yaz_sru_decode(http_req, &sru_pdu_req, soap, - odr_de, &charset, - &(sru_pdu_res->u.response->diagnostics), + if (0 == yaz_sru_decode(http_req, &sru_pdu_req, soap, + odr_de, &charset, + &(sru_pdu_res->u.response->diagnostics), &(sru_pdu_res->u.response->num_diagnostics))) { if (sru_pdu_res->u.response->num_diagnostics) @@ -262,10 +262,10 @@ Z_SRW_PDU * mp_util::decode_sru_request(mp::Package &package, } return sru_pdu_req; } - else if (0 == yaz_srw_decode(http_req, &sru_pdu_req, soap, + else if (0 == yaz_srw_decode(http_req, &sru_pdu_req, soap, odr_de, &charset)) return sru_pdu_req; - else + else { //sru_pdu_res = sru_pdu_res_exp; package.session().close(); @@ -275,22 +275,22 @@ Z_SRW_PDU * mp_util::decode_sru_request(mp::Package &package, } -bool -mp_util::check_sru_query_exists(mp::Package &package, +bool +mp_util::check_sru_query_exists(mp::Package &package, mp::odr &odr_en, - Z_SRW_PDU *sru_pdu_res, + Z_SRW_PDU *sru_pdu_res, Z_SRW_searchRetrieveRequest const *sr_req) { if ((sr_req->query_type == Z_SRW_query_type_cql && !sr_req->query.cql)) { yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.response->diagnostics), - &(sru_pdu_res->u.response->num_diagnostics), + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED, "query"); yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.response->diagnostics), - &(sru_pdu_res->u.response->num_diagnostics), + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), YAZ_SRW_QUERY_SYNTAX_ERROR, "CQL query is empty"); return false; @@ -298,8 +298,8 @@ mp_util::check_sru_query_exists(mp::Package &package, if ((sr_req->query_type == Z_SRW_query_type_xcql && !sr_req->query.xcql)) { yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.response->diagnostics), - &(sru_pdu_res->u.response->num_diagnostics), + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), YAZ_SRW_QUERY_SYNTAX_ERROR, "XCQL query is empty"); return false; @@ -307,8 +307,8 @@ mp_util::check_sru_query_exists(mp::Package &package, if ((sr_req->query_type == Z_SRW_query_type_pqf && !sr_req->query.pqf)) { yaz_add_srw_diagnostic(odr_en, - &(sru_pdu_res->u.response->diagnostics), - &(sru_pdu_res->u.response->num_diagnostics), + &(sru_pdu_res->u.response->diagnostics), + &(sru_pdu_res->u.response->num_diagnostics), YAZ_SRW_QUERY_SYNTAX_ERROR, "PQF query is empty"); return false; @@ -317,24 +317,24 @@ mp_util::check_sru_query_exists(mp::Package &package, } -Z_ElementSetNames * +Z_ElementSetNames * mp_util::build_esn_from_schema(mp::odr &odr_en, const char *schema) { if (!schema) return 0; - - Z_ElementSetNames *esn + + Z_ElementSetNames *esn = (Z_ElementSetNames *) odr_malloc(odr_en, sizeof(Z_ElementSetNames)); esn->which = Z_ElementSetNames_generic; esn->u.generic = odr_strdup(odr_en, schema); - return esn; + return esn; } -std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu) +std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu) { os << "SRU"; - + switch (srw_pdu.which) { case Z_SRW_searchRetrieve_request: @@ -364,7 +364,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu) os << " " << (sr->recordSchema); else os << " -"; - + switch (sr->query_type){ case Z_SRW_query_type_cql: os << " CQL"; @@ -404,7 +404,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu) os << " " << *(sr->nextRecordPosition); else os << " -"; - } + } else { os << " DIAG"; @@ -421,8 +421,8 @@ std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu) else os << " -"; } - - + + } } break; @@ -444,11 +444,11 @@ std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu) case Z_SRW_update_response: os << " " << "updateResponse"; break; - default: - os << " " << "UNKNOWN"; + default: + os << " " << "UNKNOWN"; } - return os; + return os; } /* diff --git a/src/sru_util.hpp b/src/sru_util.hpp index 48ff27f..94d537d 100644 --- a/src/sru_util.hpp +++ b/src/sru_util.hpp @@ -27,9 +27,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include -namespace std +namespace std { - std::ostream& operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu); + std::ostream& operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu); } @@ -41,37 +41,37 @@ namespace metaproxy_1 { // std::string sru_protocol(const Z_HTTP_Request &http_req); // std::string debug_http(const Z_HTTP_Request &http_req); - // void http_response(mp::Package &package, - // const std::string &content, + // void http_response(mp::Package &package, + // const std::string &content, // int http_code = 200); bool build_sru_debug_package(metaproxy_1::Package &package); SRUServerInfo get_sru_server_info(metaproxy_1::Package &package); - // Z_SRW_explainRequest + // Z_SRW_explainRequest //const *er_req); - -// bool build_simple_explain(metaproxy_1::Package &package, + +// bool build_simple_explain(metaproxy_1::Package &package, // metaproxy_1::odr &odr_en, // Z_SRW_PDU *sru_pdu_res, // SRUServerInfo sruinfo, // Z_SRW_explainRequest const *er_req = 0); - - bool build_sru_explain(metaproxy_1::Package &package, + + bool build_sru_explain(metaproxy_1::Package &package, metaproxy_1::odr &odr_en, Z_SRW_PDU *sru_pdu_res, SRUServerInfo sruinfo, const xmlNode *explain = 0, Z_SRW_explainRequest const *er_req = 0); - - bool build_sru_response(metaproxy_1::Package &package, + + bool build_sru_response(metaproxy_1::Package &package, metaproxy_1::odr &odr_en, Z_SOAP *soap, const Z_SRW_PDU *sru_pdu_res, char *charset, - const char *stylesheet); - - Z_SRW_PDU * decode_sru_request(metaproxy_1::Package &package, + const char *stylesheet); + + Z_SRW_PDU * decode_sru_request(metaproxy_1::Package &package, metaproxy_1::odr &odr_de, metaproxy_1::odr &odr_en, Z_SRW_PDU *sru_pdu_res, @@ -84,8 +84,8 @@ namespace metaproxy_1 { Z_SRW_PDU *sru_pdu_res, Z_SRW_searchRetrieveRequest const *sr_req); - - Z_ElementSetNames * build_esn_from_schema(metaproxy_1::odr &odr_en, + + Z_ElementSetNames * build_esn_from_schema(metaproxy_1::odr &odr_en, const char *schema); class SRUServerInfo @@ -99,11 +99,11 @@ namespace metaproxy_1 { std::string host; std::string port; }; - - - -// class SRU + + + +// class SRU // { // public: // enum SRU_protocol_type { SRU_NONE, SRU_GET, SRU_POST, SRU_SOAP}; @@ -115,9 +115,9 @@ namespace metaproxy_1 { // private: // SRU_protocol_type m_protocol; // std::string m_charset; -// std::string m_stylesheet; +// std::string m_stylesheet; // }; - } + } } #endif diff --git a/src/test_boost_threads.cpp b/src/test_boost_threads.cpp index f014f95..b630a0f 100644 --- a/src/test_boost_threads.cpp +++ b/src/test_boost_threads.cpp @@ -31,12 +31,12 @@ class counter { public: counter() : count(0) { } - + int increment() { boost::mutex::scoped_lock scoped_lock(mutex); return ++count; } - + private: boost::mutex mutex; int count; @@ -57,11 +57,11 @@ public: BOOST_AUTO_TEST_CASE( thread_group ) { - try + try { const int num_threads = 4; boost::thread_group thrds; - + for (int i=0; i < num_threads; ++i) { worker w; @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE( thread_group ) } thrds.join_all(); } - catch (...) + catch (...) { BOOST_CHECK(false); } @@ -79,11 +79,11 @@ BOOST_AUTO_TEST_CASE( thread_group ) BOOST_AUTO_TEST_CASE( thread_list ) { - try + try { const int num_threads = 4; std::list thread_list; - + for (int i=0; i < num_threads; ++i) { worker w; @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE( thread_list ) } } - catch (...) + catch (...) { BOOST_CHECK(false); } diff --git a/src/test_filter1.cpp b/src/test_filter1.cpp index f8df1d9..4fd8005 100644 --- a/src/test_filter1.cpp +++ b/src/test_filter1.cpp @@ -35,14 +35,14 @@ public: void configure(const xmlNode * ptr, bool test_only, const char *path) { }; }; - + BOOST_AUTO_TEST_CASE( test_filter1 ) { try{ TFilter filter; - + BOOST_CHECK (sizeof(filter) > 0); } catch ( ... ) { diff --git a/src/test_filter2.cpp b/src/test_filter2.cpp index 600004d..894b958 100644 --- a/src/test_filter2.cpp +++ b/src/test_filter2.cpp @@ -56,9 +56,9 @@ void FilterConstant::configure(const xmlNode* ptr, bool test_only, BOOST_CHECK_EQUAL (ptr->type, XML_ELEMENT_NODE); BOOST_CHECK_EQUAL(std::string((const char *) ptr->name), "filter"); - + const struct _xmlAttr *attr; - + for (attr = ptr->properties; attr; attr = attr->next) { BOOST_CHECK_EQUAL( std::string((const char *)attr->name), "type"); @@ -71,15 +71,15 @@ void FilterConstant::configure(const xmlNode* ptr, bool test_only, { if (p->type != XML_ELEMENT_NODE) continue; - + BOOST_CHECK_EQUAL (p->type, XML_ELEMENT_NODE); BOOST_CHECK_EQUAL(std::string((const char *) p->name), "value"); - + const xmlNode *val = p->children; BOOST_CHECK(val); if (!val) continue; - + BOOST_CHECK_EQUAL(val->type, XML_TEXT_NODE); BOOST_CHECK_EQUAL(std::string((const char *)val->content), "2"); @@ -88,7 +88,7 @@ void FilterConstant::configure(const xmlNode* ptr, bool test_only, } // This filter dose not have a configure function - + class FilterDouble: public mp::filter::Base { public: void process(mp::Package & package) const { @@ -99,7 +99,7 @@ public: }; -BOOST_AUTO_TEST_CASE( testfilter2_1 ) +BOOST_AUTO_TEST_CASE( testfilter2_1 ) { try { FilterConstant fc; @@ -107,36 +107,36 @@ BOOST_AUTO_TEST_CASE( testfilter2_1 ) { mp::RouterChain router1; - + // test filter set/get/exception router1.append(fc); - + router1.append(fd); mp::Session session; mp::Origin origin; mp::Package pack(session, origin); - - pack.router(router1).move(); - + + pack.router(router1).move(); + //BOOST_CHECK_EQUAL(pack.data(), 2468); - + } - + { mp::RouterChain router2; - + router2.append(fd); router2.append(fc); - + mp::Session session; mp::Origin origin; mp::Package pack(session, origin); - + pack.router(router2).move(); - + //BOOST_CHECK_EQUAL(pack.data(), 1234); - + } } @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_CASE( testfilter2_1 ) } -BOOST_AUTO_TEST_CASE( testfilter2_2 ) +BOOST_AUTO_TEST_CASE( testfilter2_2 ) { try { FilterConstant fc; @@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE( testfilter2_2 ) "\n" " 2\n" ""; - + // std::cout << some_xml << std::endl; xmlDocPtr doc = xmlParseMemory(some_xml.c_str(), some_xml.size()); @@ -172,9 +172,9 @@ BOOST_AUTO_TEST_CASE( testfilter2_2 ) if (doc) { xmlNodePtr root_element = xmlDocGetRootElement(doc); - + base->configure(root_element, true, 0); - + xmlFreeDoc(doc); } diff --git a/src/test_filter_auth_simple.cpp b/src/test_filter_auth_simple.cpp index 07daa9f..03842c5 100644 --- a/src/test_filter_auth_simple.cpp +++ b/src/test_filter_auth_simple.cpp @@ -35,12 +35,12 @@ namespace mp = metaproxy_1; class FilterBounceInit: public mp::filter::Base { public: void process(mp::Package & package) const { - + if (package.session().is_closed()) { // std::cout << "Got Close.\n"; } - + Z_GDU *gdu = package.request().get(); if (gdu && gdu->which == Z_GDU_Z3950) { @@ -57,7 +57,7 @@ public: BOOST_AUTO_TEST_CASE( test_filter_auth_simple_1 ) { - try + try { mp::filter::AuthSimple lf; } @@ -68,31 +68,31 @@ BOOST_AUTO_TEST_CASE( test_filter_auth_simple_1 ) BOOST_AUTO_TEST_CASE( test_filter_auth_simple2 ) { - try + try { mp::RouterChain router; - + mp::filter::AuthSimple auth; FilterBounceInit bounce; - + router.append(auth); router.append(bounce); - + // Create package with Z39.50 init request in it mp::Package pack; - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); - + pack.request() = apdu; - // Done creating query. - + // Done creating query. + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 init response yazpp_1::GDU *gdu = &pack.response(); - + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (z_gdu) { diff --git a/src/test_filter_backend_test.cpp b/src/test_filter_backend_test.cpp index adbf348..a4f7315 100644 --- a/src/test_filter_backend_test.cpp +++ b/src/test_filter_backend_test.cpp @@ -40,7 +40,7 @@ namespace mp = metaproxy_1; BOOST_AUTO_TEST_CASE( test_filter_backend_test_1 ) { - try + try { mp::filter::BackendTest btest; } @@ -51,30 +51,30 @@ BOOST_AUTO_TEST_CASE( test_filter_backend_test_1 ) BOOST_AUTO_TEST_CASE( test_filter_backend_test_2 ) { - try + try { mp::RouterChain router; - + mp::filter::BackendTest btest; router.append(btest); - + mp::Package pack; - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); - + BOOST_CHECK(apdu); - + pack.request() = apdu; - + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 init Response OK. yazpp_1::GDU *gdu = &pack.response(); - - BOOST_CHECK(!pack.session().is_closed()); - + + BOOST_CHECK(!pack.session().is_closed()); + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (z_gdu) { @@ -89,39 +89,39 @@ BOOST_AUTO_TEST_CASE( test_filter_backend_test_2 ) BOOST_AUTO_TEST_CASE( test_filter_backend_test_3 ) { - try + try { mp::RouterChain router; - + mp::filter::BackendTest btest; router.append(btest); - + mp::Package pack; - + // send search request as first request.. That should fail with // a close from the backend mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest); mp::util::pqf(odr, apdu, "computer"); - + apdu->u.searchRequest->num_databaseNames = 1; apdu->u.searchRequest->databaseNames = (char**) odr_malloc(odr, sizeof(char *)); apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, "Default"); - + BOOST_CHECK(apdu); - + pack.request() = apdu; - + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 close yazpp_1::GDU *gdu = &pack.response(); - - BOOST_CHECK(pack.session().is_closed()); - + + BOOST_CHECK(pack.session().is_closed()); + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (z_gdu) { @@ -136,32 +136,32 @@ BOOST_AUTO_TEST_CASE( test_filter_backend_test_3 ) BOOST_AUTO_TEST_CASE( test_filter_backend_test_4 ) { - try + try { mp::RouterChain router; - + mp::filter::BackendTest btest; router.append(btest); - + mp::Package pack; - + // send present request as first request.. That should fail with // a close from the backend mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest); BOOST_CHECK(apdu); - + pack.request() = apdu; - + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 close yazpp_1::GDU *gdu = &pack.response(); - - BOOST_CHECK(pack.session().is_closed()); - + + BOOST_CHECK(pack.session().is_closed()); + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (z_gdu) { diff --git a/src/test_filter_bounce.cpp b/src/test_filter_bounce.cpp index 5325416..89a3ee0 100644 --- a/src/test_filter_bounce.cpp +++ b/src/test_filter_bounce.cpp @@ -47,19 +47,19 @@ void check_bounce_z3950(mp::RouterChain &router, int request, int response) // Create package with Z39.50 init request in it mp::Package pack; - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, request); pack.request() = apdu; // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect bounced back request yazpp_1::GDU *gdu_req = &pack.request(); yazpp_1::GDU *gdu_res = &pack.response(); - + Z_GDU *z_gdu_req = gdu_req->get(); Z_GDU *z_gdu_res = gdu_res->get(); @@ -89,19 +89,19 @@ void check_bounce_http(mp::RouterChain &router) // Create package with Z39.50 init request in it mp::Package pack; - + mp::odr odr; Z_GDU *gdu = z_get_HTTP_Request(odr); //z_get_HTTP_Request_host_path(odr, host, path); pack.request() = gdu; // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect bounced back request yazpp_1::GDU *gdu_req = &pack.request(); yazpp_1::GDU *gdu_res = &pack.response(); - + Z_GDU *z_gdu_req = gdu_req->get(); Z_GDU *z_gdu_res = gdu_res->get(); @@ -122,7 +122,7 @@ void check_bounce_http(mp::RouterChain &router) BOOST_AUTO_TEST_CASE( test_filter_bounce_1 ) { - try + try { mp::filter::Bounce f_bounce; } @@ -133,39 +133,39 @@ BOOST_AUTO_TEST_CASE( test_filter_bounce_1 ) BOOST_AUTO_TEST_CASE( test_filter_bounce_2 ) { - try + try { - mp::RouterChain router; + mp::RouterChain router; mp::filter::Bounce f_bounce; router.append(f_bounce); - check_bounce_z3950(router, + check_bounce_z3950(router, Z_APDU_initRequest, Z_APDU_close); - //check_bounce_z3950(router, + //check_bounce_z3950(router, // Z_APDU_searchRequest, Z_APDU_close); - check_bounce_z3950(router, + check_bounce_z3950(router, Z_APDU_presentRequest, Z_APDU_close); - check_bounce_z3950(router, + check_bounce_z3950(router, Z_APDU_deleteResultSetRequest, Z_APDU_close); - //check_bounce_z3950(router, + //check_bounce_z3950(router, // Z_APDU_accessControlRequest, Z_APDU_close); - check_bounce_z3950(router, + check_bounce_z3950(router, Z_APDU_resourceControlRequest, Z_APDU_close); - check_bounce_z3950(router, + check_bounce_z3950(router, Z_APDU_triggerResourceControlRequest, Z_APDU_close); - check_bounce_z3950(router, + check_bounce_z3950(router, Z_APDU_resourceReportRequest, Z_APDU_close); - //check_bounce_z3950(router, + //check_bounce_z3950(router, // Z_APDU_scanRequest, Z_APDU_close); - //check_bounce_z3950(router, + //check_bounce_z3950(router, // Z_APDU_sortRequest, Z_APDU_close); - check_bounce_z3950(router, + check_bounce_z3950(router, Z_APDU_segmentRequest, Z_APDU_close); - //check_bounce_z3950(router, + //check_bounce_z3950(router, // Z_APDU_extendedServicesRequest, Z_APDU_close); - check_bounce_z3950(router, + check_bounce_z3950(router, Z_APDU_close , Z_APDU_close); - //check_bounce_z3950(router, + //check_bounce_z3950(router, // Z_APDU_duplicateDetectionRequest, Z_APDU_close); @@ -177,9 +177,9 @@ BOOST_AUTO_TEST_CASE( test_filter_bounce_2 ) BOOST_AUTO_TEST_CASE( test_filter_bounce_3 ) { - try + try { - mp::RouterChain router; + mp::RouterChain router; mp::filter::Bounce f_bounce; router.append(f_bounce); diff --git a/src/test_filter_factory.cpp b/src/test_filter_factory.cpp index afc70a6..23d22d0 100644 --- a/src/test_filter_factory.cpp +++ b/src/test_filter_factory.cpp @@ -67,20 +67,20 @@ static mp::filter::Base* yfilter_creator(){ BOOST_AUTO_TEST_CASE( test_filter_factory_1 ) { try { - + mp::FactoryFilter ffactory; - + XFilter xf; YFilter yf; const std::string xfid = "XFilter"; const std::string yfid = "YFilter"; - + BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator)); BOOST_CHECK(ffactory.drop_creator(xfid)); BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator)); BOOST_CHECK(ffactory.add_creator(yfid, yfilter_creator)); - + mp::filter::Base* xfilter = 0; xfilter = ffactory.create(xfid); mp::filter::Base* yfilter = 0; @@ -106,17 +106,17 @@ BOOST_AUTO_TEST_CASE( test_filter_factory_1 ) #if HAVE_DLFCN_H BOOST_AUTO_TEST_CASE( test_filter_factory_2 ) { - try { + try { mp::FactoryFilter ffactory; - + const std::string id = "dl"; - + // first load BOOST_CHECK(ffactory.add_creator_dl(id, ".libs")); // test double load BOOST_CHECK(ffactory.add_creator_dl(id, ".libs")); - + mp::filter::Base* filter = 0; filter = ffactory.create(id); diff --git a/src/test_filter_frontend_net.cpp b/src/test_filter_frontend_net.cpp index 6f0ade0..12f1a0f 100644 --- a/src/test_filter_frontend_net.cpp +++ b/src/test_filter_frontend_net.cpp @@ -36,12 +36,12 @@ namespace mp = metaproxy_1; class FilterInit: public mp::filter::Base { public: void process(mp::Package & package) const { - + if (package.session().is_closed()) { // std::cout << "Got Close.\n"; } - + Z_GDU *gdu = package.request().get(); if (gdu && gdu->which == Z_GDU_Z3950) { @@ -58,7 +58,7 @@ public: BOOST_AUTO_TEST_CASE( test_filter_frontend_net_1 ) { - try + try { { mp::filter::FrontendNet nf; @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE( test_filter_frontend_net_1 ) BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 ) { - try + try { { mp::RouterChain router; @@ -89,12 +89,12 @@ BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 ) mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); - + pack.request() = apdu; - // Done creating query. + // Done creating query. // Put it in router - pack.router(router).move(); + pack.router(router).move(); // Inspect that we got Z39.50 init response yazpp_1::GDU *gdu = &pack.response(); @@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 ) BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 ) { - try + try { { mp::RouterChain router; @@ -137,8 +137,8 @@ BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 ) router.append(filter_init); mp::Package pack; - - pack.router(router).move(); + + pack.router(router).move(); } BOOST_CHECK(true); } diff --git a/src/test_filter_log.cpp b/src/test_filter_log.cpp index 0f49e12..0f3cb66 100644 --- a/src/test_filter_log.cpp +++ b/src/test_filter_log.cpp @@ -35,12 +35,12 @@ namespace mp = metaproxy_1; class FilterBounceInit: public mp::filter::Base { public: void process(mp::Package & package) const { - + if (package.session().is_closed()) { // std::cout << "Got Close.\n"; } - + Z_GDU *gdu = package.request().get(); if (gdu && gdu->which == Z_GDU_Z3950) { @@ -57,7 +57,7 @@ public: BOOST_AUTO_TEST_CASE( test_filter_log_1 ) { - try + try { mp::filter::Log lf; } @@ -68,31 +68,31 @@ BOOST_AUTO_TEST_CASE( test_filter_log_1 ) BOOST_AUTO_TEST_CASE( test_filter_log_2 ) { - try + try { mp::RouterChain router; - + mp::filter::Log lf; FilterBounceInit bf; - + router.append(lf); router.append(bf); - + // Create package with Z39.50 init request in it mp::Package pack; - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); - + pack.request() = apdu; - // Done creating query. - + // Done creating query. + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 init response yazpp_1::GDU *gdu = &pack.response(); - + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (z_gdu) { diff --git a/src/test_filter_multi.cpp b/src/test_filter_multi.cpp index 2455f16..672517b 100644 --- a/src/test_filter_multi.cpp +++ b/src/test_filter_multi.cpp @@ -35,12 +35,12 @@ namespace mp = metaproxy_1; class FilterBounceInit: public mp::filter::Base { public: void process(mp::Package & package) const { - + if (package.session().is_closed()) { // std::cout << "Got Close.\n"; } - + Z_GDU *gdu = package.request().get(); if (gdu && gdu->which == Z_GDU_Z3950) { @@ -57,7 +57,7 @@ public: BOOST_AUTO_TEST_CASE( test_filter_multi_1 ) { - try + try { mp::filter::Multi lf; } @@ -68,31 +68,31 @@ BOOST_AUTO_TEST_CASE( test_filter_multi_1 ) BOOST_AUTO_TEST_CASE( test_filter_multi_2 ) { - try + try { mp::RouterChain router; - + mp::filter::Multi multi; FilterBounceInit bounce; - + router.append(multi); router.append(bounce); - + // Create package with Z39.50 init request in it mp::Package pack; - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); - + pack.request() = apdu; - // Done creating query. - + // Done creating query. + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 init response yazpp_1::GDU *gdu = &pack.response(); - + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (z_gdu) { diff --git a/src/test_filter_query_rewrite.cpp b/src/test_filter_query_rewrite.cpp index 1ae68a8..506b600 100644 --- a/src/test_filter_query_rewrite.cpp +++ b/src/test_filter_query_rewrite.cpp @@ -37,40 +37,40 @@ using namespace mp::util; class FilterBounceZ3950: public mp::filter::Base { public: void process(mp::Package & package) const { - + if (package.session().is_closed()) { std::cout << "Got Close.\n"; return; } - + Z_GDU *gdu = package.request().get(); - - if (gdu && gdu->which == Z_GDU_Z3950 + + if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_initRequest) { - std::cout << "Got Z3950 Init PDU\n"; + std::cout << "Got Z3950 Init PDU\n"; //Z_InitRequest *req = gdu->u.z3950->u.initRequest; //package.request() = gdu; return; - } - else if (gdu && gdu->which == Z_GDU_Z3950 + } + else if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_searchRequest) { - std::cout << "Got Z3950 Search PDU\n"; + std::cout << "Got Z3950 Search PDU\n"; //Z_SearchRequest *req = gdu->u.z3950->u.searchRequest; //package.request() = gdu; return; - } - else if (gdu && gdu->which == Z_GDU_Z3950 + } + else if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which == Z_APDU_scanRequest) { - std::cout << "Got Z3950 Scan PDU\n"; + std::cout << "Got Z3950 Scan PDU\n"; //Z_ScanRequest *req = gdu->u.z3950->u.scanRequest; //package.request() = gdu; return; - } - + } + package.move(); }; }; @@ -81,20 +81,20 @@ void check_query_rewrite_init(mp::RouterChain &router) // Create package with Z39.50 init request in it mp::Package pack; - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); - + pack.request() = apdu; // Done creating query. // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect bounced back request //yazpp_1::GDU *gdu = &pack.response(); yazpp_1::GDU *gdu = &pack.request(); - + Z_GDU *z_gdu = gdu->get(); //std::cout << "Z_GDU " << z_gdu << "\n"; @@ -105,48 +105,48 @@ void check_query_rewrite_init(mp::RouterChain &router) } } -void check_query_rewrite_search(mp::RouterChain &router, +void check_query_rewrite_search(mp::RouterChain &router, std::string query_in, std::string query_expect) { - //std::cout << "QUERY REWRITE SEARCH " + //std::cout << "QUERY REWRITE SEARCH " // << query_in << " " << query_expect << "\n"; - + // Create package with Z39.50 search request in it mp::Package pack; - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest); - // create package PQF query here + // create package PQF query here mp::util::pqf(odr, apdu, query_in); // create package PDF database info (needed!) apdu->u.searchRequest->num_databaseNames = 1; - apdu->u.searchRequest->databaseNames + apdu->u.searchRequest->databaseNames = (char**)odr_malloc(odr, sizeof(char *)); apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, "Default"); - // Done creating request package + // Done creating request package pack.request() = apdu; - + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect bounced back request //yazpp_1::GDU *gdu = &pack.response(); yazpp_1::GDU *gdu = &pack.request(); - + Z_GDU *z_gdu = gdu->get(); //std::cout << "Z_GDU " << z_gdu << "\n"; - + BOOST_CHECK(z_gdu); if (z_gdu) { BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950); BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_searchRequest); // take query out of package again and check rewrite - std::string query_changed + std::string query_changed = zQueryToString(z_gdu->u.z3950->u.searchRequest->query); BOOST_CHECK_EQUAL(query_expect, query_changed); } @@ -155,7 +155,7 @@ void check_query_rewrite_search(mp::RouterChain &router, BOOST_AUTO_TEST_CASE( test_filter_query_rewrite_1 ) { - try + try { mp::filter::QueryRewrite f_query_rewrite; } @@ -166,19 +166,19 @@ BOOST_AUTO_TEST_CASE( test_filter_query_rewrite_1 ) BOOST_AUTO_TEST_CASE( test_filter_query_rewrite2 ) { - try + try { mp::RouterChain router; - + mp::filter::QueryRewrite f_query_rewrite; //FilterBounceZ3950 f_bounce_z3950; - + router.append(f_query_rewrite); //router.append(f_bounce_z3950); check_query_rewrite_init(router); - check_query_rewrite_search(router, - "@attrset Bib-1 @attr 1=4 the", + check_query_rewrite_search(router, + "@attrset Bib-1 @attr 1=4 the", "@attrset Bib-1 @attr 1=4 the"); } @@ -190,20 +190,20 @@ BOOST_AUTO_TEST_CASE( test_filter_query_rewrite2 ) BOOST_AUTO_TEST_CASE( test_filter_query_rewrite3 ) { - - try + + try { mp::RouterChain router; - - std::string xmlconf = + + std::string xmlconf = "\n" "\n" "\n" ; - + //std::cout << xmlconf << std::endl; // reading and parsing XML conf @@ -214,17 +214,17 @@ BOOST_AUTO_TEST_CASE( test_filter_query_rewrite3 ) // creating and configuring filter mp::filter::QueryRewrite f_query_rewrite; f_query_rewrite.configure(root_element, true, 0); - + // remeber to free XML DOM xmlFreeDoc(doc); - + // add only filter to router router.append(f_query_rewrite); // start testing check_query_rewrite_init(router); - check_query_rewrite_search(router, - "@attrset Bib-1 @attr 1=4 the", + check_query_rewrite_search(router, + "@attrset Bib-1 @attr 1=4 the", "@attrset Bib-1 @attr 1=4 the"); } diff --git a/src/test_filter_record_transform.cpp b/src/test_filter_record_transform.cpp index 49390fa..33451d7 100644 --- a/src/test_filter_record_transform.cpp +++ b/src/test_filter_record_transform.cpp @@ -38,7 +38,7 @@ namespace mp = metaproxy_1; BOOST_AUTO_TEST_CASE( test_filter_record_transform_1 ) { - try + try { mp::filter::RecordTransform f_rec_trans; } @@ -49,17 +49,17 @@ BOOST_AUTO_TEST_CASE( test_filter_record_transform_1 ) BOOST_AUTO_TEST_CASE( test_filter_record_transform_2 ) { - try + try { mp::RouterChain router; - + mp::filter::RecordTransform f_rec_trans; - + router.append(f_rec_trans); //check_sru_to_z3950_init(router); - //check_sru_to_z3950_search(router, - // "@attrset Bib-1 @attr 1=4 the", + //check_sru_to_z3950_search(router, + // "@attrset Bib-1 @attr 1=4 the", // "@attrset Bib-1 @attr 1=4 the"); } @@ -71,19 +71,19 @@ BOOST_AUTO_TEST_CASE( test_filter_record_transform_2 ) BOOST_AUTO_TEST_CASE( test_filter_record_transform_3 ) { - - try + + try { mp::RouterChain router; - - std::string xmlconf = + + std::string xmlconf = "\n" "\n" "" - "" "" "\n" ; - + //std::cout << xmlconf << std::endl; // reading and parsing XML conf @@ -104,17 +104,17 @@ BOOST_AUTO_TEST_CASE( test_filter_record_transform_3 ) // creating and configuring filter mp::filter::RecordTransform f_rec_trans; f_rec_trans.configure(root_element, true, 0); - + // remeber to free XML DOM xmlFreeDoc(doc); - + // add only filter to router router.append(f_rec_trans); // start testing //check_sru_to_z3950_init(router); - //check_sru_to_z3950_search(router, - // "@attrset Bib-1 @attr 1=4 the", + //check_sru_to_z3950_search(router, + // "@attrset Bib-1 @attr 1=4 the", // "@attrset Bib-1 @attr 1=4 the"); } diff --git a/src/test_filter_sru_to_z3950.cpp b/src/test_filter_sru_to_z3950.cpp index bce264b..d555842 100644 --- a/src/test_filter_sru_to_z3950.cpp +++ b/src/test_filter_sru_to_z3950.cpp @@ -39,7 +39,7 @@ using namespace mp::util; BOOST_AUTO_TEST_CASE( test_filter_sru_to_z3950_1 ) { - try + try { mp::filter::SRUtoZ3950 f_sru_to_z3950; } @@ -50,17 +50,17 @@ BOOST_AUTO_TEST_CASE( test_filter_sru_to_z3950_1 ) BOOST_AUTO_TEST_CASE( test_filter_sru_to_z3950_2 ) { - try + try { mp::RouterChain router; - + mp::filter::SRUtoZ3950 f_sru_to_z3950; - + router.append(f_sru_to_z3950); //check_sru_to_z3950_init(router); - //check_sru_to_z3950_search(router, - // "@attrset Bib-1 @attr 1=4 the", + //check_sru_to_z3950_search(router, + // "@attrset Bib-1 @attr 1=4 the", // "@attrset Bib-1 @attr 1=4 the"); } @@ -72,20 +72,20 @@ BOOST_AUTO_TEST_CASE( test_filter_sru_to_z3950_2 ) // BOOST_AUTO_TEST_CASE( test_filter_sru_to_z3950_3 ) // { - -// try + +// try // { // mp::RouterChain router; - -// std::string xmlconf = + +// std::string xmlconf = // "\n" // "\n" // "\n" // ; - + // //std::cout << xmlconf << std::endl; // // reading and parsing XML conf @@ -96,17 +96,17 @@ BOOST_AUTO_TEST_CASE( test_filter_sru_to_z3950_2 ) // // creating and configuring filter // mp::filter::SRUtoZ3950 f_sru_to_z3950; // f_sru_to_z3950.configure(root_element); - + // // remeber to free XML DOM // xmlFreeDoc(doc); - + // // add only filter to router // router.append(f_sru_to_z3950); // // start testing // check_sru_to_z3950_init(router); -// check_sru_to_z3950_search(router, -// "@attrset Bib-1 @attr 1=4 the", +// check_sru_to_z3950_search(router, +// "@attrset Bib-1 @attr 1=4 the", // "@attrset Bib-1 @attr 1=4 the"); // } diff --git a/src/test_filter_virt_db.cpp b/src/test_filter_virt_db.cpp index 6c44158..46cb10a 100644 --- a/src/test_filter_virt_db.cpp +++ b/src/test_filter_virt_db.cpp @@ -41,7 +41,7 @@ namespace mp = metaproxy_1; BOOST_AUTO_TEST_CASE( test_filter_virt_db_1 ) { - try + try { mp::filter::VirtualDB vdb; } @@ -52,34 +52,34 @@ BOOST_AUTO_TEST_CASE( test_filter_virt_db_1 ) BOOST_AUTO_TEST_CASE( test_filter_virt_db_2 ) { - try + try { mp::RouterChain router; - + mp::filter::VirtualDB vdb; - + router.append(vdb); - + // Create package with Z39.50 init request in it // Since there is not vhost given, the virt will make its // own init response (regardless of backend) mp::Package pack; - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); - + BOOST_CHECK(apdu); - + pack.request() = apdu; - + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 init Response OK. yazpp_1::GDU *gdu = &pack.response(); - - BOOST_CHECK(!pack.session().is_closed()); - + + BOOST_CHECK(!pack.session().is_closed()); + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (z_gdu) { @@ -98,21 +98,21 @@ static void init(mp::Package &pack, mp::Router &router) // Create package with Z39.50 init request in it mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); - + BOOST_CHECK(apdu); if (!apdu) return; - + pack.request() = apdu; - + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 init response yazpp_1::GDU *gdu = &pack.response(); - - BOOST_CHECK(!pack.session().is_closed()); - + + BOOST_CHECK(!pack.session().is_closed()); + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (!z_gdu) @@ -120,42 +120,42 @@ static void init(mp::Package &pack, mp::Router &router) BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950); BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse); } - + static void search(mp::Package &pack, mp::Router &router, const std::string &query, const char *db, const char *setname) { // Create package with Z39.50 search request in it - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest); mp::util::pqf(odr, apdu, query); apdu->u.searchRequest->resultSetName = odr_strdup(odr, setname); - + apdu->u.searchRequest->num_databaseNames = 1; apdu->u.searchRequest->databaseNames = (char**) odr_malloc(odr, sizeof(char *)); apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, db); - + BOOST_CHECK(apdu); if (!apdu) return; - + pack.request() = apdu; - + Z_GDU *gdu_test = pack.request().get(); BOOST_CHECK(gdu_test); - + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 search response yazpp_1::GDU *gdu = &pack.response(); - - BOOST_CHECK(!pack.session().is_closed()); - + + BOOST_CHECK(!pack.session().is_closed()); + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (!z_gdu) @@ -169,10 +169,10 @@ static void present(mp::Package &pack, mp::Router &router, const char *setname) { // Create package with Z39.50 present request in it - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest); - + apdu->u.presentRequest->resultSetId = odr_strdup(odr, setname); *apdu->u.presentRequest->resultSetStartPoint = start; *apdu->u.presentRequest->numberOfRecordsRequested = number; @@ -180,20 +180,20 @@ static void present(mp::Package &pack, mp::Router &router, BOOST_CHECK(apdu); if (!apdu) return; - + pack.request() = apdu; - + Z_GDU *gdu_test = pack.request().get(); BOOST_CHECK(gdu_test); - + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 present response yazpp_1::GDU *gdu = &pack.response(); - - BOOST_CHECK(!pack.session().is_closed()); - + + BOOST_CHECK(!pack.session().is_closed()); + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (!z_gdu) @@ -204,7 +204,7 @@ static void present(mp::Package &pack, mp::Router &router, BOOST_AUTO_TEST_CASE( test_filter_virt_db_3 ) { - try + try { mp::RouterChain router; @@ -212,8 +212,8 @@ BOOST_AUTO_TEST_CASE( test_filter_virt_db_3 ) #if 0 router.append(filter_log1); #endif - - mp::filter::VirtualDB vdb; + + mp::filter::VirtualDB vdb; router.append(vdb); vdb.add_map_db2target("Default", "localhost:210", ""); mp::filter::Log filter_log2("BACK"); @@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE( test_filter_virt_db_3 ) mp::Session session1; mp::Origin origin1; - + { mp::Package pack(session1, origin1); init(pack, router); diff --git a/src/test_filter_z3950_client.cpp b/src/test_filter_z3950_client.cpp index 7f72571..2ad654d 100644 --- a/src/test_filter_z3950_client.cpp +++ b/src/test_filter_z3950_client.cpp @@ -39,7 +39,7 @@ namespace mp = metaproxy_1; BOOST_AUTO_TEST_CASE( test_filter_z3950_client_1 ) { - try + try { mp::filter::Z3950Client zc; // can we construct OK? } @@ -50,33 +50,33 @@ BOOST_AUTO_TEST_CASE( test_filter_z3950_client_1 ) BOOST_AUTO_TEST_CASE( test_filter_z3950_client_2 ) { - try + try { mp::RouterChain router; - + mp::filter::Z3950Client zc; - + router.append(zc); - + // Create package with Z39.50 init request in it mp::Package pack; - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); - + BOOST_CHECK(apdu); - + pack.request() = apdu; - + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 init Response - a Z39.50 session MUST // specify a virtual host yazpp_1::GDU *gdu = &pack.response(); - - BOOST_CHECK(pack.session().is_closed()); - + + BOOST_CHECK(pack.session().is_closed()); + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (z_gdu) { @@ -91,33 +91,33 @@ BOOST_AUTO_TEST_CASE( test_filter_z3950_client_2 ) BOOST_AUTO_TEST_CASE( test_filter_z3950_client_3 ) { - try + try { mp::RouterChain router; - + mp::filter::Z3950Client zc; router.append(zc); - + // Create package with Z39.50 present request in it mp::Package pack; - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest); - + BOOST_CHECK(apdu); - + pack.request() = apdu; - + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + // Inspect that we got Z39.50 close - a Z39.50 session must start // with an init ! yazpp_1::GDU *gdu = &pack.response(); - - BOOST_CHECK(pack.session().is_closed()); - + + BOOST_CHECK(pack.session().is_closed()); + Z_GDU *z_gdu = gdu->get(); BOOST_CHECK(z_gdu); if (z_gdu) { @@ -132,20 +132,20 @@ BOOST_AUTO_TEST_CASE( test_filter_z3950_client_3 ) BOOST_AUTO_TEST_CASE( test_filter_z3950_client_4 ) { - try + try { mp::RouterChain router; - + mp::filter::Z3950Client zc; - + router.append(zc); - + // Create package with Z39.50 init request in it mp::Package pack; - + mp::odr odr; Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); - + const char *vhost = "localhost:9999"; if (vhost) { @@ -153,12 +153,12 @@ BOOST_AUTO_TEST_CASE( test_filter_z3950_client_4 ) odr, yaz_oid_userinfo_proxy, 1, vhost); } BOOST_CHECK(apdu); - + pack.request() = apdu; - + // Put it in router - pack.router(router).move(); - + pack.router(router).move(); + if (pack.session().is_closed()) { // OK, server was not up! diff --git a/src/test_pipe.cpp b/src/test_pipe.cpp index 0680ca7..8006ecd 100644 --- a/src/test_pipe.cpp +++ b/src/test_pipe.cpp @@ -60,7 +60,7 @@ public: Timer::Timer(yazpp_1::ISocketObservable *obs, - int duration) : + int duration) : m_obs(obs), m_pipe(9122), m_data(false), m_timeout(false) { obs->addObserver(m_pipe.read_fd(), this); @@ -104,7 +104,7 @@ void Timer::socketNotify(int event) BOOST_AUTO_TEST_CASE( test_pipe_1 ) { yazpp_1::SocketManager mySocketManager; - + Timer t(&mySocketManager, 1); while (mySocketManager.processEvent() > 0) diff --git a/src/test_router_flexml.cpp b/src/test_router_flexml.cpp index 39d0b63..e3f3223 100644 --- a/src/test_router_flexml.cpp +++ b/src/test_router_flexml.cpp @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE( test_router_flexml_1 ) " other\n" " \n" " \n" - " \n" + " \n" " \n" " \n" " \n" @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE( test_router_flexml_2 ) " \n" " \n" " @:210\n"; - + mp::FactoryFilter factory; mp::RouterFleXML rflexml(xmlconf_invalid, factory, true); } @@ -140,14 +140,14 @@ BOOST_AUTO_TEST_CASE( test_router_flexml_3 ) " my msg\n" " \n" " \n" - " \n" + " \n" " \n" " \n" " \n" " \n" " \n" "\n"; - + mp::FactoryStatic factory; mp::RouterFleXML rflexml(xmlconf, factory, true); } @@ -169,13 +169,13 @@ BOOST_AUTO_TEST_CASE( test_router_flexml_4 ) std::string xmlconf = "\n" "\n" - " \n" + " \n" " \n" " \n" " @:210\n" " \n" " \n" - " \n" + " \n" " \n" " \n" " \n" diff --git a/src/test_ses_map.cpp b/src/test_ses_map.cpp index f073f42..8868cee 100644 --- a/src/test_ses_map.cpp +++ b/src/test_ses_map.cpp @@ -39,7 +39,7 @@ namespace mp = metaproxy_1; namespace metaproxy_1 { class SesMap; - + class SesMap { class Wrap { @@ -53,7 +53,7 @@ namespace metaproxy_1 { public: void create(SesMap &sm, const mp::Session &s, double &t) { boost::mutex::scoped_lock lock(m_map_mutex); - + boost::shared_ptr w_ptr(new Wrap(t)); m_map_ptr[s] = w_ptr; } @@ -64,7 +64,7 @@ namespace metaproxy_1 { BOOST_AUTO_TEST_CASE( test_ses_map_1 ) { - try + try { mp::SesMap ses_map; } diff --git a/src/test_session1.cpp b/src/test_session1.cpp index ca4d3b7..e7d9b7c 100644 --- a/src/test_session1.cpp +++ b/src/test_session1.cpp @@ -28,10 +28,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using namespace boost::unit_test; namespace mp = metaproxy_1; -BOOST_AUTO_TEST_CASE( testsession1 ) +BOOST_AUTO_TEST_CASE( testsession1 ) { - // test session + // test session try { mp::Session session1; mp::Session session2; diff --git a/src/test_session2.cpp b/src/test_session2.cpp index 350b6a1..7087e37 100644 --- a/src/test_session2.cpp +++ b/src/test_session2.cpp @@ -34,17 +34,17 @@ namespace mp = metaproxy_1; boost::mutex io_mutex; -class Worker +class Worker { public: - Worker(int nr = 0) + Worker(int nr = 0) : m_nr(nr), m_id(0) {}; - + void operator() (void) { for (int i=0; i < 100; ++i) { mp::Session session; - m_id = session.id(); + m_id = session.id(); //print(); } } @@ -52,26 +52,26 @@ class Worker void print() { boost::mutex::scoped_lock scoped_lock(io_mutex); - std::cout << "Worker " << m_nr + std::cout << "Worker " << m_nr << " session.id() " << m_id << std::endl; } - - private: + + private: int m_nr; int m_id; }; -BOOST_AUTO_TEST_CASE( testsession2 ) +BOOST_AUTO_TEST_CASE( testsession2 ) { - // test session + // test session try { const int num_threads = 100; boost::thread_group thrds; - + for (int i=0; i < num_threads; ++i) { @@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE( testsession2 ) mp::Session session; BOOST_CHECK (session.id() == 10001); - + } catch (std::exception &e) { std::cout << e.what() << "\n"; diff --git a/src/test_thread_pool_observer.cpp b/src/test_thread_pool_observer.cpp index 89f8f04..fc84b9b 100644 --- a/src/test_thread_pool_observer.cpp +++ b/src/test_thread_pool_observer.cpp @@ -83,8 +83,8 @@ void My_Msg::result(const char *t_info) } My_Timer_Thread::My_Timer_Thread(ISocketObservable *obs, - mp::ThreadPoolSocketObserver *t) : - m_obs(obs), m_pipe(9123) + mp::ThreadPoolSocketObserver *t) : + m_obs(obs), m_pipe(9123) { m_t = t; m_sum = 0; @@ -111,7 +111,7 @@ void My_Timer_Thread::socketNotify(int event) #endif } -BOOST_AUTO_TEST_CASE( thread_pool_observer1 ) +BOOST_AUTO_TEST_CASE( thread_pool_observer1 ) { SocketManager mySocketManager; diff --git a/src/test_xmlutil.cpp b/src/test_xmlutil.cpp index 6ede61c..7c6dcf2 100644 --- a/src/test_xmlutil.cpp +++ b/src/test_xmlutil.cpp @@ -36,9 +36,9 @@ namespace mp_xml = metaproxy_1::xml; BOOST_AUTO_TEST_CASE( url_recipe ) { - try + try { - const char *xml_text = + const char *xml_text = "\n" "\n" diff --git a/src/thread_pool_observer.cpp b/src/thread_pool_observer.cpp index e9dd20c..f88a520 100644 --- a/src/thread_pool_observer.cpp +++ b/src/thread_pool_observer.cpp @@ -185,9 +185,9 @@ void ThreadPoolSocketObserver::run(void *p) m_p->m_no_threads_waiting--; if (m_p->m_stop_flag) break; - + in = m_p->m_input.front(); - m_p->m_input.pop_front(); + m_p->m_input.pop_front(); m_p->m_cond_input_full.notify_all(); } IThreadPoolMsg *out = in->handle(); diff --git a/src/torus.cpp b/src/torus.cpp index bd0a63b..b5f0275 100644 --- a/src/torus.cpp +++ b/src/torus.cpp @@ -53,7 +53,7 @@ xmlDoc *mp::get_searchable(mp::Package &package, Z_HTTP_Header *http_headers = 0; mp::odr odr; - + z_HTTP_header_add(odr, &http_headers, "Accept","application/xml"); yaz_url_t url_p = yaz_url_create(); @@ -67,13 +67,13 @@ xmlDoc *mp::get_searchable(mp::Package &package, 0, /* content buf */ 0 /* content_len */ ); - if (http_response && http_response->code == 200 && + if (http_response && http_response->code == 200 && http_response->content_buf) { package.log("zoom", YLOG_LOG, "Torus: %s OK", url_template.c_str()); doc = xmlParseMemory(http_response->content_buf, http_response->content_len); - + } else { diff --git a/src/url_recipe.cpp b/src/url_recipe.cpp index b514f7c..c6e4f86 100644 --- a/src/url_recipe.cpp +++ b/src/url_recipe.cpp @@ -73,7 +73,7 @@ std::string mp_xml::url_recipe_handle(xmlDoc *doc, std::string recipe) int c_check = c; if (c_prev == '\\') c_check = 0; - + if (c_check == '}') step = 5; else if (step == 0) diff --git a/src/util.cpp b/src/util.cpp index 97b1125..245bf47 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -34,14 +34,14 @@ namespace mp = metaproxy_1; // Doxygen doesn't like mp::util, so we use this instead namespace mp_util = metaproxy_1::util; -const char * +const char * mp_util::record_composition_to_esn(Z_RecordComposition *comp) { if (comp && comp->which == Z_RecordComp_complex) { - if (comp->u.complex->generic + if (comp->u.complex->generic && comp->u.complex->generic->elementSpec - && (comp->u.complex->generic->elementSpec->which == + && (comp->u.complex->generic->elementSpec->which == Z_ElementSpec_elementSetName)) return comp->u.complex->generic->elementSpec->u.elementSetName; } @@ -53,26 +53,26 @@ mp_util::record_composition_to_esn(Z_RecordComposition *comp) -std::string mp_util::http_header_value(const Z_HTTP_Header* header, +std::string mp_util::http_header_value(const Z_HTTP_Header* header, const std::string name) { while (header && header->name && std::string(header->name) != name) header = header->next; - + if (header && header->name && std::string(header->name) == name && header->value) return std::string(header->value); - + return std::string(); } - + std::string mp_util::http_headers_debug(const Z_HTTP_Request &http_req) { std::string message("\n\n

" "Metaproxy SRUtoZ3950 filter" "

\n"); - + message += "

HTTP Info


\n"; message += "

\n"; message += "Method: " + std::string(http_req.method) + "
\n"; @@ -85,43 +85,43 @@ std::string mp_util::http_headers_debug(const Z_HTTP_Request &http_req) message += "Content-Length:" + mp_util::http_header_value(http_req.headers, "Content-Length") + "
\n"; - message += "

\n"; - + message += "

\n"; + message += "

Headers


\n"; - message += "

\n"; + message += "

\n"; Z_HTTP_Header* header = http_req.headers; while (header){ - message += "Header: " + message += "Header: " + std::string(header->name) + ": " + std::string(header->value) + "
\n"; header = header->next; } - message += "

\n"; + message += "

\n"; message += "\n\n"; return message; } -void mp_util::http_response(metaproxy_1::Package &package, - const std::string &content, +void mp_util::http_response(metaproxy_1::Package &package, + const std::string &content, int http_code) { - Z_GDU *zgdu_req = package.request().get(); - Z_GDU *zgdu_res = 0; + Z_GDU *zgdu_req = package.request().get(); + Z_GDU *zgdu_res = 0; mp::odr odr; - zgdu_res - = odr.create_HTTP_Response(package.session(), - zgdu_req->u.HTTP_Request, + zgdu_res + = odr.create_HTTP_Response(package.session(), + zgdu_req->u.HTTP_Request, http_code); - + zgdu_res->u.HTTP_Response->content_len = content.size(); - zgdu_res->u.HTTP_Response->content_buf + zgdu_res->u.HTTP_Response->content_buf = (char*) odr_malloc(odr, zgdu_res->u.HTTP_Response->content_len); - - strncpy(zgdu_res->u.HTTP_Response->content_buf, + + strncpy(zgdu_res->u.HTTP_Response->content_buf, content.c_str(), zgdu_res->u.HTTP_Response->content_len); - + //z_HTTP_header_add(odr, &hres->headers, // "Content-Type", content_type.c_str()); package.response() = zgdu_res; @@ -139,7 +139,7 @@ int mp_util::memcmp2(const void *buf1, int len1, return 1; else if (c < 0) return -1; - + // compare (remaining bytes) if (d > 0) return 1; @@ -219,7 +219,7 @@ void mp_util::piggyback(Odr_int smallSetUpperBound, number_to_present = result_set_size; if (element_set_name && smallSetElementSetNames) *element_set_name = smallSetElementSetNames; - + } else if (result_set_size > largeSetLowerBound) { @@ -242,7 +242,7 @@ void mp_util::piggyback(Odr_int smallSetUpperBound, bool mp_util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) { YAZ_PQF_Parser pqf_parser = yaz_pqf_create(); - + Z_RPNQuery *rpn = yaz_pqf_parse(pqf_parser, odr, q.c_str()); if (!rpn) { @@ -253,7 +253,7 @@ bool mp_util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) Z_Query *query = (Z_Query *) odr_malloc(odr, sizeof(Z_Query)); query->which = Z_Query_type_1; query->u.type_1 = rpn; - + apdu->u.searchRequest->query = query; return true; } @@ -266,14 +266,14 @@ std::string mp_util::zQueryToString(Z_Query *query) if (query && query->which == Z_Query_type_1) { Z_RPNQuery *rpn = query->u.type_1; - + if (rpn) { mp::wrbuf w; - + // put query in w yaz_rpnquery_to_wrbuf(w, rpn); - + // from w to std::string query_str = std::string(w.buf(), w.len()); } @@ -281,19 +281,19 @@ std::string mp_util::zQueryToString(Z_Query *query) #if 0 if (query && query->which == Z_Query_type_1){ - + // allocate wrbuf (strings in YAZ!) WRBUF w = wrbuf_alloc(); - + // put query in w yaz_query_to_wrbuf(w, query); - + // from w to std::string query_str = std::string(wrbuf_buf(w), wrbuf_len(w)); - + // destroy wrbuf wrbuf_free(w, 1); - } + } #endif return query_str; } @@ -317,7 +317,7 @@ void mp_util::get_init_diagnostics( Z_InitResponse *initrs, int &error_code, std::string &addinfo) { Z_External *uif = initrs->userInformationField; - + if (uif && uif->which == Z_External_userInfo1) { Z_OtherInformation *ui = uif->u.userInfo1; @@ -328,9 +328,9 @@ void mp_util::get_init_diagnostics( if (unit->which == Z_OtherInfo_externallyDefinedInfo && unit->information.externallyDefinedInfo && unit->information.externallyDefinedInfo->which == - Z_External_diag1) + Z_External_diag1) { - Z_DiagnosticFormat *diag = + Z_DiagnosticFormat *diag = unit->information.externallyDefinedInfo->u.diag1; if (diag->num > 0) @@ -340,7 +340,7 @@ void mp_util::get_init_diagnostics( mp::util::get_default_diag(ds->u.defaultDiagRec, error_code, addinfo); } - } + } } } } @@ -411,7 +411,7 @@ void mp_util::split_zurl(std::string zurl, std::string &host, cs_get_host_args(zurl_cstr, &args); if (args && *args) - { + { host = std::string(zurl_cstr, args - zurl_cstr); const char *cp1 = args; @@ -440,7 +440,7 @@ bool mp_util::set_databases_from_zurl( std::list dblist; split_zurl(zurl, host, dblist); - + if (dblist.size() == 0) return false; *db_num = dblist.size(); @@ -476,7 +476,7 @@ Z_APDU *mp::odr::create_close(const Z_APDU *in_apdu, int reason, const char *addinfo) { Z_APDU *apdu = create_APDU(Z_APDU_close, in_apdu); - + *apdu->u.close->closeReason = reason; if (addinfo) apdu->u.close->diagnosticInformation = odr_strdup(m_odr, addinfo); @@ -527,10 +527,10 @@ Z_APDU *mp::odr::create_initResponse(const Z_APDU *in_apdu, apdu->u.initResponse->implementationName = odr_prepend(m_odr, "Metaproxy", apdu->u.initResponse->implementationName); - apdu->u.initResponse->implementationVersion = + apdu->u.initResponse->implementationVersion = odr_prepend(m_odr, VERSION, apdu->u.initResponse->implementationVersion); - + return apdu; } @@ -546,7 +546,7 @@ Z_APDU *mp::odr::create_searchResponse(const Z_APDU *in_apdu, rec->which = Z_Records_NSD; rec->u.nonSurrogateDiagnostic = zget_DefaultDiagFormat(m_odr, error, addinfo); - + } return apdu; } @@ -559,7 +559,7 @@ Z_APDU *mp::odr::create_presentResponse(const Z_APDU *in_apdu, { Z_Records *rec = (Z_Records *) odr_malloc(m_odr, sizeof(Z_Records)); apdu->u.presentResponse->records = rec; - + rec->which = Z_Records_NSD; rec->u.nonSurrogateDiagnostic = zget_DefaultDiagFormat(m_odr, error, addinfo); @@ -584,7 +584,7 @@ Z_APDU *mp::odr::create_scanResponse(const Z_APDU *in_apdu, res->entries->num_nonsurrogateDiagnostics = 1; res->entries->nonsurrogateDiagnostics = (Z_DiagRec **) odr_malloc(m_odr, sizeof(Z_DiagRec *)); - res->entries->nonsurrogateDiagnostics[0] = + res->entries->nonsurrogateDiagnostics[0] = zget_DiagRec(m_odr, error, addinfo); } else @@ -600,7 +600,7 @@ Z_GDU *mp::odr::create_HTTP_Response(mp::Session &session, { const char *response_version = "1.0"; bool keepalive = false; - if (!strcmp(hreq->version, "1.0")) + if (!strcmp(hreq->version, "1.0")) { const char *v = z_HTTP_header_lookup(hreq->headers, "Connection"); if (v && !strcmp(v, "Keep-Alive")) @@ -624,7 +624,7 @@ Z_GDU *mp::odr::create_HTTP_Response(mp::Session &session, hres->version = odr_strdup(m_odr, response_version); if (keepalive) z_HTTP_header_add(m_odr, &hres->headers, "Connection", "Keep-Alive"); - + return gdu; } @@ -633,7 +633,7 @@ Z_ReferenceId **mp_util::get_referenceId(const Z_APDU *apdu) switch (apdu->which) { case Z_APDU_initRequest: - return &apdu->u.initRequest->referenceId; + return &apdu->u.initRequest->referenceId; case Z_APDU_initResponse: return &apdu->u.initResponse->referenceId; case Z_APDU_searchRequest: diff --git a/src/xmlutil.cpp b/src/xmlutil.cpp index c59f506..f48868c 100644 --- a/src/xmlutil.cpp +++ b/src/xmlutil.cpp @@ -60,7 +60,7 @@ bool mp_xml::get_bool(const xmlNode *ptr, bool default_value) } int mp_xml::get_int(const xmlNode *ptr, int default_value) -{ +{ if (ptr && ptr->type != XML_TEXT_NODE) ptr = ptr->children; if (ptr && ptr->type == XML_TEXT_NODE && ptr->content) @@ -70,13 +70,13 @@ int mp_xml::get_int(const xmlNode *ptr, int default_value) return default_value; } -bool mp_xml::check_attribute(const _xmlAttr *ptr, +bool mp_xml::check_attribute(const _xmlAttr *ptr, const std::string &ns, const std::string &name) { if (!mp::xml::is_attribute(ptr, ns, name)) - { + { std::string got_attr = "'"; if (ptr && ptr->name) got_attr += std::string((const char *)ptr->name); @@ -85,23 +85,23 @@ bool mp_xml::check_attribute(const _xmlAttr *ptr, got_attr += std::string((const char *)ptr->ns->href); } got_attr += "'"; - - throw mp::XMLError("Expected XML attribute '" + name + + throw mp::XMLError("Expected XML attribute '" + name + " " + ns + "'" + ", not " + got_attr); } return true; } -bool mp_xml::is_attribute(const _xmlAttr *ptr, +bool mp_xml::is_attribute(const _xmlAttr *ptr, const std::string &ns, const std::string &name) { if (0 != xmlStrcmp(BAD_CAST name.c_str(), ptr->name)) return false; - if (ns.size() - && (!ptr->ns || !ptr->ns->href + if (ns.size() + && (!ptr->ns || !ptr->ns->href || 0 != xmlStrcmp(BAD_CAST ns.c_str(), ptr->ns->href))) return false; @@ -109,25 +109,25 @@ bool mp_xml::is_attribute(const _xmlAttr *ptr, } -bool mp_xml::is_element(const xmlNode *ptr, +bool mp_xml::is_element(const xmlNode *ptr, const std::string &ns, const std::string &name) { - if (ptr && ptr->type == XML_ELEMENT_NODE && ptr->ns && ptr->ns->href + if (ptr && ptr->type == XML_ELEMENT_NODE && ptr->ns && ptr->ns->href && !xmlStrcmp(BAD_CAST ns.c_str(), ptr->ns->href) && !xmlStrcmp(BAD_CAST name.c_str(), ptr->name)) return true; return false; } -bool mp_xml::is_element_mp(const xmlNode *ptr, +bool mp_xml::is_element_mp(const xmlNode *ptr, const std::string &name) { return mp::xml::is_element(ptr, metaproxy_ns, name); } -bool mp_xml::check_element_mp(const xmlNode *ptr, +bool mp_xml::check_element_mp(const xmlNode *ptr, const std::string &name) { if (!mp::xml::is_element_mp(ptr, name)) @@ -142,7 +142,7 @@ bool mp_xml::check_element_mp(const xmlNode *ptr, } got_element += ">"; - throw mp::XMLError("Expected XML element <" + name + throw mp::XMLError("Expected XML element <" + name + " xmlns=\"" + metaproxy_ns + "\">" + ", not " + got_element); } @@ -159,10 +159,10 @@ std::string mp_xml::get_route(const xmlNode *node, std::string &auth) { std::string name = std::string((const char *) attr->name); std::string value; - + if (attr->children && attr->children->type == XML_TEXT_NODE) value = std::string((const char *)attr->children->content); - + if (name == "route") route_value = value; else if (name == "auth") -- 1.7.10.4