Add support for thread config element which specifies number of
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 9 Jun 2006 09:35:13 +0000 (09:35 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 9 Jun 2006 09:35:13 +0000 (09:35 +0000)
threads to be used for auhentication modules. By default, no
threading is used which happen to be value 0. Modules will still
work but they will be blocking.

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

index 9804cd5..91aef13 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
 <?xml version="1.0"?>
-<!-- $Id: config-modules.xml,v 1.2 2005-05-30 20:09:20 adam Exp $ -->
+<!-- $Id: config-modules.xml,v 1.3 2006-06-09 09:35:13 adam Exp $ -->
 <!-- 
    Config that uses modules 
 -->
 <!-- 
    Config that uses modules 
 -->
@@ -37,4 +37,5 @@
   <max-clients>50</max-clients>
   <log>client-requests server-requests</log>
   <module>../src/.libs/mod_proxy_sample.so</module>
   <max-clients>50</max-clients>
   <log>client-requests server-requests</log>
   <module>../src/.libs/mod_proxy_sample.so</module>
+  <threads>2</threads>
 </proxy>
 </proxy>
index 938044f..dbed522 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: proxy.h,v 1.35 2006-04-26 11:59:10 adam Exp $
+/* $Id: proxy.h,v 1.36 2006-06-09 09:35:13 adam Exp $
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
@@ -213,7 +213,6 @@ class YAZ_EXPORT Yaz_Proxy : public yazpp_1::Z_Assoc {
               Yaz_Proxy *parent = 0);
     ~Yaz_Proxy();
 
               Yaz_Proxy *parent = 0);
     ~Yaz_Proxy();
 
-
     void inc_ref();
     bool dec_ref();
 
     void inc_ref();
     bool dec_ref();
 
@@ -254,6 +253,7 @@ class YAZ_EXPORT Yaz_Proxy : public yazpp_1::Z_Assoc {
     int handle_init_response_for_invalid_session(Z_APDU *apdu);
     void set_debug_mode(int mode);
     void send_response_fail_client(const char *addr);
     int handle_init_response_for_invalid_session(Z_APDU *apdu);
     void set_debug_mode(int mode);
     void send_response_fail_client(const char *addr);
+    int m_num_msg_threads;
     Msg_Thread *m_my_thread;
     void base64_decode(const char *base64, char *buf, int buf_len);
 };
     Msg_Thread *m_my_thread;
     void base64_decode(const char *base64, char *buf, int buf_len);
 };
index 8a94f9a..06e46bd 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: proxyp.h,v 1.16 2006-04-06 16:25:21 adam Exp $
+/* $Id: proxyp.h,v 1.17 2006-06-09 09:35:13 adam Exp $
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
@@ -106,7 +106,8 @@ public:
 
     void get_generic_info(int *log_mask, int *max_clients,
                           int *max_connect, int *limit_connect,
 
     void get_generic_info(int *log_mask, int *max_clients,
                           int *max_connect, int *limit_connect,
-                          int *period_connect);
+                          int *period_connect,
+                          int *msg_threads);
 
     int get_file_access_info(const char *path);
 
 
     int get_file_access_info(const char *path);
 
index 040abc5..24fa1b0 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: yaz-proxy-config.cpp,v 1.31 2006-04-16 07:33:13 adam Exp $
+/* $Id: yaz-proxy-config.cpp,v 1.32 2006-06-09 09:35:14 adam Exp $
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
@@ -1022,10 +1022,12 @@ void Yaz_ProxyConfig::get_generic_info(int *log_mask,
                                        int *max_clients,
                                        int *max_connect,
                                        int *limit_connect,
                                        int *max_clients,
                                        int *max_connect,
                                        int *limit_connect,
-                                       int *period_connect)
+                                       int *period_connect,
+                                       int *num_msg_threads)
 {
     *max_connect = 0;
     *limit_connect = 0;
 {
     *max_connect = 0;
     *limit_connect = 0;
+    *num_msg_threads = 0;
 #if HAVE_XSLT
     xmlNodePtr ptr;
     if (!m_cp->m_proxyPtr)
 #if HAVE_XSLT
     xmlNodePtr ptr;
     if (!m_cp->m_proxyPtr)
@@ -1107,6 +1109,15 @@ void Yaz_ProxyConfig::get_generic_info(int *log_mask,
         else if (ptr->type == XML_ELEMENT_NODE &&
             !strcmp((const char *) ptr->name, "module"))
             ;
         else if (ptr->type == XML_ELEMENT_NODE &&
             !strcmp((const char *) ptr->name, "module"))
             ;
+        else if (ptr->type == XML_ELEMENT_NODE &&
+            !strcmp((const char *) ptr->name, "threads"))
+        {
+            const char *t = m_cp->get_text(ptr);
+            if (t)
+            {
+                *num_msg_threads = atoi(t);
+            }
+        }
         else if (ptr->type == XML_ELEMENT_NODE)
         {
             yaz_log(YLOG_WARN, "0 Unknown element %s in yazproxy config",
         else if (ptr->type == XML_ELEMENT_NODE)
         {
             yaz_log(YLOG_WARN, "0 Unknown element %s in yazproxy config",
index dcabc91..194b973 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: yaz-proxy.cpp,v 1.67 2006-06-09 09:01:31 adam Exp $
+/* $Id: yaz-proxy.cpp,v 1.68 2006-06-09 09:35:14 adam Exp $
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
@@ -59,9 +59,6 @@ using namespace yazpp_1;
 #define strncasecmp _strnicmp
 #endif
 
 #define strncasecmp _strnicmp
 #endif
 
-#define USE_AUTH_MSG 1
-
-#if USE_AUTH_MSG
 class YAZ_EXPORT Auth_Msg : public IMsg_Thread {
 public:
     int m_ret;
 class YAZ_EXPORT Auth_Msg : public IMsg_Thread {
 public:
     int m_ret;
@@ -122,8 +119,6 @@ void Auth_Msg::result()
     delete this;
 }
 
     delete this;
 }
 
-#endif
-
 void Yaz_Proxy::result_authentication(Z_APDU *apdu, int ret)
 {
     if (apdu == 0 || ret == 0)
 void Yaz_Proxy::result_authentication(Z_APDU *apdu, int ret)
 {
     if (apdu == 0 || ret == 0)
@@ -295,6 +290,7 @@ Yaz_Proxy::Yaz_Proxy(IPDU_Observable *the_PDU_Observable,
     m_ref_count = 1;
     m_main_ptr_dec = false;
     m_peername = 0;
     m_ref_count = 1;
     m_main_ptr_dec = false;
     m_peername = 0;
+    m_num_msg_threads = 0;
 }
 
 void Yaz_Proxy::inc_ref()
 }
 
 void Yaz_Proxy::inc_ref()
@@ -358,7 +354,8 @@ int Yaz_Proxy::set_config(const char *config)
     {
         int period = 60;
         m_config->get_generic_info(&m_log_mask, &m_max_clients,
     {
         int period = 60;
         m_config->get_generic_info(&m_log_mask, &m_max_clients,
-                                   &m_max_connect, &m_limit_connect, &period);
+                                   &m_max_connect, &m_limit_connect, &period,
+                                   &m_num_msg_threads);
         m_connect.set_period(period);
     }
     return r;
         m_connect.set_period(period);
     }
     return r;
@@ -414,7 +411,7 @@ Yaz_ProxyConfig *Yaz_Proxy::check_reconfigure()
                 int period = 60;
                 cfg->get_generic_info(&m_log_mask, &m_max_clients,
                                       &m_max_connect, &m_limit_connect,
                 int period = 60;
                 cfg->get_generic_info(&m_log_mask, &m_max_clients,
                                       &m_max_connect, &m_limit_connect,
-                                      &period);
+                                      &period, &m_num_msg_threads);
                 m_connect.set_period(period);
             }
         }
                 m_connect.set_period(period);
             }
         }
@@ -456,6 +453,7 @@ IPDU_Observer *Yaz_Proxy::sessionNotify(IPDU_Observable
     new_proxy->m_max_clients = m_max_clients;
     new_proxy->m_log_mask = m_log_mask;
     new_proxy->m_session_no = m_session_no;
     new_proxy->m_max_clients = m_max_clients;
     new_proxy->m_log_mask = m_log_mask;
     new_proxy->m_session_no = m_session_no;
+    new_proxy->m_num_msg_threads = m_num_msg_threads;
 
 #if 0
     // in case we want to watch a particular client..
 
 #if 0
     // in case we want to watch a particular client..
@@ -473,8 +471,12 @@ IPDU_Observer *Yaz_Proxy::sessionNotify(IPDU_Observable
     new_proxy->set_proxy_negotiation(m_proxy_negotiation_charset,
         m_proxy_negotiation_lang, m_proxy_negotiation_default_charset);
     // create thread object the first time we get an incoming connection
     new_proxy->set_proxy_negotiation(m_proxy_negotiation_charset,
         m_proxy_negotiation_lang, m_proxy_negotiation_default_charset);
     // create thread object the first time we get an incoming connection
-    if (!m_my_thread)
-        m_my_thread = new Msg_Thread(m_socket_observable, 1);
+    if (!m_my_thread && m_num_msg_threads > 0)
+    {
+        yaz_log (YLOG_LOG, "%sStarting message thread management. number=%d",
+                 session_str, m_num_msg_threads);
+        m_my_thread = new Msg_Thread(m_socket_observable, m_num_msg_threads);
+    }
     new_proxy->m_my_thread = m_my_thread;
     return new_proxy;
 }
     new_proxy->m_my_thread = m_my_thread;
     return new_proxy;
 }
@@ -3143,21 +3145,24 @@ void Yaz_Proxy::handle_init(Z_APDU *apdu)
     }
     m_client->m_init_flag = 1;
 
     }
     m_client->m_init_flag = 1;
 
-#if USE_AUTH_MSG
-    Auth_Msg *m = new Auth_Msg;
-    m->m_proxy = this;
-    z_APDU(odr_encode(), &apdu, 0, "encode");
-    char *apdu_buf = odr_getbuf(odr_encode(), &m->m_apdu_len, 0);
-    m->m_apdu_buf = (char*) nmem_malloc(m->m_nmem, m->m_apdu_len);
-    memcpy(m->m_apdu_buf, apdu_buf, m->m_apdu_len);
-    odr_reset(odr_encode());
-
-    inc_ref();
-    m_my_thread->put(m);
-#else
-    int ret = handle_authentication(apdu);
-    result_authentication(apdu, ret);
-#endif
+    if (m_num_msg_threads && m_my_thread)
+    {
+        Auth_Msg *m = new Auth_Msg;
+        m->m_proxy = this;
+        z_APDU(odr_encode(), &apdu, 0, "encode");
+        char *apdu_buf = odr_getbuf(odr_encode(), &m->m_apdu_len, 0);
+        m->m_apdu_buf = (char*) nmem_malloc(m->m_nmem, m->m_apdu_len);
+        memcpy(m->m_apdu_buf, apdu_buf, m->m_apdu_len);
+        odr_reset(odr_encode());
+        
+        inc_ref();
+        m_my_thread->put(m);
+    }
+    else
+    {
+        int ret = handle_authentication(apdu);
+        result_authentication(apdu, ret);
+    }
 }
 
 void Yaz_Proxy::handle_incoming_Z_PDU(Z_APDU *apdu)
 }
 
 void Yaz_Proxy::handle_incoming_Z_PDU(Z_APDU *apdu)