1 /* $Id: yaz-proxy-config.cpp,v 1.25 2006-03-25 10:59:14 adam Exp $
2 Copyright (c) 1998-2005, Index Data.
4 This file is part of the yaz-proxy.
6 YAZ proxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with YAZ proxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 class Yaz_ProxyConfigP {
28 friend class Yaz_ProxyConfig;
30 Yaz_ProxyModules m_modules;
31 int mycmp(const char *hay, const char *item, size_t len);
32 int match_list(int v, const char *m);
33 int atoi_l(const char **cp);
35 void load_modules(void);
36 int check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
37 const char *schema_identifier);
39 xmlNodePtr m_proxyPtr;
40 void return_target_info(xmlNodePtr ptr, const char **url,
41 int *limit_bw, int *limit_pdu, int *limit_req,
42 int *limit_search, int *limit_connect,
43 int *target_idletime, int *client_idletime,
44 int *keepalive_limit_bw, int *keepalive_limit_pdu,
45 int *pre_init, const char **cql2rpn,
46 const char **negotiation_charset,
47 const char **negotiation_lang,
48 const char **target_charset,
49 const char **default_client_query_charset);
50 void return_limit(xmlNodePtr ptr,
51 int *limit_bw, int *limit_pdu, int *limit_req,
52 int *limit_search, int *limit_connect);
53 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
55 xmlNodePtr find_target_node(const char *name, const char *db);
56 xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
57 const char *get_text(xmlNodePtr ptr);
58 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
59 Z_AttributeList *attrs,
61 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
63 int get_explain_ptr(const char *host, const char *db,
64 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
70 Yaz_ProxyConfigP::Yaz_ProxyConfigP() : m_modules()
78 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
86 Yaz_ProxyConfig::Yaz_ProxyConfig()
88 m_cp = new Yaz_ProxyConfigP();
91 Yaz_ProxyConfig::~Yaz_ProxyConfig()
97 void Yaz_ProxyConfigP::load_modules()
102 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
105 if (ptr->type == XML_ELEMENT_NODE
106 && !strcmp((const char *) ptr->name, "module")
107 && (fname = get_text(ptr)))
109 m_modules.add_module(fname);
115 int Yaz_ProxyConfig::read_xml(const char *fname)
118 xmlDocPtr ndoc = xmlParseFile(fname);
122 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
123 return -1; // no good
125 int noSubstitutions = xmlXIncludeProcess(ndoc);
126 if (noSubstitutions == -1)
127 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
129 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
130 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
131 strcmp((const char *) proxyPtr->name, "proxy"))
133 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
137 m_cp->m_proxyPtr = proxyPtr;
139 // OK: release previous and make it the current one.
141 xmlFreeDoc(m_cp->m_docPtr);
142 m_cp->m_docPtr = ndoc;
144 m_cp->m_modules.unload_modules();
145 m_cp->load_modules();
153 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
155 for(ptr = ptr->children; ptr; ptr = ptr->next)
156 if (ptr->type == XML_TEXT_NODE)
158 xmlChar *t = ptr->content;
163 return (const char *) t;
171 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
178 for (ptr = ptr->children; ptr; ptr = ptr->next)
180 if (ptr->type == XML_ELEMENT_NODE
181 && !strcmp((const char *) ptr->name, "bandwidth"))
183 const char *t = get_text(ptr);
187 if (ptr->type == XML_ELEMENT_NODE
188 && !strcmp((const char *) ptr->name, "retrieve"))
190 const char *t = get_text(ptr);
192 *limit_req = atoi(t);
194 if (ptr->type == XML_ELEMENT_NODE
195 && !strcmp((const char *) ptr->name, "pdu"))
197 const char *t = get_text(ptr);
199 *limit_pdu = atoi(t);
201 if (ptr->type == XML_ELEMENT_NODE
202 && !strcmp((const char *) ptr->name, "search"))
204 const char *t = get_text(ptr);
206 *limit_search = atoi(t);
208 if (ptr->type == XML_ELEMENT_NODE
209 && !strcmp((const char *) ptr->name, "connect"))
211 const char *t = get_text(ptr);
213 *limit_connect = atoi(t);
220 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
227 int *target_idletime,
228 int *client_idletime,
229 int *keepalive_limit_bw,
230 int *keepalive_limit_pdu,
232 const char **cql2rpn,
233 const char **negotiation_charset,
234 const char **negotiation_lang,
235 const char **target_charset,
236 const char **default_client_query_charset)
241 for (; ptr; ptr = ptr->next)
243 if (ptr->type == XML_ELEMENT_NODE
244 && !strcmp((const char *) ptr->name, "preinit"))
246 const char *v = get_text(ptr);
247 *pre_init = v ? atoi(v) : 1;
249 if (ptr->type == XML_ELEMENT_NODE
250 && !strcmp((const char *) ptr->name, "url"))
252 const char *t = get_text(ptr);
253 if (t && no_url < MAX_ZURL_PLEX)
259 if (ptr->type == XML_ELEMENT_NODE
260 && !strcmp((const char *) ptr->name, "keepalive"))
263 *keepalive_limit_bw = 500000;
264 *keepalive_limit_pdu = 1000;
265 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
266 &dummy, &dummy, &dummy);
268 if (ptr->type == XML_ELEMENT_NODE
269 && !strcmp((const char *) ptr->name, "limit"))
270 return_limit(ptr, limit_bw, limit_pdu, limit_req,
271 limit_search, limit_connect);
272 if (ptr->type == XML_ELEMENT_NODE
273 && !strcmp((const char *) ptr->name, "target-timeout"))
275 const char *t = get_text(ptr);
278 *target_idletime = atoi(t);
279 if (*target_idletime < 0)
280 *target_idletime = 0;
283 if (ptr->type == XML_ELEMENT_NODE
284 && !strcmp((const char *) ptr->name, "client-timeout"))
286 const char *t = get_text(ptr);
289 *client_idletime = atoi(t);
290 if (*client_idletime < 0)
291 *client_idletime = 0;
294 if (ptr->type == XML_ELEMENT_NODE
295 && !strcmp((const char *) ptr->name, "cql2rpn"))
297 const char *t = get_text(ptr);
301 if (ptr->type == XML_ELEMENT_NODE
302 && !strcmp((const char *) ptr->name, "target-charset"))
304 const char *t = get_text(ptr);
305 if (t && target_charset)
308 if (ptr->type == XML_ELEMENT_NODE
309 && !strcmp((const char *) ptr->name, "default-client-charset"))
311 const char *t = get_text(ptr);
312 if (t && default_client_query_charset)
313 *default_client_query_charset = t;
315 if (ptr->type == XML_ELEMENT_NODE
316 && !strcmp((const char *) ptr->name, "negotiation-charset"))
318 const char *t = get_text(ptr);
320 *negotiation_charset = t;
322 if (ptr->type == XML_ELEMENT_NODE
323 && !strcmp((const char *) ptr->name, "negotiation-lang"))
325 const char *t = get_text(ptr);
327 *negotiation_lang = t;
333 int Yaz_ProxyConfigP::atoi_l(const char **cp)
336 while (**cp && isdigit(**cp))
338 v = v*10 + (**cp - '0');
344 int Yaz_ProxyConfigP::match_list(int v, const char *m)
348 while(*m && isspace(*m))
359 if (v >= l && v <= h)
368 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
369 Z_AttributeList *attrs,
373 for (i = 0; i<attrs->num_attributes; i++)
375 Z_AttributeElement *el = attrs->attributes[i];
377 if (!el->attributeType)
379 int type = *el->attributeType;
382 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
383 value = el->value.numeric;
386 for(ptr = ptrl->children; ptr; ptr = ptr->next)
388 if (ptr->type == XML_ELEMENT_NODE &&
389 !strcmp((const char *) ptr->name, "attribute"))
391 const char *match_type = 0;
392 const char *match_value = 0;
393 const char *match_error = 0;
394 struct _xmlAttr *attr;
395 for (attr = ptr->properties; attr; attr = attr->next)
397 if (!strcmp((const char *) attr->name, "type") &&
398 attr->children && attr->children->type == XML_TEXT_NODE)
399 match_type = (const char *) attr->children->content;
400 if (!strcmp((const char *) attr->name, "value") &&
401 attr->children && attr->children->type == XML_TEXT_NODE)
402 match_value = (const char *) attr->children->content;
403 if (!strcmp((const char *) attr->name, "error") &&
404 attr->children && attr->children->type == XML_TEXT_NODE)
405 match_error = (const char *) attr->children->content;
407 if (match_type && match_value)
409 char addinfo_str[20];
410 if (!match_list(type, match_type))
414 if (!strcmp(match_type, "*"))
415 sprintf (addinfo_str, "%d", type);
418 if (!match_list(*value, match_value))
420 sprintf (addinfo_str, "%d", *value);
428 *addinfo = odr_strdup(odr, addinfo_str);
429 return atoi(match_error);
441 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
445 if (q->which == Z_RPNStructure_complex)
447 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
450 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
453 else if (q->which == Z_RPNStructure_simple)
455 if (q->u.simple->which == Z_Operand_APT)
457 return check_type_1_attributes(
458 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
467 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
470 // possibly check for Bib-1
471 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
475 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
481 ptr = m_cp->find_target_node(name, 0);
484 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
485 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
492 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
493 const char *schema_identifier)
496 int default_match = 1;
497 if (comp && comp->which == Z_RecordComp_simple &&
498 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
500 esn = comp->u.simple->u.generic;
502 // if no ESN/schema was given accept..
505 // check if schema identifier match
506 if (schema_identifier && !strcmp(esn, schema_identifier))
508 // Check each name element
509 for (; ptr; ptr = ptr->next)
511 if (ptr->type == XML_ELEMENT_NODE
512 && !strcmp((const char *) ptr->name, "name"))
514 xmlNodePtr tptr = ptr->children;
516 for (; tptr; tptr = tptr->next)
517 if (tptr->type == XML_TEXT_NODE && tptr->content)
519 xmlChar *t = tptr->content;
520 while (*t && isspace(*t))
523 while (esn[i] && esn[i] == t[i])
525 if (!esn[i] && (!t[i] || isspace(t[i])))
530 return default_match;
534 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
540 {".xml", "text/xml"},
541 {".xsl", "text/xml"},
542 {".tkl", "text/xml"},
543 {".xsd", "text/xml"},
544 {".html", "text/html"},
545 {".jpg", "image/jpeg"},
546 {".png", "image/png"},
547 {".gif", "image/gif"},
552 size_t plen = strlen (path);
553 for (i = 0; types[i].type; i++)
554 if (types[i].mask == 0)
555 return types[i].type;
558 size_t mlen = strlen(types[i].mask);
559 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
560 return types[i].type;
562 return "application/octet-stream";
566 void Yaz_ProxyConfig::target_authentication(const char *name,
567 ODR odr, Z_InitRequest *req)
570 xmlNodePtr ptr = m_cp->find_target_node(name, 0);
574 for (ptr = ptr->children; ptr; ptr = ptr->next)
575 if (ptr->type == XML_ELEMENT_NODE &&
576 !strcmp((const char *) ptr->name, "target-authentication"))
578 struct _xmlAttr *attr;
579 const char *type = "open";
580 for (attr = ptr->properties; attr; attr = attr->next)
582 if (!strcmp((const char *) attr->name, "type") &&
583 attr->children && attr->children->type == XML_TEXT_NODE)
584 type = (const char *) attr->children->content;
586 const char *t = m_cp->get_text(ptr);
587 if (!t || !strcmp(type, "none"))
589 req->idAuthentication = 0;
591 else if (!strcmp(type, "anonymous"))
593 req->idAuthentication =
594 (Z_IdAuthentication *)
595 odr_malloc (odr, sizeof(*req->idAuthentication));
596 req->idAuthentication->which =
597 Z_IdAuthentication_anonymous;
598 req->idAuthentication->u.anonymous = odr_nullval();
600 else if (!strcmp(type, "open"))
602 req->idAuthentication =
603 (Z_IdAuthentication *)
604 odr_malloc (odr, sizeof(*req->idAuthentication));
605 req->idAuthentication->which =
606 Z_IdAuthentication_open;
607 req->idAuthentication->u.open = odr_strdup (odr, t);
609 else if (!strcmp(type, "idPass"))
611 char user[64], group[64], password[64];
615 sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
617 req->idAuthentication =
618 (Z_IdAuthentication *)
619 odr_malloc (odr, sizeof(*req->idAuthentication));
620 req->idAuthentication->which =
621 Z_IdAuthentication_idPass;
622 req->idAuthentication->u.idPass =
623 (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
624 req->idAuthentication->u.idPass->userId =
625 *user ? odr_strdup(odr, user) : 0;
626 req->idAuthentication->u.idPass->groupId =
627 *group ? odr_strdup(odr, group) : 0;
628 req->idAuthentication->u.idPass->password =
629 *password ? odr_strdup(odr, password) : 0;
635 int Yaz_ProxyConfig::client_authentication(const char *name,
638 const char *password,
641 int ret = YAZPROXY_RET_NOT_ME;
644 ptr = m_cp->find_target_node(name, 0);
647 for (ptr = ptr->children; ptr; ptr = ptr->next)
648 if (ptr->type == XML_ELEMENT_NODE &&
649 !strcmp((const char *) ptr->name, "client-authentication"))
651 struct _xmlAttr *attr;
652 const char *module_name = 0;
653 for (attr = ptr->properties; attr; attr = attr->next)
655 if (!strcmp((const char *) attr->name, "module") &&
656 attr->children && attr->children->type == XML_TEXT_NODE)
657 module_name = (const char *) attr->children->content;
659 ret = m_cp->m_modules.authenticate(module_name,
661 user, group, password,
664 if (ret != YAZPROXY_RET_NOT_ME)
668 if (ret == YAZPROXY_RET_PERM)
673 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
674 Odr_oid *syntax, Z_RecordComposition *comp,
676 char **stylesheet, char **schema,
678 char **backend_charset,
679 char **usemarcon_ini_stage1,
680 char **usemarcon_ini_stage2
695 xfree (*backend_type);
700 xfree (*backend_charset);
701 *backend_charset = 0;
703 if (usemarcon_ini_stage1)
705 xfree (*usemarcon_ini_stage1);
706 *usemarcon_ini_stage1 = 0;
708 if (usemarcon_ini_stage2)
710 xfree (*usemarcon_ini_stage2);
711 *usemarcon_ini_stage2 = 0;
714 int syntax_has_matched = 0;
717 ptr = m_cp->find_target_node(name, 0);
720 for(ptr = ptr->children; ptr; ptr = ptr->next)
722 if (ptr->type == XML_ELEMENT_NODE &&
723 !strcmp((const char *) ptr->name, "syntax"))
725 int match = 0; // if we match record syntax
726 const char *match_type = 0;
727 const char *match_error = 0;
728 const char *match_marcxml = 0;
729 const char *match_stylesheet = 0;
730 const char *match_identifier = 0;
731 const char *match_backend_type = 0;
732 const char *match_backend_charset = 0;
733 const char *match_usemarcon_ini_stage1 = 0;
734 const char *match_usemarcon_ini_stage2 = 0;
735 struct _xmlAttr *attr;
736 for (attr = ptr->properties; attr; attr = attr->next)
738 if (!strcmp((const char *) attr->name, "type") &&
739 attr->children && attr->children->type == XML_TEXT_NODE)
740 match_type = (const char *) attr->children->content;
741 if (!strcmp((const char *) attr->name, "error") &&
742 attr->children && attr->children->type == XML_TEXT_NODE)
743 match_error = (const char *) attr->children->content;
744 if (!strcmp((const char *) attr->name, "marcxml") &&
745 attr->children && attr->children->type == XML_TEXT_NODE)
746 match_marcxml = (const char *) attr->children->content;
747 if (!strcmp((const char *) attr->name, "stylesheet") &&
748 attr->children && attr->children->type == XML_TEXT_NODE)
749 match_stylesheet = (const char *) attr->children->content;
750 if (!strcmp((const char *) attr->name, "identifier") &&
751 attr->children && attr->children->type == XML_TEXT_NODE)
752 match_identifier = (const char *) attr->children->content;
753 if (!strcmp((const char *) attr->name, "backendtype") &&
754 attr->children && attr->children->type == XML_TEXT_NODE)
755 match_backend_type = (const char *)
756 attr->children->content;
757 if (!strcmp((const char *) attr->name, "backendcharset") &&
758 attr->children && attr->children->type == XML_TEXT_NODE)
759 match_backend_charset = (const char *)
760 attr->children->content;
761 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
762 attr->children && attr->children->type == XML_TEXT_NODE)
763 match_usemarcon_ini_stage1 = (const char *)
764 attr->children->content;
765 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
766 attr->children && attr->children->type == XML_TEXT_NODE)
767 match_usemarcon_ini_stage2 = (const char *)
768 attr->children->content;
772 if (!strcmp(match_type, "*"))
774 else if (!strcmp(match_type, "none"))
781 int match_oid[OID_SIZE];
782 oid_name_to_oid(CLASS_RECSYN, match_type, match_oid);
783 if (oid_oidcmp(match_oid, syntax) == 0)
790 syntax_has_matched = 1;
791 match = m_cp->check_schema(ptr->children, comp,
796 if (stylesheet && match_stylesheet)
799 *stylesheet = xstrdup(match_stylesheet);
801 if (schema && match_identifier)
804 *schema = xstrdup(match_identifier);
806 if (backend_type && match_backend_type)
808 xfree(*backend_type);
809 *backend_type = xstrdup(match_backend_type);
811 if (backend_charset && match_backend_charset)
813 xfree(*backend_charset);
814 *backend_charset = xstrdup(match_backend_charset);
816 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
818 xfree(*usemarcon_ini_stage1);
819 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
821 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
823 xfree(*usemarcon_ini_stage2);
824 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
832 if (syntax_has_matched) // if syntax OK, bad schema/ESN
836 char dotoid_str[100];
837 oid_to_dotstring(syntax, dotoid_str);
838 *addinfo = odr_strdup(odr, dotoid_str);
840 return atoi(match_error);
851 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
858 for (dptr = ptr->children; dptr; dptr = dptr->next)
859 if (dptr->type == XML_ELEMENT_NODE &&
860 !strcmp((const char *) dptr->name, "database"))
862 struct _xmlAttr *attr;
863 for (attr = dptr->properties; attr; attr = attr->next)
864 if (!strcmp((const char *) attr->name, "name"))
867 && attr->children->type==XML_TEXT_NODE
868 && attr->children->content
869 && (!strcmp((const char *) attr->children->content, db)
870 || !strcmp((const char *) attr->children->content,
878 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
883 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
885 if (ptr->type == XML_ELEMENT_NODE &&
886 !strcmp((const char *) ptr->name, "target"))
891 // <target default="1"> ?
892 struct _xmlAttr *attr;
893 for (attr = ptr->properties; attr; attr = attr->next)
894 if (!strcmp((const char *) attr->name, "default") &&
895 attr->children && attr->children->type == XML_TEXT_NODE)
897 xmlChar *t = attr->children->content;
900 return find_target_db(ptr, db);
906 // <target name="name"> ?
907 struct _xmlAttr *attr;
908 for (attr = ptr->properties; attr; attr = attr->next)
909 if (!strcmp((const char *) attr->name, "name"))
912 && attr->children->type==XML_TEXT_NODE
913 && attr->children->content
914 && (!strcmp((const char *) attr->children->content,
916 || !strcmp((const char *) attr->children->content,
919 return find_target_db(ptr, db);
929 int Yaz_ProxyConfig::get_target_no(int no,
937 int *target_idletime,
938 int *client_idletime,
940 int *keepalive_limit_bw,
941 int *keepalive_limit_pdu,
943 const char **cql2rpn,
944 const char **authentication,
945 const char **negotiation_charset,
946 const char **negotiation_lang,
947 const char **target_charset,
948 const char **default_client_query_charset)
952 if (!m_cp->m_proxyPtr)
955 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
956 if (ptr->type == XML_ELEMENT_NODE &&
957 !strcmp((const char *) ptr->name, "target"))
961 struct _xmlAttr *attr;
962 for (attr = ptr->properties; attr; attr = attr->next)
963 if (!strcmp((const char *) attr->name, "name"))
966 && attr->children->type==XML_TEXT_NODE
967 && attr->children->content)
968 *name = (const char *) attr->children->content;
970 m_cp->return_target_info(
972 limit_bw, limit_pdu, limit_req,
973 limit_search, limit_connect,
974 target_idletime, client_idletime,
975 keepalive_limit_bw, keepalive_limit_pdu,
977 negotiation_charset, negotiation_lang, target_charset,
978 default_client_query_charset);
987 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
989 if (len == strlen(item) && memcmp(hay, item, len) == 0)
994 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
999 if (!m_cp->m_proxyPtr)
1001 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1003 if (ptr->type == XML_ELEMENT_NODE
1004 && !strcmp((const char *) ptr->name, "log"))
1006 const char *v = m_cp->get_text(ptr);
1011 while (*cp && *cp != ',' && !isspace(*cp))
1013 size_t len = cp - v;
1014 if (m_cp->mycmp(v, "client-apdu", len))
1015 *log_mask |= PROXY_LOG_APDU_CLIENT;
1016 if (m_cp->mycmp(v, "server-apdu", len))
1017 *log_mask |= PROXY_LOG_APDU_SERVER;
1018 if (m_cp->mycmp(v, "client-requests", len))
1019 *log_mask |= PROXY_LOG_REQ_CLIENT;
1020 if (m_cp->mycmp(v, "server-requests", len))
1021 *log_mask |= PROXY_LOG_REQ_SERVER;
1023 *log_mask |= atoi(v);
1026 while (*cp && isspace(*cp))
1031 if (ptr->type == XML_ELEMENT_NODE &&
1032 !strcmp((const char *) ptr->name, "max-clients"))
1034 const char *t = m_cp->get_text(ptr);
1037 *max_clients = atoi(t);
1038 if (*max_clients < 1)
1047 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1048 xmlNodePtr *ptr_target,
1049 xmlNodePtr *ptr_explain)
1056 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1058 if (ptr->type == XML_ELEMENT_NODE &&
1059 !strcmp((const char *) ptr->name, "target"))
1062 xmlNodePtr ptr = (*ptr_target)->children;
1063 for (; ptr; ptr = ptr->next)
1065 if (ptr->type == XML_ELEMENT_NODE &&
1066 !strcmp((const char *) ptr->name, "explain"))
1069 xmlNodePtr ptr = (*ptr_explain)->children;
1071 for (; ptr; ptr = ptr->next)
1072 if (ptr->type == XML_ELEMENT_NODE &&
1073 !strcmp((const char *) ptr->name, "serverInfo"))
1077 for (ptr = ptr->children; ptr; ptr = ptr->next)
1078 if (ptr->type == XML_ELEMENT_NODE &&
1079 !strcmp((const char *) ptr->name, "database"))
1084 for (ptr = ptr->children; ptr; ptr = ptr->next)
1085 if (ptr->type == XML_TEXT_NODE &&
1087 !strcmp((const char *) ptr->content, db))
1100 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1101 const char **backend_db)
1104 xmlNodePtr ptr_target, ptr_explain;
1105 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1108 struct _xmlAttr *attr;
1109 const char *name = 0;
1111 for (attr = ptr_target->properties; attr; attr = attr->next)
1112 if (!strcmp((const char *) attr->name, "name")
1114 && attr->children->type==XML_TEXT_NODE
1115 && attr->children->content
1116 && attr->children->content[0])
1118 name = (const char *)attr->children->content;
1123 for (attr = ptr_target->properties; attr; attr = attr->next)
1124 if (!strcmp((const char *) attr->name, "database"))
1127 && attr->children->type==XML_TEXT_NODE
1128 && attr->children->content)
1129 *backend_db = (const char *) attr->children->content;
1138 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1139 const char *db, int *len)
1142 xmlNodePtr ptr_target, ptr_explain;
1143 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1145 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1147 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1149 xmlDocSetRootElement(doc, ptr2);
1152 xmlDocDumpMemory(doc, &buf_out, len);
1153 char *content = (char*) odr_malloc(odr, *len);
1154 memcpy(content, buf_out, *len);
1164 void Yaz_ProxyConfig::get_target_info(const char *name,
1171 int *target_idletime,
1172 int *client_idletime,
1174 int *keepalive_limit_bw,
1175 int *keepalive_limit_pdu,
1177 const char **cql2rpn,
1178 const char **negotiation_charset,
1179 const char **negotiation_lang,
1180 const char **target_charset,
1181 const char **default_client_query_charset)
1185 if (!m_cp->m_proxyPtr)
1192 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1194 if (ptr->type == XML_ELEMENT_NODE &&
1195 !strcmp((const char *) ptr->name, "max-clients"))
1197 const char *t = m_cp->get_text(ptr);
1200 *max_clients = atoi(t);
1201 if (*max_clients < 1)
1206 ptr = m_cp->find_target_node(name, 0);
1214 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1215 limit_search, limit_connect,
1216 target_idletime, client_idletime,
1217 keepalive_limit_bw, keepalive_limit_pdu,
1219 negotiation_charset, negotiation_lang,
1221 default_client_query_charset);
1233 * indent-tabs-mode: nil
1235 * vim: shiftwidth=4 tabstop=8 expandtab