From 41ddc790e888e2b0cfe5da66a34e26e737e20b54 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 27 Jun 2013 11:50:23 +0200 Subject: [PATCH] Only do CDATA for attr="#text", verbose flag --- src/filter_http_rewrite.cpp | 27 ++++++++++++++++++++++++++- src/test_filter_rewrite.cpp | 9 +++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/filter_http_rewrite.cpp b/src/filter_http_rewrite.cpp index e69aba6..90e3152 100644 --- a/src/filter_http_rewrite.cpp +++ b/src/filter_http_rewrite.cpp @@ -68,7 +68,9 @@ namespace metaproxy_1 { class HttpRewrite::Phase { public: + Phase(); std::list within_list; + int m_verbose; void rewrite_reqline(mp::odr & o, Z_HTTP_Request *hreq, std::map & vars) const; void rewrite_headers(mp::odr & o, Z_HTTP_Header *headers, @@ -225,6 +227,9 @@ void yf::HttpRewrite::Phase::rewrite_body(mp::odr & o, HTMLParser parser; Event ev(this, vars); + + parser.set_verbose(m_verbose); + std::string buf(*content_buf, *content_len); parser.parse(ev, buf.c_str()); @@ -265,7 +270,17 @@ void yf::HttpRewrite::Event::openTagStart(const char *tag, int tag_len) if (it->tag.length() > 0 && yaz_strcasecmp(it->tag.c_str(), t.c_str()) == 0) { - enabled_within = it; + std::vector attr; + boost::split(attr, it->attr, boost::is_any_of(",")); + size_t i; + for (i = 0; i < attr.size(); i++) + { + if (attr[i].compare("#text") == 0) + { + enabled_within = it; + break; + } + } } } } @@ -560,9 +575,19 @@ std::string yf::HttpRewrite::Replace::sub_vars ( return out; } +yf::HttpRewrite::Phase::Phase() : m_verbose(0) +{ +} void yf::HttpRewrite::configure_phase(const xmlNode *ptr, Phase &phase) { + static const char *names[2] = { "verbose", 0 }; + std::string values[1]; + values[0] = "0"; + mp::xml::parse_attr(ptr, names, values); + + phase.m_verbose = atoi(values[0].c_str()); + std::map rules; for (ptr = ptr->children; ptr; ptr = ptr->next) { diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index 65cb4c0..2e4ae54 100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) "\n" "\n" - " \n" + " \n" " \n" " \n" " \n" " \n" " \n" - " \n" - " \n" + " \n" + " \n" + " \n" " \n" " \n" "\n" -- 1.7.10.4