metaproxy  1.21.0
Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
metaproxy_1::filter::Log::Impl Class Reference
Collaboration diagram for metaproxy_1::filter::Log::Impl:
Collaboration graph

Classes

class  LFile
 

Public Types

typedef boost::shared_ptr< Log::Impl::LFileLFilePtr
 

Public Member Functions

 Impl (const std::string &x="-")
 
 ~Impl ()
 
void process (metaproxy_1::Package &package)
 
void configure (const xmlNode *ptr)
 

Private Member Functions

void openfile (const std::string &fname)
 

Static Private Member Functions

static void stream_write (ODR o, void *handle, int type, const char *buf, int len)
 
static void option_write (const char *name, void *handle)
 

Private Attributes

std::string m_msg_config
 
bool m_1line
 
bool m_access
 
bool m_user_access
 
bool m_req_apdu
 
bool m_res_apdu
 
bool m_req_session
 
bool m_res_session
 
bool m_init_options
 
LFilePtr m_file
 
std::string m_time_format
 
boost::mutex m_session_mutex
 
std::map< mp::Session, std::string > m_sessions
 

Detailed Description

Definition at line 46 of file filter_log.cpp.

Member Typedef Documentation

◆ LFilePtr

Definition at line 49 of file filter_log.cpp.

Constructor & Destructor Documentation

◆ Impl()

mp::filter::Log::Impl::Impl ( const std::string &  x = "-")

Definition at line 121 of file filter_log.cpp.

122  : m_msg_config(x),
123  m_1line(false),
124  m_access(true),
125  m_user_access(false),
126  m_req_apdu(false),
127  m_res_apdu(false),
128  m_req_session(false),
129  m_res_session(false),
130  m_init_options(false),
131  m_time_format("%H:%M:%S-%d/%m")
132 {
133  openfile("");
134 }
void openfile(const std::string &fname)
Definition: filter_log.cpp:796

References openfile().

Here is the call graph for this function:

◆ ~Impl()

mp::filter::Log::Impl::~Impl ( )

Definition at line 137 of file filter_log.cpp.

138 {
139 }

Member Function Documentation

◆ configure()

void mp::filter::Log::Impl::configure ( const xmlNode *  ptr)

Definition at line 512 of file filter_log.cpp.

513 {
514  for (ptr = ptr->children; ptr; ptr = ptr->next)
515  {
516  if (ptr->type != XML_ELEMENT_NODE)
517  continue;
518  if (!strcmp((const char *) ptr->name, "message"))
519  m_msg_config = mp::xml::get_text(ptr);
520  else if (!strcmp((const char *) ptr->name, "filename"))
521  {
522  std::string fname = mp::xml::get_text(ptr);
523  openfile(fname);
524  }
525  else if (!strcmp((const char *) ptr->name, "time-format"))
526  {
527  m_time_format = mp::xml::get_text(ptr);
528  }
529  else if (!strcmp((const char *) ptr->name, "category"))
530  {
531  const struct _xmlAttr *attr;
532  for (attr = ptr->properties; attr; attr = attr->next)
533  {
534  if (!strcmp((const char *) attr->name, "line"))
535  m_1line = mp::xml::get_bool(attr->children, true);
536  else if (!strcmp((const char *) attr->name, "access"))
537  m_access = mp::xml::get_bool(attr->children, true);
538  else if (!strcmp((const char *) attr->name, "user-access"))
539  m_user_access = mp::xml::get_bool(attr->children, true);
540  else if (!strcmp((const char *) attr->name, "request-apdu"))
541  m_req_apdu = mp::xml::get_bool(attr->children, true);
542  else if (!strcmp((const char *) attr->name, "response-apdu"))
543  m_res_apdu = mp::xml::get_bool(attr->children, true);
544  else if (!strcmp((const char *) attr->name, "apdu"))
545  {
546  m_req_apdu = mp::xml::get_bool(attr->children, true);
548  }
549  else if (!strcmp((const char *) attr->name,
550  "request-session"))
551  m_req_session =
552  mp::xml::get_bool(attr->children, true);
553  else if (!strcmp((const char *) attr->name,
554  "response-session"))
555  m_res_session =
556  mp::xml::get_bool(attr->children, true);
557  else if (!strcmp((const char *) attr->name,
558  "session"))
559  {
560  m_req_session =
561  mp::xml::get_bool(attr->children, true);
563  }
564  else if (!strcmp((const char *) attr->name,
565  "init-options"))
567  mp::xml::get_bool(attr->children, true);
568  else if (!strcmp((const char *) attr->name,
569  "init-options"))
571  mp::xml::get_bool(attr->children, true);
572  else
573  throw mp::filter::FilterException(
574  "Bad attribute " + std::string((const char *)
575  attr->name));
576  }
577  }
578  else
579  {
580  throw mp::filter::FilterException("Bad element "
581  + std::string((const char *)
582  ptr->name));
583  }
584  }
585 }

◆ openfile()

void mp::filter::Log::Impl::openfile ( const std::string &  fname)
private

