+void yf::HttpRewrite::Content::parse(
+ int verbose,
+ std::string &content,
+ std::map<std::string, std::string> &vars,
+ std::list<boost::regex> & skip_list ) const
+{
+ if (type == "html")
+ {
+ HTMLParser parser;
+ Event ev(this, vars, skip_list);
+
+ parser.set_verbose(verbose);
+
+ parser.parse(ev, content.c_str());
+ content = ev.result();
+ }
+ if (type == "quoted-literal")
+ {
+ quoted_literal(content, vars, skip_list);
+ }
+}
+
+void yf::HttpRewrite::Content::quoted_literal(
+ std::string &content,
+ std::map<std::string, std::string> &vars,
+ std::list<boost::regex> & skip_list ) const
+{
+ std::list<Within>::const_iterator it = within_list.begin();
+ if (it != within_list.end())
+ embed_quoted_literal(content, vars, it->rule, false, skip_list);
+}
+
+void yf::HttpRewrite::Content::configure(
+ const xmlNode *ptr, std::map<std::string, RulePtr > &rules)
+{
+ for (; ptr; ptr = ptr->next)
+ {
+ if (ptr->type != XML_ELEMENT_NODE)
+ continue;
+ if (!strcmp((const char *) ptr->name, "within"))
+ {
+ static const char *names[7] =
+ { "header", "attr", "tag", "rule", "reqline", "type", 0 };
+ std::string values[6];
+ mp::xml::parse_attr(ptr, names, values);
+ Within w;
+ if (values[0].length() > 0)
+ w.header.assign(values[0], boost::regex_constants::icase);
+ if (values[1].length() > 0)
+ w.attr.assign(values[1], boost::regex_constants::icase);
+ if (values[2].length() > 0)
+ w.tag.assign(values[2], boost::regex_constants::icase);
+
+ std::vector<std::string> rulenames;
+ boost::split(rulenames, values[3], boost::is_any_of(","));
+ if (rulenames.size() == 0)
+ {
+ throw mp::filter::FilterException
+ ("Empty rule in '" + values[3] +
+ "' in http_rewrite filter");
+ }
+ else if (rulenames.size() == 1)
+ {
+ std::map<std::string,RulePtr>::const_iterator it =
+ rules.find(rulenames[0]);
+ if (it == rules.end())
+ throw mp::filter::FilterException
+ ("Reference to non-existing rule '" + rulenames[0] +
+ "' in http_rewrite filter");
+ w.rule = it->second;
+
+ }
+ else
+ {
+ RulePtr rule(new Rule);
+ size_t i;
+ for (i = 0; i < rulenames.size(); i++)
+ {
+ std::map<std::string,RulePtr>::const_iterator it =
+ rules.find(rulenames[i]);
+ if (it == rules.end())
+ throw mp::filter::FilterException
+ ("Reference to non-existing rule '" + rulenames[i] +
+ "' in http_rewrite filter");
+ RulePtr subRule = it->second;
+ std::list<Replace>::iterator rit =
+ subRule->replace_list.begin();
+ for (; rit != subRule->replace_list.end(); rit++)
+ rule->replace_list.push_back(*rit);
+ }
+ w.rule = rule;
+ }
+ w.reqline = values[4] == "1";
+ w.type = values[5];
+ if (w.type.empty() || w.type == "quoted-literal")
+ ;
+ else
+ throw mp::filter::FilterException
+ ("within type must be quoted-literal or none in "
+ " in http_rewrite filter");
+ within_list.push_back(w);
+ }
+ }
+}
+