1 /* This file is part of YAZ proxy
2 Copyright (C) 1998-2011 Index Data
4 YAZ proxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <yaz/oid_db.h>
25 class Yaz_ProxyConfigP {
26 friend class Yaz_ProxyConfig;
28 Yaz_ProxyModules m_modules;
29 int mycmp(const char *hay, const char *item, size_t len);
30 int match_list(int v, const char *m);
31 int atoi_l(const char **cp);
33 void load_modules(void);
34 int check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
35 const char *schema_identifier);
37 xmlNodePtr m_proxyPtr;
38 void return_target_info(xmlNodePtr ptr, const char **url,
39 int *limit_bw, int *limit_pdu, int *limit_req,
41 int *target_idletime, int *client_idletime,
43 int *keepalive_limit_bw, int *keepalive_limit_pdu,
44 int *pre_init, const char **cql2rpn,
45 const char **negotiation_charset,
46 const char **negotiation_lang,
47 const char **target_charset,
48 const char **default_client_query_charset);
49 void return_limit(xmlNodePtr ptr,
50 int *limit_bw, int *limit_pdu, int *limit_req,
52 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
54 xmlNodePtr find_target_node(const char *name);
55 const char *get_text(xmlNodePtr ptr);
56 void get_period(xmlNodePtr ptr, int *period);
57 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
58 Z_AttributeList *attrs,
60 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
62 int get_explain_ptr(const char *db,
63 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
69 Yaz_ProxyConfigP::Yaz_ProxyConfigP() : m_modules()
77 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
85 Yaz_ProxyConfig::Yaz_ProxyConfig()
87 m_cp = new Yaz_ProxyConfigP();
90 Yaz_ProxyConfig::~Yaz_ProxyConfig()
96 void Yaz_ProxyConfigP::load_modules()
101 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
104 if (ptr->type == XML_ELEMENT_NODE
105 && !strcmp((const char *) ptr->name, "module")
106 && (fname = get_text(ptr)))
108 m_modules.add_module(fname);
114 int Yaz_ProxyConfig::read_xml(const char *fname)
117 xmlDocPtr ndoc = xmlParseFile(fname);
121 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
122 return -1; // no good
124 int noSubstitutions = xmlXIncludeProcess(ndoc);
125 if (noSubstitutions == -1)
126 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
128 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
129 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
130 strcmp((const char *) proxyPtr->name, "proxy"))
132 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
136 m_cp->m_proxyPtr = proxyPtr;
138 // OK: release previous and make it the current one.
140 xmlFreeDoc(m_cp->m_docPtr);
141 m_cp->m_docPtr = ndoc;
143 m_cp->m_modules.unload_modules();
144 m_cp->load_modules();
152 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
154 for(ptr = ptr->children; ptr; ptr = ptr->next)
155 if (ptr->type == XML_TEXT_NODE)
157 xmlChar *t = ptr->content;
162 return (const char *) t;
168 void Yaz_ProxyConfigP::get_period(xmlNodePtr ptr, int *period)
170 struct _xmlAttr *attr;
172 for (attr = ptr->properties; attr; attr = attr->next)
174 if (!strcmp((const char *) attr->name, "period") &&
175 attr->children && attr->children->type == XML_TEXT_NODE)
176 *period = atoi((const char *) attr->children->content);
182 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
188 for (ptr = ptr->children; ptr; ptr = ptr->next)
190 if (ptr->type == XML_ELEMENT_NODE
191 && !strcmp((const char *) ptr->name, "bandwidth"))
193 const char *t = get_text(ptr);
197 if (ptr->type == XML_ELEMENT_NODE
198 && !strcmp((const char *) ptr->name, "retrieve"))
200 const char *t = get_text(ptr);
202 *limit_req = atoi(t);
204 if (ptr->type == XML_ELEMENT_NODE
205 && !strcmp((const char *) ptr->name, "pdu"))
207 const char *t = get_text(ptr);
209 *limit_pdu = atoi(t);
211 if (ptr->type == XML_ELEMENT_NODE
212 && !strcmp((const char *) ptr->name, "search"))
214 const char *t = get_text(ptr);
216 *limit_search = atoi(t);
223 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
229 int *target_idletime,
230 int *client_idletime,
232 int *keepalive_limit_bw,
233 int *keepalive_limit_pdu,
235 const char **cql2rpn,
236 const char **negotiation_charset,
237 const char **negotiation_lang,
238 const char **target_charset,
239 const char **default_client_query_charset)
244 for (; ptr; ptr = ptr->next)
246 if (ptr->type == XML_ELEMENT_NODE
247 && !strcmp((const char *) ptr->name, "preinit"))
249 const char *v = get_text(ptr);
250 *pre_init = v ? atoi(v) : 1;
252 if (ptr->type == XML_ELEMENT_NODE
253 && !strcmp((const char *) ptr->name, "url"))
255 const char *t = get_text(ptr);
256 if (t && no_url < MAX_ZURL_PLEX)
262 if (ptr->type == XML_ELEMENT_NODE
263 && !strcmp((const char *) ptr->name, "keepalive"))
266 *keepalive_limit_bw = 500000;
267 *keepalive_limit_pdu = 1000;
268 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
271 if (ptr->type == XML_ELEMENT_NODE
272 && !strcmp((const char *) ptr->name, "limit"))
273 return_limit(ptr, limit_bw, limit_pdu, limit_req,
275 if (ptr->type == XML_ELEMENT_NODE
276 && !strcmp((const char *) ptr->name, "target-timeout"))
278 const char *t = get_text(ptr);
281 *target_idletime = atoi(t);
282 if (*target_idletime < 0)
283 *target_idletime = 0;
286 if (ptr->type == XML_ELEMENT_NODE
287 && !strcmp((const char *) ptr->name, "client-timeout"))
289 const char *t = get_text(ptr);
292 *client_idletime = atoi(t);
293 if (*client_idletime < 0)
294 *client_idletime = 0;
297 if (ptr->type == XML_ELEMENT_NODE
298 && !strcmp((const char *) ptr->name, "max-sockets"))
300 const char *t = get_text(ptr);
301 if (t && max_sockets)
303 *max_sockets = atoi(t);
306 if (ptr->type == XML_ELEMENT_NODE
307 && !strcmp((const char *) ptr->name, "cql2rpn"))
309 const char *t = get_text(ptr);
313 if (ptr->type == XML_ELEMENT_NODE
314 && !strcmp((const char *) ptr->name, "target-charset"))
316 const char *t = get_text(ptr);
317 if (t && target_charset)
320 if (ptr->type == XML_ELEMENT_NODE
321 && !strcmp((const char *) ptr->name, "default-client-charset"))
323 const char *t = get_text(ptr);
324 if (t && default_client_query_charset)
325 *default_client_query_charset = t;
327 if (ptr->type == XML_ELEMENT_NODE
328 && !strcmp((const char *) ptr->name, "negotiation-charset"))
330 const char *t = get_text(ptr);
332 *negotiation_charset = t;
334 if (ptr->type == XML_ELEMENT_NODE
335 && !strcmp((const char *) ptr->name, "negotiation-lang"))
337 const char *t = get_text(ptr);
339 *negotiation_lang = t;
345 int Yaz_ProxyConfigP::atoi_l(const char **cp)
348 while (**cp && isdigit(**cp))
350 v = v*10 + (**cp - '0');
356 int Yaz_ProxyConfigP::match_list(int v, const char *m)
360 while(*m && isspace(*m))
371 if (v >= l && v <= h)
380 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
381 Z_AttributeList *attrs,
385 for (i = 0; i<attrs->num_attributes; i++)
387 Z_AttributeElement *el = attrs->attributes[i];
389 if (!el->attributeType)
391 int type = *el->attributeType;
394 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
395 value = el->value.numeric;
398 for(ptr = ptrl->children; ptr; ptr = ptr->next)
400 if (ptr->type == XML_ELEMENT_NODE &&
401 !strcmp((const char *) ptr->name, "attribute"))
403 const char *match_type = 0;
404 const char *match_value = 0;
405 const char *match_error = 0;
406 struct _xmlAttr *attr;
407 for (attr = ptr->properties; attr; attr = attr->next)
409 if (!strcmp((const char *) attr->name, "type") &&
410 attr->children && attr->children->type == XML_TEXT_NODE)
411 match_type = (const char *) attr->children->content;
412 if (!strcmp((const char *) attr->name, "value") &&
413 attr->children && attr->children->type == XML_TEXT_NODE)
414 match_value = (const char *) attr->children->content;
415 if (!strcmp((const char *) attr->name, "error") &&
416 attr->children && attr->children->type == XML_TEXT_NODE)
417 match_error = (const char *) attr->children->content;
419 if (match_type && match_value)
421 char addinfo_str[20];
422 if (!match_list(type, match_type))
426 if (!strcmp(match_type, "*"))
427 sprintf (addinfo_str, "%d", type);
430 if (!match_list(*value, match_value))
432 sprintf (addinfo_str, ODR_INT_PRINTF, *value);
440 *addinfo = odr_strdup(odr, addinfo_str);
441 return atoi(match_error);
453 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
457 if (q->which == Z_RPNStructure_complex)
459 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
462 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
465 else if (q->which == Z_RPNStructure_simple)
467 if (q->u.simple->which == Z_Operand_APT)
469 return check_type_1_attributes(
470 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
479 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
482 // possibly check for Bib-1
483 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
487 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
493 ptr = m_cp->find_target_node(name);
496 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
497 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
504 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
505 const char *schema_identifier)
508 int default_match = 1;
509 if (comp && comp->which == Z_RecordComp_simple &&
510 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
512 esn = comp->u.simple->u.generic;
514 // if no ESN/schema was given accept..
517 // check if schema identifier match
518 if (schema_identifier && !strcmp(esn, schema_identifier))
520 // Check each name element
521 for (; ptr; ptr = ptr->next)
523 if (ptr->type == XML_ELEMENT_NODE
524 && !strcmp((const char *) ptr->name, "name"))
526 xmlNodePtr tptr = ptr->children;
528 for (; tptr; tptr = tptr->next)
529 if (tptr->type == XML_TEXT_NODE && tptr->content)
531 xmlChar *t = tptr->content;
532 while (*t && isspace(*t))
535 while (esn[i] && esn[i] == t[i])
537 if (!esn[i] && (!t[i] || isspace(t[i])))
542 return default_match;
546 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
552 {".xml", "text/xml"},
553 {".xsl", "text/xml"},
554 {".tkl", "text/xml"},
555 {".xsd", "text/xml"},
556 {".html", "text/html"},
557 {".jpg", "image/jpeg"},
558 {".png", "image/png"},
559 {".gif", "image/gif"},
560 {".css", "text/css"},
561 {".pdf", "application/pdf"},
566 size_t plen = strlen (path);
567 for (i = 0; types[i].type; i++)
568 if (types[i].mask == 0)
569 return types[i].type;
572 size_t mlen = strlen(types[i].mask);
573 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
574 return types[i].type;
576 return "application/octet-stream";
580 void Yaz_ProxyConfig::target_authentication(const char *name,
581 ODR odr, Z_InitRequest *req)
584 xmlNodePtr ptr = m_cp->find_target_node(name);
588 for (ptr = ptr->children; ptr; ptr = ptr->next)
589 if (ptr->type == XML_ELEMENT_NODE &&
590 !strcmp((const char *) ptr->name, "target-authentication"))
592 struct _xmlAttr *attr;
593 const char *type = "open";
594 for (attr = ptr->properties; attr; attr = attr->next)
596 if (!strcmp((const char *) attr->name, "type") &&
597 attr->children && attr->children->type == XML_TEXT_NODE)
598 type = (const char *) attr->children->content;
600 const char *t = m_cp->get_text(ptr);
601 if (!t || !strcmp(type, "none"))
603 req->idAuthentication = 0;
605 else if (!strcmp(type, "anonymous"))
607 req->idAuthentication =
608 (Z_IdAuthentication *)
609 odr_malloc (odr, sizeof(*req->idAuthentication));
610 req->idAuthentication->which =
611 Z_IdAuthentication_anonymous;
612 req->idAuthentication->u.anonymous = odr_nullval();
614 else if (!strcmp(type, "open"))
616 req->idAuthentication =
617 (Z_IdAuthentication *)
618 odr_malloc (odr, sizeof(*req->idAuthentication));
619 req->idAuthentication->which =
620 Z_IdAuthentication_open;
621 req->idAuthentication->u.open = odr_strdup (odr, t);
623 else if (!strcmp(type, "idPass"))
625 char user[64], group[64], password[64];
629 sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
631 req->idAuthentication =
632 (Z_IdAuthentication *)
633 odr_malloc (odr, sizeof(*req->idAuthentication));
634 req->idAuthentication->which =
635 Z_IdAuthentication_idPass;
636 req->idAuthentication->u.idPass =
637 (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
638 req->idAuthentication->u.idPass->userId =
639 *user ? odr_strdup(odr, user) : 0;
640 req->idAuthentication->u.idPass->groupId =
641 *group ? odr_strdup(odr, group) : 0;
642 req->idAuthentication->u.idPass->password =
643 *password ? odr_strdup(odr, password) : 0;
649 int Yaz_ProxyConfig::client_authentication(const char *name,
652 const char *password,
655 int ret = YAZPROXY_RET_NOT_ME;
658 ptr = m_cp->find_target_node(name);
661 for (ptr = ptr->children; ptr; ptr = ptr->next)
662 if (ptr->type == XML_ELEMENT_NODE &&
663 !strcmp((const char *) ptr->name, "client-authentication"))
665 struct _xmlAttr *attr;
666 const char *module_name = 0;
667 for (attr = ptr->properties; attr; attr = attr->next)
669 if (!strcmp((const char *) attr->name, "module") &&
670 attr->children && attr->children->type == XML_TEXT_NODE)
671 module_name = (const char *) attr->children->content;
673 ret = m_cp->m_modules.authenticate(module_name,
675 user, group, password,
678 if (ret != YAZPROXY_RET_NOT_ME)
682 if (ret == YAZPROXY_RET_PERM)
687 int Yaz_ProxyConfig::global_client_authentication(const char *user,
689 const char *password,
692 int ret = YAZPROXY_RET_NOT_ME;
694 if (!m_cp->m_proxyPtr)
697 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
699 if (ptr->type == XML_ELEMENT_NODE &&
700 !strcmp((const char *) ptr->name, "client-authentication"))
702 struct _xmlAttr *attr;
703 const char *module_name = 0;
704 for (attr = ptr->properties; attr; attr = attr->next)
706 if (!strcmp((const char *) attr->name, "module") &&
707 attr->children && attr->children->type == XML_TEXT_NODE)
708 module_name = (const char *) attr->children->content;
710 ret = m_cp->m_modules.authenticate(module_name,
712 user, group, password,
715 if (ret != YAZPROXY_RET_NOT_ME)
720 if (ret == YAZPROXY_RET_PERM)
725 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
726 Odr_oid *syntax, Z_RecordComposition *comp,
728 char **stylesheet, char **schema,
730 char **backend_charset,
731 char **usemarcon_ini_stage1,
732 char **usemarcon_ini_stage2
747 xfree (*backend_type);
752 xfree (*backend_charset);
753 *backend_charset = 0;
755 if (usemarcon_ini_stage1)
757 xfree (*usemarcon_ini_stage1);
758 *usemarcon_ini_stage1 = 0;
760 if (usemarcon_ini_stage2)
762 xfree (*usemarcon_ini_stage2);
763 *usemarcon_ini_stage2 = 0;
766 int syntax_has_matched = 0;
769 ptr = m_cp->find_target_node(name);
772 for(ptr = ptr->children; ptr; ptr = ptr->next)
774 if (ptr->type == XML_ELEMENT_NODE &&
775 !strcmp((const char *) ptr->name, "syntax"))
777 int match = 0; // if we match record syntax
778 const char *match_type = 0;
779 const char *match_error = 0;
780 const char *match_marcxml = 0;
781 const char *match_stylesheet = 0;
782 const char *match_identifier = 0;
783 const char *match_backend_type = 0;
784 const char *match_backend_charset = 0;
785 const char *match_usemarcon_ini_stage1 = 0;
786 const char *match_usemarcon_ini_stage2 = 0;
787 struct _xmlAttr *attr;
788 for (attr = ptr->properties; attr; attr = attr->next)
790 if (!strcmp((const char *) attr->name, "type") &&
791 attr->children && attr->children->type == XML_TEXT_NODE)
792 match_type = (const char *) attr->children->content;
793 if (!strcmp((const char *) attr->name, "error") &&
794 attr->children && attr->children->type == XML_TEXT_NODE)
795 match_error = (const char *) attr->children->content;
796 if (!strcmp((const char *) attr->name, "marcxml") &&
797 attr->children && attr->children->type == XML_TEXT_NODE)
798 match_marcxml = (const char *) attr->children->content;
799 if (!strcmp((const char *) attr->name, "stylesheet") &&
800 attr->children && attr->children->type == XML_TEXT_NODE)
801 match_stylesheet = (const char *) attr->children->content;
802 if (!strcmp((const char *) attr->name, "identifier") &&
803 attr->children && attr->children->type == XML_TEXT_NODE)
804 match_identifier = (const char *) attr->children->content;
805 if (!strcmp((const char *) attr->name, "backendtype") &&
806 attr->children && attr->children->type == XML_TEXT_NODE)
807 match_backend_type = (const char *)
808 attr->children->content;
809 if (!strcmp((const char *) attr->name, "backendcharset") &&
810 attr->children && attr->children->type == XML_TEXT_NODE)
811 match_backend_charset = (const char *)
812 attr->children->content;
813 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
814 attr->children && attr->children->type == XML_TEXT_NODE)
815 match_usemarcon_ini_stage1 = (const char *)
816 attr->children->content;
817 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
818 attr->children && attr->children->type == XML_TEXT_NODE)
819 match_usemarcon_ini_stage2 = (const char *)
820 attr->children->content;
824 if (!strcmp(match_type, "*"))
826 else if (!strcmp(match_type, "none"))
834 = yaz_string_to_oid_odr(yaz_oid_std(),
835 CLASS_RECSYN, match_type,
837 if (oid_oidcmp(match_oid, syntax) == 0)
844 syntax_has_matched = 1;
845 match = m_cp->check_schema(ptr->children, comp,
850 if (stylesheet && match_stylesheet)
853 *stylesheet = xstrdup(match_stylesheet);
855 if (schema && match_identifier)
858 *schema = xstrdup(match_identifier);
860 if (backend_type && match_backend_type)
862 xfree(*backend_type);
863 *backend_type = xstrdup(match_backend_type);
865 if (backend_charset && match_backend_charset)
867 xfree(*backend_charset);
868 *backend_charset = xstrdup(match_backend_charset);
870 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
872 xfree(*usemarcon_ini_stage1);
873 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
875 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
877 xfree(*usemarcon_ini_stage2);
878 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
886 if (syntax_has_matched) // if syntax OK, bad schema/ESN
890 char dotoid_str[OID_STR_MAX];
891 oid_oid_to_dotstring(syntax, dotoid_str);
892 *addinfo = odr_strdup(odr, dotoid_str);
894 return atoi(match_error);
907 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name)
909 /* db seems always to be passed as NULL */
913 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
915 if (ptr->type == XML_ELEMENT_NODE &&
916 !strcmp((const char *) ptr->name, "target"))
921 // <target default="1"> ?
922 struct _xmlAttr *attr;
923 for (attr = ptr->properties; attr; attr = attr->next)
924 if (!strcmp((const char *) attr->name, "default") &&
925 attr->children && attr->children->type == XML_TEXT_NODE)
927 xmlChar *t = attr->children->content;
934 // <target name="name"> ?
935 struct _xmlAttr *attr;
936 for (attr = ptr->properties; attr; attr = attr->next)
937 if (!strcmp((const char *) attr->name, "name"))
940 && attr->children->type==XML_TEXT_NODE
941 && attr->children->content
942 && (!strcmp((const char *) attr->children->content,
944 || !strcmp((const char *) attr->children->content,
957 int Yaz_ProxyConfig::get_target_no(int no,
964 int *target_idletime,
965 int *client_idletime,
968 int *keepalive_limit_bw,
969 int *keepalive_limit_pdu,
971 const char **cql2rpn,
972 const char **authentication,
973 const char **negotiation_charset,
974 const char **negotiation_lang,
975 const char **target_charset,
976 const char **default_client_query_charset)
980 if (!m_cp->m_proxyPtr)
983 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
984 if (ptr->type == XML_ELEMENT_NODE &&
985 !strcmp((const char *) ptr->name, "target"))
989 struct _xmlAttr *attr;
990 for (attr = ptr->properties; attr; attr = attr->next)
991 if (!strcmp((const char *) attr->name, "name"))
994 && attr->children->type==XML_TEXT_NODE
995 && attr->children->content)
996 *name = (const char *) attr->children->content;
998 m_cp->return_target_info(
1000 limit_bw, limit_pdu, limit_req,
1002 target_idletime, client_idletime,
1004 keepalive_limit_bw, keepalive_limit_pdu,
1006 negotiation_charset, negotiation_lang, target_charset,
1007 default_client_query_charset);
1016 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
1018 if (len == strlen(item) && memcmp(hay, item, len) == 0)
1023 int Yaz_ProxyConfig::get_file_access_info(const char *path)
1027 if (!m_cp->m_proxyPtr)
1029 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1031 if (ptr->type == XML_ELEMENT_NODE
1032 && !strcmp((const char *) ptr->name, "docpath"))
1034 const char *docpath = m_cp->get_text(ptr);
1035 size_t docpath_len = strlen(docpath);
1036 if (docpath_len < strlen(path) && path[docpath_len] == '/'
1037 && !memcmp(docpath, path, docpath_len))
1045 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
1049 int *period_connect,
1050 int *num_msg_threads)
1054 *num_msg_threads = 0;
1057 if (!m_cp->m_proxyPtr)
1059 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1061 if (ptr->type == XML_ELEMENT_NODE
1062 && !strcmp((const char *) ptr->name, "log"))
1064 const char *v = m_cp->get_text(ptr);
1069 while (*cp && *cp != ',' && !isspace(*cp))
1071 size_t len = cp - v;
1072 if (m_cp->mycmp(v, "client-apdu", len))
1073 *log_mask |= PROXY_LOG_APDU_CLIENT;
1074 if (m_cp->mycmp(v, "server-apdu", len))
1075 *log_mask |= PROXY_LOG_APDU_SERVER;
1076 if (m_cp->mycmp(v, "client-requests", len))
1077 *log_mask |= PROXY_LOG_REQ_CLIENT;
1078 if (m_cp->mycmp(v, "server-requests", len))
1079 *log_mask |= PROXY_LOG_REQ_SERVER;
1080 if (m_cp->mycmp(v, "client-ip", len))
1081 *log_mask |= PROXY_LOG_IP_CLIENT;
1083 *log_mask |= atoi(v);
1086 while (*cp && isspace(*cp))
1091 else if (ptr->type == XML_ELEMENT_NODE &&
1092 !strcmp((const char *) ptr->name, "max-clients"))
1094 const char *t = m_cp->get_text(ptr);
1097 *max_clients = atoi(t);
1098 if (*max_clients < 1)
1102 else if (ptr->type == XML_ELEMENT_NODE &&
1103 !strcmp((const char *) ptr->name, "period-connect"))
1105 const char *t = m_cp->get_text(ptr);
1107 *period_connect = atoi(t);
1109 else if (ptr->type == XML_ELEMENT_NODE &&
1110 !strcmp((const char *) ptr->name, "max-connect"))
1112 const char *t = m_cp->get_text(ptr);
1115 *max_connect = atoi(t);
1118 else if (ptr->type == XML_ELEMENT_NODE &&
1119 !strcmp((const char *) ptr->name, "limit-connect"))
1121 const char *t = m_cp->get_text(ptr);
1124 *limit_connect = atoi(t);
1127 else if (ptr->type == XML_ELEMENT_NODE &&
1128 !strcmp((const char *) ptr->name, "target"))
1130 else if (ptr->type == XML_ELEMENT_NODE &&
1131 !strcmp((const char *) ptr->name, "docpath"))
1133 else if (ptr->type == XML_ELEMENT_NODE &&
1134 !strcmp((const char *) ptr->name, "module"))
1136 else if (ptr->type == XML_ELEMENT_NODE &&
1137 !strcmp((const char *) ptr->name, "client-authentication"))
1139 else if (ptr->type == XML_ELEMENT_NODE &&
1140 !strcmp((const char *) ptr->name, "threads"))
1142 const char *t = m_cp->get_text(ptr);
1145 *num_msg_threads = atoi(t);
1148 else if (ptr->type == XML_ELEMENT_NODE)
1150 yaz_log(YLOG_WARN, "0 Unknown element %s in yazproxy config",
1158 int Yaz_ProxyConfigP::get_explain_ptr(const char *db,
1159 xmlNodePtr *ptr_target,
1160 xmlNodePtr *ptr_explain)
1167 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1169 if (ptr->type == XML_ELEMENT_NODE &&
1170 !strcmp((const char *) ptr->name, "target"))
1172 int db_match_on_name = 0;
1173 struct _xmlAttr *attr;
1175 for (attr = ptr->properties; attr; attr = attr->next)
1176 if (!strcmp((const char *) attr->name, "name"))
1179 && attr->children->type==XML_TEXT_NODE
1180 && attr->children->content
1181 && (!strcmp((const char *) attr->children->content,
1183 db_match_on_name = 1;
1186 xmlNodePtr ptr = (*ptr_target)->children;
1187 for (; ptr; ptr = ptr->next)
1189 if (ptr->type == XML_ELEMENT_NODE &&
1190 !strcmp((const char *) ptr->name, "explain"))
1193 xmlNodePtr ptr = (*ptr_explain)->children;
1195 for (; ptr; ptr = ptr->next)
1196 if (ptr->type == XML_ELEMENT_NODE &&
1197 !strcmp((const char *) ptr->name, "serverInfo"))
1201 for (ptr = ptr->children; ptr; ptr = ptr->next)
1202 if (ptr->type == XML_ELEMENT_NODE &&
1203 !strcmp((const char *) ptr->name, "database"))
1208 for (ptr = ptr->children; ptr; ptr = ptr->next)
1209 if (ptr->type == XML_TEXT_NODE &&
1211 !strcmp((const char *) ptr->content, db))
1218 if (db_match_on_name)
1226 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1227 const char **backend_db)
1230 xmlNodePtr ptr_target, ptr_explain;
1231 if (m_cp->get_explain_ptr(db, &ptr_target, &ptr_explain)
1234 struct _xmlAttr *attr;
1235 const char *name = 0;
1237 for (attr = ptr_target->properties; attr; attr = attr->next)
1238 if (!strcmp((const char *) attr->name, "name")
1240 && attr->children->type==XML_TEXT_NODE
1241 && attr->children->content
1242 && attr->children->content[0])
1244 name = (const char *)attr->children->content;
1249 for (attr = ptr_target->properties; attr; attr = attr->next)
1250 if (!strcmp((const char *) attr->name, "database"))
1253 && attr->children->type==XML_TEXT_NODE
1254 && attr->children->content)
1255 *backend_db = (const char *) attr->children->content;
1264 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1265 const char *db, int *len,
1269 xmlNodePtr ptr_target, ptr_explain;
1270 if (m_cp->get_explain_ptr(db, &ptr_target, &ptr_explain))
1279 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1281 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1283 xmlDocSetRootElement(doc, ptr2);
1286 xmlDocDumpMemory(doc, &buf_out, len);
1287 char *content = (char*) odr_malloc(odr, *len);
1288 memcpy(content, buf_out, *len);
1300 void Yaz_ProxyConfig::get_target_info(const char *name,
1306 int *target_idletime,
1307 int *client_idletime,
1310 int *keepalive_limit_bw,
1311 int *keepalive_limit_pdu,
1313 const char **cql2rpn,
1314 const char **negotiation_charset,
1315 const char **negotiation_lang,
1316 const char **target_charset,
1317 const char **default_client_query_charset)
1321 if (!m_cp->m_proxyPtr)
1328 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1330 if (ptr->type == XML_ELEMENT_NODE &&
1331 !strcmp((const char *) ptr->name, "max-clients"))
1333 const char *t = m_cp->get_text(ptr);
1336 *max_clients = atoi(t);
1337 if (*max_clients < 1)
1342 ptr = m_cp->find_target_node(name);
1350 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1352 target_idletime, client_idletime,
1354 keepalive_limit_bw, keepalive_limit_pdu,
1356 negotiation_charset, negotiation_lang,
1358 default_client_query_charset);
1370 * c-file-style: "Stroustrup"
1371 * indent-tabs-mode: nil
1373 * vim: shiftwidth=4 tabstop=8 expandtab