Option -X now makes it possible to stop YAZ proxy by sending
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 21 Feb 2005 14:27:31 +0000 (14:27 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 21 Feb 2005 14:27:31 +0000 (14:27 +0000)
"stop" as PROXY target (in init). This used to be debug code in a
#if 0 .. #endif section.

Moved a lot of "private" stuff to proxyp.h so that only Yaz_Proxy
is publicly defined in include/yazproxy/proxy.h.

Authentication info sent to target modified. Element renamed from
"authentication" to "target-authentication" to avoid confusion with
client authentication. It now takes an authentication
type=open|idPass|anonymous . Value is user:group:password for idPass,
user/pass for open. Option -U auth is no longer supported.

12 files changed:
NEWS
doc/yaz-proxy-ref.xml
etc/config.xml
etc/explain.xml
etc/yazproxy.xsd
include/yazproxy/module.h
include/yazproxy/proxy.h
src/mod_sample.cpp
src/proxyp.h
src/yaz-proxy-config.cpp
src/yaz-proxy-main.cpp
src/yaz-proxy.cpp

diff --git a/NEWS b/NEWS
index 196f87e..3d76936 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,19 @@
+Option -X now makes it possible to stop YAZ proxy by sending
+"stop" as PROXY target (in init). This used to be debug code in a
+#if 0 .. #endif section.
+
+Moved a lot of "private" stuff to proxyp.h so that only Yaz_Proxy
+is publicly defined in include/yazproxy/proxy.h.
+
+Authentication info sent to target modified. Element renamed from
+"authentication" to "target-authentication" to avoid confusion with
+client authentication. It now takes an authentication
+type=open|idPass|anonymous . Value is user:group:password for idPass,
+user/pass for open. Option -U auth is no longer supported.
+
+Update YAZ Proxy config schema yazproxy.xsd to include definitions
+for new elements negotation-charset, negotiation-lang, module, etc. .
+Bump version to 0.9.
 
 Started work on facility for module loading (plugins). Initial
 effort is to be able to authenticate via a module. See mod_sample.cpp.
 
 Started work on facility for module loading (plugins). Initial
 effort is to be able to authenticate via a module. See mod_sample.cpp.
index c44603d..209a178 100644 (file)
@@ -14,7 +14,6 @@
   <arg choice="opt">-m <replaceable>num</replaceable></arg>
   <arg choice="opt">-v <replaceable>level</replaceable></arg>
   <arg choice="opt">-t <replaceable>target</replaceable></arg>
   <arg choice="opt">-m <replaceable>num</replaceable></arg>
   <arg choice="opt">-v <replaceable>level</replaceable></arg>
   <arg choice="opt">-t <replaceable>target</replaceable></arg>
-  <arg choice="opt">-U <replaceable>auth</replaceable></arg>
   <arg choice="opt">-o <replaceable>level</replaceable></arg>
   <arg choice="opt">-i <replaceable>seconds</replaceable></arg>
   <arg choice="opt">-T <replaceable>seconds</replaceable></arg>
   <arg choice="opt">-o <replaceable>level</replaceable></arg>
   <arg choice="opt">-i <replaceable>seconds</replaceable></arg>
   <arg choice="opt">-T <replaceable>seconds</replaceable></arg>
      <literal>initRequest</literal>.
     </para></listitem>
   </varlistentry>
      <literal>initRequest</literal>.
     </para></listitem>
   </varlistentry>
-  <varlistentry><term>-U <replaceable>auth</replaceable></term>
-   <listitem><para>
-     Specifies authentication info to be sent to the backend target.
-     This is useful if you happen to have an internal target that
-     requires authentication, or if the client software does not allow
-     you to set it.
-    </para></listitem>
-  </varlistentry>
   <varlistentry><term>-o <replaceable>level</replaceable></term>
    <listitem><para>
      Sets level for optimization. Use zero to disable; non-zero
   <varlistentry><term>-o <replaceable>level</replaceable></term>
    <listitem><para>
      Sets level for optimization. Use zero to disable; non-zero
index 6fffe7b..0265e45 100644 (file)
@@ -1,17 +1,15 @@
 <?xml version="1.0"?>
 <?xml version="1.0"?>
-<!-- $Id: config.xml,v 1.8 2005-02-11 15:19:07 adam Exp $ -->
-<proxy xmlns="http://indexdata.dk/yazproxy/schema/0.8/"
+<!-- $Id: config.xml,v 1.9 2005-02-21 14:27:31 adam Exp $ -->
+<proxy xmlns="http://indexdata.dk/yazproxy/schema/0.9/"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://indexdata.dk/yazproxy/schema/0.8/ yazproxy.xsd"
->
+ xsi:schemaLocation="http://indexdata.dk/yazproxy/schema/0.9/ yazproxy.xsd"
+  >
 <!-- Config can be checked with xerces-c++: PParse -n -s config.xml -->
   <target name="localhost" default="1">
 <!-- Config can be checked with xerces-c++: PParse -n -s config.xml -->
   <target name="localhost" default="1">
-    <negotiation-charset>iso-8859-1</negotiation-charset>
     <url>localhost:9999</url>
     <target-timeout>30</target-timeout>
     <client-timeout>60</client-timeout>
     <url>localhost:9999</url>
     <target-timeout>30</target-timeout>
     <client-timeout>60</client-timeout>
-    <authentication handler="pipe" args="authenticate.pl"/>
     <keepalive>
       <bandwidth>1000000</bandwidth>
       <pdu>1000</pdu>
     <keepalive>
       <bandwidth>1000000</bandwidth>
       <pdu>1000</pdu>
     <preinit>0</preinit>
     <xi:include href="explain.xml"/>
     <cql2rpn>pqf.properties</cql2rpn>
     <preinit>0</preinit>
     <xi:include href="explain.xml"/>
     <cql2rpn>pqf.properties</cql2rpn>
+    <target-authentication type="open">my/bad</target-authentication>
+    <client-authentication module="sample" args="authenticate.pl"/>
+    <negotiation-charset>iso-8859-1</negotiation-charset>
+    <negotiation-lang>US</negotiation-lang>
   </target>
   <target name="*">
     <target-timeout>60</target-timeout>
   </target>
   <target name="*">
     <target-timeout>60</target-timeout>
index 4db3c6b..3369e0e 100644 (file)
@@ -2,7 +2,7 @@
   <serverInfo>
     <host>localhost</host>
     <port>9000</port>
   <serverInfo>
     <host>localhost</host>
     <port>9000</port>
-    <database>gils</database>
+    <database>Default</database>
   </serverInfo>
   <databaseInfo>
     <title>My Database</title>
   </serverInfo>
   <databaseInfo>
     <title>My Database</title>
index f447afc..4e30805 100644 (file)
@@ -1,12 +1,12 @@
 <?xml version="1.0"?>
 <!-- XML Schema for YAZ proxy config file.
 <?xml version="1.0"?>
 <!-- XML Schema for YAZ proxy config file.
-    $Id: yazproxy.xsd,v 1.7 2004-12-03 14:28:18 adam Exp $
+    $Id: yazproxy.xsd,v 1.8 2005-02-21 14:27:31 adam Exp $
 -->
 <xs:schema
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:exp="http://explain.z3950.org/dtd/2.0/"
 -->
 <xs:schema
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:exp="http://explain.z3950.org/dtd/2.0/"
-  xmlns="http://indexdata.dk/yazproxy/schema/0.8/"
-  targetNamespace="http://indexdata.dk/yazproxy/schema/0.8/"
+  xmlns="http://indexdata.dk/yazproxy/schema/0.9/"
+  targetNamespace="http://indexdata.dk/yazproxy/schema/0.9/"
   >
  <xs:import namespace="http://explain.z3950.org/dtd/2.0/" 
       schemaLocation="zeerex-2.0.xsd"/>
   >
  <xs:import namespace="http://explain.z3950.org/dtd/2.0/" 
       schemaLocation="zeerex-2.0.xsd"/>
@@ -16,6 +16,7 @@
     <xs:element ref="target" minOccurs="0" maxOccurs="unbounded"/>
     <xs:element ref="max-clients" minOccurs="0"/>
     <xs:element ref="log" minOccurs="0"/>
     <xs:element ref="target" minOccurs="0" maxOccurs="unbounded"/>
     <xs:element ref="max-clients" minOccurs="0"/>
     <xs:element ref="log" minOccurs="0"/>
+    <xs:element ref="module" minOccurs="0"/>
    </xs:sequence>
   </xs:complexType>
  </xs:element>
    </xs:sequence>
   </xs:complexType>
  </xs:element>
      <xs:element ref="preinit" minOccurs="0"/>
      <xs:element ref="exp:explain" minOccurs="0"/>
      <xs:element ref="cql2rpn" minOccurs="0"/>
      <xs:element ref="preinit" minOccurs="0"/>
      <xs:element ref="exp:explain" minOccurs="0"/>
      <xs:element ref="cql2rpn" minOccurs="0"/>
-     <xs:element ref="authentication" minOccurs="0"/>
+     <xs:element ref="target-authentication" minOccurs="0"/>
+     <xs:element ref="client-authentication" minOccurs="0"/>
+     <xs:element ref="negotiation-charset" minOccurs="0"/>
+     <xs:element ref="negotiation-lang" minOccurs="0"/>
    </xs:sequence>
    <xs:attribute name="default" type="xs:string" use="optional"/>
    <xs:attribute name="name" type="xs:string"/>
    </xs:sequence>
    <xs:attribute name="default" type="xs:string" use="optional"/>
    <xs:attribute name="name" type="xs:string"/>
  <xs:element name="retrieve" type="xs:integer"/>
  <xs:element name="preinit" type="xs:integer"/>
  <xs:element name="cql2rpn" type="xs:string"/>
  <xs:element name="retrieve" type="xs:integer"/>
  <xs:element name="preinit" type="xs:integer"/>
  <xs:element name="cql2rpn" type="xs:string"/>
- <xs:element name="authentication" type="xs:string"/>
+ <xs:element name="target-authentication">
+   <xs:complexType>
+    <xs:simpleContent>
+      <xs:extension base="xs:string">
+        <xs:attribute name="type" type="xs:string"/>
+      </xs:extension>
+    </xs:simpleContent>
+   </xs:complexType>
+ </xs:element>
+
+ <xs:element name="client-authentication">
+   <xs:complexType>
+    <xs:simpleContent>
+      <xs:extension base="xs:string">
+        <xs:attribute name="module" type="xs:string"/>
+        <xs:attribute name="args" type="xs:string"/>
+      </xs:extension>
+    </xs:simpleContent>
+   </xs:complexType>
+ </xs:element>
+
+ <xs:element name="negotiation-charset" type="xs:string"/>
+ <xs:element name="negotiation-lang" type="xs:string"/>
 
  <xs:element name="keepalive">
   <xs:complexType>
 
  <xs:element name="keepalive">
   <xs:complexType>
 
  <xs:element name="max-clients" type="xs:integer"/>
  <xs:element name="log" type="xs:string"/>
 
  <xs:element name="max-clients" type="xs:integer"/>
  <xs:element name="log" type="xs:string"/>
+ <xs:element name="module" type="xs:string"/>
 
 </xs:schema>
 
 </xs:schema>
index 6d2fd34..7afbff5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: module.h,v 1.1 2005-02-11 15:19:08 adam Exp $
+/* $Id: module.h,v 1.2 2005-02-21 14:27:31 adam Exp $
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
@@ -34,10 +34,20 @@ struct Yaz_ProxyModule_entry {
 #define  YAZPROXY_RET_PERM   2 /* Permissiong denied, reject etc. */
 
 struct Yaz_ProxyModule_int0 {
 #define  YAZPROXY_RET_PERM   2 /* Permissiong denied, reject etc. */
 
 struct Yaz_ProxyModule_int0 {
-    void *(*init)(void);
-    void (*destroy)(void *handle);
-    int (*authenticate)(void *handle,
-                       const char *user, const char *group, const char *pw);
+    void *(*init)(void);   // Init handler - returns module-specific handle
+
+    void (*destroy)(       // Destroy handler
+       void *handle       // module-specific handle as returned by init
+       );
+    
+    int (*authenticate)(   // Authenticate handler. Returns YAZPROXY_RET_..
+       void *handle,      // module-specific handle as returned by init 
+       const char *name,  // target name (or NULL if default target)
+       void *element_ptr, // xmlnodePtr thing to XML config this
+       const char *user,  // User ID (or NULL if no suppliied User ID)
+       const char *group, // Group ID (or NULL if no supplied Group ID)
+       const char *pw     // Password (or NULL if no supplied password)
+    );
 };
 
 #endif
 };
 
 #endif
index 264aac5..95dc385 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: proxy.h,v 1.12 2005-02-11 15:19:08 adam Exp $
+/* $Id: proxy.h,v 1.13 2005-02-21 14:27:32 adam Exp $
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
@@ -38,134 +38,9 @@ class Yaz_Proxy;
 #define PROXY_LOG_REQ_CLIENT 4
 #define PROXY_LOG_REQ_SERVER 8
 
 #define PROXY_LOG_REQ_CLIENT 4
 #define PROXY_LOG_REQ_SERVER 8
 
-struct Yaz_RecordCache_Entry;
-class Yaz_ProxyConfigP;
 class Yaz_usemarcon;
 class Yaz_usemarcon;
-
-class YAZ_EXPORT Yaz_ProxyConfig {
-public:
-    Yaz_ProxyConfig();
-    ~Yaz_ProxyConfig();
-    int read_xml(const char *fname);
-
-    int get_target_no(int no,
-                     const char **name,
-                     const char **url,
-                     int *limit_bw,
-                     int *limit_pdu,
-                     int *limit_req,
-                     int *target_idletime,
-                     int *client_idletime,
-                     int *max_clients,
-                     int *keepalive_limit_bw,
-                     int *keepalive_limit_pdu,
-                     int *pre_init,
-                     const char **cql2rpn,
-                     const char **authentication,
-                     const char **negotiation_charset,
-                     const char **negotiation_lang);
-    
-    void get_generic_info(int *log_mask, int *max_clients);
-
-    void get_target_info(const char *name, const char **url,
-                        int *limit_bw, int *limit_pdu, int *limit_req,
-                        int *target_idletime, int *client_idletime,
-                        int *max_clients,
-                        int *keepalive_limit_bw, int *keepalive_limit_pdu,
-                        int *pre_init,
-                        const char **cql2rpn,
-                        const char **authentication,
-                        const char **negotiation_charset,
-                        const char **negotiation_lang);
-
-    const char *check_mime_type(const char *path);
-    int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
-    int check_syntax(ODR odr, const char *name,
-                    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);
-
-    int check_authentication(const char *user, const char *group,
-                            const char *password);
-    char *get_explain_doc(ODR odr, const char *name, const char *db,
-                         int *len);
-    const char *get_explain_name(const char *db, const char **backend_db);
- private:
-    void operator=(const Yaz_ProxyConfig &conf);
-    class Yaz_ProxyConfigP *m_cp;
-};
-
-class YAZ_EXPORT Yaz_RecordCache {
- public:
-    Yaz_RecordCache ();
-    ~Yaz_RecordCache ();
-    void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
-    
-    int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
-               Odr_oid *syntax, Z_RecordComposition *comp);
-    void clear();
-
-    void copy_searchRequest(Z_SearchRequest *sr);
-    void copy_presentRequest(Z_PresentRequest *pr);
-    void set_max_size(int sz);
- private:
-    NMEM m_mem;
-    Yaz_RecordCache_Entry *m_entries;
-    Z_SearchRequest *m_searchRequest;
-    Z_PresentRequest *m_presentRequest;
-    int match (Yaz_RecordCache_Entry *entry,
-              Odr_oid *syntax, int offset,
-              Z_RecordComposition *comp);
-    int m_max_size;
-};
-
-/// Private class
-class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc {
-    friend class Yaz_Proxy;
-    Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable,
-                   Yaz_Proxy *parent);
-    ~Yaz_ProxyClient();
-    void recv_GDU(Z_GDU *apdu, int len);
-    void recv_Z_PDU(Z_APDU *apdu, int len);
-    void recv_HTTP_response(Z_HTTP_Response *apdu, int len);
-    IYaz_PDU_Observer* sessionNotify
-       (IYaz_PDU_Observable *the_PDU_Observable, int fd);
-    void shutdown();
-    Yaz_Proxy *m_server;
-    void failNotify();
-    void timeoutNotify();
-    void connectNotify();
-    int send_to_target(Z_APDU *apdu);
-    const char *get_session_str();
-    char *m_cookie;
-    Yaz_ProxyClient *m_next;
-    Yaz_ProxyClient **m_prev;
-    int m_init_flag;
-    Yaz_Z_Query *m_last_query;
-    Yaz_Z_Databases m_last_databases;
-    char *m_last_resultSetId;
-    int m_last_ok;
-    int m_last_resultCount;
-    int m_sr_transform;
-    int m_seqno;
-    int m_waiting;
-    int m_resultSetStartPoint;
-    int m_bytes_sent;
-    int m_bytes_recv;
-    int m_pdu_recv;
-    ODR m_init_odr;
-    Z_APDU *m_initResponse;
-    Z_Options *m_initResponse_options;
-    Z_ProtocolVersion *m_initResponse_version;
-    int m_initResponse_preferredMessageSize;
-    int m_initResponse_maximumRecordSize;
-    Yaz_RecordCache m_cache;
-    void pre_init_client();
-    int m_target_idletime;
-    Yaz_Proxy *m_root;
-};
-
+class Yaz_ProxyConfig;
+class Yaz_ProxyClient;
 
 /// Information Retrieval Proxy Server.
 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
 
 /// Information Retrieval Proxy Server.
 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
@@ -191,9 +66,9 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
     int m_keepalive_limit_pdu;
     int m_client_idletime;
     int m_target_idletime;
     int m_keepalive_limit_pdu;
     int m_client_idletime;
     int m_target_idletime;
+    int m_debug_mode;
     char *m_proxyTarget;
     char *m_default_target;
     char *m_proxyTarget;
     char *m_default_target;
-    char *m_proxy_authentication;
     char *m_proxy_negotiation_charset;
     char *m_proxy_negotiation_lang;
     long m_seed;
     char *m_proxy_negotiation_charset;
     char *m_proxy_negotiation_lang;
     long m_seed;
@@ -305,7 +180,6 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
     void markInvalid();
     const char *option(const char *name, const char *value);
     void set_default_target(const char *target);
     void markInvalid();
     const char *option(const char *name, const char *value);
     void set_default_target(const char *target);
-    void set_proxy_authentication (const char *auth);
     void set_proxy_negotiation (const char *charset, const char *lang);
     char *get_proxy_target() { return m_proxyTarget; };
     char *get_session_str() { return m_session_str; };
     void set_proxy_negotiation (const char *charset, const char *lang);
     char *get_proxy_target() { return m_proxyTarget; };
     char *get_session_str() { return m_session_str; };
@@ -320,6 +194,7 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
     void pre_init();
     int get_log_mask() { return m_log_mask; };
     int handle_init_response_for_invalid_session(Z_APDU *apdu);
     void pre_init();
     int get_log_mask() { return m_log_mask; };
     int handle_init_response_for_invalid_session(Z_APDU *apdu);
+    void set_debug_mode(int mode);
 };
 
 #endif
 };
 
 #endif
index 05b121b..11c00ad 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mod_sample.cpp,v 1.1 2005-02-11 15:19:08 adam Exp $
+/* $Id: mod_sample.cpp,v 1.2 2005-02-21 14:27:32 adam Exp $
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
@@ -24,6 +24,14 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include <yazproxy/module.h>
 
 
 #include <yazproxy/module.h>
 
+#if HAVE_XSLT
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xinclude.h>
+#include <libxslt/xsltutils.h>
+#include <libxslt/transform.h>
+#endif
+
 void *my_init(void)
 {
     return 0;  // no private data for handler
 void *my_init(void)
 {
     return 0;  // no private data for handler
@@ -34,11 +42,30 @@ void my_destroy(void *p)
     // private data destroy
 }
 
     // private data destroy
 }
 
-int my_authenticate(void *p, const char *user, const char *group,
-                   const char *password)
+int my_authenticate(void *user_handle,
+                   const char *target_name,
+                   void *element_ptr,
+                   const char *user, const char *group, const char *password)
 {
 {
-    fprintf(stderr, "my_authenticate: user=%s group=%s\n",
-           user ? user : "none", group ? group : "none");
+    // see if we have an "args" attribute
+    const char *args = 0;
+#if HAVE_XSLT
+    xmlNodePtr ptr = (xmlNodePtr) element_ptr;
+    struct _xmlAttr *attr;
+    
+    for (attr = ptr->properties; attr; attr = attr->next)
+    {
+       if (!strcmp((const char *) attr->name, "args") &&
+           attr->children && attr->children->type == XML_TEXT_NODE)
+           args = (const char *) attr->children->content;
+    }
+#endif
+    // args holds args (or NULL if  none is provided)
+
+    fprintf(stderr, "my_authenticate: target=%s user=%s group=%s args=%s\n",
+           target_name ? target_name : "none", 
+           user ? user : "none", group ? group : "none",
+           args ? args : "none");
     // authentication handler
     if (!user && !group && !password)
        return YAZPROXY_RET_OK;   // OK if anonymous
     // authentication handler
     if (!user && !group && !password)
        return YAZPROXY_RET_OK;   // OK if anonymous
@@ -60,4 +87,3 @@ Yaz_ProxyModule_entry yazproxy_module = {
     "Sample Module for YAZ Proxy",// description
     &interface0
 };
     "Sample Module for YAZ Proxy",// description
     &interface0
 };
-       
index 1f2acd6..3485885 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: proxyp.h,v 1.2 2005-02-11 15:19:08 adam Exp $
+/* $Id: proxyp.h,v 1.3 2005-02-21 14:27:32 adam Exp $
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
@@ -34,6 +34,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <yazproxy/proxy.h>
 #include <yazproxy/module.h>
 
 #include <yazproxy/proxy.h>
 #include <yazproxy/module.h>
 
+struct Yaz_RecordCache_Entry;
+
 class Yaz_usemarcon {
  public:
     Yaz_usemarcon();
 class Yaz_usemarcon {
  public:
     Yaz_usemarcon();
@@ -49,3 +51,131 @@ class Yaz_usemarcon {
     int dummy;
 #endif
 };
     int dummy;
 #endif
 };
+
+class Yaz_ProxyConfig {
+public:
+    Yaz_ProxyConfig();
+    ~Yaz_ProxyConfig();
+    int read_xml(const char *fname);
+
+    int get_target_no(int no,
+                     const char **name,
+                     const char **url,
+                     int *limit_bw,
+                     int *limit_pdu,
+                     int *limit_req,
+                     int *target_idletime,
+                     int *client_idletime,
+                     int *max_clients,
+                     int *keepalive_limit_bw,
+                     int *keepalive_limit_pdu,
+                     int *pre_init,
+                     const char **cql2rpn,
+                     const char **authentication,
+                     const char **negotiation_charset,
+                     const char **negotiation_lang);
+    
+    void get_generic_info(int *log_mask, int *max_clients);
+
+    void get_target_info(const char *name, const char **url,
+                        int *limit_bw, int *limit_pdu, int *limit_req,
+                        int *target_idletime, int *client_idletime,
+                        int *max_clients,
+                        int *keepalive_limit_bw, int *keepalive_limit_pdu,
+                        int *pre_init,
+                        const char **cql2rpn,
+                        const char **negotiation_charset,
+                        const char **negotiation_lang);
+
+    const char *check_mime_type(const char *path);
+    int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
+    int check_syntax(ODR odr, const char *name,
+                    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);
+
+    void target_authentication(const char *name,
+                              ODR odr,
+                              Z_InitRequest *req);
+
+    int client_authentication(const char *name,
+                             const char *user, const char *group,
+                             const char *password);
+    char *get_explain_doc(ODR odr, const char *name, const char *db,
+                         int *len);
+    const char *get_explain_name(const char *db, const char **backend_db);
+ private:
+    void operator=(const Yaz_ProxyConfig &conf);
+    class Yaz_ProxyConfigP *m_cp;
+};
+
+class Yaz_RecordCache {
+ public:
+    Yaz_RecordCache ();
+    ~Yaz_RecordCache ();
+    void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
+    
+    int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
+               Odr_oid *syntax, Z_RecordComposition *comp);
+    void clear();
+
+    void copy_searchRequest(Z_SearchRequest *sr);
+    void copy_presentRequest(Z_PresentRequest *pr);
+    void set_max_size(int sz);
+ private:
+    NMEM m_mem;
+    Yaz_RecordCache_Entry *m_entries;
+    Z_SearchRequest *m_searchRequest;
+    Z_PresentRequest *m_presentRequest;
+    int match (Yaz_RecordCache_Entry *entry,
+              Odr_oid *syntax, int offset,
+              Z_RecordComposition *comp);
+    int m_max_size;
+};
+
+class Yaz_ProxyClient : public Yaz_Z_Assoc {
+    friend class Yaz_Proxy;
+    Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable,
+                   Yaz_Proxy *parent);
+    ~Yaz_ProxyClient();
+    void recv_GDU(Z_GDU *apdu, int len);
+    void recv_Z_PDU(Z_APDU *apdu, int len);
+    void recv_HTTP_response(Z_HTTP_Response *apdu, int len);
+    IYaz_PDU_Observer* sessionNotify
+       (IYaz_PDU_Observable *the_PDU_Observable, int fd);
+    void shutdown();
+    Yaz_Proxy *m_server;
+    void failNotify();
+    void timeoutNotify();
+    void connectNotify();
+    int send_to_target(Z_APDU *apdu);
+    const char *get_session_str();
+    char *m_cookie;
+    Yaz_ProxyClient *m_next;
+    Yaz_ProxyClient **m_prev;
+    int m_init_flag;
+    Yaz_Z_Query *m_last_query;
+    Yaz_Z_Databases m_last_databases;
+    char *m_last_resultSetId;
+    int m_last_ok;
+    int m_last_resultCount;
+    int m_sr_transform;
+    int m_seqno;
+    int m_waiting;
+    int m_resultSetStartPoint;
+    int m_bytes_sent;
+    int m_bytes_recv;
+    int m_pdu_recv;
+    ODR m_init_odr;
+    Z_APDU *m_initResponse;
+    Z_Options *m_initResponse_options;
+    Z_ProtocolVersion *m_initResponse_version;
+    int m_initResponse_preferredMessageSize;
+    int m_initResponse_maximumRecordSize;
+    Yaz_RecordCache m_cache;
+    void pre_init_client();
+    int m_target_idletime;
+    Yaz_Proxy *m_root;
+};
+
index 951f1aa..29865e0 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: yaz-proxy-config.cpp,v 1.16 2005-02-20 21:59:08 adam Exp $
+/* $Id: yaz-proxy-config.cpp,v 1.17 2005-02-21 14:27:32 adam Exp $
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
@@ -31,7 +31,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 class Yaz_ProxyModule {
 private:
 
 class Yaz_ProxyModule {
 private:
-    void *m_dl_handle;                 /* dlopen/close handle */
+    void *m_dl_handle;                /* dlopen/close handle */
     Yaz_ProxyModule_entry *m_entry;
     Yaz_ProxyModule *m_next; 
     void *m_user_handle;              /* user handle */
     Yaz_ProxyModule_entry *m_entry;
     Yaz_ProxyModule *m_next; 
     void *m_user_handle;              /* user handle */
@@ -39,10 +39,20 @@ public:
     Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
                    Yaz_ProxyModule *next);
     ~Yaz_ProxyModule();
     Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
                    Yaz_ProxyModule *next);
     ~Yaz_ProxyModule();
