1 /* $Id: yaz-proxy-config.cpp,v 1.34 2006-07-06 11:50:26 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::global_client_authentication(const char *user,
681 const char *password,
684 int ret = YAZPROXY_RET_NOT_ME;
686 if (!m_cp->m_proxyPtr)
689 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
691 if (ptr->type == XML_ELEMENT_NODE &&
692 !strcmp((const char *) ptr->name, "client-authentication"))
694 struct _xmlAttr *attr;
695 const char *module_name = 0;
696 for (attr = ptr->properties; attr; attr = attr->next)
698 if (!strcmp((const char *) attr->name, "module") &&
699 attr->children && attr->children->type == XML_TEXT_NODE)
700 module_name = (const char *) attr->children->content;
702 ret = m_cp->m_modules.authenticate(module_name,
704 user, group, password,
707 if (ret != YAZPROXY_RET_NOT_ME)
712 if (ret == YAZPROXY_RET_PERM)
717 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
718 Odr_oid *syntax, Z_RecordComposition *comp,
720 char **stylesheet, char **schema,
722 char **backend_charset,
723 char **usemarcon_ini_stage1,
724 char **usemarcon_ini_stage2
739 xfree (*backend_type);
744 xfree (*backend_charset);
745 *backend_charset = 0;
747 if (usemarcon_ini_stage1)
749 xfree (*usemarcon_ini_stage1);
750 *usemarcon_ini_stage1 = 0;
752 if (usemarcon_ini_stage2)
754 xfree (*usemarcon_ini_stage2);
755 *usemarcon_ini_stage2 = 0;
758 int syntax_has_matched = 0;
761 ptr = m_cp->find_target_node(name, 0);
764 for(ptr = ptr->children; ptr; ptr = ptr->next)
766 if (ptr->type == XML_ELEMENT_NODE &&
767 !strcmp((const char *) ptr->name, "syntax"))
769 int match = 0; // if we match record syntax
770 const char *match_type = 0;
771 const char *match_error = 0;
772 const char *match_marcxml = 0;
773 const char *match_stylesheet = 0;
774 const char *match_identifier = 0;
775 const char *match_backend_type = 0;
776 const char *match_backend_charset = 0;
777 const char *match_usemarcon_ini_stage1 = 0;
778 const char *match_usemarcon_ini_stage2 = 0;
779 struct _xmlAttr *attr;
780 for (attr = ptr->properties; attr; attr = attr->next)
782 if (!strcmp((const char *) attr->name, "type") &&
783 attr->children && attr->children->type == XML_TEXT_NODE)
784 match_type = (const char *) attr->children->content;
785 if (!strcmp((const char *) attr->name, "error") &&
786 attr->children && attr->children->type == XML_TEXT_NODE)
787 match_error = (const char *) attr->children->content;
788 if (!strcmp((const char *) attr->name, "marcxml") &&
789 attr->children && attr->children->type == XML_TEXT_NODE)
790 match_marcxml = (const char *) attr->children->content;
791 if (!strcmp((const char *) attr->name, "stylesheet") &&
792 attr->children && attr->children->type == XML_TEXT_NODE)
793 match_stylesheet = (const char *) attr->children->content;
794 if (!strcmp((const char *) attr->name, "identifier") &&
795 attr->children && attr->children->type == XML_TEXT_NODE)
796 match_identifier = (const char *) attr->children->content;
797 if (!strcmp((const char *) attr->name, "backendtype") &&
798 attr->children && attr->children->type == XML_TEXT_NODE)
799 match_backend_type = (const char *)
800 attr->children->content;
801 if (!strcmp((const char *) attr->name, "backendcharset") &&
802 attr->children && attr->children->type == XML_TEXT_NODE)
803 match_backend_charset = (const char *)
804 attr->children->content;
805 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
806 attr->children && attr->children->type == XML_TEXT_NODE)
807 match_usemarcon_ini_stage1 = (const char *)
808 attr->children->content;
809 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
810 attr->children && attr->children->type == XML_TEXT_NODE)
811 match_usemarcon_ini_stage2 = (const char *)
812 attr->children->content;
816 if (!strcmp(match_type, "*"))
818 else if (!strcmp(match_type, "none"))
825 int match_oid[OID_SIZE];
826 oid_name_to_oid(CLASS_RECSYN, match_type, match_oid);
827 if (oid_oidcmp(match_oid, syntax) == 0)
834 syntax_has_matched = 1;
835 match = m_cp->check_schema(ptr->children, comp,
840 if (stylesheet && match_stylesheet)
843 *stylesheet = xstrdup(match_stylesheet);
845 if (schema && match_identifier)
848 *schema = xstrdup(match_identifier);
850 if (backend_type && match_backend_type)
852 xfree(*backend_type);
853 *backend_type = xstrdup(match_backend_type);
855 if (backend_charset && match_backend_charset)
857 xfree(*backend_charset);
858 *backend_charset = xstrdup(match_backend_charset);
860 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
862 xfree(*usemarcon_ini_stage1);
863 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
865 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
867 xfree(*usemarcon_ini_stage2);
868 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
876 if (syntax_has_matched) // if syntax OK, bad schema/ESN
880 char dotoid_str[100];
881 oid_to_dotstring(syntax, dotoid_str);
882 *addinfo = odr_strdup(odr, dotoid_str);
884 return atoi(match_error);
895 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
902 for (dptr = ptr->children; dptr; dptr = dptr->next)
903 if (dptr->type == XML_ELEMENT_NODE &&
904 !strcmp((const char *) dptr->name, "database"))
906 struct _xmlAttr *attr;
907 for (attr = dptr->properties; attr; attr = attr->next)
908 if (!strcmp((const char *) attr->name, "name"))
911 && attr->children->type==XML_TEXT_NODE
912 && attr->children->content
913 && (!strcmp((const char *) attr->children->content, db)
914 || !strcmp((const char *) attr->children->content,
922 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
927 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
929 if (ptr->type == XML_ELEMENT_NODE &&
930 !strcmp((const char *) ptr->name, "target"))
935 // <target default="1"> ?
936 struct _xmlAttr *attr;
937 for (attr = ptr->properties; attr; attr = attr->next)
938 if (!strcmp((const char *) attr->name, "default") &&
939 attr->children && attr->children->type == XML_TEXT_NODE)
941 xmlChar *t = attr->children->content;
944 return find_target_db(ptr, db);
950 // <target name="name"> ?
951 struct _xmlAttr *attr;
952 for (attr = ptr->properties; attr; attr = attr->next)
953 if (!strcmp((const char *) attr->name, "name"))
956 && attr->children->type==XML_TEXT_NODE
957 && attr->children->content
958 && (!strcmp((const char *) attr->children->content,
960 || !strcmp((const char *) attr->children->content,
963 return find_target_db(ptr, db);
973 int Yaz_ProxyConfig::get_target_no(int no,
980 int *target_idletime,
981 int *client_idletime,
983 int *keepalive_limit_bw,
984 int *keepalive_limit_pdu,
986 const char **cql2rpn,
987 const char **authentication,
988 const char **negotiation_charset,
989 const char **negotiation_lang,
990 const char **target_charset,
991 const char **default_client_query_charset)
995 if (!m_cp->m_proxyPtr)
998 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
999 if (ptr->type == XML_ELEMENT_NODE &&
1000 !strcmp((const char *) ptr->name, "target"))
1004 struct _xmlAttr *attr;
1005 for (attr = ptr->properties; attr; attr = attr->next)
1006 if (!strcmp((const char *) attr->name, "name"))
1009 && attr->children->type==XML_TEXT_NODE
1010 && attr->children->content)
1011 *name = (const char *) attr->children->content;
1013 m_cp->return_target_info(
1015 limit_bw, limit_pdu, limit_req,
1017 target_idletime, client_idletime,
1018 keepalive_limit_bw, keepalive_limit_pdu,
1020 negotiation_charset, negotiation_lang, target_charset,
1021 default_client_query_charset);
1030 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
1032 if (len == strlen(item) && memcmp(hay, item, len) == 0)
1037 int Yaz_ProxyConfig::get_file_access_info(const char *path)
1041 if (!m_cp->m_proxyPtr)
1043 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1045 if (ptr->type == XML_ELEMENT_NODE
1046 && !strcmp((const char *) ptr->name, "docpath"))
1048 const char *docpath = m_cp->get_text(ptr);
1049 size_t docpath_len = strlen(docpath);
1050 if (docpath_len < strlen(path) && path[docpath_len] == '/'
1051 && !memcmp(docpath, path, docpath_len))
1059 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
1063 int *period_connect,
1064 int *num_msg_threads)
1068 *num_msg_threads = 0;
1071 if (!m_cp->m_proxyPtr)
1073 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1075 if (ptr->type == XML_ELEMENT_NODE
1076 && !strcmp((const char *) ptr->name, "log"))
1078 const char *v = m_cp->get_text(ptr);
1083 while (*cp && *cp != ',' && !isspace(*cp))
1085 size_t len = cp - v;
1086 if (m_cp->mycmp(v, "client-apdu", len))
1087 *log_mask |= PROXY_LOG_APDU_CLIENT;
1088 if (m_cp->mycmp(v, "server-apdu", len))
1089 *log_mask |= PROXY_LOG_APDU_SERVER;
1090 if (m_cp->mycmp(v, "client-requests", len))
1091 *log_mask |= PROXY_LOG_REQ_CLIENT;
1092 if (m_cp->mycmp(v, "server-requests", len))
1093 *log_mask |= PROXY_LOG_REQ_SERVER;
1094 if (m_cp->mycmp(v, "client-ip", len))
1095 *log_mask |= PROXY_LOG_IP_CLIENT;
1097 *log_mask |= atoi(v);
1100 while (*cp && isspace(*cp))
1105 else if (ptr->type == XML_ELEMENT_NODE &&
1106 !strcmp((const char *) ptr->name, "max-clients"))
1108 const char *t = m_cp->get_text(ptr);
1111 *max_clients = atoi(t);
1112 if (*max_clients < 1)
1116 else if (ptr->type == XML_ELEMENT_NODE &&
1117 !strcmp((const char *) ptr->name, "period-connect"))
1119 const char *t = m_cp->get_text(ptr);
1121 *period_connect = atoi(t);
1123 else if (ptr->type == XML_ELEMENT_NODE &&
1124 !strcmp((const char *) ptr->name, "max-connect"))
1126 const char *t = m_cp->get_text(ptr);
1129 *max_connect = atoi(t);
1132 else if (ptr->type == XML_ELEMENT_NODE &&
1133 !strcmp((const char *) ptr->name, "limit-connect"))
1135 const char *t = m_cp->get_text(ptr);
1138 *limit_connect = atoi(t);
1141 else if (ptr->type == XML_ELEMENT_NODE &&
1142 !strcmp((const char *) ptr->name, "target"))
1144 else if (ptr->type == XML_ELEMENT_NODE &&
1145 !strcmp((const char *) ptr->name, "docpath"))
1147 else if (ptr->type == XML_ELEMENT_NODE &&
1148 !strcmp((const char *) ptr->name, "module"))
1150 else if (ptr->type == XML_ELEMENT_NODE &&
1151 !strcmp((const char *) ptr->name, "client-authentication"))
1153 else if (ptr->type == XML_ELEMENT_NODE &&
1154 !strcmp((const char *) ptr->name, "threads"))
1156 const char *t = m_cp->get_text(ptr);
1159 *num_msg_threads = atoi(t);
1162 else if (ptr->type == XML_ELEMENT_NODE)
1164 yaz_log(YLOG_WARN, "0 Unknown element %s in yazproxy config",
1172 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1173 xmlNodePtr *ptr_target,
1174 xmlNodePtr *ptr_explain)
1181 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1183 if (ptr->type == XML_ELEMENT_NODE &&
1184 !strcmp((const char *) ptr->name, "target"))
1187 xmlNodePtr ptr = (*ptr_target)->children;
1188 for (; ptr; ptr = ptr->next)
1190 if (ptr->type == XML_ELEMENT_NODE &&
1191 !strcmp((const char *) ptr->name, "explain"))
1194 xmlNodePtr ptr = (*ptr_explain)->children;
1196 for (; ptr; ptr = ptr->next)
1197 if (ptr->type == XML_ELEMENT_NODE &&
1198 !strcmp((const char *) ptr->name, "serverInfo"))
1202 for (ptr = ptr->children; ptr; ptr = ptr->next)
1203 if (ptr->type == XML_ELEMENT_NODE &&
1204 !strcmp((const char *) ptr->name, "database"))
1209 for (ptr = ptr->children; ptr; ptr = ptr->next)
1210 if (ptr->type == XML_TEXT_NODE &&
1212 !strcmp((const char *) ptr->content, db))
1225 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1226 const char **backend_db)
1229 xmlNodePtr ptr_target, ptr_explain;
1230 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1233 struct _xmlAttr *attr;
1234 const char *name = 0;
1236 for (attr = ptr_target->properties; attr; attr = attr->next)
1237 if (!strcmp((const char *) attr->name, "name")
1239 && attr->children->type==XML_TEXT_NODE
1240 && attr->children->content
1241 && attr->children->content[0])
1243 name = (const char *)attr->children->content;
1248 for (attr = ptr_target->properties; attr; attr = attr->next)
1249 if (!strcmp((const char *) attr->name, "database"))
1252 && attr->children->type==XML_TEXT_NODE
1253 && attr->children->content)
1254 *backend_db = (const char *) attr->children->content;
1263 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1264 const char *db, int *len)
1267 xmlNodePtr ptr_target, ptr_explain;
1268 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1270 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1272 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1274 xmlDocSetRootElement(doc, ptr2);
1277 xmlDocDumpMemory(doc, &buf_out, len);
1278 char *content = (char*) odr_malloc(odr, *len);
1279 memcpy(content, buf_out, *len);
1289 void Yaz_ProxyConfig::get_target_info(const char *name,
1295 int *target_idletime,
1296 int *client_idletime,
1298 int *keepalive_limit_bw,
1299 int *keepalive_limit_pdu,
1301 const char **cql2rpn,
1302 const char **negotiation_charset,
1303 const char **negotiation_lang,
1304 const char **target_charset,
1305 const char **default_client_query_charset)
1309 if (!m_cp->m_proxyPtr)
1316 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1318 if (ptr->type == XML_ELEMENT_NODE &&
1319 !strcmp((const char *) ptr->name, "max-clients"))
1321 const char *t = m_cp->get_text(ptr);
1324 *max_clients = atoi(t);
1325 if (*max_clients < 1)
1330 ptr = m_cp->find_target_node(name, 0);
1338 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1340 target_idletime, client_idletime,
1341 keepalive_limit_bw, keepalive_limit_pdu,
1343 negotiation_charset, negotiation_lang,
1345 default_client_query_charset);
1357 * indent-tabs-mode: nil
1359 * vim: shiftwidth=4 tabstop=8 expandtab