chiark / gitweb /
keep cookie more private to disorder.cgi
[disorder] / server / cgimain.c
index 61f808f680ff4c2d7378329a3186d54736b7240b..b377c8e996614c19f3744bc2a65ec60b56f9848d 100644 (file)
 #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 *cookie_env, *conf;
@@ -54,12 +56,14 @@ int main(int argc, char **argv) {
   if((conf = getenv("DISORDER_CONFIG"))) configfile = xstrdup(conf);
   if(getenv("DISORDER_DEBUG")) debugging = 1;
   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); 
+  output.sink = sink_stdio("stdout", stdout);
   /* See if there's a cookie */
   cookie_env = getenv("HTTP_COOKIE");
   if(cookie_env) {
@@ -72,11 +76,8 @@ int main(int argc, char **argv) {
        login_cookie = cd.cookies[n].value;
     }
   }
-  /* Log in with the cookie if possible otherwise as guest */
-  if(disorder_connect_cookie(g.client, login_cookie)) {
-    disorder_cgi_error(&output, &s, "connect");
-    return 0;
-  }
+  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;