+    
     Yaz_ProxyModule *get_next() { return m_next; };
     Yaz_ProxyModule *get_next() { return m_next; };
-    int authenticate(const char *user, const char *group, const char *password);
+    int is_module(const char *name);
+    int authenticate(const char *target_name, void *element_ptr,
+                    const char *user, const char *group, const char *password);
 };
 
 };
 
+int Yaz_ProxyModule::is_module(const char *type)
+{
+    if (!type || !strcmp(m_entry->module_name, type))
+       return 1;
+    return 0;
+}
+
 Yaz_ProxyModule::Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
                                 Yaz_ProxyModule *next)
 {
 Yaz_ProxyModule::Yaz_ProxyModule(void *dl_handle, Yaz_ProxyModule_entry *ent,
                                 Yaz_ProxyModule *next)
 {
@@ -73,7 +83,9 @@ Yaz_ProxyModule::~Yaz_ProxyModule()
 #endif
 }
 
 #endif
 }
 
-int Yaz_ProxyModule::authenticate(const char *user, const char *group,
+int Yaz_ProxyModule::authenticate(const char *name,
+                                 void *element_ptr,
+                                 const char *user, const char *group,
                                  const char *password)
 {
     if (m_entry->int_version == 0)
                                  const char *password)
 {
     if (m_entry->int_version == 0)
@@ -83,7 +95,8 @@ int Yaz_ProxyModule::authenticate(const char *user, const char *group,
        
        if (!int0->authenticate)
            return YAZPROXY_RET_NOT_ME;
        
        if (!int0->authenticate)
            return YAZPROXY_RET_NOT_ME;
-       return (*int0->authenticate)(m_user_handle, user, group, password);
+       return (*int0->authenticate)(m_user_handle, name, element_ptr,
+                                    user, group, password);
     }
     return YAZPROXY_RET_NOT_ME;
 }
     }
     return YAZPROXY_RET_NOT_ME;
 }
