1 /* $Id: yaz-proxy-config.cpp,v 1.20 2005-05-30 20:09:21 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 *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 void return_limit(xmlNodePtr ptr,
49 int *limit_bw, int *limit_pdu, int *limit_req);
50 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
52 xmlNodePtr find_target_node(const char *name, const char *db);
53 xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
54 const char *get_text(xmlNodePtr ptr);
55 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
56 Z_AttributeList *attrs,
58 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
60 int get_explain_ptr(const char *host, const char *db,
61 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
67 Yaz_ProxyConfigP::Yaz_ProxyConfigP() : m_modules()
75 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
83 Yaz_ProxyConfig::Yaz_ProxyConfig()
85 m_cp = new Yaz_ProxyConfigP();
88 Yaz_ProxyConfig::~Yaz_ProxyConfig()
94 void Yaz_ProxyConfigP::load_modules()
99 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
102 if (ptr->type == XML_ELEMENT_NODE
103 && !strcmp((const char *) ptr->name, "module")
104 && (fname = get_text(ptr)))
106 m_modules.add_module(fname);
112 int Yaz_ProxyConfig::read_xml(const char *fname)
115 xmlDocPtr ndoc = xmlParseFile(fname);
119 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
120 return -1; // no good
122 int noSubstitutions = xmlXIncludeProcess(ndoc);
123 if (noSubstitutions == -1)
124 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
126 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
127 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
128 strcmp((const char *) proxyPtr->name, "proxy"))
130 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
134 m_cp->m_proxyPtr = proxyPtr;
136 // OK: release previous and make it the current one.
138 xmlFreeDoc(m_cp->m_docPtr);
139 m_cp->m_docPtr = ndoc;
141 m_cp->m_modules.unload_modules();
142 m_cp->load_modules();
150 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
152 for(ptr = ptr->children; ptr; ptr = ptr->next)
153 if (ptr->type == XML_TEXT_NODE)
155 xmlChar *t = ptr->content;
160 return (const char *) t;
168 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
173 for (ptr = ptr->children; ptr; ptr = ptr->next)
175 if (ptr->type == XML_ELEMENT_NODE
176 && !strcmp((const char *) ptr->name, "bandwidth"))
178 const char *t = get_text(ptr);
182 if (ptr->type == XML_ELEMENT_NODE
183 && !strcmp((const char *) ptr->name, "retrieve"))
185 const char *t = get_text(ptr);
187 *limit_req = atoi(t);
189 if (ptr->type == XML_ELEMENT_NODE
190 && !strcmp((const char *) ptr->name, "pdu"))
192 const char *t = get_text(ptr);
194 *limit_pdu = atoi(t);
201 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
206 int *target_idletime,
207 int *client_idletime,
208 int *keepalive_limit_bw,
209 int *keepalive_limit_pdu,
211 const char **cql2rpn,
212 const char **negotiation_charset,
213 const char **negotiation_lang,
214 const char **target_charset)
219 for (; ptr; ptr = ptr->next)
221 if (ptr->type == XML_ELEMENT_NODE
222 && !strcmp((const char *) ptr->name, "preinit"))
224 const char *v = get_text(ptr);
225 *pre_init = v ? atoi(v) : 1;
227 if (ptr->type == XML_ELEMENT_NODE
228 && !strcmp((const char *) ptr->name, "url"))
230 const char *t = get_text(ptr);
231 if (t && no_url < MAX_ZURL_PLEX)
237 if (ptr->type == XML_ELEMENT_NODE
238 && !strcmp((const char *) ptr->name, "keepalive"))
241 *keepalive_limit_bw = 500000;
242 *keepalive_limit_pdu = 1000;
243 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
246 if (ptr->type == XML_ELEMENT_NODE
247 && !strcmp((const char *) ptr->name, "limit"))
248 return_limit(ptr, limit_bw, limit_pdu, limit_req);
249 if (ptr->type == XML_ELEMENT_NODE
250 && !strcmp((const char *) ptr->name, "target-timeout"))
252 const char *t = get_text(ptr);
255 *target_idletime = atoi(t);
256 if (*target_idletime < 0)
257 *target_idletime = 0;
260 if (ptr->type == XML_ELEMENT_NODE
261 && !strcmp((const char *) ptr->name, "client-timeout"))
263 const char *t = get_text(ptr);
266 *client_idletime = atoi(t);
267 if (*client_idletime < 0)
268 *client_idletime = 0;
271 if (ptr->type == XML_ELEMENT_NODE
272 && !strcmp((const char *) ptr->name, "cql2rpn"))
274 const char *t = get_text(ptr);
278 if (ptr->type == XML_ELEMENT_NODE
279 && !strcmp((const char *) ptr->name, "target-charset"))
281 const char *t = get_text(ptr);
282 if (t && target_charset)
285 if (ptr->type == XML_ELEMENT_NODE
286 && !strcmp((const char *) ptr->name, "negotiation-charset"))
288 const char *t = get_text(ptr);
290 *negotiation_charset = t;
292 if (ptr->type == XML_ELEMENT_NODE
293 && !strcmp((const char *) ptr->name, "negotiation-lang"))
295 const char *t = get_text(ptr);
297 *negotiation_lang = t;
303 int Yaz_ProxyConfigP::atoi_l(const char **cp)
306 while (**cp && isdigit(**cp))
308 v = v*10 + (**cp - '0');
314 int Yaz_ProxyConfigP::match_list(int v, const char *m)
318 while(*m && isspace(*m))
329 if (v >= l && v <= h)
338 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
339 Z_AttributeList *attrs,
343 for (i = 0; i<attrs->num_attributes; i++)
345 Z_AttributeElement *el = attrs->attributes[i];
347 if (!el->attributeType)
349 int type = *el->attributeType;
352 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
353 value = el->value.numeric;
356 for(ptr = ptrl->children; ptr; ptr = ptr->next)
358 if (ptr->type == XML_ELEMENT_NODE &&
359 !strcmp((const char *) ptr->name, "attribute"))
361 const char *match_type = 0;
362 const char *match_value = 0;
363 const char *match_error = 0;
364 struct _xmlAttr *attr;
365 for (attr = ptr->properties; attr; attr = attr->next)
367 if (!strcmp((const char *) attr->name, "type") &&
368 attr->children && attr->children->type == XML_TEXT_NODE)
369 match_type = (const char *) attr->children->content;
370 if (!strcmp((const char *) attr->name, "value") &&
371 attr->children && attr->children->type == XML_TEXT_NODE)
372 match_value = (const char *) attr->children->content;
373 if (!strcmp((const char *) attr->name, "error") &&
374 attr->children && attr->children->type == XML_TEXT_NODE)
375 match_error = (const char *) attr->children->content;
377 if (match_type && match_value)
379 char addinfo_str[20];
380 if (!match_list(type, match_type))
384 if (!strcmp(match_type, "*"))
385 sprintf (addinfo_str, "%d", type);
388 if (!match_list(*value, match_value))
390 sprintf (addinfo_str, "%d", *value);
398 *addinfo = odr_strdup(odr, addinfo_str);
399 return atoi(match_error);
411 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
415 if (q->which == Z_RPNStructure_complex)
417 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
420 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
423 else if (q->which == Z_RPNStructure_simple)
425 if (q->u.simple->which == Z_Operand_APT)
427 return check_type_1_attributes(
428 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
437 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
440 // possibly check for Bib-1
441 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
445 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
451 ptr = m_cp->find_target_node(name, 0);
454 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
455 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
462 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
463 const char *schema_identifier)
466 int default_match = 1;
467 if (comp && comp->which == Z_RecordComp_simple &&
468 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
470 esn = comp->u.simple->u.generic;
472 // if no ESN/schema was given accept..
475 // check if schema identifier match
476 if (schema_identifier && !strcmp(esn, schema_identifier))
478 // Check each name element
479 for (; ptr; ptr = ptr->next)
481 if (ptr->type == XML_ELEMENT_NODE
482 && !strcmp((const char *) ptr->name, "name"))
484 xmlNodePtr tptr = ptr->children;
486 for (; tptr; tptr = tptr->next)
487 if (tptr->type == XML_TEXT_NODE && tptr->content)
489 xmlChar *t = tptr->content;
490 while (*t && isspace(*t))
493 while (esn[i] && esn[i] == t[i])
495 if (!esn[i] && (!t[i] || isspace(t[i])))
500 return default_match;
504 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
510 {".xml", "text/xml"},
511 {".xsl", "text/xml"},
512 {".tkl", "text/xml"},
513 {".xsd", "text/xml"},
514 {".html", "text/html"},
515 {".jpg", "image/jpeg"},
516 {".png", "image/png"},
517 {".gif", "image/gif"},
522 size_t plen = strlen (path);
523 for (i = 0; types[i].type; i++)
524 if (types[i].mask == 0)
525 return types[i].type;
528 size_t mlen = strlen(types[i].mask);
529 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
530 return types[i].type;
532 return "application/octet-stream";
536 void Yaz_ProxyConfig::target_authentication(const char *name,
537 ODR odr, Z_InitRequest *req)
540 xmlNodePtr ptr = m_cp->find_target_node(name, 0);
544 for (ptr = ptr->children; ptr; ptr = ptr->next)
545 if (ptr->type == XML_ELEMENT_NODE &&
546 !strcmp((const char *) ptr->name, "target-authentication"))
548 struct _xmlAttr *attr;
549 const char *type = "open";
550 for (attr = ptr->properties; attr; attr = attr->next)
552 if (!strcmp((const char *) attr->name, "type") &&
553 attr->children && attr->children->type == XML_TEXT_NODE)
554 type = (const char *) attr->children->content;
556 const char *t = m_cp->get_text(ptr);
557 if (!t || !strcmp(type, "none"))
558 req->idAuthentication = 0;
559 else if (!strcmp(type, "anonymous"))
561 req->idAuthentication =
562 (Z_IdAuthentication *)
563 odr_malloc (odr, sizeof(*req->idAuthentication));
564 req->idAuthentication->which =
565 Z_IdAuthentication_anonymous;
566 req->idAuthentication->u.anonymous = odr_nullval();
568 else if (!strcmp(type, "open"))
570 req->idAuthentication =
571 (Z_IdAuthentication *)
572 odr_malloc (odr, sizeof(*req->idAuthentication));
573 req->idAuthentication->which =
574 Z_IdAuthentication_open;
575 req->idAuthentication->u.open = odr_strdup (odr, t);
577 else if (!strcmp(type, "idPass"))
579 char user[64], group[64], password[64];
583 sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
585 req->idAuthentication =
586 (Z_IdAuthentication *)
587 odr_malloc (odr, sizeof(*req->idAuthentication));
588 req->idAuthentication->which =
589 Z_IdAuthentication_idPass;
590 req->idAuthentication->u.idPass =
591 (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
592 req->idAuthentication->u.idPass->userId =
593 *user ? odr_strdup(odr, user) : 0;
594 req->idAuthentication->u.idPass->groupId =
595 *group ? odr_strdup(odr, group) : 0;
596 req->idAuthentication->u.idPass->password =
597 *password ? odr_strdup(odr, password) : 0;
603 int Yaz_ProxyConfig::client_authentication(const char *name,
606 const char *password)
608 int ret = YAZPROXY_RET_NOT_ME;
611 ptr = m_cp->find_target_node(name, 0);
614 for (ptr = ptr->children; ptr; ptr = ptr->next)
615 if (ptr->type == XML_ELEMENT_NODE &&
616 !strcmp((const char *) ptr->name, "client-authentication"))
618 struct _xmlAttr *attr;
619 const char *module_name = 0;
620 for (attr = ptr->properties; attr; attr = attr->next)
622 if (!strcmp((const char *) attr->name, "module") &&
623 attr->children && attr->children->type == XML_TEXT_NODE)
624 module_name = (const char *) attr->children->content;
626 ret = m_cp->m_modules.authenticate(module_name,
628 user, group, password);
629 if (ret != YAZPROXY_RET_NOT_ME)
633 if (ret == YAZPROXY_RET_PERM)
638 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
639 Odr_oid *syntax, Z_RecordComposition *comp,
641 char **stylesheet, char **schema,
643 char **backend_charset,
644 char **usemarcon_ini_stage1,
645 char **usemarcon_ini_stage2
660 xfree (*backend_type);
665 xfree (*backend_charset);
666 *backend_charset = 0;
668 if (usemarcon_ini_stage1)
670 xfree (*usemarcon_ini_stage1);
671 *usemarcon_ini_stage1 = 0;
673 if (usemarcon_ini_stage2)
675 xfree (*usemarcon_ini_stage2);
676 *usemarcon_ini_stage2 = 0;
679 int syntax_has_matched = 0;
682 ptr = m_cp->find_target_node(name, 0);
685 for(ptr = ptr->children; ptr; ptr = ptr->next)
687 if (ptr->type == XML_ELEMENT_NODE &&
688 !strcmp((const char *) ptr->name, "syntax"))
690 int match = 0; // if we match record syntax
691 const char *match_type = 0;
692 const char *match_error = 0;
693 const char *match_marcxml = 0;
694 const char *match_stylesheet = 0;
695 const char *match_identifier = 0;
696 const char *match_backend_type = 0;
697 const char *match_backend_charset = 0;
698 const char *match_usemarcon_ini_stage1 = 0;
699 const char *match_usemarcon_ini_stage2 = 0;
700 struct _xmlAttr *attr;
701 for (attr = ptr->properties; attr; attr = attr->next)
703 if (!strcmp((const char *) attr->name, "type") &&
704 attr->children && attr->children->type == XML_TEXT_NODE)
705 match_type = (const char *) attr->children->content;
706 if (!strcmp((const char *) attr->name, "error") &&
707 attr->children && attr->children->type == XML_TEXT_NODE)
708 match_error = (const char *) attr->children->content;
709 if (!strcmp((const char *) attr->name, "marcxml") &&
710 attr->children && attr->children->type == XML_TEXT_NODE)
711 match_marcxml = (const char *) attr->children->content;
712 if (!strcmp((const char *) attr->name, "stylesheet") &&
713 attr->children && attr->children->type == XML_TEXT_NODE)
714 match_stylesheet = (const char *) attr->children->content;
715 if (!strcmp((const char *) attr->name, "identifier") &&
716 attr->children && attr->children->type == XML_TEXT_NODE)
717 match_identifier = (const char *) attr->children->content;
718 if (!strcmp((const char *) attr->name, "backendtype") &&
719 attr->children && attr->children->type == XML_TEXT_NODE)
720 match_backend_type = (const char *)
721 attr->children->content;
722 if (!strcmp((const char *) attr->name, "backendcharset") &&
723 attr->children && attr->children->type == XML_TEXT_NODE)
724 match_backend_charset = (const char *)
725 attr->children->content;
726 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
727 attr->children && attr->children->type == XML_TEXT_NODE)
728 match_usemarcon_ini_stage1 = (const char *)
729 attr->children->content;
730 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
731 attr->children && attr->children->type == XML_TEXT_NODE)
732 match_usemarcon_ini_stage2 = (const char *)
733 attr->children->content;
737 if (!strcmp(match_type, "*"))
739 else if (!strcmp(match_type, "none"))
746 int match_oid[OID_SIZE];
747 oid_name_to_oid(CLASS_RECSYN, match_type, match_oid);
748 if (oid_oidcmp(match_oid, syntax) == 0)
755 syntax_has_matched = 1;
756 match = m_cp->check_schema(ptr->children, comp,
761 if (stylesheet && match_stylesheet)
764 *stylesheet = xstrdup(match_stylesheet);
766 if (schema && match_identifier)
769 *schema = xstrdup(match_identifier);
771 if (backend_type && match_backend_type)
773 xfree(*backend_type);
774 *backend_type = xstrdup(match_backend_type);
776 if (backend_charset && match_backend_charset)
778 xfree(*backend_charset);
779 *backend_charset = xstrdup(match_backend_charset);
781 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
783 xfree(*usemarcon_ini_stage1);
784 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
786 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
788 xfree(*usemarcon_ini_stage2);
789 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
797 if (syntax_has_matched) // if syntax OK, bad schema/ESN
801 char dotoid_str[100];
802 oid_to_dotstring(syntax, dotoid_str);
803 *addinfo = odr_strdup(odr, dotoid_str);
805 return atoi(match_error);
816 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
823 for (dptr = ptr->children; dptr; dptr = dptr->next)
824 if (dptr->type == XML_ELEMENT_NODE &&
825 !strcmp((const char *) dptr->name, "database"))
827 struct _xmlAttr *attr;
828 for (attr = dptr->properties; attr; attr = attr->next)
829 if (!strcmp((const char *) attr->name, "name"))
832 && attr->children->type==XML_TEXT_NODE
833 && attr->children->content
834 && (!strcmp((const char *) attr->children->content, db)
835 || !strcmp((const char *) attr->children->content,
843 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
848 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
850 if (ptr->type == XML_ELEMENT_NODE &&
851 !strcmp((const char *) ptr->name, "target"))
856 // <target default="1"> ?
857 struct _xmlAttr *attr;
858 for (attr = ptr->properties; attr; attr = attr->next)
859 if (!strcmp((const char *) attr->name, "default") &&
860 attr->children && attr->children->type == XML_TEXT_NODE)
862 xmlChar *t = attr->children->content;
865 return find_target_db(ptr, db);
871 // <target name="name"> ?
872 struct _xmlAttr *attr;
873 for (attr = ptr->properties; attr; attr = attr->next)
874 if (!strcmp((const char *) attr->name, "name"))
877 && attr->children->type==XML_TEXT_NODE
878 && attr->children->content
879 && (!strcmp((const char *) attr->children->content,
881 || !strcmp((const char *) attr->children->content,
884 return find_target_db(ptr, db);
894 int Yaz_ProxyConfig::get_target_no(int no,
900 int *target_idletime,
901 int *client_idletime,
903 int *keepalive_limit_bw,
904 int *keepalive_limit_pdu,
906 const char **cql2rpn,
907 const char **authentication,
908 const char **negotiation_charset,
909 const char **negotiation_lang,
910 const char **target_charset)
914 if (!m_cp->m_proxyPtr)
917 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
918 if (ptr->type == XML_ELEMENT_NODE &&
919 !strcmp((const char *) ptr->name, "target"))
923 struct _xmlAttr *attr;
924 for (attr = ptr->properties; attr; attr = attr->next)
925 if (!strcmp((const char *) attr->name, "name"))
928 && attr->children->type==XML_TEXT_NODE
929 && attr->children->content)
930 *name = (const char *) attr->children->content;
932 m_cp->return_target_info(
934 limit_bw, limit_pdu, limit_req,
935 target_idletime, client_idletime,
936 keepalive_limit_bw, keepalive_limit_pdu,
938 negotiation_charset, negotiation_lang, target_charset);
947 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
949 if (len == strlen(item) && memcmp(hay, item, len) == 0)
954 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
959 if (!m_cp->m_proxyPtr)
961 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
963 if (ptr->type == XML_ELEMENT_NODE
964 && !strcmp((const char *) ptr->name, "log"))
966 const char *v = m_cp->get_text(ptr);
971 while (*cp && *cp != ',' && !isspace(*cp))
974 if (m_cp->mycmp(v, "client-apdu", len))
975 *log_mask |= PROXY_LOG_APDU_CLIENT;
976 if (m_cp->mycmp(v, "server-apdu", len))
977 *log_mask |= PROXY_LOG_APDU_SERVER;
978 if (m_cp->mycmp(v, "client-requests", len))
979 *log_mask |= PROXY_LOG_REQ_CLIENT;
980 if (m_cp->mycmp(v, "server-requests", len))
981 *log_mask |= PROXY_LOG_REQ_SERVER;
983 *log_mask |= atoi(v);
986 while (*cp && isspace(*cp))
991 if (ptr->type == XML_ELEMENT_NODE &&
992 !strcmp((const char *) ptr->name, "max-clients"))
994 const char *t = m_cp->get_text(ptr);
997 *max_clients = atoi(t);
998 if (*max_clients < 1)
1007 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1008 xmlNodePtr *ptr_target,
1009 xmlNodePtr *ptr_explain)
1016 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1018 if (ptr->type == XML_ELEMENT_NODE &&
1019 !strcmp((const char *) ptr->name, "target"))
1022 xmlNodePtr ptr = (*ptr_target)->children;
1023 for (; ptr; ptr = ptr->next)
1025 if (ptr->type == XML_ELEMENT_NODE &&
1026 !strcmp((const char *) ptr->name, "explain"))
1029 xmlNodePtr ptr = (*ptr_explain)->children;
1031 for (; ptr; ptr = ptr->next)
1032 if (ptr->type == XML_ELEMENT_NODE &&
1033 !strcmp((const char *) ptr->name, "serverInfo"))
1037 for (ptr = ptr->children; ptr; ptr = ptr->next)
1038 if (ptr->type == XML_ELEMENT_NODE &&
1039 !strcmp((const char *) ptr->name, "database"))
1044 for (ptr = ptr->children; ptr; ptr = ptr->next)
1045 if (ptr->type == XML_TEXT_NODE &&
1047 !strcmp((const char *) ptr->content, db))
1060 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1061 const char **backend_db)
1064 xmlNodePtr ptr_target, ptr_explain;
1065 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1068 struct _xmlAttr *attr;
1069 const char *name = 0;
1071 for (attr = ptr_target->properties; attr; attr = attr->next)
1072 if (!strcmp((const char *) attr->name, "name")
1074 && attr->children->type==XML_TEXT_NODE
1075 && attr->children->content
1076 && attr->children->content[0])
1078 name = (const char *)attr->children->content;
1083 for (attr = ptr_target->properties; attr; attr = attr->next)
1084 if (!strcmp((const char *) attr->name, "database"))
1087 && attr->children->type==XML_TEXT_NODE
1088 && attr->children->content)
1089 *backend_db = (const char *) attr->children->content;
1098 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1099 const char *db, int *len)
1102 xmlNodePtr ptr_target, ptr_explain;
1103 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1105 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1107 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1109 xmlDocSetRootElement(doc, ptr2);
1112 xmlDocDumpMemory(doc, &buf_out, len);
1113 char *content = (char*) odr_malloc(odr, *len);
1114 memcpy(content, buf_out, *len);
1124 void Yaz_ProxyConfig::get_target_info(const char *name,
1129 int *target_idletime,
1130 int *client_idletime,
1132 int *keepalive_limit_bw,
1133 int *keepalive_limit_pdu,
1135 const char **cql2rpn,
1136 const char **negotiation_charset,
1137 const char **negotiation_lang,
1138 const char **target_charset)
1142 if (!m_cp->m_proxyPtr)
1149 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1151 if (ptr->type == XML_ELEMENT_NODE &&
1152 !strcmp((const char *) ptr->name, "max-clients"))
1154 const char *t = m_cp->get_text(ptr);
1157 *max_clients = atoi(t);
1158 if (*max_clients < 1)
1163 ptr = m_cp->find_target_node(name, 0);
1171 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1172 target_idletime, client_idletime,
1173 keepalive_limit_bw, keepalive_limit_pdu,
1175 negotiation_charset, negotiation_lang,