+ if (!s_within.empty())
+ {
+ std::list<Within>::const_iterator it = s_within.top();
+ std::string t(tag, tag_len);
+ if (regex_match(t, it->tag))
+ s_within.pop();
+ }
+ }
+ if (close_it)
+ wrbuf_putc(m_w, '/');
+ wrbuf_putc(m_w, '>');
+}
+
+void yf::HttpRewrite::Event::attribute(const char *tag, int tag_len,
+ const char *attr, int attr_len,
+ const char *value, int val_len,
+ const char *sep)
+{
+ std::list<Within>::const_iterator it = m_content->within_list.begin();
+ bool subst = false;
+
+ for (; it != m_content->within_list.end(); it++)
+ {
+ std::string t(tag, tag_len);
+ if (it->tag.empty() || regex_match(t, it->tag))
+ {
+ std::string a(attr, attr_len);
+ if (!it->attr.empty() && regex_match(a, it->attr))
+ subst = true;
+ }
+ if (subst)
+ break;
+ }
+
+ wrbuf_putc(m_w, ' ');
+ wrbuf_write(m_w, attr, attr_len);
+ if (value)
+ {
+ wrbuf_puts(m_w, "=");
+ wrbuf_puts(m_w, sep);
+
+ std::string output;
+ if (subst)
+ {
+ std::string s(value, val_len);
+ it->exec(m_vars, s, true);
+ wrbuf_puts(m_w, s.c_str());
+ }
+ else
+ wrbuf_write(m_w, value, val_len);
+ wrbuf_puts(m_w, sep);
+ }
+}
+
+void yf::HttpRewrite::Event::closeTag(const char *tag, int tag_len)
+{
+ if (!s_within.empty())
+ {
+ std::list<Within>::const_iterator it = s_within.top();
+ std::string t(tag, tag_len);
+ if (regex_match(t, it->tag))
+ s_within.pop();
+ }
+ wrbuf_puts(m_w, "</");
+ wrbuf_write(m_w, tag, tag_len);
+}
+
+void yf::HttpRewrite::Event::text(const char *value, int len)
+{
+ std::list<Within>::const_iterator it = m_content->within_list.end();
+ if (!s_within.empty())
+ it = s_within.top();
+ if (it != m_content->within_list.end())
+ {
+ std::string s(value, len);
+ it->exec(m_vars, s, false);
+ wrbuf_puts(m_w, s.c_str());
+ }
+ else
+ wrbuf_write(m_w, value, len);
+}
+
+static bool embed_quoted_literal(
+ std::string &content,
+ std::map<std::string, std::string> &vars,
+ mp::filter::HttpRewrite::RulePtr ruleptr,
+ bool html_context)
+{
+ bool replace = false;
+ std::string res;
+ const char *cp = content.c_str();
+ const char *cp0 = cp;
+ while (*cp)
+ {
+ if (html_context && !strncmp(cp, """, 6))
+ {
+ cp += 6;
+ res.append(cp0, cp - cp0);
+ cp0 = cp;
+ while (*cp)
+ {
+ if (!strncmp(cp, """, 6))
+ break;
+ if (*cp == '\n')
+ break;
+ cp++;
+ }
+ if (!*cp)
+ break;
+ std::string s(cp0, cp - cp0);
+ if (ruleptr->test_patterns(vars, s, true))
+ replace = true;
+ cp0 = cp;
+ res.append(s);
+ }
+ else if (*cp == '"' || *cp == '\'')
+ {
+ int m = *cp;
+ cp++;
+ res.append(cp0, cp - cp0);
+ cp0 = cp;
+ while (*cp)
+ {
+ if (cp[-1] != '\\' && *cp == m)
+ break;
+ if (*cp == '\n')
+ break;
+ cp++;
+ }
+ if (!*cp)
+ break;
+ std::string s(cp0, cp - cp0);
+ if (ruleptr->test_patterns(vars, s, true))
+ replace = true;
+ cp0 = cp;
+ res.append(s);
+ }
+ else if (*cp == '/' && cp[1] == '/')
+ {
+ while (cp[1] && cp[1] != '\n')
+ cp++;
+ }
+ cp++;