2 * Copyright (c) 1998-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: yaz-proxy-main.cpp,v 1.22 2003-10-23 11:45:08 adam Exp $
11 #include <sys/types.h>
14 #include <yaz/options.h>
16 #include <yaz++/socket-manager.h>
17 #include <yaz++/pdu-assoc.h>
18 #include <yaz++/proxy.h>
20 void usage(char *prog)
22 fprintf (stderr, "%s: [-c config] [-a log] [-m num] [-v level] [-t target] [-i sec] "
23 "[-u uid] [-p pidfile] [-o optlevel] @:port\n", prog);
27 static char *pid_fname = 0;
30 int args(Yaz_Proxy *proxy, int argc, char **argv)
37 while ((ret = options("o:a:t:v:c:u:i:m:l:T:p:U:", argv, argc, &arg)) != -2)
51 err = proxy->set_config(arg);
54 fprintf(stderr, "Config file support not enabled (proxy not compiled with libxml2 support)\n");
59 fprintf(stderr, "Bad or missing file %s\n", arg);
64 proxy->set_APDU_log(arg);
67 proxy->set_default_target(arg);
70 proxy->set_proxy_authentication(arg);
73 proxy->option("optimize", arg);
76 yaz_log_init_level (yaz_log_mask_str(arg));
79 yaz_log_init_file (arg);
82 proxy->set_max_clients(atoi(arg));
85 proxy->set_client_idletime(atoi(arg));
88 proxy->set_target_idletime(atoi(arg));
92 pid_fname = xstrdup(arg);
105 if (proxy->server(addr))
107 yaz_log(LOG_FATAL|LOG_ERRNO, "listen %s", addr);
119 static Yaz_Proxy *static_yaz_proxy = 0;
120 static void sighup_handler(int num)
122 if (static_yaz_proxy)
123 static_yaz_proxy->reconfig();
126 int main(int argc, char **argv)
128 static int mk_pid = 0;
129 Yaz_SocketManager mySocketManager;
130 Yaz_Proxy proxy(new Yaz_PDU_Assoc(&mySocketManager));
132 static_yaz_proxy = &proxy;
134 signal(SIGHUP, sighup_handler);
136 args(&proxy, argc, argv);
140 FILE *f = fopen(pid_fname, "w");
143 yaz_log(LOG_ERRNO|LOG_FATAL, "Couldn't create %s", pid_fname);
146 fprintf(f, "%ld", (long) getpid());
154 if (!(pw = getpwnam(uid)))
156 yaz_log(LOG_FATAL, "%s: Unknown user", uid);
159 if (setuid(pw->pw_uid) < 0)
161 yaz_log(LOG_FATAL|LOG_ERRNO, "setuid");
167 while (mySocketManager.processEvent() > 0)