Added patch, which involve yazproxy to Character Set and Language
[yazproxy-moved-to-github.git] / src / yaz-proxy-config.cpp
index 2bc8cfe..fc81b94 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: yaz-proxy-config.cpp,v 1.11 2004-12-03 14:28:18 adam Exp $
+/* $Id: yaz-proxy-config.cpp,v 1.14 2005-02-10 08:09:42 oleg Exp $
    Copyright (c) 1998-2004, Index Data.
 
 This file is part of the yaz-proxy.
@@ -20,7 +20,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  */
 
 #include <ctype.h>
-#include <yaz/ylog.h>
+#include <yaz/log.h>
 #include "proxyp.h"
 
 class Yaz_ProxyConfigP {
@@ -41,7 +41,9 @@ class Yaz_ProxyConfigP {
                            int *target_idletime, int *client_idletime,
                            int *keepalive_limit_bw, int *keepalive_limit_pdu,
                            int *pre_init, const char **cql2rpn,
-                           const char **authentication);
+                           const char **authentication,
+                           const char **negotiation_charset,
+                           const char **negotiation_lang);
     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,
@@ -175,7 +177,9 @@ void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
                                          int *keepalive_limit_pdu,
                                          int *pre_init,
                                          const char **cql2rpn,
-                                         const char **authentication)
+                                         const char **authentication,
+                                         const char **negotiation_charset,
+                                         const char **negotiation_lang)
 {
     *pre_init = 0;
     int no_url = 0;
@@ -246,6 +250,20 @@ void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
            if (t)
                *authentication = t;
        }
+       if (ptr->type == XML_ELEMENT_NODE 
+           && !strcmp((const char *) ptr->name, "negotiation-charset"))
+       {
+           const char *t = get_text(ptr);
+           if (t)
+               *negotiation_charset = t;
+       }
+       if (ptr->type == XML_ELEMENT_NODE 
+           && !strcmp((const char *) ptr->name, "negotiation-lang"))
+       {
+           const char *t = get_text(ptr);
+           if (t)
+               *negotiation_lang = t;
+       }
     }
 }
 #endif
@@ -451,6 +469,38 @@ int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp,
 }
 #endif
 
+const char *Yaz_ProxyConfig::check_mime_type(const char *path)
+{
+    struct {
+       const char *mask;
+       const char *type;
+    } types[] = {
+       {".xml", "text/xml"},
+       {".xsl", "text/xml"},
+       {".tkl", "text/xml"},
+       {".xsd", "text/xml"},
+       {".html", "text/html"},
+       {".jpg", "image/jpeg"},
+       {".png", "image/png"},
+       {".gif", "image/gif"},
+       {0, "text/plain"},
+       {0, 0},
+    };
+    int i;
+    size_t plen = strlen (path);
+    for (i = 0; types[i].type; i++)
+       if (types[i].mask == 0)
+           return types[i].type;
+       else
+       {
+           size_t mlen = strlen(types[i].mask);
+           if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
+               return types[i].type;
+       }
+    return "application/octet-stream";
+}
+
+
 int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
                                  Odr_oid *syntax, Z_RecordComposition *comp,
                                  char **addinfo,
@@ -720,7 +770,9 @@ int Yaz_ProxyConfig::get_target_no(int no,
                                   int *keepalive_limit_pdu,
                                   int *pre_init,
                                   const char **cql2rpn,
-                                  const char **authentication)
+                                  const char **authentication,
+                                  const char **negotiation_charset,
+                                  const char **negotiation_lang)
 {
 #if HAVE_XSLT
     xmlNodePtr ptr;
@@ -747,7 +799,8 @@ 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, authentication);
+                   pre_init, cql2rpn, authentication,
+                   negotiation_charset, negotiation_lang);
                return 1;
            }
            i++;
@@ -945,7 +998,9 @@ void Yaz_ProxyConfig::get_target_info(const char *name,
                                      int *keepalive_limit_pdu,
                                      int *pre_init,
                                      const char **cql2rpn,
-                                     const char **authentication)
+                                     const char **authentication,
+                                     const char **negotiation_charset,
+                                     const char **negotiation_lang)
 {
 #if HAVE_XSLT
     xmlNodePtr ptr;
@@ -981,7 +1036,8 @@ 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, authentication);
+                                pre_init, cql2rpn, authentication,
+                                negotiation_charset, negotiation_lang);
     }
 #else
     *url = name;