1 /* $Id: yaz-proxy-config.cpp,v 1.17 2005-02-21 14:27:32 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 void return_limit(xmlNodePtr ptr,
127 int *limit_bw, int *limit_pdu, int *limit_req);
128 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
130 xmlNodePtr find_target_node(const char *name, const char *db);
131 xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
132 const char *get_text(xmlNodePtr ptr);
133 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
134 Z_AttributeList *attrs,
136 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
138 int get_explain_ptr(const char *host, const char *db,
139 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
145 Yaz_ProxyConfigP::Yaz_ProxyConfigP()
154 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
158 xmlFreeDoc(m_docPtr);
162 Yaz_ProxyConfig::Yaz_ProxyConfig()
164 m_cp = new Yaz_ProxyConfigP;
167 Yaz_ProxyConfig::~Yaz_ProxyConfig()
173 void Yaz_ProxyConfigP::unload_modules()
175 Yaz_ProxyModule *m = m_modules;
178 Yaz_ProxyModule *m_next = m->get_next();
187 void Yaz_ProxyConfigP::load_modules()
192 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
195 if (ptr->type == XML_ELEMENT_NODE
196 && !strcmp((const char *) ptr->name, "module")
197 && (fname = get_text(ptr)))
200 void *dl_handle = dlopen(fname, RTLD_NOW|RTLD_GLOBAL);
203 Yaz_ProxyModule_entry *fl_ptr = 0;
204 fl_ptr = reinterpret_cast<Yaz_ProxyModule_entry *>
205 (dlsym(dl_handle, "yazproxy_module"));
208 Yaz_ProxyModule *m = new Yaz_ProxyModule(dl_handle,
212 yaz_log(YLOG_LOG, "Loading %s OK", fname);
216 yaz_log(YLOG_WARN, "Loading %s FAIL: missing yazproxy_module symbol", fname);
221 yaz_log(YLOG_WARN, "Loading %s FAIL: dlopen failed", fname);
223 yaz_log(YLOG_WARN, "Loading &s FAIL: dl unsupported", fname);
230 int Yaz_ProxyConfig::read_xml(const char *fname)
233 xmlDocPtr ndoc = xmlParseFile(fname);
237 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
238 return -1; // no good
240 int noSubstitutions = xmlXIncludeProcess(ndoc);
241 if (noSubstitutions == -1)
242 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
244 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
245 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
246 strcmp((const char *) proxyPtr->name, "proxy"))
248 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
252 m_cp->m_proxyPtr = proxyPtr;
254 // OK: release previous and make it the current one.
256 xmlFreeDoc(m_cp->m_docPtr);
257 m_cp->m_docPtr = ndoc;
259 m_cp->unload_modules();
260 m_cp->load_modules();
268 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
270 for(ptr = ptr->children; ptr; ptr = ptr->next)
271 if (ptr->type == XML_TEXT_NODE)
273 xmlChar *t = ptr->content;
278 return (const char *) t;
286 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
291 for (ptr = ptr->children; ptr; ptr = ptr->next)
293 if (ptr->type == XML_ELEMENT_NODE
294 && !strcmp((const char *) ptr->name, "bandwidth"))
296 const char *t = get_text(ptr);
300 if (ptr->type == XML_ELEMENT_NODE
301 && !strcmp((const char *) ptr->name, "retrieve"))
303 const char *t = get_text(ptr);
305 *limit_req = atoi(t);
307 if (ptr->type == XML_ELEMENT_NODE
308 && !strcmp((const char *) ptr->name, "pdu"))
310 const char *t = get_text(ptr);
312 *limit_pdu = atoi(t);
319 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
324 int *target_idletime,
325 int *client_idletime,
326 int *keepalive_limit_bw,
327 int *keepalive_limit_pdu,
329 const char **cql2rpn,
330 const char **negotiation_charset,
331 const char **negotiation_lang)
336 for (; ptr; ptr = ptr->next)
338 if (ptr->type == XML_ELEMENT_NODE
339 && !strcmp((const char *) ptr->name, "preinit"))
341 const char *v = get_text(ptr);
342 *pre_init = v ? atoi(v) : 1;
344 if (ptr->type == XML_ELEMENT_NODE
345 && !strcmp((const char *) ptr->name, "url"))
347 const char *t = get_text(ptr);
348 if (t && no_url < MAX_ZURL_PLEX)
354 if (ptr->type == XML_ELEMENT_NODE
355 && !strcmp((const char *) ptr->name, "keepalive"))
358 *keepalive_limit_bw = 500000;
359 *keepalive_limit_pdu = 1000;
360 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
363 if (ptr->type == XML_ELEMENT_NODE
364 && !strcmp((const char *) ptr->name, "limit"))
365 return_limit(ptr, limit_bw, limit_pdu, limit_req);
366 if (ptr->type == XML_ELEMENT_NODE
367 && !strcmp((const char *) ptr->name, "target-timeout"))
369 const char *t = get_text(ptr);
372 *target_idletime = atoi(t);
373 if (*target_idletime < 0)
374 *target_idletime = 0;
377 if (ptr->type == XML_ELEMENT_NODE
378 && !strcmp((const char *) ptr->name, "client-timeout"))
380 const char *t = get_text(ptr);
383 *client_idletime = atoi(t);
384 if (*client_idletime < 0)
385 *client_idletime = 0;
388 if (ptr->type == XML_ELEMENT_NODE
389 && !strcmp((const char *) ptr->name, "cql2rpn"))
391 const char *t = get_text(ptr);
395 if (ptr->type == XML_ELEMENT_NODE
396 && !strcmp((const char *) ptr->name, "negotiation-charset"))
398 const char *t = get_text(ptr);
400 *negotiation_charset = t;
402 if (ptr->type == XML_ELEMENT_NODE
403 && !strcmp((const char *) ptr->name, "negotiation-lang"))
405 const char *t = get_text(ptr);
407 *negotiation_lang = t;
413 int Yaz_ProxyConfigP::atoi_l(const char **cp)
416 while (**cp && isdigit(**cp))
418 v = v*10 + (**cp - '0');
424 int Yaz_ProxyConfigP::match_list(int v, const char *m)
428 while(*m && isspace(*m))
439 if (v >= l && v <= h)
448 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
449 Z_AttributeList *attrs,
453 for (i = 0; i<attrs->num_attributes; i++)
455 Z_AttributeElement *el = attrs->attributes[i];
457 if (!el->attributeType)
459 int type = *el->attributeType;
462 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
463 value = el->value.numeric;
466 for(ptr = ptrl->children; ptr; ptr = ptr->next)
468 if (ptr->type == XML_ELEMENT_NODE &&
469 !strcmp((const char *) ptr->name, "attribute"))
471 const char *match_type = 0;
472 const char *match_value = 0;
473 const char *match_error = 0;
474 struct _xmlAttr *attr;
475 for (attr = ptr->properties; attr; attr = attr->next)
477 if (!strcmp((const char *) attr->name, "type") &&
478 attr->children && attr->children->type == XML_TEXT_NODE)
479 match_type = (const char *) attr->children->content;
480 if (!strcmp((const char *) attr->name, "value") &&
481 attr->children && attr->children->type == XML_TEXT_NODE)
482 match_value = (const char *) attr->children->content;
483 if (!strcmp((const char *) attr->name, "error") &&
484 attr->children && attr->children->type == XML_TEXT_NODE)
485 match_error = (const char *) attr->children->content;
487 if (match_type && match_value)
489 char addinfo_str[20];
490 if (!match_list(type, match_type))
494 if (!strcmp(match_type, "*"))
495 sprintf (addinfo_str, "%d", type);
498 if (!match_list(*value, match_value))
500 sprintf (addinfo_str, "%d", *value);
508 *addinfo = odr_strdup(odr, addinfo_str);
509 return atoi(match_error);
521 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
525 if (q->which == Z_RPNStructure_complex)
527 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
530 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
533 else if (q->which == Z_RPNStructure_simple)
535 if (q->u.simple->which == Z_Operand_APT)
537 return check_type_1_attributes(
538 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
547 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
550 // possibly check for Bib-1
551 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
555 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
561 ptr = m_cp->find_target_node(name, 0);
564 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
565 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
572 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
573 const char *schema_identifier)
576 int default_match = 1;
577 if (comp && comp->which == Z_RecordComp_simple &&
578 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
580 esn = comp->u.simple->u.generic;
582 // if no ESN/schema was given accept..
585 // check if schema identifier match
586 if (schema_identifier && !strcmp(esn, schema_identifier))
588 // Check each name element
589 for (; ptr; ptr = ptr->next)
591 if (ptr->type == XML_ELEMENT_NODE
592 && !strcmp((const char *) ptr->name, "name"))
594 xmlNodePtr tptr = ptr->children;
596 for (; tptr; tptr = tptr->next)
597 if (tptr->type == XML_TEXT_NODE && tptr->content)
599 xmlChar *t = tptr->content;
600 while (*t && isspace(*t))
603 while (esn[i] && esn[i] == t[i])
605 if (!esn[i] && (!t[i] || isspace(t[i])))
610 return default_match;
614 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
620 {".xml", "text/xml"},
621 {".xsl", "text/xml"},
622 {".tkl", "text/xml"},
623 {".xsd", "text/xml"},
624 {".html", "text/html"},
625 {".jpg", "image/jpeg"},
626 {".png", "image/png"},
627 {".gif", "image/gif"},
632 size_t plen = strlen (path);
633 for (i = 0; types[i].type; i++)
634 if (types[i].mask == 0)
635 return types[i].type;
638 size_t mlen = strlen(types[i].mask);
639 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
640 return types[i].type;
642 return "application/octet-stream";
646 void Yaz_ProxyConfig::target_authentication(const char *name,
647 ODR odr, Z_InitRequest *req)
650 xmlNodePtr ptr = m_cp->find_target_node(name, 0);
654 for (ptr = ptr->children; ptr; ptr = ptr->next)
655 if (ptr->type == XML_ELEMENT_NODE &&
656 !strcmp((const char *) ptr->name, "target-authentication"))
658 struct _xmlAttr *attr;
659 const char *type = "open";
660 for (attr = ptr->properties; attr; attr = attr->next)
662 if (!strcmp((const char *) attr->name, "type") &&
663 attr->children && attr->children->type == XML_TEXT_NODE)
664 type = (const char *) attr->children->content;
666 const char *t = m_cp->get_text(ptr);
667 if (!t || !strcmp(type, "none"))
668 req->idAuthentication = 0;
669 else if (!strcmp(type, "anonymous"))
671 req->idAuthentication =
672 (Z_IdAuthentication *)
673 odr_malloc (odr, sizeof(*req->idAuthentication));
674 req->idAuthentication->which =
675 Z_IdAuthentication_anonymous;
676 req->idAuthentication->u.anonymous = odr_nullval();
678 else if (!strcmp(type, "open"))
680 req->idAuthentication =
681 (Z_IdAuthentication *)
682 odr_malloc (odr, sizeof(*req->idAuthentication));
683 req->idAuthentication->which =
684 Z_IdAuthentication_open;
685 req->idAuthentication->u.open = odr_strdup (odr, t);
687 else if (!strcmp(type, "idPass"))
689 char user[64], group[64], password[64];
693 sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
695 req->idAuthentication =
696 (Z_IdAuthentication *)
697 odr_malloc (odr, sizeof(*req->idAuthentication));
698 req->idAuthentication->which =
699 Z_IdAuthentication_idPass;
700 req->idAuthentication->u.idPass =
701 (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
702 req->idAuthentication->u.idPass->userId =
703 *user ? odr_strdup(odr, user) : 0;
704 req->idAuthentication->u.idPass->groupId =
705 *group ? odr_strdup(odr, group) : 0;
706 req->idAuthentication->u.idPass->password =
707 *password ? odr_strdup(odr, password) : 0;
713 int Yaz_ProxyConfig::client_authentication(const char *name,
716 const char *password)
718 int ret = YAZPROXY_RET_NOT_ME;
721 ptr = m_cp->find_target_node(name, 0);
724 for (ptr = ptr->children; ptr; ptr = ptr->next)
725 if (ptr->type == XML_ELEMENT_NODE &&
726 !strcmp((const char *) ptr->name, "client-authentication"))
728 struct _xmlAttr *attr;
729 const char *module_name = 0;
730 for (attr = ptr->properties; attr; attr = attr->next)
732 if (!strcmp((const char *) attr->name, "module") &&
733 attr->children && attr->children->type == XML_TEXT_NODE)
734 module_name = (const char *) attr->children->content;
736 Yaz_ProxyModule *m = m_cp->m_modules;
737 for (; m; m = m->get_next())
739 if (m->is_module(module_name))
741 ret = m->authenticate(name, ptr, user, group, password);
742 if (ret != YAZPROXY_RET_NOT_ME)
748 if (ret == YAZPROXY_RET_PERM)
753 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
754 Odr_oid *syntax, Z_RecordComposition *comp,
756 char **stylesheet, char **schema,
758 char **backend_charset,
759 char **usemarcon_ini_stage1,
760 char **usemarcon_ini_stage2
775 xfree (*backend_type);
780 xfree (*backend_charset);
781 *backend_charset = 0;
783 if (usemarcon_ini_stage1)
785 xfree (*usemarcon_ini_stage1);
786 *usemarcon_ini_stage1 = 0;
788 if (usemarcon_ini_stage2)
790 xfree (*usemarcon_ini_stage2);
791 *usemarcon_ini_stage2 = 0;
794 int syntax_has_matched = 0;
797 ptr = m_cp->find_target_node(name, 0);
800 for(ptr = ptr->children; ptr; ptr = ptr->next)
802 if (ptr->type == XML_ELEMENT_NODE &&
803 !strcmp((const char *) ptr->name, "syntax"))
805 int match = 0; // if we match record syntax
806 const char *match_type = 0;
807 const char *match_error = 0;
808 const char *match_marcxml = 0;
809 const char *match_stylesheet = 0;
810 const char *match_identifier = 0;
811 const char *match_backend_type = 0;
812 const char *match_backend_charset = 0;
813 const char *match_usemarcon_ini_stage1 = 0;
814 const char *match_usemarcon_ini_stage2 = 0;
815 struct _xmlAttr *attr;
816 for (attr = ptr->properties; attr; attr = attr->next)
818 if (!strcmp((const char *) attr->name, "type") &&
819 attr->children && attr->children->type == XML_TEXT_NODE)
820 match_type = (const char *) attr->children->content;
821 if (!strcmp((const char *) attr->name, "error") &&
822 attr->children && attr->children->type == XML_TEXT_NODE)
823 match_error = (const char *) attr->children->content;
824 if (!strcmp((const char *) attr->name, "marcxml") &&
825 attr->children && attr->children->type == XML_TEXT_NODE)
826 match_marcxml = (const char *) attr->children->content;
827 if (!strcmp((const char *) attr->name, "stylesheet") &&
828 attr->children && attr->children->type == XML_TEXT_NODE)
829 match_stylesheet = (const char *) attr->children->content;
830 if (!strcmp((const char *) attr->name, "identifier") &&
831 attr->children && attr->children->type == XML_TEXT_NODE)
832 match_identifier = (const char *) attr->children->content;
833 if (!strcmp((const char *) attr->name, "backendtype") &&
834 attr->children && attr->children->type == XML_TEXT_NODE)
835 match_backend_type = (const char *)
836 attr->children->content;
837 if (!strcmp((const char *) attr->name, "backendcharset") &&
838 attr->children && attr->children->type == XML_TEXT_NODE)
839 match_backend_charset = (const char *)
840 attr->children->content;
841 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
842 attr->children && attr->children->type == XML_TEXT_NODE)
843 match_usemarcon_ini_stage1 = (const char *)
844 attr->children->content;
845 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
846 attr->children && attr->children->type == XML_TEXT_NODE)
847 match_usemarcon_ini_stage2 = (const char *)
848 attr->children->content;
852 if (!strcmp(match_type, "*"))
854 else if (!strcmp(match_type, "none"))
861 int match_oid[OID_SIZE];
862 oid_name_to_oid(CLASS_RECSYN, match_type, match_oid);
863 if (oid_oidcmp(match_oid, syntax) == 0)
870 syntax_has_matched = 1;
871 match = m_cp->check_schema(ptr->children, comp,
876 if (stylesheet && match_stylesheet)
879 *stylesheet = xstrdup(match_stylesheet);
881 if (schema && match_identifier)
884 *schema = xstrdup(match_identifier);
886 if (backend_type && match_backend_type)
888 xfree(*backend_type);
889 *backend_type = xstrdup(match_backend_type);
891 if (backend_charset && match_backend_charset)
893 xfree(*backend_charset);
894 *backend_charset = xstrdup(match_backend_charset);
896 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
898 xfree(*usemarcon_ini_stage1);
899 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
901 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
903 xfree(*usemarcon_ini_stage2);
904 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
912 if (syntax_has_matched) // if syntax OK, bad schema/ESN
916 char dotoid_str[100];
917 oid_to_dotstring(syntax, dotoid_str);
918 *addinfo = odr_strdup(odr, dotoid_str);
920 return atoi(match_error);
931 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
938 for (dptr = ptr->children; dptr; dptr = dptr->next)
939 if (dptr->type == XML_ELEMENT_NODE &&
940 !strcmp((const char *) dptr->name, "database"))
942 struct _xmlAttr *attr;
943 for (attr = dptr->properties; attr; attr = attr->next)
944 if (!strcmp((const char *) attr->name, "name"))
947 && attr->children->type==XML_TEXT_NODE
948 && attr->children->content
949 && (!strcmp((const char *) attr->children->content, db)
950 || !strcmp((const char *) attr->children->content,
958 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
963 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
965 if (ptr->type == XML_ELEMENT_NODE &&
966 !strcmp((const char *) ptr->name, "target"))
971 // <target default="1"> ?
972 struct _xmlAttr *attr;
973 for (attr = ptr->properties; attr; attr = attr->next)
974 if (!strcmp((const char *) attr->name, "default") &&
975 attr->children && attr->children->type == XML_TEXT_NODE)
977 xmlChar *t = attr->children->content;
980 return find_target_db(ptr, db);
986 // <target name="name"> ?
987 struct _xmlAttr *attr;
988 for (attr = ptr->properties; attr; attr = attr->next)
989 if (!strcmp((const char *) attr->name, "name"))
992 && attr->children->type==XML_TEXT_NODE
993 && attr->children->content
994 && (!strcmp((const char *) attr->children->content,
996 || !strcmp((const char *) attr->children->content,
999 return find_target_db(ptr, db);
1009 int Yaz_ProxyConfig::get_target_no(int no,
1015 int *target_idletime,
1016 int *client_idletime,
1018 int *keepalive_limit_bw,
1019 int *keepalive_limit_pdu,
1021 const char **cql2rpn,
1022 const char **authentication,
1023 const char **negotiation_charset,
1024 const char **negotiation_lang)
1028 if (!m_cp->m_proxyPtr)
1031 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1032 if (ptr->type == XML_ELEMENT_NODE &&
1033 !strcmp((const char *) ptr->name, "target"))
1037 struct _xmlAttr *attr;
1038 for (attr = ptr->properties; attr; attr = attr->next)
1039 if (!strcmp((const char *) attr->name, "name"))
1042 && attr->children->type==XML_TEXT_NODE
1043 && attr->children->content)
1044 *name = (const char *) attr->children->content;
1046 m_cp->return_target_info(
1048 limit_bw, limit_pdu, limit_req,
1049 target_idletime, client_idletime,
1050 keepalive_limit_bw, keepalive_limit_pdu,
1052 negotiation_charset, negotiation_lang);
1061 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
1063 if (len == strlen(item) && memcmp(hay, item, len) == 0)
1068 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
1073 if (!m_cp->m_proxyPtr)
1075 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1077 if (ptr->type == XML_ELEMENT_NODE
1078 && !strcmp((const char *) ptr->name, "log"))
1080 const char *v = m_cp->get_text(ptr);
1085 while (*cp && *cp != ',' && !isspace(*cp))
1087 size_t len = cp - v;
1088 if (m_cp->mycmp(v, "client-apdu", len))
1089 *log_mask |= PROXY_LOG_APDU_CLIENT;
1090 if (m_cp->mycmp(v, "server-apdu", len))
1091 *log_mask |= PROXY_LOG_APDU_SERVER;
1092 if (m_cp->mycmp(v, "client-requests", len))
1093 *log_mask |= PROXY_LOG_REQ_CLIENT;
1094 if (m_cp->mycmp(v, "server-requests", len))
1095 *log_mask |= PROXY_LOG_REQ_SERVER;
1097 *log_mask |= atoi(v);
1100 while (*cp && isspace(*cp))
1105 if (ptr->type == XML_ELEMENT_NODE &&
1106 !strcmp((const char *) ptr->name, "max-clients"))
1108 const char *t = m_cp->get_text(ptr);
1111 *max_clients = atoi(t);
1112 if (*max_clients < 1)
1121 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1122 xmlNodePtr *ptr_target,
1123 xmlNodePtr *ptr_explain)
1130 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1132 if (ptr->type == XML_ELEMENT_NODE &&
1133 !strcmp((const char *) ptr->name, "target"))
1136 xmlNodePtr ptr = (*ptr_target)->children;
1137 for (; ptr; ptr = ptr->next)
1139 if (ptr->type == XML_ELEMENT_NODE &&
1140 !strcmp((const char *) ptr->name, "explain"))
1143 xmlNodePtr ptr = (*ptr_explain)->children;
1145 for (; ptr; ptr = ptr->next)
1146 if (ptr->type == XML_ELEMENT_NODE &&
1147 !strcmp((const char *) ptr->name, "serverInfo"))
1151 for (ptr = ptr->children; ptr; ptr = ptr->next)
1152 if (ptr->type == XML_ELEMENT_NODE &&
1153 !strcmp((const char *) ptr->name, "database"))
1158 for (ptr = ptr->children; ptr; ptr = ptr->next)
1159 if (ptr->type == XML_TEXT_NODE &&
1161 !strcmp((const char *) ptr->content, db))
1174 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1175 const char **backend_db)
1178 xmlNodePtr ptr_target, ptr_explain;
1179 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1182 struct _xmlAttr *attr;
1183 const char *name = 0;
1185 for (attr = ptr_target->properties; attr; attr = attr->next)
1186 if (!strcmp((const char *) attr->name, "name")
1188 && attr->children->type==XML_TEXT_NODE
1189 && attr->children->content
1190 && attr->children->content[0])
1192 name = (const char *)attr->children->content;
1197 for (attr = ptr_target->properties; attr; attr = attr->next)
1198 if (!strcmp((const char *) attr->name, "database"))
1201 && attr->children->type==XML_TEXT_NODE
1202 && attr->children->content)
1203 *backend_db = (const char *) attr->children->content;
1212 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1213 const char *db, int *len)
1216 xmlNodePtr ptr_target, ptr_explain;
1217 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1219 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1221 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1223 xmlDocSetRootElement(doc, ptr2);
1226 xmlDocDumpMemory(doc, &buf_out, len);
1227 char *content = (char*) odr_malloc(odr, *len);
1228 memcpy(content, buf_out, *len);
1238 void Yaz_ProxyConfig::get_target_info(const char *name,
1243 int *target_idletime,
1244 int *client_idletime,
1246 int *keepalive_limit_bw,
1247 int *keepalive_limit_pdu,
1249 const char **cql2rpn,
1250 const char **negotiation_charset,
1251 const char **negotiation_lang)
1255 if (!m_cp->m_proxyPtr)
1262 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1264 if (ptr->type == XML_ELEMENT_NODE &&
1265 !strcmp((const char *) ptr->name, "max-clients"))
1267 const char *t = m_cp->get_text(ptr);
1270 *max_clients = atoi(t);
1271 if (*max_clients < 1)
1276 ptr = m_cp->find_target_node(name, 0);
1284 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1285 target_idletime, client_idletime,
1286 keepalive_limit_bw, keepalive_limit_pdu,
1288 negotiation_charset, negotiation_lang);