1 /* $Id: yaz-proxy-config.cpp,v 1.16 2005-02-20 21:59:08 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
32 class Yaz_ProxyModule {
34 void *m_dl_handle; /* dlopen/close handle */
35 Yaz_ProxyModule_entry *m_entry;
36 Yaz_ProxyModule *m_next;
37 void *m_user_handle; /* user handle */
39 Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
40 Yaz_ProxyModule *next);
42 Yaz_ProxyModule *get_next() { return m_next; };
43 int authenticate(const char *user, const char *group, const char *password);
46 Yaz_ProxyModule::Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
47 Yaz_ProxyModule *next)
49 m_dl_handle = dl_handle;
53 if (m_entry->int_version == 0)
55 struct Yaz_ProxyModule_int0 *int0 =
56 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
58 m_user_handle = (*int0->init)();
62 Yaz_ProxyModule::~Yaz_ProxyModule()
64 if (m_entry->int_version == 0)
66 struct Yaz_ProxyModule_int0 *int0 =
67 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
69 (*int0->destroy)(m_user_handle);
76 int Yaz_ProxyModule::authenticate(const char *user, const char *group,
79 if (m_entry->int_version == 0)
81 struct Yaz_ProxyModule_int0 *int0 =
82 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
84 if (!int0->authenticate)
85 return YAZPROXY_RET_NOT_ME;
86 return (*int0->authenticate)(m_user_handle, user, group, password);
88 return YAZPROXY_RET_NOT_ME;
91 class Yaz_ProxyConfigP {
92 friend class Yaz_ProxyConfig;
94 Yaz_ProxyModule *m_modules;
96 int mycmp(const char *hay, const char *item, size_t len);
97 int match_list(int v, const char *m);
98 int atoi_l(const char **cp);
100 void load_modules(void);
101 void unload_modules(void);
102 int check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
103 const char *schema_identifier);
105 xmlNodePtr m_proxyPtr;
106 void return_target_info(xmlNodePtr ptr, const char **url,
107 int *limit_bw, int *limit_pdu, int *limit_req,
108 int *target_idletime, int *client_idletime,
109 int *keepalive_limit_bw, int *keepalive_limit_pdu,
110 int *pre_init, const char **cql2rpn,
111 const char **authentication,
112 const char **negotiation_charset,
113 const char **negotiation_lang);
114 void return_limit(xmlNodePtr ptr,
115 int *limit_bw, int *limit_pdu, int *limit_req);
116 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
118 xmlNodePtr find_target_node(const char *name, const char *db);
119 xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
120 const char *get_text(xmlNodePtr ptr);
121 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
122 Z_AttributeList *attrs,
124 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
126 int get_explain_ptr(const char *host, const char *db,
127 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
133 Yaz_ProxyConfigP::Yaz_ProxyConfigP()
142 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
146 xmlFreeDoc(m_docPtr);
150 Yaz_ProxyConfig::Yaz_ProxyConfig()
152 m_cp = new Yaz_ProxyConfigP;
155 Yaz_ProxyConfig::~Yaz_ProxyConfig()
161 void Yaz_ProxyConfigP::unload_modules()
163 yaz_log(YLOG_WARN, "unload_modules not implemented yet");
168 void Yaz_ProxyConfigP::load_modules()
173 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
176 if (ptr->type == XML_ELEMENT_NODE
177 && !strcmp((const char *) ptr->name, "module")
178 && (fname = get_text(ptr)))
181 void *dl_handle = dlopen(fname, RTLD_NOW|RTLD_GLOBAL);
184 Yaz_ProxyModule_entry *fl_ptr = 0;
185 fl_ptr = reinterpret_cast<Yaz_ProxyModule_entry *>
186 (dlsym(dl_handle, "yazproxy_module"));
189 Yaz_ProxyModule *m = new Yaz_ProxyModule(dl_handle,
193 yaz_log(YLOG_LOG, "Loading %s OK", fname);
197 yaz_log(YLOG_WARN, "Loading %s FAIL: missing yazproxy_module symbol", fname);
202 yaz_log(YLOG_WARN, "Loading %s FAIL: dlopen failed", fname);
204 yaz_log(YLOG_WARN, "Loading &s FAIL: dl unsupported", fname);
211 int Yaz_ProxyConfig::read_xml(const char *fname)
214 xmlDocPtr ndoc = xmlParseFile(fname);
218 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
219 return -1; // no good
221 int noSubstitutions = xmlXIncludeProcess(ndoc);
222 if (noSubstitutions == -1)
223 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
225 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
226 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
227 strcmp((const char *) proxyPtr->name, "proxy"))
229 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
233 m_cp->m_proxyPtr = proxyPtr;
235 // OK: release previous and make it the current one.
237 xmlFreeDoc(m_cp->m_docPtr);
238 m_cp->m_docPtr = ndoc;
240 m_cp->unload_modules();
241 m_cp->load_modules();
249 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
251 for(ptr = ptr->children; ptr; ptr = ptr->next)
252 if (ptr->type == XML_TEXT_NODE)
254 xmlChar *t = ptr->content;
259 return (const char *) t;
267 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
272 for (ptr = ptr->children; ptr; ptr = ptr->next)
274 if (ptr->type == XML_ELEMENT_NODE
275 && !strcmp((const char *) ptr->name, "bandwidth"))
277 const char *t = get_text(ptr);
281 if (ptr->type == XML_ELEMENT_NODE
282 && !strcmp((const char *) ptr->name, "retrieve"))
284 const char *t = get_text(ptr);
286 *limit_req = atoi(t);
288 if (ptr->type == XML_ELEMENT_NODE
289 && !strcmp((const char *) ptr->name, "pdu"))
291 const char *t = get_text(ptr);
293 *limit_pdu = atoi(t);
300 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
305 int *target_idletime,
306 int *client_idletime,
307 int *keepalive_limit_bw,
308 int *keepalive_limit_pdu,
310 const char **cql2rpn,
311 const char **authentication,
312 const char **negotiation_charset,
313 const char **negotiation_lang)
318 for (; ptr; ptr = ptr->next)
320 if (ptr->type == XML_ELEMENT_NODE
321 && !strcmp((const char *) ptr->name, "preinit"))
323 const char *v = get_text(ptr);
324 *pre_init = v ? atoi(v) : 1;
326 if (ptr->type == XML_ELEMENT_NODE
327 && !strcmp((const char *) ptr->name, "url"))
329 const char *t = get_text(ptr);
330 if (t && no_url < MAX_ZURL_PLEX)
336 if (ptr->type == XML_ELEMENT_NODE
337 && !strcmp((const char *) ptr->name, "keepalive"))
340 *keepalive_limit_bw = 500000;
341 *keepalive_limit_pdu = 1000;
342 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
345 if (ptr->type == XML_ELEMENT_NODE
346 && !strcmp((const char *) ptr->name, "limit"))
347 return_limit(ptr, limit_bw, limit_pdu, limit_req);
348 if (ptr->type == XML_ELEMENT_NODE
349 && !strcmp((const char *) ptr->name, "target-timeout"))
351 const char *t = get_text(ptr);
354 *target_idletime = atoi(t);
355 if (*target_idletime < 0)
356 *target_idletime = 0;
359 if (ptr->type == XML_ELEMENT_NODE
360 && !strcmp((const char *) ptr->name, "client-timeout"))
362 const char *t = get_text(ptr);
365 *client_idletime = atoi(t);
366 if (*client_idletime < 0)
367 *client_idletime = 0;
370 if (ptr->type == XML_ELEMENT_NODE
371 && !strcmp((const char *) ptr->name, "cql2rpn"))
373 const char *t = get_text(ptr);
377 if (ptr->type == XML_ELEMENT_NODE
378 && !strcmp((const char *) ptr->name, "authentication"))
380 const char *t = get_text(ptr);
384 if (ptr->type == XML_ELEMENT_NODE
385 && !strcmp((const char *) ptr->name, "negotiation-charset"))
387 const char *t = get_text(ptr);
389 *negotiation_charset = t;
391 if (ptr->type == XML_ELEMENT_NODE
392 && !strcmp((const char *) ptr->name, "negotiation-lang"))
394 const char *t = get_text(ptr);
396 *negotiation_lang = t;
402 int Yaz_ProxyConfigP::atoi_l(const char **cp)
405 while (**cp && isdigit(**cp))
407 v = v*10 + (**cp - '0');
413 int Yaz_ProxyConfigP::match_list(int v, const char *m)
417 while(*m && isspace(*m))
428 if (v >= l && v <= h)
437 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
438 Z_AttributeList *attrs,
442 for (i = 0; i<attrs->num_attributes; i++)
444 Z_AttributeElement *el = attrs->attributes[i];
446 if (!el->attributeType)
448 int type = *el->attributeType;
451 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
452 value = el->value.numeric;
455 for(ptr = ptrl->children; ptr; ptr = ptr->next)
457 if (ptr->type == XML_ELEMENT_NODE &&
458 !strcmp((const char *) ptr->name, "attribute"))
460 const char *match_type = 0;
461 const char *match_value = 0;
462 const char *match_error = 0;
463 struct _xmlAttr *attr;
464 for (attr = ptr->properties; attr; attr = attr->next)
466 if (!strcmp((const char *) attr->name, "type") &&
467 attr->children && attr->children->type == XML_TEXT_NODE)
468 match_type = (const char *) attr->children->content;
469 if (!strcmp((const char *) attr->name, "value") &&
470 attr->children && attr->children->type == XML_TEXT_NODE)
471 match_value = (const char *) attr->children->content;
472 if (!strcmp((const char *) attr->name, "error") &&
473 attr->children && attr->children->type == XML_TEXT_NODE)
474 match_error = (const char *) attr->children->content;
476 if (match_type && match_value)
478 char addinfo_str[20];
479 if (!match_list(type, match_type))
483 if (!strcmp(match_type, "*"))
484 sprintf (addinfo_str, "%d", type);
487 if (!match_list(*value, match_value))
489 sprintf (addinfo_str, "%d", *value);
497 *addinfo = odr_strdup(odr, addinfo_str);
498 return atoi(match_error);
510 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
514 if (q->which == Z_RPNStructure_complex)
516 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
519 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
522 else if (q->which == Z_RPNStructure_simple)
524 if (q->u.simple->which == Z_Operand_APT)
526 return check_type_1_attributes(
527 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
536 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
539 // possibly check for Bib-1
540 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
544 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
550 ptr = m_cp->find_target_node(name, 0);
553 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
554 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
561 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
562 const char *schema_identifier)
565 int default_match = 1;
566 if (comp && comp->which == Z_RecordComp_simple &&
567 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
569 esn = comp->u.simple->u.generic;
571 // if no ESN/schema was given accept..
574 // check if schema identifier match
575 if (schema_identifier && !strcmp(esn, schema_identifier))
577 // Check each name element
578 for (; ptr; ptr = ptr->next)
580 if (ptr->type == XML_ELEMENT_NODE
581 && !strcmp((const char *) ptr->name, "name"))
583 xmlNodePtr tptr = ptr->children;
585 for (; tptr; tptr = tptr->next)
586 if (tptr->type == XML_TEXT_NODE && tptr->content)
588 xmlChar *t = tptr->content;
589 while (*t && isspace(*t))
592 while (esn[i] && esn[i] == t[i])
594 if (!esn[i] && (!t[i] || isspace(t[i])))
599 return default_match;
603 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
609 {".xml", "text/xml"},
610 {".xsl", "text/xml"},
611 {".tkl", "text/xml"},
612 {".xsd", "text/xml"},
613 {".html", "text/html"},
614 {".jpg", "image/jpeg"},
615 {".png", "image/png"},
616 {".gif", "image/gif"},
621 size_t plen = strlen (path);
622 for (i = 0; types[i].type; i++)
623 if (types[i].mask == 0)
624 return types[i].type;
627 size_t mlen = strlen(types[i].mask);
628 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
629 return types[i].type;
631 return "application/octet-stream";
635 int Yaz_ProxyConfig::check_authentication(const char *user,
637 const char *password)
639 Yaz_ProxyModule *m = m_cp->m_modules;
641 int ret = YAZPROXY_RET_NOT_ME;
642 for (; m; m = m->get_next())
644 ret = m->authenticate(user, group, password);
645 if (ret != YAZPROXY_RET_NOT_ME)
648 if (ret == YAZPROXY_RET_PERM)
653 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
654 Odr_oid *syntax, Z_RecordComposition *comp,
656 char **stylesheet, char **schema,
658 char **backend_charset,
659 char **usemarcon_ini_stage1,
660 char **usemarcon_ini_stage2
675 xfree (*backend_type);
680 xfree (*backend_charset);
681 *backend_charset = 0;
683 if (usemarcon_ini_stage1)
685 xfree (*usemarcon_ini_stage1);
686 *usemarcon_ini_stage1 = 0;
688 if (usemarcon_ini_stage2)
690 xfree (*usemarcon_ini_stage2);
691 *usemarcon_ini_stage2 = 0;
694 int syntax_has_matched = 0;
697 ptr = m_cp->find_target_node(name, 0);
700 for(ptr = ptr->children; ptr; ptr = ptr->next)
702 if (ptr->type == XML_ELEMENT_NODE &&
703 !strcmp((const char *) ptr->name, "syntax"))
705 int match = 0; // if we match record syntax
706 const char *match_type = 0;
707 const char *match_error = 0;
708 const char *match_marcxml = 0;
709 const char *match_stylesheet = 0;
710 const char *match_identifier = 0;
711 const char *match_backend_type = 0;
712 const char *match_backend_charset = 0;
713 const char *match_usemarcon_ini_stage1 = 0;
714 const char *match_usemarcon_ini_stage2 = 0;
715 struct _xmlAttr *attr;
716 for (attr = ptr->properties; attr; attr = attr->next)
718 if (!strcmp((const char *) attr->name, "type") &&
719 attr->children && attr->children->type == XML_TEXT_NODE)
720 match_type = (const char *) attr->children->content;
721 if (!strcmp((const char *) attr->name, "error") &&
722 attr->children && attr->children->type == XML_TEXT_NODE)
723 match_error = (const char *) attr->children->content;
724 if (!strcmp((const char *) attr->name, "marcxml") &&
725 attr->children && attr->children->type == XML_TEXT_NODE)
726 match_marcxml = (const char *) attr->children->content;
727 if (!strcmp((const char *) attr->name, "stylesheet") &&
728 attr->children && attr->children->type == XML_TEXT_NODE)
729 match_stylesheet = (const char *) attr->children->content;
730 if (!strcmp((const char *) attr->name, "identifier") &&
731 attr->children && attr->children->type == XML_TEXT_NODE)
732 match_identifier = (const char *) attr->children->content;
733 if (!strcmp((const char *) attr->name, "backendtype") &&
734 attr->children && attr->children->type == XML_TEXT_NODE)
735 match_backend_type = (const char *)
736 attr->children->content;
737 if (!strcmp((const char *) attr->name, "backendcharset") &&
738 attr->children && attr->children->type == XML_TEXT_NODE)
739 match_backend_charset = (const char *)
740 attr->children->content;
741 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
742 attr->children && attr->children->type == XML_TEXT_NODE)
743 match_usemarcon_ini_stage1 = (const char *)
744 attr->children->content;
745 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
746 attr->children && attr->children->type == XML_TEXT_NODE)
747 match_usemarcon_ini_stage2 = (const char *)
748 attr->children->content;
752 if (!strcmp(match_type, "*"))
754 else if (!strcmp(match_type, "none"))
761 int match_oid[OID_SIZE];
762 oid_name_to_oid(CLASS_RECSYN, match_type, match_oid);
763 if (oid_oidcmp(match_oid, syntax) == 0)
770 syntax_has_matched = 1;
771 match = m_cp->check_schema(ptr->children, comp,
776 if (stylesheet && match_stylesheet)
779 *stylesheet = xstrdup(match_stylesheet);
781 if (schema && match_identifier)
784 *schema = xstrdup(match_identifier);
786 if (backend_type && match_backend_type)
788 xfree(*backend_type);
789 *backend_type = xstrdup(match_backend_type);
791 if (backend_charset && match_backend_charset)
793 xfree(*backend_charset);
794 *backend_charset = xstrdup(match_backend_charset);
796 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
798 xfree(*usemarcon_ini_stage1);
799 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
801 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
803 xfree(*usemarcon_ini_stage2);
804 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
812 if (syntax_has_matched) // if syntax OK, bad schema/ESN
816 char dotoid_str[100];
817 oid_to_dotstring(syntax, dotoid_str);
818 *addinfo = odr_strdup(odr, dotoid_str);
820 return atoi(match_error);
831 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
838 for (dptr = ptr->children; dptr; dptr = dptr->next)
839 if (dptr->type == XML_ELEMENT_NODE &&
840 !strcmp((const char *) dptr->name, "database"))
842 struct _xmlAttr *attr;
843 for (attr = dptr->properties; attr; attr = attr->next)
844 if (!strcmp((const char *) attr->name, "name"))
847 && attr->children->type==XML_TEXT_NODE
848 && attr->children->content
849 && (!strcmp((const char *) attr->children->content, db)
850 || !strcmp((const char *) attr->children->content,
858 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
863 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
865 if (ptr->type == XML_ELEMENT_NODE &&
866 !strcmp((const char *) ptr->name, "target"))
871 // <target default="1"> ?
872 struct _xmlAttr *attr;
873 for (attr = ptr->properties; attr; attr = attr->next)
874 if (!strcmp((const char *) attr->name, "default") &&
875 attr->children && attr->children->type == XML_TEXT_NODE)
877 xmlChar *t = attr->children->content;
880 return find_target_db(ptr, db);
886 // <target name="name"> ?
887 struct _xmlAttr *attr;
888 for (attr = ptr->properties; attr; attr = attr->next)
889 if (!strcmp((const char *) attr->name, "name"))
892 && attr->children->type==XML_TEXT_NODE
893 && attr->children->content
894 && (!strcmp((const char *) attr->children->content,
896 || !strcmp((const char *) attr->children->content,
899 return find_target_db(ptr, db);
909 int Yaz_ProxyConfig::get_target_no(int no,
915 int *target_idletime,
916 int *client_idletime,
918 int *keepalive_limit_bw,
919 int *keepalive_limit_pdu,
921 const char **cql2rpn,
922 const char **authentication,
923 const char **negotiation_charset,
924 const char **negotiation_lang)
928 if (!m_cp->m_proxyPtr)
931 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
932 if (ptr->type == XML_ELEMENT_NODE &&
933 !strcmp((const char *) ptr->name, "target"))
937 struct _xmlAttr *attr;
938 for (attr = ptr->properties; attr; attr = attr->next)
939 if (!strcmp((const char *) attr->name, "name"))
942 && attr->children->type==XML_TEXT_NODE
943 && attr->children->content)
944 *name = (const char *) attr->children->content;
946 m_cp->return_target_info(
948 limit_bw, limit_pdu, limit_req,
949 target_idletime, client_idletime,
950 keepalive_limit_bw, keepalive_limit_pdu,
951 pre_init, cql2rpn, authentication,
952 negotiation_charset, negotiation_lang);
961 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
963 if (len == strlen(item) && memcmp(hay, item, len) == 0)
968 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
973 if (!m_cp->m_proxyPtr)
975 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
977 if (ptr->type == XML_ELEMENT_NODE
978 && !strcmp((const char *) ptr->name, "log"))
980 const char *v = m_cp->get_text(ptr);
985 while (*cp && *cp != ',' && !isspace(*cp))
988 if (m_cp->mycmp(v, "client-apdu", len))
989 *log_mask |= PROXY_LOG_APDU_CLIENT;
990 if (m_cp->mycmp(v, "server-apdu", len))
991 *log_mask |= PROXY_LOG_APDU_SERVER;
992 if (m_cp->mycmp(v, "client-requests", len))
993 *log_mask |= PROXY_LOG_REQ_CLIENT;
994 if (m_cp->mycmp(v, "server-requests", len))
995 *log_mask |= PROXY_LOG_REQ_SERVER;
997 *log_mask |= atoi(v);
1000 while (*cp && isspace(*cp))
1005 if (ptr->type == XML_ELEMENT_NODE &&
1006 !strcmp((const char *) ptr->name, "max-clients"))
1008 const char *t = m_cp->get_text(ptr);
1011 *max_clients = atoi(t);
1012 if (*max_clients < 1)
1021 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1022 xmlNodePtr *ptr_target,
1023 xmlNodePtr *ptr_explain)
1030 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1032 if (ptr->type == XML_ELEMENT_NODE &&
1033 !strcmp((const char *) ptr->name, "target"))
1036 xmlNodePtr ptr = (*ptr_target)->children;
1037 for (; ptr; ptr = ptr->next)
1039 if (ptr->type == XML_ELEMENT_NODE &&
1040 !strcmp((const char *) ptr->name, "explain"))
1043 xmlNodePtr ptr = (*ptr_explain)->children;
1045 for (; ptr; ptr = ptr->next)
1046 if (ptr->type == XML_ELEMENT_NODE &&
1047 !strcmp((const char *) ptr->name, "serverInfo"))
1051 for (ptr = ptr->children; ptr; ptr = ptr->next)
1052 if (ptr->type == XML_ELEMENT_NODE &&
1053 !strcmp((const char *) ptr->name, "database"))
1058 for (ptr = ptr->children; ptr; ptr = ptr->next)
1059 if (ptr->type == XML_TEXT_NODE &&
1061 !strcmp((const char *) ptr->content, db))
1074 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1075 const char **backend_db)
1078 xmlNodePtr ptr_target, ptr_explain;
1079 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1082 struct _xmlAttr *attr;
1083 const char *name = 0;
1085 for (attr = ptr_target->properties; attr; attr = attr->next)
1086 if (!strcmp((const char *) attr->name, "name")
1088 && attr->children->type==XML_TEXT_NODE
1089 && attr->children->content
1090 && attr->children->content[0])
1092 name = (const char *)attr->children->content;
1097 for (attr = ptr_target->properties; attr; attr = attr->next)
1098 if (!strcmp((const char *) attr->name, "database"))
1101 && attr->children->type==XML_TEXT_NODE
1102 && attr->children->content)
1103 *backend_db = (const char *) attr->children->content;
1112 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1113 const char *db, int *len)
1116 xmlNodePtr ptr_target, ptr_explain;
1117 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1119 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1121 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1123 xmlDocSetRootElement(doc, ptr2);
1126 xmlDocDumpMemory(doc, &buf_out, len);
1127 char *content = (char*) odr_malloc(odr, *len);
1128 memcpy(content, buf_out, *len);
1138 void Yaz_ProxyConfig::get_target_info(const char *name,
1143 int *target_idletime,
1144 int *client_idletime,
1146 int *keepalive_limit_bw,
1147 int *keepalive_limit_pdu,
1149 const char **cql2rpn,
1150 const char **authentication,
1151 const char **negotiation_charset,
1152 const char **negotiation_lang)
1156 if (!m_cp->m_proxyPtr)
1163 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1165 if (ptr->type == XML_ELEMENT_NODE &&
1166 !strcmp((const char *) ptr->name, "max-clients"))
1168 const char *t = m_cp->get_text(ptr);
1171 *max_clients = atoi(t);
1172 if (*max_clients < 1)
1177 ptr = m_cp->find_target_node(name, 0);
1185 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1186 target_idletime, client_idletime,
1187 keepalive_limit_bw, keepalive_limit_pdu,
1188 pre_init, cql2rpn, authentication,
1189 negotiation_charset, negotiation_lang);