summaryrefslogtreecommitdiff
path: root/xs_httpd.h
diff options
context:
space:
mode:
authorGravatar default2022-09-23 20:28:23 +0200
committerGravatar default2022-09-23 20:28:23 +0200
commit1d694a245a56bb4fd90fd917ad3648c2c5449746 (patch)
treecb96eb621ca84ebfdfba40cf859af477639f75d6 /xs_httpd.h
parentNew function process_queue(). (diff)
downloadsnac2-1d694a245a56bb4fd90fd917ad3648c2c5449746.tar.gz
snac2-1d694a245a56bb4fd90fd917ad3648c2c5449746.tar.xz
snac2-1d694a245a56bb4fd90fd917ad3648c2c5449746.zip
xs_httpd_request() also returns the payload.
Diffstat (limited to 'xs_httpd.h')
-rw-r--r--xs_httpd.h21
1 files changed, 10 insertions, 11 deletions
diff --git a/xs_httpd.h b/xs_httpd.h
index d15a473..d56226f 100644
--- a/xs_httpd.h
+++ b/xs_httpd.h
@@ -6,7 +6,7 @@
6 6
7d_char *xs_url_dec(char *str); 7d_char *xs_url_dec(char *str);
8d_char *xs_url_vars(char *str); 8d_char *xs_url_vars(char *str);
9d_char *xs_httpd_request(FILE *f); 9d_char *xs_httpd_request(FILE *f, d_char **payload, int *p_size);
10void xs_httpd_response(FILE *f, int status, d_char *headers, char *body, int b_size); 10void xs_httpd_response(FILE *f, int status, d_char *headers, char *body, int b_size);
11 11
12 12
@@ -69,7 +69,7 @@ d_char *xs_url_vars(char *str)
69} 69}
70 70
71 71
72d_char *xs_httpd_request(FILE *f) 72d_char *xs_httpd_request(FILE *f, d_char **payload, int *p_size)
73/* processes an httpd connection */ 73/* processes an httpd connection */
74{ 74{
75 xs *headers = NULL; 75 xs *headers = NULL;
@@ -127,19 +127,18 @@ d_char *xs_httpd_request(FILE *f)
127 127
128 xs_socket_timeout(fileno(f), 5.0, 0.0); 128 xs_socket_timeout(fileno(f), 5.0, 0.0);
129 129
130 if ((v = xs_dict_get(headers, "content-length")) != NULL) {
131 /* if it has a payload, load it */
132 *p_size = atoi(v);
133 *payload = xs_read(f, *p_size);
134 }
135
130 /* does it have a payload with form urlencoded variables? */ 136 /* does it have a payload with form urlencoded variables? */
131 v = xs_dict_get(headers, "content-type"); 137 v = xs_dict_get(headers, "content-type");
132 138
133 if (v && strcmp(v, "application/x-www-form-urlencoded") == 0) { 139 if (v && strcmp(v, "application/x-www-form-urlencoded") == 0) {
134 if ((v = xs_dict_get(headers, "content-length")) != NULL) { 140 xs *upl = xs_url_dec(*payload);
135 int cl = atoi(v); 141 p_vars = xs_url_vars(upl);
136 xs *payload;
137
138 if ((payload = xs_read(f, cl)) != NULL) {
139 xs *upl = xs_url_dec(payload);
140 p_vars = xs_url_vars(upl);
141 }
142 }
143 } 142 }
144 else 143 else
145 p_vars = xs_dict_new(); 144 p_vars = xs_dict_new();