@@ -108,7 +121,6 @@ class Yaz_ProxyConfigP {
                            int *target_idletime, int *client_idletime,
                            int *keepalive_limit_bw, int *keepalive_limit_pdu,
                            int *pre_init, const char **cql2rpn,
                            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 **negotiation_charset,
                            const char **negotiation_lang);
     void return_limit(xmlNodePtr ptr,
                            const char **negotiation_charset,
                            const char **negotiation_lang);
     void return_limit(xmlNodePtr ptr,
@@ -160,7 +172,14 @@ Yaz_ProxyConfig::~Yaz_ProxyConfig()
 #if HAVE_XSLT
 void Yaz_ProxyConfigP::unload_modules()
 {
 #if HAVE_XSLT
 void Yaz_ProxyConfigP::unload_modules()
 {
-    yaz_log(YLOG_WARN, "unload_modules not implemented yet");
+    Yaz_ProxyModule *m = m_modules;
+    while (m)
+    {
+       Yaz_ProxyModule *m_next = m->get_next();
+       delete m;
+       m = m_next;
+    }
+    m_modules = 0;
 }
 #endif
 
 }
 #endif
 
@@ -308,7 +327,6 @@ void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
                                          int *keepalive_limit_pdu,
                                          int *pre_init,
                                          const char **cql2rpn,
                                          int *keepalive_limit_pdu,
                                          int *pre_init,
                                          const char **cql2rpn,
-                                         const char **authentication,
                                          const char **negotiation_charset,
                                          const char **negotiation_lang)
 {
                                          const char **negotiation_charset,
                                          const char **negotiation_lang)
 {
@@ -375,13 +393,6 @@ void Yaz_ProxyConfigP::return_target_info(xmlNodePtr ptr,
                *cql2rpn = t;
        }
        if (ptr->type == XML_ELEMENT_NODE 
                *cql2rpn = t;
        }
        if (ptr->type == XML_ELEMENT_NODE 
-           && !strcmp((const char *) ptr->name, "authentication"))
-       {
-           const char *t = get_text(ptr);
-           if (t)
-               *authentication = t;
-       }
-       if (ptr->type == XML_ELEMENT_NODE 
            && !strcmp((const char *) ptr->name, "negotiation-charset"))
        {
            const char *t = get_text(ptr);
            && !strcmp((const char *) ptr->name, "negotiation-charset"))
        {
            const char *t = get_text(ptr);
@@ -632,19 +643,108 @@ const char *Yaz_ProxyConfig::check_mime_type(const char *path)
 }
 
 
 }
 
 
