From 5c45ffbb2b430a6f41277c303a5e9b94242dab96 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 21 Apr 1999 12:09:01 +0000 Subject: [PATCH] Many improvements. Modified to proxy server to work with "sessions" based on cookies. --- include/yaz-ir-assoc.h | 10 +-- include/yaz-proxy.h | 14 ++++- include/yaz-z-assoc.h | 19 +++++- include/yaz-z-query.h | 3 +- src/yaz-client.cpp | 26 ++++++-- src/yaz-ir-assoc.cpp | 56 +++++++---------- src/yaz-pdu-assoc.cpp | 14 +++-- src/yaz-proxy-main.cpp | 8 ++- src/yaz-proxy.cpp | 145 ++++++++++++++++++++++++++++++++++++++------ src/yaz-server.cpp | 16 +++-- src/yaz-socket-manager.cpp | 9 ++- src/yaz-z-assoc.cpp | 108 ++++++++++++++++++++++++++++++++- src/yaz-z-query.cpp | 9 ++- 13 files changed, 348 insertions(+), 89 deletions(-) diff --git a/include/yaz-ir-assoc.h b/include/yaz-ir-assoc.h index 553903c..b60f415 100644 --- a/include/yaz-ir-assoc.h +++ b/include/yaz-ir-assoc.h @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: yaz-ir-assoc.h,v 1.6 1999-04-20 10:30:05 adam Exp $ + * $Id: yaz-ir-assoc.h,v 1.7 1999-04-21 12:09:01 adam Exp $ */ #include @@ -45,14 +45,6 @@ class YAZ_EXPORT Yaz_IR_Assoc: public Yaz_Z_Assoc { int get_lastReceived(); void set_lastReceived(int lastReceived); - /// OtherInformation - void set_otherInformationString (Z_OtherInformation **otherInformationP, - int *oid, int categoryValue, - const char *str); - void set_otherInformationString ( - Z_OtherInformation **otherInformation, - int oidval, int categoryValue, - const char *str); /// Settings void set_proxy(const char *str); const char *get_proxy(); diff --git a/include/yaz-proxy.h b/include/yaz-proxy.h index 86ae642..db2595f 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.4 1999-04-20 10:30:05 adam Exp $ + * $Id: yaz-proxy.h,v 1.5 1999-04-21 12:09:01 adam Exp $ */ #include @@ -14,12 +14,15 @@ class Yaz_Proxy; class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc { friend Yaz_Proxy; Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable); + ~Yaz_ProxyClient(); void recv_Z_PDU(Z_APDU *apdu); IYaz_PDU_Observer* clone(IYaz_PDU_Observable *the_PDU_Observable); Yaz_Proxy *m_server; void failNotify(); - char *m_cookie; + void timeoutNotify(); + char m_cookie[32]; Yaz_ProxyClient *m_next; + Yaz_ProxyClient **m_prev; }; /// Information Retrieval Proxy Server. @@ -30,10 +33,17 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc { void recv_Z_PDU(Z_APDU *apdu); IYaz_PDU_Observer* clone(IYaz_PDU_Observable *the_PDU_Observable); void failNotify(); + void timeoutNotify(); private: char *get_cookie(Z_OtherInformation **otherInfo); char *get_proxy(Z_OtherInformation **otherInfo); + Yaz_ProxyClient *get_client(Z_APDU *apdu); Yaz_ProxyClient *m_client; IYaz_PDU_Observable *m_PDU_Observable; + Yaz_ProxyClient *m_clientPool; + Yaz_Proxy *m_parent; + int m_seqno; + int m_keepalive; }; + diff --git a/include/yaz-z-assoc.h b/include/yaz-z-assoc.h index 59b0b9f..e8c2a1a 100644 --- a/include/yaz-z-assoc.h +++ b/include/yaz-z-assoc.h @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: yaz-z-assoc.h,v 1.2 1999-04-20 10:30:05 adam Exp $ + * $Id: yaz-z-assoc.h,v 1.3 1999-04-21 12:09:01 adam Exp $ */ #include @@ -28,6 +28,8 @@ class YAZ_EXPORT Yaz_Z_Assoc : public IYaz_PDU_Observer { void failNotify(); /// Timeout notification void timeoutNotify(); + /// Timeout specify + void timeout(int timeout); /// Begin Z39.50 client role void client(const char *addr); /// Begin Z39.50 server role @@ -48,10 +50,25 @@ class YAZ_EXPORT Yaz_Z_Assoc : public IYaz_PDU_Observer { ODR odr_encode (); ODR odr_decode (); ODR odr_print (); + /// OtherInformation + void get_otherInfoAPDU(Z_APDU *apdu, Z_OtherInformation ***oip); Z_OtherInformationUnit *update_otherInformation ( Z_OtherInformation **otherInformationP, int createFlag, int *oid, int categoryValue); + void set_otherInformationString ( + Z_OtherInformation **otherInformationP, + int *oid, int categoryValue, + const char *str); + void set_otherInformationString ( + Z_OtherInformation **otherInformation, + int oidval, int categoryValue, + const char *str); + void set_otherInformationString ( + Z_APDU *apdu, + int oidval, int categoryValue, + const char *str); + void set_apdu_log(const char *file); private: static int yaz_init_flag; static int yaz_init_func(); diff --git a/include/yaz-z-query.h b/include/yaz-z-query.h index 587a842..5a2763f 100644 --- a/include/yaz-z-query.h +++ b/include/yaz-z-query.h @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: yaz-z-query.h,v 1.3 1999-04-20 10:30:05 adam Exp $ + * $Id: yaz-z-query.h,v 1.4 1999-04-21 12:09:01 adam Exp $ */ #include @@ -31,4 +31,5 @@ class YAZ_EXPORT Yaz_Z_Query : public Yaz_Query { int len; ODR odr_decode; ODR odr_encode; + ODR odr_print; }; diff --git a/src/yaz-client.cpp b/src/yaz-client.cpp index e0c26f1..6acdc70 100644 --- a/src/yaz-client.cpp +++ b/src/yaz-client.cpp @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-client.cpp,v $ - * Revision 1.6 1999-04-20 10:30:05 adam + * Revision 1.7 1999-04-21 12:09:01 adam + * Many improvements. Modified to proxy server to work with "sessions" + * based on cookies. + * + * Revision 1.6 1999/04/20 10:30:05 adam * Implemented various stuff for client and proxy. Updated calls * to ODR to reflect new name parameter. * @@ -76,6 +80,7 @@ public: int cmd_find(char *args); int cmd_show(char *args); int cmd_cookie(char *args); + int cmd_init(char *args); }; IYaz_PDU_Observer *MyClient::clone(IYaz_PDU_Observable *the_PDU_Observable) @@ -302,7 +307,7 @@ void MyClient::recv_record(Z_DatabaseRecord *record, int offset, else { printf("Unknown record representation.\n"); - if (!z_External(odr_print(), &r, 0)) + if (!z_External(odr_print(), &r, 0, 0)) { odr_perror(odr_print(), "Printing external"); odr_reset(odr_print()); @@ -322,7 +327,11 @@ void MyClient::recv_namePlusRecord (Z_NamePlusRecord *zpr, int offset) void MyClient::recv_records (Z_Records *records) { +#ifdef ASN_COMPILED Z_DiagRec dr, *dr_p = &dr; +#endif + if (!records) + return; int i; switch (records->which) { @@ -358,8 +367,7 @@ void MyClient::recv_searchResponse(Z_SearchResponse *searchResponse) } printf ("Ok\n"); printf ("Hits: %d\n", *searchResponse->resultCount); - if (searchResponse->records) - recv_records (searchResponse->records); + recv_records (searchResponse->records); } void MyClient::recv_presentResponse(Z_PresentResponse *presentResponse) @@ -384,6 +392,12 @@ int MyClient::wait() int MyClient::cmd_open(char *host) { client (host); + m_socketManager->processEvent(); + return 1; +} + +int MyClient::cmd_init(char *args) +{ if (send_initRequest() >= 0) wait(); else @@ -421,6 +435,7 @@ int MyClient::cmd_show(char *args) int start = m_setOffset, number = 1; sscanf (args, "%d %d", &start, &number); + m_setOffset = start; if (send_presentRequest(start, number) >= 0) wait(); return 1; @@ -428,7 +443,7 @@ int MyClient::cmd_show(char *args) int MyClient::cmd_cookie(char *args) { - set_cookie(args); + set_cookie(*args ? args : 0); return 1; } @@ -448,6 +463,7 @@ int MyClient::processCommand(const char *commandLine) {"find", &cmd_find, ""}, {"show", &cmd_show, "[ []]"}, {"cookie", &cmd_cookie, ""}, + {"init", &cmd_init, ""}, {0,0,0} }; diff --git a/src/yaz-ir-assoc.cpp b/src/yaz-ir-assoc.cpp index ad24cb2..a88888d 100644 --- a/src/yaz-ir-assoc.cpp +++ b/src/yaz-ir-assoc.cpp @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-ir-assoc.cpp,v $ - * Revision 1.6 1999-04-20 10:30:05 adam + * Revision 1.7 1999-04-21 12:09:01 adam + * Many improvements. Modified to proxy server to work with "sessions" + * based on cookies. + * + * Revision 1.6 1999/04/20 10:30:05 adam * Implemented various stuff for client and proxy. Updated calls * to ODR to reflect new name parameter. * @@ -153,33 +157,6 @@ void Yaz_IR_Assoc::get_elementSetName (const char **elementSetName) *elementSetName = m_elementSetNames->u.generic; } -void Yaz_IR_Assoc::set_otherInformationString ( - Z_OtherInformation **otherInformation, - int oidval, int categoryValue, - const char *str) -{ - int oid[OID_SIZE]; - struct oident ent; - ent.proto = PROTO_Z3950; - ent.oclass = CLASS_USERINFO; - ent.value = (oid_value) oidval; - if (!oid_ent_to_oid (&ent, oid)) - return ; - set_otherInformationString(otherInformation, oid, categoryValue, str); -} - -void Yaz_IR_Assoc::set_otherInformationString ( - Z_OtherInformation **otherInformation, - int *oid, int categoryValue, - const char *str) -{ - Z_OtherInformationUnit *oi = - update_otherInformation(otherInformation, 1, oid, categoryValue); - if (!oi) - return; - oi->information.characterInfo = odr_strdup (odr_encode(), str); -} - void Yaz_IR_Assoc::recv_Z_PDU(Z_APDU *apdu) { logf (LOG_LOG, "recv_Z_PDU"); @@ -237,7 +214,10 @@ int Yaz_IR_Assoc::send_searchRequest(Yaz_Z_Query *query) logf (LOG_LOG, "send_searchRequest"); assert (req->otherInfo == 0); if (m_cookie) + { set_otherInformationString(&req->otherInfo, VAL_COOKIE, 1, m_cookie); + assert (req->otherInfo); + } return send_Z_PDU(apdu); } @@ -277,16 +257,24 @@ int Yaz_IR_Assoc::send_presentRequest(int start, int number) void Yaz_IR_Assoc::set_proxy(const char *str) { - delete m_proxy; - m_proxy = new char[strlen(str)+1]; - strcpy (m_proxy, str); + delete [] m_proxy; + m_proxy = 0; + if (str) + { + m_proxy = new char[strlen(str)+1]; + strcpy (m_proxy, str); + } } void Yaz_IR_Assoc::set_cookie(const char *str) { - delete m_cookie; - m_cookie = new char[strlen(str)+1]; - strcpy(m_cookie, str); + delete [] m_cookie; + m_cookie = 0; + if (str) + { + m_cookie = new char[strlen(str)+1]; + strcpy(m_cookie, str); + } } const char *Yaz_IR_Assoc::get_cookie() diff --git a/src/yaz-pdu-assoc.cpp b/src/yaz-pdu-assoc.cpp index 7937e59..744e793 100644 --- a/src/yaz-pdu-assoc.cpp +++ b/src/yaz-pdu-assoc.cpp @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-pdu-assoc.cpp,v $ - * Revision 1.6 1999-04-20 10:30:05 adam + * Revision 1.7 1999-04-21 12:09:01 adam + * Many improvements. Modified to proxy server to work with "sessions" + * based on cookies. + * + * Revision 1.6 1999/04/20 10:30:05 adam * Implemented various stuff for client and proxy. Updated calls * to ODR to reflect new name parameter. * @@ -116,8 +120,8 @@ void Yaz_PDU_Assoc::socketNotify(int event) assoc->m_socketObservable->maskObserver(assoc, YAZ_SOCKET_OBSERVE_READ| YAZ_SOCKET_OBSERVE_EXCEPT); - if (m_idleTime) - assoc->m_socketObservable->timeoutObserver(assoc, m_idleTime); + assoc->m_socketObservable->timeoutObserver(assoc, + assoc->m_idleTime); } } else if (m_state == Ready) @@ -271,7 +275,7 @@ int Yaz_PDU_Assoc::send_PDU(const char *buf, int len) if (!m_cs) { logf (LOG_LOG, "Yaz_PDU_Assoc::send_PDU failed, m_cs == 0"); - return 0; + return -1; } while (*pq) pq = &(*pq)->m_next; @@ -320,6 +324,8 @@ void Yaz_PDU_Assoc::listen(IYaz_PDU_Observer *observer, void Yaz_PDU_Assoc::idleTime(int idleTime) { m_idleTime = idleTime; + logf (LOG_LOG, "Yaz_PDU_Assoc::idleTime(%d)", idleTime); + m_socketObservable->timeoutObserver(this, m_idleTime); } void Yaz_PDU_Assoc::connect(IYaz_PDU_Observer *observer, diff --git a/src/yaz-proxy-main.cpp b/src/yaz-proxy-main.cpp index b7292fd..904f915 100644 --- a/src/yaz-proxy-main.cpp +++ b/src/yaz-proxy-main.cpp @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-proxy-main.cpp,v $ - * Revision 1.4 1999-04-09 11:46:57 adam + * Revision 1.5 1999-04-21 12:09:01 adam + * Many improvements. Modified to proxy server to work with "sessions" + * based on cookies. + * + * Revision 1.4 1999/04/09 11:46:57 adam * Added object Yaz_Z_Assoc. Much more functional client. * * Revision 1.3 1999/02/02 14:01:21 adam @@ -30,7 +34,7 @@ int main(int argc, char **argv) Yaz_SocketManager mySocketManager; Yaz_Proxy proxy(new Yaz_PDU_Assoc(&mySocketManager, 0)); - proxy.server(argc < 2 ? "@:9999" : argv[1]); + proxy.server(argc < 2 ? "@:9000" : argv[1]); while (mySocketManager.processEvent() > 0) ; return 0; diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 8360dbe..beff26c 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-proxy.cpp,v $ - * Revision 1.4 1999-04-20 10:30:05 adam + * Revision 1.5 1999-04-21 12:09:01 adam + * Many improvements. Modified to proxy server to work with "sessions" + * based on cookies. + * + * Revision 1.4 1999/04/20 10:30:05 adam * Implemented various stuff for client and proxy. Updated calls * to ODR to reflect new name parameter. * @@ -31,6 +35,10 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable) : { m_PDU_Observable = the_PDU_Observable; m_client = 0; + m_parent = 0; + m_clientPool = 0; + m_seqno = 1; + m_keepalive = 1; } Yaz_Proxy::~Yaz_Proxy() @@ -40,7 +48,10 @@ Yaz_Proxy::~Yaz_Proxy() IYaz_PDU_Observer *Yaz_Proxy::clone(IYaz_PDU_Observable *the_PDU_Observable) { - return new Yaz_Proxy(the_PDU_Observable); + Yaz_Proxy *new_proxy = new Yaz_Proxy(the_PDU_Observable); + new_proxy->m_parent = this; + new_proxy->timeout(120); + return new_proxy; } char *Yaz_Proxy::get_cookie(Z_OtherInformation **otherInfo) @@ -51,7 +62,9 @@ char *Yaz_Proxy::get_cookie(Z_OtherInformation **otherInfo) ent.proto = PROTO_Z3950; ent.oclass = CLASS_USERINFO; ent.value = (oid_value) VAL_COOKIE; - if (oid_ent_to_oid (&ent, oid) && + assert (oid_ent_to_oid (&ent, oid)); + + if (oid_ent_to_oid (&ent, oid) && (oi = update_otherInformation(otherInfo, 0, oid, 1)) && oi->which == Z_OtherInfo_characterInfo) return oi->information.characterInfo; @@ -73,30 +86,94 @@ char *Yaz_Proxy::get_proxy(Z_OtherInformation **otherInfo) return 0; } +Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu) +{ + assert (m_parent); + Yaz_Proxy *parent = m_parent; + Z_OtherInformation **oi; + Yaz_ProxyClient *c = m_client; + + get_otherInfoAPDU(apdu, &oi); + char *cookie = get_cookie(oi); + logf (LOG_LOG, "Yaz_Proxy::get_client cookie=%s", cookie ? cookie : + ""); + if (cookie) + { + for (c = parent->m_clientPool; c; c = c->m_next) + { + assert (c->m_prev); + assert (*c->m_prev == c); + if (!strcmp(cookie,c->m_cookie)) + { + logf (LOG_LOG, "Yaz_Proxy::get_client cached"); + break; + } + } + } + else if (!m_client) + { + logf (LOG_LOG, "Yaz_Proxy::get_client creating new"); + c = new Yaz_ProxyClient(m_PDU_Observable->clone()); + c->m_next = parent->m_clientPool; + if (c->m_next) + c->m_next->m_prev = &c->m_next; + parent->m_clientPool = c; + c->m_prev = &parent->m_clientPool; + + sprintf (c->m_cookie, "%d", parent->m_seqno); + (parent->m_seqno)++; + + if (apdu->which == Z_APDU_initRequest) + { + 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->timeout(600); + } + return c; +} + void Yaz_Proxy::recv_Z_PDU(Z_APDU *apdu) { - if (apdu->which == Z_APDU_initRequest) + logf (LOG_LOG, "Yaz_Proxy::recv_Z_PDU"); + // Determine our client. + m_client = get_client(apdu); + if (!m_client) { - assert (m_client == 0); - logf (LOG_LOG, "got InitRequest"); - m_client = new Yaz_ProxyClient(m_PDU_Observable->clone()); - m_client->m_server = this; - - char *proxy_host = get_cookie(&apdu->u.initRequest->otherInfo); - if (proxy_host) - m_client->client(proxy_host); - else - m_client->client("localhost:8888"); + delete this; + return; + } + m_client->m_server = this; + + Z_OtherInformation **oi; + get_otherInfoAPDU(apdu, &oi); + *oi = 0; + logf (LOG_LOG, "Yaz_ProxyClient::send_Z_PDU"); + if (m_client->send_Z_PDU(apdu) < 0) + { + delete m_client; + delete this; } - assert (m_client); - logf (LOG_LOG, "sending PDU"); - m_client->send_Z_PDU(apdu); } void Yaz_Proxy::failNotify() { logf (LOG_LOG, "failNotity server"); - delete m_client; + if (m_keepalive) + { + // Tell client (if any) that not server connection is there.. + if (m_client) + m_client->m_server = 0; + } + else + { + delete m_client; + } delete this; } @@ -113,14 +190,42 @@ IYaz_PDU_Observer *Yaz_ProxyClient::clone(IYaz_PDU_Observable return new Yaz_ProxyClient(the_PDU_Observable); } +Yaz_ProxyClient::~Yaz_ProxyClient() +{ + if (m_prev) + { + *m_prev = m_next; + if (m_next) + m_next->m_prev = m_prev; + } +} + +void Yaz_Proxy::timeoutNotify() +{ + failNotify(); +} + +void Yaz_ProxyClient::timeoutNotify() +{ + failNotify(); +} + Yaz_ProxyClient::Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable) : Yaz_Z_Assoc (the_PDU_Observable) { - m_cookie = 0; + m_cookie[0] = 0; m_next = 0; + m_prev = 0; } void Yaz_ProxyClient::recv_Z_PDU(Z_APDU *apdu) { - m_server->send_Z_PDU(apdu); + logf (LOG_LOG, "Yaz_ProxyClient::recv_Z_PDU"); + if (m_cookie) + set_otherInformationString (apdu, VAL_COOKIE, 1, m_cookie); + if (m_server) + { + logf (LOG_LOG, "Yaz_Proxy::send_Z_PDU"); + m_server->send_Z_PDU(apdu); + } } diff --git a/src/yaz-server.cpp b/src/yaz-server.cpp index 2d2c244..ec6133d 100644 --- a/src/yaz-server.cpp +++ b/src/yaz-server.cpp @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-server.cpp,v $ - * Revision 1.5 1999-04-09 11:46:57 adam + * Revision 1.6 1999-04-21 12:09:01 adam + * Many improvements. Modified to proxy server to work with "sessions" + * based on cookies. + * + * Revision 1.5 1999/04/09 11:46:57 adam * Added object Yaz_Z_Assoc. Much more functional client. * * Revision 1.4 1999/03/23 14:17:57 adam @@ -59,16 +63,19 @@ void MyServer::recv_Z_PDU(Z_APDU *apdu) logf (LOG_LOG, "got presentRequest"); apdu = create_Z_PDU(Z_APDU_presentResponse); send_Z_PDU(apdu); - stop = 1; + // stop = 1; break; } } IYaz_PDU_Observer *MyServer::clone(IYaz_PDU_Observable *the_PDU_Observable) { + MyServer *new_server; logf (LOG_LOG, "child no %d", m_no); m_no++; - return new MyServer(the_PDU_Observable); + new_server = new MyServer(the_PDU_Observable); + new_server->timeout(60); + return new_server; } MyServer::MyServer(IYaz_PDU_Observable *the_PDU_Observable) : @@ -94,9 +101,8 @@ int main(int argc, char **argv) Yaz_SocketManager mySocketManager; Yaz_PDU_Assoc *my_PDU_Assoc = new Yaz_PDU_Assoc(&mySocketManager, 0); - my_PDU_Assoc->idleTime(20); MyServer z(my_PDU_Assoc); - + if (argc <= 1) z.server("@:9999"); else diff --git a/src/yaz-socket-manager.cpp b/src/yaz-socket-manager.cpp index 43d90ca..7988dca 100644 --- a/src/yaz-socket-manager.cpp +++ b/src/yaz-socket-manager.cpp @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-socket-manager.cpp,v $ - * Revision 1.5 1999-04-09 11:46:57 adam + * Revision 1.6 1999-04-21 12:09:01 adam + * Many improvements. Modified to proxy server to work with "sessions" + * based on cookies. + * + * Revision 1.5 1999/04/09 11:46:57 adam * Added object Yaz_Z_Assoc. Much more functional client. * * Revision 1.4 1999/03/23 14:17:57 adam @@ -167,7 +171,8 @@ int Yaz_SocketManager::processEvent() struct timeval to; to.tv_sec = timeout; to.tv_usec = 0; - + + logf (LOG_LOG, "timeout=%d", timeout); while ((res = select(max + 1, &in, &out, &except, timeout ? &to : 0)) < 0) if (errno != EINTR) return -1; diff --git a/src/yaz-z-assoc.cpp b/src/yaz-z-assoc.cpp index 4d16b08..c9b4307 100644 --- a/src/yaz-z-assoc.cpp +++ b/src/yaz-z-assoc.cpp @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-z-assoc.cpp,v $ - * Revision 1.2 1999-04-20 10:30:05 adam + * Revision 1.3 1999-04-21 12:09:01 adam + * Many improvements. Modified to proxy server to work with "sessions" + * based on cookies. + * + * Revision 1.2 1999/04/20 10:30:05 adam * Implemented various stuff for client and proxy. Updated calls * to ODR to reflect new name parameter. * @@ -50,12 +54,23 @@ void Yaz_Z_Assoc::recv_PDU(const char *buf, int len) logf (LOG_LOG, "recv_PDU len=%d", len); Z_APDU *apdu = decode_Z_PDU (buf, len); if (apdu) + { recv_Z_PDU (apdu); + } } Z_APDU *Yaz_Z_Assoc::create_Z_PDU(int type) { - return zget_APDU(m_odr_out, type); + Z_APDU *apdu = zget_APDU(m_odr_out, type); + if (apdu->which == Z_APDU_initRequest) + { + Z_InitRequest * p = apdu->u.initRequest; + char *newName = (char*) odr_malloc(m_odr_out, 50); + strcpy (newName, p->implementationName); + strcat (newName, " YAZ++"); + p->implementationName = newName; + } + return apdu; } int Yaz_Z_Assoc::send_Z_PDU(Z_APDU *apdu) @@ -86,7 +101,7 @@ Z_APDU *Yaz_Z_Assoc::decode_Z_PDU(const char *buf, int len) } else { - logf (LOG_LOG, "decoded ok"); + z_APDU(m_odr_print, &apdu, 0, "decode"); return apdu; } } @@ -98,6 +113,7 @@ int Yaz_Z_Assoc::encode_Z_PDU(Z_APDU *apdu, char **buf, int *len) logf (LOG_LOG, "yaz_Z_Assoc::encode_Z_PDU failed"); return -1; } + z_APDU(m_odr_print, &apdu, 0, "encode"); *buf = odr_getbuf (m_odr_out, len, 0); odr_reset (m_odr_out); return *len; @@ -147,6 +163,90 @@ ODR Yaz_Z_Assoc::odr_print() return m_odr_print; } +void Yaz_Z_Assoc::timeout(int timeout) +{ + m_PDU_Observable->idleTime(timeout); +} + +void Yaz_Z_Assoc::get_otherInfoAPDU(Z_APDU *apdu, Z_OtherInformation ***oip) +{ + switch (apdu->which) + { + case Z_APDU_initRequest: + *oip = &apdu->u.initRequest->otherInfo; + break; + case Z_APDU_searchRequest: + *oip = &apdu->u.searchRequest->otherInfo; + break; + case Z_APDU_presentRequest: + *oip = &apdu->u.presentRequest->otherInfo; + break; + case Z_APDU_sortRequest: + *oip = &apdu->u.sortRequest->otherInfo; + break; + case Z_APDU_scanRequest: + *oip = &apdu->u.scanRequest->otherInfo; + break; + case Z_APDU_initResponse: + *oip = &apdu->u.initResponse->otherInfo; + break; + case Z_APDU_searchResponse: + *oip = &apdu->u.searchResponse->otherInfo; + break; + case Z_APDU_presentResponse: + *oip = &apdu->u.presentResponse->otherInfo; + break; + case Z_APDU_sortResponse: + *oip = &apdu->u.sortResponse->otherInfo; + break; + case Z_APDU_scanResponse: + *oip = &apdu->u.scanResponse->otherInfo; + break; + default: + *oip = 0; + break; + } +} + +void Yaz_Z_Assoc::set_otherInformationString ( + Z_APDU *apdu, + int oidval, int categoryValue, + const char *str) +{ + Z_OtherInformation **otherInformation; + get_otherInfoAPDU(apdu, &otherInformation); + if (!otherInformation) + return; + set_otherInformationString(otherInformation, oidval, categoryValue, str); +} + +void Yaz_Z_Assoc::set_otherInformationString ( + Z_OtherInformation **otherInformation, + int oidval, int categoryValue, + const char *str) +{ + int oid[OID_SIZE]; + struct oident ent; + ent.proto = PROTO_Z3950; + ent.oclass = CLASS_USERINFO; + ent.value = (oid_value) oidval; + if (!oid_ent_to_oid (&ent, oid)) + return ; + set_otherInformationString(otherInformation, oid, categoryValue, str); +} + +void Yaz_Z_Assoc::set_otherInformationString ( + Z_OtherInformation **otherInformation, + int *oid, int categoryValue, + const char *str) +{ + Z_OtherInformationUnit *oi = + update_otherInformation(otherInformation, 1, oid, categoryValue); + if (!oi) + return; + oi->information.characterInfo = odr_strdup (odr_encode(), str); +} + Z_OtherInformationUnit *Yaz_Z_Assoc::update_otherInformation ( Z_OtherInformation **otherInformationP, int createFlag, int *oid, int categoryValue) @@ -165,6 +265,8 @@ Z_OtherInformationUnit *Yaz_Z_Assoc::update_otherInformation ( for (i = 0; i<8; i++) otherInformation->list[i] = 0; } + logf (LOG_LOG, "Yaz_Z_Assoc::update_otherInformation num=%d", + otherInformation->num_elements); for (i = 0; inum_elements; i++) { assert (otherInformation->list[i]); diff --git a/src/yaz-z-query.cpp b/src/yaz-z-query.cpp index 895fbb0..16c3fb4 100644 --- a/src/yaz-z-query.cpp +++ b/src/yaz-z-query.cpp @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-z-query.cpp,v $ - * Revision 1.3 1999-04-20 10:30:05 adam + * Revision 1.4 1999-04-21 12:09:01 adam + * Many improvements. Modified to proxy server to work with "sessions" + * based on cookies. + * + * Revision 1.3 1999/04/20 10:30:05 adam * Implemented various stuff for client and proxy. Updated calls * to ODR to reflect new name parameter. * @@ -23,6 +27,7 @@ Yaz_Z_Query::Yaz_Z_Query() { odr_encode = odr_createmem (ODR_ENCODE); odr_decode = odr_createmem (ODR_DECODE); + odr_print = odr_createmem (ODR_PRINT); } int Yaz_Z_Query::set_rpn (const char *rpn) @@ -36,6 +41,7 @@ int Yaz_Z_Query::set_rpn (const char *rpn) return -1; if (!z_Query (odr_encode, &query, 0, 0)) return -1; + z_Query(odr_print, &query, 0, 0); buf = odr_getbuf (odr_encode, &len, 0); return len; } @@ -53,6 +59,7 @@ Yaz_Z_Query::~Yaz_Z_Query() { odr_destroy (odr_encode); odr_destroy (odr_decode); + odr_destroy (odr_print); } Z_Query *Yaz_Z_Query::get_Z_Query () -- 1.7.10.4