2 * Copyright (c) 1998-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: yaz-proxy-main.cpp,v 1.21 2003-10-23 09:08:52 adam Exp $
11 #include <yaz/options.h>
13 #include <yaz++/socket-manager.h>
14 #include <yaz++/pdu-assoc.h>
15 #include <yaz++/proxy.h>
17 void usage(char *prog)
19 fprintf (stderr, "%s: [-c config] [-a log] [-m num] [-v level] [-t target] [-i sec] "
20 "[-u auth] [-o optlevel] @:port\n", prog);
24 static char *pid_fname = 0;
26 int args(Yaz_Proxy *proxy, int argc, char **argv)
33 while ((ret = options("o:a:t:v:c:u:i:m:l:T:p:", argv, argc, &arg)) != -2)
47 err = proxy->set_config(arg);
50 fprintf(stderr, "Config file support not enabled (proxy not compiled with libxml2 support)\n");
55 fprintf(stderr, "Bad or missing file %s\n", arg);
60 proxy->set_APDU_log(arg);
63 proxy->set_default_target(arg);
66 proxy->set_proxy_authentication(arg);
69 proxy->option("optimize", arg);
72 yaz_log_init_level (yaz_log_mask_str(arg));
75 yaz_log_init_file (arg);
78 proxy->set_max_clients(atoi(arg));
81 proxy->set_client_idletime(atoi(arg));
84 proxy->set_target_idletime(atoi(arg));
88 pid_fname = xstrdup(arg);
107 static Yaz_Proxy *static_yaz_proxy = 0;
108 static void sighup_handler(int num)
110 if (static_yaz_proxy)
111 static_yaz_proxy->reconfig();
114 int main(int argc, char **argv)
116 static int mk_pid = 0;
117 Yaz_SocketManager mySocketManager;
118 Yaz_Proxy proxy(new Yaz_PDU_Assoc(&mySocketManager));
120 static_yaz_proxy = &proxy;
122 signal(SIGHUP, sighup_handler);
124 args(&proxy, argc, argv);
125 while (mySocketManager.processEvent() > 0)
126 if (!mk_pid && pid_fname)
128 FILE *f = fopen(pid_fname, "w");
131 yaz_log(LOG_ERRNO|LOG_FATAL, "Couldn't create %s", pid_fname);
134 fprintf(f, "%ld", (long) getpid());