chiark / gitweb /
Assume initial digits in a track name are a sort key even without the
[disorder] / cgi / cgimain.c
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
ac169f8a 3 * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
460b9539 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 2 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, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
9faa7a88
RK
20/** @file server/cgimain.c
21 * @brief DisOrder CGI
22 */
460b9539 23
1e97629d 24#include "disorder-cgi.h"
9faa7a88 25
460b9539 26int main(int argc, char **argv) {
d0b6635e 27 const char *conf;
460b9539 28
9faa7a88
RK
29 if(argc > 0)
30 progname = argv[0];
ad9bae0b 31 /* RFC 3875 s8.2 recommends rejecting PATH_INFO if we don't make use of
32 * it. */
d0b6635e 33 /* TODO we could make disorder/ACTION equivalent to disorder?action=ACTION */
ad9bae0b 34 if(getenv("PATH_INFO")) {
9faa7a88 35 /* TODO it might be nice to link back to the right place... */
10921eba 36 printf("Content-Type: text/html; charset=UTF-8\n");
ad9bae0b 37 printf("Status: 404\n");
38 printf("\n");
cc5b0a8e
RK
39 printf("<p>Sorry, is PATH_INFO not supported."
40 "<a href=\"%s\">Try here instead.</a></p>\n",
41 cgi_sgmlquote(infer_url(0/*!include_path_info*/)));
ad9bae0b 42 exit(0);
43 }
d0b6635e 44 /* Parse CGI arguments */
71634563 45 cgi_init();
9faa7a88
RK
46 /* We allow various things to be overridden from the environment. This is
47 * intended for debugging and is not a documented feature. */
48 if((conf = getenv("DISORDER_CONFIG")))
49 configfile = xstrdup(conf);
50 if(getenv("DISORDER_DEBUG"))
51 debugging = 1;
2257512d
RK
52 /* Read configuration */
53 if(config_read(0/*!server*/))
9faa7a88
RK
54 exit(EXIT_FAILURE);
55 /* Figure out our URL. This can still be overridden from the config file if
56 * necessary but it shouldn't be necessary in ordinary installations. */
36bde473 57 if(!config->url)
cc5b0a8e 58 config->url = infer_url(1/*include_path_info*/);
d0b6635e
RK
59 /* Pick up the cookie, if there is one */
60 dcgi_get_cookie();
9faa7a88
RK
61 /* Register expansions */
62 mx_register_builtin();
1e97629d 63 dcgi_expansions();
9faa7a88
RK
64 /* Update search path. We look in the config directory first and the data
65 * directory second, so that the latter overrides the former. */
66 mx_search_path(pkgconfdir);
67 mx_search_path(pkgdatadir);
bca4e2b7 68 /* Never cache anythging */
71634563
RK
69 if(printf("Cache-Control: no-cache\n") < 0)
70 fatal(errno, "error writing to stdout");
9faa7a88
RK
71 /* Create the initial connection, trying the cookie if we found a suitable
72 * one. */
1e97629d 73 dcgi_login();
2257512d 74 /* Do whatever the user wanted */
1e97629d 75 dcgi_action(NULL);
9faa7a88
RK
76 /* In practice if a write fails that probably means the web server went away,
77 * but we log it anyway. */
78 if(fclose(stdout) < 0)
79 fatal(errno, "error closing stdout");
460b9539 80 return 0;
81}
82
83/*
84Local Variables:
85c-basic-offset:2
86comment-column:40
ac169f8a 87fill-column:79
88indent-tabs-mode:nil
460b9539 89End:
90*/