aboutsummaryrefslogtreecommitdiff
path: root/query.c
diff options
context:
space:
mode:
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"));
}
/*