X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/6d2d327ca57fefaddceba10eb323451f8150e95d..5e34540b562f91c7b383a307c32e1a159266dd11:/server/cgimain.c diff --git a/server/cgimain.c b/server/cgimain.c index 231ece1..b377c8e 100644 --- a/server/cgimain.c +++ b/server/cgimain.c @@ -1,6 +1,6 @@ /* * This file is part of DisOrder. - * Copyright (C) 2004, 2005 Richard Kettlewell + * Copyright (C) 2004, 2005, 2007 Richard Kettlewell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,39 +33,51 @@ #include "client.h" #include "sink.h" #include "cgi.h" -#include "dcgi.h" #include "mem.h" #include "log.h" #include "configuration.h" #include "disorder.h" #include "api-client.h" - +#include "mime.h" +#include "printf.h" +#include "dcgi.h" +#include "url.h" + int main(int argc, char **argv) { - const char *user, *conf; + const char *cookie_env, *conf; dcgi_global g; dcgi_state s; cgi_sink output; + int n; + struct cookiedata cd; if(argc > 0) progname = argv[0]; cgi_parse(); if((conf = getenv("DISORDER_CONFIG"))) configfile = xstrdup(conf); if(getenv("DISORDER_DEBUG")) debugging = 1; - if(config_read()) exit(EXIT_FAILURE); + if(config_read(0)) exit(EXIT_FAILURE); + if(!config->url) + config->url = infer_url(); 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); - if(!(user = getenv("REMOTE_USER"))) fatal(0, "REMOTE_USER is not set"); - if(disorder_connect(g.client)) { - disorder_cgi_error(&output, &s, "connect"); - return 0; - } - if(disorder_become(g.client, user)) { - disorder_cgi_error(&output, &s, "become"); - return 0; + 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)) { + for(n = 0; n < cd.ncookies + && strcmp(cd.cookies[n].name, "disorder"); ++n) + ; + if(n < cd.ncookies) + login_cookie = cd.cookies[n].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"); return 0;