1 /* $Id: yaz-proxy-config.cpp,v 1.35 2007-04-12 18:18:42 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,
45 int *keepalive_limit_bw, int *keepalive_limit_pdu,
46 int *pre_init, const char **cql2rpn,
47 const char **negotiation_charset,
48 const char **negotiation_lang,
49 const char **target_charset,
50 const char **default_client_query_charset);
51 void return_limit(xmlNodePtr ptr,
52 int *limit_bw, int *limit_pdu, int *limit_req,
54 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
56 xmlNodePtr find_target_node(const char *name, const char *db);
57 xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db);
58 const char *get_text(xmlNodePtr ptr);
59 void get_period(xmlNodePtr ptr, int *period);
60 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
61 Z_AttributeList *attrs,
63 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
65 int get_explain_ptr(const char *host, const char *db,
66 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
72 Yaz_ProxyConfigP::Yaz_ProxyConfigP() : m_modules()
80 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
88 Yaz_ProxyConfig::Yaz_ProxyConfig()
90 m_cp = new Yaz_ProxyConfigP();
93 Yaz_ProxyConfig::~Yaz_ProxyConfig()
99 void Yaz_ProxyConfigP::load_modules()
104 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
107 if (ptr->type == XML_ELEMENT_NODE
108 && !strcmp((const char *) ptr->name, "module")
109 && (fname = get_text(ptr)))
111 m_modules.add_module(fname);
117 int Yaz_ProxyConfig::read_xml(const char *fname)
120 xmlDocPtr ndoc = xmlParseFile(fname);
124 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
125 return -1; // no good
127 int noSubstitutions = xmlXIncludeProcess(ndoc);
128 if (noSubstitutions == -1)
129 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
131 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
132 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
133 strcmp((const char *) proxyPtr->name, "proxy"))
135 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
139 m_cp->m_proxyPtr = proxyPtr;
141 // OK: release previous and make it the current one.
143 xmlFreeDoc(m_cp->m_docPtr);
144 m_cp->m_docPtr = ndoc;
146 m_cp->m_modules.unload_modules();
147 m_cp->load_modules();
155 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
157 for(ptr = ptr->children; ptr; ptr = ptr->next)
158 if (ptr->type == XML_TEXT_NODE)
160 xmlChar *t = ptr->content;
165 return (const char *) t;
171 void Yaz_ProxyConfigP::get_period(xmlNodePtr ptr, int *period)
173 struct _xmlAttr *attr;
175 for (attr = ptr->properties; attr; attr = attr->next)
177 if (!strcmp((const char *) attr->name, "period") &&
178 attr->children && attr->children->type == XML_TEXT_NODE)
179 *period = atoi((const char *) attr->children->content);
185 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
191 for (ptr = ptr->children; ptr; ptr = ptr->next)
193 if (ptr->type == XML_ELEMENT_NODE
194 && !strcmp((const char *) ptr->name, "bandwidth"))
196 const char *t = get_text(ptr);
200 if (ptr->type == XML_ELEMENT_NODE
201 && !strcmp((const char *) ptr->name, "retrieve"))
203 const char *t = get_text(ptr);
205 *limit_req = atoi(t);
207 if (ptr->type == XML_ELEMENT_NODE
208 && !strcmp((const char *) ptr->name, "pdu"))
210 const char *t = get_text(ptr);
212 *limit_pdu = atoi(t);
214 if (ptr->type == XML_ELEMENT_NODE
215 && !strcmp((const char *) ptr->name, "search"))
217 const char *t = get_text(ptr);
219 *limit_search = atoi(t);
226 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
232 int *target_idletime,
233 int *client_idletime,
234 int *keepalive_limit_bw,
235 int *keepalive_limit_pdu,
237 const char **cql2rpn,
238 const char **negotiation_charset,
239 const char **negotiation_lang,
240 const char **target_charset,
241 const char **default_client_query_charset)
246 for (; ptr; ptr = ptr->next)
248 if (ptr->type == XML_ELEMENT_NODE
249 && !strcmp((const char *) ptr->name, "preinit"))
251 const char *v = get_text(ptr);
252 *pre_init = v ? atoi(v) : 1;
254 if (ptr->type == XML_ELEMENT_NODE
255 && !strcmp((const char *) ptr->name, "url"))
257 const char *t = get_text(ptr);
258 if (t && no_url < MAX_ZURL_PLEX)
264 if (ptr->type == XML_ELEMENT_NODE
265 && !strcmp((const char *) ptr->name, "keepalive"))
268 *keepalive_limit_bw = 500000;
269 *keepalive_limit_pdu = 1000;
270 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
273 if (ptr->type == XML_ELEMENT_NODE
274 && !strcmp((const char *) ptr->name, "limit"))
275 return_limit(ptr, limit_bw, limit_pdu, limit_req,
277 if (ptr->type == XML_ELEMENT_NODE
278 && !strcmp((const char *) ptr->name, "target-timeout"))
280 const char *t = get_text(ptr);
283 *target_idletime = atoi(t);
284 if (*target_idletime < 0)
285 *target_idletime = 0;
288 if (ptr->type == XML_ELEMENT_NODE
289 && !strcmp((const char *) ptr->name, "client-timeout"))
291 const char *t = get_text(ptr);
294 *client_idletime = atoi(t);
295 if (*client_idletime < 0)
296 *client_idletime = 0;
299 if (ptr->type == XML_ELEMENT_NODE
300 && !strcmp((const char *) ptr->name, "cql2rpn"))
302 const char *t = get_text(ptr);
306 if (ptr->type == XML_ELEMENT_NODE
307 && !strcmp((const char *) ptr->name, "target-charset"))
309 const char *t = get_text(ptr);
310 if (t && target_charset)
313 if (ptr->type == XML_ELEMENT_NODE
314 && !strcmp((const char *) ptr->name, "default-client-charset"))
316 const char *t = get_text(ptr);
317 if (t && default_client_query_charset)
318 *default_client_query_charset = t;
320 if (ptr->type == XML_ELEMENT_NODE
321 && !strcmp((const char *) ptr->name, "negotiation-charset"))
323 const char *t = get_text(ptr);
325 *negotiation_charset = t;
327 if (ptr->type == XML_ELEMENT_NODE
328 && !strcmp((const char *) ptr->name, "negotiation-lang"))
330 const char *t = get_text(ptr);
332 *negotiation_lang = t;
338 int Yaz_ProxyConfigP::atoi_l(const char **cp)
341 while (**cp && isdigit(**cp))
343 v = v*10 + (**cp - '0');
349 int Yaz_ProxyConfigP::match_list(int v, const char *m)
353 while(*m && isspace(*m))
364 if (v >= l && v <= h)
373 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
374 Z_AttributeList *attrs,
378 for (i = 0; i<attrs->num_attributes; i++)
380 Z_AttributeElement *el = attrs->attributes[i];
382 if (!el->attributeType)
384 int type = *el->attributeType;
387 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
388 value = el->value.numeric;
391 for(ptr = ptrl->children; ptr; ptr = ptr->next)
393 if (ptr->type == XML_ELEMENT_NODE &&
394 !strcmp((const char *) ptr->name, "attribute"))
396 const char *match_type = 0;
397 const char *match_value = 0;
398 const char *match_error = 0;
399 struct _xmlAttr *attr;
400 for (attr = ptr->properties; attr; attr = attr->next)
402 if (!strcmp((const char *) attr->name, "type") &&
403 attr->children && attr->children->type == XML_TEXT_NODE)
404 match_type = (const char *) attr->children->content;
405 if (!strcmp((const char *) attr->name, "value") &&
406 attr->children && attr->children->type == XML_TEXT_NODE)
407 match_value = (const char *) attr->children->content;
408 if (!strcmp((const char *) attr->name, "error") &&
409 attr->children && attr->children->type == XML_TEXT_NODE)
410 match_error = (const char *) attr->children->content;
412 if (match_type && match_value)
414 char addinfo_str[20];
415 if (!match_list(type, match_type))
419 if (!strcmp(match_type, "*"))
420 sprintf (addinfo_str, "%d", type);
423 if (!match_list(*value, match_value))
425 sprintf (addinfo_str, "%d", *value);
433 *addinfo = odr_strdup(odr, addinfo_str);
434 return atoi(match_error);
446 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
450 if (q->which == Z_RPNStructure_complex)
452 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
455 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
458 else if (q->which == Z_RPNStructure_simple)
460 if (q->u.simple->which == Z_Operand_APT)
462 return check_type_1_attributes(
463 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
472 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
475 // possibly check for Bib-1
476 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
480 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
486 ptr = m_cp->find_target_node(name, 0);
489 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
490 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
497 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
498 const char *schema_identifier)
501 int default_match = 1;
502 if (comp && comp->which == Z_RecordComp_simple &&
503 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
505 esn = comp->u.simple->u.generic;
507 // if no ESN/schema was given accept..
510 // check if schema identifier match
511 if (schema_identifier && !strcmp(esn, schema_identifier))
513 // Check each name element
514 for (; ptr; ptr = ptr->next)
516 if (ptr->type == XML_ELEMENT_NODE
517 && !strcmp((const char *) ptr->name, "name"))
519 xmlNodePtr tptr = ptr->children;
521 for (; tptr; tptr = tptr->next)
522 if (tptr->type == XML_TEXT_NODE && tptr->content)
524 xmlChar *t = tptr->content;
525 while (*t && isspace(*t))
528 while (esn[i] && esn[i] == t[i])
530 if (!esn[i] && (!t[i] || isspace(t[i])))
535 return default_match;
539 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
545 {".xml", "text/xml"},
546 {".xsl", "text/xml"},
547 {".tkl", "text/xml"},
548 {".xsd", "text/xml"},
549 {".html", "text/html"},
550 {".jpg", "image/jpeg"},
551 {".png", "image/png"},
552 {".gif", "image/gif"},
553 {".css", "text/css"},
554 {".pdf", "application/pdf"},
559 size_t plen = strlen (path);
560 for (i = 0; types[i].type; i++)
561 if (types[i].mask == 0)
562 return types[i].type;
565 size_t mlen = strlen(types[i].mask);
566 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
567 return types[i].type;
569 return "application/octet-stream";
573 void Yaz_ProxyConfig::target_authentication(const char *name,
574 ODR odr, Z_InitRequest *req)
577 xmlNodePtr ptr = m_cp->find_target_node(name, 0);
581 for (ptr = ptr->children; ptr; ptr = ptr->next)
582 if (ptr->type == XML_ELEMENT_NODE &&
583 !strcmp((const char *) ptr->name, "target-authentication"))
585 struct _xmlAttr *attr;
586 const char *type = "open";
587 for (attr = ptr->properties; attr; attr = attr->next)
589 if (!strcmp((const char *) attr->name, "type") &&
590 attr->children && attr->children->type == XML_TEXT_NODE)
591 type = (const char *) attr->children->content;
593 const char *t = m_cp->get_text(ptr);
594 if (!t || !strcmp(type, "none"))
596 req->idAuthentication = 0;
598 else if (!strcmp(type, "anonymous"))
600 req->idAuthentication =
601 (Z_IdAuthentication *)
602 odr_malloc (odr, sizeof(*req->idAuthentication));
603 req->idAuthentication->which =
604 Z_IdAuthentication_anonymous;
605 req->idAuthentication->u.anonymous = odr_nullval();
607 else if (!strcmp(type, "open"))
609 req->idAuthentication =
610 (Z_IdAuthentication *)
611 odr_malloc (odr, sizeof(*req->idAuthentication));
612 req->idAuthentication->which =
613 Z_IdAuthentication_open;
614 req->idAuthentication->u.open = odr_strdup (odr, t);
616 else if (!strcmp(type, "idPass"))
618 char user[64], group[64], password[64];
622 sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
624 req->idAuthentication =
625 (Z_IdAuthentication *)
626 odr_malloc (odr, sizeof(*req->idAuthentication));
627 req->idAuthentication->which =
628 Z_IdAuthentication_idPass;
629 req->idAuthentication->u.idPass =
630 (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
631 req->idAuthentication->u.idPass->userId =
632 *user ? odr_strdup(odr, user) : 0;
633 req->idAuthentication->u.idPass->groupId =
634 *group ? odr_strdup(odr, group) : 0;
635 req->idAuthentication->u.idPass->password =
636 *password ? odr_strdup(odr, password) : 0;
642 int Yaz_ProxyConfig::client_authentication(const char *name,
645 const char *password,
648 int ret = YAZPROXY_RET_NOT_ME;
651 ptr = m_cp->find_target_node(name, 0);
654 for (ptr = ptr->children; ptr; ptr = ptr->next)
655 if (ptr->type == XML_ELEMENT_NODE &&
656 !strcmp((const char *) ptr->name, "client-authentication"))
658 struct _xmlAttr *attr;
659 const char *module_name = 0;
660 for (attr = ptr->properties; attr; attr = attr->next)
662 if (!strcmp((const char *) attr->name, "module") &&
663 attr->children && attr->children->type == XML_TEXT_NODE)
664 module_name = (const char *) attr->children->content;
666 ret = m_cp->m_modules.authenticate(module_name,
668 user, group, password,
671 if (ret != YAZPROXY_RET_NOT_ME)
675 if (ret == YAZPROXY_RET_PERM)
680 int Yaz_ProxyConfig::global_client_authentication(const char *user,
682 const char *password,
685 int ret = YAZPROXY_RET_NOT_ME;
687 if (!m_cp->m_proxyPtr)
690 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
692 if (ptr->type == XML_ELEMENT_NODE &&
693 !strcmp((const char *) ptr->name, "client-authentication"))
695 struct _xmlAttr *attr;
696 const char *module_name = 0;
697 for (attr = ptr->properties; attr; attr = attr->next)
699 if (!strcmp((const char *) attr->name, "module") &&
700 attr->children && attr->children->type == XML_TEXT_NODE)
701 module_name = (const char *) attr->children->content;
703 ret = m_cp->m_modules.authenticate(module_name,
705 user, group, password,
708 if (ret != YAZPROXY_RET_NOT_ME)
713 if (ret == YAZPROXY_RET_PERM)
718 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
719 Odr_oid *syntax, Z_RecordComposition *comp,
721 char **stylesheet, char **schema,
723 char **backend_charset,
724 char **usemarcon_ini_stage1,
725 char **usemarcon_ini_stage2
740 xfree (*backend_type);
745 xfree (*backend_charset);
746 *backend_charset = 0;
748 if (usemarcon_ini_stage1)
750 xfree (*usemarcon_ini_stage1);
751 *usemarcon_ini_stage1 = 0;
753 if (usemarcon_ini_stage2)
755 xfree (*usemarcon_ini_stage2);
756 *usemarcon_ini_stage2 = 0;
759 int syntax_has_matched = 0;
762 ptr = m_cp->find_target_node(name, 0);
765 for(ptr = ptr->children; ptr; ptr = ptr->next)
767 if (ptr->type == XML_ELEMENT_NODE &&
768 !strcmp((const char *) ptr->name, "syntax"))
770 int match = 0; // if we match record syntax
771 const char *match_type = 0;
772 const char *match_error = 0;
773 const char *match_marcxml = 0;
774 const char *match_stylesheet = 0;
775 const char *match_identifier = 0;
776 const char *match_backend_type = 0;
777 const char *match_backend_charset = 0;
778 const char *match_usemarcon_ini_stage1 = 0;
779 const char *match_usemarcon_ini_stage2 = 0;
780 struct _xmlAttr *attr;
781 for (attr = ptr->properties; attr; attr = attr->next)
783 if (!strcmp((const char *) attr->name, "type") &&
784 attr->children && attr->children->type == XML_TEXT_NODE)
785 match_type = (const char *) attr->children->content;
786 if (!strcmp((const char *) attr->name, "error") &&
787 attr->children && attr->children->type == XML_TEXT_NODE)
788 match_error = (const char *) attr->children->content;
789 if (!strcmp((const char *) attr->name, "marcxml") &&
790 attr->children && attr->children->type == XML_TEXT_NODE)
791 match_marcxml = (const char *) attr->children->content;
792 if (!strcmp((const char *) attr->name, "stylesheet") &&
793 attr->children && attr->children->type == XML_TEXT_NODE)
794 match_stylesheet = (const char *) attr->children->content;
795 if (!strcmp((const char *) attr->name, "identifier") &&
796 attr->children && attr->children->type == XML_TEXT_NODE)
797 match_identifier = (const char *) attr->children->content;
798 if (!strcmp((const char *) attr->name, "backendtype") &&
799 attr->children && attr->children->type == XML_TEXT_NODE)
800 match_backend_type = (const char *)
801 attr->children->content;
802 if (!strcmp((const char *) attr->name, "backendcharset") &&
803 attr->children && attr->children->type == XML_TEXT_NODE)
804 match_backend_charset = (const char *)
805 attr->children->content;
806 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
807 attr->children && attr->children->type == XML_TEXT_NODE)
808 match_usemarcon_ini_stage1 = (const char *)
809 attr->children->content;
810 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
811 attr->children && attr->children->type == XML_TEXT_NODE)
812 match_usemarcon_ini_stage2 = (const char *)
813 attr->children->content;
817 if (!strcmp(match_type, "*"))
819 else if (!strcmp(match_type, "none"))
827 = yaz_string_to_oid_odr(yaz_oid_std(),
828 CLASS_RECSYN, match_type,
830 if (oid_oidcmp(match_oid, syntax) == 0)
837 syntax_has_matched = 1;
838 match = m_cp->check_schema(ptr->children, comp,
843 if (stylesheet && match_stylesheet)
846 *stylesheet = xstrdup(match_stylesheet);
848 if (schema && match_identifier)
851 *schema = xstrdup(match_identifier);
853 if (backend_type && match_backend_type)
855 xfree(*backend_type);
856 *backend_type = xstrdup(match_backend_type);
858 if (backend_charset && match_backend_charset)
860 xfree(*backend_charset);
861 *backend_charset = xstrdup(match_backend_charset);
863 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
865 xfree(*usemarcon_ini_stage1);
866 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
868 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
870 xfree(*usemarcon_ini_stage2);
871 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
879 if (syntax_has_matched) // if syntax OK, bad schema/ESN
883 char dotoid_str[100];
884 oid_to_dotstring(syntax, dotoid_str);
885 *addinfo = odr_strdup(odr, dotoid_str);
887 return atoi(match_error);
898 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
905 for (dptr = ptr->children; dptr; dptr = dptr->next)
906 if (dptr->type == XML_ELEMENT_NODE &&
907 !strcmp((const char *) dptr->name, "database"))
909 struct _xmlAttr *attr;
910 for (attr = dptr->properties; attr; attr = attr->next)
911 if (!strcmp((const char *) attr->name, "name"))
914 && attr->children->type==XML_TEXT_NODE
915 && attr->children->content
916 && (!strcmp((const char *) attr->children->content, db)
917 || !strcmp((const char *) attr->children->content,
925 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
930 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
932 if (ptr->type == XML_ELEMENT_NODE &&
933 !strcmp((const char *) ptr->name, "target"))
938 // <target default="1"> ?
939 struct _xmlAttr *attr;
940 for (attr = ptr->properties; attr; attr = attr->next)
941 if (!strcmp((const char *) attr->name, "default") &&
942 attr->children && attr->children->type == XML_TEXT_NODE)
944 xmlChar *t = attr->children->content;
947 return find_target_db(ptr, db);
953 // <target name="name"> ?
954 struct _xmlAttr *attr;
955 for (attr = ptr->properties; attr; attr = attr->next)
956 if (!strcmp((const char *) attr->name, "name"))
959 && attr->children->type==XML_TEXT_NODE
960 && attr->children->content
961 && (!strcmp((const char *) attr->children->content,
963 || !strcmp((const char *) attr->children->content,
966 return find_target_db(ptr, db);
976 int Yaz_ProxyConfig::get_target_no(int no,
983 int *target_idletime,
984 int *client_idletime,
986 int *keepalive_limit_bw,
987 int *keepalive_limit_pdu,
989 const char **cql2rpn,
990 const char **authentication,
991 const char **negotiation_charset,
992 const char **negotiation_lang,
993 const char **target_charset,
994 const char **default_client_query_charset)
998 if (!m_cp->m_proxyPtr)
1001 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1002 if (ptr->type == XML_ELEMENT_NODE &&
1003 !strcmp((const char *) ptr->name, "target"))
1007 struct _xmlAttr *attr;
1008 for (attr = ptr->properties; attr; attr = attr->next)
1009 if (!strcmp((const char *) attr->name, "name"))
1012 && attr->children->type==XML_TEXT_NODE
1013 && attr->children->content)
1014 *name = (const char *) attr->children->content;
1016 m_cp->return_target_info(
1018 limit_bw, limit_pdu, limit_req,
1020 target_idletime, client_idletime,
1021 keepalive_limit_bw, keepalive_limit_pdu,
1023 negotiation_charset, negotiation_lang, target_charset,
1024 default_client_query_charset);
1033 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
1035 if (len == strlen(item) && memcmp(hay, item, len) == 0)
1040 int Yaz_ProxyConfig::get_file_access_info(const char *path)
1044 if (!m_cp->m_proxyPtr)
1046 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1048 if (ptr->type == XML_ELEMENT_NODE
1049 && !strcmp((const char *) ptr->name, "docpath"))
1051 const char *docpath = m_cp->get_text(ptr);
1052 size_t docpath_len = strlen(docpath);
1053 if (docpath_len < strlen(path) && path[docpath_len] == '/'
1054 && !memcmp(docpath, path, docpath_len))
1062 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
1066 int *period_connect,
1067 int *num_msg_threads)
1071 *num_msg_threads = 0;
1074 if (!m_cp->m_proxyPtr)
1076 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1078 if (ptr->type == XML_ELEMENT_NODE
1079 && !strcmp((const char *) ptr->name, "log"))
1081 const char *v = m_cp->get_text(ptr);
1086 while (*cp && *cp != ',' && !isspace(*cp))
1088 size_t len = cp - v;
1089 if (m_cp->mycmp(v, "client-apdu", len))
1090 *log_mask |= PROXY_LOG_APDU_CLIENT;
1091 if (m_cp->mycmp(v, "server-apdu", len))
1092 *log_mask |= PROXY_LOG_APDU_SERVER;
1093 if (m_cp->mycmp(v, "client-requests", len))
1094 *log_mask |= PROXY_LOG_REQ_CLIENT;
1095 if (m_cp->mycmp(v, "server-requests", len))
1096 *log_mask |= PROXY_LOG_REQ_SERVER;
1097 if (m_cp->mycmp(v, "client-ip", len))
1098 *log_mask |= PROXY_LOG_IP_CLIENT;
1100 *log_mask |= atoi(v);
1103 while (*cp && isspace(*cp))
1108 else if (ptr->type == XML_ELEMENT_NODE &&
1109 !strcmp((const char *) ptr->name, "max-clients"))
1111 const char *t = m_cp->get_text(ptr);
1114 *max_clients = atoi(t);
1115 if (*max_clients < 1)
1119 else if (ptr->type == XML_ELEMENT_NODE &&
1120 !strcmp((const char *) ptr->name, "period-connect"))
1122 const char *t = m_cp->get_text(ptr);
1124 *period_connect = atoi(t);
1126 else if (ptr->type == XML_ELEMENT_NODE &&
1127 !strcmp((const char *) ptr->name, "max-connect"))
1129 const char *t = m_cp->get_text(ptr);
1132 *max_connect = atoi(t);
1135 else if (ptr->type == XML_ELEMENT_NODE &&
1136 !strcmp((const char *) ptr->name, "limit-connect"))
1138 const char *t = m_cp->get_text(ptr);
1141 *limit_connect = atoi(t);
1144 else if (ptr->type == XML_ELEMENT_NODE &&
1145 !strcmp((const char *) ptr->name, "target"))
1147 else if (ptr->type == XML_ELEMENT_NODE &&
1148 !strcmp((const char *) ptr->name, "docpath"))
1150 else if (ptr->type == XML_ELEMENT_NODE &&
1151 !strcmp((const char *) ptr->name, "module"))
1153 else if (ptr->type == XML_ELEMENT_NODE &&
1154 !strcmp((const char *) ptr->name, "client-authentication"))
1156 else if (ptr->type == XML_ELEMENT_NODE &&
1157 !strcmp((const char *) ptr->name, "threads"))
1159 const char *t = m_cp->get_text(ptr);
1162 *num_msg_threads = atoi(t);
1165 else if (ptr->type == XML_ELEMENT_NODE)
1167 yaz_log(YLOG_WARN, "0 Unknown element %s in yazproxy config",
1175 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1176 xmlNodePtr *ptr_target,
1177 xmlNodePtr *ptr_explain)
1184 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1186 if (ptr->type == XML_ELEMENT_NODE &&
1187 !strcmp((const char *) ptr->name, "target"))
1190 xmlNodePtr ptr = (*ptr_target)->children;
1191 for (; ptr; ptr = ptr->next)
1193 if (ptr->type == XML_ELEMENT_NODE &&
1194 !strcmp((const char *) ptr->name, "explain"))
1197 xmlNodePtr ptr = (*ptr_explain)->children;
1199 for (; ptr; ptr = ptr->next)
1200 if (ptr->type == XML_ELEMENT_NODE &&
1201 !strcmp((const char *) ptr->name, "serverInfo"))
1205 for (ptr = ptr->children; ptr; ptr = ptr->next)
1206 if (ptr->type == XML_ELEMENT_NODE &&
1207 !strcmp((const char *) ptr->name, "database"))
1212 for (ptr = ptr->children; ptr; ptr = ptr->next)
1213 if (ptr->type == XML_TEXT_NODE &&
1215 !strcmp((const char *) ptr->content, db))
1228 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1229 const char **backend_db)
1232 xmlNodePtr ptr_target, ptr_explain;
1233 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1236 struct _xmlAttr *attr;
1237 const char *name = 0;
1239 for (attr = ptr_target->properties; attr; attr = attr->next)
1240 if (!strcmp((const char *) attr->name, "name")
1242 && attr->children->type==XML_TEXT_NODE
1243 && attr->children->content
1244 && attr->children->content[0])
1246 name = (const char *)attr->children->content;
1251 for (attr = ptr_target->properties; attr; attr = attr->next)
1252 if (!strcmp((const char *) attr->name, "database"))
1255 && attr->children->type==XML_TEXT_NODE
1256 && attr->children->content)
1257 *backend_db = (const char *) attr->children->content;
1266 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1267 const char *db, int *len)
1270 xmlNodePtr ptr_target, ptr_explain;
1271 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1273 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1275 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1277 xmlDocSetRootElement(doc, ptr2);
1280 xmlDocDumpMemory(doc, &buf_out, len);
1281 char *content = (char*) odr_malloc(odr, *len);
1282 memcpy(content, buf_out, *len);
1292 void Yaz_ProxyConfig::get_target_info(const char *name,
1298 int *target_idletime,
1299 int *client_idletime,
1301 int *keepalive_limit_bw,
1302 int *keepalive_limit_pdu,
1304 const char **cql2rpn,
1305 const char **negotiation_charset,
1306 const char **negotiation_lang,
1307 const char **target_charset,
1308 const char **default_client_query_charset)
1312 if (!m_cp->m_proxyPtr)
1319 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1321 if (ptr->type == XML_ELEMENT_NODE &&
1322 !strcmp((const char *) ptr->name, "max-clients"))
1324 const char *t = m_cp->get_text(ptr);
1327 *max_clients = atoi(t);
1328 if (*max_clients < 1)
1333 ptr = m_cp->find_target_node(name, 0);
1341 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1343 target_idletime, client_idletime,
1344 keepalive_limit_bw, keepalive_limit_pdu,
1346 negotiation_charset, negotiation_lang,
1348 default_client_query_charset);
1360 * indent-tabs-mode: nil
1362 * vim: shiftwidth=4 tabstop=8 expandtab