*/
#include "config.hpp"
+
+#include <stdlib.h>
+#include <sys/types.h>
#include "filter_zoom.hpp"
#include <yaz/zoom.h>
#include <yaz/yaz-version.h>
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;
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;
+ std::string proxy;
std::map<std::string,SearchablePtr> s_map;
};
}
}
}
-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()
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;
element_transform = mp::xml::get_text(attr->children);
else if (!strcmp((const char *) attr->name, "element_raw"))
element_raw = mp::xml::get_text(attr->children);
+ else if (!strcmp((const char *) attr->name, "proxy"))
+ proxy = mp::xml::get_text(attr->children);
else
throw mp::filter::FilterException(
"Bad attribute " + std::string((const char *)
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
sptr = it->second;
else
{
- xmlDoc *doc = mp::get_searchable(m_p->torus_url, torus_db);
+ xmlDoc *doc = mp::get_searchable(m_p->torus_url, torus_db, m_p->proxy);
if (!doc)
{
*error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
if (ptr->type == XML_ELEMENT_NODE
&& !strcmp((const char *) ptr->name, "record"))
{
+ if (sptr)
+ {
+ *error = YAZ_BIB1_UNSPECIFIED_ERROR;
+ *addinfo = (char*) odr_malloc(odr, 40 + database.length()),
+ sprintf(*addinfo, "multiple records for udb=%s",
+ database.c_str());
+ xmlFreeDoc(doc);
+ BackendPtr b;
+ return b;
+ }
sptr = m_p->parse_torus_record(ptr);
- break;
}
}
}
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;
}
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);
-
- if (fd == -1)
+ 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;
+
+ FILE *file = fopen(fname, "w");
+ if (!file)
{
yaz_log(YLOG_WARN|YLOG_ERRNO, "create %s", fname);
*error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
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());
wrbuf_printf(w, "authentication: %s\n", authentication.c_str());
if (proxy.length())
wrbuf_printf(w, "proxy: %s\n", proxy.c_str());
- if (sptr->cfAuth.length())
- wrbuf_printf(w, "cfauth: %s\n", sptr->cfAuth.c_str());
if (sptr->cfProxy.length())
wrbuf_printf(w, "cfproxy: %s\n", sptr->cfProxy.c_str());
- write(fd, wrbuf_buf(w), wrbuf_len(w));
- close(fd);
+ fwrite(wrbuf_buf(w), 1, wrbuf_len(w), file);
+ fclose(file);
yaz_log(YLOG_LOG, "file %s created\n", fname);
xfree(fname);
}
-
std::string url;
if (sptr->sru.length())
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;
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++)