summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
}