X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_http_rewrite.cpp;h=3adc7db8503975cfc3a2ba8b56335adc11d6f69c;hb=4a14f732154658bbd097d833089f968d77568ebd;hp=3fd5fc2c51c3c3feb5b94c3fdc8583194bf4317b;hpb=3ea5cbf51b66f787daac04cd6c625c217e09080e;p=metaproxy-moved-to-github.git diff --git a/src/filter_http_rewrite.cpp b/src/filter_http_rewrite.cpp index 3fd5fc2..3adc7db 100644 --- a/src/filter_http_rewrite.cpp +++ b/src/filter_http_rewrite.cpp @@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include "filter_http_rewrite.hpp" +#include "html_parser.hpp" #include #include @@ -30,10 +31,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include -#if HAVE_SYS_TYPES_H -#include -#endif - namespace mp = metaproxy_1; namespace yf = mp::filter; @@ -67,7 +64,7 @@ namespace metaproxy_1 { RulePtr rule; }; - class HttpRewrite::Section { + class HttpRewrite::Phase : public HTMLParserEvent { public: std::list within_list; void rewrite_reqline(mp::odr & o, Z_HTTP_Request *hreq, @@ -77,12 +74,20 @@ namespace metaproxy_1 { void rewrite_body(mp::odr & o, char **content_buf, int *content_len, std::map & vars) const; + void openTagStart(const char *name); + void anyTagEnd(const char *name); + void attribute(const char *tagName, + const char *name, + const char *value, + int val_len); + void closeTag(const char *name); + void text(const char *value, int len); }; } } yf::HttpRewrite::HttpRewrite() : - req_section(new Section), res_section(new Section) + req_phase(new Phase), res_phase(new Phase) { } @@ -101,10 +106,10 @@ void yf::HttpRewrite::process(mp::Package & package) const { Z_HTTP_Request *hreq = gdu->u.HTTP_Request; mp::odr o; - req_section->rewrite_reqline(o, hreq, vars); + req_phase->rewrite_reqline(o, hreq, vars); yaz_log(YLOG_LOG, ">> Request headers"); - req_section->rewrite_headers(o, hreq->headers, vars); - req_section->rewrite_body(o, + req_phase->rewrite_headers(o, hreq->headers, vars); + req_phase->rewrite_body(o, &hreq->content_buf, &hreq->content_len, vars); package.request() = gdu; } @@ -116,14 +121,14 @@ void yf::HttpRewrite::process(mp::Package & package) const yaz_log(YLOG_LOG, "Response code %d", hres->code); mp::odr o; yaz_log(YLOG_LOG, "<< Respose headers"); - res_section->rewrite_headers(o, hres->headers, vars); - res_section->rewrite_body(o, &hres->content_buf, + res_phase->rewrite_headers(o, hres->headers, vars); + res_phase->rewrite_body(o, &hres->content_buf, &hres->content_len, vars); package.response() = gdu; } } -void yf::HttpRewrite::Section::rewrite_reqline (mp::odr & o, +void yf::HttpRewrite::Phase::rewrite_reqline (mp::odr & o, Z_HTTP_Request *hreq, std::map & vars) const { @@ -158,7 +163,7 @@ void yf::HttpRewrite::Section::rewrite_reqline (mp::odr & o, } } -void yf::HttpRewrite::Section::rewrite_headers(mp::odr & o, +void yf::HttpRewrite::Phase::rewrite_headers(mp::odr & o, Z_HTTP_Header *headers, std::map & vars) const { @@ -192,7 +197,7 @@ void yf::HttpRewrite::Section::rewrite_headers(mp::odr & o, } } -void yf::HttpRewrite::Section::rewrite_body(mp::odr & o, +void yf::HttpRewrite::Phase::rewrite_body(mp::odr & o, char **content_buf, int *content_len, std::map & vars) const @@ -216,6 +221,32 @@ void yf::HttpRewrite::Section::rewrite_body(mp::odr & o, } } + +void yf::HttpRewrite::Phase::openTagStart(const char *name) +{ +} + +void yf::HttpRewrite::Phase::anyTagEnd(const char *name) +{ +} + +void yf::HttpRewrite::Phase::attribute(const char *tagName, + const char *name, + const char *value, + int val_len) +{ +} + + +void yf::HttpRewrite::Phase::closeTag(const char *name) +{ +} + +void yf::HttpRewrite::Phase::text(const char *value, int len) +{ +} + + /** * Tests pattern from the vector in order and executes recipe on the first match. @@ -388,8 +419,7 @@ std::string yf::HttpRewrite::Replace::sub_vars ( } -void yf::HttpRewrite::configure_section(const xmlNode *ptr, - Section §ion) +void yf::HttpRewrite::configure_phase(const xmlNode *ptr, Phase &phase) { std::map rules; for (ptr = ptr->children; ptr; ptr = ptr->next) @@ -456,7 +486,7 @@ void yf::HttpRewrite::configure_section(const xmlNode *ptr, ("Reference to non-existing rule '" + values[3] + "' in http_rewrite filter"); w.rule = it->second; - section.within_list.push_back(w); + phase.within_list.push_back(w); } else { @@ -477,11 +507,11 @@ void yf::HttpRewrite::configure(const xmlNode * ptr, bool test_only, continue; else if (!strcmp((const char *) ptr->name, "request")) { - configure_section(ptr, *req_section); + configure_phase(ptr, *req_phase); } else if (!strcmp((const char *) ptr->name, "response")) { - configure_section(ptr, *res_section); + configure_phase(ptr, *res_phase); } else {