Working on UrsulaRenewal, Request, and Update
[yazpp-moved-to-github.git] / src / yaz-proxy-main.cpp
1 /*
2  * Copyright (c) 1998-2001, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Log: yaz-proxy-main.cpp,v $
6  * Revision 1.13  2001-04-10 10:48:08  adam
7  * Fixed problem where proxy could cash bad result sets.
8  *
9  * Revision 1.12  2000/10/11 11:58:16  adam
10  * Moved header files to include/yaz++. Switched to libtool and automake.
11  * Configure script creates yaz++-config script.
12  *
13  * Revision 1.11  2000/09/08 10:23:42  adam
14  * Added skeleton of yaz-z-server.
15  *
16  * Revision 1.10  2000/09/04 08:59:16  adam
17  * Changed call to logging functions (yaz_ added).
18  *
19  * Revision 1.9  2000/08/07 14:19:59  adam
20  * Fixed serious bug regarding timeouts. Improved logging for proxy.
21  *
22  * Revision 1.8  2000/07/04 13:48:49  adam
23  * Implemented upper-limit on proxy-to-target sessions.
24  *
25  * Revision 1.7  1999/12/06 13:52:45  adam
26  * Modified for new location of YAZ header files. Experimental threaded
27  * operation.
28  *
29  * Revision 1.6  1999/11/10 10:02:34  adam
30  * Work on proxy.
31  *
32  * Revision 1.5  1999/04/21 12:09:01  adam
33  * Many improvements. Modified to proxy server to work with "sessions"
34  * based on cookies.
35  *
36  * Revision 1.4  1999/04/09 11:46:57  adam
37  * Added object Yaz_Z_Assoc. Much more functional client.
38  *
39  * Revision 1.3  1999/02/02 14:01:21  adam
40  * First WIN32 port of YAZ++.
41  *
42  * Revision 1.2  1999/01/28 13:08:45  adam
43  * Yaz_PDU_Assoc better encapsulated. Memory leak fix in
44  * yaz-socket-manager.cc.
45  *
46  * Revision 1.1.1.1  1999/01/28 09:41:07  adam
47  * First implementation of YAZ++.
48  *
49  */
50
51 #include <yaz/log.h>
52 #include <yaz/options.h>
53
54 #include <yaz++/yaz-socket-manager.h>
55 #include <yaz++/yaz-pdu-assoc.h>
56 #include <yaz++/yaz-proxy.h>
57
58 void usage(char *prog)
59 {
60     fprintf (stderr, "%s: [-a log] [-c num] [-v level] [-t target] @:port\n", prog);
61     exit (1);
62 }
63
64
65 int args(Yaz_Proxy *proxy, int argc, char **argv)
66 {
67     char *addr = 0;
68     char *arg;
69     char *prog = argv[0];
70     int ret;
71
72     while ((ret = options("a:t:v:c:", argv, argc, &arg)) != -2)
73     {
74         switch (ret)
75         {
76         case 0:
77             if (addr)
78             {
79                 usage(prog);
80                 return 1;
81             }
82             addr = arg;
83             break;
84         case 'a':
85             proxy->set_APDU_log(arg);
86             break;
87         case 't':
88             proxy->set_proxyTarget(arg);
89             break;
90         case 'v':
91             yaz_log_init_level (yaz_log_mask_str(arg));
92             break;
93         case 'c':
94             proxy->set_max_clients(atoi(arg));
95             break;
96         default:
97             usage(prog);
98             return 1;
99         }
100     }
101     if (addr)
102     {
103         proxy->server(addr);
104     }
105     else
106     {
107         usage(prog);
108         return 1;
109     }
110     return 0;
111 }
112
113 int main(int argc, char **argv)
114 {
115     Yaz_SocketManager mySocketManager;
116     Yaz_Proxy proxy(new Yaz_PDU_Assoc(&mySocketManager));
117
118     args(&proxy, argc, argv);
119     while (mySocketManager.processEvent() > 0)
120         ;
121     exit (0);
122     return 0;
123 }