aboutsummaryrefslogtreecommitdiff
path: root/query.c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-09-18 23:10:23 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-09-18 23:11:23 +0200
commit7708b5f493bf3057af331624d29664ad17a87dbc (patch)
treebe56e078c043b7338938507d048307e851249726 /query.c
parent9ff1b81d65c370a938cd9d9c033e04e395f00704 (diff)
downloadcforum-7708b5f493bf3057af331624d29664ad17a87dbc.tar.gz
Make nextparam work with non-NUL-terminated data
At least on POST.
Diffstat (limited to 'query.c')
-rw-r--r--query.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/query.c b/query.c
index 370fa54..27770e4 100644
--- a/query.c
+++ b/query.c
@@ -5,14 +5,19 @@
#include "query.h"
/*
- * Return an allocated string containing the next query string parameter
- * ("key=value"). The string is truncated to max characters (but is always
- * NUL-terminated). If truncation occurred, the -1th character of the string
- * is set to 1.
+ * Return an allocated string containing the next parameter ("key=value").
+ * The method argument decides which data (GET or POST) to read from.
+ *
+ * If len is NULL, the string will be NUL-terminated; if len is non-NULL,
+ * the string will not be NUL-terminated, and len will be pointed to the
+ * length of the string.
+ *
+ * The string is truncated to max characters. If truncation occurred, the
+ * -1th character of the string is set to 1.
*/
char *
-nextparam(enum method method, int max)
-{
+nextparam(enum method method, int *len, int max)
+{
char *buf;
int i, sz;
static int j = 0;
@@ -73,7 +78,8 @@ rest:
err(1, "realloc");
}
}
- buf[i] = 0;
+ if(len) *len = i;
+ else buf[i] = 0;
return buf;
}
@@ -88,6 +94,8 @@ setquery()
exit(1);
}
query.method = strcmp(getenv("REQUEST_METHOD"), "POST")? GET: POST;
+ if(query.method == POST)
+ query.length = atoi(getenv("CONTENT_LENGTH"));
}
/*