X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/d22b8a59995829bc14b4490b9bddd95346e0585d..8ab2aa9fd51a89e06d92a4f7c3792aaa4a08cc71:/lib/url.c
diff --git a/lib/url.c b/lib/url.c
index 16f3257..7ee1f45 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2,32 +2,26 @@
* This file is part of DisOrder
* Copyright (C) 2007, 2008 Richard Kettlewell
*
- * This program is free software; you can redistribute it and/or modify
+ * 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program. If not, see .
*/
/** @file lib/url.c
* @brief URL support functions
*/
-#include
-#include "types.h"
+#include "common.h"
-#include
-#include
#include
-#include
#include "mem.h"
#include "log.h"
@@ -36,12 +30,13 @@
#include "kvp.h"
/** @brief Infer the for the web interface
+ * @param include_path_info 1 to include post-script path, else 0
* @return Inferred URL
*
* See RFC 3875.
*/
-char *infer_url(void) {
- const char *scheme = "http", *server, *script, *e, *request_uri;
+char *infer_url(int include_path_info) {
+ const char *scheme = "http", *server, *script, *e, *request_uri, *path_info;
char *url;
int port;
@@ -52,7 +47,7 @@ char *infer_url(void) {
/* 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");
+ disorder_fatal(0, "SERVER_NAME is not set");
server = xstrdup(server);
/* Figure out the port. 'MUST' be set but we cope if it is not. */
@@ -62,7 +57,7 @@ char *infer_url(void) {
port = 80;
/* Figure out path to ourselves. */
- if((request_uri = getenv("REQUEST_URI"))) {
+ if(include_path_info && (request_uri = getenv("REQUEST_URI"))) {
/* REQUEST_URI is an Apache extexnsion. If it's available it results in
* more accurate self-referencing URLs. */
if((e = strchr(request_uri, '?')))
@@ -72,15 +67,18 @@ char *infer_url(void) {
} else {
/* RFC3875 s4.1.13 */
if(!(script = getenv("SCRIPT_NAME")))
- fatal(0, "SCRIPT_NAME is not set");
+ disorder_fatal(0, "SCRIPT_NAME is not set");
/* SCRIPT_NAME may be "" */
if(!*script)
script = "/";
/* SCRIPT_NAME is not URL-encoded */
script = urlencodestring(script);
+ if(include_path_info && (path_info = getenv("PATH_INFO")))
+ byte_xasprintf((char **)&script, "%s%s",
+ script, urlencodestring(path_info));
}
if(script[0] != '/')
- fatal(0, "SCRIPT_NAME does not start with a '/'");
+ disorder_fatal(0, "SCRIPT_NAME does not start with a '/'");
script = xstrdup(script);
if(port == 80)