Implement XInclude for XML configuration file(s).
[yazproxy-moved-to-github.git] / src / yaz-proxy-config.cpp
index 21497ec..c05724e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: yaz-proxy-config.cpp,v 1.7 2004-10-18 22:10:57 adam Exp $
+/* $Id: yaz-proxy-config.cpp,v 1.9 2004-11-09 14:24:22 adam Exp $
    Copyright (c) 1998-2004, Index Data.
 
 This file is part of the yaz-proxy.
@@ -26,6 +26,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #if HAVE_XSLT
 #include <libxml/parser.h>
 #include <libxml/tree.h>
+#include <libxml/xinclude.h>
 #include <libxslt/xsltutils.h>
 #include <libxslt/transform.h>
 #endif
@@ -47,7 +48,8 @@ class Yaz_ProxyConfigP {
                            int *limit_bw, int *limit_pdu, int *limit_req,
                            int *target_idletime, int *client_idletime,
                            int *keepalive_limit_bw, int *keepalive_limit_pdu,
-                           int *pre_init, const char **cql2rpn);
+                           int *pre_init, const char **cql2rpn,
+                           const char **authentication);
     void return_limit(xmlNodePtr ptr,
                      int *limit_bw, int *limit_pdu, int *limit_req);
     int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
@@ -94,6 +96,10 @@ int Yaz_ProxyConfig::read_xml(const char *fname)
        yaz_log(LOG_WARN, "Config file %s not found or parse error", fname);
        return -1;  // no good
     }
+    int noSubstitutions = xmlXIncludeProcess(ndoc);
+    if (noSubstitutions == -1)
+       yaz_log(LOG_WARN, "XInclude processing failed on config %s", fname);
+
     xmlNodePtr proxyPtr = xmlDocGetRootElement(ndoc);
     if (!proxyPtr || proxyPtr->type != XML_ELEMENT_NODE ||
        strcmp((const char *) proxyPtr->name, "proxy"))
@@ -176,7 +182,8 @@ void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
                                          int *keepalive_limit_bw,
                                          int *keepalive_limit_pdu,
                                          int *pre_init,
-                                         const char **cql2rpn)
+                                         const char **cql2rpn,
+                                         const char **authentication)
 {
     *pre_init = 0;
     int no_url = 0;
@@ -240,6 +247,13 @@ void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
            if (t)
                *cql2rpn = t;
        }
+       if (ptr->type == XML_ELEMENT_NODE 
+           && !strcmp((const char *) ptr->name, "authentication"))
+       {
+           const char *t = get_text(ptr);
+           if (t)
+               *authentication = t;
+       }
     }
 }
 #endif
@@ -680,7 +694,8 @@ int Yaz_ProxyConfig::get_target_no(int no,
                                   int *keepalive_limit_bw,
                                   int *keepalive_limit_pdu,
                                   int *pre_init,
-                                  const char **cql2rpn)
+                                  const char **cql2rpn,
+                                  const char **authentication)
 {
 #if HAVE_XSLT
     xmlNodePtr ptr;
@@ -707,7 +722,7 @@ int Yaz_ProxyConfig::get_target_no(int no,
                    limit_bw, limit_pdu, limit_req,
                    target_idletime, client_idletime,
                    keepalive_limit_bw, keepalive_limit_pdu,
-                   pre_init, cql2rpn);
+                   pre_init, cql2rpn, authentication);
                return 1;
            }
            i++;
@@ -904,7 +919,8 @@ void Yaz_ProxyConfig::get_target_info(const char *name,
                                      int *keepalive_limit_bw,
                                      int *keepalive_limit_pdu,
                                      int *pre_init,
-                                     const char **cql2rpn)
+                                     const char **cql2rpn,
+                                     const char **authentication)
 {
 #if HAVE_XSLT
     xmlNodePtr ptr;
@@ -940,7 +956,7 @@ void Yaz_ProxyConfig::get_target_info(const char *name,
        m_cp->return_target_info(ptr, url, limit_bw, limit_pdu, limit_req,
                                 target_idletime, client_idletime,
                                 keepalive_limit_bw, keepalive_limit_pdu,
-                                pre_init, cql2rpn);
+                                pre_init, cql2rpn, authentication);
     }
 #else
     *url = name;