X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_zoom.cpp;h=2c70e94458ee600974e39329437cf4c940840ed8;hb=5d21a3cf208a7bc9951846dab4b8b6ff97b46863;hp=2ac339d0bab2d02973ae9d4b4a583b02c621717c;hpb=3094d68080f8bebd6c3b041899d37a3459796eb5;p=metaproxy-moved-to-github.git diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index 2ac339d..2c70e94 100644 --- a/src/filter_zoom.cpp +++ b/src/filter_zoom.cpp @@ -17,6 +17,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "config.hpp" + +#include +#include +#include #include "filter_zoom.hpp" #include #include @@ -49,7 +53,8 @@ namespace yf = mp::filter; namespace metaproxy_1 { namespace filter { - struct Zoom::Searchable : boost::noncopyable { + class Zoom::Searchable : boost::noncopyable { + public: std::string authentication; std::string cfAuth; std::string cfProxy; @@ -145,6 +150,7 @@ namespace metaproxy_1 { std::string file_path; std::string content_proxy_server; std::string content_tmp_file; + bool apdu_log; CCL_bibset bibset; std::string element_transform; std::string element_raw; @@ -360,9 +366,12 @@ void yf::Zoom::Impl::release_frontend(mp::Package &package) } } -yf::Zoom::Impl::Impl() : element_transform("pz2") , element_raw("raw") +yf::Zoom::Impl::Impl() : + apdu_log(false), element_transform("pz2") , element_raw("raw") { bibset = ccl_qual_mk(); + + srand((unsigned int) time(0)); } yf::Zoom::Impl::~Impl() @@ -519,7 +528,7 @@ void yf::Zoom::Impl::configure_local_records(const xmlNode *ptr, bool test_only) void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only, const char *path) { - content_tmp_file = "/tmp/mp_content_proxy."; + content_tmp_file = "/tmp/cf.XXXXXX.p"; if (path && *path) { file_path = path; @@ -587,6 +596,19 @@ void yf::Zoom::Impl::configure(const xmlNode *ptr, bool test_only, attr->name)); } } + else if (!strcmp((const char *) ptr->name, "log")) + { + const struct _xmlAttr *attr; + for (attr = ptr->properties; attr; attr = attr->next) + { + if (!strcmp((const char *) attr->name, "apdu")) + apdu_log = mp::xml::get_bool(attr->children, false); + else + throw mp::filter::FilterException( + "Bad attribute " + std::string((const char *) + attr->name)); + } + } else { throw mp::filter::FilterException @@ -713,7 +735,13 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( b->set_option("rpnCharset", sptr->query_encoding); b->set_option("timeout", "40"); + + if (m_p->apdu_log) + b->set_option("apdulog", "1"); + if (sptr->piggyback) + b->set_option("count", "10"); + b->set_option("piggyback", sptr->piggyback ? "1" : "0"); std::string authentication = sptr->authentication; std::string proxy = sptr->cfProxy; @@ -814,13 +842,19 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( } if (b->sptr->contentConnector.length()) { - int fd; - char *fname = (char *) xmalloc(m_p->content_tmp_file.length() + 8); strcpy(fname, m_p->content_tmp_file.c_str()); - strcat(fname, "XXXXXX"); - fd = mkstemp(fname); - + char *xx = strstr(fname, "XXXXXX"); + if (!xx) + { + xx = fname + strlen(fname); + strcat(fname, "XXXXXX"); + } + char tmp_char = xx[6]; + sprintf(xx, "%06d", ((unsigned) rand()) % 1000000); + xx[6] = tmp_char; + + int fd = creat(fname, 0666); if (fd == -1) { yaz_log(YLOG_WARN|YLOG_ERRNO, "create %s", fname); @@ -831,7 +865,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( BackendPtr backend_null; return backend_null; } - b->content_session_id.assign(fname + (strlen(fname) - 6)); + b->content_session_id.assign(xx, 6); WRBUF w = wrbuf_alloc(); wrbuf_puts(w, "#content_proxy\n"); wrbuf_printf(w, "connector: %s\n", b->sptr->contentConnector.c_str()); @@ -849,7 +883,6 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( yaz_log(YLOG_LOG, "file %s created\n", fname); xfree(fname); } - std::string url; if (sptr->sru.length()) @@ -895,7 +928,7 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start, number_to_present = 10000; ZOOM_record *recs = (ZOOM_record *) - odr_malloc(odr, number_to_present * sizeof(*recs)); + odr_malloc(odr, (size_t) number_to_present * sizeof(*recs)); char oid_name_str[OID_STR_MAX]; const char *syntax_name = 0; @@ -944,7 +977,7 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start, b->present(start, number_to_present, recs, error, addinfo, odr); - Odr_int i = 0; + int i = 0; if (!*error) { for (i = 0; i < number_to_present; i++)