From 67e481dac76e773799e3e18c87d29f0a210cbfb1 Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Mon, 6 May 2013 15:48:48 +0200 Subject: [PATCH] Configure from XML --- src/filter_http_rewrite.cpp | 66 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/src/filter_http_rewrite.cpp b/src/filter_http_rewrite.cpp index 47b33ed..e64fb36 100644 --- a/src/filter_http_rewrite.cpp +++ b/src/filter_http_rewrite.cpp @@ -146,9 +146,6 @@ void yf::HttpRewrite::rewrite_body (mp::odr & o, char **content_buf, int *conten } } - -void yf::HttpRewrite::configure(const xmlNode* ptr, bool test_only, const char *path) {}; - /** * Tests pattern from the vector in order and executes recipe on the first match. @@ -340,6 +337,69 @@ void yf::HttpRewrite::configure( parse_groups(res_uri_pats, res_groups_bynum); } + +static void configure_rules(const xmlNode *ptr, yf::HttpRewrite::spair_vec & dest) +{ + for (ptr = ptr->children; ptr; ptr = ptr->next) + { + if (ptr->type != XML_ELEMENT_NODE) + continue; + else if (!strcmp((const char *) ptr->name, "rewrite")) + { + std::string from, to; + const struct _xmlAttr *attr; + for (attr = ptr->properties; attr; attr = attr->next) + { + if (!strcmp((const char *) attr->name, "from")) + from = mp::xml::get_text(attr->children); + else if (!strcmp((const char *) attr->name, "to")) + to = mp::xml::get_text(attr->children); + else + throw mp::filter::FilterException + ("Bad attribute " + + std::string((const char *) attr->name) + + " in rewrite section of http_rewrite"); + } + if (!from.empty()) + dest.push_back(std::make_pair(from, to)); + } + else + { + throw mp::filter::FilterException + ("Bad element " + + std::string((const char *) ptr->name) + + " in http_rewrite1 filter"); + } + } +} + +void yf::HttpRewrite::configure(const xmlNode * ptr, bool test_only, + const char *path) +{ + spair_vec req_uri_pats; + spair_vec res_uri_pats; + for (ptr = ptr->children; ptr; ptr = ptr->next) + { + if (ptr->type != XML_ELEMENT_NODE) + continue; + else if (!strcmp((const char *) ptr->name, "request")) + { + configure_rules(ptr->children, req_uri_pats); + } + else if (!strcmp((const char *) ptr->name, "response")) + { + configure_rules(ptr->children, res_uri_pats); + } + else + { + throw mp::filter::FilterException + ("Bad element " + + std::string((const char *) ptr->name) + + " in http_rewrite1 filter"); + } + } +} + static mp::filter::Base* filter_creator() { return new mp::filter::HttpRewrite; -- 1.7.10.4