Per-session databases and configuration. This was implemented
[pazpar2-moved-to-github.git] / src / pazpar2.c
1 /* $Id: pazpar2.c,v 1.82 2007-04-22 15:07:10 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 'd':
63                 global_parameters.dump_records = 1;
64                 break;
65             default:
66                 fprintf(stderr, "Usage: pazpar2\n"
67                         "    -f configfile\n"
68                         "    -h [host:]port          (REST protocol listener)\n"
69                         "    -C cclconfig\n"
70                         "    -s simpletargetfile\n"
71                         "    -p hostname[:portno]    (HTTP proxy)\n"
72                         "    -z hostname[:portno]    (Z39.50 proxy)\n"
73                         "    -d                      (show internal records)\n");
74                 exit(1);
75         }
76     }
77
78     if (!config)
79     {
80         yaz_log(YLOG_FATAL, "Load config with -f");
81         exit(1);
82     }
83     global_parameters.server = config->servers;
84
85     start_http_listener();
86     start_proxy();
87     start_zproxy();
88     init_settings();
89
90     if (*global_parameters.settings_path_override)
91         settings_read(global_parameters.settings_path_override);
92     else if (global_parameters.server->settings)
93         settings_read(global_parameters.server->settings);
94     else
95         yaz_log(YLOG_WARN, "No settings-directory specified");
96     global_parameters.odr_in = odr_createmem(ODR_DECODE);
97     global_parameters.odr_out = odr_createmem(ODR_ENCODE);
98
99     pazpar2_event_loop();
100
101     return 0;
102 }
103
104 /*
105  * Local variables:
106  * c-basic-offset: 4
107  * indent-tabs-mode: nil
108  * End:
109  * vim: shiftwidth=4 tabstop=8 expandtab
110  */