X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;ds=sidebyside;f=src%2Futil.cpp;h=1ea62d3bf05106ba4581f3ab883d3f5fa311746c;hb=HEAD;hp=aef7caa77d78264ffc95e7869f96846cb908acbc;hpb=8ff69c27be66eb65b0b5fd6afa4de1a3556d7344;p=metaproxy-moved-to-github.git diff --git a/src/util.cpp b/src/util.cpp index aef7caa..1ea62d3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2013 Index Data + Copyright (C) Index Data Metaproxy is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -26,6 +26,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include + +#include #include @@ -500,15 +503,9 @@ void mp_util::transfer_referenceId(ODR odr, const Z_APDU *src, Z_APDU *dst) if (src) { Z_ReferenceId **id_from = mp::util::get_referenceId(src); - if (id_from && *id_from && id_to) - { - *id_to = (Z_ReferenceId*) odr_malloc (odr, sizeof(**id_to)); - (*id_to)->size = (*id_to)->len = (*id_from)->len; - (*id_to)->buf = (unsigned char*) odr_malloc(odr, (*id_to)->len); - memcpy((*id_to)->buf, (*id_from)->buf, (*id_to)->len); - } - else if (id_to) - *id_to = 0; + if (id_from && *id_from) + *id_to = odr_create_Odr_oct(odr, (*id_from)->buf, + (*id_from)->len); } } @@ -618,12 +615,13 @@ Z_GDU *mp::odr::create_HTTP_Response_details(mp::Session &session, response_version = "1.1"; } - Z_GDU *gdu = z_get_HTTP_Response_details(m_odr, code, details); + Z_GDU *gdu = z_get_HTTP_Response_server( + m_odr, code, details, "Metaproxy/" VERSION, + "http://www.indexdata.com/metaproxy"); Z_HTTP_Response *hres = gdu->u.HTTP_Response; hres->version = odr_strdup(m_odr, response_version); if (keepalive) z_HTTP_header_add(m_odr, &hres->headers, "Connection", "Keep-Alive"); - return gdu; } @@ -732,6 +730,36 @@ const char *mp::wrbuf::buf() return wrbuf_buf(m_wrbuf); } +const char *mp::wrbuf::c_str() +{ + return wrbuf_cstr(m_wrbuf); +} + +const char *mp::wrbuf::c_str_null() +{ + return wrbuf_cstr_null(m_wrbuf); +} + +bool mp::util::match_ip(const std::string &pattern, const std::string &value) +{ + std::vector globitems; + // split may produce empty strings as results - in particular + // the empty pattern produces one empty string (vector size 1) + boost::split(globitems, pattern, boost::is_any_of(" ")); + bool ret_value = true; // for now (if only empty values) + std::vector::const_iterator it = globitems.begin(); + for (; it != globitems.end(); it++) + { + const char *c_str = (*it).c_str(); + if (*c_str) + { + ret_value = false; // at least one non-empty value + if (yaz_match_glob(c_str, value.c_str())) + return true; + } + } + return ret_value; +} /* * Local variables: