summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-07-18 18:08:15 -0400
committerJakob Kaivo <jkk@ung.org>2019-07-18 18:08:15 -0400
commit40e6878a6e96084c2fa0c98b988020ee06b5f9c1 (patch)
tree9a387043ef57b6fe83f36423ac0db6b6b6e9adee
parente30980265e897e020fc137afd9465889d993d63c (diff)
account for final field not ending in &, decode '+' to ' '
-rw-r--r--post.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/post.c b/post.c
index b0eed9e..67d3957 100644
--- a/post.c
+++ b/post.c
@@ -8,6 +8,22 @@
#define HSIZE 4 /* username, password, title, body */
+static void add_data(char *buf)
+{
+ char *value = strchr(buf, '=');
+ *value = '\0';
+ value++;
+
+ char *key = strdup(buf);
+ char *data = strdup(value);
+
+ ENTRY e = {
+ .key = key,
+ .data = data
+ };
+ hsearch(e, ENTER);
+}
+
void read_post_data(void)
{
char *content_length = getenv("CONTENT_LENGTH");
@@ -33,19 +49,10 @@ void read_post_data(void)
int c;
while ((c = getchar()) != EOF) {
if (c == '&') {
- char *value = strchr(buf, '=');
- *value = '\0';
- value++;
-
- char *key = strdup(buf);
- char *data = strdup(value);
-
- ENTRY e = {
- .key = key,
- .data = data
- };
- hsearch(e, ENTER);
+ add_data(buf);
pos = 0;
+ } else if (c == '+') {
+ buf[++pos] = ' ';
} else if (c == '%') {
char hex[3] = { 0, 0, 0 };
hex[0] = getchar();
@@ -58,6 +65,10 @@ void read_post_data(void)
}
}
+ if (pos != 0) {
+ add_data(buf);
+ }
+
free(buf);
}