|
@@ -19,7 +19,6 @@
|
|
|
* THE SOFTWARE.
|
|
|
*/
|
|
|
|
|
|
-
|
|
|
static int
|
|
|
url_encoded_field_found(const struct mg_connection *conn,
|
|
|
const char *key,
|
|
@@ -83,7 +82,6 @@ url_encoded_field_found(const struct mg_connection *conn,
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
static int
|
|
|
url_encoded_field_get(const struct mg_connection *conn,
|
|
|
const char *key,
|
|
@@ -121,7 +119,6 @@ url_encoded_field_get(const struct mg_connection *conn,
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
static int
|
|
|
unencoded_field_get(const struct mg_connection *conn,
|
|
|
const char *key,
|
|
@@ -138,7 +135,6 @@ unencoded_field_get(const struct mg_connection *conn,
|
|
|
return fdh->field_get(key_dec, value, value_len, fdh->user_data);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
static int
|
|
|
field_stored(const struct mg_connection *conn,
|
|
|
const char *path,
|
|
@@ -152,7 +148,6 @@ field_stored(const struct mg_connection *conn,
|
|
|
return fdh->field_store(path, file_size, fdh->user_data);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
static const char *
|
|
|
search_boundary(const char *buf,
|
|
|
size_t buf_len,
|
|
@@ -174,7 +169,6 @@ search_boundary(const char *buf,
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
int
|
|
|
mg_handle_form_request(struct mg_connection *conn,
|
|
|
struct mg_form_data_handler *fdh)
|
|
@@ -384,7 +378,7 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
|
|
|
|
size_t to_read = sizeof(buf) - 1 - (size_t)buf_fill;
|
|
|
r = mg_read(conn, buf + (size_t)buf_fill, to_read);
|
|
|
- if (r < 0) {
|
|
|
+ if ((r < 0) || ((r == 0) && all_data_read)) {
|
|
|
/* read error */
|
|
|
return -1;
|
|
|
}
|
|
@@ -507,7 +501,7 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
|
|
|
|
size_t to_read = sizeof(buf) - 1 - (size_t)buf_fill;
|
|
|
r = mg_read(conn, buf + (size_t)buf_fill, to_read);
|
|
|
- if (r < 0) {
|
|
|
+ if ((r < 0) || ((r == 0) && all_data_read)) {
|
|
|
/* read error */
|
|
|
if (fstore.access.fp) {
|
|
|
mg_fclose(&fstore.access);
|
|
@@ -579,6 +573,7 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
|
const char *content_disp, *hend, *fbeg, *fend, *nbeg, *nend;
|
|
|
const char *next;
|
|
|
unsigned part_no;
|
|
|
+ int all_data_read = 0;
|
|
|
|
|
|
memset(&part_header, 0, sizeof(part_header));
|
|
|
|
|
@@ -649,15 +644,18 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
|
for (part_no = 0;; part_no++) {
|
|
|
size_t towrite, fnlen, n;
|
|
|
int get_block;
|
|
|
+ size_t to_read = sizeof(buf) - 1 - (size_t)buf_fill;
|
|
|
|
|
|
- r = mg_read(conn,
|
|
|
- buf + (size_t)buf_fill,
|
|
|
- sizeof(buf) - 1 - (size_t)buf_fill);
|
|
|
- if (r < 0) {
|
|
|
+ r = mg_read(conn, buf + (size_t)buf_fill, to_read);
|
|
|
+ if ((r < 0) || ((r == 0) && all_data_read)) {
|
|
|
/* read error */
|
|
|
mg_free(boundary);
|
|
|
return -1;
|
|
|
}
|
|
|
+ if (r != (int)to_read) {
|
|
|
+ all_data_read = 1;
|
|
|
+ }
|
|
|
+
|
|
|
buf_fill += r;
|
|
|
buf[buf_fill] = 0;
|
|
|
if (buf_fill < 1) {
|
|
@@ -922,10 +920,9 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
|
hend = buf;
|
|
|
|
|
|
/* Read new data */
|
|
|
- r = mg_read(conn,
|
|
|
- buf + (size_t)buf_fill,
|
|
|
- sizeof(buf) - 1 - (size_t)buf_fill);
|
|
|
- if (r < 0) {
|
|
|
+ to_read = sizeof(buf) - 1 - (size_t)buf_fill;
|
|
|
+ r = mg_read(conn, buf + (size_t)buf_fill, to_read);
|
|
|
+ if ((r < 0) || ((r == 0) && all_data_read)) {
|
|
|
/* read error */
|
|
|
if (fstore.access.fp) {
|
|
|
mg_fclose(&fstore.access);
|
|
@@ -934,6 +931,10 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
|
mg_free(boundary);
|
|
|
return -1;
|
|
|
}
|
|
|
+ if (r != (int)to_read) {
|
|
|
+ all_data_read = 1;
|
|
|
+ }
|
|
|
+
|
|
|
buf_fill += r;
|
|
|
buf[buf_fill] = 0;
|
|
|
/* buf_fill is at least 8 here */
|
|
@@ -1018,5 +1019,4 @@ mg_handle_form_request(struct mg_connection *conn,
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/* End of handle_form.inl */
|