-int Yaz_ProxyConfig::check_authentication(const char *user,
-                                         const char *group,
-                                         const char *password)
+void Yaz_ProxyConfig::target_authentication(const char *name,
+                                           ODR odr, Z_InitRequest *req)
 {
 {
-    Yaz_ProxyModule *m = m_cp->m_modules;
+#if HAVE_XSLT
+    xmlNodePtr ptr = m_cp->find_target_node(name, 0);
+    if (!ptr)
+       return ;
+    
+    for (ptr = ptr->children; ptr; ptr = ptr->next)
+       if (ptr->type == XML_ELEMENT_NODE &&
+           !strcmp((const char *) ptr->name, "target-authentication"))
+       {
+           struct _xmlAttr *attr;
+           const char *type = "open";
+           for (attr = ptr->properties; attr; attr = attr->next)
+           {
+               if (!strcmp((const char *) attr->name, "type") &&
+                   attr->children && attr->children->type == XML_TEXT_NODE)
+                   type = (const char *) attr->children->content;
+           }
+           const char *t = m_cp->get_text(ptr);
+           if (!t || !strcmp(type, "none"))
+               req->idAuthentication = 0;
+           else if (!strcmp(type, "anonymous"))
+           {
+               req->idAuthentication =
+                   (Z_IdAuthentication *)
+                   odr_malloc (odr, sizeof(*req->idAuthentication));
+               req->idAuthentication->which =
+                   Z_IdAuthentication_anonymous;
+               req->idAuthentication->u.anonymous = odr_nullval();
+           }
+           else if (!strcmp(type, "open"))
+           {
+               req->idAuthentication =
+                   (Z_IdAuthentication *)
+                   odr_malloc (odr, sizeof(*req->idAuthentication));
+               req->idAuthentication->which =
+                   Z_IdAuthentication_open;
+               req->idAuthentication->u.open = odr_strdup (odr, t);
+           }
+           else if (!strcmp(type, "idPass"))
+           {
+               char user[64], group[64], password[64];
+               *group = '\0';
+               *password = '\0';
+               *user = '\0';
+               sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
+               
+               req->idAuthentication =
+                   (Z_IdAuthentication *)
+                   odr_malloc (odr, sizeof(*req->idAuthentication));
+               req->idAuthentication->which =
+                   Z_IdAuthentication_idPass;
+               req->idAuthentication->u.idPass =
+                   (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
+               req->idAuthentication->u.idPass->userId =
+                   *user ? odr_strdup(odr, user) : 0;
+               req->idAuthentication->u.idPass->groupId =
+                   *group ? odr_strdup(odr, group) : 0;
+               req->idAuthentication->u.idPass->password =
+                   *password ? odr_strdup(odr, password) : 0;
+           }
+       }
+#endif
+}
 
 
+int Yaz_ProxyConfig::client_authentication(const char *name,
+                                          const char *user,
+                                          const char *group,
+                                          const char *password)
+{
     int ret = YAZPROXY_RET_NOT_ME;
     int ret = YAZPROXY_RET_NOT_ME;
-    for (; m; m = m->get_next())
-    {
-       ret = m->authenticate(user, group, password);
-       if (ret != YAZPROXY_RET_NOT_ME)
-           break;
-    }
+#if HAVE_XSLT
+    xmlNodePtr ptr;
+    ptr = m_cp->find_target_node(name, 0);
+    if (!ptr)
+       return 1;
+    for (ptr = ptr->children; ptr; ptr = ptr->next)
+       if (ptr->type == XML_ELEMENT_NODE &&
+           !strcmp((const char *) ptr->name, "client-authentication"))
+       {
+           struct _xmlAttr *attr;
+           const char *module_name = 0;
+           for (attr = ptr->properties; attr; attr = attr->next)
+           {
+               if (!strcmp((const char *) attr->name, "module") &&
+                   attr->children && attr->children->type == XML_TEXT_NODE)
+                   module_name = (const char *) attr->children->content;
+           }
+           Yaz_ProxyModule *m = m_cp->m_modules;
+           for (; m; m = m->get_next())
+           {
+               if (m->is_module(module_name))
+               {
+                   ret = m->authenticate(name, ptr, user, group, password);
+                   if (ret != YAZPROXY_RET_NOT_ME)
+                       break;
+               }
+           }
+       }
+#endif
     if (ret == YAZPROXY_RET_PERM)
        return 0;
     return 1;
     if (ret == YAZPROXY_RET_PERM)
        return 0;
     return 1;
@@ -948,7 +1048,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,
                    limit_bw, limit_pdu, limit_req,
                    target_idletime, client_idletime,
                    keepalive_limit_bw, keepalive_limit_pdu,
-                   pre_init, cql2rpn, authentication,
+                   pre_init, cql2rpn,
                    negotiation_charset, negotiation_lang);
                return 1;
            }
                    negotiation_charset, negotiation_lang);
                return 1;
            }
