1 /* $Id: yaz-proxy-config.cpp,v 1.15 2005-02-11 15:19: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);
74 int Yaz_ProxyModule::authenticate(const char *user, const char *group,
77 if (m_entry->int_version == 0)
79 struct Yaz_ProxyModule_int0 *int0 =
80 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
82 if (!int0->authenticate)
83 return YAZPROXY_RET_NOT_ME;
84 return (*int0->authenticate)(m_user_handle, user, group, password);
86 return YAZPROXY_RET_NOT_ME;
89 class Yaz_ProxyConfigP {
90 friend class Yaz_ProxyConfig;
92 Yaz_ProxyModule *m_modules;
94 int mycmp(const char *hay, const char *item, size_t len);
95 int match_list(int v, const char *m);
96 int atoi_l(const char **cp);
98 void load_modules(void);
99 void unload_modules(void);
100 int check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
101 const char *schema_identifier);
103 xmlNodePtr m_proxyPtr;
104 void return_target_info(xmlNodePtr ptr, const char **url,
105 int *limit_bw, int *limit_pdu, int *limit_req,
106 int *target_idletime, int *client_idletime,
107 int *keepalive_limit_bw, int *keepalive_limit_pdu,
108 int *pre_init, const char **cql2rpn,
109 const char **authentication,
110 const char **negotiation_charset,
111 const char **negotiation_lang);
112 void return_limit(xmlNodePtr ptr,
113 int *limit_bw, int *limit_pdu, int *limit_req);
114 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
116 xmlNodePtr find_target_node(const char *name, const char *db);
117 xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
118 const char *get_text(xmlNodePtr ptr);
119 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
120 Z_AttributeList *attrs,
122 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
124 int get_explain_ptr(const char *host, const char *db,
125 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
131 Yaz_ProxyConfigP::Yaz_ProxyConfigP()
140 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
144 xmlFreeDoc(m_docPtr);
148 Yaz_ProxyConfig::Yaz_ProxyConfig()
150 m_cp = new Yaz_ProxyConfigP;
153 Yaz_ProxyConfig::~Yaz_ProxyConfig()
159 void Yaz_ProxyConfigP::unload_modules()
161 yaz_log(YLOG_WARN, "unload_modules not implemented yet");
166 void Yaz_ProxyConfigP::load_modules()
171 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
174 if (ptr->type == XML_ELEMENT_NODE
175 && !strcmp((const char *) ptr->name, "module")
176 && (fname = get_text(ptr)))
179 void *dl_handle = dlopen(fname, RTLD_NOW|RTLD_GLOBAL);
182 Yaz_ProxyModule_entry *fl_ptr = 0;
183 fl_ptr = reinterpret_cast<Yaz_ProxyModule_entry *>
184 (dlsym(dl_handle, "yazproxy_module"));
187 Yaz_ProxyModule *m = new Yaz_ProxyModule(dl_handle,
191 yaz_log(YLOG_LOG, "Loading %s OK", fname);
195 yaz_log(YLOG_WARN, "Loading %s FAIL: missing yazproxy_module symbol", fname);
200 yaz_log(YLOG_WARN, "Loading %s FAIL: dlopen failed", fname);
202 yaz_log(YLOG_WARN, "Loading &s FAIL: dl unsupported", fname);
209 int Yaz_ProxyConfig::read_xml(const char *fname)
212 xmlDocPtr ndoc = xmlParseFile(fname);
216 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
217 return -1; // no good
219 int noSubstitutions = xmlXIncludeProcess(ndoc);
220 if (noSubstitutions == -1)
221 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
223 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
224 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
225 strcmp((const char *) proxyPtr->name, "proxy"))
227 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
231 m_cp->m_proxyPtr = proxyPtr;
233 // OK: release previous and make it the current one.
235 xmlFreeDoc(m_cp->m_docPtr);
236 m_cp->m_docPtr = ndoc;
238 m_cp->unload_modules();
239 m_cp->load_modules();
247 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
249 for(ptr = ptr->children; ptr; ptr = ptr->next)
250 if (ptr->type == XML_TEXT_NODE)
252 xmlChar *t = ptr->content;
257 return (const char *) t;
265 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
270 for (ptr = ptr->children; ptr; ptr = ptr->next)
272 if (ptr->type == XML_ELEMENT_NODE
273 && !strcmp((const char *) ptr->name, "bandwidth"))
275 const char *t = get_text(ptr);
279 if (ptr->type == XML_ELEMENT_NODE
280 && !strcmp((const char *) ptr->name, "retrieve"))
282 const char *t = get_text(ptr);
284 *limit_req = atoi(t);
286 if (ptr->type == XML_ELEMENT_NODE
287 && !strcmp((const char *) ptr->name, "pdu"))
289 const char *t = get_text(ptr);
291 *limit_pdu = atoi(t);
298 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
303 int *target_idletime,
304 int *client_idletime,
305 int *keepalive_limit_bw,
306 int *keepalive_limit_pdu,
308 const char **cql2rpn,
309 const char **authentication,
310 const char **negotiation_charset,
311 const char **negotiation_lang)
316 for (; ptr; ptr = ptr->next)
318 if (ptr->type == XML_ELEMENT_NODE
319 && !strcmp((const char *) ptr->name, "preinit"))
321 const char *v = get_text(ptr);
322 *pre_init = v ? atoi(v) : 1;
324 if (ptr->type == XML_ELEMENT_NODE
325 && !strcmp((const char *) ptr->name, "url"))
327 const char *t = get_text(ptr);
328 if (t && no_url < MAX_ZURL_PLEX)
334 if (ptr->type == XML_ELEMENT_NODE
335 && !strcmp((const char *) ptr->name, "keepalive"))
338 *keepalive_limit_bw = 500000;
339 *keepalive_limit_pdu = 1000;
340 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
343 if (ptr->type == XML_ELEMENT_NODE
344 && !strcmp((const char *) ptr->name, "limit"))
345 return_limit(ptr, limit_bw, limit_pdu, limit_req);
346 if (ptr->type == XML_ELEMENT_NODE
347 && !strcmp((const char *) ptr->name, "target-timeout"))
349 const char *t = get_text(ptr);
352 *target_idletime = atoi(t);
353 if (*target_idletime < 0)
354 *target_idletime = 0;
357 if (ptr->type == XML_ELEMENT_NODE
358 && !strcmp((const char *) ptr->name, "client-timeout"))
360 const char *t = get_text(ptr);
363 *client_idletime = atoi(t);
364 if (*client_idletime < 0)
365 *client_idletime = 0;
368 if (ptr->type == XML_ELEMENT_NODE
369 && !strcmp((const char *) ptr->name, "cql2rpn"))
371 const char *t = get_text(ptr);
375 if (ptr->type == XML_ELEMENT_NODE
376 && !strcmp((const char *) ptr->name, "authentication"))
378 const char *t = get_text(ptr);
382 if (ptr->type == XML_ELEMENT_NODE
383 && !strcmp((const char *) ptr->name, "negotiation-charset"))
385 const char *t = get_text(ptr);
387 *negotiation_charset = t;
389 if (ptr->type == XML_ELEMENT_NODE
390 && !strcmp((const char *) ptr->name, "negotiation-lang"))
392 const char *t = get_text(ptr);
394 *negotiation_lang = t;
400 int Yaz_ProxyConfigP::atoi_l(const char **cp)
403 while (**cp && isdigit(**cp))
405 v = v*10 + (**cp - '0');
411 int Yaz_ProxyConfigP::match_list(int v, const char *m)
415 while(*m && isspace(*m))
426 if (v >= l && v <= h)
435 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
436 Z_AttributeList *attrs,
440 for (i = 0; i<attrs->num_attributes; i++)
442 Z_AttributeElement *el = attrs->attributes[i];
444 if (!el->attributeType)
446 int type = *el->attributeType;
449 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
450 value = el->value.numeric;
453 for(ptr = ptrl->children; ptr; ptr = ptr->next)
455 if (ptr->type == XML_ELEMENT_NODE &&
456 !strcmp((const char *) ptr->name, "attribute"))
458 const char *match_type = 0;
459 const char *match_value = 0;
460 const char *match_error = 0;
461 struct _xmlAttr *attr;
462 for (attr = ptr->properties; attr; attr = attr->next)
464 if (!strcmp((const char *) attr->name, "type") &&
465 attr->children && attr->children->type == XML_TEXT_NODE)
466 match_type = (const char *) attr->children->content;
467 if (!strcmp((const char *) attr->name, "value") &&
468 attr->children && attr->children->type == XML_TEXT_NODE)
469 match_value = (const char *) attr->children->content;
470 if (!strcmp((const char *) attr->name, "error") &&
471 attr->children && attr->children->type == XML_TEXT_NODE)
472 match_error = (const char *) attr->children->content;
474 if (match_type && match_value)
476 char addinfo_str[20];
477 if (!match_list(type, match_type))
481 if (!strcmp(match_type, "*"))
482 sprintf (addinfo_str, "%d", type);
485 if (!match_list(*value, match_value))
487 sprintf (addinfo_str, "%d", *value);
495 *addinfo = odr_strdup(odr, addinfo_str);
496 return atoi(match_error);
508 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
512 if (q->which == Z_RPNStructure_complex)
514 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
517 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
520 else if (q->which == Z_RPNStructure_simple)
522 if (q->u.simple->which == Z_Operand_APT)
524 return check_type_1_attributes(
525 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
534 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
537 // possibly check for Bib-1
538 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
542 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
548 ptr = m_cp->find_target_node(name, 0);
551 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
552 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
559 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
560 const char *schema_identifier)
563 int default_match = 1;
564 if (comp && comp->which == Z_RecordComp_simple &&
565 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
567 esn = comp->u.simple->u.generic;
569 // if no ESN/schema was given accept..
572 // check if schema identifier match
573 if (schema_identifier && !strcmp(esn, schema_identifier))
575 // Check each name element
576 for (; ptr; ptr = ptr->next)
578 if (ptr->type == XML_ELEMENT_NODE
579 && !strcmp((const char *) ptr->name, "name"))
581 xmlNodePtr tptr = ptr->children;
583 for (; tptr; tptr = tptr->next)
584 if (tptr->type == XML_TEXT_NODE && tptr->content)
586 xmlChar *t = tptr->content;
587 while (*t && isspace(*t))
590 while (esn[i] && esn[i] == t[i])
592 if (!esn[i] && (!t[i] || isspace(t[i])))
597 return default_match;
601 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
607 {".xml", "text/xml"},
608 {".xsl", "text/xml"},
609 {".tkl", "text/xml"},
610 {".xsd", "text/xml"},
611 {".html", "text/html"},
612 {".jpg", "image/jpeg"},
613 {".png", "image/png"},
614 {".gif", "image/gif"},
619 size_t plen = strlen (path);
620 for (i = 0; types[i].type; i++)
621 if (types[i].mask == 0)
622 return types[i].type;
625 size_t mlen = strlen(types[i].mask);
626 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
627 return types[i].type;
629 return "application/octet-stream";
633 int Yaz_ProxyConfig::check_authentication(const char *user,
635 const char *password)
637 Yaz_ProxyModule *m = m_cp->m_modules;
639 int ret = YAZPROXY_RET_NOT_ME;
640 for (; m; m = m->get_next())
642 ret = m->authenticate(user, group, password);
643 if (ret != YAZPROXY_RET_NOT_ME)
646 if (ret == YAZPROXY_RET_PERM)
651 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
652 Odr_oid *syntax, Z_RecordComposition *comp,
654 char **stylesheet, char **schema,
656 char **backend_charset,
657 char **usemarcon_ini_stage1,
658 char **usemarcon_ini_stage2
673 xfree (*backend_type);
678 xfree (*backend_charset);
679 *backend_charset = 0;
681 if (usemarcon_ini_stage1)
683 xfree (*usemarcon_ini_stage1);
684 *usemarcon_ini_stage1 = 0;
686 if (usemarcon_ini_stage2)
688 xfree (*usemarcon_ini_stage2);
689 *usemarcon_ini_stage2 = 0;
692 int syntax_has_matched = 0;
695 ptr = m_cp->find_target_node(name, 0);
698 for(ptr = ptr->children; ptr; ptr = ptr->next)
700 if (ptr->type == XML_ELEMENT_NODE &&
701 !strcmp((const char *) ptr->name, "syntax"))
703 int match = 0; // if we match record syntax
704 const char *match_type = 0;
705 const char *match_error = 0;
706 const char *match_marcxml = 0;
707 const char *match_stylesheet = 0;
708 const char *match_identifier = 0;
709 const char *match_backend_type = 0;
710 const char *match_backend_charset = 0;
711 const char *match_usemarcon_ini_stage1 = 0;
712 const char *match_usemarcon_ini_stage2 = 0;
713 struct _xmlAttr *attr;
714 for (attr = ptr->properties; attr; attr = attr->next)
716 if (!strcmp((const char *) attr->name, "type") &&
717 attr->children && attr->children->type == XML_TEXT_NODE)
718 match_type = (const char *) attr->children->content;
719 if (!strcmp((const char *) attr->name, "error") &&
720 attr->children && attr->children->type == XML_TEXT_NODE)
721 match_error = (const char *) attr->children->content;
722 if (!strcmp((const char *) attr->name, "marcxml") &&
723 attr->children && attr->children->type == XML_TEXT_NODE)
724 match_marcxml = (const char *) attr->children->content;
725 if (!strcmp((const char *) attr->name, "stylesheet") &&
726 attr->children && attr->children->type == XML_TEXT_NODE)
727 match_stylesheet = (const char *) attr->children->content;
728 if (!strcmp((const char *) attr->name, "identifier") &&
729 attr->children && attr->children->type == XML_TEXT_NODE)
730 match_identifier = (const char *) attr->children->content;
731 if (!strcmp((const char *) attr->name, "backendtype") &&
732 attr->children && attr->children->type == XML_TEXT_NODE)
733 match_backend_type = (const char *)
734 attr->children->content;
735 if (!strcmp((const char *) attr->name, "backendcharset") &&
736 attr->children && attr->children->type == XML_TEXT_NODE)
737 match_backend_charset = (const char *)
738 attr->children->content;
739 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
740 attr->children && attr->children->type == XML_TEXT_NODE)
741 match_usemarcon_ini_stage1 = (const char *)
742 attr->children->content;
743 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
744 attr->children && attr->children->type == XML_TEXT_NODE)
745 match_usemarcon_ini_stage2 = (const char *)
746 attr->children->content;
750 if (!strcmp(match_type, "*"))
752 else if (!strcmp(match_type, "none"))
759 int match_oid[OID_SIZE];
760 oid_name_to_oid(CLASS_RECSYN, match_type, match_oid);
761 if (oid_oidcmp(match_oid, syntax) == 0)
768 syntax_has_matched = 1;
769 match = m_cp->check_schema(ptr->children, comp,
774 if (stylesheet && match_stylesheet)
777 *stylesheet = xstrdup(match_stylesheet);
779 if (schema && match_identifier)
782 *schema = xstrdup(match_identifier);
784 if (backend_type && match_backend_type)
786 xfree(*backend_type);
787 *backend_type = xstrdup(match_backend_type);
789 if (backend_charset && match_backend_charset)
791 xfree(*backend_charset);
792 *backend_charset = xstrdup(match_backend_charset);
794 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
796 xfree(*usemarcon_ini_stage1);
797 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
799 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
801 xfree(*usemarcon_ini_stage2);
802 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
810 if (syntax_has_matched) // if syntax OK, bad schema/ESN
814 char dotoid_str[100];
815 oid_to_dotstring(syntax, dotoid_str);
816 *addinfo = odr_strdup(odr, dotoid_str);
818 return atoi(match_error);
829 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
836 for (dptr = ptr->children; dptr; dptr = dptr->next)
837 if (dptr->type == XML_ELEMENT_NODE &&
838 !strcmp((const char *) dptr->name, "database"))
840 struct _xmlAttr *attr;
841 for (attr = dptr->properties; attr; attr = attr->next)
842 if (!strcmp((const char *) attr->name, "name"))
845 && attr->children->type==XML_TEXT_NODE
846 && attr->children->content
847 && (!strcmp((const char *) attr->children->content, db)
848 || !strcmp((const char *) attr->children->content,
856 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
861 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
863 if (ptr->type == XML_ELEMENT_NODE &&
864 !strcmp((const char *) ptr->name, "target"))
869 // <target default="1"> ?
870 struct _xmlAttr *attr;
871 for (attr = ptr->properties; attr; attr = attr->next)
872 if (!strcmp((const char *) attr->name, "default") &&
873 attr->children && attr->children->type == XML_TEXT_NODE)
875 xmlChar *t = attr->children->content;
878 return find_target_db(ptr, db);
884 // <target name="name"> ?
885 struct _xmlAttr *attr;
886 for (attr = ptr->properties; attr; attr = attr->next)
887 if (!strcmp((const char *) attr->name, "name"))
890 && attr->children->type==XML_TEXT_NODE
891 && attr->children->content
892 && (!strcmp((const char *) attr->children->content,
894 || !strcmp((const char *) attr->children->content,
897 return find_target_db(ptr, db);
907 int Yaz_ProxyConfig::get_target_no(int no,
913 int *target_idletime,
914 int *client_idletime,
916 int *keepalive_limit_bw,
917 int *keepalive_limit_pdu,
919 const char **cql2rpn,
920 const char **authentication,
921 const char **negotiation_charset,
922 const char **negotiation_lang)
926 if (!m_cp->m_proxyPtr)
929 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
930 if (ptr->type == XML_ELEMENT_NODE &&
931 !strcmp((const char *) ptr->name, "target"))
935 struct _xmlAttr *attr;
936 for (attr = ptr->properties; attr; attr = attr->next)
937 if (!strcmp((const char *) attr->name, "name"))
940 && attr->children->type==XML_TEXT_NODE
941 && attr->children->content)
942 *name = (const char *) attr->children->content;
944 m_cp->return_target_info(
946 limit_bw, limit_pdu, limit_req,
947 target_idletime, client_idletime,
948 keepalive_limit_bw, keepalive_limit_pdu,
949 pre_init, cql2rpn, authentication,
950 negotiation_charset, negotiation_lang);
959 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
961 if (len == strlen(item) && memcmp(hay, item, len) == 0)
966 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
971 if (!m_cp->m_proxyPtr)
973 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
975 if (ptr->type == XML_ELEMENT_NODE
976 && !strcmp((const char *) ptr->name, "log"))
978 const char *v = m_cp->get_text(ptr);
983 while (*cp && *cp != ',' && !isspace(*cp))
986 if (m_cp->mycmp(v, "client-apdu", len))
987 *log_mask |= PROXY_LOG_APDU_CLIENT;
988 if (m_cp->mycmp(v, "server-apdu", len))
989 *log_mask |= PROXY_LOG_APDU_SERVER;
990 if (m_cp->mycmp(v, "client-requests", len))
991 *log_mask |= PROXY_LOG_REQ_CLIENT;
992 if (m_cp->mycmp(v, "server-requests", len))
993 *log_mask |= PROXY_LOG_REQ_SERVER;
995 *log_mask |= atoi(v);
998 while (*cp && isspace(*cp))
1003 if (ptr->type == XML_ELEMENT_NODE &&
1004 !strcmp((const char *) ptr->name, "max-clients"))
1006 const char *t = m_cp->get_text(ptr);
1009 *max_clients = atoi(t);
1010 if (*max_clients < 1)
1019 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1020 xmlNodePtr *ptr_target,
1021 xmlNodePtr *ptr_explain)
1028 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1030 if (ptr->type == XML_ELEMENT_NODE &&
1031 !strcmp((const char *) ptr->name, "target"))
1034 xmlNodePtr ptr = (*ptr_target)->children;
1035 for (; ptr; ptr = ptr->next)
1037 if (ptr->type == XML_ELEMENT_NODE &&
1038 !strcmp((const char *) ptr->name, "explain"))
1041 xmlNodePtr ptr = (*ptr_explain)->children;
1043 for (; ptr; ptr = ptr->next)
1044 if (ptr->type == XML_ELEMENT_NODE &&
1045 !strcmp((const char *) ptr->name, "serverInfo"))
1049 for (ptr = ptr->children; ptr; ptr = ptr->next)
1050 if (ptr->type == XML_ELEMENT_NODE &&
1051 !strcmp((const char *) ptr->name, "database"))
1056 for (ptr = ptr->children; ptr; ptr = ptr->next)
1057 if (ptr->type == XML_TEXT_NODE &&
1059 !strcmp((const char *) ptr->content, db))
1072 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1073 const char **backend_db)
1076 xmlNodePtr ptr_target, ptr_explain;
1077 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1080 struct _xmlAttr *attr;
1081 const char *name = 0;
1083 for (attr = ptr_target->properties; attr; attr = attr->next)
1084 if (!strcmp((const char *) attr->name, "name")
1086 && attr->children->type==XML_TEXT_NODE
1087 && attr->children->content
1088 && attr->children->content[0])
1090 name = (const char *)attr->children->content;
1095 for (attr = ptr_target->properties; attr; attr = attr->next)
1096 if (!strcmp((const char *) attr->name, "database"))
1099 && attr->children->type==XML_TEXT_NODE
1100 && attr->children->content)
1101 *backend_db = (const char *) attr->children->content;
1110 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1111 const char *db, int *len)
1114 xmlNodePtr ptr_target, ptr_explain;
1115 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1117 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1119 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1121 xmlDocSetRootElement(doc, ptr2);
1124 xmlDocDumpMemory(doc, &buf_out, len);
1125 char *content = (char*) odr_malloc(odr, *len);
1126 memcpy(content, buf_out, *len);
1136 void Yaz_ProxyConfig::get_target_info(const char *name,
1141 int *target_idletime,
1142 int *client_idletime,
1144 int *keepalive_limit_bw,
1145 int *keepalive_limit_pdu,
1147 const char **cql2rpn,
1148 const char **authentication,
1149 const char **negotiation_charset,
1150 const char **negotiation_lang)
1154 if (!m_cp->m_proxyPtr)
1161 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1163 if (ptr->type == XML_ELEMENT_NODE &&
1164 !strcmp((const char *) ptr->name, "max-clients"))
1166 const char *t = m_cp->get_text(ptr);
1169 *max_clients = atoi(t);
1170 if (*max_clients < 1)
1175 ptr = m_cp->find_target_node(name, 0);
1183 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1184 target_idletime, client_idletime,
1185 keepalive_limit_bw, keepalive_limit_pdu,
1186 pre_init, cql2rpn, authentication,
1187 negotiation_charset, negotiation_lang);