X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_http_rewrite.cpp;h=29ce8b05eb5185328aa30068674d022bb95de2f7;hb=c26efced52c043f96c6560b453975d77ebde1b0f;hp=47b33ed4ae918896d78abf49eb31ac34b2e51781;hpb=3a51c4a584225b0e77d17600acb527337f5ac8ce;p=metaproxy-moved-to-github.git diff --git a/src/filter_http_rewrite.cpp b/src/filter_http_rewrite.cpp index 47b33ed..29ce8b0 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,72 @@ 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"); + } + std::cout << "Found rewrite rule from=" << from << " to " << to << std::endl; + if (!from.empty()) + dest.push_back(std::make_pair(from, to)); + } + else + { + throw mp::filter::FilterException + ("Bad element o" + + 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")) + { + std::cout << "Found request rule" << std::endl; + configure_rules(ptr, req_uri_pats); + } + else if (!strcmp((const char *) ptr->name, "response")) + { + configure_rules(ptr, res_uri_pats); + } + else + { + throw mp::filter::FilterException + ("Bad element " + + std::string((const char *) ptr->name) + + " in http_rewrite1 filter"); + } + } + configure(req_uri_pats, res_uri_pats); +} + static mp::filter::Base* filter_creator() { return new mp::filter::HttpRewrite;