1 /* $Id: yaz-proxy-config.cpp,v 1.32 2006-06-09 09:35:14 adam Exp $
2 Copyright (c) 1998-2006, 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
27 class Yaz_ProxyConfigP {
28 friend class Yaz_ProxyConfig;
30 Yaz_ProxyModules m_modules;
31 int mycmp(const char *hay, const char *item, size_t len);
32 int match_list(int v, const char *m);
33 int atoi_l(const char **cp);
35 void load_modules(void);
36 int check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
37 const char *schema_identifier);
39 xmlNodePtr m_proxyPtr;
40 void return_target_info(xmlNodePtr ptr, const char **url,
41 int *limit_bw, int *limit_pdu, int *limit_req,
43 int *target_idletime, int *client_idletime,
44 int *keepalive_limit_bw, int *keepalive_limit_pdu,
45 int *pre_init, const char **cql2rpn,
46 const char **negotiation_charset,
47 const char **negotiation_lang,
48 const char **target_charset,
49 const char **default_client_query_charset);
50 void return_limit(xmlNodePtr ptr,
51 int *limit_bw, int *limit_pdu, int *limit_req,
53 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
55 xmlNodePtr find_target_node(const char *name, const char *db);
56 xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
57 const char *get_text(xmlNodePtr ptr);
58 void get_period(xmlNodePtr ptr, int *period);
59 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
60 Z_AttributeList *attrs,
62 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
64 int get_explain_ptr(const char *host, const char *db,
65 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
71 Yaz_ProxyConfigP::Yaz_ProxyConfigP() : m_modules()
79 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
87 Yaz_ProxyConfig::Yaz_ProxyConfig()
89 m_cp = new Yaz_ProxyConfigP();
92 Yaz_ProxyConfig::~Yaz_ProxyConfig()
98 void Yaz_ProxyConfigP::load_modules()
103 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
106 if (ptr->type == XML_ELEMENT_NODE
107 && !strcmp((const char *) ptr->name, "module")
108 && (fname = get_text(ptr)))
110 m_modules.add_module(fname);
116 int Yaz_ProxyConfig::read_xml(const char *fname)
119 xmlDocPtr ndoc = xmlParseFile(fname);
123 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
124 return -1; // no good
126 int noSubstitutions = xmlXIncludeProcess(ndoc);
127 if (noSubstitutions == -1)
128 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
130 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
131 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
132 strcmp((const char *) proxyPtr->name, "proxy"))
134 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
138 m_cp->m_proxyPtr = proxyPtr;
140 // OK: release previous and make it the current one.
142 xmlFreeDoc(m_cp->m_docPtr);
143 m_cp->m_docPtr = ndoc;
145 m_cp->m_modules.unload_modules();
146 m_cp->load_modules();
154 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
156 for(ptr = ptr->children; ptr; ptr = ptr->next)
157 if (ptr->type == XML_TEXT_NODE)
159 xmlChar *t = ptr->content;
164 return (const char *) t;
170 void Yaz_ProxyConfigP::get_period(xmlNodePtr ptr, int *period)
172 struct _xmlAttr *attr;
174 for (attr = ptr->properties; attr; attr = attr->next)
176 if (!strcmp((const char *) attr->name, "period") &&
177 attr->children && attr->children->type == XML_TEXT_NODE)
178 *period = atoi((const char *) attr->children->content);
184 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
190 for (ptr = ptr->children; ptr; ptr = ptr->next)
192 if (ptr->type == XML_ELEMENT_NODE
193 && !strcmp((const char *) ptr->name, "bandwidth"))
195 const char *t = get_text(ptr);
199 if (ptr->type == XML_ELEMENT_NODE
200 && !strcmp((const char *) ptr->name, "retrieve"))
202 const char *t = get_text(ptr);
204 *limit_req = atoi(t);
206 if (ptr->type == XML_ELEMENT_NODE
207 && !strcmp((const char *) ptr->name, "pdu"))
209 const char *t = get_text(ptr);
211 *limit_pdu = atoi(t);
213 if (ptr->type == XML_ELEMENT_NODE
214 && !strcmp((const char *) ptr->name, "search"))
216 const char *t = get_text(ptr);
218 *limit_search = atoi(t);
225 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
231 int *target_idletime,
232 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, "cql2rpn"))
301 const char *t = get_text(ptr);
305 if (ptr->type == XML_ELEMENT_NODE
306 && !strcmp((const char *) ptr->name, "target-charset"))
308 const char *t = get_text(ptr);
309 if (t && target_charset)
312 if (ptr->type == XML_ELEMENT_NODE
313 && !strcmp((const char *) ptr->name, "default-client-charset"))
315 const char *t = get_text(ptr);
316 if (t && default_client_query_charset)
317 *default_client_query_charset = t;
319 if (ptr->type == XML_ELEMENT_NODE
320 && !strcmp((const char *) ptr->name, "negotiation-charset"))
322 const char *t = get_text(ptr);
324 *negotiation_charset = t;
326 if (ptr->type == XML_ELEMENT_NODE
327 && !strcmp((const char *) ptr->name, "negotiation-lang"))
329 const char *t = get_text(ptr);
331 *negotiation_lang = t;
337 int Yaz_ProxyConfigP::atoi_l(const char **cp)
340 while (**cp && isdigit(**cp))
342 v = v*10 + (**cp - '0');
348 int Yaz_ProxyConfigP::match_list(int v, const char *m)
352 while(*m && isspace(*m))
363 if (v >= l && v <= h)
372 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
373 Z_AttributeList *attrs,
377 for (i = 0; i<attrs->num_attributes; i++)
379 Z_AttributeElement *el = attrs->attributes[i];
381 if (!el->attributeType)
383 int type = *el->attributeType;
386 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
387 value = el->value.numeric;
390 for(ptr = ptrl->children; ptr; ptr = ptr->next)
392 if (ptr->type == XML_ELEMENT_NODE &&
393 !strcmp((const char *) ptr->name, "attribute"))
395 const char *match_type = 0;
396 const char *match_value = 0;
397 const char *match_error = 0;
398 struct _xmlAttr *attr;
399 for (attr = ptr->properties; attr; attr = attr->next)
401 if (!strcmp((const char *) attr->name, "type") &&
402 attr->children && attr->children->type == XML_TEXT_NODE)
403 match_type = (const char *) attr->children->content;
404 if (!strcmp((const char *) attr->name, "value") &&
405 attr->children && attr->children->type == XML_TEXT_NODE)
406 match_value = (const char *) attr->children->content;
407 if (!strcmp((const char *) attr->name, "error") &&
408 attr->children && attr->children->type == XML_TEXT_NODE)
409 match_error = (const char *) attr->children->content;
411 if (match_type && match_value)
413 char addinfo_str[20];
414 if (!match_list(type, match_type))
418 if (!strcmp(match_type, "*"))
419 sprintf (addinfo_str, "%d", type);
422 if (!match_list(*value, match_value))
424 sprintf (addinfo_str, "%d", *value);
432 *addinfo = odr_strdup(odr, addinfo_str);
433 return atoi(match_error);
445 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
449 if (q->which == Z_RPNStructure_complex)
451 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
454 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
457 else if (q->which == Z_RPNStructure_simple)
459 if (q->u.simple->which == Z_Operand_APT)
461 return check_type_1_attributes(
462 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
471 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
474 // possibly check for Bib-1
475 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
479 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
485 ptr = m_cp->find_target_node(name, 0);
488 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
489 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
496 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
497 const char *schema_identifier)
500 int default_match = 1;
501 if (comp && comp->which == Z_RecordComp_simple &&
502 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
504 esn = comp->u.simple->u.generic;
506 // if no ESN/schema was given accept..
509 // check if schema identifier match
510 if (schema_identifier && !strcmp(esn, schema_identifier))
512 // Check each name element
513 for (; ptr; ptr = ptr->next)
515 if (ptr->type == XML_ELEMENT_NODE
516 && !strcmp((const char *) ptr->name, "name"))
518 xmlNodePtr tptr = ptr->children;
520 for (; tptr; tptr = tptr->next)
521 if (tptr->type == XML_TEXT_NODE && tptr->content)
523 xmlChar *t = tptr->content;
524 while (*t && isspace(*t))
527 while (esn[i] && esn[i] == t[i])
529 if (!esn[i] && (!t[i] || isspace(t[i])))
534 return default_match;
538 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
544 {".xml", "text/xml"},
545 {".xsl", "text/xml"},
546 {".tkl", "text/xml"},
547 {".xsd", "text/xml"},
548 {".html", "text/html"},
549 {".jpg", "image/jpeg"},
550 {".png", "image/png"},
551 {".gif", "image/gif"},
552 {".css", "text/css"},
553 {".pdf", "application/pdf"},
558 size_t plen = strlen (path);
559 for (i = 0; types[i].type; i++)
560 if (types[i].mask == 0)
561 return types[i].type;
564 size_t mlen = strlen(types[i].mask);
565 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
566 return types[i].type;
568 return "application/octet-stream";
572 void Yaz_ProxyConfig::target_authentication(const char *name,
573 ODR odr, Z_InitRequest *req)
576 xmlNodePtr ptr = m_cp->find_target_node(name, 0);
580 for (ptr = ptr->children; ptr; ptr = ptr->next)
581 if (ptr->type == XML_ELEMENT_NODE &&
582 !strcmp((const char *) ptr->name, "target-authentication"))
584 struct _xmlAttr *attr;
585 const char *type = "open";
586 for (attr = ptr->properties; attr; attr = attr->next)
588 if (!strcmp((const char *) attr->name, "type") &&
589 attr->children && attr->children->type == XML_TEXT_NODE)
590 type = (const char *) attr->children->content;
592 const char *t = m_cp->get_text(ptr);
593 if (!t || !strcmp(type, "none"))
595 req->idAuthentication = 0;
597 else if (!strcmp(type, "anonymous"))
599 req->idAuthentication =
600 (Z_IdAuthentication *)
601 odr_malloc (odr, sizeof(*req->idAuthentication));
602 req->idAuthentication->which =
603 Z_IdAuthentication_anonymous;
604 req->idAuthentication->u.anonymous = odr_nullval();
606 else if (!strcmp(type, "open"))
608 req->idAuthentication =
609 (Z_IdAuthentication *)
610 odr_malloc (odr, sizeof(*req->idAuthentication));
611 req->idAuthentication->which =
612 Z_IdAuthentication_open;
613 req->idAuthentication->u.open = odr_strdup (odr, t);
615 else if (!strcmp(type, "idPass"))
617 char user[64], group[64], password[64];
621 sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
623 req->idAuthentication =
624 (Z_IdAuthentication *)
625 odr_malloc (odr, sizeof(*req->idAuthentication));
626 req->idAuthentication->which =
627 Z_IdAuthentication_idPass;
628 req->idAuthentication->u.idPass =
629 (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
630 req->idAuthentication->u.idPass->userId =
631 *user ? odr_strdup(odr, user) : 0;
632 req->idAuthentication->u.idPass->groupId =
633 *group ? odr_strdup(odr, group) : 0;
634 req->idAuthentication->u.idPass->password =
635 *password ? odr_strdup(odr, password) : 0;
641 int Yaz_ProxyConfig::client_authentication(const char *name,
644 const char *password,
647 int ret = YAZPROXY_RET_NOT_ME;
650 ptr = m_cp->find_target_node(name, 0);
653 for (ptr = ptr->children; ptr; ptr = ptr->next)
654 if (ptr->type == XML_ELEMENT_NODE &&
655 !strcmp((const char *) ptr->name, "client-authentication"))
657 struct _xmlAttr *attr;
658 const char *module_name = 0;
659 for (attr = ptr->properties; attr; attr = attr->next)
661 if (!strcmp((const char *) attr->name, "module") &&
662 attr->children && attr->children->type == XML_TEXT_NODE)
663 module_name = (const char *) attr->children->content;
665 ret = m_cp->m_modules.authenticate(module_name,
667 user, group, password,
670 if (ret != YAZPROXY_RET_NOT_ME)
674 if (ret == YAZPROXY_RET_PERM)
679 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
680 Odr_oid *syntax, Z_RecordComposition *comp,
682 char **stylesheet, char **schema,
684 char **backend_charset,
685 char **usemarcon_ini_stage1,
686 char **usemarcon_ini_stage2
701 xfree (*backend_type);
706 xfree (*backend_charset);
707 *backend_charset = 0;
709 if (usemarcon_ini_stage1)
711 xfree (*usemarcon_ini_stage1);
712 *usemarcon_ini_stage1 = 0;
714 if (usemarcon_ini_stage2)
716 xfree (*usemarcon_ini_stage2);
717 *usemarcon_ini_stage2 = 0;
720 int syntax_has_matched = 0;
723 ptr = m_cp->find_target_node(name, 0);
726 for(ptr = ptr->children; ptr; ptr = ptr->next)
728 if (ptr->type == XML_ELEMENT_NODE &&
729 !strcmp((const char *) ptr->name, "syntax"))
731 int match = 0; // if we match record syntax
732 const char *match_type = 0;
733 const char *match_error = 0;
734 const char *match_marcxml = 0;
735 const char *match_stylesheet = 0;
736 const char *match_identifier = 0;
737 const char *match_backend_type = 0;
738 const char *match_backend_charset = 0;
739 const char *match_usemarcon_ini_stage1 = 0;
740 const char *match_usemarcon_ini_stage2 = 0;
741 struct _xmlAttr *attr;
742 for (attr = ptr->properties; attr; attr = attr->next)
744 if (!strcmp((const char *) attr->name, "type") &&
745 attr->children && attr->children->type == XML_TEXT_NODE)
746 match_type = (const char *) attr->children->content;
747 if (!strcmp((const char *) attr->name, "error") &&
748 attr->children && attr->children->type == XML_TEXT_NODE)
749 match_error = (const char *) attr->children->content;
750 if (!strcmp((const char *) attr->name, "marcxml") &&
751 attr->children && attr->children->type == XML_TEXT_NODE)
752 match_marcxml = (const char *) attr->children->content;
753 if (!strcmp((const char *) attr->name, "stylesheet") &&
754 attr->children && attr->children->type == XML_TEXT_NODE)
755 match_stylesheet = (const char *) attr->children->content;
756 if (!strcmp((const char *) attr->name, "identifier") &&
757 attr->children && attr->children->type == XML_TEXT_NODE)
758 match_identifier = (const char *) attr->children->content;
759 if (!strcmp((const char *) attr->name, "backendtype") &&
760 attr->children && attr->children->type == XML_TEXT_NODE)
761 match_backend_type = (const char *)
762 attr->children->content;
763 if (!strcmp((const char *) attr->name, "backendcharset") &&
764 attr->children && attr->children->type == XML_TEXT_NODE)
765 match_backend_charset = (const char *)
766 attr->children->content;
767 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
768 attr->children && attr->children->type == XML_TEXT_NODE)
769 match_usemarcon_ini_stage1 = (const char *)
770 attr->children->content;
771 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
772 attr->children && attr->children->type == XML_TEXT_NODE)
773 match_usemarcon_ini_stage2 = (const char *)
774 attr->children->content;
778 if (!strcmp(match_type, "*"))
780 else if (!strcmp(match_type, "none"))
787 int match_oid[OID_SIZE];
788 oid_name_to_oid(CLASS_RECSYN, match_type, match_oid);
789 if (oid_oidcmp(match_oid, syntax) == 0)
796 syntax_has_matched = 1;
797 match = m_cp->check_schema(ptr->children, comp,
802 if (stylesheet && match_stylesheet)
805 *stylesheet = xstrdup(match_stylesheet);
807 if (schema && match_identifier)
810 *schema = xstrdup(match_identifier);
812 if (backend_type && match_backend_type)
814 xfree(*backend_type);
815 *backend_type = xstrdup(match_backend_type);
817 if (backend_charset && match_backend_charset)
819 xfree(*backend_charset);
820 *backend_charset = xstrdup(match_backend_charset);
822 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
824 xfree(*usemarcon_ini_stage1);
825 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
827 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
829 xfree(*usemarcon_ini_stage2);
830 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
838 if (syntax_has_matched) // if syntax OK, bad schema/ESN
842 char dotoid_str[100];
843 oid_to_dotstring(syntax, dotoid_str);
844 *addinfo = odr_strdup(odr, dotoid_str);
846 return atoi(match_error);
857 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
864 for (dptr = ptr->children; dptr; dptr = dptr->next)
865 if (dptr->type == XML_ELEMENT_NODE &&
866 !strcmp((const char *) dptr->name, "database"))
868 struct _xmlAttr *attr;
869 for (attr = dptr->properties; attr; attr = attr->next)
870 if (!strcmp((const char *) attr->name, "name"))
873 && attr->children->type==XML_TEXT_NODE
874 && attr->children->content
875 && (!strcmp((const char *) attr->children->content, db)
876 || !strcmp((const char *) attr->children->content,
884 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
889 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
891 if (ptr->type == XML_ELEMENT_NODE &&
892 !strcmp((const char *) ptr->name, "target"))
897 // <target default="1"> ?
898 struct _xmlAttr *attr;
899 for (attr = ptr->properties; attr; attr = attr->next)
900 if (!strcmp((const char *) attr->name, "default") &&
901 attr->children && attr->children->type == XML_TEXT_NODE)
903 xmlChar *t = attr->children->content;
906 return find_target_db(ptr, db);
912 // <target name="name"> ?
913 struct _xmlAttr *attr;
914 for (attr = ptr->properties; attr; attr = attr->next)
915 if (!strcmp((const char *) attr->name, "name"))
918 && attr->children->type==XML_TEXT_NODE
919 && attr->children->content
920 && (!strcmp((const char *) attr->children->content,
922 || !strcmp((const char *) attr->children->content,
925 return find_target_db(ptr, db);
935 int Yaz_ProxyConfig::get_target_no(int no,
942 int *target_idletime,
943 int *client_idletime,
945 int *keepalive_limit_bw,
946 int *keepalive_limit_pdu,
948 const char **cql2rpn,
949 const char **authentication,
950 const char **negotiation_charset,
951 const char **negotiation_lang,
952 const char **target_charset,
953 const char **default_client_query_charset)
957 if (!m_cp->m_proxyPtr)
960 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
961 if (ptr->type == XML_ELEMENT_NODE &&
962 !strcmp((const char *) ptr->name, "target"))
966 struct _xmlAttr *attr;
967 for (attr = ptr->properties; attr; attr = attr->next)
968 if (!strcmp((const char *) attr->name, "name"))
971 && attr->children->type==XML_TEXT_NODE
972 && attr->children->content)
973 *name = (const char *) attr->children->content;
975 m_cp->return_target_info(
977 limit_bw, limit_pdu, limit_req,
979 target_idletime, client_idletime,
980 keepalive_limit_bw, keepalive_limit_pdu,
982 negotiation_charset, negotiation_lang, target_charset,
983 default_client_query_charset);
992 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
994 if (len == strlen(item) && memcmp(hay, item, len) == 0)
999 int Yaz_ProxyConfig::get_file_access_info(const char *path)
1003 if (!m_cp->m_proxyPtr)
1005 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1007 if (ptr->type == XML_ELEMENT_NODE
1008 && !strcmp((const char *) ptr->name, "docpath"))
1010 const char *docpath = m_cp->get_text(ptr);
1011 size_t docpath_len = strlen(docpath);
1012 if (docpath_len < strlen(path) && path[docpath_len] == '/'
1013 && !memcmp(docpath, path, docpath_len))
1021 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
1025 int *period_connect,
1026 int *num_msg_threads)
1030 *num_msg_threads = 0;
1033 if (!m_cp->m_proxyPtr)
1035 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1037 if (ptr->type == XML_ELEMENT_NODE
1038 && !strcmp((const char *) ptr->name, "log"))
1040 const char *v = m_cp->get_text(ptr);
1045 while (*cp && *cp != ',' && !isspace(*cp))
1047 size_t len = cp - v;
1048 if (m_cp->mycmp(v, "client-apdu", len))
1049 *log_mask |= PROXY_LOG_APDU_CLIENT;
1050 if (m_cp->mycmp(v, "server-apdu", len))
1051 *log_mask |= PROXY_LOG_APDU_SERVER;
1052 if (m_cp->mycmp(v, "client-requests", len))
1053 *log_mask |= PROXY_LOG_REQ_CLIENT;
1054 if (m_cp->mycmp(v, "server-requests", len))
1055 *log_mask |= PROXY_LOG_REQ_SERVER;
1056 if (m_cp->mycmp(v, "client-ip", len))
1057 *log_mask |= PROXY_LOG_IP_CLIENT;
1059 *log_mask |= atoi(v);
1062 while (*cp && isspace(*cp))
1067 else if (ptr->type == XML_ELEMENT_NODE &&
1068 !strcmp((const char *) ptr->name, "max-clients"))
1070 const char *t = m_cp->get_text(ptr);
1073 *max_clients = atoi(t);
1074 if (*max_clients < 1)
1078 else if (ptr->type == XML_ELEMENT_NODE &&
1079 !strcmp((const char *) ptr->name, "period-connect"))
1081 const char *t = m_cp->get_text(ptr);
1083 *period_connect = atoi(t);
1085 else if (ptr->type == XML_ELEMENT_NODE &&
1086 !strcmp((const char *) ptr->name, "max-connect"))
1088 const char *t = m_cp->get_text(ptr);
1091 *max_connect = atoi(t);
1094 else if (ptr->type == XML_ELEMENT_NODE &&
1095 !strcmp((const char *) ptr->name, "limit-connect"))
1097 const char *t = m_cp->get_text(ptr);
1100 *limit_connect = atoi(t);
1103 else if (ptr->type == XML_ELEMENT_NODE &&
1104 !strcmp((const char *) ptr->name, "target"))
1106 else if (ptr->type == XML_ELEMENT_NODE &&
1107 !strcmp((const char *) ptr->name, "docpath"))
1109 else if (ptr->type == XML_ELEMENT_NODE &&
1110 !strcmp((const char *) ptr->name, "module"))
1112 else if (ptr->type == XML_ELEMENT_NODE &&
1113 !strcmp((const char *) ptr->name, "threads"))
1115 const char *t = m_cp->get_text(ptr);
1118 *num_msg_threads = atoi(t);
1121 else if (ptr->type == XML_ELEMENT_NODE)
1123 yaz_log(YLOG_WARN, "0 Unknown element %s in yazproxy config",
1131 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1132 xmlNodePtr *ptr_target,
1133 xmlNodePtr *ptr_explain)
1140 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1142 if (ptr->type == XML_ELEMENT_NODE &&
1143 !strcmp((const char *) ptr->name, "target"))
1146 xmlNodePtr ptr = (*ptr_target)->children;
1147 for (; ptr; ptr = ptr->next)
1149 if (ptr->type == XML_ELEMENT_NODE &&
1150 !strcmp((const char *) ptr->name, "explain"))
1153 xmlNodePtr ptr = (*ptr_explain)->children;
1155 for (; ptr; ptr = ptr->next)
1156 if (ptr->type == XML_ELEMENT_NODE &&
1157 !strcmp((const char *) ptr->name, "serverInfo"))
1161 for (ptr = ptr->children; ptr; ptr = ptr->next)
1162 if (ptr->type == XML_ELEMENT_NODE &&
1163 !strcmp((const char *) ptr->name, "database"))
1168 for (ptr = ptr->children; ptr; ptr = ptr->next)
1169 if (ptr->type == XML_TEXT_NODE &&
1171 !strcmp((const char *) ptr->content, db))
1184 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1185 const char **backend_db)
1188 xmlNodePtr ptr_target, ptr_explain;
1189 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1192 struct _xmlAttr *attr;
1193 const char *name = 0;
1195 for (attr = ptr_target->properties; attr; attr = attr->next)
1196 if (!strcmp((const char *) attr->name, "name")
1198 && attr->children->type==XML_TEXT_NODE
1199 && attr->children->content
1200 && attr->children->content[0])
1202 name = (const char *)attr->children->content;
1207 for (attr = ptr_target->properties; attr; attr = attr->next)
1208 if (!strcmp((const char *) attr->name, "database"))
1211 && attr->children->type==XML_TEXT_NODE
1212 && attr->children->content)
1213 *backend_db = (const char *) attr->children->content;
1222 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1223 const char *db, int *len)
1226 xmlNodePtr ptr_target, ptr_explain;
1227 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1229 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1231 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1233 xmlDocSetRootElement(doc, ptr2);
1236 xmlDocDumpMemory(doc, &buf_out, len);
1237 char *content = (char*) odr_malloc(odr, *len);
1238 memcpy(content, buf_out, *len);
1248 void Yaz_ProxyConfig::get_target_info(const char *name,
1254 int *target_idletime,
1255 int *client_idletime,
1257 int *keepalive_limit_bw,
1258 int *keepalive_limit_pdu,
1260 const char **cql2rpn,
1261 const char **negotiation_charset,
1262 const char **negotiation_lang,
1263 const char **target_charset,
1264 const char **default_client_query_charset)
1268 if (!m_cp->m_proxyPtr)
1275 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1277 if (ptr->type == XML_ELEMENT_NODE &&
1278 !strcmp((const char *) ptr->name, "max-clients"))
1280 const char *t = m_cp->get_text(ptr);
1283 *max_clients = atoi(t);
1284 if (*max_clients < 1)
1289 ptr = m_cp->find_target_node(name, 0);
1297 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1299 target_idletime, client_idletime,
1300 keepalive_limit_bw, keepalive_limit_pdu,
1302 negotiation_charset, negotiation_lang,
1304 default_client_query_charset);
1316 * indent-tabs-mode: nil
1318 * vim: shiftwidth=4 tabstop=8 expandtab