Definition at line 796 of file filter_log.cpp.

797 {
798  std::list<LFilePtr>::const_iterator it
799  = filter_log_files.begin();
800  for (; it != filter_log_files.end(); it++)
801  {
802  if ((*it)->m_fname == fname)
803  {
804  m_file = *it;
805  return;
806  }
807  }
808  LFilePtr newfile(new LFile(fname));
809  filter_log_files.push_back(newfile);
810  m_file = newfile;
811 }
boost::shared_ptr< Log::Impl::LFile > LFilePtr
Definition: filter_log.cpp:48
static std::list< yf::Log::Impl::LFilePtr > filter_log_files
Definition: filter_log.cpp:91

References metaproxy_1::filter::filter_log_files.

Referenced by Impl().

◆ option_write()

void mp::filter::Log::Impl::option_write ( const char *  name,
void *  handle 
)
staticprivate

Definition at line 820 of file filter_log.cpp.

821 {
822  std::ostringstream *os = (std::ostringstream *) handle;
823  *os << " " << name;
824 }

◆ process()

void mp::filter::Log::Impl::process ( metaproxy_1::Package &  package)

Definition at line 587 of file filter_log.cpp.

588 {
589  Z_GDU *gdu_req = package.request().get();
590  std::string user("-");
591 
592  yaz_timing_t timer = yaz_timing_create();
593 
594  // scope for session lock
595  {
596  boost::mutex::scoped_lock scoped_lock(m_session_mutex);
597 
598  if (gdu_req && gdu_req->which == Z_GDU_Z3950)
599  {
600  Z_APDU *apdu_req = gdu_req->u.z3950;
601  if (apdu_req->which == Z_APDU_initRequest)
602  {
603  Z_InitRequest *req = apdu_req->u.initRequest;
604  Z_IdAuthentication *a = req->idAuthentication;
605  if (a)
606  {
607  if (a->which == Z_IdAuthentication_idPass
608  && a->u.idPass->userId)
609  user = a->u.idPass->userId;
610  else if (a->which == Z_IdAuthentication_open)
611  user = a->u.open;
612 
613  m_sessions[package.session()] = user;
614  }
615  }
616  }
617  std::map<mp::Session,std::string>::iterator it =
618  m_sessions.find(package.session());
619  if (it != m_sessions.end())
620  user = it->second;
621 
622  if (package.session().is_closed())
623  m_sessions.erase(package.session());
624  }
625  // scope for locking Ostream
626  {
627  boost::mutex::scoped_lock scoped_lock(m_file->m_mutex);
628 
629  if (m_access)
630  {
631  if (gdu_req)
632  {
633  std::ostringstream os;
634  os << m_msg_config << " "
635  << package << " "
636  << "0.000000" << " "
637  << *gdu_req;
638  m_file->log(m_time_format, os);
639  }
640  }
641 
642  if (m_user_access)
643  {
644  if (gdu_req)
645  {
646  std::ostringstream os;
647  os << m_msg_config << " " << user << " "
648  << package << " "
649  << "0.000000" << " "
650  << *gdu_req;
651  m_file->log(m_time_format, os);
652  }
653  }
654 
655  if (m_req_session)
656  {
657  std::ostringstream os;
658  os << m_msg_config;
659  os << " request id=" << package.session().id();
660  os << " close="
661  << (package.session().is_closed() ? "yes" : "no");
662  m_file->log(m_time_format, os);
663  }
664 
665  if (m_init_options)
666  {
667  if (gdu_req && gdu_req->which == Z_GDU_Z3950 &&
668  gdu_req->u.z3950->which == Z_APDU_initRequest)
669  {
670  std::ostringstream os;
671  os << m_msg_config << " init options:";
672  yaz_init_opt_decode(gdu_req->u.z3950->u.initRequest->options,
673  option_write, &os);
674  m_file->log(m_time_format, os);
675  }
676  }
677 
678  if (m_req_apdu)
679  {
680  if (gdu_req)
681  {
682  mp::odr odr(ODR_PRINT);
683  odr_set_stream(odr, m_file->fhandle, stream_write, 0);
684  if (!m_file->fhandle)
685  yaz_log_lock();
686  z_GDU(odr, &gdu_req, 0, 0);
687  if (!m_file->fhandle)
688  yaz_log_unlock();
689  }
690  }
691  }
692 
693  // unlocked during move
694  package.move();
695 
696  Z_GDU *gdu_res = package.response().get();
697 
698  gdu_req = package.request().get();
699 
700  yaz_timing_stop(timer);
701  double duration = yaz_timing_get_real(timer);
702 
703  // scope for locking Ostream
704  {
705  boost::mutex::scoped_lock scoped_lock(m_file->m_mutex);
706 
707  if (m_1line)
708  {
709  mp::wrbuf w;
710 
711  log_1line_Z_GDU(gdu_req, gdu_res, w);
712  if (w.len() > 0)
713  {
714  const char *message = wrbuf_cstr(w);
715  std::ostringstream os;
716  os << m_msg_config << " "
717  << package << " "
718  << std::fixed << std::setprecision (6) << duration
719  << " "
720  << message;
721  m_file->log(m_time_format, os);
722  }
723  }
724 
725  if (m_access)
726  {
727  if (gdu_res)
728  {
729  std::ostringstream os;
730  os << m_msg_config << " "
731  << package << " "
732  << std::fixed << std::setprecision (6) << duration
733  << " "
734  << *gdu_res;
735  m_file->log(m_time_format, os);
736  }
737  }
738  if (m_user_access)
739  {
740  if (gdu_res)
741  {
742  std::ostringstream os;
743  os << m_msg_config << " " << user << " "
744  << package << " "
745  << std::fixed << std::setprecision (6) << duration << " "
746  << *gdu_res;
747  m_file->log(m_time_format, os);
748  }
749  }
750 
751  if (m_res_session)
752  {
753  std::ostringstream os;
754  os << m_msg_config;
755  os << " response id=" << package.session().id();
756  os << " close="
757  << (package.session().is_closed() ? "yes " : "no ")
758  << "duration="
759  << std::fixed << std::setprecision (6) << duration;
760  m_file->log(m_time_format, os);
761  }
762 
763  if (m_init_options)
764  {
765  if (gdu_res && gdu_res->which == Z_GDU_Z3950 &&
766  gdu_res->u.z3950->which == Z_APDU_initResponse)
767  {
768  std::ostringstream os;
769  os << m_msg_config;
770  os << " init options:";
771  yaz_init_opt_decode(gdu_res->u.z3950->u.initResponse->options,
772  option_write, &os);
773  m_file->log(m_time_format, os);
774  }
775  }
776 
777  if (m_res_apdu)
778  {
779  if (gdu_res)
780  {
781  mp::odr odr(ODR_PRINT);
782  odr_set_stream(odr, m_file->fhandle, stream_write, 0);
783  if (!m_file->fhandle)
784  yaz_log_lock();
785  z_GDU(odr, &gdu_res, 0, 0);
786  if (!m_file->fhandle)
787  yaz_log_unlock();
788  }
789  }
790  }
791  m_file->flush();
792  yaz_timing_destroy(&timer);
793 }
static void stream_write(ODR o, void *handle, int type, const char *buf, int len)
Definition: filter_log.cpp:814
static void option_write(const char *name, void *handle)
Definition: filter_log.cpp:820
std::map< mp::Session, std::string > m_sessions
Definition: filter_log.cpp:76
static void log_1line_Z_GDU(Z_GDU *gdu_req, Z_GDU *gdu_res, WRBUF w)
Definition: filter_log.cpp:496

