+
+void yf::HttpRewrite::configure_phase(const xmlNode *ptr, Phase &phase)
+{
+ std::map<std::string, RulePtr > rules;
+ for (ptr = ptr->children; ptr; ptr = ptr->next)
+ {
+ if (ptr->type != XML_ELEMENT_NODE)
+ continue;
+ else if (!strcmp((const char *) ptr->name, "rule"))
+ {
+ static const char *names[2] = { "name", 0 };
+ std::string values[1];
+ values[0] = "default";
+ mp::xml::parse_attr(ptr, names, values);
+
+ RulePtr rule(new Rule);
+ for (xmlNode *p = ptr->children; p; p = p->next)
+ {
+ if (p->type != XML_ELEMENT_NODE)
+ continue;
+ if (!strcmp((const char *) p->name, "rewrite"))
+ {
+ Replace replace;
+ const struct _xmlAttr *attr;
+ for (attr = p->properties; attr; attr = attr->next)
+ {
+ if (!strcmp((const char *) attr->name, "from"))
+ replace.regex = mp::xml::get_text(attr->children);
+ else if (!strcmp((const char *) attr->name, "to"))
+ replace.recipe = 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");
+ }
+ yaz_log(YLOG_LOG, "Found rewrite rule from '%s' to '%s'",
+ replace.regex.c_str(), replace.recipe.c_str());
+ replace.parse_groups();
+ if (!replace.regex.empty())
+ rule->replace_list.push_back(replace);
+ }
+ else
+ throw mp::filter::FilterException
+ ("Bad element "
+ + std::string((const char *) p->name)
+ + " in http_rewrite filter");
+ }
+ rules[values[0]] = rule;
+ }
+ else if (!strcmp((const char *) ptr->name, "within"))
+ {
+ static const char *names[6] =
+ { "header", "attr", "tag", "rule", "reqline", 0 };
+ std::string values[5];
+ mp::xml::parse_attr(ptr, names, values);
+ Within w;
+ w.header = values[0];
+ w.attr = values[1];
+ w.tag = values[2];
+ std::map<std::string,RulePtr>::const_iterator it =
+ rules.find(values[3]);
+ if (it == rules.end())
+ throw mp::filter::FilterException
+ ("Reference to non-existing rule '" + values[3] +
+ "' in http_rewrite filter");
+ w.rule = it->second;
+ w.reqline = values[4] == "1";
+ phase.within_list.push_back(w);
+ }
+ else
+ {
+ throw mp::filter::FilterException
+ ("Bad element "
+ + std::string((const char *) ptr->name)
+ + " in http_rewrite filter");
+ }
+ }
+}
+
+void yf::HttpRewrite::configure(const xmlNode * ptr, bool test_only,
+ const char *path)