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