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