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

Public Member Functions

bool test_patterns (std::map< std::string, std::string > &vars, std::string &txt, bool anchor, std::list< boost::regex > &skip_list)
 

Public Attributes

std::list< Replacereplace_list
 

Detailed Description

Definition at line 52 of file filter_http_rewrite.cpp.

Member Function Documentation

◆ test_patterns()

bool mp::filter::HttpRewrite::Rule::test_patterns ( std::map< std::string, std::string > &  vars,
std::string &  txt,
bool  anchor,
std::list< boost::regex > &  skip_list 
)

Definition at line 563 of file filter_http_rewrite.cpp.

567 {
568  bool replaces = false;
569  bool first = anchor;
570  std::string out;
571  std::string::const_iterator start, end;
572  start = txt.begin();
573  end = txt.end();
574  while (1)
575  {
576  std::list<Replace>::iterator bit = replace_list.end();
577  boost::smatch bwhat;
578  bool match_one = false;
579  {
580  std::list<Replace>::iterator it = replace_list.begin();
581  for (; it != replace_list.end(); it++)
582  {
583  if (it->start_anchor && !first)
584  continue;
585  boost::smatch what;
586  if (regex_search(start, end, what, it->re))
587  {
588  if (!match_one || what[0].first < bwhat[0].first)
589  {
590  bwhat = what;
591  bit = it;
592  }
593  match_one = true;
594  }
595  }
596  if (!match_one)
597  break;
598  }
599  first = false;
600  replaces = true;
601  size_t i;
602  for (i = 1; i < bwhat.size(); ++i)
603  {
604  //check if the group is named
605  std::map<int, std::string>::const_iterator git
606  = bit->group_index.find(i);
607  if (git != bit->group_index.end())
608  { //it is
609  vars[git->second] = bwhat[i];
610  }
611 
612  }
613  // Compare against skip_list
614  bool skipthis = false;
615  std::list<boost::regex>::iterator si = skip_list.begin();
616  for ( ; si != skip_list.end(); si++) {
617  if ( boost::regex_search(bwhat.str(0), *si) )
618  {
619  skipthis = true;
620  break;
621  }
622  }
623  //prepare replacement string
624  std::string rvalue = bit->sub_vars(vars);
625  out.append(start, bwhat[0].first);
626  if ( skipthis )
627  {
628  yaz_log(YLOG_LOG,"! Not rewriting '%s', skiplist match",
629  bwhat.str(0).c_str() );
630  out.append(bwhat.str(0).c_str());
631  }
632  else
633  {
634  yaz_log(YLOG_LOG, "! Rewritten '%s' to '%s'",
635  bwhat.str(0).c_str(), rvalue.c_str());
636  out.append(rvalue);
637  }
638  start = bwhat[0].second; //move search forward
639  }
640  out.append(start, end);
641  txt = out;
642  return replaces;
643 }

Member Data Documentation

◆ replace_list

std::list<Replace> metaproxy_1::filter::HttpRewrite::Rule::replace_list

Definition at line 54 of file filter_http_rewrite.cpp.


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