1 /* This file is part of YAZ proxy
2 Copyright (C) 1998-2011 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);
55 const char *get_text(xmlNodePtr ptr);
56 void get_period(xmlNodePtr ptr, int *period);
57 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
58 Z_AttributeList *attrs,
60 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
62 int get_explain_ptr(const char *db,
63 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
69 Yaz_ProxyConfigP::Yaz_ProxyConfigP() : m_modules()
77 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
85 Yaz_ProxyConfig::Yaz_ProxyConfig()
87 m_cp = new Yaz_ProxyConfigP();
90 Yaz_ProxyConfig::~Yaz_ProxyConfig()
96 void Yaz_ProxyConfigP::load_modules()
101 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
104 if (ptr->type == XML_ELEMENT_NODE
105 && !strcmp((const char *) ptr->name, "module")
106 && (fname = get_text(ptr)))
108 m_modules.add_module(fname);
114 int Yaz_ProxyConfig::read_xml(const char *fname)
117 xmlDocPtr ndoc = xmlParseFile(fname);
121 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
122 return -1; // no good
124 int noSubstitutions = xmlXIncludeProcess(ndoc);
125 if (noSubstitutions == -1)
126 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
128 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
129 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
130 strcmp((const char *) proxyPtr->name, "proxy"))
132 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
136 m_cp->m_proxyPtr = proxyPtr;
138 // OK: release previous and make it the current one.
140 xmlFreeDoc(m_cp->m_docPtr);
141 m_cp->m_docPtr = ndoc;
143 m_cp->m_modules.unload_modules();
144 m_cp->load_modules();
152 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
154 for(ptr = ptr->children; ptr; ptr = ptr->next)
155 if (ptr->type == XML_TEXT_NODE)
157 xmlChar *t = ptr->content;
162 return (const char *) t;
168 void Yaz_ProxyConfigP::get_period(xmlNodePtr ptr, int *period)
170 struct _xmlAttr *attr;
172 for (attr = ptr->properties; attr; attr = attr->next)
174 if (!strcmp((const char *) attr->name, "period") &&
175 attr->children && attr->children->type == XML_TEXT_NODE)
176 *period = atoi((const char *) attr->children->content);
182 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
188 for (ptr = ptr->children; ptr; ptr = ptr->next)
190 if (ptr->type == XML_ELEMENT_NODE
191 && !strcmp((const char *) ptr->name, "bandwidth"))
193 const char *t = get_text(ptr);
197 if (ptr->type == XML_ELEMENT_NODE
198 && !strcmp((const char *) ptr->name, "retrieve"))
200 const char *t = get_text(ptr);
202 *limit_req = atoi(t);
204 if (ptr->type == XML_ELEMENT_NODE
205 && !strcmp((const char *) ptr->name, "pdu"))
207 const char *t = get_text(ptr);
209 *limit_pdu = atoi(t);
211 if (ptr->type == XML_ELEMENT_NODE
212 && !strcmp((const char *) ptr->name, "search"))
214 const char *t = get_text(ptr);
216 *limit_search = atoi(t);
223 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
229 int *target_idletime,
230 int *client_idletime,
232 int *keepalive_limit_bw,
233 int *keepalive_limit_pdu,
235 const char **cql2rpn,
236 const char **negotiation_charset,
237 const char **negotiation_lang,
238 const char **target_charset,
239 const char **default_client_query_charset)
244 for (; ptr; ptr = ptr->next)
246 if (ptr->type == XML_ELEMENT_NODE
247 && !strcmp((const char *) ptr->name, "preinit"))
249 const char *v = get_text(ptr);
250 *pre_init = v ? atoi(v) : 1;
252 if (ptr->type == XML_ELEMENT_NODE
253 && !strcmp((const char *) ptr->name, "url"))
255 const char *t = get_text(ptr);
256 if (t && no_url < MAX_ZURL_PLEX)
262 if (ptr->type == XML_ELEMENT_NODE
263 && !strcmp((const char *) ptr->name, "keepalive"))
266 *keepalive_limit_bw = 500000;
267 *keepalive_limit_pdu = 1000;
268 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
271 if (ptr->type == XML_ELEMENT_NODE
272 && !strcmp((const char *) ptr->name, "limit"))
273 return_limit(ptr, limit_bw, limit_pdu, limit_req,
275 if (ptr->type == XML_ELEMENT_NODE
276 && !strcmp((const char *) ptr->name, "target-timeout"))
278 const char *t = get_text(ptr);
281 *target_idletime = atoi(t);
282 if (*target_idletime < 0)
283 *target_idletime = 0;
286 if (ptr->type == XML_ELEMENT_NODE
287 && !strcmp((const char *) ptr->name, "client-timeout"))
289 const char *t = get_text(ptr);
292 *client_idletime = atoi(t);
293 if (*client_idletime < 0)
294 *client_idletime = 0;
297 if (ptr->type == XML_ELEMENT_NODE
298 && !strcmp((const char *) ptr->name, "max-sockets"))
300 const char *t = get_text(ptr);
301 if (t && max_sockets)
303 *max_sockets = atoi(t);
306 if (ptr->type == XML_ELEMENT_NODE
307 && !strcmp((const char *) ptr->name, "cql2rpn"))
309 const char *t = get_text(ptr);
313 if (ptr->type == XML_ELEMENT_NODE
314 && !strcmp((const char *) ptr->name, "target-charset"))
316 const char *t = get_text(ptr);
317 if (t && target_charset)
320 if (ptr->type == XML_ELEMENT_NODE
321 && !strcmp((const char *) ptr->name, "default-client-charset"))
323 const char *t = get_text(ptr);
324 if (t && default_client_query_charset)
325 *default_client_query_charset = t;
327 if (ptr->type == XML_ELEMENT_NODE
328 && !strcmp((const char *) ptr->name, "negotiation-charset"))
330 const char *t = get_text(ptr);
332 *negotiation_charset = t;
334 if (ptr->type == XML_ELEMENT_NODE
335 && !strcmp((const char *) ptr->name, "negotiation-lang"))
337 const char *t = get_text(ptr);
339 *negotiation_lang = t;
345 int Yaz_ProxyConfigP::atoi_l(const char **cp)
348 while (**cp && isdigit(**cp))
350 v = v*10 + (**cp - '0');
356 int Yaz_ProxyConfigP::match_list(int v, const char *m)
360 while(*m && isspace(*m))
371 if (v >= l && v <= h)
380 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
381 Z_AttributeList *attrs,
385 for (i = 0; i<attrs->num_attributes; i++)
387 Z_AttributeElement *el = attrs->attributes[i];
389 if (!el->attributeType)
391 int type = *el->attributeType;
394 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
395 value = el->value.numeric;
398 for(ptr = ptrl->children; ptr; ptr = ptr->next)
400 if (ptr->type == XML_ELEMENT_NODE &&
401 !strcmp((const char *) ptr->name, "attribute"))
403 const char *match_type = 0;
404 const char *match_value = 0;
405 const char *match_error = 0;
406 struct _xmlAttr *attr;
407 for (attr = ptr->properties; attr; attr = attr->next)
409 if (!strcmp((const char *) attr->name, "type") &&
410 attr->children && attr->children->type == XML_TEXT_NODE)
411 match_type = (const char *) attr->children->content;
412 if (!strcmp((const char *) attr->name, "value") &&
413 attr->children && attr->children->type == XML_TEXT_NODE)
414 match_value = (const char *) attr->children->content;
415 if (!strcmp((const char *) attr->name, "error") &&
416 attr->children && attr->children->type == XML_TEXT_NODE)
417 match_error = (const char *) attr->children->content;
419 if (match_type && match_value)
421 char addinfo_str[20];
422 if (!match_list(type, match_type))
426 if (!strcmp(match_type, "*"))
427 sprintf (addinfo_str, "%d", type);
430 if (!match_list(*value, match_value))
432 sprintf (addinfo_str, ODR_INT_PRINTF, *value);
440 *addinfo = odr_strdup(odr, addinfo_str);
441 return atoi(match_error);
453 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
457 if (q->which == Z_RPNStructure_complex)
459 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
462 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
465 else if (q->which == Z_RPNStructure_simple)
467 if (q->u.simple->which == Z_Operand_APT)
469 return check_type_1_attributes(
470 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
479 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
482 // possibly check for Bib-1
483 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
487 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
493 ptr = m_cp->find_target_node(name);
496 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
497 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
504 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
505 const char *schema_identifier)
508 int default_match = 1;
509 if (comp && comp->which == Z_RecordComp_simple &&
510 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
512 esn = comp->u.simple->u.generic;
514 // if no ESN/schema was given accept..
517 // check if schema identifier match
518 if (schema_identifier && !strcmp(esn, schema_identifier))
520 // Check each name element
521 for (; ptr; ptr = ptr->next)
523 if (ptr->type == XML_ELEMENT_NODE
524 && !strcmp((const char *) ptr->name, "name"))
526 xmlNodePtr tptr = ptr->children;
528 for (; tptr; tptr = tptr->next)
529 if (tptr->type == XML_TEXT_NODE && tptr->content)
531 xmlChar *t = tptr->content;
532 while (*t && isspace(*t))
535 while (esn[i] && esn[i] == t[i])
537 if (!esn[i] && (!t[i] || isspace(t[i])))
542 return default_match;
546 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
552 {".xml", "text/xml"},
553 {".xsl", "text/xml"},
554 {".tkl", "text/xml"},
555 {".xsd", "text/xml"},
556 {".html", "text/html"},
557 {".jpg", "image/jpeg"},
558 {".png", "image/png"},
559 {".gif", "image/gif"},
560 {".css", "text/css"},
561 {".pdf", "application/pdf"},
566 size_t plen = strlen (path);
567 for (i = 0; types[i].type; i++)
568 if (types[i].mask == 0)
569 return types[i].type;
572 size_t mlen = strlen(types[i].mask);
573 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
574 return types[i].type;
576 return "application/octet-stream";
580 void Yaz_ProxyConfig::target_authentication(const char *name,
581 ODR odr, Z_InitRequest *req)
584 xmlNodePtr ptr = m_cp->find_target_node(name);
588 for (ptr = ptr->children; ptr; ptr = ptr->next)
589 if (ptr->type == XML_ELEMENT_NODE &&
590 !strcmp((const char *) ptr->name, "target-authentication"))
592 struct _xmlAttr *attr;
593 const char *type = "open";
594 for (attr = ptr->properties; attr; attr = attr->next)
596 if (!strcmp((const char *) attr->name, "type") &&
597 attr->children && attr->children->type == XML_TEXT_NODE)
598 type = (const char *) attr->children->content;
600 const char *t = m_cp->get_text(ptr);
601 if (!t || !strcmp(type, "none"))
603 req->idAuthentication = 0;
605 else if (!strcmp(type, "anonymous"))
607 req->idAuthentication =
608 (Z_IdAuthentication *)
609 odr_malloc (odr, sizeof(*req->idAuthentication));
610 req->idAuthentication->which =
611 Z_IdAuthentication_anonymous;
612 req->idAuthentication->u.anonymous = odr_nullval();
614 else if (!strcmp(type, "open"))
616 req->idAuthentication =
617 (Z_IdAuthentication *)
618 odr_malloc (odr, sizeof(*req->idAuthentication));
619 req->idAuthentication->which =
620 Z_IdAuthentication_open;
621 req->idAuthentication->u.open = odr_strdup (odr, t);
623 else if (!strcmp(type, "idPass"))
625 char user[64], group[64], password[64];
629 sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
631 req->idAuthentication =
632 (Z_IdAuthentication *)
633 odr_malloc (odr, sizeof(*req->idAuthentication));
634 req->idAuthentication->which =
635 Z_IdAuthentication_idPass;
636 req->idAuthentication->u.idPass =
637 (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
638 req->idAuthentication->u.idPass->userId =
639 *user ? odr_strdup(odr, user) : 0;
640 req->idAuthentication->u.idPass->groupId =
641 *group ? odr_strdup(odr, group) : 0;
642 req->idAuthentication->u.idPass->password =
643 *password ? odr_strdup(odr, password) : 0;
649 int Yaz_ProxyConfig::client_authentication(const char *name,
652 const char *password,
655 int ret = YAZPROXY_RET_NOT_ME;
658 ptr = m_cp->find_target_node(name);
661 for (ptr = ptr->children; ptr; ptr = ptr->next)
662 if (ptr->type == XML_ELEMENT_NODE &&
663 !strcmp((const char *) ptr->name, "client-authentication"))
665 struct _xmlAttr *attr;
666 const char *module_name = 0;
667 for (attr = ptr->properties; attr; attr = attr->next)
669 if (!strcmp((const char *) attr->name, "module") &&
670 attr->children && attr->children->type == XML_TEXT_NODE)
671 module_name = (const char *) attr->children->content;
673 ret = m_cp->m_modules.authenticate(module_name,
675 user, group, password,
678 if (ret != YAZPROXY_RET_NOT_ME)
682 if (ret == YAZPROXY_RET_PERM)
687 int Yaz_ProxyConfig::global_client_authentication(const char *user,
689 const char *password,
692 int ret = YAZPROXY_RET_NOT_ME;
694 if (!m_cp->m_proxyPtr)
697 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
699 if (ptr->type == XML_ELEMENT_NODE &&
700 !strcmp((const char *) ptr->name, "client-authentication"))
702 struct _xmlAttr *attr;
703 const char *module_name = 0;
704 for (attr = ptr->properties; attr; attr = attr->next)
706 if (!strcmp((const char *) attr->name, "module") &&
707 attr->children && attr->children->type == XML_TEXT_NODE)
708 module_name = (const char *) attr->children->content;
710 ret = m_cp->m_modules.authenticate(module_name,
712 user, group, password,
715 if (ret != YAZPROXY_RET_NOT_ME)
720 if (ret == YAZPROXY_RET_PERM)
725 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
726 Odr_oid *syntax, Z_RecordComposition *comp,
728 char **stylesheet, char **schema,
730 char **backend_charset,
731 char **usemarcon_ini_stage1,
732 char **usemarcon_ini_stage2,
733 char **backend_elementset
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;
766 xfree(*backend_elementset);
767 *backend_elementset = 0;
769 int syntax_has_matched = 0;
772 ptr = m_cp->find_target_node(name);
775 for(ptr = ptr->children; ptr; ptr = ptr->next)
777 if (ptr->type == XML_ELEMENT_NODE &&
778 !strcmp((const char *) ptr->name, "syntax"))
780 int match = 0; // if we match record syntax
781 const char *match_type = 0;
782 const char *match_error = 0;
783 const char *match_marcxml = 0;
784 const char *match_stylesheet = 0;
785 const char *match_identifier = 0;
786 const char *match_backend_type = 0;
787 const char *match_backend_charset = 0;
788 const char *match_usemarcon_ini_stage1 = 0;
789 const char *match_usemarcon_ini_stage2 = 0;
790 const char *match_elementset = 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;
825 if (!strcmp((const char *) attr->name, "backendelementset") &&
826 attr->children && attr->children->type == XML_TEXT_NODE)
827 match_elementset = (const char *) attr->children->content;
831 if (!strcmp(match_type, "*"))
833 else if (!strcmp(match_type, "none"))
841 = yaz_string_to_oid_odr(yaz_oid_std(),
842 CLASS_RECSYN, match_type,
844 if (oid_oidcmp(match_oid, syntax) == 0)
851 syntax_has_matched = 1;
852 match = m_cp->check_schema(ptr->children, comp,
857 if (stylesheet && match_stylesheet)
860 *stylesheet = xstrdup(match_stylesheet);
862 if (schema && match_identifier)
865 *schema = xstrdup(match_identifier);
867 if (backend_type && match_backend_type)
869 xfree(*backend_type);
870 *backend_type = xstrdup(match_backend_type);
872 if (backend_charset && match_backend_charset)
874 xfree(*backend_charset);
875 *backend_charset = xstrdup(match_backend_charset);
877 if (match_elementset)
879 xfree(*backend_elementset);
880 *backend_elementset = xstrdup(match_elementset);
882 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
884 xfree(*usemarcon_ini_stage1);
885 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
887 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
889 xfree(*usemarcon_ini_stage2);
890 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
898 if (syntax_has_matched) // if syntax OK, bad schema/ESN
902 char dotoid_str[OID_STR_MAX];
903 oid_oid_to_dotstring(syntax, dotoid_str);
904 *addinfo = odr_strdup(odr, dotoid_str);
906 return atoi(match_error);
919 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name)
921 /* db seems always to be passed as NULL */
925 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
927 if (ptr->type == XML_ELEMENT_NODE &&
928 !strcmp((const char *) ptr->name, "target"))
933 // <target default="1"> ?
934 struct _xmlAttr *attr;
935 for (attr = ptr->properties; attr; attr = attr->next)
936 if (!strcmp((const char *) attr->name, "default") &&
937 attr->children && attr->children->type == XML_TEXT_NODE)
939 xmlChar *t = attr->children->content;
946 // <target name="name"> ?
947 struct _xmlAttr *attr;
948 for (attr = ptr->properties; attr; attr = attr->next)
949 if (!strcmp((const char *) attr->name, "name"))
952 && attr->children->type==XML_TEXT_NODE
953 && attr->children->content
954 && (!strcmp((const char *) attr->children->content,
956 || !strcmp((const char *) attr->children->content,
969 int Yaz_ProxyConfig::get_target_no(int no,
976 int *target_idletime,
977 int *client_idletime,
980 int *keepalive_limit_bw,
981 int *keepalive_limit_pdu,
983 const char **cql2rpn,
984 const char **authentication,
985 const char **negotiation_charset,
986 const char **negotiation_lang,
987 const char **target_charset,
988 const char **default_client_query_charset)
992 if (!m_cp->m_proxyPtr)
995 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
996 if (ptr->type == XML_ELEMENT_NODE &&
997 !strcmp((const char *) ptr->name, "target"))
1001 struct _xmlAttr *attr;
1002 for (attr = ptr->properties; attr; attr = attr->next)
1003 if (!strcmp((const char *) attr->name, "name"))
1006 && attr->children->type==XML_TEXT_NODE
1007 && attr->children->content)
1008 *name = (const char *) attr->children->content;
1010 m_cp->return_target_info(
1012 limit_bw, limit_pdu, limit_req,
1014 target_idletime, client_idletime,
1016 keepalive_limit_bw, keepalive_limit_pdu,
1018 negotiation_charset, negotiation_lang, target_charset,
1019 default_client_query_charset);
1028 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
1030 if (len == strlen(item) && memcmp(hay, item, len) == 0)
1035 int Yaz_ProxyConfig::get_file_access_info(const char *path)
1039 if (!m_cp->m_proxyPtr)
1041 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1043 if (ptr->type == XML_ELEMENT_NODE
1044 && !strcmp((const char *) ptr->name, "docpath"))
1046 const char *docpath = m_cp->get_text(ptr);
1047 size_t docpath_len = strlen(docpath);
1048 if (docpath_len < strlen(path) && path[docpath_len] == '/'
1049 && !memcmp(docpath, path, docpath_len))
1057 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
1061 int *period_connect,
1062 int *num_msg_threads)
1066 *num_msg_threads = 0;
1069 if (!m_cp->m_proxyPtr)
1071 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1073 if (ptr->type == XML_ELEMENT_NODE
1074 && !strcmp((const char *) ptr->name, "log"))
1076 const char *v = m_cp->get_text(ptr);
1081 while (*cp && *cp != ',' && !isspace(*cp))
1083 size_t len = cp - v;
1084 if (m_cp->mycmp(v, "client-apdu", len))
1085 *log_mask |= PROXY_LOG_APDU_CLIENT;
1086 if (m_cp->mycmp(v, "server-apdu", len))
1087 *log_mask |= PROXY_LOG_APDU_SERVER;
1088 if (m_cp->mycmp(v, "client-requests", len))
1089 *log_mask |= PROXY_LOG_REQ_CLIENT;
1090 if (m_cp->mycmp(v, "server-requests", len))
1091 *log_mask |= PROXY_LOG_REQ_SERVER;
1092 if (m_cp->mycmp(v, "client-ip", len))
1093 *log_mask |= PROXY_LOG_IP_CLIENT;
1095 *log_mask |= atoi(v);
1098 while (*cp && isspace(*cp))
1103 else if (ptr->type == XML_ELEMENT_NODE &&
1104 !strcmp((const char *) ptr->name, "max-clients"))
1106 const char *t = m_cp->get_text(ptr);
1109 *max_clients = atoi(t);
1110 if (*max_clients < 1)
1114 else if (ptr->type == XML_ELEMENT_NODE &&
1115 !strcmp((const char *) ptr->name, "period-connect"))
1117 const char *t = m_cp->get_text(ptr);
1119 *period_connect = atoi(t);
1121 else if (ptr->type == XML_ELEMENT_NODE &&
1122 !strcmp((const char *) ptr->name, "max-connect"))
1124 const char *t = m_cp->get_text(ptr);
1127 *max_connect = atoi(t);
1130 else if (ptr->type == XML_ELEMENT_NODE &&
1131 !strcmp((const char *) ptr->name, "limit-connect"))
1133 const char *t = m_cp->get_text(ptr);
1136 *limit_connect = atoi(t);
1139 else if (ptr->type == XML_ELEMENT_NODE &&
1140 !strcmp((const char *) ptr->name, "target"))
1142 else if (ptr->type == XML_ELEMENT_NODE &&
1143 !strcmp((const char *) ptr->name, "docpath"))
1145 else if (ptr->type == XML_ELEMENT_NODE &&
1146 !strcmp((const char *) ptr->name, "module"))
1148 else if (ptr->type == XML_ELEMENT_NODE &&
1149 !strcmp((const char *) ptr->name, "client-authentication"))
1151 else if (ptr->type == XML_ELEMENT_NODE &&
1152 !strcmp((const char *) ptr->name, "threads"))
1154 const char *t = m_cp->get_text(ptr);
1157 *num_msg_threads = atoi(t);
1160 else if (ptr->type == XML_ELEMENT_NODE)
1162 yaz_log(YLOG_WARN, "0 Unknown element %s in yazproxy config",
1170 int Yaz_ProxyConfigP::get_explain_ptr(const char *db,
1171 xmlNodePtr *ptr_target,
1172 xmlNodePtr *ptr_explain)
1179 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1181 if (ptr->type == XML_ELEMENT_NODE &&
1182 !strcmp((const char *) ptr->name, "target"))
1184 int db_match_on_name = 0;
1185 struct _xmlAttr *attr;
1187 for (attr = ptr->properties; attr; attr = attr->next)
1188 if (!strcmp((const char *) attr->name, "name"))
1191 && attr->children->type==XML_TEXT_NODE
1192 && attr->children->content
1193 && (!strcmp((const char *) attr->children->content,
1195 db_match_on_name = 1;
1198 xmlNodePtr ptr = (*ptr_target)->children;
1199 for (; ptr; ptr = ptr->next)
1201 if (ptr->type == XML_ELEMENT_NODE &&
1202 !strcmp((const char *) ptr->name, "explain"))
1205 xmlNodePtr ptr = (*ptr_explain)->children;
1207 for (; ptr; ptr = ptr->next)
1208 if (ptr->type == XML_ELEMENT_NODE &&
1209 !strcmp((const char *) ptr->name, "serverInfo"))
1213 for (ptr = ptr->children; ptr; ptr = ptr->next)
1214 if (ptr->type == XML_ELEMENT_NODE &&
1215 !strcmp((const char *) ptr->name, "database"))
1220 for (ptr = ptr->children; ptr; ptr = ptr->next)
1221 if (ptr->type == XML_TEXT_NODE &&
1223 !strcmp((const char *) ptr->content, db))
1230 if (db_match_on_name)
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(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,
1281 xmlNodePtr ptr_target, ptr_explain;
1282 if (m_cp->get_explain_ptr(db, &ptr_target, &ptr_explain))
1291 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1293 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1295 xmlDocSetRootElement(doc, ptr2);
1298 xmlDocDumpMemory(doc, &buf_out, len);
1299 char *content = (char*) odr_malloc(odr, *len);
1300 memcpy(content, buf_out, *len);
1312 void Yaz_ProxyConfig::get_target_info(const char *name,
1318 int *target_idletime,
1319 int *client_idletime,
1322 int *keepalive_limit_bw,
1323 int *keepalive_limit_pdu,
1325 const char **cql2rpn,
1326 const char **negotiation_charset,
1327 const char **negotiation_lang,
1328 const char **target_charset,
1329 const char **default_client_query_charset)
1333 if (!m_cp->m_proxyPtr)
1340 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1342 if (ptr->type == XML_ELEMENT_NODE &&
1343 !strcmp((const char *) ptr->name, "max-clients"))
1345 const char *t = m_cp->get_text(ptr);
1348 *max_clients = atoi(t);
1349 if (*max_clients < 1)
1354 ptr = m_cp->find_target_node(name);
1362 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1364 target_idletime, client_idletime,
1366 keepalive_limit_bw, keepalive_limit_pdu,
1368 negotiation_charset, negotiation_lang,
1370 default_client_query_charset);
1382 * c-file-style: "Stroustrup"
1383 * indent-tabs-mode: nil
1385 * vim: shiftwidth=4 tabstop=8 expandtab