New pazpar2 option -X which puts pazpar2 in debug (insecure) mode.
[pazpar2-moved-to-github.git] / src / pazpar2.c
1 /* $Id: pazpar2.c,v 1.85 2007-05-23 21:58:28 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 #include <assert.h>
29
30 #include "pazpar2.h"
31 #include "database.h"
32 #include "settings.h"
33
34 int main(int argc, char **argv)
35 {
36     int ret;
37     char *arg;
38
39     if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
40         yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
41
42     yaz_log_init_prefix("pazpar2");
43
44     while ((ret = options("f:h:p:z:t:l:dX", argv, argc, &arg)) != -2)
45     {
46         switch (ret)
47         {
48         case 'f':
49             if (!read_config(arg))
50                 exit(1);
51             break;
52         case 'h':
53             strcpy(global_parameters.listener_override, arg);
54             break;
55         case 'p':
56             strcpy(global_parameters.proxy_override, arg);
57             break;
58         case 'z':
59             strcpy(global_parameters.zproxy_override, arg);
60             break;
61         case 't':
62             strcpy(global_parameters.settings_path_override, arg);
63              break;
64         case 'd':
65             global_parameters.dump_records = 1;
66             break;
67         case 'l':
68             yaz_log_init_file(arg);
69             break;
70         case 'X':
71             global_parameters.debug_mode = 1;
72             break;
73         default:
74             fprintf(stderr, "Usage: pazpar2\n"
75                     "    -f configfile\n"
76                     "    -h [host:]port          (REST protocol listener)\n"
77                     "    -p hostname[:portno]    (HTTP proxy)\n"
78                     "    -z hostname[:portno]    (Z39.50 proxy)\n"
79                     "    -t settings\n"
80                     "    -d                      (show internal records)\n"
81                     "    -l file                 log to file\n"
82                     "    -X                      debug mode\n"
83                 );
84             exit(1);
85         }
86     }
87
88     if (!config)
89     {
90         yaz_log(YLOG_FATAL, "Load config with -f");
91         exit(1);
92     }
93     global_parameters.server = config->servers;
94
95     start_http_listener();
96     start_proxy();
97     start_zproxy();
98     init_settings();
99
100     if (*global_parameters.settings_path_override)
101         settings_read(global_parameters.settings_path_override);
102     else if (global_parameters.server->settings)
103         settings_read(global_parameters.server->settings);
104     else
105         yaz_log(YLOG_WARN, "No settings-directory specified");
106     global_parameters.odr_in = odr_createmem(ODR_DECODE);
107     global_parameters.odr_out = odr_createmem(ODR_ENCODE);
108
109     pazpar2_event_loop();
110
111     return 0;
112 }
113
114
115 /*
116  * Local variables:
117  * c-basic-offset: 4
118  * indent-tabs-mode: nil
119  * End:
120  * vim: shiftwidth=4 tabstop=8 expandtab
121  */