@@ -1147,7 +1247,6 @@ void Yaz_ProxyConfig::get_target_info(const char *name,
                                      int *keepalive_limit_pdu,
                                      int *pre_init,
                                      const char **cql2rpn,
                                      int *keepalive_limit_pdu,
                                      int *pre_init,
                                      const char **cql2rpn,
-                                     const char **authentication,
                                      const char **negotiation_charset,
                                      const char **negotiation_lang)
 {
                                      const char **negotiation_charset,
                                      const char **negotiation_lang)
 {
@@ -1185,7 +1284,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,
        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,
                                 negotiation_charset, negotiation_lang);
     }
 #else
                                 negotiation_charset, negotiation_lang);
     }
 #else
index e25b1e4..f40c64a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: yaz-proxy-main.cpp,v 1.11 2005-02-11 15:39:55 adam Exp $
+/* $Id: yaz-proxy-main.cpp,v 1.12 2005-02-21 14:27:32 adam Exp $
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
@@ -76,7 +76,7 @@ int args(Yaz_Proxy *proxy, int argc, char **argv)
     char *prog = argv[0];
     int ret;
 
     char *prog = argv[0];
     int ret;
 
-    while ((ret = options("o:a:t:v:c:u:i:m:l:T:p:U:n:X",
+    while ((ret = options("o:a:t:v:c:u:i:m:l:T:p:n:X",
                          argv, argc, &arg)) != -2)
     {
        int err;
                          argv, argc, &arg)) != -2)
     {
        int err;
@@ -109,9 +109,6 @@ int args(Yaz_Proxy *proxy, int argc, char **argv)
         case 't':
            proxy->set_default_target(arg);
            break;
         case 't':
            proxy->set_default_target(arg);
            break;
-        case 'U':
-            proxy->set_proxy_authentication(arg);
-            break;
         case 'o':
            proxy->option("optimize", arg);
            break;
         case 'o':
            proxy->option("optimize", arg);
            break;
@@ -135,6 +132,7 @@ int args(Yaz_Proxy *proxy, int argc, char **argv)
            no_limit_files = atoi(arg);
            break;
        case 'X':
            no_limit_files = atoi(arg);
            break;
        case 'X':
+           proxy->set_debug_mode(1);
            debug = 1;
            break;
        case 'p':
            debug = 1;
            break;
        case 'p':
index 4400bbb..0e07078 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: yaz-proxy.cpp,v 1.22 2005-02-11 15:19:08 adam Exp $
+/* $Id: yaz-proxy.cpp,v 1.23 2005-02-21 14:27:32 adam Exp $
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
    Copyright (c) 1998-2005, Index Data.
 
 This file is part of the yaz-proxy.
@@ -38,6 +38,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #endif
 
 #include <assert.h>
 #endif
 
 #include <assert.h>
+#include <stdlib.h>
 #include <time.h>
 #include <fcntl.h>
 
 #include <time.h>
 #include <fcntl.h>
 
@@ -116,7 +117,6 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable,
     m_keepalive_limit_pdu = 1000;
     m_proxyTarget = 0;
     m_default_target = 0;
     m_keepalive_limit_pdu = 1000;
     m_proxyTarget = 0;
     m_default_target = 0;
-    m_proxy_authentication = 0;
     m_proxy_negotiation_charset = 0;
     m_proxy_negotiation_lang = 0;
     m_max_clients = 150;
     m_proxy_negotiation_charset = 0;
     m_proxy_negotiation_lang = 0;
     m_max_clients = 150;
@@ -196,7 +196,6 @@ Yaz_Proxy::~Yaz_Proxy()
 
     xfree(m_proxyTarget);
     xfree(m_default_target);
 
     xfree(m_proxyTarget);
     xfree(m_default_target);
-    xfree(m_proxy_authentication);
     xfree(m_proxy_negotiation_charset);
     xfree(m_proxy_negotiation_lang);
     xfree(m_optimize);
     xfree(m_proxy_negotiation_charset);
     xfree(m_proxy_negotiation_lang);
     xfree(m_optimize);
@@ -222,6 +221,11 @@ Yaz_Proxy::~Yaz_Proxy()
     delete m_config;
 }
 
     delete m_config;
 }
 
+void Yaz_Proxy::set_debug_mode(int mode)
+{
+    m_debug_mode = mode;
+}
+
 int Yaz_Proxy::set_config(const char *config)
 {
     delete m_config;
 int Yaz_Proxy::set_config(const char *config)
 {
     delete m_config;
@@ -242,14 +246,6 @@ void Yaz_Proxy::set_default_target(const char *target)
        m_default_target = (char *) xstrdup (target);
 }
 
        m_default_target = (char *) xstrdup (target);
 }
 
-void Yaz_Proxy::set_proxy_authentication (const char *auth)
-{
-    xfree (m_proxy_authentication);
-    m_proxy_authentication = 0;
-    if (auth)
-       m_proxy_authentication = (char *) xstrdup (auth);
-}
-
 void Yaz_Proxy::set_proxy_negotiation (const char *charset, const char *lang)
 {
     yaz_log(YLOG_LOG, "%sSet the proxy negotiation: charset to '%s', "
 void Yaz_Proxy::set_proxy_negotiation (const char *charset, const char *lang)
 {
     yaz_log(YLOG_LOG, "%sSet the proxy negotiation: charset to '%s', "
@@ -310,7 +306,6 @@ IYaz_PDU_Observer *Yaz_Proxy::sessionNotify(IYaz_PDU_Observable
        new_proxy->set_APDU_yazlog(1);
     else
        new_proxy->set_APDU_yazlog(0);
        new_proxy->set_APDU_yazlog(1);
     else
        new_proxy->set_APDU_yazlog(0);
-    new_proxy->set_proxy_authentication(m_proxy_authentication);
     new_proxy->set_proxy_negotiation(m_proxy_negotiation_charset,
        m_proxy_negotiation_lang);
     sprintf(new_proxy->m_session_str, "%ld:%d ", (long) time(0), m_session_no);
     new_proxy->set_proxy_negotiation(m_proxy_negotiation_charset,
        m_proxy_negotiation_lang);
     sprintf(new_proxy->m_session_str, "%ld:%d ", (long) time(0), m_session_no);
@@ -415,18 +410,18 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie,
        Yaz_ProxyConfig *cfg = check_reconfigure();
        if (proxy_host)
        {
        Yaz_ProxyConfig *cfg = check_reconfigure();
        if (proxy_host)
        {
-#if 0
-/* only to be enabled for debugging... */
-           if (!strcmp(proxy_host, "stop"))
-               exit(0);
-#endif
+           if (parent && parent->m_debug_mode)
+           {
+                // only to be enabled for debugging...
+               if (!strcmp(proxy_host, "stop"))
+                   exit(0);
+           }
            xfree(m_default_target);
            m_default_target = xstrdup(proxy_host);
        }
        proxy_host = m_default_target;
        int client_idletime = -1;
        const char *cql2rpn_fname = 0;
            xfree(m_default_target);
            m_default_target = xstrdup(proxy_host);
        }
        proxy_host = m_default_target;
        int client_idletime = -1;
        const char *cql2rpn_fname = 0;
