}
void mp::filter::Filter_myfilter::process(mp::Package & package) const
-{ // See src/filter_backend_test.cpp for a more comprehensive
+{ // See src/filter_backend_test.cpp for a more comprehensive
// example of a dummy Z-server
Z_GDU *gdu = package.request().get();
Z_APDU *apdu_res = 0;
return;
}
Z_APDU *apdu_req = gdu->u.z3950;
- if (apdu_req->which == Z_APDU_initRequest)
+ if (apdu_req->which == Z_APDU_initRequest)
{
yaz_log(YLOG_LOG, "myfilter::process: Init request");
- apdu_res= odr.create_initResponse( apdu_req,
+ apdu_res= odr.create_initResponse( apdu_req,
YAZ_BIB1_PERMANENT_SYSTEM_ERROR, "Not implemented!");
package.response() = apdu_res;
}
- else
+ else
{
yaz_log(YLOG_LOG, "myfilter::process: Unknown request type");
package.move(); // Send on to other filters
void mp::filter::Filter_myfilter::configure(const xmlNode *ptr, bool test_only)
{
yaz_log(YLOG_LOG, "myfilter::configure");
- for (ptr = ptr->children; ptr; ptr = ptr->next)
+ for (ptr = ptr->children; ptr; ptr = ptr->next)
{
if (ptr->type != XML_ELEMENT_NODE)
continue;
yaz_log(YLOG_LOG, "myfilter::configure: %s", msg.c_str() );
}
- else
+ else
{
throw mp::filter::FilterException("Bad element "
+ std::string((const char *) ptr->name));
class Base {
public:
virtual ~Base(){};
-
+
///sends Package off to next Filter, returns altered Package
virtual void process(Package & package) const = 0;
- /// configuration during filter load
+ /// configuration during filter load
virtual void configure(const xmlNode * ptr, bool test_only,
const char *path) = 0;
}
namespace metaproxy_1 {
-
+
class Origin {
public:
Origin();
-
+
/// set client IP info - left val in assignment
void set_tcpip_address(std::string addr, unsigned long id);
/// set max sockets (for outgoing connections to a given target)
int get_max_sockets();
-
+
/// get tcpip address
std::string get_address();
void set_custom_session(const std::string &s);
private:
- friend std::ostream&
+ friend std::ostream&
std::operator<<(std::ostream& os, const metaproxy_1::Origin& o);
-
+
std::string m_address;
unsigned int m_origin_id;
int m_max_sockets;
}
-namespace std
+namespace std
{
std::ostream& operator<<(std::ostream& os, const metaproxy_1::Package& p);
}
Package();
~Package();
-
- Package(metaproxy_1::Session &session,
+
+ Package(metaproxy_1::Session &session,
const metaproxy_1::Origin &origin);
/// copy constructor which copies route pos + logger
/// send Package to other route
void move(std::string route);
-
+
/// access session - left val in assignment
metaproxy_1::Session & session();
-
+
/// get function - right val in assignment
Origin origin() const;
-
+
/// set function - left val in assignment
Origin & origin();
-
+
/// set function - can be chained
Package & router(const Router &router);
yazpp_1::GDU &request();
yazpp_1::GDU &response();
-
+
/// get function - right val in assignment
Session session() const;
RoutePos *m_route_pos;
PackageLoggerPtr p_logger;
-
+
yazpp_1::GDU m_request_gdu;
yazpp_1::GDU m_response_gdu;
};
#include <string>
#include <stdexcept>
-namespace metaproxy_1
+namespace metaproxy_1
{
namespace filter {
class Base;
}
class RoutePos;
-
+
class RouterException : public std::runtime_error {
public:
RouterException(const std::string message)
: std::runtime_error("RouterException: " + message){};
};
-
+
class Router : boost::noncopyable {
public:
Router(){};
#include <boost/thread/mutex.hpp>
namespace metaproxy_1 {
-
+
class Session
{
//typedef unsigned long type;
public:
-
+
/// create new session with new unique id
Session() {
boost::mutex::scoped_lock scoped_lock(m_mutex);
m_id = m_global_id;
m_close = false;
}
-
+
/// copy session including old id
Session(const Session &s) : m_id(s.m_id), m_close(s.m_close) {};
-
- Session& operator=(const Session &s) {
+
+ Session& operator=(const Session &s) {
if (this != &s)
{
m_id = s.m_id;
bool operator<(const Session &s) const {
return m_id < s.m_id ? true : false;
}
-
+
unsigned long id() const {
return m_id;
}
-
+
bool is_closed() const {
return m_close;
}
-
+
/// mark session closed, can not be unset
void close() {
m_close = true;
bool operator == (Session &ses) const {
return ses.m_id == m_id;
}
-
+
private:
-
+
unsigned long int m_id;
bool m_close;
-
+
/// static mutex to lock static m_id
static boost::mutex m_mutex;
-
+
/// static m_id to make sure that there is only one id counter
static unsigned long int m_global_id;
-
+
};
template <class T> class session_map {
public:
- void create(T &t, const metaproxy_1::Session &s) {
+ void create(T &t, const metaproxy_1::Session &s) {
boost::mutex::scoped_lock lock(m_map_mutex);
m_map[s] = SessionItem(t);
};
boost::mutex m_map_mutex;
std::map<metaproxy_1::Session,SessionItem>m_map;
};
-
+
}
#endif
namespace metaproxy_1 {
namespace util {
-
- template<typename T>
+
+ template<typename T>
std::string to_string(const T& t)
{
std::ostringstream o;
if(o << t)
- return o.str();
+ return o.str();
return std::string();
};
- const char *
+ const char *
record_composition_to_esn(Z_RecordComposition *comp);
- std::string http_header_value(const Z_HTTP_Header* header,
+ std::string http_header_value(const Z_HTTP_Header* header,
const std::string name);
- std::string http_headers_debug(const Z_HTTP_Request &http_req);
+ std::string http_headers_debug(const Z_HTTP_Request &http_req);
- void http_response(metaproxy_1::Package &package,
- const std::string &content,
+ void http_response(metaproxy_1::Package &package,
+ const std::string &content,
int http_code = 200);
void split_zurl(std::string zurl, std::string &host,
std::list<std::string> &db);
-
+
void get_vhost_otherinfo(Z_OtherInformation *otherInformation,
std::list<std::string> &vhosts);
-
+
int remove_vhost_otherinfo(Z_OtherInformation **otherInformation,
std::list<std::string> &vhosts);
- void set_vhost_otherinfo(Z_OtherInformation **otherInformation,
+ void set_vhost_otherinfo(Z_OtherInformation **otherInformation,
ODR odr,
- const std::string vhost,
+ const std::string vhost,
const int cat);
void set_vhost_otherinfo(Z_OtherInformation **otherInformation,
odr();
~odr();
operator ODR() const;
- Z_APDU *create_close(const Z_APDU *in_apdu,
+ Z_APDU *create_close(const Z_APDU *in_apdu,
int reason, const char *addinfo);
- Z_APDU *create_initResponse(const Z_APDU *in_apdu,
+ Z_APDU *create_initResponse(const Z_APDU *in_apdu,
int error, const char *addinfo);
Z_APDU *create_searchResponse(const Z_APDU *in_apdu,
int error, const char *addinfo);
private:
WRBUF m_wrbuf;
};
-
+
class PlainFile {
class Rep;
boost::scoped_ptr<Rep> m_p;
std::string get_text(const xmlNode *ptr);
bool get_bool(const xmlNode *ptr, bool default_value);
int get_int(const xmlNode *ptr, int default_value);
- bool check_attribute(const _xmlAttr *ptr,
+ bool check_attribute(const _xmlAttr *ptr,
const std::string &ns,
const std::string &name);
- bool is_attribute(const _xmlAttr *ptr,
+ bool is_attribute(const _xmlAttr *ptr,
const std::string &ns,
const std::string &name);
- bool is_element(const xmlNode *ptr,
+ bool is_element(const xmlNode *ptr,
const std::string &ns,
const std::string &name);
bool is_element_mp(const xmlNode *ptr, const std::string &name);
- bool check_element_mp(const xmlNode *ptr,
+ bool check_element_mp(const xmlNode *ptr,
const std::string &name);
std::string get_route(const xmlNode *node);
std::string get_route(const xmlNode *node, std::string &auth);
const xmlNode* jump_to(const xmlNode* node, int node_type);
const xmlNode* jump_to_next(const xmlNode* node, int node_type);
-
+
const xmlNode* jump_to_children(const xmlNode* node, int node_type);
void check_empty(const xmlNode *node);
{
// std::cout << "Got Close.\n";
}
-
+
Z_GDU *gdu = package.request().get();
if (gdu && gdu->which == Z_GDU_HTTP_Request)
{
mp::odr odr;
Z_GDU *gdu = z_get_HTTP_Response(odr, 200);
Z_HTTP_Response *http_res = gdu->u.HTTP_Response;
-
+
z_HTTP_header_add(odr, &http_res->headers,
"Content-Type", "text/plain");
-
- http_res->content_buf =
+
+ http_res->content_buf =
odr_strdup(odr, "Welcome to Metaproxy");
http_res->content_len = strlen(http_res->content_buf);
-
+
package.response() = gdu;
}
return package.move();
int main(int argc, char **argv)
{
- try
+ try
{
std::vector<std::string> ports;
int duration = -1;
int ret;
char *arg;
- while ((ret = options("h{help}d{duration}:p{port}:",
+ while ((ret = options("h{help}d{duration}:p{port}:",
argv, argc, &arg)) != -2)
{
switch(ret)
mp::Session session;
mp::Origin origin;
mp::Package pack(session, origin);
-
- pack.router(router).move();
+
+ pack.router(router).move();
}
}
catch ( ... ) {
int main(int argc, char **argv)
{
- try
+ try
{
int ret;
char *arg;
char *fname = 0;
- while ((ret = options("h{help}c{config}:",
+ while ((ret = options("h{help}c{config}:",
argv, argc, &arg)) != -2)
{
switch(ret)
mp::RouterFleXML router(doc, factory, false, 0);
mp::Package pack;
-
+
pack.router(router).move();
xmlFreeDoc(doc);
namespace metaproxy_1 {
class FactoryFilter::Rep {
typedef std::map<std::string, CreateFilterCallback> CallbackMap;
- typedef std::map<std::string, CreateFilterCallback>::iterator
+ typedef std::map<std::string, CreateFilterCallback>::iterator
CallbackMapIt;
public:
friend class FactoryFilter;
bool mp::FactoryFilter::exist(std::string fi)
{
Rep::CallbackMap::const_iterator it = m_p->m_fcm.find(fi);
-
+
if (it == m_p->m_fcm.end())
{
return false;
mp::filter::Base* mp::FactoryFilter::create(std::string fi)
{
Rep::CallbackMap::const_iterator it = m_p->m_fcm.find(fi);
-
+
if (it == m_p->m_fcm.end()){
std::string msg = "filter type '" + fi + "' not found";
throw NotFound(msg);
if (!dl_handle)
{
const char *dl = dlerror();
- std::cout << "dlopen " << full_path << " failed. dlerror=" << dl <<
+ std::cout << "dlopen " << full_path << " failed. dlerror=" << dl <<
std::endl;
return false;
}
std::string full_name = "metaproxy_1_filter_" + fi;
-
+
void *dlsym_ptr = dlsym(dl_handle, full_name.c_str());
if (!dlsym_ptr)
{
class Rep;
public:
/// true if registration ok
-
+
FactoryFilter();
~FactoryFilter();
bool add_creator(const std::string &fi, CreateFilterCallback cfc);
-
+
bool drop_creator(std::string fi);
-
+
metaproxy_1::filter::Base* create(std::string fi);
bool exist(std::string fi);
-
+
bool add_creator_dl(const std::string &fi, const std::string &path);
bool have_dl_support();
&metaproxy_1_filter_cgi,
#endif
&metaproxy_1_filter_cql_to_rpn,
- &metaproxy_1_filter_frontend_net,
+ &metaproxy_1_filter_frontend_net,
&metaproxy_1_filter_http_file,
&metaproxy_1_filter_limit,
&metaproxy_1_filter_load_balance,
static bool contains(std::list<std::string> list, std::string thing) {
std::list<std::string>::const_iterator i;
for (i = list.begin(); i != list.end(); i++)
- if (mp::util::database_name_normalize(*i) ==
+ if (mp::util::database_name_normalize(*i) ==
mp::util::database_name_normalize(thing))
return true;
-
+
return false;
}
// Make an Search rejection APDU
mp::odr odr;
Z_APDU *apdu = odr.create_searchResponse(
- package.request().get()->u.z3950,
+ package.request().get()->u.z3950,
YAZ_BIB1_ACCESS_TO_SPECIFIED_DATABASE_DENIED,
req->databaseNames[i]);
package.response() = apdu;
// Make an Scan rejection APDU
mp::odr odr;
Z_APDU *apdu = odr.create_scanResponse(
- package.request().get()->u.z3950,
+ package.request().get()->u.z3950,
YAZ_BIB1_ACCESS_TO_SPECIFIED_DATABASE_DENIED,
req->databaseNames[i]);
package.response() = apdu;
}
-static void reject_init(mp::Package &package, int err, const char *addinfo) {
+static void reject_init(mp::Package &package, int err, const char *addinfo) {
if (err == 0)
err = YAZ_BIB1_INIT_AC_AUTHENTICATION_SYSTEM_ERROR;
// Make an Init rejection APDU
int *number_returned, int *next_position)
{
const char *element_set_name = "F"; // default to use
-
+
if (number + start - 1 > result_set_size || start < 1)
{
error_code = YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE;
{
if (esn->which != Z_ElementSetNames_generic)
{
- error_code
+ error_code
= YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_;
return 0;
}
element_set_name = esn->u.generic;
}
- if (!strcmp(element_set_name, "B")
+ if (!strcmp(element_set_name, "B")
&& !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_usmarc))
; // Brief
- else if (!strcmp(element_set_name, "F")
+ else if (!strcmp(element_set_name, "F")
&& !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_usmarc))
; // Full
- else if (!strncmp(element_set_name, "FF", 2)
+ else if (!strncmp(element_set_name, "FF", 2)
&& !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml))
; // Huge XML test record
else
{
- error_code
+ error_code
= YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_;
addinfo = std::string(element_set_name);
return 0;
Z_APDU *apdu_req = gdu->u.z3950;
Z_APDU *apdu_res = 0;
mp::odr odr;
-
- if (apdu_req->which != Z_APDU_initRequest &&
+
+ if (apdu_req->which != Z_APDU_initRequest &&
!m_p->m_sessions.exist(package.session()))
{
apdu_res = odr.create_close(apdu_req,
resp->implementationName = odr_strdup(odr, "backend_test");
if (ODR_MASK_GET(req->options, Z_Options_namedResultSets))
m_p->m_support_named_result_sets = true;
-
+
int i;
static const int masks[] = {
Z_Options_search, Z_Options_present,
- Z_Options_namedResultSets, -1
+ Z_Options_namedResultSets, -1
};
for (i = 0; masks[i] != -1; i++)
if (ODR_MASK_GET(req->options, masks[i]))
else if (apdu_req->which == Z_APDU_searchRequest)
{
Z_SearchRequest *req = apdu_req->u.searchRequest;
-
- if (!m_p->m_support_named_result_sets &&
+
+ if (!m_p->m_support_named_result_sets &&
strcmp(req->resultSetName, "default"))
{
- apdu_res =
+ apdu_res =
odr.create_searchResponse(
apdu_req, YAZ_BIB1_RESULT_SET_NAMING_UNSUPP, 0);
}
int error_code = 0;
std::string addinfo;
const char *element_set_name = 0;
-
+
Odr_int number = 0;
mp::util::piggyback_sr(req, result_set_size,
number, &element_set_name);
-
- if (number)
- { // not a large set for sure
+
+ if (number)
+ { // not a large set for sure
Z_ElementSetNames *esn;
if (number > *req->smallSetUpperBound)
esn = req->mediumSetElementSetNames;
}
if (error_code)
{
- apdu_res =
+ apdu_res =
odr.create_searchResponse(
apdu_req, error_code, addinfo.c_str());
Z_SearchResponse *resp = apdu_res->u.searchResponse;
}
else
{
- apdu_res =
+ apdu_res =
odr.create_searchResponse(apdu_req, 0, 0);
Z_SearchResponse *resp = apdu_res->u.searchResponse;
*resp->resultCount = result_set_size;
}
}
else if (apdu_req->which == Z_APDU_presentRequest)
- {
+ {
Z_PresentRequest *req = apdu_req->u.presentRequest;
int number_returned = 0;
int next_position = 0;
return;
}
package.session().close();
-
+
Z_GDU *zgdu = package.request().get();
-
+
if (!zgdu)
return;
-
+
//std::string message("BOUNCE ");
- std::ostringstream message;
+ std::ostringstream message;
message << "BOUNCE " << *zgdu;
-
- metaproxy_1::odr odr;
-
+
+ metaproxy_1::odr odr;
+
if (zgdu->which == Z_GDU_Z3950)
{
Z_APDU *apdu_res = 0;
else if (zgdu->which == Z_GDU_HTTP_Request)
{
Z_GDU *zgdu_res = 0;
- zgdu_res
- = odr.create_HTTP_Response(package.session(),
+ zgdu_res
+ = odr.create_HTTP_Response(package.session(),
zgdu->u.HTTP_Request, 400);
-
+
package.response() = zgdu_res;
}
else if (zgdu->which == Z_GDU_HTTP_Response)
{
}
-
+
return;
}
*/
// Filter that bounces all requests packages
-// No packages are ever passed to later filters in the chain
+// No packages are ever passed to later filters in the chain
#ifndef FILTER_BOUNCE_HPP
#define FILTER_BOUNCE_HPP
yf::CGI::CGI() : m_p(new Rep)
{
-
+
}
yf::CGI::Rep::~Rep()
{
std::map<pid_t,pid_t>::const_iterator it;
boost::mutex::scoped_lock lock(m_mutex);
-
+
for (it = children.begin(); it != children.end(); it++)
kill(it->second, SIGTERM);
}
{
Z_GDU *zgdu_req = package.request().get();
Z_GDU *zgdu_res = 0;
-
+
if (!zgdu_req)
return;
-
+
if (zgdu_req->which != Z_GDU_HTTP_Request)
{
package.move();
int r;
pid_t pid;
int status;
-
+
pid = ::fork();
switch (pid)
{
exec.program = mp::xml::get_text(attr->children);
else
throw mp::filter::FilterException
- ("Bad attribute "
+ ("Bad attribute "
+ std::string((const char *) attr->name)
+ " in cgi section");
}
}
else
{
- throw mp::filter::FilterException("Bad element "
+ throw mp::filter::FilterException("Bad element "
+ std::string((const char *)
ptr->name));
}
// define Pimpl wrapper forwarding to Impl
-
+
yf::CQLtoRPN::CQLtoRPN() : m_p(new Impl)
{
}
}
yf::CQLtoRPN::Impl::~Impl()
-{
+{
}
void yf::CQLtoRPN::Impl::configure(const xmlNode *xmlnode)
<conversion file="pqf.properties"/>
</filter>
*/
-
+
std::string fname;
for (xmlnode = xmlnode->children; xmlnode; xmlnode = xmlnode->next)
{
}
else
{
- throw mp::filter::FilterException("Bad element "
+ throw mp::filter::FilterException("Bad element "
+ std::string((const char *)
xmlnode->name));
}
char *addinfo = 0;
Z_RPNQuery *rpnquery = 0;
mp::odr odr;
-
+
int r = m_cql2rpn.query_transform(sr->query->u.type_104->u.cql,
&rpnquery, odr,
&addinfo);
if (r == -3)
{
- Z_APDU *f_apdu =
+ Z_APDU *f_apdu =
odr.create_searchResponse(
- apdu_req,
+ apdu_req,
YAZ_BIB1_TEMPORARY_SYSTEM_ERROR,
"Missing CQL to RPN configuration");
package.response() = f_apdu;
{
int error_code = yaz_diag_srw_to_bib1(r);
- Z_APDU *f_apdu =
+ Z_APDU *f_apdu =
odr.create_searchResponse(apdu_req, error_code, addinfo);
package.response() = f_apdu;
return;
}
else
{ // conversion OK
-
+
sr->query->which = Z_Query_type_1;
sr->query->u.type_1 = rpnquery;
package.request() = gdu;
ZAssocChild *m_assoc_child;
mp::Package *m_package;
Rep *m_p;
- };
+ };
class FrontendNet::ZAssocServer : public yazpp_1::Z_Assoc {
public:
~ZAssocServer();
yazpp_1::IPDU_Observable *the_PDU_Observable,
int fd);
void recv_GDU(Z_GDU *apdu, int len);
-
+
void failNotify();
void timeoutNotify();
void connectNotify();
yaz_timing_stop(timer);
double duration = yaz_timing_get_real(timer);
-
+
size_t ent = 0;
while (m_p->m_duration_lim[ent] != 0.0 && duration > m_p->m_duration_lim[ent])
ent++;
if (m_p->m_duration_max < duration)
m_p->m_duration_max = duration;
-
+
if (m_p->m_duration_min == 0.0 || m_p->m_duration_min > duration)
m_p->m_duration_min = duration;
-
+
if (m_p->m_msg_config.length())
{
Z_GDU *z_gdu = gdu->get();
-
+
std::ostringstream os;
os << m_p->m_msg_config << " "
<< *m_package << " "
<< std::fixed << std::setprecision (6) << duration << " ";
-
- if (z_gdu)
+
+ if (z_gdu)
os << *z_gdu;
else
os << "-";
-
+
yaz_log(YLOG_LOG, "%s %s", os.str().c_str(), t_info);
}
}
mp::odr odr;
int len;
Z_APDU *apdu_response = odr.create_close(
- z_gdu->u.z3950, Z_Close_systemProblem,
+ z_gdu->u.z3950, Z_Close_systemProblem,
"unhandled Z39.50 request");
m_assoc_child->send_Z_PDU(apdu_response, &len);
// For HTTP, respond with Server Error
int len;
mp::odr odr;
- Z_GDU *zgdu_res
- = odr.create_HTTP_Response(m_package->session(),
+ Z_GDU *zgdu_res
+ = odr.create_HTTP_Response(m_package->session(),
z_gdu->u.HTTP_Request, 500);
m_assoc_child->send_GDU(zgdu_res, &len);
}
{
m_assoc_child->close();
}
-
+
delete this;
}
-mp::IThreadPoolMsg *yf::FrontendNet::ThreadPoolPackage::handle()
+mp::IThreadPoolMsg *yf::FrontendNet::ThreadPoolPackage::handle()
{
m_package->move(m_assoc_child->m_route);
return this;
void yf::FrontendNet::ZAssocChild::report(Z_HTTP_Request *hreq)
{
mp::odr o;
-
+
Z_GDU *gdu_res = o.create_HTTP_Response(m_session, hreq, 200);
-
+
Z_HTTP_Response *hres = gdu_res->u.HTTP_Response;
-
+
mp::wrbuf w;
size_t i;
int number_total = 0;
-
+
for (i = 0; m_p->m_duration_lim[i] != 0.0; i++)
number_total += m_p->m_duration_freq[i];
number_total += m_p->m_duration_freq[i];
-
+
wrbuf_puts(w, "<?xml version=\"1.0\"?>\n");
wrbuf_puts(w, "<frontend_net>\n");
wrbuf_printf(w, " <responses frequency=\"%d\">\n", number_total);
i > 0 ? m_p->m_duration_lim[i - 1] : 0.0,
m_p->m_duration_lim[i], m_p->m_duration_freq[i]);
}
-
+
if (m_p->m_duration_freq[i] > 0)
wrbuf_printf(
w, " <response duration_start=\"%f\" frequency=\"%d\"/>\n",
wrbuf_printf(
w, " <response duration_average=\"%f\"/>\n",
m_p->m_duration_total / number_total);
-
+
wrbuf_puts(w, " </responses>\n");
-
+
int thread_busy;
int thread_total;
m_thread_pool_observer->get_thread_info(thread_busy, thread_total);
-
+
wrbuf_printf(w, " <thread_info busy=\"%d\" total=\"%d\"/>\n",
thread_busy, thread_total);
-
+
wrbuf_puts(w, "</frontend_net>\n");
-
+
hres->content_len = w.len();
hres->content_buf = (char *) w.buf();
-
+
int len;
send_GDU(gdu_res, &len);
}
if (m_p->m_msg_config.length())
{
- if (z_pdu)
+ if (z_pdu)
{
std::ostringstream os;
os << m_p->m_msg_config << " "
<< *p << " "
- << "0.000000" << " "
+ << "0.000000" << " "
<< *z_pdu;
yaz_log(YLOG_LOG, "%s", os.str().c_str());
}
}
- m_thread_pool_observer->put(tp);
+ m_thread_pool_observer->put(tp);
}
void yf::FrontendNet::ZAssocChild::failNotify()
yazpp_1::IPDU_Observable *PDU_Observable,
std::string route,
Rep *rep)
- :
+ :
Z_Assoc(PDU_Observable), m_route(route), m_p(rep)
{
m_package = 0;
yf::FrontendNet::My_Timer_Thread::My_Timer_Thread(
yazpp_1::ISocketObservable *obs,
- int duration) :
+ int duration) :
m_obs(obs), m_pipe(9123), m_timeout(false)
{
obs->addObserver(m_pipe.read_fd(), this);
if (m_p->m_listen_duration)
tt = new My_Timer_Thread(&m_p->mySocketManager,
m_p->m_listen_duration);
-
+
ThreadPoolSocketObserver tp(&m_p->mySocketManager, m_p->m_no_threads);
for (i = 0; i<m_p->m_ports.size(); i++)
}
port.port = mp::xml::get_text(ptr);
ports.push_back(port);
-
+
}
else if (!strcmp((const char *) ptr->name, "threads"))
{
std::string threads_str = mp::xml::get_text(ptr);
int threads = atoi(threads_str.c_str());
if (threads < 1)
- throw yf::FilterException("Bad value for threads: "
+ throw yf::FilterException("Bad value for threads: "
+ threads_str);
m_p->m_no_threads = threads;
}
std::string timeout_str = mp::xml::get_text(ptr);
int timeout = atoi(timeout_str.c_str());
if (timeout < 1)
- throw yf::FilterException("Bad value for timeout: "
+ throw yf::FilterException("Bad value for timeout: "
+ timeout_str);
m_p->m_session_timeout = timeout;
}
}
else
{
- throw yf::FilterException("Bad element "
+ throw yf::FilterException("Bad element "
+ std::string((const char *)
ptr->name));
}
void yf::FrontendNet::set_ports(std::vector<Port> &ports)
{
m_p->m_ports = ports;
-
+
m_p->az = new yf::FrontendNet::ZAssocServer *[m_p->m_ports.size()];
-
+
// Create yf::FrontendNet::ZAssocServer for each port
size_t i;
for (i = 0; i<m_p->m_ports.size(); i++)
{
// create a PDU assoc object (one per yf::FrontendNet::ZAssocServer)
yazpp_1::PDU_Assoc *as = new yazpp_1::PDU_Assoc(&m_p->mySocketManager);
-
+
// create ZAssoc with PDU Assoc
m_p->az[i] = new yf::FrontendNet::ZAssocServer(
as, m_p->m_ports[i].route, m_p.get());
if (m_p->az[i]->server(m_p->m_ports[i].port.c_str()))
{
- throw yf::FilterException("Unable to bind to address "
+ throw yf::FilterException("Unable to bind to address "
+ std::string(m_p->m_ports[i].port));
}
}
{
std::string file_part = fname;
std::string::size_type p = fname.find_last_of('/');
-
+
if (p != std::string::npos)
file_part = fname.substr(p+1);
std::string &fname, mp::Package &package)
{
mp::odr o;
-
+
FILE *f = fopen(fname.c_str(), "rb");
if (!f)
{
}
}
fclose(f);
-
+
std::string content_type = get_mime_type(fname);
z_HTTP_header_add(o, &hres->headers,
bool sane = true;
std::string::size_type p;
std::string path = req->path;
-
+
p = path.find("#");
if (p != std::string::npos)
path = path.erase(p);
}
package.move();
}
-
+
void yf::HttpFile::process(mp::Package &package) const
{
Z_GDU *gdu = package.request().get();
throw mp::filter::FilterException
("Can not open mime types file " + fname);
}
-
+
std::vector<std::string> args;
while (f.getline(args))
{
{
if (a_node->type != XML_ELEMENT_NODE)
continue;
-
+
if (mp::xml::is_element_mp(a_node, "documentroot"))
a.m_file_root = mp::xml::get_text(a_node);
else if (mp::xml::is_element_mp(a_node, "prefix"))
a.m_url_path_prefix = mp::xml::get_text(a_node);
else
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) a_node->name)
+ " in area section"
);
else
{
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) ptr->name)
+ " in virt_db filter");
}
}
// define Pimpl wrapper forwarding to Impl
-
+
yf::Limit::Limit() : m_p(new Impl)
{
}
}
yf::Limit::Impl::~Impl()
-{
+{
}
void yf::Limit::Impl::configure(const xmlNode *ptr)
}
else
{
- throw mp::filter::FilterException("Bad element "
+ throw mp::filter::FilterException("Bad element "
+ std::string((const char *)
ptr->name));
}
yf::Limit::Ses *ses = 0;
- std::map<mp::Session,yf::Limit::Ses *>::iterator it =
+ std::map<mp::Session,yf::Limit::Ses *>::iterator it =
m_sessions.find(package.session());
if (it != m_sessions.end())
ses = it->second;
yf::Limit::Ses *ses = 0;
- std::map<mp::Session,yf::Limit::Ses *>::iterator it =
+ std::map<mp::Session,yf::Limit::Ses *>::iterator it =
m_sessions.find(package.session());
if (it != m_sessions.end())
ses = it->second;
}
sz += package.response().get_size();
-
+
ses->bw_stat.add_bytes(sz);
ses->pdu_stat.add_bytes(1);
-
+
int bw_total = ses->bw_stat.get_total();
int pdu_total = ses->pdu_stat.get_total();
int search_total = ses->search_stat.get_total();
-
+
if (m_search_max)
reduce += search_total / m_search_max;
if (m_bw_max)
void process(metaproxy_1::Package & package);
void configure(const xmlNode * ptr);
private:
- // statistic manipulating functions,
+ // statistic manipulating functions,
void add_dead(unsigned long session_id);
//void clear_dead(unsigned long session_id);
void add_package(unsigned long session_id);
}
// define Pimpl wrapper forwarding to Impl
-
+
yf::LoadBalance::LoadBalance() : m_p(new Impl)
{
}
}
yf::LoadBalance::Impl::~Impl()
-{
+{
}
void yf::LoadBalance::Impl::configure(const xmlNode *xmlnode)
void yf::LoadBalance::Impl::process(mp::Package &package)
{
bool is_closed_front = false;
-
+
// checking for closed front end packages
if (package.session().is_closed())
{
is_closed_front = true;
- }
+ }
Z_GDU *gdu_req = package.request().get();
init_pkg.copy_filter(package);
unsigned int cost = std::numeric_limits<unsigned int>::max();
- {
+ {
boost::mutex::scoped_lock scoped_lock(m_mutex);
-
+
for (; ivh != vhosts.end(); )
{
if ((*ivh).size() != 0)
{
- unsigned int vhcost
+ unsigned int vhcost
= yf::LoadBalance::Impl::cost(*ivh);
yaz_log(YLOG_LOG, "Consider %s cost=%u vhcost=%u",
(*ivh).c_str(), cost, vhcost);
if (target.length() == 0)
break;
// copying new target into init package
-
+
yazpp_1::GDU init_gdu(base_req);
Z_InitRequest *init_req = init_gdu.get()->u.z3950->u.initRequest;
-
- mp::util::set_vhost_otherinfo(&(init_req->otherInfo),
+
+ mp::util::set_vhost_otherinfo(&(init_req->otherInfo),
odr_en, target, 1);
-
+
init_pkg.request() = init_gdu;
-
- // moving all package types
+
+ // moving all package types
init_pkg.move();
-
+
// checking for closed back end packages
if (!init_pkg.session().is_closed())
{
else if (gdu_req->u.z3950->which == Z_APDU_close)
{
is_closed_front = true;
- boost::mutex::scoped_lock scoped_lock(m_mutex);
+ boost::mutex::scoped_lock scoped_lock(m_mutex);
add_package(package.session().id());
- }
+ }
// any other Z39.50 package is added to statistics
else
{
- boost::mutex::scoped_lock scoped_lock(m_mutex);
+ boost::mutex::scoped_lock scoped_lock(m_mutex);
add_package(package.session().id());
}
}
- // moving all package types
+ // moving all package types
package.move();
bool is_closed_back = false;
is_closed_back = true;
boost::mutex::scoped_lock scoped_lock(m_mutex);
remove_package(package.session().id());
- }
+ }
// any other Z39.50 package is removed from statistics
else
{
{
boost::mutex::scoped_lock scoped_lock(m_mutex);
- // marking backend dead if backend closed without fronted close
+ // marking backend dead if backend closed without fronted close
if (is_closed_front == false)
add_dead(package.session().id());
package.session().close();
}
}
-
-// statistic manipulating functions,
+
+// statistic manipulating functions,
void yf::LoadBalance::Impl::add_dead(unsigned long session_id)
{
std::string target = find_session_target(session_id);
if (target.size() != 0)
{
- std::map<std::string, TargetStat>::iterator itarg;
+ std::map<std::string, TargetStat>::iterator itarg;
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end()
&& itarg->second.deads < std::numeric_limits<unsigned int>::max())
{
itarg->second.deads += 1;
- // std:.cout << "add_dead " << session_id << " " << target
+ // std:.cout << "add_dead " << session_id << " " << target
// << " d:" << itarg->second.deads << "\n";
}
}
if (target.size() != 0)
{
- std::map<std::string, TargetStat>::iterator itarg;
+ std::map<std::string, TargetStat>::iterator itarg;
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end()
- && itarg->second.packages
+ && itarg->second.packages
< std::numeric_limits<unsigned int>::max())
{
itarg->second.packages += 1;
if (target.size() != 0)
{
- std::map<std::string, TargetStat>::iterator itarg;
+ std::map<std::string, TargetStat>::iterator itarg;
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end()
&& itarg->second.packages > 0)
}
}
-void yf::LoadBalance::Impl::add_session(unsigned long session_id,
+void yf::LoadBalance::Impl::add_session(unsigned long session_id,
std::string target)
{
// finding and adding session
stat.packages = 0;
stat.deads = 0;
m_target_stat.insert(std::make_pair(target, stat));
- }
+ }
else if (itarg->second.sessions < std::numeric_limits<unsigned int>::max())
{
itarg->second.sessions += 1;
m_session_target.erase(isess);
return;
}
-
+
// counting session down
if (itarg->second.sessions > 0)
itarg->second.sessions -= 1;
if (target.size() != 0)
{
- std::map<std::string, TargetStat>::iterator itarg;
+ std::map<std::string, TargetStat>::iterator itarg;
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end())
cost = itarg->second.cost();
if (target.size() != 0)
{
- std::map<std::string, TargetStat>::iterator itarg;
+ std::map<std::string, TargetStat>::iterator itarg;
itarg = m_target_stat.find(target);
if (itarg != m_target_stat.end())
dead = itarg->second.deads;
private:
void openfile(const std::string &fname);
// needs to be static to be called by C pointer-to-function-syntax
- static void stream_write(ODR o, void *handle, int type,
+ static void stream_write(ODR o, void *handle, int type,
const char *buf, int len);
// needs to be static to be called by C pointer-to-function-syntax
static void option_write(const char *name, void *handle);
bool m_init_options;
LFilePtr m_file;
std::string m_time_format;
- // Only used during confiqgure stage (no threading),
- // for performance avoid opening files which other log filter
+ // Only used during confiqgure stage (no threading),
+ // for performance avoid opening files which other log filter
// instances already have opened
static std::list<LFilePtr> filter_log_files;
std::ostringstream &os);
void flush();
};
-
+
}
}
// define Pimpl wrapper forwarding to Impl
-
+
yf::Log::Log() : m_p(new Impl)
{
}
}
-yf::Log::Impl::~Impl()
+yf::Log::Impl::~Impl()
{
}
wrbuf_puts(w, "-");
}
wrbuf_printf(w, " ID:%s Name:%s Version:%s",
- req->implementationId ? req->implementationId :"-",
+ req->implementationId ? req->implementationId :"-",
req->implementationName ?req->implementationName : "-",
req->implementationVersion ?
req->implementationVersion : "-");
{
wrbuf_puts(w, "ERROR ");
log_DiagRecs(
- w,
+ w,
res->records->u.multipleNonSurDiagnostics->num_diagRecs,
res->records->u.multipleNonSurDiagnostics->diagRecs);
}
{
wrbuf_puts(w, "ERROR ");
log_DiagRecs(
- w,
+ w,
res->records->u.multipleNonSurDiagnostics->num_diagRecs,
res->records->u.multipleNonSurDiagnostics->diagRecs);
}
wrbuf_puts(w, " ");
assert(req->preferredRecordSyntax);
log_syntax(w, req->preferredRecordSyntax);
-
+
wrbuf_printf(w, " %s " ODR_INT_PRINTF "+" ODR_INT_PRINTF " ",
req->resultSetId, *req->resultSetStartPoint,
*req->numberOfRecordsRequested);
wrbuf_puts(w, "ERROR");
else
wrbuf_printf(w, "PARTIAL" ODR_INT_PRINTF, *res->scanStatus);
-
- wrbuf_printf(w, " " ODR_INT_PRINTF " " ODR_INT_PRINTF "+"
+
+ wrbuf_printf(w, " " ODR_INT_PRINTF " " ODR_INT_PRINTF "+"
ODR_INT_PRINTF "+" ODR_INT_PRINTF " ",
res->numberOfEntriesReturned ?
*res->numberOfEntriesReturned : 0,
*req->preferredPositionInResponse : 1,
*req->numberOfTermsRequested,
res->stepSize ? *res->stepSize : 1);
-
- yaz_scan_to_wrbuf(w, req->termListAndStartPoint,
+
+ yaz_scan_to_wrbuf(w, req->termListAndStartPoint,
req->attributeSet);
}
break;
if (*res->sortStatus == Z_SortResponse_success)
wrbuf_puts(w, "OK");
- else if (*res->sortStatus == Z_SortResponse_partial_1)
+ else if (*res->sortStatus == Z_SortResponse_partial_1)
wrbuf_puts(w, "PARTIAL");
else if (*res->sortStatus == Z_SortResponse_failure)
wrbuf_puts(w, "ERROR");
if (res->diagnostics && res->num_diagnostics >= 1)
log_DiagRecs(w, res->num_diagnostics,res->diagnostics);
else
- wrbuf_puts(w, "-");
+ wrbuf_puts(w, "-");
}
break;
case Z_APDU_close:
{
if (gdu_req && gdu_req->which == Z_GDU_Z3950)
{
- log_1line_Z_APDU(gdu_req->u.z3950,
+ log_1line_Z_APDU(gdu_req->u.z3950,
(gdu_res && gdu_res->which == Z_GDU_Z3950) ?
gdu_res->u.z3950 : 0, w);
}
}
else if (!strcmp((const char *) attr->name,
"request-session"))
- m_req_session =
+ m_req_session =
mp::xml::get_bool(attr->children, true);
- else if (!strcmp((const char *) attr->name,
+ else if (!strcmp((const char *) attr->name,
"response-session"))
- m_res_session =
+ m_res_session =
mp::xml::get_bool(attr->children, true);
else if (!strcmp((const char *) attr->name,
"session"))
{
- m_req_session =
+ m_req_session =
mp::xml::get_bool(attr->children, true);
m_res_session = m_req_session;
}
- else if (!strcmp((const char *) attr->name,
+ else if (!strcmp((const char *) attr->name,
"init-options"))
- m_init_options =
+ m_init_options =
mp::xml::get_bool(attr->children, true);
- else if (!strcmp((const char *) attr->name,
+ else if (!strcmp((const char *) attr->name,
"init-options"))
- m_init_options =
+ m_init_options =
mp::xml::get_bool(attr->children, true);
else
throw mp::filter::FilterException(
}
else
{
- throw mp::filter::FilterException("Bad element "
+ throw mp::filter::FilterException("Bad element "
+ std::string((const char *)
ptr->name));
}
// scope for session lock
{
boost::mutex::scoped_lock scoped_lock(m_session_mutex);
-
+
if (gdu_req && gdu_req->which == Z_GDU_Z3950)
{
Z_APDU *apdu_req = gdu_req->u.z3950;
user = a->u.idPass->userId;
else if (a->which == Z_IdAuthentication_open)
user = a->u.open;
-
+
m_sessions[package.session()] = user;
}
}
}
- std::map<mp::Session,std::string>::iterator it =
+ std::map<mp::Session,std::string>::iterator it =
m_sessions.find(package.session());
if (it != m_sessions.end())
user = it->second;
-
+
if (package.session().is_closed())
m_sessions.erase(package.session());
}
// scope for locking Ostream
- {
+ {
boost::mutex::scoped_lock scoped_lock(m_file->m_mutex);
-
+
if (m_access)
{
- if (gdu_req)
+ if (gdu_req)
{
std::ostringstream os;
os << m_msg_config << " "
<< package << " "
- << "0.000000" << " "
+ << "0.000000" << " "
<< *gdu_req;
m_file->log(m_time_format, os);
}
if (m_user_access)
{
- if (gdu_req)
+ if (gdu_req)
{
std::ostringstream os;
os << m_msg_config << " " << user << " "
<< package << " "
- << "0.000000" << " "
+ << "0.000000" << " "
<< *gdu_req;
m_file->log(m_time_format, os);
}
std::ostringstream os;
os << m_msg_config;
os << " request id=" << package.session().id();
- os << " close="
+ os << " close="
<< (package.session().is_closed() ? "yes" : "no");
m_file->log(m_time_format, os);
}
m_file->log(m_time_format, os);
}
}
-
+
if (m_req_apdu)
{
if (gdu_req)
}
}
}
-
+
// unlocked during move
package.move();
yaz_timing_stop(timer);
double duration = yaz_timing_get_real(timer);
- // scope for locking Ostream
- {
+ // scope for locking Ostream
+ {
boost::mutex::scoped_lock scoped_lock(m_file->m_mutex);
-
+
if (m_1line)
{
mp::wrbuf w;
-
+
log_1line_Z_GDU(gdu_req, gdu_res, w);
if (w.len() > 0)
{
<< std::fixed << std::setprecision (6) << duration << " "
<< *gdu_res;
m_file->log(m_time_format, os);
- }
+ }
}
if (m_res_session)
std::ostringstream os;
os << m_msg_config;
os << " response id=" << package.session().id();
- os << " close="
+ os << " close="
<< (package.session().is_closed() ? "yes " : "no ")
- << "duration="
+ << "duration="
<< std::fixed << std::setprecision (6) << duration;
m_file->log(m_time_format, os);
}
m_file->log(m_time_format, os);
}
}
-
+
if (m_res_apdu)
{
if (gdu_res)
}
-yf::Log::Impl::LFile::LFile(std::string fname) :
+yf::Log::Impl::LFile::LFile(std::string fname) :
m_fname(fname)
-
+
{
if (fname.c_str())
fhandle = fopen(fname.c_str(), "a");
}
fputs(os.str().c_str(), fhandle);
fputc('\n', fhandle);
- }
+ }
else
yaz_log(YLOG_LOG, "%s", os.str().c_str());
}
BackendPtr m_backend;
int m_pos; // position for backend (1=first, 2=second,..
int m_start; // present request start
- PresentJob(BackendPtr ptr, int pos) :
+ PresentJob(BackendPtr ptr, int pos) :
m_backend(ptr), m_pos(pos), m_start(0) {};
};
FrontendSet(std::string setname);
void scan2(Package &package, Z_APDU *apdu);
void relay_apdu(Package &package, Z_APDU *apdu);
Rep *m_p;
- };
+ };
class Multi::Map {
std::string m_target_pattern;
std::string m_route;
std::string m_auth;
public:
- Map(std::string pattern, std::string route, std::string auth) :
+ Map(std::string pattern, std::string route, std::string auth) :
m_target_pattern(pattern), m_route(route), m_auth(auth) {};
bool match(const std::string target, std::string *ret,
std::string *auth) const {
class Multi::Rep {
friend class Multi;
friend struct Frontend;
-
+
Rep();
FrontendPtr get_frontend(Package &package);
void release_frontend(Package &package);
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::Multi::FrontendPtr>::iterator it;
-
+
while(true)
{
it = m_clients.find(package.session());
if (it == m_clients.end())
break;
-
+
if (!it->second->m_in_use)
{
it->second->m_in_use = true;
{
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::Multi::FrontendPtr>::iterator it;
-
+
it = m_clients.find(package.session());
if (it != m_clients.end())
{
}
-void yf::Multi::Backend::operator() (void)
+void yf::Multi::Backend::operator() (void)
{
m_package->move(m_route);
}
std::list<BackendSet>::const_iterator bsit;
int voffset = 0;
int offset = start + i - 1;
- for (bsit = m_backend_sets.begin(); bsit != m_backend_sets.end();
+ for (bsit = m_backend_sets.begin(); bsit != m_backend_sets.end();
bsit++)
{
if (offset >= voffset && offset < voffset + bsit->m_count)
// Yes. skip until start.. Rounding off is deliberate!
min = (start-p) / no_left;
p += no_left * min;
-
+
// update positions in each set..
std::list<int>::iterator psit = pos.begin();
for (psit = pos.begin(); psit != pos.end(); psit++)
}
// skip on each set.. before "present range"..
p = p + skip;
-
+
std::list<int>::iterator psit = pos.begin();
for (psit = pos.begin(); psit != pos.end(); psit++)
*psit += min;
-
+
omin = min; // update so we consider next class (with higher count)
}
#endif
}
m_is_multi = true;
- // create init request
+ // create init request
std::list<BackendPtr>::iterator bit;
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
mp::odr odr;
BackendPtr b = *bit;
Z_APDU *init_apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
std::list<std::string>vhost_one;
vhost_one.push_back(b->m_vhost);
mp::util::set_vhost_otherinfo(&init_apdu->u.initRequest->otherInfo,
}
else
breq->idAuthentication = req->idAuthentication;
-
+
*breq->preferredMessageSize = *req->preferredMessageSize;
*breq->maximumRecordSize = *req->maximumRecordSize;
ODR_MASK_SET(breq->options, Z_Options_present);
ODR_MASK_SET(breq->options, Z_Options_namedResultSets);
ODR_MASK_SET(breq->options, Z_Options_scan);
-
+
ODR_MASK_SET(breq->protocolVersion, Z_ProtocolVersion_1);
ODR_MASK_SET(breq->protocolVersion, Z_ProtocolVersion_2);
ODR_MASK_SET(breq->protocolVersion, Z_ProtocolVersion_3);
-
+
b->m_package->request() = init_apdu;
b->m_package->copy_filter(package);
ODR_MASK_SET(f_resp->options, Z_Options_present);
ODR_MASK_SET(f_resp->options, Z_Options_namedResultSets);
ODR_MASK_SET(f_resp->options, Z_Options_scan);
-
+
ODR_MASK_SET(f_resp->protocolVersion, Z_ProtocolVersion_1);
ODR_MASK_SET(f_resp->protocolVersion, Z_ProtocolVersion_2);
ODR_MASK_SET(f_resp->protocolVersion, Z_ProtocolVersion_3);
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); )
{
PackagePtr p = (*bit)->m_package;
-
+
if (p->session().is_closed())
{
// failed. Remove from list and increment number of failed
}
else
{
- if (!f_resp->userInformationField
+ if (!f_resp->userInformationField
&& b_resp->userInformationField)
f_resp->userInformationField = b_resp->userInformationField;
no_failed++;
void yf::Multi::Frontend::search(mp::Package &package, Z_APDU *apdu_req)
{
- // create search request
+ // create search request
Z_SearchRequest *req = apdu_req->u.searchRequest;
// save these for later
Odr_int smallSetUpperBound = *req->smallSetUpperBound;
Odr_int largeSetLowerBound = *req->largeSetLowerBound;
Odr_int mediumSetPresentNumber = *req->mediumSetPresentNumber;
-
+
// they are altered now - to disable piggyback
*req->smallSetUpperBound = 0;
*req->largeSetLowerBound = 1;
{
PackagePtr p = (*bit)->m_package;
mp::odr odr;
-
+
if (!mp::util::set_databases_from_zurl(odr, (*bit)->m_vhost,
&req->num_databaseNames,
&req->databaseNames))
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
PackagePtr p = (*bit)->m_package;
-
+
// save closing package for at least one target
- if (p->session().is_closed())
+ if (p->session().is_closed())
close_p = p;
Z_GDU *gdu = p->response().get();
{
Z_APDU *b_apdu = gdu->u.z3950;
Z_SearchResponse *b_resp = b_apdu->u.searchResponse;
-
+
// see we get any errors (AKA diagnstics)
if (b_resp->records)
{
*p_req->numberOfRecordsRequested = number;
pp.request() = p_apdu;
present(pp, p_apdu);
-
+
if (pp.session().is_closed())
package.session().close();
-
+
Z_GDU *gdu = pp.response().get();
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_presentResponse)
{
Z_PresentResponse *p_res = gdu->u.z3950->u.presentResponse;
f_resp->records = p_res->records;
- *f_resp->numberOfRecordsReturned =
+ *f_resp->numberOfRecordsReturned =
*p_res->numberOfRecordsReturned;
- *f_resp->nextResultSetPosition =
+ *f_resp->nextResultSetPosition =
*p_res->nextResultSetPosition;
}
- else
+ else
{
- package.response() = pp.response();
+ package.response() = pp.response();
return;
}
}
void yf::Multi::Frontend::present(mp::Package &package, Z_APDU *apdu_req)
{
- // create present request
+ // create present request
Z_PresentRequest *req = apdu_req->u.presentRequest;
Sets_it it;
if (it == m_sets.end())
{
mp::odr odr;
- Z_APDU *apdu =
+ Z_APDU *apdu =
odr.create_presentResponse(
apdu_req,
YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
*req->resultSetStartPoint = start;
*req->numberOfRecordsRequested = end - start + 1;
-
+
p->request() = apdu_req;
p->copy_filter(package);
for (; pbit != present_backend_list.end(); pbit++)
{
PackagePtr p = (*pbit)->m_package;
-
+
if (p->session().is_closed()) // if any backend closes, close frontend
package.session().close();
-
+
Z_GDU *gdu = p->response().get();
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_presentResponse)
{
Z_APDU *b_apdu = gdu->u.z3950;
Z_PresentResponse *b_resp = b_apdu->u.presentResponse;
-
+
// see we get any errors (AKA diagnstics)
if (b_resp->records)
{
}
else
{
- // if any target does not return present response - return that
+ // if any target does not return present response - return that
package.response() = p->response();
return;
}
}
else if (number < 0 || (size_t) number > jobs.size())
{
- f_apdu =
+ f_apdu =
odr.create_presentResponse(
apdu_req,
YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE,
for (jit = jobs.begin(); jit != jobs.end(); jit++, i++)
{
PackagePtr p = jit->m_backend->m_package;
-
+
Z_GDU *gdu = p->response().get();
Z_APDU *b_apdu = gdu->u.z3950;
Z_PresentResponse *b_resp = b_apdu->u.presentResponse;
if (m_backend_list.size() > 1)
{
mp::odr odr;
- Z_APDU *f_apdu =
+ Z_APDU *f_apdu =
odr.create_scanResponse(
apdu_req, YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP, 0);
package.response() = f_apdu;
{
PackagePtr p = (*bit)->m_package;
mp::odr odr;
-
+
if (!mp::util::set_databases_from_zurl(odr, (*bit)->m_vhost,
&req->num_databaseNames,
&req->databaseNames))
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
PackagePtr p = (*bit)->m_package;
-
+
if (p->session().is_closed()) // if any backend closes, close frontend
package.session().close();
-
+
Z_GDU *gdu = p->response().get();
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_scanResponse)
}
else
{
- // if any target does not return scan response - return that
+ // if any target does not return scan response - return that
package.response() = p->response();
return;
}
{
PackagePtr p = (*bit)->m_package;
mp::odr odr;
-
+
p->request() = apdu_req;
p->copy_filter(package);
}
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
PackagePtr p = (*bit)->m_package;
-
+
if (p->session().is_closed()) // if any backend closes, close frontend
package.session().close();
-
+
package.response() = p->response();
}
}
{
PackagePtr p = (*bit)->m_package;
mp::odr odr;
-
+
if (!mp::util::set_databases_from_zurl(odr, (*bit)->m_vhost,
&req->num_databaseNames,
&req->databaseNames))
for (bit = m_backend_list.begin(); bit != m_backend_list.end(); bit++)
{
PackagePtr p = (*bit)->m_package;
-
+
if (p->session().is_closed()) // if any backend closes, close frontend
package.session().close();
-
+
Z_GDU *gdu = p->response().get();
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_scanResponse)
Z_APDU *f_apdu = odr.create_scanResponse(apdu_req, 1, 0);
Z_ScanResponse *f_res = f_apdu->u.scanResponse;
- f_res->entries->nonsurrogateDiagnostics =
+ f_res->entries->nonsurrogateDiagnostics =
res->entries->nonsurrogateDiagnostics;
- f_res->entries->num_nonsurrogateDiagnostics =
+ f_res->entries->num_nonsurrogateDiagnostics =
res->entries->num_nonsurrogateDiagnostics;
package.response() = f_apdu;
}
if (my.m_norm_term.length())
{
- ScanTermInfoList::iterator it =
+ ScanTermInfoList::iterator it =
entries_before.begin();
while (it != entries_before.end() && my <*it)
it++;
}
if (my.m_norm_term.length())
{
- ScanTermInfoList::iterator it =
+ ScanTermInfoList::iterator it =
entries_after.begin();
while (it != entries_after.end() && *it < my)
it++;
}
}
- }
+ }
}
else
{
- // if any target does not return scan response - return that
+ // if any target does not return scan response - return that
package.response() = p->response();
return;
}
{
std::cout << " " << it->m_norm_term << " " << it->m_count << "\n";
}
-
+
std::cout << "AFTER\n";
it = entries_after.begin();
for(; it != entries_after.end(); it++)
mp::odr odr;
Z_APDU *f_apdu = odr.create_scanResponse(apdu_req, 0, 0);
Z_ScanResponse *resp = f_apdu->u.scanResponse;
-
+
int number_returned = *req->numberOfTermsRequested;
int position_returned = *req->preferredPositionInResponse;
-
+
resp->entries->num_entries = number_returned;
resp->entries->entries = (Z_Entry**)
odr_malloc(odr, sizeof(Z_Entry*) * number_returned);
FrontendPtr f = m_p->get_frontend(package);
Z_GDU *gdu = package.request().get();
-
+
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_initRequest && !f->m_is_multi)
{
if (apdu->which == Z_APDU_initRequest)
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu,
Z_Close_protocolError,
"double init");
-
+
package.session().close();
}
else if (apdu->which == Z_APDU_searchRequest)
else
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu, Z_Close_protocolError,
"unsupported APDU in filter multi");
-
+
package.session().close();
}
}
else
{
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) ptr->name)
+ " in multi filter");
}
void yf::QueryRewrite::Rep::process(mp::Package &package) const
{
Z_GDU *gdu = package.request().get();
-
+
if (gdu && gdu->which == Z_GDU_Z3950)
{
Z_APDU *apdu_req = gdu->u.z3950;
const char *addinfo = 0;
mp::odr odr;
Z_SearchRequest *req = apdu_req->u.searchRequest;
-
+
if (m_stylesheet)
{
xmlDocPtr doc_input = 0;
yaz_query2xml(req->query, &doc_input);
-
+
if (!doc_input)
{
error_code = YAZ_BIB1_MALFORMED_QUERY;
}
if (error_code)
{
- Z_APDU *f_apdu =
+ Z_APDU *f_apdu =
odr.create_searchResponse(apdu_req, error_code, addinfo);
package.response() = f_apdu;
return;
}
package.request() = gdu;
- }
+ }
}
package.move();
}
std::string fname;
- for (struct _xmlAttr *attr = ptr->properties;
+ for (struct _xmlAttr *attr = ptr->properties;
attr; attr = attr->next)
{
mp::xml::check_attribute(attr, "", "stylesheet");
- fname = mp::xml::get_text(attr);
+ fname = mp::xml::get_text(attr);
}
if (0 == fname.size())
throw mp::filter::FilterException
- ("Attribute <xslt stylesheet=\""
+ ("Attribute <xslt stylesheet=\""
+ fname
+ "\"> needs XSLT stylesheet path content"
+ " in query_rewrite filter");
if (!m_stylesheet)
{
throw mp::filter::FilterException
- ("Failed to read XSLT stylesheet '"
+ ("Failed to read XSLT stylesheet '"
+ fname
+ "' in query_rewrite filter");
}
}
else if (mp::xml::is_element_mp(ptr, "charset"))
{
- for (struct _xmlAttr *attr = ptr->properties;
+ for (struct _xmlAttr *attr = ptr->properties;
attr; attr = attr->next)
{
if (!strcmp((const char *) attr->name, "from"))
else
{
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) ptr->name)
+ " in query_rewrite filter");
}
return -1;
}
p->usemarcon1->GetMarcRecord(converted, convlen);
-
+
if (p->usemarcon2)
{
p->usemarcon2->SetMarcRecord(converted, convlen);
-
+
res = p->usemarcon2->Convert();
free(converted);
if (res != 0)
#endif
// define Pimpl wrapper forwarding to Impl
-
+
yf::RecordTransform::RecordTransform() : m_p(new Impl)
{
}
}
-yf::RecordTransform::Impl::Impl()
+yf::RecordTransform::Impl::Impl()
{
m_retrieval = yaz_retrieval_create();
assert(m_retrieval);
}
yf::RecordTransform::Impl::~Impl()
-{
+{
if (m_retrieval)
yaz_retrieval_destroy(m_retrieval);
}
// parsing down to retrieval node, which can be any of the children nodes
xmlNode *retrieval_node;
- for (retrieval_node = xml_node->children;
- retrieval_node;
+ for (retrieval_node = xml_node->children;
+ retrieval_node;
retrieval_node = retrieval_node->next)
{
if (retrieval_node->type != XML_ELEMENT_NODE)
// the effective element set name.. Therefore we can only allow
// two cases.. Both equal or absent.. If not, we'll just have to
// disable the piggyback!
- if (sr_req->smallSetElementSetNames
+ if (sr_req->smallSetElementSetNames
&&
sr_req->mediumSetElementSetNames
&&
sr_req->smallSetElementSetNames->which == Z_ElementSetNames_generic
- &&
+ &&
sr_req->mediumSetElementSetNames->which == Z_ElementSetNames_generic
- &&
+ &&
!strcmp(sr_req->smallSetElementSetNames->u.generic,
sr_req->mediumSetElementSetNames->u.generic))
{
input_schema = sr_req->smallSetElementSetNames->u.generic;
}
- else if (!sr_req->smallSetElementSetNames &&
+ else if (!sr_req->smallSetElementSetNames &&
!sr_req->mediumSetElementSetNames)
; // input_schema is 0 already
else
package.move();
return;
}
-
+
mp::odr odr_en(ODR_ENCODE);
// setting up variables for conversion state
const char *backend_schema = 0;
Odr_oid *backend_syntax = 0;
- int ret_code
+ int ret_code
= yaz_retrieval_request(m_retrieval,
input_schema, input_syntax,
&match_schema, &match_syntax,
if (sr_req)
{
- if (backend_syntax)
+ if (backend_syntax)
sr_req->preferredRecordSyntax = odr_oiddup(odr_en, backend_syntax);
else
sr_req->preferredRecordSyntax = 0;
= (Z_ElementSetNames *)
odr_malloc(odr_en, sizeof(Z_ElementSetNames));
sr_req->smallSetElementSetNames->which = Z_ElementSetNames_generic;
- sr_req->smallSetElementSetNames->u.generic
+ sr_req->smallSetElementSetNames->u.generic
= odr_strdup(odr_en, backend_schema);
sr_req->mediumSetElementSetNames = sr_req->smallSetElementSetNames;
}
}
else if (pr_req)
{
- if (backend_syntax)
+ if (backend_syntax)
pr_req->preferredRecordSyntax = odr_oiddup(odr_en, backend_syntax);
else
pr_req->preferredRecordSyntax = 0;
-
+
if (backend_schema)
{
- pr_req->recordComposition
- = (Z_RecordComposition *)
+ pr_req->recordComposition
+ = (Z_RecordComposition *)
odr_malloc(odr_en, sizeof(Z_RecordComposition));
- pr_req->recordComposition->which
+ pr_req->recordComposition->which
= Z_RecordComp_simple;
- pr_req->recordComposition->u.simple
+ pr_req->recordComposition->u.simple
= (Z_ElementSetNames *)
odr_malloc(odr_en, sizeof(Z_ElementSetNames));
pr_req->recordComposition->u.simple->which = Z_ElementSetNames_generic;
- pr_req->recordComposition->u.simple->u.generic
+ pr_req->recordComposition->u.simple->u.generic
= odr_strdup(odr_en, backend_schema);
}
else
package.request() = gdu_req;
package.move();
-
+
Z_GDU *gdu_res = package.response().get();
// see if we have a records list to patch!
gdu_res->u.z3950->which == Z_APDU_presentResponse)
{
Z_PresentResponse * pr_res = gdu_res->u.z3950->u.presentResponse;
-
- if (rc && pr_res
- && pr_res->numberOfRecordsReturned
+
+ if (rc && pr_res
+ && pr_res->numberOfRecordsReturned
&& *(pr_res->numberOfRecordsReturned) > 0
&& pr_res->records
&& pr_res->records->which == Z_Records_DBOSD)
gdu_res->u.z3950->which == Z_APDU_searchResponse)
{
Z_SearchResponse *sr_res = gdu_res->u.z3950->u.searchResponse;
-
- if (rc && sr_res
- && sr_res->numberOfRecordsReturned
+
+ if (rc && sr_res
+ && sr_res->numberOfRecordsReturned
&& *(sr_res->numberOfRecordsReturned) > 0
&& sr_res->records
&& sr_res->records->which == Z_Records_DBOSD)
records = sr_res->records->u.databaseOrSurDiagnostics;
}
}
-
+
if (records)
{
int i;
yaz_record_conv_opac_record(rc, r->u.opac,
output_record);
}
- else if (r->which == Z_External_octet)
+ else if (r->which == Z_External_octet)
{
ret_trans =
yaz_record_conv_record(rc, (const char *)
- r->u.octet_aligned->buf,
+ r->u.octet_aligned->buf,
r->u.octet_aligned->len,
output_record);
}
Rep *m_p;
BackendClassPtr m_backend_class;
FrontendSets m_frontend_sets;
- };
+ };
// representation
class SessionShared::Rep {
friend class SessionShared;
friend struct Frontend;
-
+
FrontendPtr get_frontend(Package &package);
void release_frontend(Package &package);
Rep();
{
}
-const yf::SessionShared::Databases &
+const yf::SessionShared::Databases &
yf::SessionShared::FrontendSet::get_databases()
{
return m_databases;
yf::SessionShared::InitKey::InitKey(const InitKey &k)
{
m_odr = odr_createmem(ODR_ENCODE);
-
+
m_idAuthentication_size = k.m_idAuthentication_size;
m_idAuthentication_buf = (char*)odr_malloc(m_odr, m_idAuthentication_size);
memcpy(m_idAuthentication_buf, k.m_idAuthentication_buf,
}
bool yf::SessionShared::InitKey::operator < (const SessionShared::InitKey &k)
- const
+ const
{
int c;
c = mp::util::memcmp2(
void yf::SessionShared::BackendClass::remove_backend(BackendInstancePtr b)
{
BackendInstanceList::iterator it = m_backend_list.begin();
-
+
while (it != m_backend_list.end())
{
if (*it == b)
0, Z_Close_lackOfActivity, 0);
(*it)->m_close_package->session().close();
(*it)->m_close_package->move();
-
+
it = m_backend_list.erase(it);
}
else
-yf::SessionShared::BackendInstancePtr
+yf::SessionShared::BackendInstancePtr
yf::SessionShared::BackendClass::get_backend(
const mp::Package &frontend_package)
{
{
boost::mutex::scoped_lock lock(m_mutex_backend_class);
-
+
BackendInstanceList::const_iterator it = m_backend_list.begin();
-
+
BackendInstancePtr backend1; // null
-
+
for (; it != m_backend_list.end(); it++)
{
if (!(*it)->m_in_use)
{
- if (!backend1
+ if (!backend1
|| (*it)->m_sequence_this < backend1->m_sequence_this)
backend1 = *it;
}
/* already closed. We don't know why */
return null;
}
- else if (gdu && gdu->which == Z_GDU_Z3950
+ else if (gdu && gdu->which == Z_GDU_Z3950
&& gdu->u.z3950->which == Z_APDU_initResponse
&& *gdu->u.z3950->u.initResponse->result)
{
}
else
{
- frontend->m_backend_class = it->second;
+ frontend->m_backend_class = it->second;
}
}
BackendClassPtr bc = frontend->m_backend_class;
Z_GDU *response_gdu = init_response.get();
mp::util::transfer_referenceId(odr, gdu->u.z3950,
response_gdu->u.z3950);
-
+
Z_Options *server_options =
response_gdu->u.z3950->u.initResponse->options;
Z_Options *client_options = &frontend->m_init_options;
-
+
int i;
for (i = 0; i < 30; i++)
if (!ODR_MASK_GET(client_options, i))
const Databases &databases,
const yazpp_1::Yaz_Z_Query &query) :
m_result_set_id(result_set_id),
- m_databases(databases), m_result_set_size(0), m_query(query)
+ m_databases(databases), m_result_set_size(0), m_query(query)
{
timestamp();
}
req->query = m_query.get_Z_Query();
req->num_databaseNames = m_databases.size();
- req->databaseNames = (char**)
+ req->databaseNames = (char**)
odr_malloc(odr, req->num_databaseNames * sizeof(char *));
Databases::const_iterator it = m_databases.begin();
size_t i = 0;
Z_GDU *gdu = search_package.response().get();
if (!search_package.session().is_closed()
- && gdu && gdu->which == Z_GDU_Z3950
+ && gdu && gdu->which == Z_GDU_Z3950
&& gdu->u.z3950->which == Z_APDU_searchResponse)
{
Z_SearchResponse *b_resp = gdu->u.z3950->u.searchResponse;
if (bc->m_named_result_sets)
{
result_set_id = boost::io::str(
- boost::format("%1%") %
+ boost::format("%1%") %
found_backend->m_result_set_sequence);
found_backend->m_result_set_sequence++;
}
if ((int) bc->m_backend_list.size() >= m_p->m_session_max)
out_of_sessions = true;
-
+
if (m_p->m_optimize_search)
{
// look at each backend and see if we have a similar search
Z_APDU *f_apdu = 0;
mp::odr odr;
const char *addinfo = 0;
-
+
if (out_of_sessions)
addinfo = "session_shared: all sessions in use";
if (apdu_req->which == Z_APDU_searchRequest)
apdu_req, found_backend, &z_records))
{
bc->remove_backend(found_backend);
- return; // search error
+ return; // search error
}
if (z_records)
else if (z_records->which == Z_Records_multipleNSD)
{
if (z_records->u.multipleNonSurDiagnostics->num_diagRecs >= 1
- &&
-
+ &&
+
z_records->u.multipleNonSurDiagnostics->diagRecs[0]->which ==
Z_DiagRec_defaultFormat)
{
condition = get_diagnostic(
z_records->u.multipleNonSurDiagnostics->diagRecs[0]->u.defaultFormat);
-
+
}
}
if (m_p->m_restart && !session_restarted &&
mp::odr odr;
if (apdu_req->which == Z_APDU_searchRequest)
{
- Z_APDU *f_apdu = odr.create_searchResponse(apdu_req,
+ Z_APDU *f_apdu = odr.create_searchResponse(apdu_req,
0, 0);
Z_SearchResponse *f_resp = f_apdu->u.searchResponse;
*f_resp->searchStatus = Z_SearchResponse_none;
}
if (apdu_req->which == Z_APDU_presentRequest)
{
- Z_APDU *f_apdu = odr.create_presentResponse(apdu_req,
+ Z_APDU *f_apdu = odr.create_presentResponse(apdu_req,
0, 0);
Z_PresentResponse *f_resp = f_apdu->u.presentResponse;
f_resp->records = z_records;
package.response() = f_apdu;
}
bc->release_backend(found_backend);
- return; // search error
+ return; // search error
}
}
if (m_p->m_restart && !session_restarted && new_set->m_result_set_size < 0)
Z_APDU *apdu_req)
{
Z_SearchRequest *req = apdu_req->u.searchRequest;
- FrontendSets::iterator fset_it =
+ FrontendSets::iterator fset_it =
m_frontend_sets.find(req->resultSetName);
if (fset_it != m_frontend_sets.end())
{
- // result set already exist
+ // result set already exist
// if replace indicator is off: we return diagnostic if
// result set already exist.
if (*req->replaceIndicator == 0)
{
mp::odr odr;
- Z_APDU *apdu =
+ Z_APDU *apdu =
odr.create_searchResponse(
apdu_req,
YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF,
0);
package.response() = apdu;
-
+
return;
}
m_frontend_sets.erase(fset_it);
}
-
+
yazpp_1::Yaz_Z_Query query;
query.set_Z_Query(req->query);
Databases databases;
mp::odr odr;
Z_PresentRequest *req = apdu_req->u.presentRequest;
- FrontendSets::iterator fset_it =
+ FrontendSets::iterator fset_it =
m_frontend_sets.find(req->resultSetId);
if (fset_it == m_frontend_sets.end())
{
- Z_APDU *apdu =
+ Z_APDU *apdu =
odr.create_presentResponse(
apdu_req,
YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
return;
Z_NamePlusRecordList *npr_res = 0;
- if (found_set->m_record_cache.lookup(odr, &npr_res,
+ if (found_set->m_record_cache.lookup(odr, &npr_res,
*req->resultSetStartPoint,
*req->numberOfRecordsRequested,
req->preferredRecordSyntax,
Z_APDU *f_apdu_res = odr.create_presentResponse(apdu_req, 0, 0);
Z_PresentResponse *f_resp = f_apdu_res->u.presentResponse;
- yaz_log(YLOG_LOG, "Found " ODR_INT_PRINTF "+" ODR_INT_PRINTF
+ yaz_log(YLOG_LOG, "Found " ODR_INT_PRINTF "+" ODR_INT_PRINTF
" records in cache %p",
- *req->resultSetStartPoint,
+ *req->resultSetStartPoint,
*req->numberOfRecordsRequested,
- &found_set->m_record_cache);
+ &found_set->m_record_cache);
*f_resp->numberOfRecordsReturned = *req->numberOfRecordsRequested;
- *f_resp->nextResultSetPosition =
+ *f_resp->nextResultSetPosition =
*req->resultSetStartPoint + *req->numberOfRecordsRequested;
// f_resp->presentStatus assumed OK.
f_resp->records = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
}
found_backend->timestamp();
-
+
Z_APDU *p_apdu = zget_APDU(odr, Z_APDU_presentRequest);
Z_PresentRequest *p_req = p_apdu->u.presentRequest;
p_req->preferredRecordSyntax = req->preferredRecordSyntax;
Z_GDU *gdu = present_package.response().get();
if (!present_package.session().is_closed()
- && gdu && gdu->which == Z_GDU_Z3950
+ && gdu && gdu->which == Z_GDU_Z3950
&& gdu->u.z3950->which == Z_APDU_presentResponse)
{
Z_PresentResponse *b_resp = gdu->u.z3950->u.presentResponse;
{
yaz_log(YLOG_LOG, "Adding " ODR_INT_PRINTF "+" ODR_INT_PRINTF
" records to cache %p",
- *req->resultSetStartPoint,
+ *req->resultSetStartPoint,
*f_resp->numberOfRecordsReturned,
- &found_set->m_record_cache);
+ &found_set->m_record_cache);
found_set->m_record_cache.add(
odr,
b_resp->records->u.databaseOrSurDiagnostics,
- *req->resultSetStartPoint,
+ *req->resultSetStartPoint,
*f_resp->numberOfRecordsReturned);
}
bc->release_backend(found_backend);
else
{
bc->remove_backend(found_backend);
- Z_APDU *f_apdu_res =
+ Z_APDU *f_apdu_res =
odr.create_presentResponse(
apdu_req, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, 0);
package.response() = f_apdu_res;
while (bit != m_backend_list.end())
{
time_t last_use = (*bit)->m_time_last_use;
-
+
if ((*bit)->m_in_use)
{
bit++;
boost::xtime_get(&xt, boost::TIME_UTC);
xt.sec += m_session_ttl / 3;
boost::thread::sleep(xt);
-
+
BackendClassMap::const_iterator b_it = m_backend_map.begin();
for (; b_it != m_backend_map.end(); b_it++)
b_it->second->expire_class();
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::SessionShared::FrontendPtr>::iterator it;
-
+
while(true)
{
it = m_clients.find(package.session());
if (it == m_clients.end())
break;
-
+
if (!it->second->m_in_use)
{
it->second->m_in_use = true;
{
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::SessionShared::FrontendPtr>::iterator it;
-
+
it = m_clients.find(package.session());
if (it != m_clients.end())
{
FrontendPtr f = m_p->get_frontend(package);
Z_GDU *gdu = package.request().get();
-
+
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_initRequest && !f->m_is_virtual)
{
if (apdu->which == Z_APDU_initRequest)
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu,
Z_Close_protocolError,
"double init");
-
+
package.session().close();
}
else if (apdu->which == Z_APDU_close)
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu,
Z_Close_peerAbort, "received close from client");
else
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu, Z_Close_protocolError,
"unsupported APDU in filter_session_shared");
-
+
package.session().close();
}
}
for (attr = ptr->properties; attr; attr = attr->next)
{
if (!strcmp((const char *) attr->name, "ttl"))
- m_p->m_resultset_ttl =
+ m_p->m_resultset_ttl =
mp::xml::get_int(attr->children, 30);
else if (!strcmp((const char *) attr->name, "max"))
{
- m_p->m_resultset_max =
+ m_p->m_resultset_max =
mp::xml::get_int(attr->children, 10);
}
else if (!strcmp((const char *) attr->name, "optimizesearch"))
for (attr = ptr->properties; attr; attr = attr->next)
{
if (!strcmp((const char *) attr->name, "ttl"))
- m_p->m_session_ttl =
+ m_p->m_session_ttl =
mp::xml::get_int(attr->children, 90);
else if (!strcmp((const char *) attr->name, "max"))
- m_p->m_session_max =
+ m_p->m_session_max =
mp::xml::get_int(attr->children, 100);
else
throw mp::filter::FilterException(
}
else
{
- throw mp::filter::FilterException("Bad element "
+ throw mp::filter::FilterException("Bad element "
+ std::string((const char *)
ptr->name));
}
xmlNodePtr cur;
int size;
int i;
-
+
assert(output);
size = nodes ? nodes->nodeNr : 0;
-
+
fprintf(output, "Result (%d nodes):\n", size);
for (i = 0; i < size; ++i) {
assert(nodes->nodeTab[i]);
-
+
if (nodes->nodeTab[i]->type == XML_NAMESPACE_DECL)
{
xmlNsPtr ns = (xmlNsPtr)nodes->nodeTab[i];
cur = (xmlNodePtr)ns->next;
if (cur->ns)
- fprintf(output, "= namespace \"%s\"=\"%s\" for node %s:%s\n",
+ fprintf(output, "= namespace \"%s\"=\"%s\" for node %s:%s\n",
ns->prefix, ns->href, cur->ns->href, cur->name);
else
- fprintf(output, "= namespace \"%s\"=\"%s\" for node %s\n",
+ fprintf(output, "= namespace \"%s\"=\"%s\" for node %s\n",
ns->prefix, ns->href, cur->name);
}
else if (nodes->nodeTab[i]->type == XML_ELEMENT_NODE)
{
- cur = nodes->nodeTab[i];
+ cur = nodes->nodeTab[i];
if (cur->ns)
- fprintf(output, "= element node \"%s:%s\"\n",
+ fprintf(output, "= element node \"%s:%s\"\n",
cur->ns->href, cur->name);
else
fprintf(output, "= element node \"%s\"\n", cur->name);
}
else
{
- cur = nodes->nodeTab[i];
+ cur = nodes->nodeTab[i];
fprintf(output, "= node \"%s\": type %d\n", cur->name, cur->type);
}
}
xmlChar* prefix;
xmlChar* href;
xmlChar* next;
-
+
assert(xpathCtx);
assert(nsList);
nsListDup = xmlStrdup((const xmlChar *) nsList);
if (!nsListDup)
return false;
-
- next = nsListDup;
+
+ next = nsListDup;
while (next)
{
/* skip spaces */
xmlFree(nsListDup);
return false;
}
- *next++ = '\0';
-
+ *next++ = '\0';
+
/* find href */
href = next;
next = (xmlChar*)xmlStrchr(next, ' ');
if (next)
- *next++ = '\0';
+ *next++ = '\0';
/* do register namespace */
if (xmlXPathRegisterNs(xpathCtx, prefix, href) != 0)
return false;
}
}
-
+
xmlFree(nsListDup);
return true;
}
{
xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
if (xpathCtx)
- {
+ {
register_namespaces(xpathCtx, namespaces);
xmlXPathObjectPtr xpathObj =
xmlXPathEvalExpression((const xmlChar *) expr, xpathCtx);
yf::Sort::Record::Record(Z_NamePlusRecord *n,
const char *namespaces,
const char *expr,
- bool debug) : npr(n)
+ bool debug) : npr(n)
{
if (npr->which == Z_NamePlusRecord_databaseRecord)
{
yf::Sort::RecordList::~RecordList()
{
-
+
}
-
+
bool yf::Sort::RecordList::cmp(Odr_oid *syntax)
{
if ((!this->syntax && !syntax)
}
-yf::Sort::Frontend::Frontend(Impl *impl) :
+yf::Sort::Frontend::Frontend(Impl *impl) :
m_p(impl), m_is_virtual(false), m_in_use(true)
{
}
}
yf::Sort::Impl::~Impl()
-{
+{
}
yf::Sort::FrontendPtr yf::Sort::Impl::get_frontend(mp::Package &package)
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::Sort::FrontendPtr>::iterator it;
-
+
while(true)
{
it = m_clients.find(package.session());
if (it == m_clients.end())
break;
-
+
if (!it->second->m_in_use)
{
it->second->m_in_use = true;
{
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::Sort::FrontendPtr>::iterator it;
-
+
it = m_clients.find(package.session());
if (it != m_clients.end())
{
if (ptr->type != XML_ELEMENT_NODE)
continue;
if (!strcmp((const char *) ptr->name, "sort"))
- {
+ {
const struct _xmlAttr *attr;
for (attr = ptr->properties; attr; attr = attr->next)
{
if (m_prefetch < 0)
{
throw mp::filter::FilterException(
- "Bad or missing value for attribute " +
+ "Bad or missing value for attribute " +
std::string((const char *) attr->name));
}
}
else
{
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) ptr->name)
+ " in sort filter");
}
void yf::Sort::Frontend::handle_search(mp::Package &package, Z_APDU *apdu_req)
{
- Z_SearchRequest *req = apdu_req->u.searchRequest;
+ Z_SearchRequest *req = apdu_req->u.searchRequest;
std::string resultSetId = req->resultSetName;
Package b_package(package.session(), package.origin());
mp::odr odr;
Sets_it sets_it = m_sets.find(req->resultSetName);
if (sets_it != m_sets.end())
{
- // result set already exist
+ // result set already exist
// if replace indicator is off: we return diagnostic if
// result set already exist.
if (*req->replaceIndicator == 0)
{
- Z_APDU *apdu =
+ Z_APDU *apdu =
odr.create_searchResponse(
apdu_req,
YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF,
0);
package.response() = apdu;
return;
- }
+ }
m_sets.erase(resultSetId);
}
ResultSetPtr s(new ResultSet);
void yf::Sort::Frontend::handle_present(mp::Package &package, Z_APDU *apdu_req)
{
- Z_PresentRequest *req = apdu_req->u.presentRequest;
+ Z_PresentRequest *req = apdu_req->u.presentRequest;
std::string resultSetId = req->resultSetId;
Package b_package(package.session(), package.origin());
mp::odr odr;
Sets_it sets_it = m_sets.find(resultSetId);
if (sets_it == m_sets.end())
{
- Z_APDU *apdu =
+ Z_APDU *apdu =
odr.create_presentResponse(
apdu_req,
YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
for (; it != rset->record_lists.end(); it++)
if ((*it)->cmp(req->preferredRecordSyntax))
{
- if (*req->resultSetStartPoint - 1 + *req->numberOfRecordsRequested
+ if (*req->resultSetStartPoint - 1 + *req->numberOfRecordsRequested
<= (*it)->size())
{
int i;
*p_res->nextResultSetPosition = *req->resultSetStartPoint +
*req->numberOfRecordsRequested;
- *p_res->numberOfRecordsReturned =
+ *p_res->numberOfRecordsReturned =
*req->numberOfRecordsRequested;
- p_res->records = (Z_Records *)
+ p_res->records = (Z_Records *)
odr_malloc(odr, sizeof(*p_res->records));
p_res->records->which = Z_Records_DBOSD;
Z_NamePlusRecordList *nprl = (Z_NamePlusRecordList *)
Z_APDU_presentResponse)
{
Z_PresentResponse *res = gdu_res->u.z3950->u.presentResponse;
- handle_records(b_package, apdu_req, res->records,
+ handle_records(b_package, apdu_req, res->records,
start, rset, syntax, resultSetId.c_str());
package.response() = gdu_res;
}
boost::mutex m_mutex_session;
boost::condition m_cond_session_ready;
- std::map<mp::Session, FrontendPtr> m_clients;
+ std::map<mp::Session, FrontendPtr> m_clients;
private:
void sru(metaproxy_1::Package &package, Z_GDU *zgdu_req);
int z3950_build_query(
- mp::odr &odr_en, Z_Query *z_query,
+ mp::odr &odr_en, Z_Query *z_query,
const Z_SRW_searchRetrieveRequest *req
) const;
-
+
bool z3950_init_request(
- mp::Package &package,
+ mp::Package &package,
mp::odr &odr_en,
std::string zurl,
Z_SRW_PDU *sru_pdu_res,
Z_SRW_PDU *sru_pdu_res,
Z_SRW_searchRetrieveRequest const *sr_req
) const;
-
+
bool z3950_to_srw_diagnostics_ok(
- mp::odr &odr_en,
+ mp::odr &odr_en,
Z_SRW_searchRetrieveResponse *srw_res,
Z_Records *records
) const;
-
+
int z3950_to_srw_diag(
- mp::odr &odr_en,
+ mp::odr &odr_en,
Z_SRW_searchRetrieveResponse *srw_res,
Z_DefaultDiagFormat *ddf
) const;
void yf::SRUtoZ3950::Impl::configure(const xmlNode *confignode)
{
const xmlNode * dbnode;
-
+
for (dbnode = confignode->children; dbnode; dbnode = dbnode->next)
{
if (dbnode->type != XML_ELEMENT_NODE)
continue;
-
+
std::string database;
mp::xml::check_element_mp(dbnode, "database");
- for (struct _xmlAttr *attr = dbnode->properties;
+ for (struct _xmlAttr *attr = dbnode->properties;
attr; attr = attr->next)
{
-
+
mp::xml::check_attribute(attr, "", "name");
database = mp::xml::get_text(attr);
-
+
const xmlNode *explainnode;
- for (explainnode = dbnode->children;
+ for (explainnode = dbnode->children;
explainnode; explainnode = explainnode->next)
{
if (explainnode->type != XML_ELEMENT_NODE)
if (explainnode)
break;
}
- // assigning explain node to database name - no check yet
+ // assigning explain node to database name - no check yet
m_database_explain.insert(std::make_pair(database, explainnode));
}
}
void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req)
{
- bool ok = true;
+ bool ok = true;
mp::odr odr_de(ODR_DECODE);
Z_SRW_PDU *sru_pdu_req = 0;
char *stylesheet = 0;
// filter acts as sink for non-valid SRU requests
- if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en,
+ if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en,
sru_pdu_res, &soap,
charset, stylesheet)))
{
if (soap)
{
- mp_util::build_sru_explain(package, odr_en, sru_pdu_res,
+ mp_util::build_sru_explain(package, odr_en, sru_pdu_res,
sruinfo, explainnode);
- mp_util::build_sru_response(package, odr_en, soap,
+ mp_util::build_sru_response(package, odr_en, soap,
sru_pdu_res, charset, stylesheet);
}
else
{
- metaproxy_1::odr odr;
- Z_GDU *zgdu_res =
- odr.create_HTTP_Response(package.session(),
+ metaproxy_1::odr odr;
+ Z_GDU *zgdu_res =
+ odr.create_HTTP_Response(package.session(),
zgdu_req->u.HTTP_Request, 400);
package.response() = zgdu_res;
}
return;
}
-
+
bool enable_package_log = false;
std::string zurl;
Z_SRW_extra_arg *arg;
if (sru_pdu_req->which == Z_SRW_explain_request)
{
Z_SRW_explainRequest *er_req = sru_pdu_req->u.explain_request;
- mp_util::build_sru_explain(package, odr_en, sru_pdu_res,
+ mp_util::build_sru_explain(package, odr_en, sru_pdu_res,
sruinfo, explainnode, er_req);
}
else if (sru_pdu_req->which == Z_SRW_searchRetrieve_request
&& sru_pdu_req->u.request)
{ // searchRetrieve
- Z_SRW_searchRetrieveRequest *sr_req = sru_pdu_req->u.request;
-
+ Z_SRW_searchRetrieveRequest *sr_req = sru_pdu_req->u.request;
+
sru_pdu_res = yaz_srw_get_pdu(odr_en, Z_SRW_searchRetrieve_response,
sru_pdu_req->srw_version);
// checking that we have a query
- ok = mp_util::check_sru_query_exists(package, odr_en,
+ ok = mp_util::check_sru_query_exists(package, odr_en,
sru_pdu_res, sr_req);
if (ok && z3950_init_request(package, odr_en,
{
ok = z3950_search_request(package, odr_en,
sru_pdu_res, sr_req, zurl);
-
- if (ok
+
+ if (ok
&& sru_pdu_res->u.response->numberOfRecords
&& *(sru_pdu_res->u.response->numberOfRecords))
{
sru_pdu_res = yaz_srw_get_pdu(odr_en, Z_SRW_scan_response,
sru_pdu_req->srw_version);
-
+
// we do not do scan at the moment, therefore issuing a diagnostic
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.scan_response->diagnostics),
- &(sru_pdu_res->u.scan_response->num_diagnostics),
+ &(sru_pdu_res->u.scan_response->diagnostics),
+ &(sru_pdu_res->u.scan_response->num_diagnostics),
YAZ_SRW_UNSUPP_OPERATION, "scan");
}
else
{
sru_pdu_res = yaz_srw_get(odr_en, Z_SRW_explain_response);
-
+
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.explain_response->diagnostics),
- &(sru_pdu_res->u.explain_response->num_diagnostics),
+ &(sru_pdu_res->u.explain_response->diagnostics),
+ &(sru_pdu_res->u.explain_response->num_diagnostics),
YAZ_SRW_UNSUPP_OPERATION, "unknown");
}
if (l.length())
{
mp::wrbuf w;
-
+
wrbuf_puts(w, "<log>\n");
wrbuf_xmlputs(w, l.c_str());
wrbuf_puts(w, "</log>");
-
+
sru_pdu_res->extraResponseData_len = w.len();
sru_pdu_res->extraResponseData_buf =
odr_strdup(odr_en, wrbuf_cstr(w));
}
}
-
+
// build and send SRU response
- mp_util::build_sru_response(package, odr_en, soap,
+ mp_util::build_sru_response(package, odr_en, soap,
sru_pdu_res, charset, stylesheet);
}
boost::mutex::scoped_lock lock(m_mutex_session);
std::map<mp::Session,yf::SRUtoZ3950::FrontendPtr>::iterator it;
-
+
while (true)
{
it = m_clients.find(package.session());
if (it == m_clients.end())
break;
-
+
if (!it->second->m_in_use)
{
it->second->m_in_use = true;
{
boost::mutex::scoped_lock lock(m_mutex_session);
std::map<mp::Session,FrontendPtr>::iterator it;
-
+
it = m_clients.find(package.session());
if (it != m_clients.end())
{
{
const char *path = zgdu_req->u.HTTP_Request->path;
boost::mutex::scoped_lock lock(m_url_mutex);
-
+
ActiveUrlMap::iterator it = m_active_urls.find(path);
-
+
m_active_urls.erase(it);
m_cond_url_ready.notify_all();
}
release_frontend(package);
}
-bool
-yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package,
+bool
+yf::SRUtoZ3950::Impl::z3950_init_request(mp::Package &package,
mp::odr &odr_en,
std::string zurl,
Z_SRW_PDU *sru_pdu_res,
*init_req->preferredMessageSize = 10*1024*1024;
*init_req->maximumRecordSize = 10*1024*1024;
-
+
ODR_MASK_SET(init_req->options, Z_Options_search);
ODR_MASK_SET(init_req->options, Z_Options_present);
ODR_MASK_SET(init_req->options, Z_Options_namedResultSets);
ODR_MASK_SET(init_req->protocolVersion, Z_ProtocolVersion_3);
if (zurl.length())
- {
+ {
std::string host;
std::list<std::string> dblist;
mp_util::split_zurl(zurl, host, dblist);
// check successful initResponse
Z_GDU *z3950_gdu = z3950_package.response().get();
- if (z3950_gdu && z3950_gdu->which == Z_GDU_Z3950
- && z3950_gdu->u.z3950->which == Z_APDU_initResponse
+ if (z3950_gdu && z3950_gdu->which == Z_GDU_Z3950
+ && z3950_gdu->u.z3950->which == Z_APDU_initResponse
&& *z3950_gdu->u.z3950->u.initResponse->result)
return true;
-
+
yaz_add_srw_diagnostic(odr_en,
&(sru_pdu_res->u.response->diagnostics),
&(sru_pdu_res->u.response->num_diagnostics),
return false;
}
-bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package,
+bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package,
mp::odr &odr_en,
Z_SRW_PDU *sru_pdu_res,
- Z_SRW_searchRetrieveRequest
+ Z_SRW_searchRetrieveRequest
const *sr_req,
std::string zurl) const
{
odr_malloc(odr_en, sizeof(char *));
if (sr_req->database)
- z_searchRequest->databaseNames[0]
+ z_searchRequest->databaseNames[0]
= odr_strdup(odr_en, const_cast<char *>(sr_req->database));
else
- z_searchRequest->databaseNames[0]
+ z_searchRequest->databaseNames[0]
= odr_strdup(odr_en, "Default");
}
Z_Query *z_query = (Z_Query *) odr_malloc(odr_en, sizeof(Z_Query));
z_searchRequest->query = z_query;
-
+
int sru_diagnostic = z3950_build_query(odr_en, z_query, sr_req);
if (sru_diagnostic)
- {
+ {
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
sru_diagnostic,
"query");
return false;
}
z3950_package.request() = apdu;
-
+
z3950_package.move();
Z_GDU *z3950_gdu = z3950_package.response().get();
- if (!z3950_gdu || z3950_gdu->which != Z_GDU_Z3950
+ if (!z3950_gdu || z3950_gdu->which != Z_GDU_Z3950
|| z3950_gdu->u.z3950->which != Z_APDU_searchResponse
|| !z3950_gdu->u.z3950->u.searchResponse
|| !z3950_gdu->u.z3950->u.searchResponse->searchStatus)
YAZ_SRW_SYSTEM_TEMPORARILY_UNAVAILABLE, 0);
return false;
}
-
+
Z_SearchResponse *sr = z3950_gdu->u.z3950->u.searchResponse;
- if (!z3950_to_srw_diagnostics_ok(odr_en, sru_pdu_res->u.response,
+ if (!z3950_to_srw_diagnostics_ok(odr_en, sru_pdu_res->u.response,
sr->records))
{
return false;
}
bool yf::SRUtoZ3950::Impl::z3950_present_request(
- mp::Package &package,
+ mp::Package &package,
mp::odr &odr_en,
Z_SRW_PDU *sru_pdu_res,
const Z_SRW_searchRetrieveRequest *sr_req)
{
send_z3950_present = false;
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
YAZ_SRW_XPATH_RETRIEVAL_UNSUPP, 0);
}
-
+
// resultSetTTL unsupported.
// resultSetIdleTime in response
if (sr_req->resultSetTTL)
{
send_z3950_present = false;
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
YAZ_SRW_RESULT_SETS_UNSUPP, 0);
}
-
+
// sort unsupported
if (sr_req->sort_type != Z_SRW_sort_type_none)
{
send_z3950_present = false;
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
YAZ_SRW_SORT_UNSUPP, 0);
}
-
+
// start record requested negative, or larger than number of records
if (start < 0 || start > *sru_pdu_res->u.response->numberOfRecords)
{
send_z3950_present = false;
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
YAZ_SRW_FIRST_RECORD_POSITION_OUT_OF_RANGE, 0);
- }
-
+ }
+
// maximumRecords requested negative
if (max_recs < 0)
{
send_z3950_present = false;
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
YAZ_SRW_UNSUPP_PARAMETER_VALUE,
"maximumRecords");
- }
+ }
// exit on all these above diagnostics
if (!send_z3950_present)
return false;
-
+
if (max_recs > *sru_pdu_res->u.response->numberOfRecords - start)
max_recs = *sru_pdu_res->u.response->numberOfRecords - start + 1;
{
// now packaging the z3950 present request
Package z3950_package(package.session(), package.origin());
- z3950_package.copy_filter(package);
+ z3950_package.copy_filter(package);
Z_APDU *apdu = zget_APDU(odr_en, Z_APDU_presentRequest);
-
+
assert(apdu->u.presentRequest);
-
+
*apdu->u.presentRequest->resultSetStartPoint = start + num;
*apdu->u.presentRequest->numberOfRecordsRequested = max_recs - num;
-
+
// set response packing to be same as "request" packing..
int record_packing = Z_SRW_recordPacking_XML;
if (sr_req->recordPacking && 's' == *(sr_req->recordPacking))
record_packing = Z_SRW_recordPacking_string;
-
+
// RecordSyntax will always be XML
apdu->u.presentRequest->preferredRecordSyntax
= odr_oiddup(odr_en, yaz_oid_recsyn_xml);
-
+
// z3950'fy record schema
if (sr_req->recordSchema)
{
- apdu->u.presentRequest->recordComposition
- = (Z_RecordComposition *)
+ apdu->u.presentRequest->recordComposition
+ = (Z_RecordComposition *)
odr_malloc(odr_en, sizeof(Z_RecordComposition));
- apdu->u.presentRequest->recordComposition->which
+ apdu->u.presentRequest->recordComposition->which
= Z_RecordComp_simple;
- apdu->u.presentRequest->recordComposition->u.simple
+ apdu->u.presentRequest->recordComposition->u.simple
= mp_util::build_esn_from_schema(odr_en,
- (const char *)
- sr_req->recordSchema);
+ (const char *)
+ sr_req->recordSchema);
}
-
+
// attaching Z3950 package to filter chain
z3950_package.request() = apdu;
-
- // sending Z30.50 present request
+
+ // sending Z30.50 present request
z3950_package.move();
-
+
//check successful Z3950 present response
Z_GDU *z3950_gdu = z3950_package.response().get();
- if (!z3950_gdu || z3950_gdu->which != Z_GDU_Z3950
+ if (!z3950_gdu || z3950_gdu->which != Z_GDU_Z3950
|| z3950_gdu->u.z3950->which != Z_APDU_presentResponse
|| !z3950_gdu->u.z3950->u.presentResponse)
-
+
{
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
YAZ_SRW_SYSTEM_TEMPORARILY_UNAVAILABLE, 0);
return false;
}
// everything fine, continuing
-
+
Z_PresentResponse *pr = z3950_gdu->u.z3950->u.presentResponse;
-
+
// checking non surrogate diagnostics in Z3950 present response package
- if (!z3950_to_srw_diagnostics_ok(odr_en, sru_pdu_res->u.response,
+ if (!z3950_to_srw_diagnostics_ok(odr_en, sru_pdu_res->u.response,
pr->records))
return false;
-
+
// if anything but database or surrogate diagnostics, stop
if (!pr->records || pr->records->which != Z_Records_DBOSD)
break;
for (int i = 0; i < returned_recs; i++)
{
int position = i + *apdu->u.presentRequest->resultSetStartPoint;
- Z_NamePlusRecord *npr
+ Z_NamePlusRecord *npr
= pr->records->u.databaseOrSurDiagnostics->records[i];
-
+
sru_res->records[i + num].recordPacking = record_packing;
-
+
if (npr->which == Z_NamePlusRecord_surrogateDiagnostic)
{
Z_DiagRec *p = npr->u.surrogateDiagnostic;
}
}
else if (npr->which == Z_NamePlusRecord_databaseRecord &&
- npr->u.databaseRecord->direct_reference
+ npr->u.databaseRecord->direct_reference
&& !oid_oidcmp(npr->u.databaseRecord->direct_reference,
yaz_oid_recsyn_xml))
{
// got XML record back
Z_External *r = npr->u.databaseRecord;
- sru_res->records[i + num].recordPosition =
+ sru_res->records[i + num].recordPosition =
odr_intdup(odr_en, position);
sru_res->records[i + num].recordSchema = sr_req->recordSchema;
sru_res->records[i + num].recordData_buf
- = odr_strdupn(odr_en,
- (const char *)r->u.octet_aligned->buf,
+ = odr_strdupn(odr_en,
+ (const char *)r->u.octet_aligned->buf,
r->u.octet_aligned->len);
- sru_res->records[i + num].recordData_len
+ sru_res->records[i + num].recordData_len
= r->u.octet_aligned->len;
}
else
}
int yf::SRUtoZ3950::Impl::z3950_build_query(
- mp::odr &odr_en, Z_Query *z_query,
+ mp::odr &odr_en, Z_Query *z_query,
const Z_SRW_searchRetrieveRequest *req
) const
-{
+{
if (req->query_type == Z_SRW_query_type_cql)
{
- Z_External *ext = (Z_External *)
+ Z_External *ext = (Z_External *)
odr_malloc(odr_en, sizeof(*ext));
- ext->direct_reference =
+ ext->direct_reference =
odr_getoidbystr(odr_en, "1.2.840.10003.16.2");
ext->indirect_reference = 0;
ext->descriptor = 0;
ext->which = Z_External_CQL;
ext->u.cql = odr_strdup(odr_en, req->query.cql);
-
+
z_query->which = Z_Query_type_104;
z_query->u.type_104 = ext;
return 0;
{
Z_RPNQuery *RPNquery;
YAZ_PQF_Parser pqf_parser;
-
+
pqf_parser = yaz_pqf_create ();
-
+
RPNquery = yaz_pqf_parse (pqf_parser, odr_en, req->query.pqf);
yaz_pqf_destroy(pqf_parser);
z_query->which = Z_Query_type_1;
z_query->u.type_1 = RPNquery;
-
+
return 0;
}
return YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED;
}
bool yf::SRUtoZ3950::Impl::z3950_to_srw_diagnostics_ok(
- mp::odr &odr_en,
- Z_SRW_searchRetrieveResponse
+ mp::odr &odr_en,
+ Z_SRW_searchRetrieveResponse
*sru_res,
Z_Records *records) const
{
// checking non surrogate diagnostics in Z3950 present response package
- if (records
+ if (records
&& records->which == Z_Records_NSD
&& records->u.nonSurrogateDiagnostic)
{
- z3950_to_srw_diag(odr_en, sru_res,
+ z3950_to_srw_diag(odr_en, sru_res,
records->u.nonSurrogateDiagnostic);
return false;
}
}
int yf::SRUtoZ3950::Impl::z3950_to_srw_diag(
- mp::odr &odr_en,
+ mp::odr &odr_en,
Z_SRW_searchRetrieveResponse *sru_res,
Z_DefaultDiagFormat *ddf) const
{
sru_res->diagnostics = (Z_SRW_diagnostic *)
odr_malloc(odr_en, sizeof(*sru_res->diagnostics));
yaz_mk_std_diagnostic(odr_en, sru_res->diagnostics,
- yaz_diag_bib1_to_srw(bib1_code),
+ yaz_diag_bib1_to_srw(bib1_code),
ddf->u.v2Addinfo);
return 0;
}
}
// define Pimpl wrapper forwarding to Impl
-
+
yf::Template::Template() : m_p(new Impl)
{
}
}
yf::Template::Impl::~Impl()
-{
+{
}
void yf::Template::Impl::configure(const xmlNode *xmlnode, bool test_only,
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-// Filter that does nothing. Use as template for new filters
+// Filter that does nothing. Use as template for new filters
#ifndef FILTER_TEMPLATE_HPP
#define FILTER_TEMPLATE_HPP
BackendPtr b);
void fixup_npr_records(ODR odr, Z_Records *records,
BackendPtr b);
-
+
BackendPtr lookup_backend_from_databases(
std::list<std::string> databases);
BackendPtr create_backend_from_databases(
std::list<std::string> databases,
int &error_code,
std::string &failing_database);
-
+
BackendPtr init_backend(std::list<std::string> database,
Package &package,
int &error_code, std::string &addinfo);
Rep *m_p;
- };
+ };
class VirtualDB::Rep {
friend class VirtualDB;
friend struct Frontend;
-
+
FrontendPtr get_frontend(Package &package);
void release_frontend(Package &package);
void refresh_torus();
ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_3);
init_package.request() = init_apdu;
-
- init_package.move(b->m_route); // sending init
+
+ init_package.move(b->m_route); // sending init
Z_GDU *gdu = init_package.response().get();
// we hope to get an init response
close_package.move(b->m_route); // closing it
}
BackendPtr null;
- return null;
+ return null;
}
void yf::VirtualDB::Frontend::search(mp::Package &package, Z_APDU *apdu_req)
Sets_it sets_it = m_sets.find(req->resultSetName);
if (sets_it != m_sets.end())
{
- // result set already exist
+ // result set already exist
// if replace indicator is off: we return diagnostic if
// result set already exist.
if (*req->replaceIndicator == 0)
{
- Z_APDU *apdu =
+ Z_APDU *apdu =
odr.create_searchResponse(
apdu_req,
YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF,
0);
package.response() = apdu;
-
+
return;
- }
+ }
sets_it->second.m_backend->m_number_of_sets--;
}
// pick up any existing database with named result sets ..
if (!b)
{
// did not get a backend (unavailable somehow?)
-
- Z_APDU *apdu =
+
+ Z_APDU *apdu =
odr.create_searchResponse(
apdu_req, error_code, addinfo.c_str());
package.response() = apdu;
void yf::VirtualDB::Frontend::close(mp::Package &package)
{
std::list<BackendPtr>::const_iterator b_it;
-
+
for (b_it = m_backend_list.begin(); b_it != m_backend_list.end(); b_it++)
{
(*b_it)->m_backend_session.close();
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::VirtualDB::FrontendPtr>::iterator it;
-
+
while(true)
{
it = m_clients.find(package.session());
if (it == m_clients.end())
break;
-
+
if (!it->second->m_in_use)
{
it->second->m_in_use = true;
{
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::VirtualDB::FrontendPtr>::iterator it;
-
+
it = m_clients.find(package.session());
if (it != m_clients.end())
{
{
}
-yf::VirtualDB::Map::Map(std::string database,
+yf::VirtualDB::Map::Map(std::string database,
std::list<std::string> targets, std::string route)
- : m_dbpattern(database), m_targets(targets), m_route(route)
+ : m_dbpattern(database), m_targets(targets), m_route(route)
{
}
-yf::VirtualDB::Map::Map(std::string database,
+yf::VirtualDB::Map::Map(std::string database,
std::string target, std::string route)
- : m_dbpattern(database), m_route(route)
+ : m_dbpattern(database), m_route(route)
{
m_targets.push_back(target);
}
// consider each of the frontend databases..
std::list<std::string>::const_iterator db_it;
- for (db_it = b->m_frontend_databases.begin();
+ for (db_it = b->m_frontend_databases.begin();
db_it != b->m_frontend_databases.end(); db_it++)
{
// see which target it corresponds to.. (if any)
map_it++;
}
if (map_it != m_p->m_maps.end())
- {
+ {
std::list<std::string>::const_iterator t
= map_it->m_targets.begin();
while (t != map_it->m_targets.end())
t++;
}
}
-
+
}
db_it = b->m_frontend_databases.begin();
if (db_it != b->m_frontend_databases.end())
Sets_it sets_it = m_sets.find(resultSetId);
if (sets_it == m_sets.end())
{
- Z_APDU *apdu =
+ Z_APDU *apdu =
odr.create_presentResponse(
apdu_req,
YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
}
Session *id =
new mp::Session(sets_it->second.m_backend->m_backend_session);
-
+
// sending present to backend
Package present_package(*id, package.origin());
present_package.copy_filter(package);
req->resultSetId = odr_strdup(odr, sets_it->second.m_setname.c_str());
-
+
present_package.request() = ngdu;
present_package.move(sets_it->second.m_backend->m_route);
for (; map_it != m_backend_list.end(); map_it++)
{
BackendPtr b = *map_it;
-
+
Package relay_package(b->m_backend_session, package.origin());
relay_package.copy_filter(package);
if (tmp->m_frontend_databases == databases)
break;
}
- if (map_it != m_backend_list.end())
+ if (map_it != m_backend_list.end())
b = *map_it;
if (!b) // no backend yet. Must create a new one
{
odr.create_scanResponse(
apdu_req, error_code, addinfo.c_str());
package.response() = apdu;
-
+
return;
}
}
}
scan_package.request() = ngdu;
-
+
scan_package.move(b->m_route);
if (scan_package.session().is_closed())
}
-void yf::VirtualDB::add_map_db2targets(std::string db,
+void yf::VirtualDB::add_map_db2targets(std::string db,
std::list<std::string> targets,
std::string route)
{
}
-void yf::VirtualDB::add_map_db2target(std::string db,
+void yf::VirtualDB::add_map_db2target(std::string db,
std::string target,
std::string route)
FrontendPtr f = m_p->get_frontend(package);
Z_GDU *gdu = package.request().get();
-
+
if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
Z_APDU_initRequest && !f->m_is_virtual)
{
Z_InitRequest *req = gdu->u.z3950->u.initRequest;
-
+
std::list<std::string> vhosts;
mp::util::get_vhost_otherinfo(req->otherInfo, vhosts);
else
{
f->m_init_gdu = gdu;
-
+
mp::odr odr;
Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0);
Z_InitResponse *resp = apdu->u.initResponse;
-
+
int i;
static const int masks[] = {
Z_Options_search,
Z_Options_present,
Z_Options_namedResultSets,
Z_Options_scan,
- -1
+ -1
};
for (i = 0; masks[i] != -1; i++)
if (ODR_MASK_GET(req->options, masks[i]))
ODR_MASK_SET(resp->options, masks[i]);
-
+
static const int versions[] = {
Z_ProtocolVersion_1,
Z_ProtocolVersion_2,
ODR_MASK_SET(resp->protocolVersion, versions[i]);
else
break;
-
+
*resp->preferredMessageSize = *req->preferredMessageSize;
*resp->maximumRecordSize = *req->maximumRecordSize;
if (apdu->which == Z_APDU_initRequest)
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu,
Z_Close_protocolError,
"double init");
-
+
package.session().close();
}
else if (apdu->which == Z_APDU_searchRequest)
if (f->relay_apdu(package, apdu) == 0)
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu, Z_Close_finished, "virt_db");
-
+
package.session().close();
}
}
else
{
mp::odr odr;
-
+
package.response() = odr.create_close(
apdu, Z_Close_protocolError,
"unsupported APDU in filter_virt_db");
-
+
package.session().close();
}
}
{
if (v_node->type != XML_ELEMENT_NODE)
continue;
-
+
if (mp::xml::is_element_mp(v_node, "database"))
database = mp::xml::get_text(v_node);
else if (mp::xml::is_element_mp(v_node, "target"))
targets.push_back(mp::xml::get_text(v_node));
else
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) v_node->name)
+ " in virtual section"
);
else
{
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) ptr->name)
+ " in virt_db filter");
}
std::string host, int timeout_sec)
: Z_Assoc(PDU_Observable),
m_socket_manager(socket_manager), m_PDU_Observable(PDU_Observable),
- m_package(0), m_in_use(true), m_waiting(false),
+ m_package(0), m_in_use(true), m_waiting(false),
m_destroyed(false), m_connected(false), m_has_closed(false),
m_queue_len(1),
m_time_elapsed(0), m_time_max(timeout_sec), m_time_connect_max(10),
Z_APDU *apdu = 0;
if (gdu && gdu->which == Z_GDU_Z3950)
apdu = gdu->u.z3950;
-
+
m_package->response() = odr.create_close(apdu, Z_Close_peerAbort, 0);
m_package->session().close();
}
m_waiting = false;
mp::odr odr;
-
+
if (m_package)
{
Z_GDU *gdu = m_package->request().get();
Z_APDU *apdu = 0;
if (gdu && gdu->which == Z_GDU_Z3950)
apdu = gdu->u.z3950;
-
+
if (m_connected)
m_package->response() =
odr.create_close(apdu, Z_Close_lackOfActivity, 0);
else
- m_package->response() =
+ m_package->response() =
odr.create_close(apdu, Z_Close_peerAbort, 0);
-
+
m_package->session().close();
}
}
{
Z_DefaultDiagFormat *nsd = records->u.nonSurrogateDiagnostic;
std::string addinfo;
-
+
// should really check for nsd->which.. But union has two members
// containing almost same data
const char *v2Addinfo = nsd->u.v2Addinfo;
if (unit->which == Z_OtherInfo_externallyDefinedInfo &&
unit->information.externallyDefinedInfo &&
unit->information.externallyDefinedInfo->which ==
- Z_External_diag1)
+ Z_External_diag1)
{
Z_DiagnosticFormat *diag =
unit->information.externallyDefinedInfo->u.diag1;
r->u.v2Addinfo = naddinfo;
}
}
- }
+ }
}
}
}
m_waiting = false;
if (m_package)
- {
+ {
mp::odr odr; // must be in scope for response() = assignment
if (gdu && gdu->which == Z_GDU_Z3950)
{
yf::Z3950Client::~Z3950Client() {
}
-yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package)
+yf::Z3950Client::Assoc *yf::Z3950Client::Rep::get_assoc(Package &package)
{
// only one thread messes with the clients list at a time
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::Z3950Client::Assoc *>::iterator it;
-
+
Z_GDU *gdu = package.request().get();
-
+
int max_sockets = package.origin().get_max_sockets();
if (max_sockets == 0)
max_sockets = m_max_sockets;
-
+
it = m_clients.find(package.session());
if (it != m_clients.end())
{
if (apdu->which != Z_APDU_initRequest)
{
mp::odr odr;
-
+
package.response() = odr.create_close(apdu,
Z_Close_protocolError,
"First PDU was not an "
apdu,
YAZ_BIB1_INIT_NEGOTIATION_OPTION_REQUIRED,
"z3950_client: No vhost given");
-
+
package.session().close();
return 0;
}
return 0;
}
}
-
+
// see if we have reached max number of clients (max-sockets)
while (max_sockets)
if (no_not_in_use == 0) // all in use..
{
mp::odr odr;
-
+
package.response() = odr.create_initResponse(
apdu, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, "max sessions");
package.session().close();
}
boost::xtime xt;
xtime_get(&xt, boost::TIME_UTC);
-
+
xt.sec += 15;
if (!m_cond_session_ready.timed_wait(lock, xt))
{
mp::odr odr;
-
+
package.response() = odr.create_initResponse(
apdu, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, "max sessions");
package.session().close();
&& m_force_close)
{
mp::odr odr;
-
+
package.request() = odr.create_close(
0, Z_Close_finished, "z3950_client");
c->m_package = 0; // don't inspect response
return;
}
c->timeout(1); // so timeoutNotify gets called once per second
-
- while (!c->m_destroyed && c->m_waiting
+
+ while (!c->m_destroyed && c->m_waiting
&& c->m_socket_manager->processEvent() > 0)
;
}
// prepare response
c->m_time_elapsed = 0;
c->m_waiting = true;
-
+
// relay the package ..
int len;
c->send_GDU(gdu, &len);
{
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::Z3950Client::Assoc *>::iterator it;
-
+
it = m_clients.find(package.session());
if (it != m_clients.end())
{
}
else
{
- throw mp::filter::FilterException("Bad element "
+ throw mp::filter::FilterException("Bad element "
+ std::string((const char *)
ptr->name));
}
void yf::ZeeRexExplain::Impl::configure(const xmlNode *confignode)
{
const xmlNode * dbnode;
-
+
for (dbnode = confignode->children; dbnode; dbnode = dbnode->next){
if (dbnode->type != XML_ELEMENT_NODE)
continue;
-
+
std::string database;
mp::xml::check_element_mp(dbnode, "database");
- for (struct _xmlAttr *attr = dbnode->properties;
+ for (struct _xmlAttr *attr = dbnode->properties;
attr; attr = attr->next){
-
+
mp::xml::check_attribute(attr, "", "name");
database = mp::xml::get_text(attr);
-
+
std::cout << database << "\n";
-
+
const xmlNode *explainnode;
- for (explainnode = dbnode->children;
+ for (explainnode = dbnode->children;
explainnode; explainnode = explainnode->next){
if (explainnode->type != XML_ELEMENT_NODE)
continue;
if (explainnode)
break;
}
- // assigning explain node to database name - no check yet
+ // assigning explain node to database name - no check yet
m_database_explain.insert(std::make_pair(database, explainnode));
}
}
package.move();
return;
}
-
+
// only working on HTTP_Request packages now
mp::odr odr_de(ODR_DECODE);
package.move();
return;
}
-
+
// if SRU package could not be decoded, send minimal explain and
// close connection
Z_SOAP *soap = 0;
char *charset = 0;
char *stylesheet = 0;
- if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en,
+ if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en,
sru_pdu_res, &soap,
charset, stylesheet)))
{
- mp_util::build_sru_explain(package, odr_en, sru_pdu_res,
+ mp_util::build_sru_explain(package, odr_en, sru_pdu_res,
sruinfo, explainnode);
- mp_util::build_sru_response(package, odr_en, soap,
+ mp_util::build_sru_response(package, odr_en, soap,
sru_pdu_res, charset, stylesheet);
package.session().close();
return;
}
-
+
if (sru_pdu_req->which != Z_SRW_explain_request)
{
return;
}
// except valid SRU explain request, construct ZeeRex Explain response
- else
+ else
{
Z_SRW_explainRequest *er_req = sru_pdu_req->u.explain_request;
- //mp_util::build_simple_explain(package, odr_en, sru_pdu_res,
+ //mp_util::build_simple_explain(package, odr_en, sru_pdu_res,
// sruinfo, er_req);
- mp_util::build_sru_explain(package, odr_en, sru_pdu_res,
+ mp_util::build_sru_explain(package, odr_en, sru_pdu_res,
sruinfo, explainnode, er_req);
- mp_util::build_sru_response(package, odr_en, soap,
+ mp_util::build_sru_response(package, odr_en, soap,
sru_pdu_res, charset, stylesheet);
return;
}
// should never arrive here
package.session().close();
- return;
+ return;
}
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-// Filter that constructs valid ZeeRex Explain SRU responses
+// Filter that constructs valid ZeeRex Explain SRU responses
#ifndef FILTER_ZEEREX_EXPLAIN_HPP
#define FILTER_ZEEREX_EXPLAIN_HPP
std::string authentication,
std::string proxy,
std::string realm);
-
+
void prepare_elements(BackendPtr b,
Odr_oid *preferredRecordSyntax,
const char *element_set_name,
const char *element_set_name);
bool retry(mp::Package &package,
mp::odr &odr,
- BackendPtr b,
+ BackendPtr b,
int &error, char **addinfo,
int &proxy_step, int &same_retries,
int &proxy_retries);
void release_frontend(mp::Package &package);
SearchablePtr parse_torus_record(const xmlNode *ptr);
struct cql_node *convert_cql_fields(struct cql_node *cn, ODR odr);
- std::map<mp::Session, FrontendPtr> m_clients;
+ std::map<mp::Session, FrontendPtr> m_clients;
boost::mutex m_mutex;
boost::condition m_cond_session_ready;
std::string torus_searchable_url;
return ptr;
}
else // else: we don't want to find nested nodes
- {
+ {
xmlNode *ret_node = xml_node_search(ptr->children, num, m);
if (ret_node)
return ret_node;
}
// define Pimpl wrapper forwarding to Impl
-
+
yf::Zoom::Zoom() : m_p(new Impl)
{
}
{
if (!dset)
dset = "Unknown";
-
+
if (!strcmp(dset, "info:srw/diagnostic/1"))
*error = yaz_diag_srw_to_bib1(error0);
else if (!strcmp(dset, "Bib-1"))
*error = error0;
else if (!strcmp(dset, "ZOOM"))
{
- *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+ *error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
if (error0 == ZOOM_ERROR_INIT)
*error = YAZ_BIB1_INIT_AC_AUTHENTICATION_SYSTEM_ERROR;
else if (error0 == ZOOM_ERROR_DECODE)
}
else
*error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
-
+
*addinfo = (char *) odr_malloc(
odr, 30 + strlen(dset) + strlen(msg) +
(zoom_addinfo ? strlen(zoom_addinfo) : 0));
zurl.erase(h);
ZOOM_connection_connect(m_connection, zurl.length() ? zurl.c_str() : 0, 0);
get_zoom_error(error, addinfo, odr);
-
+
}
void yf::Zoom::Backend::search(ZOOM_query q, Odr_int *hits,
ccl_qual_rm(&ccl_bibset);
}
-yf::Zoom::Frontend::Frontend(Impl *impl) :
+yf::Zoom::Frontend::Frontend(Impl *impl) :
m_p(impl), m_is_virtual(false), m_in_use(true)
{
}
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::Zoom::FrontendPtr>::iterator it;
-
+
while(true)
{
it = m_clients.find(package.session());
if (it == m_clients.end())
break;
-
+
if (!it->second->m_in_use)
{
it->second->m_in_use = true;
{
boost::mutex::scoped_lock lock(m_mutex);
std::map<mp::Session,yf::Zoom::FrontendPtr>::iterator it;
-
+
it = m_clients.find(package.session());
if (it != m_clients.end())
{
yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr)
{
Zoom::SearchablePtr s(new Searchable(bibset));
-
+
for (ptr = ptr->children; ptr; ptr = ptr->next)
{
if (ptr->type != XML_ELEMENT_NODE)
"cfAuth"))
{
s->cfAuth = mp::xml::get_text(ptr);
- }
+ }
else if (!strcmp((const char *) ptr->name,
"cfProxy"))
{
s->cfProxy = mp::xml::get_text(ptr);
- }
+ }
else if (!strcmp((const char *) ptr->name,
"cfSubDB"))
{
s->cfSubDB = mp::xml::get_text(ptr);
- }
+ }
else if (!strcmp((const char *) ptr->name,
"contentConnector"))
{
s->contentConnector = mp::xml::get_text(ptr);
- }
+ }
else if (!strcmp((const char *) ptr->name, "udb"))
{
s->udb = mp::xml::get_text(ptr);
{
while (ptr && ptr->type != XML_ELEMENT_NODE)
ptr = ptr->next;
-
+
if (ptr)
{
if (!strcmp((const char *) ptr->name, "records"))
else
{
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) ptr->name)
+ " in zoom filter inside element "
"<torus><records>");
else
{
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) ptr->name)
+ " in zoom filter inside element <torus>");
}
{
yaz_log(YLOG_WARN,
"contentProxy's server attribute is deprecated");
- yaz_log(YLOG_LOG,
+ yaz_log(YLOG_LOG,
"Specify config_file instead. For example:");
- yaz_log(YLOG_LOG,
+ yaz_log(YLOG_LOG,
" content_file=\"/etc/cf-proxy/cproxy.cfg\"");
content_proxy_server = mp::xml::get_text(attr->children);
}
}
}
else if (!strcmp((const char *) ptr->name, "log"))
- {
+ {
const struct _xmlAttr *attr;
for (attr = ptr->properties; attr; attr = attr->next)
{
else
{
throw mp::filter::FilterException
- ("Bad element "
+ ("Bad element "
+ std::string((const char *) ptr->name)
+ " in zoom filter");
}
if (explain_xslt_fname.length())
{
const char *path = 0;
-
+
if (xsldir.length())
path = xsldir.c_str();
else
path = file_path.c_str();
-
+
char fullpath[1024];
char *cp = yaz_filepath_resolve(explain_xslt_fname.c_str(),
path, 0, fullpath);
xmlFreeDoc(xsp_doc);
throw mp::filter::FilterException
("Cannot parse XSLT " + explain_xslt_fname);
-
+
}
}
if (record_xslt_fname.length())
{
const char *path = 0;
-
+
if (xsldir.length())
path = xsldir.c_str();
else
path = file_path.c_str();
-
+
char fullpath[1024];
char *cp = yaz_filepath_resolve(record_xslt_fname.c_str(),
path, 0, fullpath);
xmlFreeDoc(xsp_doc);
throw mp::filter::FilterException
("Cannot parse XSLT " + record_xslt_fname);
-
+
}
}
}
proxyhostname = m_p->content_proxy_server;
legacy_format = true;
}
-
+
if (m_p->content_tmp_file.length())
tmp_file = m_p->content_tmp_file;
while (*cp == ' ')
cp++;
if (!strcmp(buf, "proxyhostname"))
- proxyhostname = cp;
+ proxyhostname = cp;
if (!strcmp(buf, "sessiondir") && *cp)
{
if (cp[strlen(cp)-1] == '/')
std::string proxy;
std::list<BackendPtr>::const_iterator map_it;
- if (m_backend && !m_backend->enable_explain &&
+ if (m_backend && !m_backend->enable_explain &&
m_backend->m_frontend_database == database)
{
connection_reuse = true;
odr_malloc(odr, (10 + no_parms) * sizeof(*out_names));
const char **out_values = (const char **)
odr_malloc(odr, (10 + no_parms) * sizeof(*out_values));
-
+
// may be changed if it's a content connection
std::string torus_url = m_p->torus_searchable_url;
int i;
else
{
proxy = dstr[*proxy_step];
-
+
(*proxy_step)++;
if (*proxy_step == dnum)
*proxy_step = 0;
*addinfo = msg;
return notfound;
}
- }
+ }
if (proxy.length())
package.log("zoom", YLOG_LOG, "proxy: %s", proxy.c_str());
if (torus_db.compare("IR-Explain---1") == 0)
return explain_search(package, database, error, addinfo, odr, torus_url,
torus_db, realm);
-
+
SearchablePtr sptr;
std::map<std::string,SearchablePtr>::iterator it;
BackendPtr b;
return b;
}
-
+
xsltStylesheetPtr xsp = 0;
if (sptr->transform_xsl_content.length())
{
*error = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
*addinfo = (char *)
odr_malloc(odr, 40 + sptr->transform_xsl_fname.length());
- sprintf(*addinfo, "File could not be read: %s",
+ sprintf(*addinfo, "File could not be read: %s",
sptr->transform_xsl_fname.c_str());
BackendPtr b;
return b;
b->set_option("extraArgs", sptr->extraArgs);
b->set_option("timeout", m_p->zoom_timeout.c_str());
-
- if (m_p->apdu_log)
+
+ if (m_p->apdu_log)
b->set_option("apdulog", "1");
if (sptr->piggyback && sptr->sru.length())
if (proxy.length() == 0)
proxy = sptr->cfProxy;
b->m_proxy = proxy;
-
+
if (sptr->cfAuth.length())
{
// A CF target
out_names[no_out_args] = "user";
out_values[no_out_args++] =
odr_strdup(odr, authentication.c_str());
- }
+ }
}
if (proxy.length())
{
else
{
size_t found = authentication.find('/');
-
+
if (sptr->sru.length() && found != std::string::npos)
{
b->set_option("user", authentication.substr(0, found));
{
char *x_args = 0;
out_names[no_out_args] = 0; // terminate list
-
+
yaz_array_to_uri(&x_args, odr, (char **) out_names,
(char **) out_values);
url += "," + std::string(x_args);
{
char oid_name_str[OID_STR_MAX];
const char *syntax_name = 0;
-
+
if (preferredRecordSyntax &&
!oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml))
{
enable_pz2_retrieval = true;
enable_pz2_transform = true;
}
- else if (element_set_name &&
+ else if (element_set_name &&
!strcmp(element_set_name, m_p->element_raw.c_str()))
{
enable_pz2_retrieval = true;
enable_record_transform = true;
}
}
-
+
if (enable_pz2_retrieval)
{
std::string configured_request_syntax = b->sptr->request_syntax;
if (configured_request_syntax.length())
{
syntax_name = configured_request_syntax.c_str();
- const Odr_oid *syntax_oid =
+ const Odr_oid *syntax_oid =
yaz_string_to_oid(yaz_oid_std(), CLASS_RECSYN, syntax_name);
if (!oid_oidcmp(syntax_oid, yaz_oid_recsyn_usmarc)
|| !oid_oidcmp(syntax_oid, yaz_oid_recsyn_opac))
number_to_present = 10000;
xmlNode *ptr = xmlDocGetRootElement(b->explain_doc);
-
+
Z_NamePlusRecordList *npl = (Z_NamePlusRecordList *)
odr_malloc(odr, sizeof(*npl));
npl->records = (Z_NamePlusRecord **)
odr_malloc(odr, number_to_present * sizeof(*npl->records));
-
+
for (i = 0; i < number_to_present; i++)
{
int num = 0;
if (start < 0 || number_to_present <=0)
return records;
-
+
if (number_to_present > 10000)
number_to_present = 10000;
const char *xsl_parms[3];
mp::wrbuf cproxy_host;
-
+
if (b->enable_cproxy && b->cproxy_host.length())
{
wrbuf_puts(cproxy_host, "\"");
int sur_error = ZOOM_record_error(recs[i], 0 /* msg */,
&addinfo, 0 /* diagset */);
-
+
if (sur_error)
{
log_diagnostic(package, sur_error, addinfo);
odr, odr_database, error, addinfo);
}
else
- {
+ {
// first stage XSLT - per target
xsltStylesheetPtr xsp = b->xsp;
xmlDoc *rec_res = xsltApplyStylesheet(xsp, rec_doc,
// insert generated-url
if (rec_res)
{
- std::string res =
+ std::string res =
mp::xml::url_recipe_handle(rec_res,
b->sptr->urlRecipe);
if (res.length())
xmlNode *ptr = xmlDocGetRootElement(rec_res);
while (ptr && ptr->type != XML_ELEMENT_NODE)
ptr = ptr->next;
- xmlNode *c =
+ xmlNode *c =
xmlNewChild(ptr, 0, BAD_CAST "metadata", 0);
xmlNewProp(c, BAD_CAST "type", BAD_CAST
"generated-url");
{
if (!rec_buf)
npr = zget_surrogateDiagRec(
- odr, odr_database,
+ odr, odr_database,
YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
rec_type_str);
else
else
{
npr = zget_surrogateDiagRec(
- odr, odr_database,
+ odr, odr_database,
YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
"ZOOM_record, type ext");
}
b->m_frontend_database = database;
b->enable_explain = true;
-
+
Z_GDU *gdu = package.request().get();
Z_APDU *apdu_req = gdu->u.z3950;
Z_SearchRequest *sr = apdu_req->u.searchRequest;
{
xmlNode *ptr = xmlDocGetRootElement(doc);
int hits = 0;
-
+
xml_node_search(ptr, &hits, 0);
Z_APDU *apdu_res = odr.create_searchResponse(apdu_req, 0, 0);
pfd.fd = cs_fileno(cs);
pfd.client_data = 0;
-
+
int ret = yaz_poll(&pfd, 1, secs, 0);
return ret > 0;
}
Z_GDU *gdu = z_get_HTTP_Request_uri(odr, uri, 0, 1);
gdu->u.HTTP_Request->method = odr_strdup(odr, "GET");
-
+
if (z_GDU(odr, &gdu, 0, 0))
{
int len;
char *buf = odr_getbuf(odr, &len, 0);
-
+
int ret = cs_connect(conn, add);
if (ret > 0 || (ret == 0 && wait_conn(conn, 1)))
{
bool yf::Zoom::Frontend::retry(mp::Package &package,
mp::odr &odr,
- BackendPtr b,
+ BackendPtr b,
int &error, char **addinfo,
int &proxy_step, int &same_retries,
int &proxy_retries)
error = YAZ_BIB1_MALFORMED_QUERY;
const char *addinfo = "CQL syntax error";
log_diagnostic(package, error, addinfo);
- apdu_res =
+ apdu_res =
odr.create_searchResponse(apdu_req, error, addinfo);
package.response() = apdu_res;
return;
addinfo = 0;
if (cn_error->which == CQL_NODE_ST)
addinfo = cn_error->u.st.index;
-
+
log_diagnostic(package, error, addinfo);
apdu_res = odr.create_searchResponse(apdu_req, error, addinfo);
package.response() = apdu_res;
yaz_tok_parse_t tp =
yaz_tok_parse_buf(tc, wrbuf_cstr(sort_spec_wrbuf));
yaz_tok_cfg_destroy(tc);
-
+
/* go through sortspec and map fields */
int token = yaz_tok_move(tp);
while (token != YAZ_TOK_EOF)
switch (cerror)
{
case CCL_ERR_UNKNOWN_QUAL:
- case CCL_ERR_TRUNC_NOT_LEFT:
+ case CCL_ERR_TRUNC_NOT_LEFT:
case CCL_ERR_TRUNC_NOT_RIGHT:
case CCL_ERR_TRUNC_NOT_BOTH:
#ifdef CCL_ERR_TRUNC_NOT_EMBED
package.log("zoom", YLOG_LOG, "RPN: %s", wrbuf_cstr(pqf_wrbuf));
ccl_rpn_delete(cn);
}
-
+
assert(pqf_wrbuf.len());
ZOOM_query q = ZOOM_query_create();
Z_RPNQuery *zquery;
zquery = p_query_rpn(odr, wrbuf_cstr(pqf_wrbuf));
mp::wrbuf wrb;
-
+
if (!strcmp(b->get_option("sru"), "solr"))
{
solr_transform_t cqlt = solr_transform_create();
-
+
status = solr_transform_rpn2solr_wrbuf(cqlt, wrb, zquery);
-
+
solr_transform_close(cqlt);
}
else
b->search(q, &hits, &error, &addinfo, odr);
}
ZOOM_query_destroy(q);
-
+
if (status)
{
error = YAZ_BIB1_MALFORMED_QUERY;
Odr_int number_to_present = 0;
if (!error)
mp::util::piggyback_sr(sr, hits, number_to_present, &element_set_name);
-
+
Odr_int number_of_records_returned = 0;
Z_Records *records = get_records(
package,
if (comp && comp->which != Z_RecordComp_simple)
{
package.response() = odr.create_presentResponse(
- apdu_req,
+ apdu_req,
YAZ_BIB1_PRESENT_COMP_SPEC_PARAMETER_UNSUPP, 0);
return;
}
*pr->resultSetStartPoint - 1, *pr->numberOfRecordsRequested,
&error, &addinfo, &number_of_records_returned, odr, m_backend,
pr->preferredRecordSyntax, element_set_name);
-
+
apdu_res = odr.create_presentResponse(apdu_req, error, addinfo);
if (records)
{
*pr->resultSetStartPoint - 1, *pr->numberOfRecordsRequested,
&error, &addinfo, &number_of_records_returned, odr, m_backend,
pr->preferredRecordSyntax, element_set_name);
-
+
apdu_res = odr.create_presentResponse(apdu_req, error, addinfo);
if (records)
{
failure_code = YAZ_BIB1_INIT_AC_BAD_USERID_AND_OR_PASSWORD;
}
else
- {
+ {
const char *ip_cstr = ip.c_str();
const char *cp = strchr(ip_cstr, ':');
if (cp)
!strcmp((const char *) ptr->name, "identityId"))
break;
ptr = ptr->next;
- }
+ }
}
if (!ptr)
{
{
Z_InitRequest *req = gdu->u.z3950->u.initRequest;
f->m_init_gdu = gdu;
-
+
mp::odr odr;
Z_APDU *apdu = odr.create_initResponse(gdu->u.z3950, 0, 0);
Z_InitResponse *resp = apdu->u.initResponse;
-
+
int i;
static const int masks[] = {
Z_Options_search,
Z_Options_present,
- -1
+ -1
};
for (i = 0; masks[i] != -1; i++)
if (ODR_MASK_GET(req->options, masks[i]))
ODR_MASK_SET(resp->options, masks[i]);
-
+
static const int versions[] = {
Z_ProtocolVersion_1,
Z_ProtocolVersion_2,
ODR_MASK_SET(resp->protocolVersion, versions[i]);
else
break;
-
+
*resp->preferredMessageSize = *req->preferredMessageSize;
*resp->maximumRecordSize = *req->maximumRecordSize;
std::ostream& std::operator<<(std::ostream& os, Z_HTTP_Request& httpreq)
{
os << httpreq.method << " ";
- os << httpreq.path;
+ os << httpreq.path;
return os;
}
std::ostream& std::operator<<(std::ostream& os, Z_HTTP_Response& httpres)
{
os << httpres.code << " ";
- os << httpres.content_len;
+ os << httpres.content_len;
return os;
}
default:
os << "Z_Records" ;
}
-
+
return os;
}
default:
os << "Z_DiagRec" ;
}
-
+
return os;
}
default:
os << "-";
}
-
+
return os;
}
case Z_APDU_initRequest:
os << " " << "initRequest";
-
+
{
- Z_InitRequest *ir
+ Z_InitRequest *ir
= zapdu.u.initRequest;
Z_IdAuthentication *a = ir->idAuthentication;
dump_opt_string(os, a->u.open);
else
dump_opt_string(os, 0);
-
+
os << " ";
std::list<std::string> vhosts;
mp::util::get_vhost_otherinfo(ir->otherInfo, vhosts);
if (vhosts.size()){
- copy(vhosts.begin(), vhosts.end(),
+ copy(vhosts.begin(), vhosts.end(),
ostream_iterator<string>(os, " "));
}
else
os << "-" ;
-
+
dump_opt_string(os, ir->implementationId);
dump_opt_string(os, ir->implementationName);
dump_opt_string(os, ir->implementationVersion);
case Z_APDU_initResponse:
os << " " << "initResponse ";
{
- Z_InitResponse *ir
+ Z_InitResponse *ir
= zapdu.u.initResponse;
if (ir->result && *(ir->result))
{
break;
case Z_APDU_searchRequest:
os << " " << "searchRequest" << " ";
- {
- Z_SearchRequest *sr
+ {
+ Z_SearchRequest *sr
= zapdu.u.searchRequest;
-
+
for (int i = 0; i < sr->num_databaseNames; i++)
{
os << sr->databaseNames[i];
char oid_name_str[OID_STR_MAX];
const char *oid_name = yaz_oid_to_string_buf(
pr->preferredRecordSyntax, 0, oid_name_str);
-
+
os << " " << oid_name;
}
else
case Z_APDU_presentResponse:
os << " " << "presentResponse" << " ";
{
- Z_PresentResponse *pr
+ Z_PresentResponse *pr
= zapdu.u.presentResponse;
if (!pr->presentStatus)
os << "Unknown";
break;
case Z_APDU_scanRequest:
os << " " << "scanRequest" << " ";
- {
+ {
Z_ScanRequest *sr = zapdu.u.scanRequest;
-
+
if (sr)
{
for (int i = 0; i < sr->num_databaseNames; i++)
if (sr->termListAndStartPoint)
{
mp::wrbuf wr;
- yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint,
+ yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint,
sr->attributeSet);
os << wrbuf_cstr(wr);
}
break;
case Z_APDU_extendedServicesRequest:
os << " " << "extendedServicesRequest";
- {
- Z_ExtendedServicesRequest *er
+ {
+ Z_ExtendedServicesRequest *er
= zapdu.u.extendedServicesRequest;
if (er)
{
}
else
os << " -";
-
-
+
+
if (er->userId)
os << " " << er->userId ;
else
os << " -";
-
+
if (er->packageName)
os << " " << er->packageName;
else
os << " -";
-
+
if (er->description)
os << " " << er->description;
else
break;
case Z_APDU_extendedServicesResponse:
os << " " << "extendedServicesResponse";
- {
- Z_ExtendedServicesResponse *er
+ {
+ Z_ExtendedServicesResponse *er
= zapdu.u.extendedServicesResponse;
if (er)
{
break;
case Z_APDU_close:
os << " " << "close" << " ";
- {
+ {
Z_Close *c = zapdu.u.close;
if (c)
{
os << "unknown";
}
}
-
+
if (c->diagnosticInformation)
os << " " << c->diagnosticInformation;
}
case Z_APDU_duplicateDetectionResponse:
os << " " << "duplicateDetectionResponse";
break;
- default:
+ default:
os << " " << "Z_APDU " << "UNKNOWN";
}
#include <iosfwd>
-namespace std
+namespace std
{
std::ostream& operator<<(std::ostream& os, Z_GDU& zgdu);
- std::ostream& operator<<(std::ostream& os, Z_APDU& zapdu);
+ std::ostream& operator<<(std::ostream& os, Z_APDU& zapdu);
std::ostream& operator<<(std::ostream& os, Z_HTTP_Request& httpreq);
std::ostream& operator<<(std::ostream& os, Z_HTTP_Response& httpres);
std::ostream& operator<<(std::ostream& os, Z_Records & rs);
namespace gdu {
- }
+ }
}
#endif
{
work_common(data);
}
-
+
static void work_normal(void *data)
{
#if HAVE_UNISTD_H
unsigned mode = 0;
const char *pidfile = 0;
const char *uid = 0;
-
- while ((ret = options("c{config}:Dh{help}l:p:tu:V{version}w:X",
+
+ while ((ret = options("c{config}:Dh{help}l:p:tu:V{version}w:X",
argv, argc, &arg)) != -2)
{
switch (ret)
" -install install windows service\n"
" -remove remove windows service\n"
#endif
-
+
<< std::endl;
break;
case 'l':
#else
chdir(arg)
#endif
- )
+ )
{
std::cerr << "chdir " << arg << " failed" << std::endl;
return 1;
std::cerr << "No configuration given; use -h for help\n";
return 1;
}
-
+
if (!test_config)
yaz_log(YLOG_LOG, "metaproxy start " VERSION
#ifdef VERSION_SHA1
yaz_log_xml_errors(0, YLOG_LOG);
xmlDocPtr doc = xmlReadFile(fname,
- NULL,
+ NULL,
XML_PARSE_XINCLUDE + XML_PARSE_NOBLANKS
+ XML_PARSE_NSCLEAN + XML_PARSE_NONET );
-
+
if (!doc)
{
yaz_log(YLOG_FATAL,"XML parsing failed");
new mp::RouterFleXML(doc, factory, test_config, wrbuf_cstr(base_path));
if (!test_config)
{
-
+
yaz_sc_running(s);
-
+
yaz_daemon("metaproxy", mode, mode == YAZ_DAEMON_DEBUG ?
work_debug : work_normal, router, pidfile, uid);
}
os << ":" << o.m_custom_session;
return os;
}
-
+
/*
* Local variables:
* c-basic-offset: 4
};
}
-mp::Package::Package()
+mp::Package::Package()
: m_route_pos(0)
{
}
delete m_route_pos;
}
-mp::Package::Package(mp::Session &session, const mp::Origin &origin)
+mp::Package::Package(mp::Session &session, const mp::Origin &origin)
: m_session(session), m_origin(origin),
m_route_pos(0)
{
return m_session;
}
-mp::Origin mp::Package::origin() const
+mp::Origin mp::Package::origin() const
{
return m_origin;
}
-
+
mp::Origin & mp::Package::origin()
{
return m_origin;
throw Pipe::Error("could not create socket");
#ifndef WIN32
unsigned long one = 1;
- if (setsockopt(m_p->m_socket, SOL_SOCKET, SO_REUSEADDR, (char*)
+ if (setsockopt(m_p->m_socket, SOL_SOCKET, SO_REUSEADDR, (char*)
&one, sizeof(one)) < 0)
throw Pipe::Error("setsockopt error");
#endif
add.sin_port = htons(port_to_use);
add.sin_addr.s_addr = INADDR_ANY;
struct sockaddr *addr = ( struct sockaddr *) &add;
-
+
if (bind(m_p->m_socket, addr, sizeof(struct sockaddr_in)))
throw Pipe::Error("could not bind on socket");
-
+
if (listen(m_p->m_socket, 3) < 0)
throw Pipe::Error("could not listen on socket");
memcpy(&add.sin_addr.s_addr, &tmpadd, sizeof(struct in_addr));
else
throw Pipe::Error("inet_addr failed");
-
+
m_p->m_fd[1] = socket(AF_INET, SOCK_STREAM, 0);
if (m_p->m_fd[1] < 0)
throw Pipe::Error("could not create socket");
-
+
m_p->nonblock(m_p->m_fd[1]);
if (connect(m_p->m_fd[1], addr, sizeof(*addr)) < 0)
class Pipe {
class Error : public std::runtime_error {
public:
- Error(const std::string msg)
+ Error(const std::string msg)
: std::runtime_error("Pipe error: " + msg) {};
};
class Rep;
m_p->close(); // might as well close it now
return false;
}
-
+
m_p->lineno++;
m_p->fh->getline(line_cstr, PLAINFILE_MAX_LINE-1);
char first = line_cstr[0];
virtual ~Pos();
mp::RouterFleXML::Rep *m_p;
- std::map<std::string,
+ std::map<std::string,
RouterFleXML::Route>::iterator m_route_it;
std::list<boost::shared_ptr <const mp::filter::Base> >::iterator m_filter_it;
};
{
std::string name = std::string((const char *) attr->name);
std::string value;
-
+
if (attr->children && attr->children->type == XML_TEXT_NODE)
value = std::string((const char *)attr->children->content);
-
+
if (name == "refid")
refid_value = value;
else if (name == "type")
m_factory->add_creator_dl(type_value, m_dl_path);
}
mp::filter::Base* filter_base = m_factory->create(type_value);
-
+
filter_base->configure(node, test_only, file_include_path);
-
+
route.m_list.push_back(
boost::shared_ptr<mp::filter::Base>(filter_base));
}
-
+
}
node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
}
{
std::string name = std::string((const char *) attr->name);
std::string value;
-
+
if (attr->children && attr->children->type == XML_TEXT_NODE)
value = std::string((const char *)attr->children->content);
-
+
if (name == "id")
id_value = value;
else
if (!strcmp((const char *) attr->name, "route"))
{
std::string value;
-
+
if (attr->children && attr->children->type == XML_TEXT_NODE)
value = std::string((const char *)attr->children->content);
-
+
std::map<std::string,RouterFleXML::Route>::iterator it;
it = m_routes.find(value);
if (it == m_routes.end())
{
if (!doc)
throw mp::XMLError("Empty XML Document");
-
+
const xmlNode* root = xmlDocGetRootElement(doc);
if (file_include_path)
if (r)
throw mp::XMLError("YAZ XML Include failed");
}
-
+
mp::xml::check_element_mp(root, "metaproxy");
const xmlNode* node = mp::xml::jump_to_children(root, XML_ELEMENT_NODE);
parse_xml_filters(doc, mp::xml::jump_to_children(node,
XML_ELEMENT_NODE),
test_only, file_include_path);
-
+
node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
}
// process <routes> node which is expected third element node
mp::xml::check_element_mp(node, "routes");
-
+
parse_xml_routes(doc, mp::xml::jump_to_children(node, XML_ELEMENT_NODE),
test_only, file_include_path);
node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
if (node)
{
- throw mp::XMLError("Unexpected element "
+ throw mp::XMLError("Unexpected element "
+ std::string((const char *)node->name));
}
{
check_routes_in_filters(
mp::xml::jump_to_children(n, XML_ELEMENT_NODE));
-
+
}
n = mp::xml::jump_to_next(n, XML_ELEMENT_NODE);
}
}
mp::RouterFleXML::RouterFleXML(std::string xmlconf, mp::FactoryFilter &factory,
- bool test_only)
+ bool test_only)
: m_p(new Rep)
-{
+{
LIBXML_TEST_VERSION;
-
+
xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(),
xmlconf.size());
if (!doc)
#include <boost/scoped_ptr.hpp>
-namespace metaproxy_1
+namespace metaproxy_1
{
- class RouterFleXML : public metaproxy_1::Router
+ class RouterFleXML : public metaproxy_1::Router
{
class Rep;
class Route;
bool test_only);
RouterFleXML(xmlDocPtr doc, metaproxy_1::FactoryFilter &factory,
bool test_only, const char *file_include_path);
-
+
~RouterFleXML();
virtual RoutePos *createpos() const;
private:
boost::scoped_ptr<Rep> m_p;
};
-
+
};
#endif
{
Z_GDU *zgdu_req = package.request().get();
if (zgdu_req && zgdu_req->which == Z_GDU_HTTP_Request)
- {
+ {
Z_HTTP_Request* http_req = zgdu_req->u.HTTP_Request;
std::string content = mp_util::http_headers_debug(*http_req);
- int http_code = 400;
+ int http_code = 400;
mp_util::http_response(package, content, http_code);
return true;
}
if (http_req)
{
std::string http_path = http_req->path;
-
+
// taking out GET parameters
std::string::size_type ipath = http_path.rfind("?");
if (ipath != std::string::npos)
// assign to database name
if (http_path.size() > 1)
sruinfo.database.assign(http_path, 1, std::string::npos);
-
+
std::string http_host_address
= mp_util::http_header_value(http_req->headers, "Host");
if (iaddress != std::string::npos)
{
sruinfo.host.assign(http_host_address, 0, iaddress);
- sruinfo.port.assign(http_host_address, iaddress + 1,
+ sruinfo.port.assign(http_host_address, iaddress + 1,
std::string::npos);
}
}
}
-
+
//std::cout << "sruinfo.database " << sruinfo.database << "\n";
//std::cout << "sruinfo.host " << sruinfo.host << "\n";
//std::cout << "sruinfo.port " << sruinfo.port << "\n";
}
-bool mp_util::build_sru_explain(metaproxy_1::Package &package,
+bool mp_util::build_sru_explain(metaproxy_1::Package &package,
metaproxy_1::odr &odr_en,
Z_SRW_PDU *sru_pdu_res,
SRUServerInfo sruinfo,
{
// building SRU explain record
- std::string explain_xml;
+ std::string explain_xml;
if (explain == 0)
{
- explain_xml
+ explain_xml
= mp_util::to_string(
"<explain xmlns=\"" + xmlns_explain + "\">\n"
" <serverInfo protocol='SRU'>\n"
// z3950'fy recordPacking
int record_packing = Z_SRW_recordPacking_XML;
if (er_req && er_req->recordPacking && 's' == *(er_req->recordPacking))
- record_packing = Z_SRW_recordPacking_string;
-
+ record_packing = Z_SRW_recordPacking_string;
+
// preparing explain record insert
Z_SRW_explainResponse *sru_res = sru_pdu_res->u.explain_response;
-
+
// inserting one and only explain record
-
+
sru_res->record.recordPosition = odr_intdup(odr_en, 1);
sru_res->record.recordPacking = record_packing;
sru_res->record.recordSchema = (char *)xmlns_explain.c_str();
sru_res->record.recordData_len = 1 + explain_xml.size();
sru_res->record.recordData_buf
- = odr_strdupn(odr_en, (const char *)explain_xml.c_str(),
+ = odr_strdupn(odr_en, (const char *)explain_xml.c_str(),
1 + explain_xml.size());
return true;
}
-bool mp_util::build_sru_response(mp::Package &package,
+bool mp_util::build_sru_response(mp::Package &package,
mp::odr &odr_en,
Z_SOAP *soap,
const Z_SRW_PDU *sru_pdu_res,
char *charset,
- const char *stylesheet)
+ const char *stylesheet)
{
// SRU request package translation to Z3950 package
//else
// std::cout << "SRU empty\n";
-
+
Z_GDU *zgdu_req = package.request().get();
if (zgdu_req && zgdu_req->which == Z_GDU_HTTP_Request)
- {
+ {
Z_GDU *zgdu_res //= z_get_HTTP_Response(odr_en, 200);
- = odr_en.create_HTTP_Response(package.session(),
- zgdu_req->u.HTTP_Request,
+ = odr_en.create_HTTP_Response(package.session(),
+ zgdu_req->u.HTTP_Request,
200);
// adding HTTP response code and headers
Z_HTTP_Response * http_res = zgdu_res->u.HTTP_Response;
//http_res->code = http_code;
-
+
std::string ctype("text/xml");
if (charset)
{
ctype += charset;
}
- z_HTTP_header_add(odr_en,
+ z_HTTP_header_add(odr_en,
&http_res->headers, "Content-Type", ctype.c_str());
// packaging Z_SOAP into HTML response
// empty stylesheet means NO stylesheet
if (stylesheet && *stylesheet == '\0')
stylesheet = 0;
-
+
// encoding SRU package
-
- soap->u.generic->p = (void*) sru_pdu_res;
- //int ret =
- z_soap_codec_enc_xsl(odr_en, &soap,
+
+ soap->u.generic->p = (void*) sru_pdu_res;
+ //int ret =
+ z_soap_codec_enc_xsl(odr_en, &soap,
&http_res->content_buf, &http_res->content_len,
soap_handlers, charset, stylesheet);
-
+
package.response() = zgdu_res;
return true;
Z_SRW_PDU *sru_pdu_res,
Z_SOAP **soap,
char *charset,
- char *stylesheet)
+ char *stylesheet)
{
Z_GDU *zgdu_req = package.request().get();
Z_SRW_PDU *sru_pdu_req = 0;
//assert((zgdu_req->which == Z_GDU_HTTP_Request));
-
+
//ignoring all non HTTP_Request packages
if (!zgdu_req || !(zgdu_req->which == Z_GDU_HTTP_Request))
{
return 0;
}
-
+
Z_HTTP_Request* http_req = zgdu_req->u.HTTP_Request;
if (! http_req)
return 0;
// checking if we got a SRU GET/POST/SOAP HTTP package
// closing connection if we did not ...
- if (0 == yaz_sru_decode(http_req, &sru_pdu_req, soap,
- odr_de, &charset,
- &(sru_pdu_res->u.response->diagnostics),
+ if (0 == yaz_sru_decode(http_req, &sru_pdu_req, soap,
+ odr_de, &charset,
+ &(sru_pdu_res->u.response->diagnostics),
&(sru_pdu_res->u.response->num_diagnostics)))
{
if (sru_pdu_res->u.response->num_diagnostics)
}
return sru_pdu_req;
}
- else if (0 == yaz_srw_decode(http_req, &sru_pdu_req, soap,
+ else if (0 == yaz_srw_decode(http_req, &sru_pdu_req, soap,
odr_de, &charset))
return sru_pdu_req;
- else
+ else
{
//sru_pdu_res = sru_pdu_res_exp;
package.session().close();
}
-bool
-mp_util::check_sru_query_exists(mp::Package &package,
+bool
+mp_util::check_sru_query_exists(mp::Package &package,
mp::odr &odr_en,
- Z_SRW_PDU *sru_pdu_res,
+ Z_SRW_PDU *sru_pdu_res,
Z_SRW_searchRetrieveRequest const *sr_req)
{
if ((sr_req->query_type == Z_SRW_query_type_cql && !sr_req->query.cql))
{
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED,
"query");
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
YAZ_SRW_QUERY_SYNTAX_ERROR,
"CQL query is empty");
return false;
if ((sr_req->query_type == Z_SRW_query_type_xcql && !sr_req->query.xcql))
{
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
YAZ_SRW_QUERY_SYNTAX_ERROR,
"XCQL query is empty");
return false;
if ((sr_req->query_type == Z_SRW_query_type_pqf && !sr_req->query.pqf))
{
yaz_add_srw_diagnostic(odr_en,
- &(sru_pdu_res->u.response->diagnostics),
- &(sru_pdu_res->u.response->num_diagnostics),
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
YAZ_SRW_QUERY_SYNTAX_ERROR,
"PQF query is empty");
return false;
}
-Z_ElementSetNames *
+Z_ElementSetNames *
mp_util::build_esn_from_schema(mp::odr &odr_en, const char *schema)
{
if (!schema)
return 0;
-
- Z_ElementSetNames *esn
+
+ Z_ElementSetNames *esn
= (Z_ElementSetNames *) odr_malloc(odr_en, sizeof(Z_ElementSetNames));
esn->which = Z_ElementSetNames_generic;
esn->u.generic = odr_strdup(odr_en, schema);
- return esn;
+ return esn;
}
-std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu)
+std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu)
{
os << "SRU";
-
+
switch (srw_pdu.which)
{
case Z_SRW_searchRetrieve_request:
os << " " << (sr->recordSchema);
else
os << " -";
-
+
switch (sr->query_type){
case Z_SRW_query_type_cql:
os << " CQL";
os << " " << *(sr->nextRecordPosition);
else
os << " -";
- }
+ }
else
{
os << " DIAG";
else
os << " -";
}
-
-
+
+
}
}
break;
case Z_SRW_update_response:
os << " " << "updateResponse";
break;
- default:
- os << " " << "UNKNOWN";
+ default:
+ os << " " << "UNKNOWN";
}
- return os;
+ return os;
}
/*
#include <iosfwd>
#include <string>
-namespace std
+namespace std
{
- std::ostream& operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu);
+ std::ostream& operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu);
}
// std::string sru_protocol(const Z_HTTP_Request &http_req);
// std::string debug_http(const Z_HTTP_Request &http_req);
- // void http_response(mp::Package &package,
- // const std::string &content,
+ // void http_response(mp::Package &package,
+ // const std::string &content,
// int http_code = 200);
bool build_sru_debug_package(metaproxy_1::Package &package);
SRUServerInfo get_sru_server_info(metaproxy_1::Package &package);
- // Z_SRW_explainRequest
+ // Z_SRW_explainRequest
//const *er_req);
-
-// bool build_simple_explain(metaproxy_1::Package &package,
+
+// bool build_simple_explain(metaproxy_1::Package &package,
// metaproxy_1::odr &odr_en,
// Z_SRW_PDU *sru_pdu_res,
// SRUServerInfo sruinfo,
// Z_SRW_explainRequest const *er_req = 0);
-
- bool build_sru_explain(metaproxy_1::Package &package,
+
+ bool build_sru_explain(metaproxy_1::Package &package,
metaproxy_1::odr &odr_en,
Z_SRW_PDU *sru_pdu_res,
SRUServerInfo sruinfo,
const xmlNode *explain = 0,
Z_SRW_explainRequest const *er_req = 0);
-
- bool build_sru_response(metaproxy_1::Package &package,
+
+ bool build_sru_response(metaproxy_1::Package &package,
metaproxy_1::odr &odr_en,
Z_SOAP *soap,
const Z_SRW_PDU *sru_pdu_res,
char *charset,
- const char *stylesheet);
-
- Z_SRW_PDU * decode_sru_request(metaproxy_1::Package &package,
+ const char *stylesheet);
+
+ Z_SRW_PDU * decode_sru_request(metaproxy_1::Package &package,
metaproxy_1::odr &odr_de,
metaproxy_1::odr &odr_en,
Z_SRW_PDU *sru_pdu_res,
Z_SRW_PDU *sru_pdu_res,
Z_SRW_searchRetrieveRequest
const *sr_req);
-
- Z_ElementSetNames * build_esn_from_schema(metaproxy_1::odr &odr_en,
+
+ Z_ElementSetNames * build_esn_from_schema(metaproxy_1::odr &odr_en,
const char *schema);
class SRUServerInfo
std::string host;
std::string port;
};
-
-
-
-// class SRU
+
+
+
+// class SRU
// {
// public:
// enum SRU_protocol_type { SRU_NONE, SRU_GET, SRU_POST, SRU_SOAP};
// private:
// SRU_protocol_type m_protocol;
// std::string m_charset;
-// std::string m_stylesheet;
+// std::string m_stylesheet;
// };
- }
+ }
}
#endif
{
public:
counter() : count(0) { }
-
+
int increment() {
boost::mutex::scoped_lock scoped_lock(mutex);
return ++count;
}
-
+
private:
boost::mutex mutex;
int count;
BOOST_AUTO_TEST_CASE( thread_group )
{
- try
+ try
{
const int num_threads = 4;
boost::thread_group thrds;
-
+
for (int i=0; i < num_threads; ++i)
{
worker w;
}
thrds.join_all();
}
- catch (...)
+ catch (...)
{
BOOST_CHECK(false);
}
BOOST_AUTO_TEST_CASE( thread_list )
{
- try
+ try
{
const int num_threads = 4;
std::list<boost::thread *> thread_list;
-
+
for (int i=0; i < num_threads; ++i)
{
worker w;
}
}
- catch (...)
+ catch (...)
{
BOOST_CHECK(false);
}
void configure(const xmlNode * ptr, bool test_only,
const char *path) { };
};
-
+
BOOST_AUTO_TEST_CASE( test_filter1 )
{
try{
TFilter filter;
-
+
BOOST_CHECK (sizeof(filter) > 0);
}
catch ( ... ) {
BOOST_CHECK_EQUAL (ptr->type, XML_ELEMENT_NODE);
BOOST_CHECK_EQUAL(std::string((const char *) ptr->name), "filter");
-
+
const struct _xmlAttr *attr;
-
+
for (attr = ptr->properties; attr; attr = attr->next)
{
BOOST_CHECK_EQUAL( std::string((const char *)attr->name), "type");
{
if (p->type != XML_ELEMENT_NODE)
continue;
-
+
BOOST_CHECK_EQUAL (p->type, XML_ELEMENT_NODE);
BOOST_CHECK_EQUAL(std::string((const char *) p->name), "value");
-
+
const xmlNode *val = p->children;
BOOST_CHECK(val);
if (!val)
continue;
-
+
BOOST_CHECK_EQUAL(val->type, XML_TEXT_NODE);
BOOST_CHECK_EQUAL(std::string((const char *)val->content), "2");
}
// This filter dose not have a configure function
-
+
class FilterDouble: public mp::filter::Base {
public:
void process(mp::Package & package) const {
};
-BOOST_AUTO_TEST_CASE( testfilter2_1 )
+BOOST_AUTO_TEST_CASE( testfilter2_1 )
{
try {
FilterConstant fc;
{
mp::RouterChain router1;
-
+
// test filter set/get/exception
router1.append(fc);
-
+
router1.append(fd);
mp::Session session;
mp::Origin origin;
mp::Package pack(session, origin);
-
- pack.router(router1).move();
-
+
+ pack.router(router1).move();
+
//BOOST_CHECK_EQUAL(pack.data(), 2468);
-
+
}
-
+
{
mp::RouterChain router2;
-
+
router2.append(fd);
router2.append(fc);
-
+
mp::Session session;
mp::Origin origin;
mp::Package pack(session, origin);
-
+
pack.router(router2).move();
-
+
//BOOST_CHECK_EQUAL(pack.data(), 1234);
-
+
}
}
}
-BOOST_AUTO_TEST_CASE( testfilter2_2 )
+BOOST_AUTO_TEST_CASE( testfilter2_2 )
{
try {
FilterConstant fc;
"<filter type=\"constant\">\n"
" <value>2</value>\n"
"</filter>";
-
+
// std::cout << some_xml << std::endl;
xmlDocPtr doc = xmlParseMemory(some_xml.c_str(), some_xml.size());
if (doc)
{
xmlNodePtr root_element = xmlDocGetRootElement(doc);
-
+
base->configure(root_element, true, 0);
-
+
xmlFreeDoc(doc);
}
class FilterBounceInit: public mp::filter::Base {
public:
void process(mp::Package & package) const {
-
+
if (package.session().is_closed())
{
// std::cout << "Got Close.\n";
}
-
+
Z_GDU *gdu = package.request().get();
if (gdu && gdu->which == Z_GDU_Z3950)
{
BOOST_AUTO_TEST_CASE( test_filter_auth_simple_1 )
{
- try
+ try
{
mp::filter::AuthSimple lf;
}
BOOST_AUTO_TEST_CASE( test_filter_auth_simple2 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::AuthSimple auth;
FilterBounceInit bounce;
-
+
router.append(auth);
router.append(bounce);
-
+
// Create package with Z39.50 init request in it
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
pack.request() = apdu;
- // Done creating query.
-
+ // Done creating query.
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 init response
yazpp_1::GDU *gdu = &pack.response();
-
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (z_gdu) {
BOOST_AUTO_TEST_CASE( test_filter_backend_test_1 )
{
- try
+ try
{
mp::filter::BackendTest btest;
}
BOOST_AUTO_TEST_CASE( test_filter_backend_test_2 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::BackendTest btest;
router.append(btest);
-
+
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
BOOST_CHECK(apdu);
-
+
pack.request() = apdu;
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 init Response OK.
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(!pack.session().is_closed());
-
+
+ BOOST_CHECK(!pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (z_gdu) {
BOOST_AUTO_TEST_CASE( test_filter_backend_test_3 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::BackendTest btest;
router.append(btest);
-
+
mp::Package pack;
-
+
// send search request as first request.. That should fail with
// a close from the backend
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
mp::util::pqf(odr, apdu, "computer");
-
+
apdu->u.searchRequest->num_databaseNames = 1;
apdu->u.searchRequest->databaseNames = (char**)
odr_malloc(odr, sizeof(char *));
apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, "Default");
-
+
BOOST_CHECK(apdu);
-
+
pack.request() = apdu;
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 close
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(pack.session().is_closed());
-
+
+ BOOST_CHECK(pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (z_gdu) {
BOOST_AUTO_TEST_CASE( test_filter_backend_test_4 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::BackendTest btest;
router.append(btest);
-
+
mp::Package pack;
-
+
// send present request as first request.. That should fail with
// a close from the backend
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
BOOST_CHECK(apdu);
-
+
pack.request() = apdu;
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 close
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(pack.session().is_closed());
-
+
+ BOOST_CHECK(pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (z_gdu) {
// Create package with Z39.50 init request in it
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, request);
pack.request() = apdu;
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect bounced back request
yazpp_1::GDU *gdu_req = &pack.request();
yazpp_1::GDU *gdu_res = &pack.response();
-
+
Z_GDU *z_gdu_req = gdu_req->get();
Z_GDU *z_gdu_res = gdu_res->get();
// Create package with Z39.50 init request in it
mp::Package pack;
-
+
mp::odr odr;
Z_GDU *gdu = z_get_HTTP_Request(odr);
//z_get_HTTP_Request_host_path(odr, host, path);
pack.request() = gdu;
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect bounced back request
yazpp_1::GDU *gdu_req = &pack.request();
yazpp_1::GDU *gdu_res = &pack.response();
-
+
Z_GDU *z_gdu_req = gdu_req->get();
Z_GDU *z_gdu_res = gdu_res->get();
BOOST_AUTO_TEST_CASE( test_filter_bounce_1 )
{
- try
+ try
{
mp::filter::Bounce f_bounce;
}
BOOST_AUTO_TEST_CASE( test_filter_bounce_2 )
{
- try
+ try
{
- mp::RouterChain router;
+ mp::RouterChain router;
mp::filter::Bounce f_bounce;
router.append(f_bounce);
- check_bounce_z3950(router,
+ check_bounce_z3950(router,
Z_APDU_initRequest, Z_APDU_close);
- //check_bounce_z3950(router,
+ //check_bounce_z3950(router,
// Z_APDU_searchRequest, Z_APDU_close);
- check_bounce_z3950(router,
+ check_bounce_z3950(router,
Z_APDU_presentRequest, Z_APDU_close);
- check_bounce_z3950(router,
+ check_bounce_z3950(router,
Z_APDU_deleteResultSetRequest, Z_APDU_close);
- //check_bounce_z3950(router,
+ //check_bounce_z3950(router,
// Z_APDU_accessControlRequest, Z_APDU_close);
- check_bounce_z3950(router,
+ check_bounce_z3950(router,
Z_APDU_resourceControlRequest, Z_APDU_close);
- check_bounce_z3950(router,
+ check_bounce_z3950(router,
Z_APDU_triggerResourceControlRequest, Z_APDU_close);
- check_bounce_z3950(router,
+ check_bounce_z3950(router,
Z_APDU_resourceReportRequest, Z_APDU_close);
- //check_bounce_z3950(router,
+ //check_bounce_z3950(router,
// Z_APDU_scanRequest, Z_APDU_close);
- //check_bounce_z3950(router,
+ //check_bounce_z3950(router,
// Z_APDU_sortRequest, Z_APDU_close);
- check_bounce_z3950(router,
+ check_bounce_z3950(router,
Z_APDU_segmentRequest, Z_APDU_close);
- //check_bounce_z3950(router,
+ //check_bounce_z3950(router,
// Z_APDU_extendedServicesRequest, Z_APDU_close);
- check_bounce_z3950(router,
+ check_bounce_z3950(router,
Z_APDU_close , Z_APDU_close);
- //check_bounce_z3950(router,
+ //check_bounce_z3950(router,
// Z_APDU_duplicateDetectionRequest, Z_APDU_close);
BOOST_AUTO_TEST_CASE( test_filter_bounce_3 )
{
- try
+ try
{
- mp::RouterChain router;
+ mp::RouterChain router;
mp::filter::Bounce f_bounce;
router.append(f_bounce);
BOOST_AUTO_TEST_CASE( test_filter_factory_1 )
{
try {
-
+
mp::FactoryFilter ffactory;
-
+
XFilter xf;
YFilter yf;
const std::string xfid = "XFilter";
const std::string yfid = "YFilter";
-
+
BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
BOOST_CHECK(ffactory.drop_creator(xfid));
BOOST_CHECK(ffactory.add_creator(xfid, xfilter_creator));
BOOST_CHECK(ffactory.add_creator(yfid, yfilter_creator));
-
+
mp::filter::Base* xfilter = 0;
xfilter = ffactory.create(xfid);
mp::filter::Base* yfilter = 0;
#if HAVE_DLFCN_H
BOOST_AUTO_TEST_CASE( test_filter_factory_2 )
{
- try {
+ try {
mp::FactoryFilter ffactory;
-
+
const std::string id = "dl";
-
+
// first load
BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
// test double load
BOOST_CHECK(ffactory.add_creator_dl(id, ".libs"));
-
+
mp::filter::Base* filter = 0;
filter = ffactory.create(id);
class FilterInit: public mp::filter::Base {
public:
void process(mp::Package & package) const {
-
+
if (package.session().is_closed())
{
// std::cout << "Got Close.\n";
}
-
+
Z_GDU *gdu = package.request().get();
if (gdu && gdu->which == Z_GDU_Z3950)
{
BOOST_AUTO_TEST_CASE( test_filter_frontend_net_1 )
{
- try
+ try
{
{
mp::filter::FrontendNet nf;
BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 )
{
- try
+ try
{
{
mp::RouterChain router;
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
pack.request() = apdu;
- // Done creating query.
+ // Done creating query.
// Put it in router
- pack.router(router).move();
+ pack.router(router).move();
// Inspect that we got Z39.50 init response
yazpp_1::GDU *gdu = &pack.response();
BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 )
{
- try
+ try
{
{
mp::RouterChain router;
router.append(filter_init);
mp::Package pack;
-
- pack.router(router).move();
+
+ pack.router(router).move();
}
BOOST_CHECK(true);
}
class FilterBounceInit: public mp::filter::Base {
public:
void process(mp::Package & package) const {
-
+
if (package.session().is_closed())
{
// std::cout << "Got Close.\n";
}
-
+
Z_GDU *gdu = package.request().get();
if (gdu && gdu->which == Z_GDU_Z3950)
{
BOOST_AUTO_TEST_CASE( test_filter_log_1 )
{
- try
+ try
{
mp::filter::Log lf;
}
BOOST_AUTO_TEST_CASE( test_filter_log_2 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::Log lf;
FilterBounceInit bf;
-
+
router.append(lf);
router.append(bf);
-
+
// Create package with Z39.50 init request in it
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
pack.request() = apdu;
- // Done creating query.
-
+ // Done creating query.
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 init response
yazpp_1::GDU *gdu = &pack.response();
-
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (z_gdu) {
class FilterBounceInit: public mp::filter::Base {
public:
void process(mp::Package & package) const {
-
+
if (package.session().is_closed())
{
// std::cout << "Got Close.\n";
}
-
+
Z_GDU *gdu = package.request().get();
if (gdu && gdu->which == Z_GDU_Z3950)
{
BOOST_AUTO_TEST_CASE( test_filter_multi_1 )
{
- try
+ try
{
mp::filter::Multi lf;
}
BOOST_AUTO_TEST_CASE( test_filter_multi_2 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::Multi multi;
FilterBounceInit bounce;
-
+
router.append(multi);
router.append(bounce);
-
+
// Create package with Z39.50 init request in it
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
pack.request() = apdu;
- // Done creating query.
-
+ // Done creating query.
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 init response
yazpp_1::GDU *gdu = &pack.response();
-
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (z_gdu) {
class FilterBounceZ3950: public mp::filter::Base {
public:
void process(mp::Package & package) const {
-
+
if (package.session().is_closed())
{
std::cout << "Got Close.\n";
return;
}
-
+
Z_GDU *gdu = package.request().get();
-
- if (gdu && gdu->which == Z_GDU_Z3950
+
+ if (gdu && gdu->which == Z_GDU_Z3950
&& gdu->u.z3950->which == Z_APDU_initRequest)
{
- std::cout << "Got Z3950 Init PDU\n";
+ std::cout << "Got Z3950 Init PDU\n";
//Z_InitRequest *req = gdu->u.z3950->u.initRequest;
//package.request() = gdu;
return;
- }
- else if (gdu && gdu->which == Z_GDU_Z3950
+ }
+ else if (gdu && gdu->which == Z_GDU_Z3950
&& gdu->u.z3950->which == Z_APDU_searchRequest)
{
- std::cout << "Got Z3950 Search PDU\n";
+ std::cout << "Got Z3950 Search PDU\n";
//Z_SearchRequest *req = gdu->u.z3950->u.searchRequest;
//package.request() = gdu;
return;
- }
- else if (gdu && gdu->which == Z_GDU_Z3950
+ }
+ else if (gdu && gdu->which == Z_GDU_Z3950
&& gdu->u.z3950->which == Z_APDU_scanRequest)
{
- std::cout << "Got Z3950 Scan PDU\n";
+ std::cout << "Got Z3950 Scan PDU\n";
//Z_ScanRequest *req = gdu->u.z3950->u.scanRequest;
//package.request() = gdu;
return;
- }
-
+ }
+
package.move();
};
};
// Create package with Z39.50 init request in it
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
pack.request() = apdu;
// Done creating query.
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect bounced back request
//yazpp_1::GDU *gdu = &pack.response();
yazpp_1::GDU *gdu = &pack.request();
-
+
Z_GDU *z_gdu = gdu->get();
//std::cout << "Z_GDU " << z_gdu << "\n";
}
}
-void check_query_rewrite_search(mp::RouterChain &router,
+void check_query_rewrite_search(mp::RouterChain &router,
std::string query_in,
std::string query_expect)
{
- //std::cout << "QUERY REWRITE SEARCH "
+ //std::cout << "QUERY REWRITE SEARCH "
// << query_in << " " << query_expect << "\n";
-
+
// Create package with Z39.50 search request in it
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
- // create package PQF query here
+ // create package PQF query here
mp::util::pqf(odr, apdu, query_in);
// create package PDF database info (needed!)
apdu->u.searchRequest->num_databaseNames = 1;
- apdu->u.searchRequest->databaseNames
+ apdu->u.searchRequest->databaseNames
= (char**)odr_malloc(odr, sizeof(char *));
apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, "Default");
- // Done creating request package
+ // Done creating request package
pack.request() = apdu;
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect bounced back request
//yazpp_1::GDU *gdu = &pack.response();
yazpp_1::GDU *gdu = &pack.request();
-
+
Z_GDU *z_gdu = gdu->get();
//std::cout << "Z_GDU " << z_gdu << "\n";
-
+
BOOST_CHECK(z_gdu);
if (z_gdu) {
BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_searchRequest);
// take query out of package again and check rewrite
- std::string query_changed
+ std::string query_changed
= zQueryToString(z_gdu->u.z3950->u.searchRequest->query);
BOOST_CHECK_EQUAL(query_expect, query_changed);
}
BOOST_AUTO_TEST_CASE( test_filter_query_rewrite_1 )
{
- try
+ try
{
mp::filter::QueryRewrite f_query_rewrite;
}
BOOST_AUTO_TEST_CASE( test_filter_query_rewrite2 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::QueryRewrite f_query_rewrite;
//FilterBounceZ3950 f_bounce_z3950;
-
+
router.append(f_query_rewrite);
//router.append(f_bounce_z3950);
check_query_rewrite_init(router);
- check_query_rewrite_search(router,
- "@attrset Bib-1 @attr 1=4 the",
+ check_query_rewrite_search(router,
+ "@attrset Bib-1 @attr 1=4 the",
"@attrset Bib-1 @attr 1=4 the");
}
BOOST_AUTO_TEST_CASE( test_filter_query_rewrite3 )
{
-
- try
+
+ try
{
mp::RouterChain router;
-
- std::string xmlconf =
+
+ std::string xmlconf =
"<?xml version='1.0'?>\n"
"<filter xmlns='http://indexdata.com/metaproxy'\n"
" id='qrw1' type='query_rewrite'>\n"
"</filter>\n"
;
-
+
//std::cout << xmlconf << std::endl;
// reading and parsing XML conf
// creating and configuring filter
mp::filter::QueryRewrite f_query_rewrite;
f_query_rewrite.configure(root_element, true, 0);
-
+
// remeber to free XML DOM
xmlFreeDoc(doc);
-
+
// add only filter to router
router.append(f_query_rewrite);
// start testing
check_query_rewrite_init(router);
- check_query_rewrite_search(router,
- "@attrset Bib-1 @attr 1=4 the",
+ check_query_rewrite_search(router,
+ "@attrset Bib-1 @attr 1=4 the",
"@attrset Bib-1 @attr 1=4 the");
}
BOOST_AUTO_TEST_CASE( test_filter_record_transform_1 )
{
- try
+ try
{
mp::filter::RecordTransform f_rec_trans;
}
BOOST_AUTO_TEST_CASE( test_filter_record_transform_2 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::RecordTransform f_rec_trans;
-
+
router.append(f_rec_trans);
//check_sru_to_z3950_init(router);
- //check_sru_to_z3950_search(router,
- // "@attrset Bib-1 @attr 1=4 the",
+ //check_sru_to_z3950_search(router,
+ // "@attrset Bib-1 @attr 1=4 the",
// "@attrset Bib-1 @attr 1=4 the");
}
BOOST_AUTO_TEST_CASE( test_filter_record_transform_3 )
{
-
- try
+
+ try
{
mp::RouterChain router;
-
- std::string xmlconf =
+
+ std::string xmlconf =
"<?xml version='1.0'?>\n"
"<filter xmlns='http://indexdata.com/metaproxy'\n"
" id='rec_trans_1' type='record_transform'>\n"
"<retrievalinfo>"
- "<retrieval"
+ "<retrieval"
" syntax=\"usmarc\""
" name=\"marcxml\">"
"<backend syntax=\"usmarc\""
"</retrievalinfo>"
"</filter>\n"
;
-
+
//std::cout << xmlconf << std::endl;
// reading and parsing XML conf
// creating and configuring filter
mp::filter::RecordTransform f_rec_trans;
f_rec_trans.configure(root_element, true, 0);
-
+
// remeber to free XML DOM
xmlFreeDoc(doc);
-
+
// add only filter to router
router.append(f_rec_trans);
// start testing
//check_sru_to_z3950_init(router);
- //check_sru_to_z3950_search(router,
- // "@attrset Bib-1 @attr 1=4 the",
+ //check_sru_to_z3950_search(router,
+ // "@attrset Bib-1 @attr 1=4 the",
// "@attrset Bib-1 @attr 1=4 the");
}
BOOST_AUTO_TEST_CASE( test_filter_sru_to_z3950_1 )
{
- try
+ try
{
mp::filter::SRUtoZ3950 f_sru_to_z3950;
}
BOOST_AUTO_TEST_CASE( test_filter_sru_to_z3950_2 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::SRUtoZ3950 f_sru_to_z3950;
-
+
router.append(f_sru_to_z3950);
//check_sru_to_z3950_init(router);
- //check_sru_to_z3950_search(router,
- // "@attrset Bib-1 @attr 1=4 the",
+ //check_sru_to_z3950_search(router,
+ // "@attrset Bib-1 @attr 1=4 the",
// "@attrset Bib-1 @attr 1=4 the");
}
// BOOST_AUTO_TEST_CASE( test_filter_sru_to_z3950_3 )
// {
-
-// try
+
+// try
// {
// mp::RouterChain router;
-
-// std::string xmlconf =
+
+// std::string xmlconf =
// "<?xml version='1.0'?>\n"
// "<filter xmlns='http://indexdata.com/metaproxy'\n"
// " id='qrw1' type='sru_to_z3950'>\n"
// "</filter>\n"
// ;
-
+
// //std::cout << xmlconf << std::endl;
// // reading and parsing XML conf
// // creating and configuring filter
// mp::filter::SRUtoZ3950 f_sru_to_z3950;
// f_sru_to_z3950.configure(root_element);
-
+
// // remeber to free XML DOM
// xmlFreeDoc(doc);
-
+
// // add only filter to router
// router.append(f_sru_to_z3950);
// // start testing
// check_sru_to_z3950_init(router);
-// check_sru_to_z3950_search(router,
-// "@attrset Bib-1 @attr 1=4 the",
+// check_sru_to_z3950_search(router,
+// "@attrset Bib-1 @attr 1=4 the",
// "@attrset Bib-1 @attr 1=4 the");
// }
BOOST_AUTO_TEST_CASE( test_filter_virt_db_1 )
{
- try
+ try
{
mp::filter::VirtualDB vdb;
}
BOOST_AUTO_TEST_CASE( test_filter_virt_db_2 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::VirtualDB vdb;
-
+
router.append(vdb);
-
+
// Create package with Z39.50 init request in it
// Since there is not vhost given, the virt will make its
// own init response (regardless of backend)
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
BOOST_CHECK(apdu);
-
+
pack.request() = apdu;
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 init Response OK.
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(!pack.session().is_closed());
-
+
+ BOOST_CHECK(!pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (z_gdu) {
// Create package with Z39.50 init request in it
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
BOOST_CHECK(apdu);
if (!apdu)
return;
-
+
pack.request() = apdu;
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 init response
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(!pack.session().is_closed());
-
+
+ BOOST_CHECK(!pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (!z_gdu)
BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
}
-
+
static void search(mp::Package &pack, mp::Router &router,
const std::string &query, const char *db,
const char *setname)
{
// Create package with Z39.50 search request in it
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
mp::util::pqf(odr, apdu, query);
apdu->u.searchRequest->resultSetName = odr_strdup(odr, setname);
-
+
apdu->u.searchRequest->num_databaseNames = 1;
apdu->u.searchRequest->databaseNames = (char**)
odr_malloc(odr, sizeof(char *));
apdu->u.searchRequest->databaseNames[0] = odr_strdup(odr, db);
-
+
BOOST_CHECK(apdu);
if (!apdu)
return;
-
+
pack.request() = apdu;
-
+
Z_GDU *gdu_test = pack.request().get();
BOOST_CHECK(gdu_test);
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 search response
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(!pack.session().is_closed());
-
+
+ BOOST_CHECK(!pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (!z_gdu)
const char *setname)
{
// Create package with Z39.50 present request in it
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
-
+
apdu->u.presentRequest->resultSetId = odr_strdup(odr, setname);
*apdu->u.presentRequest->resultSetStartPoint = start;
*apdu->u.presentRequest->numberOfRecordsRequested = number;
BOOST_CHECK(apdu);
if (!apdu)
return;
-
+
pack.request() = apdu;
-
+
Z_GDU *gdu_test = pack.request().get();
BOOST_CHECK(gdu_test);
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 present response
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(!pack.session().is_closed());
-
+
+ BOOST_CHECK(!pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (!z_gdu)
BOOST_AUTO_TEST_CASE( test_filter_virt_db_3 )
{
- try
+ try
{
mp::RouterChain router;
#if 0
router.append(filter_log1);
#endif
-
- mp::filter::VirtualDB vdb;
+
+ mp::filter::VirtualDB vdb;
router.append(vdb);
vdb.add_map_db2target("Default", "localhost:210", "");
mp::filter::Log filter_log2("BACK");
mp::Session session1;
mp::Origin origin1;
-
+
{
mp::Package pack(session1, origin1);
init(pack, router);
BOOST_AUTO_TEST_CASE( test_filter_z3950_client_1 )
{
- try
+ try
{
mp::filter::Z3950Client zc; // can we construct OK?
}
BOOST_AUTO_TEST_CASE( test_filter_z3950_client_2 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::Z3950Client zc;
-
+
router.append(zc);
-
+
// Create package with Z39.50 init request in it
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
BOOST_CHECK(apdu);
-
+
pack.request() = apdu;
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 init Response - a Z39.50 session MUST
// specify a virtual host
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(pack.session().is_closed());
-
+
+ BOOST_CHECK(pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (z_gdu) {
BOOST_AUTO_TEST_CASE( test_filter_z3950_client_3 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::Z3950Client zc;
router.append(zc);
-
+
// Create package with Z39.50 present request in it
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
-
+
BOOST_CHECK(apdu);
-
+
pack.request() = apdu;
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
// Inspect that we got Z39.50 close - a Z39.50 session must start
// with an init !
yazpp_1::GDU *gdu = &pack.response();
-
- BOOST_CHECK(pack.session().is_closed());
-
+
+ BOOST_CHECK(pack.session().is_closed());
+
Z_GDU *z_gdu = gdu->get();
BOOST_CHECK(z_gdu);
if (z_gdu) {
BOOST_AUTO_TEST_CASE( test_filter_z3950_client_4 )
{
- try
+ try
{
mp::RouterChain router;
-
+
mp::filter::Z3950Client zc;
-
+
router.append(zc);
-
+
// Create package with Z39.50 init request in it
mp::Package pack;
-
+
mp::odr odr;
Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
-
+
const char *vhost = "localhost:9999";
if (vhost)
{
odr, yaz_oid_userinfo_proxy, 1, vhost);
}
BOOST_CHECK(apdu);
-
+
pack.request() = apdu;
-
+
// Put it in router
- pack.router(router).move();
-
+ pack.router(router).move();
+
if (pack.session().is_closed())
{
// OK, server was not up!
Timer::Timer(yazpp_1::ISocketObservable *obs,
- int duration) :
+ int duration) :
m_obs(obs), m_pipe(9122), m_data(false), m_timeout(false)
{
obs->addObserver(m_pipe.read_fd(), this);
BOOST_AUTO_TEST_CASE( test_pipe_1 )
{
yazpp_1::SocketManager mySocketManager;
-
+
Timer t(&mySocketManager, 1);
while (mySocketManager.processEvent() > 0)
" <message>other</message>\n"
" </filter>\n"
" </filters>\n"
- " <routes>\n"
+ " <routes>\n"
" <route id=\"start\">\n"
" <filter refid=\"front_default\"/>\n"
" <filter refid=\"log_cout1\"/>\n"
" <filters>\n"
" <filter id=\"front_default\" type=\"frontend_net\">\n"
" <port>@:210</port>\n";
-
+
mp::FactoryFilter factory;
mp::RouterFleXML rflexml(xmlconf_invalid, factory, true);
}
" <message>my msg</message>\n"
" </mp:filter>\n"
" </mp:filters>\n"
- " <mp:routes>\n"
+ " <mp:routes>\n"
" <mp:route id=\"start\">\n"
" <mp:filter refid=\"front_default\"/>\n"
" <mp:filter refid=\"log_cout\"/>\n"
" </mp:route>\n"
" </mp:routes>\n"
"</mp:metaproxy>\n";
-
+
mp::FactoryStatic factory;
mp::RouterFleXML rflexml(xmlconf, factory, true);
}
std::string xmlconf = "<?xml version=\"1.0\"?>\n"
"<metaproxy xmlns=\"http://indexdata.com/metaproxy\""
" version=\"1.0\">\n"
- " <start route=\"start\"/>\n"
+ " <start route=\"start\"/>\n"
" <filters>\n"
" <filter id=\"front_default\" type=\"notknown\">\n"
" <port>@:210</port>\n"
" </filter>\n"
" </filters>\n"
- " <routes>\n"
+ " <routes>\n"
" <route id=\"start\">\n"
" <filter refid=\"front_default\"/>\n"
" </route>\n"
namespace metaproxy_1 {
class SesMap;
-
+
class SesMap {
class Wrap {
public:
void create(SesMap &sm, const mp::Session &s, double &t) {
boost::mutex::scoped_lock lock(m_map_mutex);
-
+
boost::shared_ptr<Wrap> w_ptr(new Wrap(t));
m_map_ptr[s] = w_ptr;
}
BOOST_AUTO_TEST_CASE( test_ses_map_1 )
{
- try
+ try
{
mp::SesMap ses_map;
}
using namespace boost::unit_test;
namespace mp = metaproxy_1;
-BOOST_AUTO_TEST_CASE( testsession1 )
+BOOST_AUTO_TEST_CASE( testsession1 )
{
- // test session
+ // test session
try {
mp::Session session1;
mp::Session session2;
boost::mutex io_mutex;
-class Worker
+class Worker
{
public:
- Worker(int nr = 0)
+ Worker(int nr = 0)
: m_nr(nr), m_id(0) {};
-
+
void operator() (void) {
for (int i=0; i < 100; ++i)
{
mp::Session session;
- m_id = session.id();
+ m_id = session.id();
//print();
}
}
void print()
{
boost::mutex::scoped_lock scoped_lock(io_mutex);
- std::cout << "Worker " << m_nr
+ std::cout << "Worker " << m_nr
<< " session.id() " << m_id << std::endl;
}
-
- private:
+
+ private:
int m_nr;
int m_id;
};
-BOOST_AUTO_TEST_CASE( testsession2 )
+BOOST_AUTO_TEST_CASE( testsession2 )
{
- // test session
+ // test session
try {
const int num_threads = 100;
boost::thread_group thrds;
-
+
for (int i=0; i < num_threads; ++i)
{
mp::Session session;
BOOST_CHECK (session.id() == 10001);
-
+
}
catch (std::exception &e) {
std::cout << e.what() << "\n";
}
My_Timer_Thread::My_Timer_Thread(ISocketObservable *obs,
- mp::ThreadPoolSocketObserver *t) :
- m_obs(obs), m_pipe(9123)
+ mp::ThreadPoolSocketObserver *t) :
+ m_obs(obs), m_pipe(9123)
{
m_t = t;
m_sum = 0;
#endif
}
-BOOST_AUTO_TEST_CASE( thread_pool_observer1 )
+BOOST_AUTO_TEST_CASE( thread_pool_observer1 )
{
SocketManager mySocketManager;
BOOST_AUTO_TEST_CASE( url_recipe )
{
- try
+ try
{
- const char *xml_text =
+ const char *xml_text =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<pz:record xmlns:pz=\"http://www.indexdata.com/pazpar2/1.0\""
" xmlns:tmarc=\"http://www.indexdata.com/turbomarc\">\n"
m_p->m_no_threads_waiting--;
if (m_p->m_stop_flag)
break;
-
+
in = m_p->m_input.front();
- m_p->m_input.pop_front();
+ m_p->m_input.pop_front();
m_p->m_cond_input_full.notify_all();
}
IThreadPoolMsg *out = in->handle();
Z_HTTP_Header *http_headers = 0;
mp::odr odr;
-
+
z_HTTP_header_add(odr, &http_headers, "Accept","application/xml");
yaz_url_t url_p = yaz_url_create();
0, /* content buf */
0 /* content_len */
);
- if (http_response && http_response->code == 200 &&
+ if (http_response && http_response->code == 200 &&
http_response->content_buf)
{
package.log("zoom", YLOG_LOG, "Torus: %s OK", url_template.c_str());
doc = xmlParseMemory(http_response->content_buf,
http_response->content_len);
-
+
}
else
{
int c_check = c;
if (c_prev == '\\')
c_check = 0;
-
+
if (c_check == '}')
step = 5;
else if (step == 0)
// Doxygen doesn't like mp::util, so we use this instead
namespace mp_util = metaproxy_1::util;
-const char *
+const char *
mp_util::record_composition_to_esn(Z_RecordComposition *comp)
{
if (comp && comp->which == Z_RecordComp_complex)
{
- if (comp->u.complex->generic
+ if (comp->u.complex->generic
&& comp->u.complex->generic->elementSpec
- && (comp->u.complex->generic->elementSpec->which ==
+ && (comp->u.complex->generic->elementSpec->which ==
Z_ElementSpec_elementSetName))
return comp->u.complex->generic->elementSpec->u.elementSetName;
}
-std::string mp_util::http_header_value(const Z_HTTP_Header* header,
+std::string mp_util::http_header_value(const Z_HTTP_Header* header,
const std::string name)
{
while (header && header->name
&& std::string(header->name) != name)
header = header->next;
-
+
if (header && header->name && std::string(header->name) == name
&& header->value)
return std::string(header->value);
-
+
return std::string();
}
-
+
std::string mp_util::http_headers_debug(const Z_HTTP_Request &http_req)
{
std::string message("<html>\n<body>\n<h1>"
"Metaproxy SRUtoZ3950 filter"
"</h1>\n");
-
+
message += "<h3>HTTP Info</h3><br/>\n";
message += "<p>\n";
message += "<b>Method: </b> " + std::string(http_req.method) + "<br/>\n";
message += "<b>Content-Length:</b>"
+ mp_util::http_header_value(http_req.headers, "Content-Length")
+ "<br/>\n";
- message += "</p>\n";
-
+ message += "</p>\n";
+
message += "<h3>Headers</h3><br/>\n";
- message += "<p>\n";
+ message += "<p>\n";
Z_HTTP_Header* header = http_req.headers;
while (header){
- message += "<b>Header: </b> <i>"
+ message += "<b>Header: </b> <i>"
+ std::string(header->name) + ":</i> "
+ std::string(header->value) + "<br/>\n";
header = header->next;
}
- message += "</p>\n";
+ message += "</p>\n";
message += "</body>\n</html>\n";
return message;
}
-void mp_util::http_response(metaproxy_1::Package &package,
- const std::string &content,
+void mp_util::http_response(metaproxy_1::Package &package,
+ const std::string &content,
int http_code)
{
- Z_GDU *zgdu_req = package.request().get();
- Z_GDU *zgdu_res = 0;
+ Z_GDU *zgdu_req = package.request().get();
+ Z_GDU *zgdu_res = 0;
mp::odr odr;
- zgdu_res
- = odr.create_HTTP_Response(package.session(),
- zgdu_req->u.HTTP_Request,
+ zgdu_res
+ = odr.create_HTTP_Response(package.session(),
+ zgdu_req->u.HTTP_Request,
http_code);
-
+
zgdu_res->u.HTTP_Response->content_len = content.size();
- zgdu_res->u.HTTP_Response->content_buf
+ zgdu_res->u.HTTP_Response->content_buf
= (char*) odr_malloc(odr, zgdu_res->u.HTTP_Response->content_len);
-
- strncpy(zgdu_res->u.HTTP_Response->content_buf,
+
+ strncpy(zgdu_res->u.HTTP_Response->content_buf,
content.c_str(), zgdu_res->u.HTTP_Response->content_len);
-
+
//z_HTTP_header_add(odr, &hres->headers,
// "Content-Type", content_type.c_str());
package.response() = zgdu_res;
return 1;
else if (c < 0)
return -1;
-
+
// compare (remaining bytes)
if (d > 0)
return 1;
number_to_present = result_set_size;
if (element_set_name && smallSetElementSetNames)
*element_set_name = smallSetElementSetNames;
-
+
}
else if (result_set_size > largeSetLowerBound)
{
bool mp_util::pqf(ODR odr, Z_APDU *apdu, const std::string &q)
{
YAZ_PQF_Parser pqf_parser = yaz_pqf_create();
-
+
Z_RPNQuery *rpn = yaz_pqf_parse(pqf_parser, odr, q.c_str());
if (!rpn)
{
Z_Query *query = (Z_Query *) odr_malloc(odr, sizeof(Z_Query));
query->which = Z_Query_type_1;
query->u.type_1 = rpn;
-
+
apdu->u.searchRequest->query = query;
return true;
}
if (query && query->which == Z_Query_type_1)
{
Z_RPNQuery *rpn = query->u.type_1;
-
+
if (rpn)
{
mp::wrbuf w;
-
+
// put query in w
yaz_rpnquery_to_wrbuf(w, rpn);
-
+
// from w to std::string
query_str = std::string(w.buf(), w.len());
}
#if 0
if (query && query->which == Z_Query_type_1){
-
+
// allocate wrbuf (strings in YAZ!)
WRBUF w = wrbuf_alloc();
-
+
// put query in w
yaz_query_to_wrbuf(w, query);
-
+
// from w to std::string
query_str = std::string(wrbuf_buf(w), wrbuf_len(w));
-
+
// destroy wrbuf
wrbuf_free(w, 1);
- }
+ }
#endif
return query_str;
}
Z_InitResponse *initrs, int &error_code, std::string &addinfo)
{
Z_External *uif = initrs->userInformationField;
-
+
if (uif && uif->which == Z_External_userInfo1)
{
Z_OtherInformation *ui = uif->u.userInfo1;
if (unit->which == Z_OtherInfo_externallyDefinedInfo &&
unit->information.externallyDefinedInfo &&
unit->information.externallyDefinedInfo->which ==
- Z_External_diag1)
+ Z_External_diag1)
{
- Z_DiagnosticFormat *diag =
+ Z_DiagnosticFormat *diag =
unit->information.externallyDefinedInfo->u.diag1;
if (diag->num > 0)
mp::util::get_default_diag(ds->u.defaultDiagRec,
error_code, addinfo);
}
- }
+ }
}
}
}
cs_get_host_args(zurl_cstr, &args);
if (args && *args)
- {
+ {
host = std::string(zurl_cstr, args - zurl_cstr);
const char *cp1 = args;
std::list<std::string> dblist;
split_zurl(zurl, host, dblist);
-
+
if (dblist.size() == 0)
return false;
*db_num = dblist.size();
int reason, const char *addinfo)
{
Z_APDU *apdu = create_APDU(Z_APDU_close, in_apdu);
-
+
*apdu->u.close->closeReason = reason;
if (addinfo)
apdu->u.close->diagnosticInformation = odr_strdup(m_odr, addinfo);
apdu->u.initResponse->implementationName =
odr_prepend(m_odr, "Metaproxy",
apdu->u.initResponse->implementationName);
- apdu->u.initResponse->implementationVersion =
+ apdu->u.initResponse->implementationVersion =
odr_prepend(m_odr,
VERSION, apdu->u.initResponse->implementationVersion);
-
+
return apdu;
}
rec->which = Z_Records_NSD;
rec->u.nonSurrogateDiagnostic =
zget_DefaultDiagFormat(m_odr, error, addinfo);
-
+
}
return apdu;
}
{
Z_Records *rec = (Z_Records *) odr_malloc(m_odr, sizeof(Z_Records));
apdu->u.presentResponse->records = rec;
-
+
rec->which = Z_Records_NSD;
rec->u.nonSurrogateDiagnostic =
zget_DefaultDiagFormat(m_odr, error, addinfo);
res->entries->num_nonsurrogateDiagnostics = 1;
res->entries->nonsurrogateDiagnostics = (Z_DiagRec **)
odr_malloc(m_odr, sizeof(Z_DiagRec *));
- res->entries->nonsurrogateDiagnostics[0] =
+ res->entries->nonsurrogateDiagnostics[0] =
zget_DiagRec(m_odr, error, addinfo);
}
else
{
const char *response_version = "1.0";
bool keepalive = false;
- if (!strcmp(hreq->version, "1.0"))
+ if (!strcmp(hreq->version, "1.0"))
{
const char *v = z_HTTP_header_lookup(hreq->headers, "Connection");
if (v && !strcmp(v, "Keep-Alive"))
hres->version = odr_strdup(m_odr, response_version);
if (keepalive)
z_HTTP_header_add(m_odr, &hres->headers, "Connection", "Keep-Alive");
-
+
return gdu;
}
switch (apdu->which)
{
case Z_APDU_initRequest:
- return &apdu->u.initRequest->referenceId;
+ return &apdu->u.initRequest->referenceId;
case Z_APDU_initResponse:
return &apdu->u.initResponse->referenceId;
case Z_APDU_searchRequest:
}
int mp_xml::get_int(const xmlNode *ptr, int default_value)
-{
+{
if (ptr && ptr->type != XML_TEXT_NODE)
ptr = ptr->children;
if (ptr && ptr->type == XML_TEXT_NODE && ptr->content)
return default_value;
}
-bool mp_xml::check_attribute(const _xmlAttr *ptr,
+bool mp_xml::check_attribute(const _xmlAttr *ptr,
const std::string &ns,
const std::string &name)
{
if (!mp::xml::is_attribute(ptr, ns, name))
- {
+ {
std::string got_attr = "'";
if (ptr && ptr->name)
got_attr += std::string((const char *)ptr->name);
got_attr += std::string((const char *)ptr->ns->href);
}
got_attr += "'";
-
- throw mp::XMLError("Expected XML attribute '" + name
+
+ throw mp::XMLError("Expected XML attribute '" + name
+ " " + ns + "'"
+ ", not " + got_attr);
}
return true;
}
-bool mp_xml::is_attribute(const _xmlAttr *ptr,
+bool mp_xml::is_attribute(const _xmlAttr *ptr,
const std::string &ns,
const std::string &name)
{
if (0 != xmlStrcmp(BAD_CAST name.c_str(), ptr->name))
return false;
- if (ns.size()
- && (!ptr->ns || !ptr->ns->href
+ if (ns.size()
+ && (!ptr->ns || !ptr->ns->href
|| 0 != xmlStrcmp(BAD_CAST ns.c_str(), ptr->ns->href)))
return false;
}
-bool mp_xml::is_element(const xmlNode *ptr,
+bool mp_xml::is_element(const xmlNode *ptr,
const std::string &ns,
const std::string &name)
{
- if (ptr && ptr->type == XML_ELEMENT_NODE && ptr->ns && ptr->ns->href
+ if (ptr && ptr->type == XML_ELEMENT_NODE && ptr->ns && ptr->ns->href
&& !xmlStrcmp(BAD_CAST ns.c_str(), ptr->ns->href)
&& !xmlStrcmp(BAD_CAST name.c_str(), ptr->name))
return true;
return false;
}
-bool mp_xml::is_element_mp(const xmlNode *ptr,
+bool mp_xml::is_element_mp(const xmlNode *ptr,
const std::string &name)
{
return mp::xml::is_element(ptr, metaproxy_ns, name);
}
-bool mp_xml::check_element_mp(const xmlNode *ptr,
+bool mp_xml::check_element_mp(const xmlNode *ptr,
const std::string &name)
{
if (!mp::xml::is_element_mp(ptr, name))
}
got_element += ">";
- throw mp::XMLError("Expected XML element <" + name
+ throw mp::XMLError("Expected XML element <" + name
+ " xmlns=\"" + metaproxy_ns + "\">"
+ ", not " + got_element);
}
{
std::string name = std::string((const char *) attr->name);
std::string value;
-
+
if (attr->children && attr->children->type == XML_TEXT_NODE)
value = std::string((const char *)attr->children->content);
-
+
if (name == "route")
route_value = value;
else if (name == "auth")