From 34b33150854c015d84bcec7d85b808387cc74d67 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 5 Jul 2013 12:32:14 +0200 Subject: [PATCH] Refactor content parse to Content::parse --- src/filter_http_rewrite.cpp | 48 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/filter_http_rewrite.cpp b/src/filter_http_rewrite.cpp index 9a5c791..501c87e 100644 --- a/src/filter_http_rewrite.cpp +++ b/src/filter_http_rewrite.cpp @@ -75,6 +75,8 @@ namespace metaproxy_1 { std::map &rules); void quoted_literal(std::string &content, std::map &vars) const; + void parse(int verbose, std::string &content, + std::map & vars) const; }; class HttpRewrite::Phase { public: @@ -272,27 +274,10 @@ void yf::HttpRewrite::Phase::rewrite_body( if ((*content_buf)[i] == 0) return; // binary content. skip - if (cit->type == "html") - { - HTMLParser parser; - Event ev(&*cit, vars); - - parser.set_verbose(m_verbose); - - std::string buf(*content_buf, *content_len); - - parser.parse(ev, buf.c_str()); - const char *res = ev.result(); - *content_buf = odr_strdup(o, res); - *content_len = strlen(res); - } - if (cit->type == "quoted-literal") - { - std::string content(*content_buf, *content_len); - cit->quoted_literal(content, vars); - *content_buf = odr_strdup(o, content.c_str()); - *content_len = strlen(*content_buf); - } + std::string content(*content_buf, *content_len); + cit->parse(m_verbose, content, vars); + *content_buf = odr_strdup(o, content.c_str()); + *content_len = strlen(*content_buf); } } @@ -612,6 +597,27 @@ yf::HttpRewrite::Phase::Phase() : m_verbose(0) { } +void yf::HttpRewrite::Content::parse( + int verbose, + std::string &content, + std::map &vars) const +{ + if (type == "html") + { + HTMLParser parser; + Event ev(this, vars); + + parser.set_verbose(verbose); + + parser.parse(ev, content.c_str()); + content = ev.result(); + } + if (type == "quoted-literal") + { + quoted_literal(content, vars); + } +} + void yf::HttpRewrite::Content::quoted_literal( std::string &content, std::map &vars) const -- 1.7.10.4