X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Fyaz-proxy-config.cpp;h=fbcc88d6b3a091c938556e32d10cae1cfe478dd1;hb=265587c6b7c73ef7a502803b54395ef847eb03f2;hp=c4ed43d591c361223b77dc12ee9c070a519d003b;hpb=7e3e46d9a207d1c6d56704b64c2ebee58b170795;p=yazpp-moved-to-github.git diff --git a/src/yaz-proxy-config.cpp b/src/yaz-proxy-config.cpp index c4ed43d..fbcc88d 100644 --- a/src/yaz-proxy-config.cpp +++ b/src/yaz-proxy-config.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy-config.cpp,v 1.14 2003-11-25 21:54:18 adam Exp $ + * $Id: yaz-proxy-config.cpp,v 1.18 2004-01-05 09:31:09 adam Exp $ */ #include @@ -12,7 +12,7 @@ Yaz_ProxyConfig::Yaz_ProxyConfig() { m_copy = 0; -#if HAVE_XML2 +#if HAVE_XSLT m_docPtr = 0; m_proxyPtr = 0; #endif @@ -20,7 +20,7 @@ Yaz_ProxyConfig::Yaz_ProxyConfig() Yaz_ProxyConfig::~Yaz_ProxyConfig() { -#if HAVE_XML2 +#if HAVE_XSLT if (!m_copy && m_docPtr) xmlFreeDoc(m_docPtr); #endif @@ -28,7 +28,7 @@ Yaz_ProxyConfig::~Yaz_ProxyConfig() int Yaz_ProxyConfig::read_xml(const char *fname) { -#if HAVE_XML2 +#if HAVE_XSLT xmlDocPtr ndoc = xmlParseFile(fname); if (!ndoc) @@ -56,7 +56,7 @@ int Yaz_ProxyConfig::read_xml(const char *fname) #endif } -#if HAVE_XML2 +#if HAVE_XSLT const char *Yaz_ProxyConfig::get_text(xmlNodePtr ptr) { for(ptr = ptr->children; ptr; ptr = ptr->next) @@ -74,7 +74,7 @@ const char *Yaz_ProxyConfig::get_text(xmlNodePtr ptr) } #endif -#if HAVE_XML2 +#if HAVE_XSLT void Yaz_ProxyConfig::return_limit(xmlNodePtr ptr, int *limit_bw, int *limit_pdu, @@ -107,7 +107,7 @@ void Yaz_ProxyConfig::return_limit(xmlNodePtr ptr, } #endif -#if HAVE_XML2 +#if HAVE_XSLT void Yaz_ProxyConfig::return_target_info(xmlNodePtr ptr, const char **url, int *limit_bw, @@ -117,7 +117,8 @@ void Yaz_ProxyConfig::return_target_info(xmlNodePtr ptr, int *client_idletime, int *keepalive_limit_bw, int *keepalive_limit_pdu, - int *pre_init) + int *pre_init, + const char **cql2rpn) { *pre_init = 0; int no_url = 0; @@ -174,6 +175,13 @@ void Yaz_ProxyConfig::return_target_info(xmlNodePtr ptr, *client_idletime = 0; } } + if (ptr->type == XML_ELEMENT_NODE + && !strcmp((const char *) ptr->name, "cql2rpn")) + { + const char *t = get_text(ptr); + if (t) + *cql2rpn = t; + } } } #endif @@ -212,7 +220,7 @@ int Yaz_ProxyConfig::match_list(int v, const char *m) return 0; } -#if HAVE_XML2 +#if HAVE_XSLT int Yaz_ProxyConfig::check_type_1_attributes(ODR odr, xmlNodePtr ptrl, Z_AttributeList *attrs, char **addinfo) @@ -285,7 +293,7 @@ int Yaz_ProxyConfig::check_type_1_attributes(ODR odr, xmlNodePtr ptrl, } #endif -#if HAVE_XML2 +#if HAVE_XSLT int Yaz_ProxyConfig::check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q, char **addinfo) @@ -311,7 +319,7 @@ int Yaz_ProxyConfig::check_type_1_structure(ODR odr, xmlNodePtr ptr, } #endif -#if HAVE_XML2 +#if HAVE_XSLT int Yaz_ProxyConfig::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query, char **addinfo) { @@ -323,10 +331,10 @@ int Yaz_ProxyConfig::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query, int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query, char **addinfo) { -#if HAVE_XML2 +#if HAVE_XSLT xmlNodePtr ptr; - ptr = find_target_node(name); + ptr = find_target_node(name, 0); if (ptr) { if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101) @@ -336,13 +344,61 @@ int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query, return 0; } +#if HAVE_XSLT +int Yaz_ProxyConfig::check_esn(xmlNodePtr ptr, Z_RecordComposition *comp) +{ + char *esn = 0; + int default_match = 1; + if (comp && comp->which == Z_RecordComp_simple && + comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic) + { + esn = comp->u.simple->u.generic; + } + if (!esn) + return 1; + for (; ptr; ptr = ptr->next) + { + if (ptr->type == XML_TEXT_NODE) + { + default_match = 0; + xmlChar *t = ptr->content; + while (*t) + { + while (*t && isspace(*t)) + t++; + xmlChar *s = t; + int i = 0; + while (esn[i] && esn[i] == *s) + { + i++; + s++; + } + if (!esn[i] && (!*s || isspace(*s))) + return 1; + while (*s && !isspace(*s)) + s++; + t = s; + } + } + } + return default_match; +} +#endif + int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, - Odr_oid *syntax, char **addinfo) + Odr_oid *syntax, Z_RecordComposition *comp, + char **addinfo, + char **stylesheet) { -#if HAVE_XML2 + if (stylesheet) + { + xfree (*stylesheet); + *stylesheet = 0; + } +#if HAVE_XSLT xmlNodePtr ptr; - ptr = find_target_node(name); + ptr = find_target_node(name, 0); if (!ptr) return 0; for(ptr = ptr->children; ptr; ptr = ptr->next) @@ -354,6 +410,7 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, const char *match_type = 0; const char *match_error = 0; const char *match_marcxml = 0; + const char *match_stylesheet = 0; struct _xmlAttr *attr; for (attr = ptr->properties; attr; attr = attr->next) { @@ -366,6 +423,9 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, if (!strcmp((const char *) attr->name, "marcxml") && attr->children && attr->children->type == XML_TEXT_NODE) match_marcxml = (const char *) attr->children->content; + if (!strcmp((const char *) attr->name, "stylesheet") && + attr->children && attr->children->type == XML_TEXT_NODE) + match_stylesheet = (const char *) attr->children->content; } if (match_type) { @@ -385,7 +445,15 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, } } if (match) + match = check_esn(ptr->children, comp); + + if (match) { + if (stylesheet && match_stylesheet) + { + xfree(*stylesheet); + *stylesheet = xstrdup(match_stylesheet); + } if (match_marcxml) { return -1; @@ -408,8 +476,35 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, return 0; } -#if HAVE_XML2 -xmlNodePtr Yaz_ProxyConfig::find_target_node(const char *name) +#if HAVE_XSLT +xmlNodePtr Yaz_ProxyConfig::find_target_db(xmlNodePtr ptr, const char *db) +{ + xmlNodePtr dptr; + if (!db) + return ptr; + if (!ptr) + return 0; + for (dptr = ptr->children; dptr; dptr = dptr->next) + if (dptr->type == XML_ELEMENT_NODE && + !strcmp((const char *) dptr->name, "database")) + { + struct _xmlAttr *attr; + for (attr = dptr->properties; attr; attr = attr->next) + if (!strcmp((const char *) attr->name, "name")) + { + if (attr->children + && attr->children->type==XML_TEXT_NODE + && attr->children->content + && (!strcmp((const char *) attr->children->content, db) + || !strcmp((const char *) attr->children->content, + "*"))) + return dptr; + } + } + return ptr; +} + +xmlNodePtr Yaz_ProxyConfig::find_target_node(const char *name, const char *db) { xmlNodePtr ptr; if (!m_proxyPtr) @@ -430,7 +525,9 @@ xmlNodePtr Yaz_ProxyConfig::find_target_node(const char *name) { xmlChar *t = attr->children->content; if (!t || *t == '1') - return ptr; + { + return find_target_db(ptr, db); + } } } else @@ -448,7 +545,7 @@ xmlNodePtr Yaz_ProxyConfig::find_target_node(const char *name) || !strcmp((const char *) attr->children->content, "*"))) { - return ptr; + return find_target_db(ptr, db); } } } @@ -469,9 +566,10 @@ int Yaz_ProxyConfig::get_target_no(int no, int *max_clients, int *keepalive_limit_bw, int *keepalive_limit_pdu, - int *pre_init) + int *pre_init, + const char **cql2rpn) { -#if HAVE_XML2 +#if HAVE_XSLT xmlNodePtr ptr; if (!m_proxyPtr) return 0; @@ -494,7 +592,7 @@ int Yaz_ProxyConfig::get_target_no(int no, return_target_info(ptr, url, limit_bw, limit_pdu, limit_req, target_idletime, client_idletime, keepalive_limit_bw, keepalive_limit_pdu, - pre_init); + pre_init, cql2rpn); return 1; } i++; @@ -513,7 +611,7 @@ int Yaz_ProxyConfig::mycmp(const char *hay, const char *item, size_t len) void Yaz_ProxyConfig::get_generic_info(int *log_mask, int *max_clients) { -#if HAVE_XML2 +#if HAVE_XSLT xmlNodePtr ptr; if (!m_proxyPtr) return; @@ -562,6 +660,43 @@ void Yaz_ProxyConfig::get_generic_info(int *log_mask, #endif } +char *Yaz_ProxyConfig::get_explain(ODR odr, const char *name, const char *db, + int *len) +{ +#if HAVE_XSLT + xmlNodePtr ptr = find_target_node(name, db); + if (ptr) + { + ptr = ptr->children; + for (; ptr; ptr = ptr->next) + if (ptr->type == XML_ELEMENT_NODE && + !strcmp((const char *) ptr->name, "explain")) + { + xmlNodePtr ptr2 = xmlCopyNode(ptr, 1); + + xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0"); + + xmlDocSetRootElement(doc, ptr2); + + xmlChar *buf_out; + int len_out; + xmlDocDumpMemory(doc, &buf_out, len); + char *content = (char*) odr_malloc(odr, *len); + memcpy(content, buf_out, *len); + + xmlFree(buf_out); + xmlFreeDoc(doc); + return content; + } + } + else + yaz_log(LOG_WARN, "No explain node 1"); + +#endif + yaz_log(LOG_WARN, "No explain node"); + return 0; +} + void Yaz_ProxyConfig::get_target_info(const char *name, const char **url, int *limit_bw, @@ -572,9 +707,10 @@ void Yaz_ProxyConfig::get_target_info(const char *name, int *max_clients, int *keepalive_limit_bw, int *keepalive_limit_pdu, - int *pre_init) + int *pre_init, + const char **cql2rpn) { -#if HAVE_XML2 +#if HAVE_XSLT xmlNodePtr ptr; if (!m_proxyPtr) { @@ -597,7 +733,7 @@ void Yaz_ProxyConfig::get_target_info(const char *name, } } } - ptr = find_target_node(name); + ptr = find_target_node(name, 0); if (ptr) { if (name) @@ -608,7 +744,7 @@ void Yaz_ProxyConfig::get_target_info(const char *name, return_target_info(ptr, url, limit_bw, limit_pdu, limit_req, target_idletime, client_idletime, keepalive_limit_bw, keepalive_limit_pdu, - pre_init); + pre_init, cql2rpn); } #else *url = name;