1 /* This file is part of YAZ proxy
2 Copyright (C) 1998-2008 Index Data
4 YAZ proxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <yaz/oid_db.h>
25 class Yaz_ProxyConfigP {
26 friend class Yaz_ProxyConfig;
28 Yaz_ProxyModules m_modules;
29 int mycmp(const char *hay, const char *item, size_t len);
30 int match_list(int v, const char *m);
31 int atoi_l(const char **cp);
33 void load_modules(void);
34 int check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
35 const char *schema_identifier);
37 xmlNodePtr m_proxyPtr;
38 void return_target_info(xmlNodePtr ptr, const char **url,
39 int *limit_bw, int *limit_pdu, int *limit_req,
41 int *target_idletime, int *client_idletime,
43 int *keepalive_limit_bw, int *keepalive_limit_pdu,
44 int *pre_init, const char **cql2rpn,
45 const char **negotiation_charset,
46 const char **negotiation_lang,
47 const char **target_charset,
48 const char **default_client_query_charset);
49 void return_limit(xmlNodePtr ptr,
50 int *limit_bw, int *limit_pdu, int *limit_req,
52 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
54 xmlNodePtr find_target_node(const char *name, const char *db);
55 xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
56 const char *get_text(xmlNodePtr ptr);
57 void get_period(xmlNodePtr ptr, int *period);
58 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
59 Z_AttributeList *attrs,
61 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
63 int get_explain_ptr(const char *host, const char *db,
64 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
70 Yaz_ProxyConfigP::Yaz_ProxyConfigP() : m_modules()
78 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
86 Yaz_ProxyConfig::Yaz_ProxyConfig()
88 m_cp = new Yaz_ProxyConfigP();
91 Yaz_ProxyConfig::~Yaz_ProxyConfig()
97 void Yaz_ProxyConfigP::load_modules()
102 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
105 if (ptr->type == XML_ELEMENT_NODE
106 && !strcmp((const char *) ptr->name, "module")
107 && (fname = get_text(ptr)))
109 m_modules.add_module(fname);
115 int Yaz_ProxyConfig::read_xml(const char *fname)
118 xmlDocPtr ndoc = xmlParseFile(fname);
122 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
123 return -1; // no good
125 int noSubstitutions = xmlXIncludeProcess(ndoc);
126 if (noSubstitutions == -1)
127 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
129 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
130 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
131 strcmp((const char *) proxyPtr->name, "proxy"))
133 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
137 m_cp->m_proxyPtr = proxyPtr;
139 // OK: release previous and make it the current one.
141 xmlFreeDoc(m_cp->m_docPtr);
142 m_cp->m_docPtr = ndoc;
144 m_cp->m_modules.unload_modules();
145 m_cp->load_modules();
153 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
155 for(ptr = ptr->children; ptr; ptr = ptr->next)
156 if (ptr->type == XML_TEXT_NODE)
158 xmlChar *t = ptr->content;
163 return (const char *) t;
169 void Yaz_ProxyConfigP::get_period(xmlNodePtr ptr, int *period)
171 struct _xmlAttr *attr;
173 for (attr = ptr->properties; attr; attr = attr->next)
175 if (!strcmp((const char *) attr->name, "period") &&
176 attr->children && attr->children->type == XML_TEXT_NODE)
177 *period = atoi((const char *) attr->children->content);
183 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
189 for (ptr = ptr->children; ptr; ptr = ptr->next)
191 if (ptr->type == XML_ELEMENT_NODE
192 && !strcmp((const char *) ptr->name, "bandwidth"))
194 const char *t = get_text(ptr);
198 if (ptr->type == XML_ELEMENT_NODE
199 && !strcmp((const char *) ptr->name, "retrieve"))
201 const char *t = get_text(ptr);
203 *limit_req = atoi(t);
205 if (ptr->type == XML_ELEMENT_NODE
206 && !strcmp((const char *) ptr->name, "pdu"))
208 const char *t = get_text(ptr);
210 *limit_pdu = atoi(t);
212 if (ptr->type == XML_ELEMENT_NODE
213 && !strcmp((const char *) ptr->name, "search"))
215 const char *t = get_text(ptr);
217 *limit_search = atoi(t);
224 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
230 int *target_idletime,
231 int *client_idletime,
233 int *keepalive_limit_bw,
234 int *keepalive_limit_pdu,
236 const char **cql2rpn,
237 const char **negotiation_charset,
238 const char **negotiation_lang,
239 const char **target_charset,
240 const char **default_client_query_charset)
245 for (; ptr; ptr = ptr->next)
247 if (ptr->type == XML_ELEMENT_NODE
248 && !strcmp((const char *) ptr->name, "preinit"))
250 const char *v = get_text(ptr);
251 *pre_init = v ? atoi(v) : 1;
253 if (ptr->type == XML_ELEMENT_NODE
254 && !strcmp((const char *) ptr->name, "url"))
256 const char *t = get_text(ptr);
257 if (t && no_url < MAX_ZURL_PLEX)
263 if (ptr->type == XML_ELEMENT_NODE
264 && !strcmp((const char *) ptr->name, "keepalive"))
267 *keepalive_limit_bw = 500000;
268 *keepalive_limit_pdu = 1000;
269 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
272 if (ptr->type == XML_ELEMENT_NODE
273 && !strcmp((const char *) ptr->name, "limit"))
274 return_limit(ptr, limit_bw, limit_pdu, limit_req,
276 if (ptr->type == XML_ELEMENT_NODE
277 && !strcmp((const char *) ptr->name, "target-timeout"))
279 const char *t = get_text(ptr);
282 *target_idletime = atoi(t);
283 if (*target_idletime < 0)
284 *target_idletime = 0;
287 if (ptr->type == XML_ELEMENT_NODE
288 && !strcmp((const char *) ptr->name, "client-timeout"))
290 const char *t = get_text(ptr);
293 *client_idletime = atoi(t);
294 if (*client_idletime < 0)
295 *client_idletime = 0;
298 if (ptr->type == XML_ELEMENT_NODE
299 && !strcmp((const char *) ptr->name, "max-sockets"))
301 const char *t = get_text(ptr);
302 if (t && max_sockets)
304 *max_sockets = atoi(t);
307 if (ptr->type == XML_ELEMENT_NODE
308 && !strcmp((const char *) ptr->name, "cql2rpn"))
310 const char *t = get_text(ptr);
314 if (ptr->type == XML_ELEMENT_NODE
315 && !strcmp((const char *) ptr->name, "target-charset"))
317 const char *t = get_text(ptr);
318 if (t && target_charset)
321 if (ptr->type == XML_ELEMENT_NODE
322 && !strcmp((const char *) ptr->name, "default-client-charset"))
324 const char *t = get_text(ptr);
325 if (t && default_client_query_charset)
326 *default_client_query_charset = t;
328 if (ptr->type == XML_ELEMENT_NODE
329 && !strcmp((const char *) ptr->name, "negotiation-charset"))
331 const char *t = get_text(ptr);
333 *negotiation_charset = t;
335 if (ptr->type == XML_ELEMENT_NODE
336 && !strcmp((const char *) ptr->name, "negotiation-lang"))
338 const char *t = get_text(ptr);
340 *negotiation_lang = t;
346 int Yaz_ProxyConfigP::atoi_l(const char **cp)
349 while (**cp && isdigit(**cp))
351 v = v*10 + (**cp - '0');
357 int Yaz_ProxyConfigP::match_list(int v, const char *m)
361 while(*m && isspace(*m))
372 if (v >= l && v <= h)
381 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
382 Z_AttributeList *attrs,
386 for (i = 0; i<attrs->num_attributes; i++)
388 Z_AttributeElement *el = attrs->attributes[i];
390 if (!el->attributeType)
392 int type = *el->attributeType;
395 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
396 value = el->value.numeric;
399 for(ptr = ptrl->children; ptr; ptr = ptr->next)
401 if (ptr->type == XML_ELEMENT_NODE &&
402 !strcmp((const char *) ptr->name, "attribute"))
404 const char *match_type = 0;
405 const char *match_value = 0;
406 const char *match_error = 0;
407 struct _xmlAttr *attr;
408 for (attr = ptr->properties; attr; attr = attr->next)
410 if (!strcmp((const char *) attr->name, "type") &&
411 attr->children && attr->children->type == XML_TEXT_NODE)
412 match_type = (const char *) attr->children->content;
413 if (!strcmp((const char *) attr->name, "value") &&
414 attr->children && attr->children->type == XML_TEXT_NODE)
415 match_value = (const char *) attr->children->content;
416 if (!strcmp((const char *) attr->name, "error") &&
417 attr->children && attr->children->type == XML_TEXT_NODE)
418 match_error = (const char *) attr->children->content;
420 if (match_type && match_value)
422 char addinfo_str[20];
423 if (!match_list(type, match_type))
427 if (!strcmp(match_type, "*"))
428 sprintf (addinfo_str, "%d", type);
431 if (!match_list(*value, match_value))
433 sprintf (addinfo_str, "%d", *value);
441 *addinfo = odr_strdup(odr, addinfo_str);
442 return atoi(match_error);
454 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
458 if (q->which == Z_RPNStructure_complex)
460 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
463 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
466 else if (q->which == Z_RPNStructure_simple)
468 if (q->u.simple->which == Z_Operand_APT)
470 return check_type_1_attributes(
471 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
480 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
483 // possibly check for Bib-1
484 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
488 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
494 ptr = m_cp->find_target_node(name, 0);
497 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
498 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
505 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
506 const char *schema_identifier)
509 int default_match = 1;
510 if (comp && comp->which == Z_RecordComp_simple &&
511 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
513 esn = comp->u.simple->u.generic;
515 // if no ESN/schema was given accept..
518 // check if schema identifier match
519 if (schema_identifier && !strcmp(esn, schema_identifier))
521 // Check each name element
522 for (; ptr; ptr = ptr->next)
524 if (ptr->type == XML_ELEMENT_NODE
525 && !strcmp((const char *) ptr->name, "name"))
527 xmlNodePtr tptr = ptr->children;
529 for (; tptr; tptr = tptr->next)
530 if (tptr->type == XML_TEXT_NODE && tptr->content)
532 xmlChar *t = tptr->content;
533 while (*t && isspace(*t))
536 while (esn[i] && esn[i] == t[i])
538 if (!esn[i] && (!t[i] || isspace(t[i])))
543 return default_match;
547 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
553 {".xml", "text/xml"},
554 {".xsl", "text/xml"},
555 {".tkl", "text/xml"},
556 {".xsd", "text/xml"},
557 {".html", "text/html"},
558 {".jpg", "image/jpeg"},
559 {".png", "image/png"},
560 {".gif", "image/gif"},
561 {".css", "text/css"},
562 {".pdf", "application/pdf"},
567 size_t plen = strlen (path);
568 for (i = 0; types[i].type; i++)
569 if (types[i].mask == 0)
570 return types[i].type;
573 size_t mlen = strlen(types[i].mask);
574 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
575 return types[i].type;
577 return "application/octet-stream";
581 void Yaz_ProxyConfig::target_authentication(const char *name,
582 ODR odr, Z_InitRequest *req)
585 xmlNodePtr ptr = m_cp->find_target_node(name, 0);
589 for (ptr = ptr->children; ptr; ptr = ptr->next)
590 if (ptr->type == XML_ELEMENT_NODE &&
591 !strcmp((const char *) ptr->name, "target-authentication"))
593 struct _xmlAttr *attr;
594 const char *type = "open";
595 for (attr = ptr->properties; attr; attr = attr->next)
597 if (!strcmp((const char *) attr->name, "type") &&
598 attr->children && attr->children->type == XML_TEXT_NODE)
599 type = (const char *) attr->children->content;
601 const char *t = m_cp->get_text(ptr);
602 if (!t || !strcmp(type, "none"))
604 req->idAuthentication = 0;
606 else if (!strcmp(type, "anonymous"))
608 req->idAuthentication =
609 (Z_IdAuthentication *)
610 odr_malloc (odr, sizeof(*req->idAuthentication));
611 req->idAuthentication->which =
612 Z_IdAuthentication_anonymous;
613 req->idAuthentication->u.anonymous = odr_nullval();
615 else if (!strcmp(type, "open"))
617 req->idAuthentication =
618 (Z_IdAuthentication *)
619 odr_malloc (odr, sizeof(*req->idAuthentication));
620 req->idAuthentication->which =
621 Z_IdAuthentication_open;
622 req->idAuthentication->u.open = odr_strdup (odr, t);
624 else if (!strcmp(type, "idPass"))
626 char user[64], group[64], password[64];
630 sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
632 req->idAuthentication =
633 (Z_IdAuthentication *)
634 odr_malloc (odr, sizeof(*req->idAuthentication));
635 req->idAuthentication->which =
636 Z_IdAuthentication_idPass;
637 req->idAuthentication->u.idPass =
638 (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
639 req->idAuthentication->u.idPass->userId =
640 *user ? odr_strdup(odr, user) : 0;
641 req->idAuthentication->u.idPass->groupId =
642 *group ? odr_strdup(odr, group) : 0;
643 req->idAuthentication->u.idPass->password =
644 *password ? odr_strdup(odr, password) : 0;
650 int Yaz_ProxyConfig::client_authentication(const char *name,
653 const char *password,
656 int ret = YAZPROXY_RET_NOT_ME;
659 ptr = m_cp->find_target_node(name, 0);
662 for (ptr = ptr->children; ptr; ptr = ptr->next)
663 if (ptr->type == XML_ELEMENT_NODE &&
664 !strcmp((const char *) ptr->name, "client-authentication"))
666 struct _xmlAttr *attr;
667 const char *module_name = 0;
668 for (attr = ptr->properties; attr; attr = attr->next)
670 if (!strcmp((const char *) attr->name, "module") &&
671 attr->children && attr->children->type == XML_TEXT_NODE)
672 module_name = (const char *) attr->children->content;
674 ret = m_cp->m_modules.authenticate(module_name,
676 user, group, password,
679 if (ret != YAZPROXY_RET_NOT_ME)
683 if (ret == YAZPROXY_RET_PERM)
688 int Yaz_ProxyConfig::global_client_authentication(const char *user,
690 const char *password,
693 int ret = YAZPROXY_RET_NOT_ME;
695 if (!m_cp->m_proxyPtr)
698 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
700 if (ptr->type == XML_ELEMENT_NODE &&
701 !strcmp((const char *) ptr->name, "client-authentication"))
703 struct _xmlAttr *attr;
704 const char *module_name = 0;
705 for (attr = ptr->properties; attr; attr = attr->next)
707 if (!strcmp((const char *) attr->name, "module") &&
708 attr->children && attr->children->type == XML_TEXT_NODE)
709 module_name = (const char *) attr->children->content;
711 ret = m_cp->m_modules.authenticate(module_name,
713 user, group, password,
716 if (ret != YAZPROXY_RET_NOT_ME)
721 if (ret == YAZPROXY_RET_PERM)
726 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
727 Odr_oid *syntax, Z_RecordComposition *comp,
729 char **stylesheet, char **schema,
731 char **backend_charset,
732 char **usemarcon_ini_stage1,
733 char **usemarcon_ini_stage2
748 xfree (*backend_type);
753 xfree (*backend_charset);
754 *backend_charset = 0;
756 if (usemarcon_ini_stage1)
758 xfree (*usemarcon_ini_stage1);
759 *usemarcon_ini_stage1 = 0;
761 if (usemarcon_ini_stage2)
763 xfree (*usemarcon_ini_stage2);
764 *usemarcon_ini_stage2 = 0;
767 int syntax_has_matched = 0;
770 ptr = m_cp->find_target_node(name, 0);
773 for(ptr = ptr->children; ptr; ptr = ptr->next)
775 if (ptr->type == XML_ELEMENT_NODE &&
776 !strcmp((const char *) ptr->name, "syntax"))
778 int match = 0; // if we match record syntax
779 const char *match_type = 0;
780 const char *match_error = 0;
781 const char *match_marcxml = 0;
782 const char *match_stylesheet = 0;
783 const char *match_identifier = 0;
784 const char *match_backend_type = 0;
785 const char *match_backend_charset = 0;
786 const char *match_usemarcon_ini_stage1 = 0;
787 const char *match_usemarcon_ini_stage2 = 0;
788 struct _xmlAttr *attr;
789 for (attr = ptr->properties; attr; attr = attr->next)
791 if (!strcmp((const char *) attr->name, "type") &&
792 attr->children && attr->children->type == XML_TEXT_NODE)
793 match_type = (const char *) attr->children->content;
794 if (!strcmp((const char *) attr->name, "error") &&
795 attr->children && attr->children->type == XML_TEXT_NODE)
796 match_error = (const char *) attr->children->content;
797 if (!strcmp((const char *) attr->name, "marcxml") &&
798 attr->children && attr->children->type == XML_TEXT_NODE)
799 match_marcxml = (const char *) attr->children->content;
800 if (!strcmp((const char *) attr->name, "stylesheet") &&
801 attr->children && attr->children->type == XML_TEXT_NODE)
802 match_stylesheet = (const char *) attr->children->content;
803 if (!strcmp((const char *) attr->name, "identifier") &&
804 attr->children && attr->children->type == XML_TEXT_NODE)
805 match_identifier = (const char *) attr->children->content;
806 if (!strcmp((const char *) attr->name, "backendtype") &&
807 attr->children && attr->children->type == XML_TEXT_NODE)
808 match_backend_type = (const char *)
809 attr->children->content;
810 if (!strcmp((const char *) attr->name, "backendcharset") &&
811 attr->children && attr->children->type == XML_TEXT_NODE)
812 match_backend_charset = (const char *)
813 attr->children->content;
814 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
815 attr->children && attr->children->type == XML_TEXT_NODE)
816 match_usemarcon_ini_stage1 = (const char *)
817 attr->children->content;
818 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
819 attr->children && attr->children->type == XML_TEXT_NODE)
820 match_usemarcon_ini_stage2 = (const char *)
821 attr->children->content;
825 if (!strcmp(match_type, "*"))
827 else if (!strcmp(match_type, "none"))
835 = yaz_string_to_oid_odr(yaz_oid_std(),
836 CLASS_RECSYN, match_type,
838 if (oid_oidcmp(match_oid, syntax) == 0)
845 syntax_has_matched = 1;
846 match = m_cp->check_schema(ptr->children, comp,
851 if (stylesheet && match_stylesheet)
854 *stylesheet = xstrdup(match_stylesheet);
856 if (schema && match_identifier)
859 *schema = xstrdup(match_identifier);
861 if (backend_type && match_backend_type)
863 xfree(*backend_type);
864 *backend_type = xstrdup(match_backend_type);
866 if (backend_charset && match_backend_charset)
868 xfree(*backend_charset);
869 *backend_charset = xstrdup(match_backend_charset);
871 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
873 xfree(*usemarcon_ini_stage1);
874 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
876 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
878 xfree(*usemarcon_ini_stage2);
879 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
887 if (syntax_has_matched) // if syntax OK, bad schema/ESN
891 char dotoid_str[OID_STR_MAX];
892 oid_oid_to_dotstring(syntax, dotoid_str);
893 *addinfo = odr_strdup(odr, dotoid_str);
895 return atoi(match_error);
906 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
913 for (dptr = ptr->children; dptr; dptr = dptr->next)
914 if (dptr->type == XML_ELEMENT_NODE &&
915 !strcmp((const char *) dptr->name, "database"))
917 struct _xmlAttr *attr;
918 for (attr = dptr->properties; attr; attr = attr->next)
919 if (!strcmp((const char *) attr->name, "name"))
922 && attr->children->type==XML_TEXT_NODE
923 && attr->children->content
924 && (!strcmp((const char *) attr->children->content, db)
925 || !strcmp((const char *) attr->children->content,
933 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
938 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
940 if (ptr->type == XML_ELEMENT_NODE &&
941 !strcmp((const char *) ptr->name, "target"))
946 // <target default="1"> ?
947 struct _xmlAttr *attr;
948 for (attr = ptr->properties; attr; attr = attr->next)
949 if (!strcmp((const char *) attr->name, "default") &&
950 attr->children && attr->children->type == XML_TEXT_NODE)
952 xmlChar *t = attr->children->content;
955 return find_target_db(ptr, db);
961 // <target name="name"> ?
962 struct _xmlAttr *attr;
963 for (attr = ptr->properties; attr; attr = attr->next)
964 if (!strcmp((const char *) attr->name, "name"))
967 && attr->children->type==XML_TEXT_NODE
968 && attr->children->content
969 && (!strcmp((const char *) attr->children->content,
971 || !strcmp((const char *) attr->children->content,
974 return find_target_db(ptr, db);
984 int Yaz_ProxyConfig::get_target_no(int no,
991 int *target_idletime,
992 int *client_idletime,
995 int *keepalive_limit_bw,
996 int *keepalive_limit_pdu,
998 const char **cql2rpn,
999 const char **authentication,
1000 const char **negotiation_charset,
1001 const char **negotiation_lang,
1002 const char **target_charset,
1003 const char **default_client_query_charset)
1007 if (!m_cp->m_proxyPtr)
1010 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1011 if (ptr->type == XML_ELEMENT_NODE &&
1012 !strcmp((const char *) ptr->name, "target"))
1016 struct _xmlAttr *attr;
1017 for (attr = ptr->properties; attr; attr = attr->next)
1018 if (!strcmp((const char *) attr->name, "name"))
1021 && attr->children->type==XML_TEXT_NODE
1022 && attr->children->content)
1023 *name = (const char *) attr->children->content;
1025 m_cp->return_target_info(
1027 limit_bw, limit_pdu, limit_req,
1029 target_idletime, client_idletime,
1031 keepalive_limit_bw, keepalive_limit_pdu,
1033 negotiation_charset, negotiation_lang, target_charset,
1034 default_client_query_charset);
1043 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
1045 if (len == strlen(item) && memcmp(hay, item, len) == 0)
1050 int Yaz_ProxyConfig::get_file_access_info(const char *path)
1054 if (!m_cp->m_proxyPtr)
1056 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1058 if (ptr->type == XML_ELEMENT_NODE
1059 && !strcmp((const char *) ptr->name, "docpath"))
1061 const char *docpath = m_cp->get_text(ptr);
1062 size_t docpath_len = strlen(docpath);
1063 if (docpath_len < strlen(path) && path[docpath_len] == '/'
1064 && !memcmp(docpath, path, docpath_len))
1072 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
1076 int *period_connect,
1077 int *num_msg_threads)
1081 *num_msg_threads = 0;
1084 if (!m_cp->m_proxyPtr)
1086 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1088 if (ptr->type == XML_ELEMENT_NODE
1089 && !strcmp((const char *) ptr->name, "log"))
1091 const char *v = m_cp->get_text(ptr);
1096 while (*cp && *cp != ',' && !isspace(*cp))
1098 size_t len = cp - v;
1099 if (m_cp->mycmp(v, "client-apdu", len))
1100 *log_mask |= PROXY_LOG_APDU_CLIENT;
1101 if (m_cp->mycmp(v, "server-apdu", len))
1102 *log_mask |= PROXY_LOG_APDU_SERVER;
1103 if (m_cp->mycmp(v, "client-requests", len))
1104 *log_mask |= PROXY_LOG_REQ_CLIENT;
1105 if (m_cp->mycmp(v, "server-requests", len))
1106 *log_mask |= PROXY_LOG_REQ_SERVER;
1107 if (m_cp->mycmp(v, "client-ip", len))
1108 *log_mask |= PROXY_LOG_IP_CLIENT;
1110 *log_mask |= atoi(v);
1113 while (*cp && isspace(*cp))
1118 else if (ptr->type == XML_ELEMENT_NODE &&
1119 !strcmp((const char *) ptr->name, "max-clients"))
1121 const char *t = m_cp->get_text(ptr);
1124 *max_clients = atoi(t);
1125 if (*max_clients < 1)
1129 else if (ptr->type == XML_ELEMENT_NODE &&
1130 !strcmp((const char *) ptr->name, "period-connect"))
1132 const char *t = m_cp->get_text(ptr);
1134 *period_connect = atoi(t);
1136 else if (ptr->type == XML_ELEMENT_NODE &&
1137 !strcmp((const char *) ptr->name, "max-connect"))
1139 const char *t = m_cp->get_text(ptr);
1142 *max_connect = atoi(t);
1145 else if (ptr->type == XML_ELEMENT_NODE &&
1146 !strcmp((const char *) ptr->name, "limit-connect"))
1148 const char *t = m_cp->get_text(ptr);
1151 *limit_connect = atoi(t);
1154 else if (ptr->type == XML_ELEMENT_NODE &&
1155 !strcmp((const char *) ptr->name, "target"))
1157 else if (ptr->type == XML_ELEMENT_NODE &&
1158 !strcmp((const char *) ptr->name, "docpath"))
1160 else if (ptr->type == XML_ELEMENT_NODE &&
1161 !strcmp((const char *) ptr->name, "module"))
1163 else if (ptr->type == XML_ELEMENT_NODE &&
1164 !strcmp((const char *) ptr->name, "client-authentication"))
1166 else if (ptr->type == XML_ELEMENT_NODE &&
1167 !strcmp((const char *) ptr->name, "threads"))
1169 const char *t = m_cp->get_text(ptr);
1172 *num_msg_threads = atoi(t);
1175 else if (ptr->type == XML_ELEMENT_NODE)
1177 yaz_log(YLOG_WARN, "0 Unknown element %s in yazproxy config",
1185 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1186 xmlNodePtr *ptr_target,
1187 xmlNodePtr *ptr_explain)
1194 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1196 if (ptr->type == XML_ELEMENT_NODE &&
1197 !strcmp((const char *) ptr->name, "target"))
1200 xmlNodePtr ptr = (*ptr_target)->children;
1201 for (; ptr; ptr = ptr->next)
1203 if (ptr->type == XML_ELEMENT_NODE &&
1204 !strcmp((const char *) ptr->name, "explain"))
1207 xmlNodePtr ptr = (*ptr_explain)->children;
1209 for (; ptr; ptr = ptr->next)
1210 if (ptr->type == XML_ELEMENT_NODE &&
1211 !strcmp((const char *) ptr->name, "serverInfo"))
1215 for (ptr = ptr->children; ptr; ptr = ptr->next)
1216 if (ptr->type == XML_ELEMENT_NODE &&
1217 !strcmp((const char *) ptr->name, "database"))
1222 for (ptr = ptr->children; ptr; ptr = ptr->next)
1223 if (ptr->type == XML_TEXT_NODE &&
1225 !strcmp((const char *) ptr->content, db))
1238 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1239 const char **backend_db)
1242 xmlNodePtr ptr_target, ptr_explain;
1243 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1246 struct _xmlAttr *attr;
1247 const char *name = 0;
1249 for (attr = ptr_target->properties; attr; attr = attr->next)
1250 if (!strcmp((const char *) attr->name, "name")
1252 && attr->children->type==XML_TEXT_NODE
1253 && attr->children->content
1254 && attr->children->content[0])
1256 name = (const char *)attr->children->content;
1261 for (attr = ptr_target->properties; attr; attr = attr->next)
1262 if (!strcmp((const char *) attr->name, "database"))
1265 && attr->children->type==XML_TEXT_NODE
1266 && attr->children->content)
1267 *backend_db = (const char *) attr->children->content;
1276 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1277 const char *db, int *len)
1280 xmlNodePtr ptr_target, ptr_explain;
1281 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1283 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1285 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1287 xmlDocSetRootElement(doc, ptr2);
1290 xmlDocDumpMemory(doc, &buf_out, len);
1291 char *content = (char*) odr_malloc(odr, *len);
1292 memcpy(content, buf_out, *len);
1302 void Yaz_ProxyConfig::get_target_info(const char *name,
1308 int *target_idletime,
1309 int *client_idletime,
1312 int *keepalive_limit_bw,
1313 int *keepalive_limit_pdu,
1315 const char **cql2rpn,
1316 const char **negotiation_charset,
1317 const char **negotiation_lang,
1318 const char **target_charset,
1319 const char **default_client_query_charset)
1323 if (!m_cp->m_proxyPtr)
1330 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1332 if (ptr->type == XML_ELEMENT_NODE &&
1333 !strcmp((const char *) ptr->name, "max-clients"))
1335 const char *t = m_cp->get_text(ptr);
1338 *max_clients = atoi(t);
1339 if (*max_clients < 1)
1344 ptr = m_cp->find_target_node(name, 0);
1352 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1354 target_idletime, client_idletime,
1356 keepalive_limit_bw, keepalive_limit_pdu,
1358 negotiation_charset, negotiation_lang,
1360 default_client_query_charset);
1372 * indent-tabs-mode: nil
1374 * vim: shiftwidth=4 tabstop=8 expandtab