1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-12 01:22:40 +03:00

Alternative to mg_upload (Step 23/?)

This commit is contained in:
bel
2016-01-17 23:14:15 +01:00
parent b7f4acc775
commit 30b7996799

View File

@@ -95,8 +95,12 @@ url_encoded_field_found(const char *key,
filename_dec[0] = 0; filename_dec[0] = 0;
} }
return fdh->field_found( return fdh->field_found(key_dec,
key_dec, key_dec_len, filename_dec, path, path_len, fdh->user_data); (size_t)key_dec_len,
filename_dec,
path,
path_len,
fdh->user_data);
} }
@@ -198,7 +202,7 @@ mg_handle_form_data(struct mg_connection *conn,
vallen = next - val; vallen = next - val;
next++; next++;
} else { } else {
vallen = strlen(val); vallen = (ptrdiff_t)strlen(val);
next = val + vallen; next = val + vallen;
} }
@@ -213,7 +217,7 @@ mg_handle_form_data(struct mg_connection *conn,
FILE *f = fopen(path, "wb"); FILE *f = fopen(path, "wb");
if (f != NULL) { if (f != NULL) {
size_t n = (size_t)fwrite(val, 1, (size_t)vallen, f); size_t n = (size_t)fwrite(val, 1, (size_t)vallen, f);
if ((n != vallen) || (ferror(f))) { if ((n != (size_t)vallen) || (ferror(f))) {
mg_cry(conn, mg_cry(conn,
"%s: Cannot write file %s", "%s: Cannot write file %s",
__func__, __func__,
@@ -267,10 +271,11 @@ mg_handle_form_data(struct mg_connection *conn,
ptrdiff_t keylen, vallen; ptrdiff_t keylen, vallen;
int used; int used;
if (buf_fill < (sizeof(buf) - 1)) { if ((size_t)buf_fill < (sizeof(buf) - 1)) {
int r = int r = mg_read(conn,
mg_read(conn, buf + buf_fill, sizeof(buf) - 1 - buf_fill); buf + (size_t)buf_fill,
sizeof(buf) - 1 - (size_t)buf_fill);
if (r < 0) { if (r < 0) {
/* read error */ /* read error */
return 0; return 0;
@@ -295,7 +300,7 @@ mg_handle_form_data(struct mg_connection *conn,
vallen = next - val; vallen = next - val;
next++; next++;
} else { } else {
vallen = strlen(val); vallen = (size_t)strlen(val);
next = val + vallen; next = val + vallen;
} }
@@ -306,7 +311,7 @@ mg_handle_form_data(struct mg_connection *conn,
/* Proceed to next entry */ /* Proceed to next entry */
used = next - buf; used = next - buf;
memmove(buf, buf + used, sizeof(buf) - used); memmove(buf, buf + (size_t)used, sizeof(buf) - (size_t)used);
buf_fill -= used; buf_fill -= used;
} }
@@ -335,7 +340,9 @@ mg_handle_form_data(struct mg_connection *conn,
boundary = content_type + 30; boundary = content_type + 30;
bl = strlen(boundary); bl = strlen(boundary);
r = mg_read(conn, buf + buf_fill, sizeof(buf) - 1 - buf_fill); r = mg_read(conn,
buf + (size_t)buf_fill,
sizeof(buf) - 1 - (size_t)buf_fill);
if (r < 0) { if (r < 0) {
/* read error */ /* read error */
return 0; return 0;