+ m_p->m_file->out << send_time << " " << m_p->m_msg_config;
+ m_p->m_file->out << " response id=" << package.session().id();
+ m_p->m_file->out << " close="
+ << (package.session().is_closed() ? "yes " : "no ")
+ << "duration=" << duration
+ << "\n";
+ }
+
+ if (m_p->m_init_options)
+ {
+ gdu = package.response().get();
+ if (gdu && gdu->which == Z_GDU_Z3950 &&
+ gdu->u.z3950->which == Z_APDU_initResponse)
+ {
+ m_p->m_file->out << receive_time << " " << m_p->m_msg_config;
+ m_p->m_file->out << " init options:";
+ yaz_init_opt_decode(gdu->u.z3950->u.initResponse->options,
+ option_write, m_p->m_file.get());
+ m_p->m_file->out << "\n";
+ }
+ }
+
+ if (m_p->m_res_apdu)
+ {
+ gdu = package.response().get();
+ if (gdu)
+ {
+ mp::odr odr(ODR_PRINT);
+ odr_set_stream(odr, m_p->m_file.get(), stream_write, 0);
+ z_GDU(odr, &gdu, 0, 0);
+ }
+ }
+
+ m_p->m_file->out.flush();
+ }
+}
+
+yf::Log::LFile::LFile(std::string fname) :
+ m_fname(fname), fout(fname.c_str()), out(fout)
+{
+}
+
+yf::Log::LFile::LFile(std::string fname, std::ostream &use_this) :
+ m_fname(fname), out(use_this)
+{
+}
+
+void yf::Log::Rep::openfile(const std::string &fname)
+{
+ std::list<LFilePtr>::const_iterator it = filter_log_files.begin();
+ for (; it != filter_log_files.end(); it++)
+ {
+ if ((*it)->m_fname == fname)
+ {
+ m_file = *it;
+ return;
+ }
+ }
+ // open stdout for empty file
+ LFilePtr newfile(fname.length() == 0
+ ? new LFile(fname, std::cout)
+ : new LFile(fname));
+ filter_log_files.push_back(newfile);
+ m_file = newfile;
+}
+
+void yf::Log::configure(const xmlNode *ptr)
+{
+ for (ptr = ptr->children; ptr; ptr = ptr->next)
+ {
+ if (ptr->type != XML_ELEMENT_NODE)
+ continue;
+ if (!strcmp((const char *) ptr->name, "message"))
+ m_p->m_msg_config = mp::xml::get_text(ptr);
+ else if (!strcmp((const char *) ptr->name, "filename"))
+ {
+ std::string fname = mp::xml::get_text(ptr);
+ m_p->openfile(fname);
+ }
+ else if (!strcmp((const char *) ptr->name, "category"))
+ {
+ const struct _xmlAttr *attr;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ if (!strcmp((const char *) attr->name,
+ "access"))
+ m_p->m_access =
+ mp::xml::get_bool(attr->children, true);
+ else if (!strcmp((const char *) attr->name, "request-apdu"))
+ m_p->m_req_apdu = mp::xml::get_bool(attr->children, true);
+ else if (!strcmp((const char *) attr->name, "response-apdu"))
+ m_p->m_res_apdu = mp::xml::get_bool(attr->children, true);
+ else if (!strcmp((const char *) attr->name, "apdu"))
+ {
+ m_p->m_req_apdu = mp::xml::get_bool(attr->children, true);
+ m_p->m_res_apdu = m_p->m_req_apdu;
+ }
+ else if (!strcmp((const char *) attr->name,
+ "request-session"))
+ m_p->m_req_session =
+ mp::xml::get_bool(attr->children, true);
+ else if (!strcmp((const char *) attr->name,
+ "response-session"))
+ m_p->m_res_session =
+ mp::xml::get_bool(attr->children, true);
+ else if (!strcmp((const char *) attr->name,
+ "session"))
+ {
+ m_p->m_req_session =
+ mp::xml::get_bool(attr->children, true);
+ m_p->m_res_session = m_p->m_req_session;
+ }
+ else if (!strcmp((const char *) attr->name,
+ "init-options"))
+ m_p->m_init_options =
+ mp::xml::get_bool(attr->children, true);
+ else
+ throw mp::filter::FilterException(
+ "Bad attribute " + std::string((const char *)
+ attr->name));
+ }
+ }
+ else
+ {
+ throw mp::filter::FilterException("Bad element "
+ + std::string((const char *)
+ ptr->name));