-       const char *authentication = 0;
        const char *negotiation_charset = 0;
        const char *negotiation_lang = 0;
        url[0] = m_default_target;
        const char *negotiation_charset = 0;
        const char *negotiation_lang = 0;
        url[0] = m_default_target;
@@ -442,7 +437,6 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie,
                                 &m_keepalive_limit_pdu,
                                 &pre_init,
                                 &cql2rpn_fname,
                                 &m_keepalive_limit_pdu,
                                 &pre_init,
                                 &cql2rpn_fname,
-                                &authentication,
                                 &negotiation_charset,
                                 &negotiation_lang);
        }
                                 &negotiation_charset,
                                 &negotiation_lang);
        }
@@ -453,11 +447,12 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie,
        }
        if (cql2rpn_fname)
            m_cql2rpn.set_pqf_file(cql2rpn_fname);
        }
        if (cql2rpn_fname)
            m_cql2rpn.set_pqf_file(cql2rpn_fname);
-       if (authentication)
-           set_proxy_authentication(authentication);
        if (negotiation_charset || negotiation_lang)
        if (negotiation_charset || negotiation_lang)
+       {
+           yaz_log(YLOG_LOG, "set_proxy_negotiation...");
            set_proxy_negotiation(negotiation_charset,
                negotiation_lang);
            set_proxy_negotiation(negotiation_charset,
                negotiation_lang);
+       }
        if (!url[0])
        {
            yaz_log(YLOG_LOG, "%sNo default target", m_session_str);
        if (!url[0])
        {
            yaz_log(YLOG_LOG, "%sNo default target", m_session_str);
@@ -561,23 +556,9 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu, const char *cookie,
        }
         Z_InitRequest *initRequest = apdu->u.initRequest;
 
        }
         Z_InitRequest *initRequest = apdu->u.initRequest;
 
