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