aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-07-13 06:35:05 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-07-13 06:35:05 +0300
commitc452c3dc47bacf1cb4dfd7a8129d62fa8819282e (patch)
tree7b8e51e49102379be2f55e349ce9544f6d587911
parent7428c24a2e3bb8897815b85fbbe61ec2ece6cfbc (diff)
downloadmagi-c452c3dc47bacf1cb4dfd7a8129d62fa8819282e.tar
magi-c452c3dc47bacf1cb4dfd7a8129d62fa8819282e.tar.xz
magi-c452c3dc47bacf1cb4dfd7a8129d62fa8819282e.zip
Buffer for post input.
-rw-r--r--include/magi/request.h1
-rw-r--r--src/parse.c29
-rw-r--r--src/request.c1
3 files changed, 28 insertions, 3 deletions
diff --git a/include/magi/request.h b/include/magi/request.h
index 32d31b5..0ec17e8 100644
--- a/include/magi/request.h
+++ b/include/magi/request.h
@@ -22,6 +22,7 @@ typedef struct magi_request_limits {
int params_meta;
int params_head;
int params_body;
+ int read_buffer;
} magi_request_limits;
typedef struct magi_request {
diff --git a/src/parse.c b/src/parse.c
index 58ae001..83884f0 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -147,9 +147,31 @@ static char *bound(const char *type)
return magi_str_create_copy(type, strcspn(type, " \t"));
}
-static int next()
+static int next(void *userdata)
{
- return getchar();
+ int size = *(int *)userdata;
+ static char *buffer = 0;
+ static int left = 0;
+ static int last = 0;
+ static int pos;
+ if (!buffer) {
+ if (last) {
+ return EOF;
+ }
+ buffer = malloc(size);
+ }
+ if (!left) {
+ if (last) {
+ free(buffer);
+ buffer = 0;
+ return EOF;
+ }
+ left = fread(buffer, 1, size, stdin);
+ last = left != size;
+ pos = 0;
+ }
+ left--;
+ return buffer[pos++];
}
/* Interfacial CGI Request Handling */
@@ -180,7 +202,8 @@ int magi_parse_body(magi_request *request)
if (!strncmp(t, "multipart/form-data", 19)) {
char *boundary = bound(t);
if (boundary && *boundary) {
- magi_parse_multipart(request, boundary, next, 0);
+ magi_parse_multipart(request, boundary, next,
+ &request->limits.read_buffer);
} else {
*e = magi_error_nobound;
}
diff --git a/src/request.c b/src/request.c
index bf8fc1d..22b3f30 100644
--- a/src/request.c
+++ b/src/request.c
@@ -13,6 +13,7 @@ void magi_request_init(magi_request *request)
request->limits.params_meta = 0;
request->limits.params_head = 0;
request->limits.params_body = 0;
+ request->limits.read_buffer = 65536;
}
}