1 /* $Id: yaz-proxy-config.cpp,v 1.19 2005-05-18 20:15:22 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);
43 Yaz_ProxyModule *get_next() { return m_next; };
44 int is_module(const char *name);
45 int authenticate(const char *target_name, void *element_ptr,
46 const char *user, const char *group, const char *password);
49 int Yaz_ProxyModule::is_module(const char *type)
51 if (!type || !strcmp(m_entry->module_name, type))
56 Yaz_ProxyModule::Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
57 Yaz_ProxyModule *next)
59 m_dl_handle = dl_handle;
63 if (m_entry->int_version == 0)
65 struct Yaz_ProxyModule_int0 *int0 =
66 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
68 m_user_handle = (*int0->init)();
72 Yaz_ProxyModule::~Yaz_ProxyModule()
74 if (m_entry->int_version == 0)
76 struct Yaz_ProxyModule_int0 *int0 =
77 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
79 (*int0->destroy)(m_user_handle);
86 int Yaz_ProxyModule::authenticate(const char *name,
88 const char *user, const char *group,
91 if (m_entry->int_version == 0)
93 struct Yaz_ProxyModule_int0 *int0 =
94 reinterpret_cast<Yaz_ProxyModule_int0 *>(m_entry->fl);
96 if (!int0->authenticate)
97 return YAZPROXY_RET_NOT_ME;
98 return (*int0->authenticate)(m_user_handle, name, element_ptr,
99 user, group, password);
101 return YAZPROXY_RET_NOT_ME;
104 class Yaz_ProxyConfigP {
105 friend class Yaz_ProxyConfig;
107 Yaz_ProxyModule *m_modules;
109 int mycmp(const char *hay, const char *item, size_t len);
110 int match_list(int v, const char *m);
111 int atoi_l(const char **cp);
113 void load_modules(void);
114 void unload_modules(void);
115 int check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
116 const char *schema_identifier);
118 xmlNodePtr m_proxyPtr;
119 void return_target_info(xmlNodePtr ptr, const char **url,
120 int *limit_bw, int *limit_pdu, int *limit_req,
121 int *target_idletime, int *client_idletime,
122 int *keepalive_limit_bw, int *keepalive_limit_pdu,
123 int *pre_init, const char **cql2rpn,
124 const char **negotiation_charset,
125 const char **negotiation_lang,
126 const char **target_charset);
127 void return_limit(xmlNodePtr ptr,
128 int *limit_bw, int *limit_pdu, int *limit_req);
129 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
131 xmlNodePtr find_target_node(const char *name, const char *db);
132 xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
133 const char *get_text(xmlNodePtr ptr);
134 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
135 Z_AttributeList *attrs,
137 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
139 int get_explain_ptr(const char *host, const char *db,
140 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
146 Yaz_ProxyConfigP::Yaz_ProxyConfigP()
155 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
159 xmlFreeDoc(m_docPtr);
163 Yaz_ProxyConfig::Yaz_ProxyConfig()
165 m_cp = new Yaz_ProxyConfigP;
168 Yaz_ProxyConfig::~Yaz_ProxyConfig()
174 void Yaz_ProxyConfigP::unload_modules()
176 Yaz_ProxyModule *m = m_modules;
179 Yaz_ProxyModule *m_next = m->get_next();
188 void Yaz_ProxyConfigP::load_modules()
193 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
196 if (ptr->type == XML_ELEMENT_NODE
197 && !strcmp((const char *) ptr->name, "module")
198 && (fname = get_text(ptr)))
201 void *dl_handle = dlopen(fname, RTLD_NOW|RTLD_GLOBAL);
204 Yaz_ProxyModule_entry *fl_ptr = 0;
205 fl_ptr = reinterpret_cast<Yaz_ProxyModule_entry *>
206 (dlsym(dl_handle, "yazproxy_module"));
209 Yaz_ProxyModule *m = new Yaz_ProxyModule(dl_handle,
213 yaz_log(YLOG_LOG, "Loading %s OK", fname);
217 yaz_log(YLOG_WARN, "Loading %s FAIL: missing yazproxy_module symbol", fname);
222 yaz_log(YLOG_WARN, "Loading %s FAIL: dlopen failed", fname);
224 yaz_log(YLOG_WARN, "Loading &s FAIL: dl unsupported", fname);
231 int Yaz_ProxyConfig::read_xml(const char *fname)
234 xmlDocPtr ndoc = xmlParseFile(fname);
238 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
239 return -1; // no good
241 int noSubstitutions = xmlXIncludeProcess(ndoc);
242 if (noSubstitutions == -1)
243 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
245 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
246 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
247 strcmp((const char *) proxyPtr->name, "proxy"))
249 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
253 m_cp->m_proxyPtr = proxyPtr;
255 // OK: release previous and make it the current one.
257 xmlFreeDoc(m_cp->m_docPtr);
258 m_cp->m_docPtr = ndoc;
260 m_cp->unload_modules();
261 m_cp->load_modules();
269 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
271 for(ptr = ptr->children; ptr; ptr = ptr->next)
272 if (ptr->type == XML_TEXT_NODE)
274 xmlChar *t = ptr->content;
279 return (const char *) t;
287 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
292 for (ptr = ptr->children; ptr; ptr = ptr->next)
294 if (ptr->type == XML_ELEMENT_NODE
295 && !strcmp((const char *) ptr->name, "bandwidth"))
297 const char *t = get_text(ptr);
301 if (ptr->type == XML_ELEMENT_NODE
302 && !strcmp((const char *) ptr->name, "retrieve"))
304 const char *t = get_text(ptr);
306 *limit_req = atoi(t);
308 if (ptr->type == XML_ELEMENT_NODE
309 && !strcmp((const char *) ptr->name, "pdu"))
311 const char *t = get_text(ptr);
313 *limit_pdu = atoi(t);
320 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
325 int *target_idletime,
326 int *client_idletime,
327 int *keepalive_limit_bw,
328 int *keepalive_limit_pdu,
330 const char **cql2rpn,
331 const char **negotiation_charset,
332 const char **negotiation_lang,
333 const char **target_charset)
338 for (; ptr; ptr = ptr->next)
340 if (ptr->type == XML_ELEMENT_NODE
341 && !strcmp((const char *) ptr->name, "preinit"))
343 const char *v = get_text(ptr);
344 *pre_init = v ? atoi(v) : 1;
346 if (ptr->type == XML_ELEMENT_NODE
347 && !strcmp((const char *) ptr->name, "url"))
349 const char *t = get_text(ptr);
350 if (t && no_url < MAX_ZURL_PLEX)
356 if (ptr->type == XML_ELEMENT_NODE
357 && !strcmp((const char *) ptr->name, "keepalive"))
360 *keepalive_limit_bw = 500000;
361 *keepalive_limit_pdu = 1000;
362 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
365 if (ptr->type == XML_ELEMENT_NODE
366 && !strcmp((const char *) ptr->name, "limit"))
367 return_limit(ptr, limit_bw, limit_pdu, limit_req);
368 if (ptr->type == XML_ELEMENT_NODE
369 && !strcmp((const char *) ptr->name, "target-timeout"))
371 const char *t = get_text(ptr);
374 *target_idletime = atoi(t);
375 if (*target_idletime < 0)
376 *target_idletime = 0;
379 if (ptr->type == XML_ELEMENT_NODE
380 && !strcmp((const char *) ptr->name, "client-timeout"))
382 const char *t = get_text(ptr);
385 *client_idletime = atoi(t);
386 if (*client_idletime < 0)
387 *client_idletime = 0;
390 if (ptr->type == XML_ELEMENT_NODE
391 && !strcmp((const char *) ptr->name, "cql2rpn"))
393 const char *t = get_text(ptr);
397 if (ptr->type == XML_ELEMENT_NODE
398 && !strcmp((const char *) ptr->name, "target-charset"))
400 const char *t = get_text(ptr);
401 if (t && target_charset)
404 if (ptr->type == XML_ELEMENT_NODE
405 && !strcmp((const char *) ptr->name, "negotiation-charset"))
407 const char *t = get_text(ptr);
409 *negotiation_charset = t;
411 if (ptr->type == XML_ELEMENT_NODE
412 && !strcmp((const char *) ptr->name, "negotiation-lang"))
414 const char *t = get_text(ptr);
416 *negotiation_lang = t;
422 int Yaz_ProxyConfigP::atoi_l(const char **cp)
425 while (**cp && isdigit(**cp))
427 v = v*10 + (**cp - '0');
433 int Yaz_ProxyConfigP::match_list(int v, const char *m)
437 while(*m && isspace(*m))
448 if (v >= l && v <= h)
457 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
458 Z_AttributeList *attrs,
462 for (i = 0; i<attrs->num_attributes; i++)
464 Z_AttributeElement *el = attrs->attributes[i];
466 if (!el->attributeType)
468 int type = *el->attributeType;
471 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
472 value = el->value.numeric;
475 for(ptr = ptrl->children; ptr; ptr = ptr->next)
477 if (ptr->type == XML_ELEMENT_NODE &&
478 !strcmp((const char *) ptr->name, "attribute"))
480 const char *match_type = 0;
481 const char *match_value = 0;
482 const char *match_error = 0;
483 struct _xmlAttr *attr;
484 for (attr = ptr->properties; attr; attr = attr->next)
486 if (!strcmp((const char *) attr->name, "type") &&
487 attr->children && attr->children->type == XML_TEXT_NODE)
488 match_type = (const char *) attr->children->content;
489 if (!strcmp((const char *) attr->name, "value") &&
490 attr->children && attr->children->type == XML_TEXT_NODE)
491 match_value = (const char *) attr->children->content;
492 if (!strcmp((const char *) attr->name, "error") &&
493 attr->children && attr->children->type == XML_TEXT_NODE)
494 match_error = (const char *) attr->children->content;
496 if (match_type && match_value)
498 char addinfo_str[20];
499 if (!match_list(type, match_type))
503 if (!strcmp(match_type, "*"))
504 sprintf (addinfo_str, "%d", type);
507 if (!match_list(*value, match_value))
509 sprintf (addinfo_str, "%d", *value);
517 *addinfo = odr_strdup(odr, addinfo_str);
518 return atoi(match_error);
530 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
534 if (q->which == Z_RPNStructure_complex)
536 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
539 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
542 else if (q->which == Z_RPNStructure_simple)
544 if (q->u.simple->which == Z_Operand_APT)
546 return check_type_1_attributes(
547 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
556 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
559 // possibly check for Bib-1
560 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
564 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
570 ptr = m_cp->find_target_node(name, 0);
573 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
574 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
581 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
582 const char *schema_identifier)
585 int default_match = 1;
586 if (comp && comp->which == Z_RecordComp_simple &&
587 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
589 esn = comp->u.simple->u.generic;
591 // if no ESN/schema was given accept..
594 // check if schema identifier match
595 if (schema_identifier && !strcmp(esn, schema_identifier))
597 // Check each name element
598 for (; ptr; ptr = ptr->next)
600 if (ptr->type == XML_ELEMENT_NODE
601 && !strcmp((const char *) ptr->name, "name"))
603 xmlNodePtr tptr = ptr->children;
605 for (; tptr; tptr = tptr->next)
606 if (tptr->type == XML_TEXT_NODE && tptr->content)
608 xmlChar *t = tptr->content;
609 while (*t && isspace(*t))
612 while (esn[i] && esn[i] == t[i])
614 if (!esn[i] && (!t[i] || isspace(t[i])))
619 return default_match;
623 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
629 {".xml", "text/xml"},
630 {".xsl", "text/xml"},
631 {".tkl", "text/xml"},
632 {".xsd", "text/xml"},
633 {".html", "text/html"},
634 {".jpg", "image/jpeg"},
635 {".png", "image/png"},
636 {".gif", "image/gif"},
641 size_t plen = strlen (path);
642 for (i = 0; types[i].type; i++)
643 if (types[i].mask == 0)
644 return types[i].type;
647 size_t mlen = strlen(types[i].mask);
648 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
649 return types[i].type;
651 return "application/octet-stream";
655 void Yaz_ProxyConfig::target_authentication(const char *name,
656 ODR odr, Z_InitRequest *req)
659 xmlNodePtr ptr = m_cp->find_target_node(name, 0);
663 for (ptr = ptr->children; ptr; ptr = ptr->next)
664 if (ptr->type == XML_ELEMENT_NODE &&
665 !strcmp((const char *) ptr->name, "target-authentication"))
667 struct _xmlAttr *attr;
668 const char *type = "open";
669 for (attr = ptr->properties; attr; attr = attr->next)
671 if (!strcmp((const char *) attr->name, "type") &&
672 attr->children && attr->children->type == XML_TEXT_NODE)
673 type = (const char *) attr->children->content;
675 const char *t = m_cp->get_text(ptr);
676 if (!t || !strcmp(type, "none"))
677 req->idAuthentication = 0;
678 else if (!strcmp(type, "anonymous"))
680 req->idAuthentication =
681 (Z_IdAuthentication *)
682 odr_malloc (odr, sizeof(*req->idAuthentication));
683 req->idAuthentication->which =
684 Z_IdAuthentication_anonymous;
685 req->idAuthentication->u.anonymous = odr_nullval();
687 else if (!strcmp(type, "open"))
689 req->idAuthentication =
690 (Z_IdAuthentication *)
691 odr_malloc (odr, sizeof(*req->idAuthentication));
692 req->idAuthentication->which =
693 Z_IdAuthentication_open;
694 req->idAuthentication->u.open = odr_strdup (odr, t);
696 else if (!strcmp(type, "idPass"))
698 char user[64], group[64], password[64];
702 sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
704 req->idAuthentication =
705 (Z_IdAuthentication *)
706 odr_malloc (odr, sizeof(*req->idAuthentication));
707 req->idAuthentication->which =
708 Z_IdAuthentication_idPass;
709 req->idAuthentication->u.idPass =
710 (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
711 req->idAuthentication->u.idPass->userId =
712 *user ? odr_strdup(odr, user) : 0;
713 req->idAuthentication->u.idPass->groupId =
714 *group ? odr_strdup(odr, group) : 0;
715 req->idAuthentication->u.idPass->password =
716 *password ? odr_strdup(odr, password) : 0;
722 int Yaz_ProxyConfig::client_authentication(const char *name,
725 const char *password)
727 int ret = YAZPROXY_RET_NOT_ME;
730 ptr = m_cp->find_target_node(name, 0);
733 for (ptr = ptr->children; ptr; ptr = ptr->next)
734 if (ptr->type == XML_ELEMENT_NODE &&
735 !strcmp((const char *) ptr->name, "client-authentication"))
737 struct _xmlAttr *attr;
738 const char *module_name = 0;
739 for (attr = ptr->properties; attr; attr = attr->next)
741 if (!strcmp((const char *) attr->name, "module") &&
742 attr->children && attr->children->type == XML_TEXT_NODE)
743 module_name = (const char *) attr->children->content;
745 Yaz_ProxyModule *m = m_cp->m_modules;
746 for (; m; m = m->get_next())
748 if (m->is_module(module_name))
750 ret = m->authenticate(name, ptr, user, group, password);
751 if (ret != YAZPROXY_RET_NOT_ME)
757 if (ret == YAZPROXY_RET_PERM)
762 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
763 Odr_oid *syntax, Z_RecordComposition *comp,
765 char **stylesheet, char **schema,
767 char **backend_charset,
768 char **usemarcon_ini_stage1,
769 char **usemarcon_ini_stage2
784 xfree (*backend_type);
789 xfree (*backend_charset);
790 *backend_charset = 0;
792 if (usemarcon_ini_stage1)
794 xfree (*usemarcon_ini_stage1);
795 *usemarcon_ini_stage1 = 0;
797 if (usemarcon_ini_stage2)
799 xfree (*usemarcon_ini_stage2);
800 *usemarcon_ini_stage2 = 0;
803 int syntax_has_matched = 0;
806 ptr = m_cp->find_target_node(name, 0);
809 for(ptr = ptr->children; ptr; ptr = ptr->next)
811 if (ptr->type == XML_ELEMENT_NODE &&
812 !strcmp((const char *) ptr->name, "syntax"))
814 int match = 0; // if we match record syntax
815 const char *match_type = 0;
816 const char *match_error = 0;
817 const char *match_marcxml = 0;
818 const char *match_stylesheet = 0;
819 const char *match_identifier = 0;
820 const char *match_backend_type = 0;
821 const char *match_backend_charset = 0;
822 const char *match_usemarcon_ini_stage1 = 0;
823 const char *match_usemarcon_ini_stage2 = 0;
824 struct _xmlAttr *attr;
825 for (attr = ptr->properties; attr; attr = attr->next)
827 if (!strcmp((const char *) attr->name, "type") &&
828 attr->children && attr->children->type == XML_TEXT_NODE)
829 match_type = (const char *) attr->children->content;
830 if (!strcmp((const char *) attr->name, "error") &&
831 attr->children && attr->children->type == XML_TEXT_NODE)
832 match_error = (const char *) attr->children->content;
833 if (!strcmp((const char *) attr->name, "marcxml") &&
834 attr->children && attr->children->type == XML_TEXT_NODE)
835 match_marcxml = (const char *) attr->children->content;
836 if (!strcmp((const char *) attr->name, "stylesheet") &&
837 attr->children && attr->children->type == XML_TEXT_NODE)
838 match_stylesheet = (const char *) attr->children->content;
839 if (!strcmp((const char *) attr->name, "identifier") &&
840 attr->children && attr->children->type == XML_TEXT_NODE)
841 match_identifier = (const char *) attr->children->content;
842 if (!strcmp((const char *) attr->name, "backendtype") &&
843 attr->children && attr->children->type == XML_TEXT_NODE)
844 match_backend_type = (const char *)
845 attr->children->content;
846 if (!strcmp((const char *) attr->name, "backendcharset") &&
847 attr->children && attr->children->type == XML_TEXT_NODE)
848 match_backend_charset = (const char *)
849 attr->children->content;
850 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
851 attr->children && attr->children->type == XML_TEXT_NODE)
852 match_usemarcon_ini_stage1 = (const char *)
853 attr->children->content;
854 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
855 attr->children && attr->children->type == XML_TEXT_NODE)
856 match_usemarcon_ini_stage2 = (const char *)
857 attr->children->content;
861 if (!strcmp(match_type, "*"))
863 else if (!strcmp(match_type, "none"))
870 int match_oid[OID_SIZE];
871 oid_name_to_oid(CLASS_RECSYN, match_type, match_oid);
872 if (oid_oidcmp(match_oid, syntax) == 0)
879 syntax_has_matched = 1;
880 match = m_cp->check_schema(ptr->children, comp,
885 if (stylesheet && match_stylesheet)
888 *stylesheet = xstrdup(match_stylesheet);
890 if (schema && match_identifier)
893 *schema = xstrdup(match_identifier);
895 if (backend_type && match_backend_type)
897 xfree(*backend_type);
898 *backend_type = xstrdup(match_backend_type);
900 if (backend_charset && match_backend_charset)
902 xfree(*backend_charset);
903 *backend_charset = xstrdup(match_backend_charset);
905 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
907 xfree(*usemarcon_ini_stage1);
908 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
910 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
912 xfree(*usemarcon_ini_stage2);
913 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
921 if (syntax_has_matched) // if syntax OK, bad schema/ESN
925 char dotoid_str[100];
926 oid_to_dotstring(syntax, dotoid_str);
927 *addinfo = odr_strdup(odr, dotoid_str);
929 return atoi(match_error);
940 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
947 for (dptr = ptr->children; dptr; dptr = dptr->next)
948 if (dptr->type == XML_ELEMENT_NODE &&
949 !strcmp((const char *) dptr->name, "database"))
951 struct _xmlAttr *attr;
952 for (attr = dptr->properties; attr; attr = attr->next)
953 if (!strcmp((const char *) attr->name, "name"))
956 && attr->children->type==XML_TEXT_NODE
957 && attr->children->content
958 && (!strcmp((const char *) attr->children->content, db)
959 || !strcmp((const char *) attr->children->content,
967 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
972 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
974 if (ptr->type == XML_ELEMENT_NODE &&
975 !strcmp((const char *) ptr->name, "target"))
980 // <target default="1"> ?
981 struct _xmlAttr *attr;
982 for (attr = ptr->properties; attr; attr = attr->next)
983 if (!strcmp((const char *) attr->name, "default") &&
984 attr->children && attr->children->type == XML_TEXT_NODE)
986 xmlChar *t = attr->children->content;
989 return find_target_db(ptr, db);
995 // <target name="name"> ?
996 struct _xmlAttr *attr;
997 for (attr = ptr->properties; attr; attr = attr->next)
998 if (!strcmp((const char *) attr->name, "name"))
1001 && attr->children->type==XML_TEXT_NODE
1002 && attr->children->content
1003 && (!strcmp((const char *) attr->children->content,
1005 || !strcmp((const char *) attr->children->content,
1008 return find_target_db(ptr, db);
1018 int Yaz_ProxyConfig::get_target_no(int no,
1024 int *target_idletime,
1025 int *client_idletime,
1027 int *keepalive_limit_bw,
1028 int *keepalive_limit_pdu,
1030 const char **cql2rpn,
1031 const char **authentication,
1032 const char **negotiation_charset,
1033 const char **negotiation_lang,
1034 const char **target_charset)
1038 if (!m_cp->m_proxyPtr)
1041 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1042 if (ptr->type == XML_ELEMENT_NODE &&
1043 !strcmp((const char *) ptr->name, "target"))
1047 struct _xmlAttr *attr;
1048 for (attr = ptr->properties; attr; attr = attr->next)
1049 if (!strcmp((const char *) attr->name, "name"))
1052 && attr->children->type==XML_TEXT_NODE
1053 && attr->children->content)
1054 *name = (const char *) attr->children->content;
1056 m_cp->return_target_info(
1058 limit_bw, limit_pdu, limit_req,
1059 target_idletime, client_idletime,
1060 keepalive_limit_bw, keepalive_limit_pdu,
1062 negotiation_charset, negotiation_lang, target_charset);
1071 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
1073 if (len == strlen(item) && memcmp(hay, item, len) == 0)
1078 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
1083 if (!m_cp->m_proxyPtr)
1085 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1087 if (ptr->type == XML_ELEMENT_NODE
1088 && !strcmp((const char *) ptr->name, "log"))
1090 const char *v = m_cp->get_text(ptr);
1095 while (*cp && *cp != ',' && !isspace(*cp))
1097 size_t len = cp - v;
1098 if (m_cp->mycmp(v, "client-apdu", len))
1099 *log_mask |= PROXY_LOG_APDU_CLIENT;
1100 if (m_cp->mycmp(v, "server-apdu", len))
1101 *log_mask |= PROXY_LOG_APDU_SERVER;
1102 if (m_cp->mycmp(v, "client-requests", len))
1103 *log_mask |= PROXY_LOG_REQ_CLIENT;
1104 if (m_cp->mycmp(v, "server-requests", len))
1105 *log_mask |= PROXY_LOG_REQ_SERVER;
1107 *log_mask |= atoi(v);
1110 while (*cp && isspace(*cp))
1115 if (ptr->type == XML_ELEMENT_NODE &&
1116 !strcmp((const char *) ptr->name, "max-clients"))
1118 const char *t = m_cp->get_text(ptr);
1121 *max_clients = atoi(t);
1122 if (*max_clients < 1)
1131 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1132 xmlNodePtr *ptr_target,
1133 xmlNodePtr *ptr_explain)
1140 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1142 if (ptr->type == XML_ELEMENT_NODE &&
1143 !strcmp((const char *) ptr->name, "target"))
1146 xmlNodePtr ptr = (*ptr_target)->children;
1147 for (; ptr; ptr = ptr->next)
1149 if (ptr->type == XML_ELEMENT_NODE &&
1150 !strcmp((const char *) ptr->name, "explain"))
1153 xmlNodePtr ptr = (*ptr_explain)->children;
1155 for (; ptr; ptr = ptr->next)
1156 if (ptr->type == XML_ELEMENT_NODE &&
1157 !strcmp((const char *) ptr->name, "serverInfo"))
1161 for (ptr = ptr->children; ptr; ptr = ptr->next)
1162 if (ptr->type == XML_ELEMENT_NODE &&
1163 !strcmp((const char *) ptr->name, "database"))
1168 for (ptr = ptr->children; ptr; ptr = ptr->next)
1169 if (ptr->type == XML_TEXT_NODE &&
1171 !strcmp((const char *) ptr->content, db))
1184 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1185 const char **backend_db)
1188 xmlNodePtr ptr_target, ptr_explain;
1189 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1192 struct _xmlAttr *attr;
1193 const char *name = 0;
1195 for (attr = ptr_target->properties; attr; attr = attr->next)
1196 if (!strcmp((const char *) attr->name, "name")
1198 && attr->children->type==XML_TEXT_NODE
1199 && attr->children->content
1200 && attr->children->content[0])
1202 name = (const char *)attr->children->content;
1207 for (attr = ptr_target->properties; attr; attr = attr->next)
1208 if (!strcmp((const char *) attr->name, "database"))
1211 && attr->children->type==XML_TEXT_NODE
1212 && attr->children->content)
1213 *backend_db = (const char *) attr->children->content;
1222 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1223 const char *db, int *len)
1226 xmlNodePtr ptr_target, ptr_explain;
1227 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1229 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1231 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1233 xmlDocSetRootElement(doc, ptr2);
1236 xmlDocDumpMemory(doc, &buf_out, len);
1237 char *content = (char*) odr_malloc(odr, *len);
1238 memcpy(content, buf_out, *len);
1248 void Yaz_ProxyConfig::get_target_info(const char *name,
1253 int *target_idletime,
1254 int *client_idletime,
1256 int *keepalive_limit_bw,
1257 int *keepalive_limit_pdu,
1259 const char **cql2rpn,
1260 const char **negotiation_charset,
1261 const char **negotiation_lang,
1262 const char **target_charset)
1266 if (!m_cp->m_proxyPtr)
1273 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1275 if (ptr->type == XML_ELEMENT_NODE &&
1276 !strcmp((const char *) ptr->name, "max-clients"))
1278 const char *t = m_cp->get_text(ptr);
1281 *max_clients = atoi(t);
1282 if (*max_clients < 1)
1287 ptr = m_cp->find_target_node(name, 0);
1295 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1296 target_idletime, client_idletime,
1297 keepalive_limit_bw, keepalive_limit_pdu,
1299 negotiation_charset, negotiation_lang,