From: Adam Dickmeiss Date: Fri, 9 Jun 2006 14:12:13 +0000 (+0000) Subject: Move memcmp2 to util. Change use of namespaces a little because Doxygen X-Git-Tag: METAPROXY.1.0.6~27 X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=9dec54edaf1536d72030e95123c77040fc951185;p=metaproxy-moved-to-github.git Move memcmp2 to util. Change use of namespaces a little because Doxygen gets confused otherwise. --- diff --git a/src/filter_session_shared.cpp b/src/filter_session_shared.cpp index f25ab3c..151fe77 100644 --- a/src/filter_session_shared.cpp +++ b/src/filter_session_shared.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_session_shared.cpp,v 1.9 2006-05-16 11:53:54 adam Exp $ +/* $Id: filter_session_shared.cpp,v 1.10 2006-06-09 14:12:13 adam Exp $ Copyright (c) 2005-2006, Index Data. %LICENSE% @@ -25,12 +25,11 @@ #include namespace mp = metaproxy_1; -namespace yf = mp::filter; +namespace yf = metaproxy_1::filter; namespace metaproxy_1 { namespace filter { - int memcmp2(const void *buf1, int len1, const void *buf2, int len2); class SessionShared::InitKey { public: @@ -76,25 +75,6 @@ namespace metaproxy_1 { } } -int yf::memcmp2(const void *buf1, int len1, - const void *buf2, int len2) -{ - int d = len1 - len2; - - // compare buffer (common length) - int c = memcmp(buf1, buf2, d > 0 ? len2 : len1); - if (c > 0) - return 1; - else if (c < 0) - return -1; - - // compare (remaining bytes) - if (d > 0) - return 1; - else if (d < 0) - return -1; - return 0; -} yf::SessionShared::InitKey::InitKey(Z_InitRequest *req) { @@ -113,15 +93,16 @@ bool yf::SessionShared::InitKey::operator < (const SessionShared::InitKey &k) const { int c; - c = memcmp2((void*) m_idAuthentication_buf, m_idAuthentication_size, - (void*) k.m_idAuthentication_buf, k.m_idAuthentication_size); + c = mp::util::memcmp2( + (void*) m_idAuthentication_buf, m_idAuthentication_size, + (void*) k.m_idAuthentication_buf, k.m_idAuthentication_size); if (c < 0) return true; else if (c > 0) return false; - c = memcmp2((void*) m_otherInfo_buf, m_otherInfo_size, - (void*) k.m_otherInfo_buf, k.m_otherInfo_size); + c = mp::util::memcmp2((void*) m_otherInfo_buf, m_otherInfo_size, + (void*) k.m_otherInfo_buf, k.m_otherInfo_size); if (c < 0) return true; else if (c > 0) @@ -137,12 +118,14 @@ void yf::SessionShared::Frontend::init(mp::Package &package, Z_GDU *gdu) mp::util::get_vhost_otherinfo(&req->otherInfo, false, targets); + // std::cout << "SessionShared::Frontend::init\n"; if (targets.size() < 1) { + // no targets given, just relay this one and don't deal with it package.move(); return; } - + InitKey k(req); } yf::SessionShared::SessionShared() : m_p(new SessionShared::Rep) diff --git a/src/thread_pool_observer.cpp b/src/thread_pool_observer.cpp index e87090c..061ec8f 100644 --- a/src/thread_pool_observer.cpp +++ b/src/thread_pool_observer.cpp @@ -1,5 +1,5 @@ -/* $Id: thread_pool_observer.cpp,v 1.15 2006-03-29 13:44:45 adam Exp $ +/* $Id: thread_pool_observer.cpp,v 1.16 2006-06-09 14:12:13 adam Exp $ Copyright (c) 2005-2006, Index Data. %LICENSE% @@ -32,8 +32,6 @@ #include "thread_pool_observer.hpp" #include "pipe.hpp" -namespace mp = metaproxy_1; - namespace metaproxy_1 { class ThreadPoolSocketObserver::Worker { public: @@ -65,9 +63,9 @@ namespace metaproxy_1 { using namespace yazpp_1; -using namespace mp; +using namespace metaproxy_1; -ThreadPoolSocketObserver::Rep::Rep(ISocketObservable *obs) +ThreadPoolSocketObserver::Rep::Rep(yazpp_1::ISocketObservable *obs) : m_socketObservable(obs), m_pipe(9123) { } @@ -81,8 +79,8 @@ IThreadPoolMsg::~IThreadPoolMsg() } -ThreadPoolSocketObserver::ThreadPoolSocketObserver(ISocketObservable *obs, - int no_threads) +ThreadPoolSocketObserver::ThreadPoolSocketObserver( + yazpp_1::ISocketObservable *obs, int no_threads) : m_p(new Rep(obs)) { obs->addObserver(m_p->m_pipe.read_fd(), this); diff --git a/src/util.cpp b/src/util.cpp index b2a70c5..941effc 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,4 +1,4 @@ -/* $Id: util.cpp,v 1.15 2006-05-15 11:43:01 adam Exp $ +/* $Id: util.cpp,v 1.16 2006-06-09 14:12:13 adam Exp $ Copyright (c) 2005-2006, Index Data. %LICENSE% @@ -16,7 +16,31 @@ namespace mp = metaproxy_1; -std::string mp::util::database_name_normalize(const std::string &s) +// Doxygen doesn't like mp::util, so we use this instead +namespace mp_util = metaproxy_1::util; + +int mp_util::memcmp2(const void *buf1, int len1, + const void *buf2, int len2) +{ + int d = len1 - len2; + + // compare buffer (common length) + int c = memcmp(buf1, buf2, d > 0 ? len2 : len1); + if (c > 0) + return 1; + else if (c < 0) + return -1; + + // compare (remaining bytes) + if (d > 0) + return 1; + else if (d < 0) + return -1; + return 0; +} + + +std::string mp_util::database_name_normalize(const std::string &s) { std::string r = s; size_t i; @@ -30,11 +54,11 @@ std::string mp::util::database_name_normalize(const std::string &s) } -void mp::util::piggyback(int smallSetUpperBound, - int largeSetLowerBound, - int mediumSetPresentNumber, - int result_set_size, - int &number_to_present) +void mp_util::piggyback(int smallSetUpperBound, + int largeSetLowerBound, + int mediumSetPresentNumber, + int result_set_size, + int &number_to_present) { // deal with piggyback @@ -58,7 +82,8 @@ void mp::util::piggyback(int smallSetUpperBound, } -bool mp::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) { +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()); @@ -77,7 +102,7 @@ bool mp::util::pqf(ODR odr, Z_APDU *apdu, const std::string &q) { } -std::string mp::util::zQueryToString(Z_Query *query) +std::string mp_util::zQueryToString(Z_Query *query) { std::string query_str = ""; @@ -119,8 +144,8 @@ std::string mp::util::zQueryToString(Z_Query *query) return query_str; } -void mp::util::get_default_diag(Z_DefaultDiagFormat *r, - int &error_code, std::string &addinfo) +void mp_util::get_default_diag(Z_DefaultDiagFormat *r, + int &error_code, std::string &addinfo) { error_code = *r->condition; switch (r->which) @@ -134,8 +159,8 @@ void mp::util::get_default_diag(Z_DefaultDiagFormat *r, } } -void mp::util::get_init_diagnostics(Z_InitResponse *initrs, - int &error_code, std::string &addinfo) +void mp_util::get_init_diagnostics( + Z_InitResponse *initrs, int &error_code, std::string &addinfo) { Z_External *uif = initrs->userInformationField; @@ -166,9 +191,10 @@ void mp::util::get_init_diagnostics(Z_InitResponse *initrs, } } -int mp::util::get_vhost_otherinfo(Z_OtherInformation **otherInformation, - bool remove_flag, - std::list &vhosts) +int mp_util::get_vhost_otherinfo( + Z_OtherInformation **otherInformation, + bool remove_flag, + std::list &vhosts) { int cat; for (cat = 1; ; cat++) @@ -187,9 +213,9 @@ int mp::util::get_vhost_otherinfo(Z_OtherInformation **otherInformation, return cat; } -void mp::util::set_vhost_otherinfo(Z_OtherInformation **otherInformation, - ODR odr, - const std::list &vhosts) +void mp_util::set_vhost_otherinfo( + Z_OtherInformation **otherInformation, ODR odr, + const std::list &vhosts) { int cat; std::list::const_iterator it = vhosts.begin(); @@ -200,8 +226,8 @@ void mp::util::set_vhost_otherinfo(Z_OtherInformation **otherInformation, } } -void mp::util::split_zurl(std::string zurl, std::string &host, - std::list &db) +void mp_util::split_zurl(std::string zurl, std::string &host, + std::list &db) { const char *zurl_cstr = zurl.c_str(); const char *sep = strchr(zurl_cstr, '/'); @@ -230,8 +256,9 @@ void mp::util::split_zurl(std::string zurl, std::string &host, } } -bool mp::util::set_databases_from_zurl(ODR odr, std::string zurl, - int *db_num, char ***db_strings) +bool mp_util::set_databases_from_zurl( + ODR odr, std::string zurl, + int *db_num, char ***db_strings) { std::string host; std::list dblist; @@ -285,7 +312,7 @@ Z_APDU *mp::odr::create_APDU(int type, Z_APDU *in_apdu) return mp::util::create_APDU(m_odr, type, in_apdu); } -Z_APDU *mp::util::create_APDU(ODR odr, int type, Z_APDU *in_apdu) +Z_APDU *mp_util::create_APDU(ODR odr, int type, Z_APDU *in_apdu) { Z_APDU *out_apdu = zget_APDU(odr, type); @@ -414,7 +441,7 @@ Z_GDU *mp::odr::create_HTTP_Response(mp::Session &session, return gdu; } -Z_ReferenceId **mp::util::get_referenceId(Z_APDU *apdu) +Z_ReferenceId **mp_util::get_referenceId(Z_APDU *apdu) { switch (apdu->which) { diff --git a/src/util.hpp b/src/util.hpp index f60e818..3a32cc9 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -1,4 +1,4 @@ -/* $Id: util.hpp,v 1.14 2006-05-15 11:43:01 adam Exp $ +/* $Id: util.hpp,v 1.15 2006-06-09 14:12:13 adam Exp $ Copyright (c) 2005-2006, Index Data. %LICENSE% @@ -18,6 +18,8 @@ namespace metaproxy_1 { namespace util { + int memcmp2(const void *buf1, int len1, const void *buf2, int len2); + std::string database_name_normalize(const std::string &s); bool pqf(ODR odr, Z_APDU *apdu, const std::string &q); diff --git a/src/xmlutil.cpp b/src/xmlutil.cpp index d1088e7..5c95d83 100644 --- a/src/xmlutil.cpp +++ b/src/xmlutil.cpp @@ -1,4 +1,4 @@ -/* $Id: xmlutil.cpp,v 1.5 2006-03-16 10:40:59 adam Exp $ +/* $Id: xmlutil.cpp,v 1.6 2006-06-09 14:12:13 adam Exp $ Copyright (c) 2005-2006, Index Data. %LICENSE% @@ -7,8 +7,10 @@ #include "xmlutil.hpp" namespace mp = metaproxy_1; +// Doxygen doesn't like mp::xml, so we use this instead +namespace mp_xml = metaproxy_1::xml; -std::string mp::xml::get_text(const xmlNode *ptr) +std::string mp_xml::get_text(const xmlNode *ptr) { std::string c; for (ptr = ptr->children; ptr; ptr = ptr->next) @@ -18,7 +20,7 @@ std::string mp::xml::get_text(const xmlNode *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) { @@ -29,14 +31,14 @@ bool mp::xml::is_element(const xmlNode *ptr, return false; } -bool mp::xml::is_element_yp2(const xmlNode *ptr, +bool mp_xml::is_element_yp2(const xmlNode *ptr, const std::string &name) { return mp::xml::is_element(ptr, "http://indexdata.dk/yp2/config/1", name); } -bool mp::xml::check_element_yp2(const xmlNode *ptr, +bool mp_xml::check_element_yp2(const xmlNode *ptr, const std::string &name) { if (!mp::xml::is_element_yp2(ptr, name)) @@ -44,7 +46,7 @@ bool mp::xml::check_element_yp2(const xmlNode *ptr, return true; } -std::string mp::xml::get_route(const xmlNode *node) +std::string mp_xml::get_route(const xmlNode *node) { std::string route_value; if (node) @@ -70,7 +72,7 @@ std::string mp::xml::get_route(const xmlNode *node) } -const xmlNode* mp::xml::jump_to_children(const xmlNode* node, +const xmlNode* mp_xml::jump_to_children(const xmlNode* node, int xml_node_type) { node = node->children; @@ -79,7 +81,7 @@ const xmlNode* mp::xml::jump_to_children(const xmlNode* node, return node; } -const xmlNode* mp::xml::jump_to_next(const xmlNode* node, +const xmlNode* mp_xml::jump_to_next(const xmlNode* node, int xml_node_type) { node = node->next; @@ -88,7 +90,7 @@ const xmlNode* mp::xml::jump_to_next(const xmlNode* node, return node; } -const xmlNode* mp::xml::jump_to(const xmlNode* node, +const xmlNode* mp_xml::jump_to(const xmlNode* node, int xml_node_type) { for (; node && node->type != xml_node_type; node = node->next) @@ -96,7 +98,7 @@ const xmlNode* mp::xml::jump_to(const xmlNode* node, return node; } -void mp::xml::check_empty(const xmlNode *node) +void mp_xml::check_empty(const xmlNode *node) { if (node) {