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

Public Member Functions

 Event (const Content *p, std::map< std::string, std::string > &vars, std::list< boost::regex > &skip_list)
 
 ~Event ()
 
const char * result ()
 
- Public Member Functions inherited from metaproxy_1::HTMLParserEvent
virtual ~ HTMLParserEvent ()
 

Private Member Functions

void openTagStart (const char *tag, int tag_len)
 
void anyTagEnd (const char *tag, int tag_len, int close_it)
 
void attribute (const char *tag, int tag_len, const char *attr, int attr_len, const char *value, int val_len, const char *sep)
 
void closeTag (const char *tag, int tag_len)
 
void text (const char *value, int len)
 

Private Attributes

const Contentm_content
 
WRBUF m_w
 
std::stack< std::list< Within >::const_iterator > s_within
 
std::map< std::string, std::string > & m_vars
 
std::list< boost::regex > & m_skips
 

Detailed Description

Definition at line 104 of file filter_http_rewrite.cpp.

Constructor & Destructor Documentation

◆ Event()

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

Definition at line 355 of file filter_http_rewrite.cpp.

358  : m_content(p), m_vars(vars), m_skips(skip_list)
359 {
360  m_w = wrbuf_alloc();
361 }
std::map< std::string, std::string > & m_vars

References m_w.

◆ ~Event()

mp::filter::HttpRewrite::Event::~Event ( )

Definition at line 363 of file filter_http_rewrite.cpp.

364 {
365  wrbuf_destroy(m_w);
366 }

Member Function Documentation

◆ anyTagEnd()

void mp::filter::HttpRewrite::Event::anyTagEnd ( const char *  tag,
int  tag_len,
int  close_it 
)
privatevirtual

Implements metaproxy_1::HTMLParserEvent.

Definition at line 393 of file filter_http_rewrite.cpp.

395 {
396  if (close_it)
397  {
398  if (!s_within.empty())
399  {
400  std::list<Within>::const_iterator it = s_within.top();
401  std::string t(tag, tag_len);
402  if (regex_match(t, it->tag))
403  s_within.pop();
404  }
405  }
406  if (close_it)
407  wrbuf_putc(m_w, '/');
408  wrbuf_putc(m_w, '>');
409 }
std::stack< std::list< Within >::const_iterator > s_within

◆ attribute()

void mp::filter::HttpRewrite::Event::attribute ( const char *  tag,
int  tag_len,
const char *  attr,
int  attr_len,
const char *  value,
int  val_len,
const char *  sep 
)
privatevirtual

Implements metaproxy_1::HTMLParserEvent.

Definition at line 411 of file filter_http_rewrite.cpp.

415 {
416  std::list<Within>::const_iterator it = m_content->within_list.begin();
417  bool subst = false;
418 
419  for (; it != m_content->within_list.end(); it++)
420  {
421  std::string t(tag, tag_len);
422  if (it->tag.empty() || regex_match(t, it->tag))
423  {
424  std::string a(attr, attr_len);
425  if (!it->attr.empty() && regex_match(a, it->attr))
426  subst = true;
427  }
428  if (subst)
429  break;
430  }
431 
432  wrbuf_putc(m_w, ' ');
433  wrbuf_write(m_w, attr, attr_len);
434  if (value)
435  {
436  wrbuf_puts(m_w, "=");
437  wrbuf_puts(m_w, sep);
438 
439  std::string output;
440  if (subst)
441  {
442  std::string s(value, val_len);
443  it->exec(m_vars, s, true, m_skips);
444  wrbuf_puts(m_w, s.c_str());
445  }
446  else
447  wrbuf_write(m_w, value, val_len);
448  wrbuf_puts(m_w, sep);
449  }
450 }

◆ closeTag()

void mp::filter::HttpRewrite::Event::closeTag ( const char *  tag,
int  tag_len 
)
privatevirtual

Implements metaproxy_1::HTMLParserEvent.

Definition at line 452 of file filter_http_rewrite.cpp.

453 {
454  if (!s_within.empty())
455  {
456  std::list<Within>::const_iterator it = s_within.top();
457  std::string t(tag, tag_len);
458  if (regex_match(t, it->tag))
459  s_within.pop();
460  }
461  wrbuf_puts(m_w, "</");
462  wrbuf_write(m_w, tag, tag_len);
463 }

◆ openTagStart()

void mp::filter::HttpRewrite::Event::openTagStart ( const char *  tag,
int  tag_len 
)
privatevirtual

Implements metaproxy_1::HTMLParserEvent.

Definition at line 373 of file filter_http_rewrite.cpp.

374 {
375  wrbuf_putc(m_w, '<');
376  wrbuf_write(m_w, tag, tag_len);
377 
378  std::string t(tag, tag_len);
379  std::list<Within>::const_iterator it = m_content->within_list.begin();
380  for (; it != m_content->within_list.end(); it++)
381  {
382  if (!it->tag.empty() && regex_match(t, it->tag))
383  {
384  if (!it->attr.empty() && regex_match("#text", it->attr))
385  {
386  s_within.push(it);
387  return;
388  }
389  }
390  }
391 }

◆ result()

const char * mp::filter::HttpRewrite::Event::result ( )

Definition at line 368 of file filter_http_rewrite.cpp.

369 {
370  return wrbuf_cstr(m_w);
371 }

Referenced by metaproxy_1::filter::HttpRewrite::Content::parse().

◆ text()

void mp::filter::HttpRewrite::Event::text ( const char *  value,
int  len 
)
privatevirtual

Implements metaproxy_1::HTMLParserEvent.

Definition at line 465 of file filter_http_rewrite.cpp.

466 {
467  std::list<Within>::const_iterator it = m_content->within_list.end();
468  if (!s_within.empty())
469  it = s_within.top();
470  if (it != m_content->within_list.end())
471  {
472  std::string s(value, len);
473  it->exec(m_vars, s, false, m_skips);
474  wrbuf_puts(m_w, s.c_str());
475  }
476  else
477  wrbuf_write(m_w, value, len);
478 }

Member Data Documentation

◆ m_content

const Content* metaproxy_1::filter::HttpRewrite::Event::m_content
private

Definition at line 113 of file filter_http_rewrite.cpp.

◆ m_skips

std::list<boost::regex>& metaproxy_1::filter::HttpRewrite::Event::m_skips
private

Definition at line 117 of file filter_http_rewrite.cpp.

◆ m_vars

std::map<std::string, std::string>& metaproxy_1::filter::HttpRewrite::Event::m_vars
private

Definition at line 116 of file filter_http_rewrite.cpp.

◆ m_w

WRBUF metaproxy_1::filter::HttpRewrite::Event::m_w
private

Definition at line 114 of file filter_http_rewrite.cpp.

Referenced by Event().

◆ s_within

std::stack<std::list<Within>::const_iterator> metaproxy_1::filter::HttpRewrite::Event::s_within
private

Definition at line 115 of file filter_http_rewrite.cpp.


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