-        if (!initRequest->idAuthentication)
-        {
-            if (m_proxy_authentication)
-            {
-                initRequest->idAuthentication =
-                    (Z_IdAuthentication *)
-                    odr_malloc (odr_encode(),
-                                sizeof(*initRequest->idAuthentication));
-                initRequest->idAuthentication->which =
-                    Z_IdAuthentication_open;
-                initRequest->idAuthentication->u.open =
-                    odr_strdup (odr_encode(), m_proxy_authentication);
-            }
-        }
-       else
+        if (initRequest->idAuthentication)
        {
        {
-           // the client use authentication. We set the keepalive PDU
+           // the client uses authentication. We set the keepalive PDU
            // to 0 so we don't cache it in releaseClient
            m_keepalive_limit_pdu = 0;
        }
            // to 0 so we don't cache it in releaseClient
            m_keepalive_limit_pdu = 0;
        }
@@ -844,6 +825,7 @@ void Yaz_Proxy::convert_to_frontend_type(Z_NamePlusRecordList *p)
                        continue;
                    }
 #endif
                        continue;
                    }
 #endif
+/* HAVE_USEMARCON */
                    npr->u.databaseRecord =
                        z_ext_record(odr_encode(),
                                     m_frontend_type,
                    npr->u.databaseRecord =
                        z_ext_record(odr_encode(),
                                     m_frontend_type,
@@ -1850,11 +1832,11 @@ int Yaz_Proxy::handle_authentication(Z_APDU *apdu)
     int ret;
     if (req->idAuthentication == 0)
     {
     int ret;
     if (req->idAuthentication == 0)
     {
-       ret = cfg->check_authentication(0, 0, 0);
+       ret = cfg->client_authentication(m_default_target, 0, 0, 0);
     }
     else if (req->idAuthentication->which == Z_IdAuthentication_idPass)
     {
     }
     else if (req->idAuthentication->which == Z_IdAuthentication_idPass)
     {
-       ret = cfg->check_authentication(
+       ret = cfg->client_authentication(m_default_target,
            req->idAuthentication->u.idPass->userId,
            req->idAuthentication->u.idPass->groupId,
            req->idAuthentication->u.idPass->password);
            req->idAuthentication->u.idPass->userId,
            req->idAuthentication->u.idPass->groupId,
            req->idAuthentication->u.idPass->password);
@@ -1865,10 +1847,13 @@ int Yaz_Proxy::handle_authentication(Z_APDU *apdu)
        *user = '\0';
        *pass = '\0';
        sscanf(req->idAuthentication->u.open, "%63[^/]/%63s", user, pass);
        *user = '\0';
        *pass = '\0';
        sscanf(req->idAuthentication->u.open, "%63[^/]/%63s", user, pass);
-       ret = cfg->check_authentication(user, 0, pass);
+       ret = cfg->client_authentication(m_default_target, user, 0, pass);
     }
     else
     }
     else
-       ret = cfg->check_authentication(0, 0, 0);
+       ret = cfg->client_authentication(m_default_target, 0, 0, 0);
+
+    cfg->target_authentication(m_default_target, odr_encode(), req);
+
     return ret;
 }
 
     return ret;
 }