2 * Copyright (c) 1998-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: yaz-proxy-main.cpp,v 1.24 2003-10-23 13:00:35 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;
29 static char *log_file = 0;
31 int args(Yaz_Proxy *proxy, int argc, char **argv)
38 while ((ret = options("o:a:t:v:c:u:i:m:l:T:p:U:", argv, argc, &arg)) != -2)
52 err = proxy->set_config(arg);
55 fprintf(stderr, "Config file support not enabled (proxy not compiled with libxml2 support)\n");
60 fprintf(stderr, "Bad or missing file %s\n", arg);
65 proxy->set_APDU_log(arg);
68 proxy->set_default_target(arg);
71 proxy->set_proxy_authentication(arg);
74 proxy->option("optimize", arg);
77 yaz_log_init_level (yaz_log_mask_str(arg));
80 yaz_log_init_file (arg);
81 log_file = xstrdup(arg);
84 proxy->set_max_clients(atoi(arg));
87 proxy->set_client_idletime(atoi(arg));
90 proxy->set_target_idletime(atoi(arg));
94 pid_fname = xstrdup(arg);
107 if (proxy->server(addr))
109 yaz_log(LOG_FATAL|LOG_ERRNO, "listen %s", addr);
121 static Yaz_Proxy *static_yaz_proxy = 0;
122 static void sighup_handler(int num)
124 signal(SIGHUP, sighup_handler);
125 if (static_yaz_proxy)
126 static_yaz_proxy->reconfig();
129 int main(int argc, char **argv)
131 static int mk_pid = 0;
132 Yaz_SocketManager mySocketManager;
133 Yaz_Proxy proxy(new Yaz_PDU_Assoc(&mySocketManager));
135 static_yaz_proxy = &proxy;
137 signal(SIGHUP, sighup_handler);
139 args(&proxy, argc, argv);
143 FILE *f = fopen(pid_fname, "w");
146 yaz_log(LOG_ERRNO|LOG_FATAL, "Couldn't create %s", pid_fname);
149 fprintf(f, "%ld", (long) getpid());
157 if (!(pw = getpwnam(uid)))
159 yaz_log(LOG_FATAL, "%s: Unknown user", uid);
164 chown(log_file, pw->pw_uid, pw->pw_gid);
168 if (setuid(pw->pw_uid) < 0)
170 yaz_log(LOG_FATAL|LOG_ERRNO, "setuid");
176 while (mySocketManager.processEvent() > 0)