aboutsummaryrefslogtreecommitdiff
path: root/query.c
diff options
context:
space:
mode:
Diffstat (limited to 'query.c')
-rw-r--r--query.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/query.c b/query.c
index 8f54ead..1f3fe88 100644
--- a/query.c
+++ b/query.c
@@ -4,6 +4,33 @@
#include <string.h>
#include "cforum.h"
+/* Return an allocated string containing the next cookie ("name=value"). */
+char *
+nextcookie(int max)
+{
+ char *buf;
+ int n;
+ static char *cs = NULL;
+
+ if(!(buf = malloc(max)))
+ err(1, "malloc");
+
+ if(!cs)
+ cs = getenv("HTTP_COOKIE");
+
+ if(!cs || !*cs)
+ return NULL;
+
+ if(*cs == ' ')
+ cs++;
+
+ n = strcspn(cs, ";");
+ snprintf(buf, max, "%.*s", n, cs);
+ cs += n + (n != strlen(cs));
+
+ return buf;
+}
+
/*
* Return an allocated string containing the next parameter ("key=value").
* The method argument decides which data (GET or POST) to read from.
@@ -21,17 +48,17 @@ nextparam(enum method method, int *len, int max)
char *buf;
int i, sz;
static int j = 0;
-
+
/* Return NULL if at end of parameter string. */
if(method == GET && !query.string[j-1])
return NULL;
-
+
#define STEP 256
-
+
sz = STEP;
if(!(buf = malloc(1+sz))) /* Leave space for -1th character. */
err(1, "malloc");
-
+
/*
* buf's -1th character is set to 1 if the string
* has been truncated (i.e. if input exceeded max).
@@ -51,14 +78,14 @@ first:
/* Return NULL if at end of parameter string. */
if(!READ(buf))
return NULL;
-
+
/* Skip empty parameters. */
if(*buf == '&')
goto first;
-
+
i = 0;
goto rest;
-
+
for(; READ(buf+i); i++){
rest:
if(buf[i] == '&'){
@@ -80,7 +107,7 @@ rest:
}
if(len) *len = i;
else buf[i] = 0;
-
+
return buf;
}
@@ -125,10 +152,10 @@ int
urldecode(char *s, int len)
{
unsigned int code, i, j;
-
+
if(len < 0)
len = strlen(s);
-
+
for(i = j = 0; i < len; i++, j++){
if(s[i] == '+')
s[j] = ' ';
@@ -140,6 +167,6 @@ urldecode(char *s, int len)
}else
s[j] = s[i];
}
-
+
return j;
} \ No newline at end of file