diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-07-18 18:08:15 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-07-18 18:08:15 -0400 |
commit | 40e6878a6e96084c2fa0c98b988020ee06b5f9c1 (patch) | |
tree | 9a387043ef57b6fe83f36423ac0db6b6b6e9adee /post.c | |
parent | e30980265e897e020fc137afd9465889d993d63c (diff) |
account for final field not ending in &, decode '+' to ' '
Diffstat (limited to 'post.c')
-rw-r--r-- | post.c | 35 |
1 files changed, 23 insertions, 12 deletions
@@ -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); } |