References log_1line_Z_GDU().

Here is the call graph for this function:

◆ stream_write()

void mp::filter::Log::Impl::stream_write ( ODR  o,
void *  handle,
int  type,
const char *  buf,
int  len 
)
staticprivate

Definition at line 814 of file filter_log.cpp.

815 {
816  FILE *f = (FILE*) handle;
817  fwrite(buf, len, 1, f ? f : yaz_log_file());
818 }

Member Data Documentation

◆ m_1line

bool metaproxy_1::filter::Log::Impl::m_1line
private

Definition at line 65 of file filter_log.cpp.

◆ m_access

bool metaproxy_1::filter::Log::Impl::m_access
private

Definition at line 66 of file filter_log.cpp.

◆ m_file

LFilePtr metaproxy_1::filter::Log::Impl::m_file
private

Definition at line 73 of file filter_log.cpp.

◆ m_init_options

bool metaproxy_1::filter::Log::Impl::m_init_options
private

Definition at line 72 of file filter_log.cpp.

◆ m_msg_config

std::string metaproxy_1::filter::Log::Impl::m_msg_config
private

Definition at line 64 of file filter_log.cpp.

◆ m_req_apdu

bool metaproxy_1::filter::Log::Impl::m_req_apdu
private

Definition at line 68 of file filter_log.cpp.

◆ m_req_session

bool metaproxy_1::filter::Log::Impl::m_req_session
private

Definition at line 70 of file filter_log.cpp.

◆ m_res_apdu

bool metaproxy_1::filter::Log::Impl::m_res_apdu
private

Definition at line 69 of file filter_log.cpp.

◆ m_res_session

bool metaproxy_1::filter::Log::Impl::m_res_session
private

Definition at line 71 of file filter_log.cpp.

◆ m_session_mutex

boost::mutex metaproxy_1::filter::Log::Impl::m_session_mutex
private

Definition at line 75 of file filter_log.cpp.

◆ m_sessions

std::map<mp::Session, std::string> metaproxy_1::filter::Log::Impl::m_sessions
private

Definition at line 76 of file filter_log.cpp.

◆ m_time_format

std::string metaproxy_1::filter::Log::Impl::m_time_format
private

Definition at line 74 of file filter_log.cpp.

◆ m_user_access

bool metaproxy_1::filter::Log::Impl::m_user_access
private

Definition at line 67 of file filter_log.cpp.


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