New syntax config attr: backendelementset
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 28 Nov 2012 13:35:27 +0000 (14:35 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 28 Nov 2012 13:35:27 +0000 (14:35 +0100)
which specifies elementset to be used for backend.

include/yazproxy/proxy.h
src/proxyp.h
src/yaz-proxy-config.cpp
src/yaz-proxy.cpp

index 7e0f0a8..3a1cb8a 100644 (file)
@@ -212,6 +212,7 @@ class YAZ_EXPORT Yaz_Proxy : public yazpp_1::Z_Assoc {
     void low_socket_close();
     char *m_usemarcon_ini_stage1;
     char *m_usemarcon_ini_stage2;
+    char *m_backend_elementset;
     Yaz_usemarcon *m_usemarcon;
     Yaz_CharsetConverter *m_charset_converter;
     yazpp_1::GDUQueue m_in_queue;
index 59278b2..f791372 100644 (file)
@@ -131,7 +131,8 @@ public:
                      Odr_oid *syntax, Z_RecordComposition *comp,
                      char **addinfo, char **stylesheet, char **schema,
                      char **backend_type, char **backend_charset,
-                     char **usemarcon_ini_stage1, char **usemarcon_ini_stage2);
+                     char **usemarcon_ini_stage1, char **usemarcon_ini_stage2,
+                     char **backend_elementset);
 
     void target_authentication(const char *name,
                                ODR odr,
index 18a49dd..4f19e06 100644 (file)
@@ -729,7 +729,8 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
                                   char **backend_type,
                                   char **backend_charset,
                                   char **usemarcon_ini_stage1,
-                                  char **usemarcon_ini_stage2
+                                  char **usemarcon_ini_stage2,
+                                  char **backend_elementset
                                   )
 {
     if (stylesheet)
@@ -762,6 +763,8 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
         xfree (*usemarcon_ini_stage2);
         *usemarcon_ini_stage2 = 0;
     }
+    xfree(*backend_elementset);
+    *backend_elementset = 0;
 #if YAZ_HAVE_XSLT
     int syntax_has_matched = 0;
     xmlNodePtr ptr;
@@ -784,6 +787,7 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
             const char *match_backend_charset = 0;
             const char *match_usemarcon_ini_stage1 = 0;
             const char *match_usemarcon_ini_stage2 = 0;
+            const char *match_elementset = 0;
             struct _xmlAttr *attr;
             for (attr = ptr->properties; attr; attr = attr->next)
             {
@@ -818,6 +822,9 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
                     attr->children && attr->children->type == XML_TEXT_NODE)
                     match_usemarcon_ini_stage2 = (const char *)
                         attr->children->content;
+                if (!strcmp((const char *) attr->name, "backendelementset") &&
+                    attr->children && attr->children->type == XML_TEXT_NODE)
+                    match_elementset = (const char *) attr->children->content;
             }
             if (match_type)
             {
@@ -867,6 +874,11 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name,
                     xfree(*backend_charset);
                     *backend_charset = xstrdup(match_backend_charset);
                 }
+                if (match_elementset)
+                {
+                    xfree(*backend_elementset);
+                    *backend_elementset = xstrdup(match_elementset);
+                }
                 if (usemarcon_ini_stage1 && match_usemarcon_ini_stage1)
                 {
                     xfree(*usemarcon_ini_stage1);
index c80c99a..7233565 100644 (file)
@@ -293,6 +293,7 @@ Yaz_Proxy::Yaz_Proxy(IPDU_Observable *the_PDU_Observable,
     m_usemarcon = new Yaz_usemarcon();
     if (!m_parent)
         low_socket_open();
+    m_backend_elementset = 0;
     m_my_thread = 0;
     m_ref_count = 1;
     m_main_ptr_dec = false;
@@ -333,6 +334,7 @@ Yaz_Proxy::~Yaz_Proxy()
     xfree(m_backend_charset);
     xfree(m_usemarcon_ini_stage1);
     xfree(m_usemarcon_ini_stage2);
+    xfree(m_backend_elementset);
     delete m_usemarcon;
     if (m_s2z_odr_init)
         odr_destroy(m_s2z_odr_init);
@@ -2723,7 +2725,8 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu)
                                     &addinfo, &stylesheet_name, &m_schema,
                                     &m_backend_type, &m_backend_charset,
                                     &m_usemarcon_ini_stage1,
-                                    &m_usemarcon_ini_stage2);
+                                    &m_usemarcon_ini_stage2,
+                                    &m_backend_elementset);
         if (stylesheet_name)
         {
             m_parent->low_socket_close();
@@ -2769,6 +2772,13 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu)
                 yaz_string_to_oid_odr(yaz_oid_std(), CLASS_RECSYN,
                                       m_backend_type, odr_encode());
         }
+        if (m_backend_elementset)
+        {
+            Z_ElementSetNames *esn = mk_esn_from_schema(odr_encode(),
+                                                        m_backend_elementset);
+            sr->smallSetElementSetNames = esn;
+            sr->mediumSetElementSetNames = esn;
+        }
     }
     else if (apdu->which == Z_APDU_presentRequest)
     {
@@ -2790,8 +2800,8 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu)
                                     &addinfo, &stylesheet_name, &m_schema,
                                     &m_backend_type, &m_backend_charset,
                                     &m_usemarcon_ini_stage1,
-                                    &m_usemarcon_ini_stage2
-                                    );
+                                    &m_usemarcon_ini_stage2,
+                                    &m_backend_elementset);
         if (stylesheet_name)
         {
             m_parent->low_socket_close();
@@ -2839,6 +2849,16 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu)
                                       CLASS_RECSYN, m_backend_type,
                                       odr_encode());
         }
+        if (m_backend_elementset)
+        {
+            Z_ElementSetNames *esn = mk_esn_from_schema(odr_encode(),
+                                                        m_backend_elementset);
+            Z_RecordComposition *comp = (Z_RecordComposition *)
+                odr_malloc(odr_encode(), sizeof(Z_RecordComposition));
+            comp->which = Z_RecordComp_simple;
+            comp->u.simple = esn;
+            pr->recordComposition = comp;
+        }
     }
     return apdu;
 }