1 /* $Id: yaz-proxy-config.cpp,v 1.21 2005-06-21 18:46:04 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,
609 int ret = YAZPROXY_RET_NOT_ME;
612 ptr = m_cp->find_target_node(name, 0);
615 for (ptr = ptr->children; ptr; ptr = ptr->next)
616 if (ptr->type == XML_ELEMENT_NODE &&
617 !strcmp((const char *) ptr->name, "client-authentication"))
619 struct _xmlAttr *attr;
620 const char *module_name = 0;
621 for (attr = ptr->properties; attr; attr = attr->next)
623 if (!strcmp((const char *) attr->name, "module") &&
624 attr->children && attr->children->type == XML_TEXT_NODE)
625 module_name = (const char *) attr->children->content;
627 ret = m_cp->m_modules.authenticate(module_name,
629 user, group, password,
632 if (ret != YAZPROXY_RET_NOT_ME)
636 if (ret == YAZPROXY_RET_PERM)
641 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
642 Odr_oid *syntax, Z_RecordComposition *comp,
644 char **stylesheet, char **schema,
646 char **backend_charset,
647 char **usemarcon_ini_stage1,
648 char **usemarcon_ini_stage2
663 xfree (*backend_type);
668 xfree (*backend_charset);
669 *backend_charset = 0;
671 if (usemarcon_ini_stage1)
673 xfree (*usemarcon_ini_stage1);
674 *usemarcon_ini_stage1 = 0;
676 if (usemarcon_ini_stage2)
678 xfree (*usemarcon_ini_stage2);
679 *usemarcon_ini_stage2 = 0;
682 int syntax_has_matched = 0;
685 ptr = m_cp->find_target_node(name, 0);
688 for(ptr = ptr->children; ptr; ptr = ptr->next)
690 if (ptr->type == XML_ELEMENT_NODE &&
691 !strcmp((const char *) ptr->name, "syntax"))
693 int match = 0; // if we match record syntax
694 const char *match_type = 0;
695 const char *match_error = 0;
696 const char *match_marcxml = 0;
697 const char *match_stylesheet = 0;
698 const char *match_identifier = 0;
699 const char *match_backend_type = 0;
700 const char *match_backend_charset = 0;
701 const char *match_usemarcon_ini_stage1 = 0;
702 const char *match_usemarcon_ini_stage2 = 0;
703 struct _xmlAttr *attr;
704 for (attr = ptr->properties; attr; attr = attr->next)
706 if (!strcmp((const char *) attr->name, "type") &&
707 attr->children && attr->children->type == XML_TEXT_NODE)
708 match_type = (const char *) attr->children->content;
709 if (!strcmp((const char *) attr->name, "error") &&
710 attr->children && attr->children->type == XML_TEXT_NODE)
711 match_error = (const char *) attr->children->content;
712 if (!strcmp((const char *) attr->name, "marcxml") &&
713 attr->children && attr->children->type == XML_TEXT_NODE)
714 match_marcxml = (const char *) attr->children->content;
715 if (!strcmp((const char *) attr->name, "stylesheet") &&
716 attr->children && attr->children->type == XML_TEXT_NODE)
717 match_stylesheet = (const char *) attr->children->content;
718 if (!strcmp((const char *) attr->name, "identifier") &&
719 attr->children && attr->children->type == XML_TEXT_NODE)
720 match_identifier = (const char *) attr->children->content;
721 if (!strcmp((const char *) attr->name, "backendtype") &&
722 attr->children && attr->children->type == XML_TEXT_NODE)
723 match_backend_type = (const char *)
724 attr->children->content;
725 if (!strcmp((const char *) attr->name, "backendcharset") &&
726 attr->children && attr->children->type == XML_TEXT_NODE)
727 match_backend_charset = (const char *)
728 attr->children->content;
729 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
730 attr->children && attr->children->type == XML_TEXT_NODE)
731 match_usemarcon_ini_stage1 = (const char *)
732 attr->children->content;
733 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
734 attr->children && attr->children->type == XML_TEXT_NODE)
735 match_usemarcon_ini_stage2 = (const char *)
736 attr->children->content;
740 if (!strcmp(match_type, "*"))
742 else if (!strcmp(match_type, "none"))
749 int match_oid[OID_SIZE];
750 oid_name_to_oid(CLASS_RECSYN, match_type, match_oid);
751 if (oid_oidcmp(match_oid, syntax) == 0)
758 syntax_has_matched = 1;
759 match = m_cp->check_schema(ptr->children, comp,
764 if (stylesheet && match_stylesheet)
767 *stylesheet = xstrdup(match_stylesheet);
769 if (schema && match_identifier)
772 *schema = xstrdup(match_identifier);
774 if (backend_type && match_backend_type)
776 xfree(*backend_type);
777 *backend_type = xstrdup(match_backend_type);
779 if (backend_charset && match_backend_charset)
781 xfree(*backend_charset);
782 *backend_charset = xstrdup(match_backend_charset);
784 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
786 xfree(*usemarcon_ini_stage1);
787 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
789 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
791 xfree(*usemarcon_ini_stage2);
792 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
800 if (syntax_has_matched) // if syntax OK, bad schema/ESN
804 char dotoid_str[100];
805 oid_to_dotstring(syntax, dotoid_str);
806 *addinfo = odr_strdup(odr, dotoid_str);
808 return atoi(match_error);
819 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
826 for (dptr = ptr->children; dptr; dptr = dptr->next)
827 if (dptr->type == XML_ELEMENT_NODE &&
828 !strcmp((const char *) dptr->name, "database"))
830 struct _xmlAttr *attr;
831 for (attr = dptr->properties; attr; attr = attr->next)
832 if (!strcmp((const char *) attr->name, "name"))
835 && attr->children->type==XML_TEXT_NODE
836 && attr->children->content
837 && (!strcmp((const char *) attr->children->content, db)
838 || !strcmp((const char *) attr->children->content,
846 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
851 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
853 if (ptr->type == XML_ELEMENT_NODE &&
854 !strcmp((const char *) ptr->name, "target"))
859 // <target default="1"> ?
860 struct _xmlAttr *attr;
861 for (attr = ptr->properties; attr; attr = attr->next)
862 if (!strcmp((const char *) attr->name, "default") &&
863 attr->children && attr->children->type == XML_TEXT_NODE)
865 xmlChar *t = attr->children->content;
868 return find_target_db(ptr, db);
874 // <target name="name"> ?
875 struct _xmlAttr *attr;
876 for (attr = ptr->properties; attr; attr = attr->next)
877 if (!strcmp((const char *) attr->name, "name"))
880 && attr->children->type==XML_TEXT_NODE
881 && attr->children->content
882 && (!strcmp((const char *) attr->children->content,
884 || !strcmp((const char *) attr->children->content,
887 return find_target_db(ptr, db);
897 int Yaz_ProxyConfig::get_target_no(int no,
903 int *target_idletime,
904 int *client_idletime,
906 int *keepalive_limit_bw,
907 int *keepalive_limit_pdu,
909 const char **cql2rpn,
910 const char **authentication,
911 const char **negotiation_charset,
912 const char **negotiation_lang,
913 const char **target_charset)
917 if (!m_cp->m_proxyPtr)
920 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
921 if (ptr->type == XML_ELEMENT_NODE &&
922 !strcmp((const char *) ptr->name, "target"))
926 struct _xmlAttr *attr;
927 for (attr = ptr->properties; attr; attr = attr->next)
928 if (!strcmp((const char *) attr->name, "name"))
931 && attr->children->type==XML_TEXT_NODE
932 && attr->children->content)
933 *name = (const char *) attr->children->content;
935 m_cp->return_target_info(
937 limit_bw, limit_pdu, limit_req,
938 target_idletime, client_idletime,
939 keepalive_limit_bw, keepalive_limit_pdu,
941 negotiation_charset, negotiation_lang, target_charset);
950 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
952 if (len == strlen(item) && memcmp(hay, item, len) == 0)
957 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
962 if (!m_cp->m_proxyPtr)
964 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
966 if (ptr->type == XML_ELEMENT_NODE
967 && !strcmp((const char *) ptr->name, "log"))
969 const char *v = m_cp->get_text(ptr);
974 while (*cp && *cp != ',' && !isspace(*cp))
977 if (m_cp->mycmp(v, "client-apdu", len))
978 *log_mask |= PROXY_LOG_APDU_CLIENT;
979 if (m_cp->mycmp(v, "server-apdu", len))
980 *log_mask |= PROXY_LOG_APDU_SERVER;
981 if (m_cp->mycmp(v, "client-requests", len))
982 *log_mask |= PROXY_LOG_REQ_CLIENT;
983 if (m_cp->mycmp(v, "server-requests", len))
984 *log_mask |= PROXY_LOG_REQ_SERVER;
986 *log_mask |= atoi(v);
989 while (*cp && isspace(*cp))
994 if (ptr->type == XML_ELEMENT_NODE &&
995 !strcmp((const char *) ptr->name, "max-clients"))
997 const char *t = m_cp->get_text(ptr);
1000 *max_clients = atoi(t);
1001 if (*max_clients < 1)
1010 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1011 xmlNodePtr *ptr_target,
1012 xmlNodePtr *ptr_explain)
1019 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1021 if (ptr->type == XML_ELEMENT_NODE &&
1022 !strcmp((const char *) ptr->name, "target"))
1025 xmlNodePtr ptr = (*ptr_target)->children;
1026 for (; ptr; ptr = ptr->next)
1028 if (ptr->type == XML_ELEMENT_NODE &&
1029 !strcmp((const char *) ptr->name, "explain"))
1032 xmlNodePtr ptr = (*ptr_explain)->children;
1034 for (; ptr; ptr = ptr->next)
1035 if (ptr->type == XML_ELEMENT_NODE &&
1036 !strcmp((const char *) ptr->name, "serverInfo"))
1040 for (ptr = ptr->children; ptr; ptr = ptr->next)
1041 if (ptr->type == XML_ELEMENT_NODE &&
1042 !strcmp((const char *) ptr->name, "database"))
1047 for (ptr = ptr->children; ptr; ptr = ptr->next)
1048 if (ptr->type == XML_TEXT_NODE &&
1050 !strcmp((const char *) ptr->content, db))
1063 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1064 const char **backend_db)
1067 xmlNodePtr ptr_target, ptr_explain;
1068 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1071 struct _xmlAttr *attr;
1072 const char *name = 0;
1074 for (attr = ptr_target->properties; attr; attr = attr->next)
1075 if (!strcmp((const char *) attr->name, "name")
1077 && attr->children->type==XML_TEXT_NODE
1078 && attr->children->content
1079 && attr->children->content[0])
1081 name = (const char *)attr->children->content;
1086 for (attr = ptr_target->properties; attr; attr = attr->next)
1087 if (!strcmp((const char *) attr->name, "database"))
1090 && attr->children->type==XML_TEXT_NODE
1091 && attr->children->content)
1092 *backend_db = (const char *) attr->children->content;
1101 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1102 const char *db, int *len)
1105 xmlNodePtr ptr_target, ptr_explain;
1106 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1108 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1110 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1112 xmlDocSetRootElement(doc, ptr2);
1115 xmlDocDumpMemory(doc, &buf_out, len);
1116 char *content = (char*) odr_malloc(odr, *len);
1117 memcpy(content, buf_out, *len);
1127 void Yaz_ProxyConfig::get_target_info(const char *name,
1132 int *target_idletime,
1133 int *client_idletime,
1135 int *keepalive_limit_bw,
1136 int *keepalive_limit_pdu,
1138 const char **cql2rpn,
1139 const char **negotiation_charset,
1140 const char **negotiation_lang,
1141 const char **target_charset)
1145 if (!m_cp->m_proxyPtr)
1152 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1154 if (ptr->type == XML_ELEMENT_NODE &&
1155 !strcmp((const char *) ptr->name, "max-clients"))
1157 const char *t = m_cp->get_text(ptr);
1160 *max_clients = atoi(t);
1161 if (*max_clients < 1)
1166 ptr = m_cp->find_target_node(name, 0);
1174 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1175 target_idletime, client_idletime,
1176 keepalive_limit_bw, keepalive_limit_pdu,
1178 negotiation_charset, negotiation_lang,