aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-07-13 05:43:49 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-07-13 05:43:49 +0300
commit7428c24a2e3bb8897815b85fbbe61ec2ece6cfbc (patch)
tree78cdaf90e7fd80c198615fed11d01445a81b40cc /src
parent4570daec42c1e38c2df88facc23743f45f907b3d (diff)
downloadmagi-7428c24a2e3bb8897815b85fbbe61ec2ece6cfbc.tar
magi-7428c24a2e3bb8897815b85fbbe61ec2ece6cfbc.tar.xz
magi-7428c24a2e3bb8897815b85fbbe61ec2ece6cfbc.zip
Added newfile in callback.
Diffstat (limited to 'src')
-rw-r--r--src/loadfiles.c18
-rw-r--r--src/multipart.c11
2 files changed, 16 insertions, 13 deletions
diff --git a/src/loadfiles.c b/src/loadfiles.c
index b3efff7..6d68895 100644
--- a/src/loadfiles.c
+++ b/src/loadfiles.c
@@ -34,14 +34,15 @@ void magi_loadfiles_free(magi_loadfiles *table)
table->count = 0;
}
-static void loadfiles(void *userdata,
- magi_file *file,
- char *addon,
- int addon_len)
+static void loadfiles_callback(void *userdata,
+ int newfile,
+ magi_file *file,
+ char *addon,
+ int addon_len)
{
magi_loadfiles *table = userdata;
int pos;
- if (!file->filename || !strcmp(file->filename, "")) {
+ if (!file->filename || !*file->filename) {
return;
}
for (pos = 0; pos != table->count; ++pos) {
@@ -49,7 +50,7 @@ static void loadfiles(void *userdata,
static FILE *f = 0;
static int unlimited;
static int left;
- if (!f) {
+ if (newfile) {
const char *path = table->files[pos].path;
f = fopen(path, "wb");
left = table->files[pos].max;
@@ -62,9 +63,8 @@ static void loadfiles(void *userdata,
fwrite(addon, 1, min, f);
left -= min;
}
- if (!addon_len) {
+ if (!addon) {
fclose(f);
- f = 0;
}
return;
}
@@ -73,6 +73,6 @@ static void loadfiles(void *userdata,
void magi_loadfiles_set(magi_request *request, magi_loadfiles *table)
{
- request->callback.act = loadfiles;
+ request->callback.act = loadfiles_callback;
request->callback.userdata = table;
}
diff --git a/src/multipart.c b/src/multipart.c
index a265184..8164bfd 100644
--- a/src/multipart.c
+++ b/src/multipart.c
@@ -48,6 +48,7 @@ typedef struct automata {
int is_CR_readed;
int is_quoted;
int readed;
+ int newfile;
} automata;
typedef void *(*state)(automata *a, char c);
@@ -120,9 +121,10 @@ static int param_end(automata *a)
{
if (a->file.filename) {
a->request->callback.act(a->request->callback.userdata,
- &a->file, a->buf, a->buf_size);
+ a->newfile, &a->file, a->buf, a->buf_size);
a->request->callback.act(a->request->callback.userdata,
- &a->file, 0, 0);
+ 0, &a->file, 0, 0);
+ a->newfile = 1;
a->readed -= a->buf_size;
a->buf_size = 0;
magi_files_add(&a->request->files, &a->file);
@@ -216,7 +218,8 @@ static void apply_callback(automata *a)
int full = a->buf_size == a->request->callback.addon_max;
if (a->file.filename && full) {
a->request->callback.act(a->request->callback.userdata,
- &a->file, a->buf, a->buf_size);
+ a->newfile, &a->file, a->buf, a->buf_size);
+ a->newfile = 0;
a->readed -= a->buf_size;
a->buf_size = 0;
}
@@ -412,7 +415,7 @@ void magi_parse_multipart(magi_request *request,
void *next_userdata)
{
automata a = {
- 0, { 0, 0, 0 }, { 0, 0 }, { 0, 0 }, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0
+ 0, { 0, 0, 0 }, { 0, 0 }, { 0, 0 }, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 1
};
a.request = request;
a.boundary = boundary;