main() in pazpar2.c . Rest of high-level logic moved to logic.c. Some
[pazpar2-moved-to-github.git] / src / pazpar2.c
1 /* $Id: pazpar2.c,v 1.79 2007-04-16 09:03:25 adam Exp $
2    Copyright (c) 2006-2007, Index Data.
3
4 This file is part of Pazpar2.
5
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #if HAVE_CONFIG_H
23 #include "cconfig.h"
24 #endif
25
26
27 #include <signal.h>
28
29 #include "pazpar2.h"
30 #include "database.h"
31 #include "settings.h"
32
33 int main(int argc, char **argv)
34 {
35     int ret;
36     char *arg;
37
38     if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
39         yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
40
41     yaz_log_init(YLOG_DEFAULT_LEVEL, "pazpar2", 0);
42
43     while ((ret = options("t:f:x:h:p:z:s:d", argv, argc, &arg)) != -2)
44     {
45         switch (ret) {
46             case 'f':
47                 if (!read_config(arg))
48                     exit(1);
49                 break;
50             case 'h':
51                 strcpy(global_parameters.listener_override, arg);
52                 break;
53             case 'p':
54                 strcpy(global_parameters.proxy_override, arg);
55                 break;
56             case 'z':
57                 strcpy(global_parameters.zproxy_override, arg);
58                 break;
59             case 't':
60                 strcpy(global_parameters.settings_path_override, arg);
61                 break;
62             case 's':
63                 load_simpletargets(arg);
64                 break;
65             case 'd':
66                 global_parameters.dump_records = 1;
67                 break;
68             default:
69                 fprintf(stderr, "Usage: pazpar2\n"
70                         "    -f configfile\n"
71                         "    -h [host:]port          (REST protocol listener)\n"
72                         "    -C cclconfig\n"
73                         "    -s simpletargetfile\n"
74                         "    -p hostname[:portno]    (HTTP proxy)\n"
75                         "    -z hostname[:portno]    (Z39.50 proxy)\n"
76                         "    -d                      (show internal records)\n");
77                 exit(1);
78         }
79     }
80
81     if (!config)
82     {
83         yaz_log(YLOG_FATAL, "Load config with -f");
84         exit(1);
85     }
86     global_parameters.server = config->servers;
87
88     start_http_listener();
89     start_proxy();
90     start_zproxy();
91
92     if (*global_parameters.settings_path_override)
93         settings_read(global_parameters.settings_path_override);
94     else if (global_parameters.server->settings)
95         settings_read(global_parameters.server->settings);
96     else
97         yaz_log(YLOG_WARN, "No settings-directory specified. Problems may well ensue!");
98     prepare_databases();
99     global_parameters.odr_in = odr_createmem(ODR_DECODE);
100     global_parameters.odr_out = odr_createmem(ODR_ENCODE);
101
102     event_loop(&channel_list);
103
104     return 0;
105 }
106
107 /*
108  * Local variables:
109  * c-basic-offset: 4
110  * indent-tabs-mode: nil
111  * End:
112  * vim: shiftwidth=4 tabstop=8 expandtab
113  */