aboutsummaryrefslogtreecommitdiff
path: root/query.c
diff options
context:
space:
mode:
Diffstat (limited to 'query.c')
-rw-r--r--query.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/query.c b/query.c
index bc96778..9847f35 100644
--- a/query.c
+++ b/query.c
@@ -10,13 +10,14 @@
* truncation occurred, the -1th character of the string is set to 1.
*/
char *
-nextparam(int max)
+nextparam(enum method method, int max)
{
char *buf;
int i, sz;
static int j = 0;
- if(!query.post && !query.string[j-1])
+ /* Return NULL if at end of parameter string. */
+ if(method == GET && !query.string[j-1])
return NULL;
#define STEP 256
@@ -32,17 +33,28 @@ nextparam(int max)
buf++;
TRUNCATED(buf) = 0;
-#define READ(b) (query.post? fread(b, 1, 1, stdin): (*(b) = query.string[j++]))
+#define READ(b) (method == GET? \
+ (*(b) = query.string[j++]): \
+ fread(b, 1, 1, stdin))
- /* Return NULL if first character cannot be read. */
+ /*
+ * The parameter is read in a rather lopsided loop, treating
+ * the first character specially.
+ */
+first:
+ /* Return NULL if at end of parameter string. */
if(!READ(buf))
return NULL;
+ /* Skip empty parameters. */
+ if(*buf == '&')
+ goto first;
+
i = 0;
- goto loop;
+ goto rest;
for(; READ(buf+i); i++){
-loop:
+rest:
if(buf[i] == '&'){
buf[i] = 0;
break;
@@ -74,12 +86,13 @@ setquery()
fprintf(stderr, "no QUERY_STRING\n");
exit(1);
}
- query.post = strcmp(getenv("REQUEST_METHOD"), "POST") == 0;
+ query.method = strcmp(getenv("REQUEST_METHOD"), "POST")? GET: POST;
}
/*
* Split parameter string on equals sign and return value portion;
- * return NULL if none found.
+ * return NULL if none found. For example, v = split(p) results in
+ * p pointing to the parameter key and v pointing to the value.
*/
char *
split(char *param)