metaproxy  1.21.0
Public Member Functions | Public Attributes | List of all members
metaproxy_1::filter::HttpRewrite::Content Class Reference
Collaboration diagram for metaproxy_1::filter::HttpRewrite::Content:
Collaboration graph

Public Member Functions

void configure (const xmlNode *ptr, std::map< std::string, RulePtr > &rules)
 
void quoted_literal (std::string &content, std::map< std::string, std::string > &vars, std::list< boost::regex > &skip_list) const
 
void parse (int verbose, std::string &content, std::map< std::string, std::string > &vars, std::list< boost::regex > &skip_list) const
 

Public Attributes

std::string type
 
boost::regex content_re
 
std::list< Withinwithin_list
 

Detailed Description

Definition at line 73 of file filter_http_rewrite.cpp.

Member Function Documentation

◆ configure()

void mp::filter::HttpRewrite::Content::configure ( const xmlNode *  ptr,
std::map< std::string, RulePtr > &  rules 
)

Definition at line 795 of file filter_http_rewrite.cpp.

797 {
798  for (; ptr; ptr = ptr->next)
799  {
800  if (ptr->type != XML_ELEMENT_NODE)
801  continue;
802  if (!strcmp((const char *) ptr->name, "within"))
803  {
804  static const char *names[7] =
805  { "header", "attr", "tag", "rule", "reqline", "type", 0 };
806  std::string values[6];
807  mp::xml::parse_attr(ptr, names, values);
808  Within w;
809  if (values[0].length() > 0)
810  w.header.assign(values[0], boost::regex_constants::icase);
811  if (values[1].length() > 0)
812  w.attr.assign(values[1], boost::regex_constants::icase);
813  if (values[2].length() > 0)
814  w.tag.assign(values[2], boost::regex_constants::icase);
815 
816  std::vector<std::string> rulenames;
817  boost::split(rulenames, values[3], boost::is_any_of(","));
818  if (rulenames.size() == 0)
819  {
820  throw mp::filter::FilterException
821  ("Empty rule in '" + values[3] +
822  "' in http_rewrite filter");
823  }
824  else if (rulenames.size() == 1)
825  {
826  std::map<std::string,RulePtr>::const_iterator it =
827  rules.find(rulenames[0]);
828  if (it == rules.end())
829  throw mp::filter::FilterException
830  ("Reference to non-existing rule '" + rulenames[0] +
831  "' in http_rewrite filter");
832  w.rule = it->second;
833 
834  }
835  else
836  {
837  RulePtr rule(new Rule);
838  size_t i;
839  for (i = 0; i < rulenames.size(); i++)
840  {
841  std::map<std::string,RulePtr>::const_iterator it =
842  rules.find(rulenames[i]);
843  if (it == rules.end())
844  throw mp::filter::FilterException
845  ("Reference to non-existing rule '" + rulenames[i] +
846  "' in http_rewrite filter");
847  RulePtr subRule = it->second;
848  std::list<Replace>::iterator rit =
849  subRule->replace_list.begin();
850  for (; rit != subRule->replace_list.end(); rit++)
851  rule->replace_list.push_back(*rit);
852  }
853  w.rule = rule;
854  }
855  w.reqline = values[4] == "1";
856  w.type = values[5];
857  if (w.type.empty() || w.type == "quoted-literal")
858  ;
859  else
860  throw mp::filter::FilterException
861  ("within type must be quoted-literal or none in "
862  " in http_rewrite filter");
863  within_list.push_back(w);
864  }
865  }
866 }
boost::shared_ptr< Rule > RulePtr

References metaproxy_1::filter::HttpRewrite::Within::attr, metaproxy_1::filter::HttpRewrite::Within::header, metaproxy_1::filter::HttpRewrite::Within::reqline, metaproxy_1::filter::HttpRewrite::Within::rule, metaproxy_1::filter::HttpRewrite::Within::tag, and metaproxy_1::filter::HttpRewrite::Within::type.

Referenced by metaproxy_1::filter::HttpRewrite::configure_phase().

◆ parse()

void mp::filter::HttpRewrite::Content::parse ( int  verbose,
std::string &  content,
std::map< std::string, std::string > &  vars,
std::list< boost::regex > &  skip_list 
) const

Definition at line 763 of file filter_http_rewrite.cpp.

768 {
769  if (type == "html")
770  {
771  HTMLParser parser;
772  Event ev(this, vars, skip_list);
773 
774  parser.set_verbose(verbose);
775 
776  parser.parse(ev, content.c_str());
777  content = ev.result();
778  }
779  if (type == "quoted-literal")
780  {
781  quoted_literal(content, vars, skip_list);
782  }
783 }
void quoted_literal(std::string &content, std::map< std::string, std::string > &vars, std::list< boost::regex > &skip_list) const

References metaproxy_1::HTMLParser::parse(), metaproxy_1::filter::HttpRewrite::Event::result(), and metaproxy_1::HTMLParser::set_verbose().

Here is the call graph for this function:

◆ quoted_literal()

void mp::filter::HttpRewrite::Content::quoted_literal ( std::string &  content,
std::map< std::string, std::string > &  vars,
std::list< boost::regex > &  skip_list 
) const

Definition at line 785 of file filter_http_rewrite.cpp.

789 {
790  std::list<Within>::const_iterator it = within_list.begin();
791  if (it != within_list.end())
792  embed_quoted_literal(content, vars, it->rule, false, skip_list);
793 }
static bool embed_quoted_literal(std::string &content, std::map< std::string, std::string > &vars, mp::filter::HttpRewrite::RulePtr ruleptr, bool html_context, std::list< boost::regex > &skip_list)

References embed_quoted_literal().

Here is the call graph for this function:

Member Data Documentation

◆ content_re

boost::regex metaproxy_1::filter::HttpRewrite::Content::content_re

◆ type

std::string metaproxy_1::filter::HttpRewrite::Content::type

◆ within_list

std::list<Within> metaproxy_1::filter::HttpRewrite::Content::within_list

Definition at line 77 of file filter_http_rewrite.cpp.


The documentation for this class was generated from the following file: