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