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