From: Adam Dickmeiss Date: Wed, 10 Nov 1999 10:02:34 +0000 (+0000) Subject: Work on proxy. X-Git-Tag: YAZPP.0.3~93 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=2e14b1af67a2044e73d024bc29445035910a2dd4;p=yazpp-moved-to-github.git Work on proxy. --- diff --git a/include/yaz-pdu-assoc.h b/include/yaz-pdu-assoc.h index afda750..ff286c0 100644 --- a/include/yaz-pdu-assoc.h +++ b/include/yaz-pdu-assoc.h @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: yaz-pdu-assoc.h,v 1.5 1999-04-20 10:30:05 adam Exp $ + * $Id: yaz-pdu-assoc.h,v 1.6 1999-11-10 10:02:34 adam Exp $ */ #include @@ -42,7 +42,7 @@ class YAZ_EXPORT Yaz_PDU_Assoc : public IYaz_PDU_Observable, IYazSocketObserver int m_idleTime; public: /// Create object using specified socketObservable - Yaz_PDU_Assoc(IYazSocketObservable *socketObservable, COMSTACK cs); + Yaz_PDU_Assoc(IYazSocketObservable *socketObservable, COMSTACK cs = 0); /// Close socket and destroy object. virtual ~Yaz_PDU_Assoc(); /// Clone the object diff --git a/include/yaz-proxy.h b/include/yaz-proxy.h index 3f863c0..3d051c9 100644 --- a/include/yaz-proxy.h +++ b/include/yaz-proxy.h @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: yaz-proxy.h,v 1.7 1999-04-28 13:31:17 adam Exp $ + * $Id: yaz-proxy.h,v 1.8 1999-11-10 10:02:34 adam Exp $ */ #include @@ -39,6 +39,7 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc { IYaz_PDU_Observer* clone(IYaz_PDU_Observable *the_PDU_Observable); void failNotify(); void timeoutNotify(); + void proxyTarget(const char *target); private: char *get_cookie(Z_OtherInformation **otherInfo); char *get_proxy(Z_OtherInformation **otherInfo); @@ -51,5 +52,6 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc { Yaz_Proxy *m_parent; int m_seqno; int m_keepalive; + char *m_proxyTarget; }; diff --git a/src/yaz-client.cpp b/src/yaz-client.cpp index 6acdc70..565652e 100644 --- a/src/yaz-client.cpp +++ b/src/yaz-client.cpp @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-client.cpp,v $ - * Revision 1.7 1999-04-21 12:09:01 adam + * Revision 1.8 1999-11-10 10:02:34 adam + * Work on proxy. + * + * Revision 1.7 1999/04/21 12:09:01 adam * Many improvements. Modified to proxy server to work with "sessions" * based on cookies. * @@ -588,7 +591,7 @@ int MyClient::args(Yaz_SocketManager *socketManager, int argc, char **argv) int main(int argc, char **argv) { Yaz_SocketManager mySocketManager; - Yaz_PDU_Assoc *some = new Yaz_PDU_Assoc(&mySocketManager, 0); + Yaz_PDU_Assoc *some = new Yaz_PDU_Assoc(&mySocketManager); MyClient z(some, &mySocketManager); diff --git a/src/yaz-proxy-main.cpp b/src/yaz-proxy-main.cpp index 904f915..2f41054 100644 --- a/src/yaz-proxy-main.cpp +++ b/src/yaz-proxy-main.cpp @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-proxy-main.cpp,v $ - * Revision 1.5 1999-04-21 12:09:01 adam + * Revision 1.6 1999-11-10 10:02:34 adam + * Work on proxy. + * + * Revision 1.5 1999/04/21 12:09:01 adam * Many improvements. Modified to proxy server to work with "sessions" * based on cookies. * @@ -24,17 +27,63 @@ */ #include +#include #include #include #include +void usage(char *prog) +{ + fprintf (stderr, "%s: [-v log] [-t target] @:port\n", prog); + exit (1); +} + + +int args(Yaz_Proxy *proxy, int argc, char **argv) +{ + char *addr = 0; + char *arg; + char *prog = argv[0]; + int ret; + + while ((ret = options("p:v:q", argv, argc, &arg)) != -2) + { + switch (ret) + { + case 0: + if (addr) + { + usage(prog); + return 1; + } + addr = arg; + break; + case 't': + proxy->proxyTarget(arg); + break; + case 'v': + log_init_level (log_mask_str(arg)); + break; + default: + usage(prog); + return 1; + } + } + if (addr) + { + proxy->server(addr); + } + return 0; +} + + int main(int argc, char **argv) { Yaz_SocketManager mySocketManager; - Yaz_Proxy proxy(new Yaz_PDU_Assoc(&mySocketManager, 0)); + Yaz_Proxy proxy(new Yaz_PDU_Assoc(&mySocketManager)); - proxy.server(argc < 2 ? "@:9000" : argv[1]); + args(&proxy, argc, argv); while (mySocketManager.processEvent() > 0) ; return 0; diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index a61233e..9d2e555 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-proxy.cpp,v $ - * Revision 1.9 1999-09-13 12:53:44 adam + * Revision 1.10 1999-11-10 10:02:34 adam + * Work on proxy. + * + * Revision 1.9 1999/09/13 12:53:44 adam * Proxy removes OtherInfo Proxy Address and Session ID. Other * Otherinfo remains untouched. * @@ -52,10 +55,21 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable) : m_clientPool = 0; m_seqno = 1; m_keepalive = 1; + m_proxyTarget = 0; } Yaz_Proxy::~Yaz_Proxy() { + xfree (m_proxyTarget); +} + + +void Yaz_Proxy::proxyTarget(const char *target) +{ + xfree (m_proxyTarget); + m_proxyTarget = 0; + if (target) + m_proxyTarget = (char *) xstrdup (target); } IYaz_PDU_Observer *Yaz_Proxy::clone(IYaz_PDU_Observable @@ -126,6 +140,17 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) } if (!m_client) { + const char *proxy_host = 0; + if (apdu->which == Z_APDU_initRequest) + { + logf (LOG_LOG, "got InitRequest"); + + char *proxy_host = get_proxy(&apdu->u.initRequest->otherInfo); + if (!proxy_host) + proxy_host = m_proxyTarget; + if (!proxy_host) + return 0; + } logf (LOG_LOG, "Yaz_Proxy::get_client creating new"); c = new Yaz_ProxyClient(m_PDU_Observable->clone()); c->m_next = parent->m_clientPool; @@ -141,11 +166,7 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) { logf (LOG_LOG, "got InitRequest"); - char *proxy_host = get_proxy(&apdu->u.initRequest->otherInfo); - if (proxy_host) - c->client(proxy_host); - else - c->client("localhost:9999"); + c->client(proxy_host); } c->timeout(600); } diff --git a/src/yaz-z-assoc.cpp b/src/yaz-z-assoc.cpp index b245a3c..f9a9596 100644 --- a/src/yaz-z-assoc.cpp +++ b/src/yaz-z-assoc.cpp @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-z-assoc.cpp,v $ - * Revision 1.4 1999-09-13 12:53:44 adam + * Revision 1.5 1999-11-10 10:02:34 adam + * Work on proxy. + * + * Revision 1.4 1999/09/13 12:53:44 adam * Proxy removes OtherInfo Proxy Address and Session ID. Other * Otherinfo remains untouched. * @@ -25,6 +28,7 @@ #include #include +#include int Yaz_Z_Assoc::yaz_init_func() {