X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fyaz-server.cpp;h=ccc5a4578e81f419cc2d9752ea0bc4172c1e83c0;hb=e7249fa8f8c707354b1a797d0bb7a5d5e1097182;hp=7d496c964b88d6090b93c15859b57e2af63e8881;hpb=bf377ba45c8c1cbcf843fdecc6d5c68fda6bad18;p=yazpp-moved-to-github.git diff --git a/src/yaz-server.cpp b/src/yaz-server.cpp index 7d496c9..ccc5a45 100644 --- a/src/yaz-server.cpp +++ b/src/yaz-server.cpp @@ -1,72 +1,160 @@ /* - * Copyright (c) 1998-1999, Index Data. + * Copyright (c) 1998-2000, Index Data. * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-server.cpp,v $ - * Revision 1.1 1999-01-28 09:41:07 adam - * Initial revision + * Revision 1.10 2000-09-12 16:04:17 adam + * Added comstack method for Yaz_PDU_Assoc.. + * + * Revision 1.9 2000/09/12 12:09:53 adam + * More work on high-level server. + * + * Revision 1.8 2000/09/08 10:23:42 adam + * Added skeleton of yaz-z-server. + * + * Revision 1.7 1999/12/06 13:52:45 adam + * Modified for new location of YAZ header files. Experimental threaded + * operation. + * + * 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 + * More work on timeout handling. Work on yaz-client. + * + * Revision 1.3 1999/02/02 14:01:22 adam + * First WIN32 port of YAZ++. + * + * Revision 1.2 1999/01/28 13:08:47 adam + * Yaz_PDU_Assoc better encapsulated. Memory leak fix in + * yaz-socket-manager.cc. + * + * Revision 1.1.1.1 1999/01/28 09:41:07 adam + * First implementation of YAZ++. * */ -#include -#include +#include +#include #include #include -class MyServer : public Yaz_IR_Assoc { +class MyServer : public Yaz_Z_Server { public: MyServer(IYaz_PDU_Observable *the_PDU_Observable); - void recv_Z_PDU(Z_APDU *apdu); + void recv_Z_init (Z_InitRequest *initRequest, + Z_InitResponse *initResponse); + void recv_Z_search (Z_SearchRequest *searchRequest, + Z_SearchResponse *searchResponse); + void recv_Z_present (Z_PresentRequest *presentRequest, + Z_PresentResponse *presentResponse); + + void recv_Z_record (const char *resultSetName, + int position, + int *format, + Z_RecordComposition *comp, + Z_NamePlusRecord *namePlusRecord, + Z_DefaultDiagFormat *diagnostics); IYaz_PDU_Observer* clone(IYaz_PDU_Observable *the_PDU_Observable); + void failNotify(); + void timeoutNotify(); + void connectNotify(); +private: + int m_no; }; static int stop = 0; -void MyServer::recv_Z_PDU(Z_APDU *apdu) +void MyServer::recv_Z_init (Z_InitRequest *initRequest, + Z_InitResponse *initResponse) { - logf (LOG_LOG, "recv_Z_PDU"); - switch (apdu->which) - { - case Z_APDU_initRequest: - logf (LOG_LOG, "got InitRequest"); - apdu = create_Z_PDU(Z_APDU_initResponse); - send_Z_PDU(apdu); - break; - case Z_APDU_searchRequest: - logf (LOG_LOG, "got searchRequest"); - apdu = create_Z_PDU(Z_APDU_searchResponse); - send_Z_PDU(apdu); - break; - case Z_APDU_presentRequest: - logf (LOG_LOG, "got presentRequest"); - apdu = create_Z_PDU(Z_APDU_presentResponse); - send_Z_PDU(apdu); - stop = 1; - break; - } + logf (LOG_LOG, "MyServer::recv_Z_init"); +} + +void MyServer::recv_Z_search (Z_SearchRequest *searchRequest, + Z_SearchResponse *searchResponse) +{ + logf (LOG_LOG, "MyServer::recv_Z_search"); + delete this; + stop = 1; +} + +void MyServer::recv_Z_present (Z_PresentRequest *presentRequest, + Z_PresentResponse *presentResponse) +{ + logf (LOG_LOG, "MyServer::recv_Z_present"); +} + +void MyServer::recv_Z_record (const char *resultSetName, + int position, + int *format, + Z_RecordComposition *comp, + Z_NamePlusRecord *namePlusRecord, + Z_DefaultDiagFormat *diagnostics) +{ + } IYaz_PDU_Observer *MyServer::clone(IYaz_PDU_Observable *the_PDU_Observable) { - return new MyServer(the_PDU_Observable); + MyServer *new_server; + logf (LOG_LOG, "child no %d", m_no); + m_no++; + new_server = new MyServer(the_PDU_Observable); + new_server->timeout(60); + return new_server; } MyServer::MyServer(IYaz_PDU_Observable *the_PDU_Observable) : - Yaz_IR_Assoc (the_PDU_Observable) + Yaz_Z_Server (the_PDU_Observable) { - + m_no = 0; } -int main(int argc, char **argv) +void MyServer::timeoutNotify() { - Yaz_SocketManager mySocketManager; + logf (LOG_LOG, "connection timed out"); + delete this; +} - Yaz_PDU_Assoc my_PDU_Assoc(&mySocketManager, 0); - MyServer z(&my_PDU_Assoc); +void MyServer::failNotify() +{ + logf (LOG_LOG, "connection closed by client"); + delete this; +} - z.server("@:9999"); +void MyServer::connectNotify() +{ +} - while (!stop && mySocketManager.processEvent() > 0) - ; +int main(int argc, char **argv) +{ + while (1) + { + stop = 0; + Yaz_SocketManager mySocketManager; + Yaz_PDU_Assoc *my_PDU_Assoc = new Yaz_PDU_Assoc(&mySocketManager); + + MyServer *z = new MyServer(my_PDU_Assoc); + + if (argc <= 1) + z->server("@:9999"); + else + { + for (int i = 1; i < argc; i++) + z->server(argv[i]); + } + COMSTACK cs = my_PDU_Assoc->comstack(); + if (cs) + printf ("fd=%d\n", cs_fileno(cs)); + while (!stop && mySocketManager.processEvent() > 0) + ; + logf (LOG_LOG, "bailing out"); + delete z; + } + return 0; }