1 /* $Id: yaz-proxy-config.cpp,v 1.26 2006-03-30 10:35:15 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 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
59 Z_AttributeList *attrs,
61 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
63 int get_explain_ptr(const char *host, const char *db,
64 xmlNodePtr *ptr_target, xmlNodePtr *ptr_explain);
70 Yaz_ProxyConfigP::Yaz_ProxyConfigP() : m_modules()
78 Yaz_ProxyConfigP::~Yaz_ProxyConfigP()
86 Yaz_ProxyConfig::Yaz_ProxyConfig()
88 m_cp = new Yaz_ProxyConfigP();
91 Yaz_ProxyConfig::~Yaz_ProxyConfig()
97 void Yaz_ProxyConfigP::load_modules()
102 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
105 if (ptr->type == XML_ELEMENT_NODE
106 && !strcmp((const char *) ptr->name, "module")
107 && (fname = get_text(ptr)))
109 m_modules.add_module(fname);
115 int Yaz_ProxyConfig::read_xml(const char *fname)
118 xmlDocPtr ndoc = xmlParseFile(fname);
122 yaz_log(YLOG_WARN, "Config file %s not found or parse error", fname);
123 return -1; // no good
125 int noSubstitutions = xmlXIncludeProcess(ndoc);
126 if (noSubstitutions == -1)
127 yaz_log(YLOG_WARN, "XInclude processing failed on config %s", fname);
129 xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
130 if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
131 strcmp((const char *) proxyPtr->name, "proxy"))
133 yaz_log(YLOG_WARN, "No proxy element in %s", fname);
137 m_cp->m_proxyPtr = proxyPtr;
139 // OK: release previous and make it the current one.
141 xmlFreeDoc(m_cp->m_docPtr);
142 m_cp->m_docPtr = ndoc;
144 m_cp->m_modules.unload_modules();
145 m_cp->load_modules();
153 const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr)
155 for(ptr = ptr->children; ptr; ptr = ptr->next)
156 if (ptr->type == XML_TEXT_NODE)
158 xmlChar *t = ptr->content;
163 return (const char *) t;
171 void Yaz_ProxyConfigP::return_limit(xmlNodePtr ptr,
177 for (ptr = ptr->children; ptr; ptr = ptr->next)
179 if (ptr->type == XML_ELEMENT_NODE
180 && !strcmp((const char *) ptr->name, "bandwidth"))
182 const char *t = get_text(ptr);
186 if (ptr->type == XML_ELEMENT_NODE
187 && !strcmp((const char *) ptr->name, "retrieve"))
189 const char *t = get_text(ptr);
191 *limit_req = atoi(t);
193 if (ptr->type == XML_ELEMENT_NODE
194 && !strcmp((const char *) ptr->name, "pdu"))
196 const char *t = get_text(ptr);
198 *limit_pdu = atoi(t);
200 if (ptr->type == XML_ELEMENT_NODE
201 && !strcmp((const char *) ptr->name, "search"))
203 const char *t = get_text(ptr);
205 *limit_search = atoi(t);
212 void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
218 int *target_idletime,
219 int *client_idletime,
220 int *keepalive_limit_bw,
221 int *keepalive_limit_pdu,
223 const char **cql2rpn,
224 const char **negotiation_charset,
225 const char **negotiation_lang,
226 const char **target_charset,
227 const char **default_client_query_charset)
232 for (; ptr; ptr = ptr->next)
234 if (ptr->type == XML_ELEMENT_NODE
235 && !strcmp((const char *) ptr->name, "preinit"))
237 const char *v = get_text(ptr);
238 *pre_init = v ? atoi(v) : 1;
240 if (ptr->type == XML_ELEMENT_NODE
241 && !strcmp((const char *) ptr->name, "url"))
243 const char *t = get_text(ptr);
244 if (t && no_url < MAX_ZURL_PLEX)
250 if (ptr->type == XML_ELEMENT_NODE
251 && !strcmp((const char *) ptr->name, "keepalive"))
254 *keepalive_limit_bw = 500000;
255 *keepalive_limit_pdu = 1000;
256 return_limit(ptr, keepalive_limit_bw, keepalive_limit_pdu,
259 if (ptr->type == XML_ELEMENT_NODE
260 && !strcmp((const char *) ptr->name, "limit"))
261 return_limit(ptr, limit_bw, limit_pdu, limit_req,
263 if (ptr->type == XML_ELEMENT_NODE
264 && !strcmp((const char *) ptr->name, "target-timeout"))
266 const char *t = get_text(ptr);
269 *target_idletime = atoi(t);
270 if (*target_idletime < 0)
271 *target_idletime = 0;
274 if (ptr->type == XML_ELEMENT_NODE
275 && !strcmp((const char *) ptr->name, "client-timeout"))
277 const char *t = get_text(ptr);
280 *client_idletime = atoi(t);
281 if (*client_idletime < 0)
282 *client_idletime = 0;
285 if (ptr->type == XML_ELEMENT_NODE
286 && !strcmp((const char *) ptr->name, "cql2rpn"))
288 const char *t = get_text(ptr);
292 if (ptr->type == XML_ELEMENT_NODE
293 && !strcmp((const char *) ptr->name, "target-charset"))
295 const char *t = get_text(ptr);
296 if (t && target_charset)
299 if (ptr->type == XML_ELEMENT_NODE
300 && !strcmp((const char *) ptr->name, "default-client-charset"))
302 const char *t = get_text(ptr);
303 if (t && default_client_query_charset)
304 *default_client_query_charset = t;
306 if (ptr->type == XML_ELEMENT_NODE
307 && !strcmp((const char *) ptr->name, "negotiation-charset"))
309 const char *t = get_text(ptr);
311 *negotiation_charset = t;
313 if (ptr->type == XML_ELEMENT_NODE
314 && !strcmp((const char *) ptr->name, "negotiation-lang"))
316 const char *t = get_text(ptr);
318 *negotiation_lang = t;
324 int Yaz_ProxyConfigP::atoi_l(const char **cp)
327 while (**cp && isdigit(**cp))
329 v = v*10 + (**cp - '0');
335 int Yaz_ProxyConfigP::match_list(int v, const char *m)
339 while(*m && isspace(*m))
350 if (v >= l && v <= h)
359 int Yaz_ProxyConfigP::check_type_1_attributes(ODR odr, xmlNodePtr ptrl,
360 Z_AttributeList *attrs,
364 for (i = 0; i<attrs->num_attributes; i++)
366 Z_AttributeElement *el = attrs->attributes[i];
368 if (!el->attributeType)
370 int type = *el->attributeType;
373 if (el->which == Z_AttributeValue_numeric && el->value.numeric)
374 value = el->value.numeric;
377 for(ptr = ptrl->children; ptr; ptr = ptr->next)
379 if (ptr->type == XML_ELEMENT_NODE &&
380 !strcmp((const char *) ptr->name, "attribute"))
382 const char *match_type = 0;
383 const char *match_value = 0;
384 const char *match_error = 0;
385 struct _xmlAttr *attr;
386 for (attr = ptr->properties; attr; attr = attr->next)
388 if (!strcmp((const char *) attr->name, "type") &&
389 attr->children && attr->children->type == XML_TEXT_NODE)
390 match_type = (const char *) attr->children->content;
391 if (!strcmp((const char *) attr->name, "value") &&
392 attr->children && attr->children->type == XML_TEXT_NODE)
393 match_value = (const char *) attr->children->content;
394 if (!strcmp((const char *) attr->name, "error") &&
395 attr->children && attr->children->type == XML_TEXT_NODE)
396 match_error = (const char *) attr->children->content;
398 if (match_type && match_value)
400 char addinfo_str[20];
401 if (!match_list(type, match_type))
405 if (!strcmp(match_type, "*"))
406 sprintf (addinfo_str, "%d", type);
409 if (!match_list(*value, match_value))
411 sprintf (addinfo_str, "%d", *value);
419 *addinfo = odr_strdup(odr, addinfo_str);
420 return atoi(match_error);
432 int Yaz_ProxyConfigP::check_type_1_structure(ODR odr, xmlNodePtr ptr,
436 if (q->which == Z_RPNStructure_complex)
438 int e = check_type_1_structure(odr, ptr, q->u.complex->s1, addinfo);
441 e = check_type_1_structure(odr, ptr, q->u.complex->s2, addinfo);
444 else if (q->which == Z_RPNStructure_simple)
446 if (q->u.simple->which == Z_Operand_APT)
448 return check_type_1_attributes(
449 odr, ptr, q->u.simple->u.attributesPlusTerm->attributes,
458 int Yaz_ProxyConfigP::check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
461 // possibly check for Bib-1
462 return check_type_1_structure(odr, ptr, query->RPNStructure, addinfo);
466 int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query,
472 ptr = m_cp->find_target_node(name, 0);
475 if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
476 return m_cp->check_type_1(odr, ptr, query->u.type_1, addinfo);
483 int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
484 const char *schema_identifier)
487 int default_match = 1;
488 if (comp && comp->which == Z_RecordComp_simple &&
489 comp->u.simple && comp->u.simple->which == Z_ElementSetNames_generic)
491 esn = comp->u.simple->u.generic;
493 // if no ESN/schema was given accept..
496 // check if schema identifier match
497 if (schema_identifier && !strcmp(esn, schema_identifier))
499 // Check each name element
500 for (; ptr; ptr = ptr->next)
502 if (ptr->type == XML_ELEMENT_NODE
503 && !strcmp((const char *) ptr->name, "name"))
505 xmlNodePtr tptr = ptr->children;
507 for (; tptr; tptr = tptr->next)
508 if (tptr->type == XML_TEXT_NODE && tptr->content)
510 xmlChar *t = tptr->content;
511 while (*t && isspace(*t))
514 while (esn[i] && esn[i] == t[i])
516 if (!esn[i] && (!t[i] || isspace(t[i])))
521 return default_match;
525 const char *Yaz_ProxyConfig::check_mime_type(const char *path)
531 {".xml", "text/xml"},
532 {".xsl", "text/xml"},
533 {".tkl", "text/xml"},
534 {".xsd", "text/xml"},
535 {".html", "text/html"},
536 {".jpg", "image/jpeg"},
537 {".png", "image/png"},
538 {".gif", "image/gif"},
543 size_t plen = strlen (path);
544 for (i = 0; types[i].type; i++)
545 if (types[i].mask == 0)
546 return types[i].type;
549 size_t mlen = strlen(types[i].mask);
550 if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
551 return types[i].type;
553 return "application/octet-stream";
557 void Yaz_ProxyConfig::target_authentication(const char *name,
558 ODR odr, Z_InitRequest *req)
561 xmlNodePtr ptr = m_cp->find_target_node(name, 0);
565 for (ptr = ptr->children; ptr; ptr = ptr->next)
566 if (ptr->type == XML_ELEMENT_NODE &&
567 !strcmp((const char *) ptr->name, "target-authentication"))
569 struct _xmlAttr *attr;
570 const char *type = "open";
571 for (attr = ptr->properties; attr; attr = attr->next)
573 if (!strcmp((const char *) attr->name, "type") &&
574 attr->children && attr->children->type == XML_TEXT_NODE)
575 type = (const char *) attr->children->content;
577 const char *t = m_cp->get_text(ptr);
578 if (!t || !strcmp(type, "none"))
580 req->idAuthentication = 0;
582 else if (!strcmp(type, "anonymous"))
584 req->idAuthentication =
585 (Z_IdAuthentication *)
586 odr_malloc (odr, sizeof(*req->idAuthentication));
587 req->idAuthentication->which =
588 Z_IdAuthentication_anonymous;
589 req->idAuthentication->u.anonymous = odr_nullval();
591 else if (!strcmp(type, "open"))
593 req->idAuthentication =
594 (Z_IdAuthentication *)
595 odr_malloc (odr, sizeof(*req->idAuthentication));
596 req->idAuthentication->which =
597 Z_IdAuthentication_open;
598 req->idAuthentication->u.open = odr_strdup (odr, t);
600 else if (!strcmp(type, "idPass"))
602 char user[64], group[64], password[64];
606 sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
608 req->idAuthentication =
609 (Z_IdAuthentication *)
610 odr_malloc (odr, sizeof(*req->idAuthentication));
611 req->idAuthentication->which =
612 Z_IdAuthentication_idPass;
613 req->idAuthentication->u.idPass =
614 (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
615 req->idAuthentication->u.idPass->userId =
616 *user ? odr_strdup(odr, user) : 0;
617 req->idAuthentication->u.idPass->groupId =
618 *group ? odr_strdup(odr, group) : 0;
619 req->idAuthentication->u.idPass->password =
620 *password ? odr_strdup(odr, password) : 0;
626 int Yaz_ProxyConfig::client_authentication(const char *name,
629 const char *password,
632 int ret = YAZPROXY_RET_NOT_ME;
635 ptr = m_cp->find_target_node(name, 0);
638 for (ptr = ptr->children; ptr; ptr = ptr->next)
639 if (ptr->type == XML_ELEMENT_NODE &&
640 !strcmp((const char *) ptr->name, "client-authentication"))
642 struct _xmlAttr *attr;
643 const char *module_name = 0;
644 for (attr = ptr->properties; attr; attr = attr->next)
646 if (!strcmp((const char *) attr->name, "module") &&
647 attr->children && attr->children->type == XML_TEXT_NODE)
648 module_name = (const char *) attr->children->content;
650 ret = m_cp->m_modules.authenticate(module_name,
652 user, group, password,
655 if (ret != YAZPROXY_RET_NOT_ME)
659 if (ret == YAZPROXY_RET_PERM)
664 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
665 Odr_oid *syntax, Z_RecordComposition *comp,
667 char **stylesheet, char **schema,
669 char **backend_charset,
670 char **usemarcon_ini_stage1,
671 char **usemarcon_ini_stage2
686 xfree (*backend_type);
691 xfree (*backend_charset);
692 *backend_charset = 0;
694 if (usemarcon_ini_stage1)
696 xfree (*usemarcon_ini_stage1);
697 *usemarcon_ini_stage1 = 0;
699 if (usemarcon_ini_stage2)
701 xfree (*usemarcon_ini_stage2);
702 *usemarcon_ini_stage2 = 0;
705 int syntax_has_matched = 0;
708 ptr = m_cp->find_target_node(name, 0);
711 for(ptr = ptr->children; ptr; ptr = ptr->next)
713 if (ptr->type == XML_ELEMENT_NODE &&
714 !strcmp((const char *) ptr->name, "syntax"))
716 int match = 0; // if we match record syntax
717 const char *match_type = 0;
718 const char *match_error = 0;
719 const char *match_marcxml = 0;
720 const char *match_stylesheet = 0;
721 const char *match_identifier = 0;
722 const char *match_backend_type = 0;
723 const char *match_backend_charset = 0;
724 const char *match_usemarcon_ini_stage1 = 0;
725 const char *match_usemarcon_ini_stage2 = 0;
726 struct _xmlAttr *attr;
727 for (attr = ptr->properties; attr; attr = attr->next)
729 if (!strcmp((const char *) attr->name, "type") &&
730 attr->children && attr->children->type == XML_TEXT_NODE)
731 match_type = (const char *) attr->children->content;
732 if (!strcmp((const char *) attr->name, "error") &&
733 attr->children && attr->children->type == XML_TEXT_NODE)
734 match_error = (const char *) attr->children->content;
735 if (!strcmp((const char *) attr->name, "marcxml") &&
736 attr->children && attr->children->type == XML_TEXT_NODE)
737 match_marcxml = (const char *) attr->children->content;
738 if (!strcmp((const char *) attr->name, "stylesheet") &&
739 attr->children && attr->children->type == XML_TEXT_NODE)
740 match_stylesheet = (const char *) attr->children->content;
741 if (!strcmp((const char *) attr->name, "identifier") &&
742 attr->children && attr->children->type == XML_TEXT_NODE)
743 match_identifier = (const char *) attr->children->content;
744 if (!strcmp((const char *) attr->name, "backendtype") &&
745 attr->children && attr->children->type == XML_TEXT_NODE)
746 match_backend_type = (const char *)
747 attr->children->content;
748 if (!strcmp((const char *) attr->name, "backendcharset") &&
749 attr->children && attr->children->type == XML_TEXT_NODE)
750 match_backend_charset = (const char *)
751 attr->children->content;
752 if (!strcmp((const char *) attr->name, "usemarconstage1") &&
753 attr->children && attr->children->type == XML_TEXT_NODE)
754 match_usemarcon_ini_stage1 = (const char *)
755 attr->children->content;
756 if (!strcmp((const char *) attr->name, "usemarconstage2") &&
757 attr->children && attr->children->type == XML_TEXT_NODE)
758 match_usemarcon_ini_stage2 = (const char *)
759 attr->children->content;
763 if (!strcmp(match_type, "*"))
765 else if (!strcmp(match_type, "none"))
772 int match_oid[OID_SIZE];
773 oid_name_to_oid(CLASS_RECSYN, match_type, match_oid);
774 if (oid_oidcmp(match_oid, syntax) == 0)
781 syntax_has_matched = 1;
782 match = m_cp->check_schema(ptr->children, comp,
787 if (stylesheet && match_stylesheet)
790 *stylesheet = xstrdup(match_stylesheet);
792 if (schema && match_identifier)
795 *schema = xstrdup(match_identifier);
797 if (backend_type && match_backend_type)
799 xfree(*backend_type);
800 *backend_type = xstrdup(match_backend_type);
802 if (backend_charset && match_backend_charset)
804 xfree(*backend_charset);
805 *backend_charset = xstrdup(match_backend_charset);
807 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
809 xfree(*usemarcon_ini_stage1);
810 *usemarcon_ini_stage1 = xstrdup(match_usemarcon_ini_stage1);
812 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage2)
814 xfree(*usemarcon_ini_stage2);
815 *usemarcon_ini_stage2 = xstrdup(match_usemarcon_ini_stage2);
823 if (syntax_has_matched) // if syntax OK, bad schema/ESN
827 char dotoid_str[100];
828 oid_to_dotstring(syntax, dotoid_str);
829 *addinfo = odr_strdup(odr, dotoid_str);
831 return atoi(match_error);
842 xmlNodePtr Yaz_ProxyConfigP::find_target_db(xmlNodePtr ptr, const char *db)
849 for (dptr = ptr->children; dptr; dptr = dptr->next)
850 if (dptr->type == XML_ELEMENT_NODE &&
851 !strcmp((const char *) dptr->name, "database"))
853 struct _xmlAttr *attr;
854 for (attr = dptr->properties; attr; attr = attr->next)
855 if (!strcmp((const char *) attr->name, "name"))
858 && attr->children->type==XML_TEXT_NODE
859 && attr->children->content
860 && (!strcmp((const char *) attr->children->content, db)
861 || !strcmp((const char *) attr->children->content,
869 xmlNodePtr Yaz_ProxyConfigP::find_target_node(const char *name, const char *db)
874 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
876 if (ptr->type == XML_ELEMENT_NODE &&
877 !strcmp((const char *) ptr->name, "target"))
882 // <target default="1"> ?
883 struct _xmlAttr *attr;
884 for (attr = ptr->properties; attr; attr = attr->next)
885 if (!strcmp((const char *) attr->name, "default") &&
886 attr->children && attr->children->type == XML_TEXT_NODE)
888 xmlChar *t = attr->children->content;
891 return find_target_db(ptr, db);
897 // <target name="name"> ?
898 struct _xmlAttr *attr;
899 for (attr = ptr->properties; attr; attr = attr->next)
900 if (!strcmp((const char *) attr->name, "name"))
903 && attr->children->type==XML_TEXT_NODE
904 && attr->children->content
905 && (!strcmp((const char *) attr->children->content,
907 || !strcmp((const char *) attr->children->content,
910 return find_target_db(ptr, db);
920 int Yaz_ProxyConfig::get_target_no(int no,
927 int *target_idletime,
928 int *client_idletime,
930 int *keepalive_limit_bw,
931 int *keepalive_limit_pdu,
933 const char **cql2rpn,
934 const char **authentication,
935 const char **negotiation_charset,
936 const char **negotiation_lang,
937 const char **target_charset,
938 const char **default_client_query_charset)
942 if (!m_cp->m_proxyPtr)
945 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
946 if (ptr->type == XML_ELEMENT_NODE &&
947 !strcmp((const char *) ptr->name, "target"))
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 *name = (const char *) attr->children->content;
960 m_cp->return_target_info(
962 limit_bw, limit_pdu, limit_req,
964 target_idletime, client_idletime,
965 keepalive_limit_bw, keepalive_limit_pdu,
967 negotiation_charset, negotiation_lang, target_charset,
968 default_client_query_charset);
977 int Yaz_ProxyConfigP::mycmp(const char *hay, const char *item, size_t len)
979 if (len == strlen(item) && memcmp(hay, item, len) == 0)
984 void Yaz_ProxyConfig::get_generic_info(int *log_mask,
991 if (!m_cp->m_proxyPtr)
993 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
995 if (ptr->type == XML_ELEMENT_NODE
996 && !strcmp((const char *) ptr->name, "log"))
998 const char *v = m_cp->get_text(ptr);
1003 while (*cp && *cp != ',' && !isspace(*cp))
1005 size_t len = cp - v;
1006 if (m_cp->mycmp(v, "client-apdu", len))
1007 *log_mask |= PROXY_LOG_APDU_CLIENT;
1008 if (m_cp->mycmp(v, "server-apdu", len))
1009 *log_mask |= PROXY_LOG_APDU_SERVER;
1010 if (m_cp->mycmp(v, "client-requests", len))
1011 *log_mask |= PROXY_LOG_REQ_CLIENT;
1012 if (m_cp->mycmp(v, "server-requests", len))
1013 *log_mask |= PROXY_LOG_REQ_SERVER;
1015 *log_mask |= atoi(v);
1018 while (*cp && isspace(*cp))
1023 if (ptr->type == XML_ELEMENT_NODE &&
1024 !strcmp((const char *) ptr->name, "max-clients"))
1026 const char *t = m_cp->get_text(ptr);
1029 *max_clients = atoi(t);
1030 if (*max_clients < 1)
1034 if (ptr->type == XML_ELEMENT_NODE &&
1035 !strcmp((const char *) ptr->name, "max-connect"))
1037 const char *t = m_cp->get_text(ptr);
1039 *max_connect = atoi(t);
1046 int Yaz_ProxyConfigP::get_explain_ptr(const char *host, const char *db,
1047 xmlNodePtr *ptr_target,
1048 xmlNodePtr *ptr_explain)
1055 for (ptr = m_proxyPtr->children; ptr; ptr = ptr->next)
1057 if (ptr->type == XML_ELEMENT_NODE &&
1058 !strcmp((const char *) ptr->name, "target"))
1061 xmlNodePtr ptr = (*ptr_target)->children;
1062 for (; ptr; ptr = ptr->next)
1064 if (ptr->type == XML_ELEMENT_NODE &&
1065 !strcmp((const char *) ptr->name, "explain"))
1068 xmlNodePtr ptr = (*ptr_explain)->children;
1070 for (; ptr; ptr = ptr->next)
1071 if (ptr->type == XML_ELEMENT_NODE &&
1072 !strcmp((const char *) ptr->name, "serverInfo"))
1076 for (ptr = ptr->children; ptr; ptr = ptr->next)
1077 if (ptr->type == XML_ELEMENT_NODE &&
1078 !strcmp((const char *) ptr->name, "database"))
1083 for (ptr = ptr->children; ptr; ptr = ptr->next)
1084 if (ptr->type == XML_TEXT_NODE &&
1086 !strcmp((const char *) ptr->content, db))
1099 const char *Yaz_ProxyConfig::get_explain_name(const char *db,
1100 const char **backend_db)
1103 xmlNodePtr ptr_target, ptr_explain;
1104 if (m_cp->get_explain_ptr(0, db, &ptr_target, &ptr_explain)
1107 struct _xmlAttr *attr;
1108 const char *name = 0;
1110 for (attr = ptr_target->properties; attr; attr = attr->next)
1111 if (!strcmp((const char *) attr->name, "name")
1113 && attr->children->type==XML_TEXT_NODE
1114 && attr->children->content
1115 && attr->children->content[0])
1117 name = (const char *)attr->children->content;
1122 for (attr = ptr_target->properties; attr; attr = attr->next)
1123 if (!strcmp((const char *) attr->name, "database"))
1126 && attr->children->type==XML_TEXT_NODE
1127 && attr->children->content)
1128 *backend_db = (const char *) attr->children->content;
1137 char *Yaz_ProxyConfig::get_explain_doc(ODR odr, const char *name,
1138 const char *db, int *len)
1141 xmlNodePtr ptr_target, ptr_explain;
1142 if (m_cp->get_explain_ptr(0 /* host */, db, &ptr_target, &ptr_explain))
1144 xmlNodePtr ptr2 = xmlCopyNode(ptr_explain, 1);
1146 xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0");
1148 xmlDocSetRootElement(doc, ptr2);
1151 xmlDocDumpMemory(doc, &buf_out, len);
1152 char *content = (char*) odr_malloc(odr, *len);
1153 memcpy(content, buf_out, *len);
1163 void Yaz_ProxyConfig::get_target_info(const char *name,
1169 int *target_idletime,
1170 int *client_idletime,
1172 int *keepalive_limit_bw,
1173 int *keepalive_limit_pdu,
1175 const char **cql2rpn,
1176 const char **negotiation_charset,
1177 const char **negotiation_lang,
1178 const char **target_charset,
1179 const char **default_client_query_charset)
1183 if (!m_cp->m_proxyPtr)
1190 for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
1192 if (ptr->type == XML_ELEMENT_NODE &&
1193 !strcmp((const char *) ptr->name, "max-clients"))
1195 const char *t = m_cp->get_text(ptr);
1198 *max_clients = atoi(t);
1199 if (*max_clients < 1)
1204 ptr = m_cp->find_target_node(name, 0);
1212 m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
1214 target_idletime, client_idletime,
1215 keepalive_limit_bw, keepalive_limit_pdu,
1217 negotiation_charset, negotiation_lang,
1219 default_client_query_charset);
1231 * indent-tabs-mode: nil
1233 * vim: shiftwidth=4 tabstop=8 expandtab