chiark / gitweb /
Use libsamplerate in disorder-normalize, if available. If it's not
[disorder] / cgi / cgimain.c
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 /** @file cgi/cgimain.c
19  * @brief DisOrder CGI
20  */
21
22 #include "disorder-cgi.h"
23
24 int main(int argc, char **argv) {
25   const char *conf;
26
27   if(argc > 0)
28     progname = argv[0];
29   /* RFC 3875 s8.2 recommends rejecting PATH_INFO if we don't make use of
30    * it. */
31   /* TODO we could make disorder/ACTION equivalent to disorder?action=ACTION */
32   if(getenv("PATH_INFO")) {
33     /* TODO it might be nice to link back to the right place... */
34     printf("Content-Type: text/html; charset=UTF-8\n");
35     printf("Status: 404\n");
36     printf("\n");
37     printf("<p>Sorry, is PATH_INFO not supported."
38            "<a href=\"%s\">Try here instead.</a></p>\n",
39            cgi_sgmlquote(infer_url(0/*!include_path_info*/)));
40     exit(0);
41   }
42   /* Parse CGI arguments */
43   cgi_init();
44   /* We allow various things to be overridden from the environment.  This is
45    * intended for debugging and is not a documented feature. */
46   if((conf = getenv("DISORDER_CONFIG")))
47     configfile = xstrdup(conf);
48   if(getenv("DISORDER_DEBUG"))
49     debugging = 1;
50   /* Read configuration */
51   if(config_read(0/*!server*/, NULL))
52     exit(EXIT_FAILURE);
53   /* Figure out our URL.  This can still be overridden from the config file if
54    * necessary but it shouldn't be necessary in ordinary installations. */
55   if(!config->url)
56     config->url = infer_url(1/*include_path_info*/);
57   /* Pick up the cookie, if there is one */
58   dcgi_get_cookie();
59   /* Register expansions */
60   mx_register_builtin();
61   dcgi_expansions();
62   /* Update search path.  We look in the config directory first and the data
63    * directory second, so that the latter overrides the former. */
64   mx_search_path(pkgconfdir);
65   mx_search_path(pkgdatadir);
66   /* Never cache anythging */
67   if(printf("Cache-Control: no-cache\n") < 0)
68     disorder_fatal(errno, "error writing to stdout");
69   /* Create the initial connection, trying the cookie if we found a suitable
70    * one. */
71   dcgi_login();
72   /* Do whatever the user wanted */
73   dcgi_action(NULL);
74   /* In practice if a write fails that probably means the web server went away,
75    * but we log it anyway. */
76   if(fclose(stdout) < 0)
77     disorder_fatal(errno, "error closing stdout");
78   return 0;
79 }
80
81 /*
82 Local Variables:
83 c-basic-offset:2
84 comment-column:40
85 fill-column:79
86 indent-tabs-mode:nil
87 End:
88 */