Proxy removes OtherInfo Proxy Address and Session ID. Other
[yazpp-moved-to-github.git] / src / yaz-server.cpp
1 /*
2  * Copyright (c) 1998-1999, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  * 
6  * $Log: yaz-server.cpp,v $
7  * Revision 1.6  1999-04-21 12:09:01  adam
8  * Many improvements. Modified to proxy server to work with "sessions"
9  * based on cookies.
10  *
11  * Revision 1.5  1999/04/09 11:46:57  adam
12  * Added object Yaz_Z_Assoc. Much more functional client.
13  *
14  * Revision 1.4  1999/03/23 14:17:57  adam
15  * More work on timeout handling. Work on yaz-client.
16  *
17  * Revision 1.3  1999/02/02 14:01:22  adam
18  * First WIN32 port of YAZ++.
19  *
20  * Revision 1.2  1999/01/28 13:08:47  adam
21  * Yaz_PDU_Assoc better encapsulated. Memory leak fix in
22  * yaz-socket-manager.cc.
23  *
24  * Revision 1.1.1.1  1999/01/28 09:41:07  adam
25  * First implementation of YAZ++.
26  *
27  */
28
29 #include <log.h>
30 #include <yaz-z-assoc.h>
31 #include <yaz-pdu-assoc.h>
32 #include <yaz-socket-manager.h>
33
34 class MyServer : public Yaz_Z_Assoc {
35 public:
36     MyServer(IYaz_PDU_Observable *the_PDU_Observable);
37     void recv_Z_PDU(Z_APDU *apdu);
38     IYaz_PDU_Observer* clone(IYaz_PDU_Observable *the_PDU_Observable);
39     void failNotify();
40     void timeoutNotify();
41 private:
42     int m_no;
43 };
44
45 static int stop = 0;
46
47 void MyServer::recv_Z_PDU(Z_APDU *apdu)
48 {
49     logf (LOG_LOG, "recv_Z_PDU");
50     switch (apdu->which)
51     {
52     case Z_APDU_initRequest:
53         logf (LOG_LOG, "got InitRequest");
54         apdu = create_Z_PDU(Z_APDU_initResponse);
55         send_Z_PDU(apdu);
56         break;
57     case Z_APDU_searchRequest:
58         logf (LOG_LOG, "got searchRequest");
59         apdu = create_Z_PDU(Z_APDU_searchResponse);
60         send_Z_PDU(apdu);
61         break;
62     case Z_APDU_presentRequest:
63         logf (LOG_LOG, "got presentRequest");
64         apdu = create_Z_PDU(Z_APDU_presentResponse);
65         send_Z_PDU(apdu);
66         // stop = 1;
67         break;
68     }
69 }
70
71 IYaz_PDU_Observer *MyServer::clone(IYaz_PDU_Observable *the_PDU_Observable)
72 {
73     MyServer *new_server;
74     logf (LOG_LOG, "child no %d", m_no);
75     m_no++;
76     new_server = new MyServer(the_PDU_Observable);
77     new_server->timeout(60);
78     return new_server;
79 }
80
81 MyServer::MyServer(IYaz_PDU_Observable *the_PDU_Observable) :
82     Yaz_Z_Assoc (the_PDU_Observable)
83 {
84     m_no = 0;
85 }
86
87 void MyServer::timeoutNotify()
88 {
89     logf (LOG_LOG, "connection timed out");
90     delete this;
91 }
92
93 void MyServer::failNotify()
94 {
95     logf (LOG_LOG, "connection closed by client");
96     delete this;
97 }
98
99 int main(int argc, char **argv)
100 {
101     Yaz_SocketManager mySocketManager;
102     Yaz_PDU_Assoc *my_PDU_Assoc = new Yaz_PDU_Assoc(&mySocketManager, 0);
103
104     MyServer z(my_PDU_Assoc);
105
106     if (argc <= 1)
107         z.server("@:9999");
108     else
109     {
110         for (int i = 1; i < argc; i++)
111             z.server(argv[i]);
112     }
113     while (!stop && mySocketManager.processEvent() > 0)
114         ;
115     return 0;
116 }