- memset(&g, 0, sizeof g);
- memset(&s, 0, sizeof s);
- s.g = &g;
- g.client = disorder_get_client();
- output.quote = 1;
- output.sink = sink_stdio("stdout", stdout);
- /* See if there's a cookie */
- cookie_env = getenv("HTTP_COOKIE");
- if(cookie_env) {
- /* This will be an HTTP header */
- if(!parse_cookie(cookie_env, &cd)) {
- /* Pick the best available cookie from all those offered */
- best_cookie = -1;
- for(n = 0; n < cd.ncookies; ++n) {
- /* Is this the right cookie? */
- if(strcmp(cd.cookies[n].name, "disorder"))
- continue;
- /* Is it better than anything we've seen so far? */
- if(best_cookie < 0
- || better_cookie(&cd.cookies[n], &cd.cookies[best_cookie]))
- best_cookie = n;
- }
- if(best_cookie != -1)
- login_cookie = cd.cookies[best_cookie].value;
- }
- }
- disorder_cgi_login(&s, &output);
- /* TODO RFC 3875 s8.2 recommendations e.g. concerning PATH_INFO */
- disorder_cgi(&output, &s);
- if(fclose(stdout) < 0) fatal(errno, "error closing stdout");
+ /* Pick up the cookie, if there is one */
+ dcgi_get_cookie();
+ /* Register expansions */
+ mx_register_builtin();
+ dcgi_expansions();
+ /* Update search path. We look in the config directory first and the data
+ * directory second, so that the latter overrides the former. */
+ mx_search_path(pkgconfdir);
+ mx_search_path(pkgdatadir);
+ /* Never cache anythging */
+ if(printf("Cache-Control: no-cache\n") < 0)
+ fatal(errno, "error writing to stdout");
+ /* Create the initial connection, trying the cookie if we found a suitable
+ * one. */
+ dcgi_login();
+ /* Do whatever the user wanted */
+ dcgi_action(NULL);
+ /* In practice if a write fails that probably means the web server went away,
+ * but we log it anyway. */
+ if(fclose(stdout) < 0)
+ fatal(errno, "error closing stdout");