-static void infer_url(void) {
- if(!config->url) {
- const char *scheme = "http", *server, *script, *e;
- int port;
-
- /* Figure out the server. 'MUST' be set and we don't cope if it
- * is not. */
- if(!(server = getenv("SERVER_NAME")))
- fatal(0, "SERVER_NAME is not set");
- server = xstrdup(server);
-
- /* Figure out the port. 'MUST' be set but we cope if it is not. */
- if((e = getenv("SERVER_PORT")))
- port = atoi(e);
- else
- port = 80;
-
- /* Figure out path to ourselves */
- if(!(script = getenv("SCRIPT_NAME")))
- fatal(0, "SCRIPT_NAME is not set");
- if(script[0] != '/')
- fatal(0, "SCRIPT_NAME does not start with a '/'");
- script = xstrdup(script);
-
- if(port == 80)
- byte_xasprintf(&config->url, "%s://%s%s",
- scheme, server, script);
- else
- byte_xasprintf(&config->url, "%s://%s:%d%s",
- scheme, server, port, script);
- }
+static int better_cookie(const struct cookie *a, const struct cookie *b) {
+ if(a->path && b->path)
+ /* If both have a path then the one with the longest path is best */
+ return strlen(a->path) > strlen(b->path);
+ else if(a->path)
+ /* If only @p a has a path then it is better */
+ return 1;
+ else
+ /* If neither have a path, or if only @p b has a path, then @p b is
+ * better */
+ return 0;