1 /* $Id: yaz-proxy-config.cpp,v 1.37 2007-05-08 12:05:09 adam Exp $
2 Copyright (c) 1998-2007, Index Data.
4 This file is part of the yazproxy.
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
26 #include <yaz/oid_db.h>
28 class Yaz_ProxyConfigP {
29 friend class Yaz_ProxyConfig;
31 Yaz_ProxyModules m_modules;
32 int mycmp(const char *hay, const char *item, size_t len);
33 int match_list(int v, const char *m);
34 int atoi_l(const char **cp);
36 void load_modules(void);
37 int check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
38 const char *schema_identifier);
40 xmlNodePtr m_proxyPtr;
41 void return_target_info(xmlNodePtr ptr, const char **url,
42 int *limit_bw, int *limit_pdu, int *limit_req,
44 int *target_idletime, int *client_idletime,
46 int *keepalive_limit_bw, int *keepalive_limit_pdu,
47 int *pre_init, const char **cql2rpn,
48 const char **negotiation_charset,
49 const char **negotiation_lang,
50 const char **target_charset,
51 const char **default_client_query_charset);
52 void return_limit(xmlNodePtr ptr,
53 int *limit_bw, int *limit_pdu, int *limit_req,
55 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
57 xmlNodePtr find_target_node(const char *name, const char *db);
58 xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
59 const char *get_text(xmlNodePtr ptr);
60 void get_period(xmlNodePtr ptr, int *period);
61 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
62 Z_AttributeList *attrs,
64 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
66 int get_explain_ptr(const char *host, const char *db,
67 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
73 Yaz_ProxyConfigP::Yaz_ProxyConfigP() : m_modules()
81 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
89 Yaz_ProxyConfig::Yaz_ProxyConfig()
91 m_cp = new Yaz_ProxyConfigP();
94 Yaz_ProxyConfig::~Yaz_ProxyConfig()
100 void Yaz_ProxyConfigP::load_modules()
105 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
108 if (ptr->type == XML_ELEMENT_NODE
109 && !strcmp((const char *) ptr->name, "module")
110 && (fname = get_text(ptr)))
112 m_modules.add_module(fname);
118 int Yaz_ProxyConfig::read_xml(const char *fname)
121 xmlDocPtr ndoc = xmlParseFile(fname);
125 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
126 return -1; // no good
128 int noSubstitutions = xmlXIncludeProcess(ndoc);
129 if (noSubstitutions == -1)
130 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
132 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
133 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
134 strcmp((const char *) proxyPtr->name, "proxy"))
136 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
140 m_cp->m_proxyPtr = proxyPtr;
142 // OK: release previous and make it the current one.
144 xmlFreeDoc(m_cp->m_docPtr);
145 m_cp->m_docPtr = ndoc;
147 m_cp->m_modules.unload_modules();
148 m_cp->load_modules();
156 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
158 for(ptr = ptr->children; ptr; ptr = ptr->next)
159 if (ptr->type == XML_TEXT_NODE)
161 xmlChar *t = ptr->content;
166 return (const char *) t;
172 void Yaz_ProxyConfigP::get_period(xmlNodePtr ptr, int *period)
174 struct _xmlAttr *attr;
176 for (attr = ptr->properties; attr; attr = attr->next)
178 if (!strcmp((const char *) attr->name, "period") &&
179 attr->children && attr->children->type == XML_TEXT_NODE)
180 *period = atoi((const char *) attr->children->content);
186 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
192 for (ptr = ptr->children; ptr; ptr = ptr->next)
194 if (ptr->type == XML_ELEMENT_NODE
195 && !strcmp((const char *) ptr->name, "bandwidth"))
197 const char *t = get_text(ptr);
201 if (ptr->type == XML_ELEMENT_NODE
202 && !strcmp((const char *) ptr->name, "retrieve"))
204 const char *t = get_text(ptr);
206 *limit_req = atoi(t);
208 if (ptr->type == XML_ELEMENT_NODE
209 && !strcmp((const char *) ptr->name, "pdu"))
211 const char *t = get_text(ptr);
213 *limit_pdu = atoi(t);
215 if (ptr->type == XML_ELEMENT_NODE
216 && !strcmp((const char *) ptr->name, "search"))
218 const char *t = get_text(ptr);
220 *limit_search = atoi(t);
227 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
233 int *target_idletime,
234 int *client_idletime,
236 int *keepalive_limit_bw,
237 int *keepalive_limit_pdu,
239 const char **cql2rpn,
240 const char **negotiation_charset,
241 const char **negotiation_lang,
242 const char **target_charset,
243 const char **default_client_query_charset)
248 for (; ptr; ptr = ptr->next)
250 if (ptr->type == XML_ELEMENT_NODE
251 && !strcmp((const char *) ptr->name, "preinit"))
253 const char *v = get_text(ptr);
254 *pre_init = v ? atoi(v) : 1;
256 if (ptr->type == XML_ELEMENT_NODE
257 && !strcmp((const char *) ptr->name, "url"))
259 const char *t = get_text(ptr);
260 if (t && no_url < MAX_ZURL_PLEX)
266 if (ptr->type == XML_ELEMENT_NODE
267 && !strcmp((const char *) ptr->name, "keepalive"))
270 *keepalive_limit_bw = 500000;
271 *keepalive_limit_pdu = 1000;
272 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
275 if (ptr->type == XML_ELEMENT_NODE
276 && !strcmp((const char *) ptr->name, "limit"))
277 return_limit(ptr, limit_bw, limit_pdu, limit_req,
279 if (ptr->type == XML_ELEMENT_NODE
280 && !strcmp((const char *) ptr->name, "target-timeout"))
282 const char *t = get_text(ptr);
285 *target_idletime = atoi(t);
286 if (*target_idletime < 0)
287 *target_idletime = 0;
290 if (ptr->type == XML_ELEMENT_NODE
291 && !strcmp((const char *) ptr->name, "client-timeout"))
293 const char *t = get_text(ptr);
296 *client_idletime = atoi(t);
297 if (*client_idletime < 0)
298 *client_idletime = 0;
301 if (ptr->type == XML_ELEMENT_NODE
302 && !strcmp((const char *) ptr->name, "max-sockets"))
304 const char *t = get_text(ptr);
305 if (t && max_sockets)
307 *max_sockets = atoi(t);
310 if (ptr->type == XML_ELEMENT_NODE
311 && !strcmp((const char *) ptr->name, "cql2rpn"))
313 const char *t = get_text(ptr);
317 if (ptr->type == XML_ELEMENT_NODE
318 && !strcmp((const char *) ptr->name, "target-charset"))
320 const char *t = get_text(ptr);
321 if (t && target_charset)
324 if (ptr->type == XML_ELEMENT_NODE
325 && !strcmp((const char *) ptr->name, "default-client-charset"))
327 const char *t = get_text(ptr);
328 if (t && default_client_query_charset)
329 *default_client_query_charset = t;
331 if (ptr->type == XML_ELEMENT_NODE
332 && !strcmp((const char *) ptr->name, "negotiation-charset"))
334 const char *t = get_text(ptr);
336 *negotiation_charset = t;
338 if (ptr->type == XML_ELEMENT_NODE
339 && !strcmp((const char *) ptr->name, "negotiation-lang"))
341 const char *t = get_text(ptr);
343 *negotiation_lang = t;
349 int Yaz_ProxyConfigP::atoi_l(const char **cp)
352 while (**cp && isdigit(**cp))
354 v = v*10 + (**cp - '0');
360 int Yaz_ProxyConfigP::match_list(int v, const char *m)
364 while(*m && isspace(*m))
375 if (v >= l && v <= h)
384 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
385 Z_AttributeList *attrs,
389 for (i = 0; i<attrs->num_attributes; i++)
391 Z_AttributeElement *el = attrs->attributes[i];
393 if (!el->attributeType)
395 int type = *el->attributeType;
398 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
399 value = el->value.numeric;
402 for(ptr = ptrl->children; ptr; ptr = ptr->next)
404 if (ptr->type == XML_ELEMENT_NODE &&
405 !strcmp((const char *) ptr->name, "attribute"))
407 const char *match_type = 0;
408 const char *match_value = 0;
409 const char *match_error = 0;
410 struct _xmlAttr *attr;
411 for (attr = ptr->properties; attr; attr = attr->next)
413 if (!strcmp((const char *) attr->name, "type") &&
414 attr->children && attr->children->type == XML_TEXT_NODE)
415 match_type = (const char *) attr->children->content;
416 if (!strcmp((const char *) attr->name, "value") &&
417 attr->children && attr->children->type == XML_TEXT_NODE)
418 match_value = (const char *) attr->children->content;
419 if (!strcmp((const char *) attr->name, "error") &&
420 attr->children && attr->children->type == XML_TEXT_NODE)
421 match_error = (const char *) attr->children->content;
423 if (match_type && match_value)
425 char addinfo_str[20];
426 if (!match_list(type, match_type))
430 if (!strcmp(match_type, "*"))
431 sprintf (addinfo_str, "%d", type);
434 if (!match_list(*value, match_value))
436 sprintf (addinfo_str, "%d", *value);
444 *addinfo = odr_strdup(odr, addinfo_str);
445 return atoi(match_error);
457 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
461 if (q->which == Z_RPNStructure_complex)
463 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
466 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
469 else if (q->which == Z_RPNStructure_simple)
471 if (q->u.simple->which == Z_Operand_APT)
473 return check_type_1_attributes(
474 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
483 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
486 // possibly check for Bib-1
487 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
491 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
497 ptr = m_cp->find_target_node(name, 0);
500 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
501 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
508 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
509 const char *schema_identifier)
512 int default_match = 1;
513 if (comp && comp->which == Z_RecordComp_simple &&
514 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
516 esn = comp->u.simple->u.generic;
518 // if no ESN/schema was given accept..
521 // check if schema identifier match
522 if (schema_identifier && !strcmp(esn, schema_identifier))
524 // Check each name element
525 for (; ptr; ptr = ptr->next)
527 if (ptr->type == XML_ELEMENT_NODE
528 && !strcmp((const char *) ptr->name, "name"))
530 xmlNodePtr tptr = ptr->children;
532 for (; tptr; tptr = tptr->next)
533 if (tptr->type == XML_TEXT_NODE && tptr->content)
535 xmlChar *t = tptr->content;
536 while (*t && isspace(*t))
539 while (esn[i] && esn[i] == t[i])
541 if (!esn[i] && (!t[i] || isspace(t[i])))
546 return default_match;
550 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
556 {".xml", "text/xml"},
557 {".xsl", "text/xml"},
558 {".tkl", "text/xml"},
559 {".xsd", "text/xml"},
560 {".html", "text/html"},
561 {".jpg", "image/jpeg"},
562 {".png", "image/png"},
563 {".gif", "image/gif"},
564 {".css", "text/css"},
565 {".pdf", "application/pdf"},
570 size_t plen = strlen (path);
571 for (i = 0; types[i].type; i++)
572 if (types[i].mask == 0)
573 return types[i].type;
576 size_t mlen = strlen(types[i].mask);
577 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
578 return types[i].type;
580 return "application/octet-stream";
584 void Yaz_ProxyConfig::target_authentication(const char *name,
585 ODR odr, Z_InitRequest *req)
588 xmlNodePtr ptr = m_cp->find_target_node(name, 0);
592 for (ptr = ptr->children; ptr; ptr = ptr->next)
593 if (ptr->type == XML_ELEMENT_NODE &&
594 !strcmp((const char *) ptr->name, "target-authentication"))
596 struct _xmlAttr *attr;
597 const char *type = "open";
598 for (attr = ptr->properties; attr; attr = attr->next)
600 if (!strcmp((const char *) attr->name, "type") &&
601 attr->children && attr->children->type == XML_TEXT_NODE)
602 type = (const char *) attr->children->content;
604 const char *t = m_cp->get_text(ptr);
605 if (!t || !strcmp(type, "none"))
607 req->idAuthentication = 0;
609 else if (!strcmp(type, "anonymous"))
611 req->idAuthentication =
612 (Z_IdAuthentication *)
613 odr_malloc (odr, sizeof(*req->idAuthentication));
614 req->idAuthentication->which =
615 Z_IdAuthentication_anonymous;
616 req->idAuthentication->u.anonymous = odr_nullval();
618 else if (!strcmp(type, "open"))
620 req->idAuthentication =
621 (Z_IdAuthentication *)
622 odr_malloc (odr, sizeof(*req->idAuthentication));
623 req->idAuthentication->which =
624 Z_IdAuthentication_open;
625 req->idAuthentication->u.open = odr_strdup (odr, t);
627 else if (!strcmp(type, "idPass"))
629 char user[64], group[64], password[64];
633 sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
635 req->idAuthentication =
636 (Z_IdAuthentication *)
637 odr_malloc (odr, sizeof(*req->idAuthentication));
638 req->idAuthentication->which =
639 Z_IdAuthentication_idPass;
640 req->idAuthentication->u.idPass =
641 (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
642 req->idAuthentication->u.idPass->userId =
643 *user ? odr_strdup(odr, user) : 0;
644 req->idAuthentication->u.idPass->groupId =
645 *group ? odr_strdup(odr, group) : 0;
646 req->idAuthentication->u.idPass->password =
647 *password ? odr_strdup(odr, password) : 0;
653 int Yaz_ProxyConfig::client_authentication(const char *name,
656 const char *password,
659 int ret = YAZPROXY_RET_NOT_ME;
662 ptr = m_cp->find_target_node(name, 0);
665 for (ptr = ptr->children; ptr; ptr = ptr->next)
666 if (ptr->type == XML_ELEMENT_NODE &&
667 !strcmp((const char *) ptr->name, "client-authentication"))
669 struct _xmlAttr *attr;
670 const char *module_name = 0;
671 for (attr = ptr->properties; attr; attr = attr->next)
673 if (!strcmp((const char *) attr->name, "module") &&
674 attr->children && attr->children->type == XML_TEXT_NODE)
675 module_name = (const char *) attr->children->content;
677 ret = m_cp->m_modules.authenticate(module_name,
679 user, group, password,
682 if (ret != YAZPROXY_RET_NOT_ME)
686 if (ret == YAZPROXY_RET_PERM)
691 int Yaz_ProxyConfig::global_client_authentication(const char *user,
693 const char *password,
696 int ret = YAZPROXY_RET_NOT_ME;
698 if (!m_cp->m_proxyPtr)
701 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
703 if (ptr->type == XML_ELEMENT_NODE &&
704 !strcmp((const char *) ptr->name, "client-authentication"))
706 struct _xmlAttr *attr;
707 const char *module_name = 0;
708 for (attr = ptr->properties; attr; attr = attr->next)
710 if (!strcmp((const char *) attr->name, "module") &&
711 attr->children && attr->children->type == XML_TEXT_NODE)
712 module_name = (const char *) attr->children->content;
714 ret = m_cp->m_modules.authenticate(module_name,
716 user, group, password,
719 if (ret != YAZPROXY_RET_NOT_ME)
724 if (ret == YAZPROXY_RET_PERM)
729 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
730 Odr_oid *syntax, Z_RecordComposition *comp,
732 char **stylesheet, char **schema,
734 char **backend_charset,
735 char **usemarcon_ini_stage1,
736 char **usemarcon_ini_stage2
751 xfree (*backend_type);
756 xfree (*backend_charset);
757 *backend_charset = 0;
759 if (usemarcon_ini_stage1)
761 xfree (*usemarcon_ini_stage1);
762 *usemarcon_ini_stage1 = 0;
764 if (usemarcon_ini_stage2)
766 xfree (*usemarcon_ini_stage2);
767 *usemarcon_ini_stage2 = 0;
770 int syntax_has_matched = 0;
773 ptr = m_cp->find_target_node(name, 0);
776 for(ptr = ptr->children; ptr; ptr = ptr->next)
778 if (ptr->type == XML_ELEMENT_NODE &&
779 !strcmp((const char *) ptr->name, "syntax"))
781 int match = 0; // if we match record syntax
782 const char *match_type = 0;
783 const char *match_error = 0;
784 const char *match_marcxml = 0;
785 const char *match_stylesheet = 0;
786 const char *match_identifier = 0;
787 const char *match_backend_type = 0;
788 const char *match_backend_charset = 0;
789 const char *match_usemarcon_ini_stage1 = 0;
790 const char *match_usemarcon_ini_stage2 = 0;
791 struct _xmlAttr *attr;
792 for (attr = ptr->properties; attr; attr = attr->next)
794 if (!strcmp((const char *) attr->name, "type") &&
795 attr->children && attr->children->type == XML_TEXT_NODE)
796 match_type = (const char *) attr->children->content;
797 if (!strcmp((const char *) attr->name, "error") &&
798 attr->children && attr->children->type == XML_TEXT_NODE)
799 match_error = (const char *) attr->children->content;
800 if (!strcmp((const char *) attr->name, "marcxml") &&
801 attr->children && attr->children->type == XML_TEXT_NODE)
802 match_marcxml = (const char *) attr->children->content;
803 if (!strcmp((const char *) attr->name, "stylesheet") &&
804 attr->children && attr->children->type == XML_TEXT_NODE)
805 match_stylesheet = (const char *) attr->children->content;
806 if (!strcmp((const char *) attr->name, "identifier") &&
807 attr->children && attr->children->type == XML_TEXT_NODE)
808 match_identifier = (const char *) attr->children->content;
809 if (!strcmp((const char *) attr->name, "backendtype") &&
810 attr->children && attr->children->type == XML_TEXT_NODE)
811 match_backend_type = (const char *)
812 attr->children->content;
813 if (!strcmp((const char *) attr->name, "backendcharset") &&
814 attr->children && attr->children->type == XML_TEXT_NODE)
815 match_backend_charset = (const char *)
816 attr->children->content;
817 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
818 attr->children && attr->children->type == XML_TEXT_NODE)
819 match_usemarcon_ini_stage1 = (const char *)
820 attr->children->content;
821 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
822 attr->children && attr->children->type == XML_TEXT_NODE)
823 match_usemarcon_ini_stage2 = (const char *)
824 attr->children->content;
828 if (!strcmp(match_type, "*"))
830 else if (!strcmp(match_type, "none"))
838 = yaz_string_to_oid_odr(yaz_oid_std(),
839 CLASS_RECSYN, match_type,
841 if (oid_oidcmp(match_oid, syntax) == 0)
848 syntax_has_matched = 1;
849 match = m_cp->check_schema(ptr->children, comp,
854 if (stylesheet && match_stylesheet)
857 *stylesheet = xstrdup(match_stylesheet);
859 if (schema && match_identifier)
862 *schema = xstrdup(match_identifier);
864 if (backend_type && match_backend_type)
866 xfree(*backend_type);
867 *backend_type = xstrdup(match_backend_type);
869 if (backend_charset && match_backend_charset)
871 xfree(*backend_charset);
872 *backend_charset = xstrdup(match_backend_charset);
874 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
876 xfree(*usemarcon_ini_stage1);
877 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
879 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
881 xfree(*usemarcon_ini_stage2);
882 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
890 if (syntax_has_matched) // if syntax OK, bad schema/ESN
894 char dotoid_str[OID_STR_MAX];
895 oid_oid_to_dotstring(syntax, dotoid_str);
896 *addinfo = odr_strdup(odr, dotoid_str);
898 return atoi(match_error);
909 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
916 for (dptr = ptr->children; dptr; dptr = dptr->next)
917 if (dptr->type == XML_ELEMENT_NODE &&
918 !strcmp((const char *) dptr->name, "database"))
920 struct _xmlAttr *attr;
921 for (attr = dptr->properties; attr; attr = attr->next)
922 if (!strcmp((const char *) attr->name, "name"))
925 && attr->children->type==XML_TEXT_NODE
926 && attr->children->content
927 && (!strcmp((const char *) attr->children->content, db)
928 || !strcmp((const char *) attr->children->content,
936 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
941 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
943 if (ptr->type == XML_ELEMENT_NODE &&
944 !strcmp((const char *) ptr->name, "target"))
949 // <target default="1"> ?
950 struct _xmlAttr *attr;
951 for (attr = ptr->properties; attr; attr = attr->next)
952 if (!strcmp((const char *) attr->name, "default") &&
953 attr->children && attr->children->type == XML_TEXT_NODE)
955 xmlChar *t = attr->children->content;
958 return find_target_db(ptr, db);
964 // <target name="name"> ?
965 struct _xmlAttr *attr;
966 for (attr = ptr->properties; attr; attr = attr->next)
967 if (!strcmp((const char *) attr->name, "name"))
970 && attr->children->type==XML_TEXT_NODE
971 && attr->children->content
972 && (!strcmp((const char *) attr->children->content,
974 || !strcmp((const char *) attr->children->content,
977 return find_target_db(ptr, db);
987 int Yaz_ProxyConfig::get_target_no(int no,
994 int *target_idletime,
995 int *client_idletime,
998 int *keepalive_limit_bw,
999 int *keepalive_limit_pdu,
1001 const char **cql2rpn,
1002 const char **authentication,
1003 const char **negotiation_charset,
1004 const char **negotiation_lang,
1005 const char **target_charset,
1006 const char **default_client_query_charset)
1010 if (!m_cp->m_proxyPtr)
1013 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1014 if (ptr->type == XML_ELEMENT_NODE &&
1015 !strcmp((const char *) ptr->name, "target"))
1019 struct _xmlAttr *attr;
1020 for (attr = ptr->properties; attr; attr = attr->next)
1021 if (!strcmp((const char *) attr->name, "name"))
1024 && attr->children->type==XML_TEXT_NODE
1025 && attr->children->content)
1026 *name = (const char *) attr->children->content;
1028 m_cp->return_target_info(
1030 limit_bw, limit_pdu, limit_req,
1032 target_idletime, client_idletime,
1034 keepalive_limit_bw, keepalive_limit_pdu,
1036 negotiation_charset, negotiation_lang, target_charset,
1037 default_client_query_charset);
1046 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
1048 if (len == strlen(item) && memcmp(hay, item, len) == 0)
1053 int Yaz_ProxyConfig::get_file_access_info(const char *path)
1057 if (!m_cp->m_proxyPtr)
1059 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1061 if (ptr->type == XML_ELEMENT_NODE
1062 && !strcmp((const char *) ptr->name, "docpath"))
1064 const char *docpath = m_cp->get_text(ptr);
1065 size_t docpath_len = strlen(docpath);
1066 if (docpath_len < strlen(path) && path[docpath_len] == '/'
1067 && !memcmp(docpath, path, docpath_len))
1075 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
1079 int *period_connect,
1080 int *num_msg_threads)
1084 *num_msg_threads = 0;
1087 if (!m_cp->m_proxyPtr)
1089 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1091 if (ptr->type == XML_ELEMENT_NODE
1092 && !strcmp((const char *) ptr->name, "log"))
1094 const char *v = m_cp->get_text(ptr);
1099 while (*cp && *cp != ',' && !isspace(*cp))
1101 size_t len = cp - v;
1102 if (m_cp->mycmp(v, "client-apdu", len))
1103 *log_mask |= PROXY_LOG_APDU_CLIENT;
1104 if (m_cp->mycmp(v, "server-apdu", len))
1105 *log_mask |= PROXY_LOG_APDU_SERVER;
1106 if (m_cp->mycmp(v, "client-requests", len))
1107 *log_mask |= PROXY_LOG_REQ_CLIENT;
1108 if (m_cp->mycmp(v, "server-requests", len))
1109 *log_mask |= PROXY_LOG_REQ_SERVER;
1110 if (m_cp->mycmp(v, "client-ip", len))
1111 *log_mask |= PROXY_LOG_IP_CLIENT;
1113 *log_mask |= atoi(v);
1116 while (*cp && isspace(*cp))
1121 else if (ptr->type == XML_ELEMENT_NODE &&
1122 !strcmp((const char *) ptr->name, "max-clients"))
1124 const char *t = m_cp->get_text(ptr);
1127 *max_clients = atoi(t);
1128 if (*max_clients < 1)
1132 else if (ptr->type == XML_ELEMENT_NODE &&
1133 !strcmp((const char *) ptr->name, "period-connect"))
1135 const char *t = m_cp->get_text(ptr);
1137 *period_connect = atoi(t);
1139 else if (ptr->type == XML_ELEMENT_NODE &&
1140 !strcmp((const char *) ptr->name, "max-connect"))
1142 const char *t = m_cp->get_text(ptr);
1145 *max_connect = atoi(t);
1148 else if (ptr->type == XML_ELEMENT_NODE &&
1149 !strcmp((const char *) ptr->name, "limit-connect"))
1151 const char *t = m_cp->get_text(ptr);
1154 *limit_connect = atoi(t);
1157 else if (ptr->type == XML_ELEMENT_NODE &&
1158 !strcmp((const char *) ptr->name, "target"))
1160 else if (ptr->type == XML_ELEMENT_NODE &&
1161 !strcmp((const char *) ptr->name, "docpath"))
1163 else if (ptr->type == XML_ELEMENT_NODE &&
1164 !strcmp((const char *) ptr->name, "module"))
1166 else if (ptr->type == XML_ELEMENT_NODE &&
1167 !strcmp((const char *) ptr->name, "client-authentication"))
1169 else if (ptr->type == XML_ELEMENT_NODE &&
1170 !strcmp((const char *) ptr->name, "threads"))
1172 const char *t = m_cp->get_text(ptr);
1175 *num_msg_threads = atoi(t);
1178 else if (ptr->type == XML_ELEMENT_NODE)
1180 yaz_log(YLOG_WARN, "0 Unknown element %s in yazproxy config",
1188 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1189 xmlNodePtr *ptr_target,
1190 xmlNodePtr *ptr_explain)
1197 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1199 if (ptr->type == XML_ELEMENT_NODE &&
1200 !strcmp((const char *) ptr->name, "target"))
1203 xmlNodePtr ptr = (*ptr_target)->children;
1204 for (; ptr; ptr = ptr->next)
1206 if (ptr->type == XML_ELEMENT_NODE &&
1207 !strcmp((const char *) ptr->name, "explain"))
1210 xmlNodePtr ptr = (*ptr_explain)->children;
1212 for (; ptr; ptr = ptr->next)
1213 if (ptr->type == XML_ELEMENT_NODE &&
1214 !strcmp((const char *) ptr->name, "serverInfo"))
1218 for (ptr = ptr->children; ptr; ptr = ptr->next)
1219 if (ptr->type == XML_ELEMENT_NODE &&
1220 !strcmp((const char *) ptr->name, "database"))
1225 for (ptr = ptr->children; ptr; ptr = ptr->next)
1226 if (ptr->type == XML_TEXT_NODE &&
1228 !strcmp((const char *) ptr->content, db))
1241 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1242 const char **backend_db)
1245 xmlNodePtr ptr_target, ptr_explain;
1246 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1249 struct _xmlAttr *attr;
1250 const char *name = 0;
1252 for (attr = ptr_target->properties; attr; attr = attr->next)
1253 if (!strcmp((const char *) attr->name, "name")
1255 && attr->children->type==XML_TEXT_NODE
1256 && attr->children->content
1257 && attr->children->content[0])
1259 name = (const char *)attr->children->content;
1264 for (attr = ptr_target->properties; attr; attr = attr->next)
1265 if (!strcmp((const char *) attr->name, "database"))
1268 && attr->children->type==XML_TEXT_NODE
1269 && attr->children->content)
1270 *backend_db = (const char *) attr->children->content;
1279 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1280 const char *db, int *len)
1283 xmlNodePtr ptr_target, ptr_explain;
1284 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1286 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1288 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1290 xmlDocSetRootElement(doc, ptr2);
1293 xmlDocDumpMemory(doc, &buf_out, len);
1294 char *content = (char*) odr_malloc(odr, *len);
1295 memcpy(content, buf_out, *len);
1305 void Yaz_ProxyConfig::get_target_info(const char *name,
1311 int *target_idletime,
1312 int *client_idletime,
1315 int *keepalive_limit_bw,
1316 int *keepalive_limit_pdu,
1318 const char **cql2rpn,
1319 const char **negotiation_charset,
1320 const char **negotiation_lang,
1321 const char **target_charset,
1322 const char **default_client_query_charset)
1326 if (!m_cp->m_proxyPtr)
1333 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1335 if (ptr->type == XML_ELEMENT_NODE &&
1336 !strcmp((const char *) ptr->name, "max-clients"))
1338 const char *t = m_cp->get_text(ptr);
1341 *max_clients = atoi(t);
1342 if (*max_clients < 1)
1347 ptr = m_cp->find_target_node(name, 0);
1355 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1357 target_idletime, client_idletime,
1359 keepalive_limit_bw, keepalive_limit_pdu,
1361 negotiation_charset, negotiation_lang,
1363 default_client_query_charset);
1375 * indent-tabs-mode: nil
1377 * vim: shiftwidth=4 tabstop=8 expandtab