-/* $Id: filter_log.cpp,v 1.19 2006-06-19 13:08:00 adam Exp $
+/* $Id: filter_log.cpp,v 1.21 2006-06-21 12:50:35 adam Exp $
Copyright (c) 2005-2006, Index Data.
See the LICENSE file for details
public:
boost::mutex m_mutex;
std::string m_fname;
- std::ofstream out;
+ std::ofstream fout;
+ std::ostream &out;
LFile(std::string fname);
+ LFile(std::string fname, std::ostream &use_this);
};
typedef boost::shared_ptr<Log::LFile> LFilePtr;
class Log::Rep {
bool m_res_apdu;
bool m_req_session;
bool m_res_session;
+ bool m_init_options;
};
// Only used during configure stage (no threading)
static std::list<LFilePtr> filter_log_files;
m_res_apdu = true;
m_req_session = true;
m_res_session = true;
+ m_init_options = false;
+ openfile("");
}
yf::Log::Log(const std::string &x) : m_p(new Rep)
lfile->out.write(buf, len);
}
+void option_write(const char *name, void *handle)
+{
+ yf::Log::LFile *lfile = (yf::Log::LFile*) handle;
+ lfile->out << " " << name;
+}
+
void yf::Log::process(mp::Package &package) const
{
Z_GDU *gdu;
<< (package.session().is_closed() ? "yes" : "no")
<< "\n";
}
+ if (m_p->m_init_options)
+ {
+ gdu = package.request().get();
+ if (gdu && gdu->which == Z_GDU_Z3950 &&
+ gdu->u.z3950->which == Z_APDU_initRequest)
+ {
+ m_p->m_file->out << receive_time << " " << m_p->m_msg;
+ m_p->m_file->out << " init options:";
+ yaz_init_opt_decode(gdu->u.z3950->u.initRequest->options,
+ option_write, m_p->m_file.get());
+ m_p->m_file->out << "\n";
+ }
+ }
+
if (m_p->m_req_apdu)
{
gdu = package.request().get();
<< "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;
+ 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();
}
}
-yf::Log::LFile::LFile(std::string fname) : m_fname(fname)
+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)
{
- out.open(fname.c_str());
}
void yf::Log::Rep::openfile(const std::string &fname)
return;
}
}
- LFilePtr newfile(new LFile(fname));
+ // 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;
}
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 =
"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 *)
ptr->name));
}
}
- if (!m_p->m_file)
- m_p->openfile("metaproxy.log");
}
static mp::filter::Base* filter_creator()