aboutsummaryrefslogtreecommitdiff
path: root/src/loadfile.c
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-03-09 20:17:28 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-03-09 20:17:28 +0300
commit5cfe6cdf6af2d630d21871f9193fc1b4a7db24ff (patch)
treeb50c9c0936a8dab87519dcd9e47ed40759d7eddc /src/loadfile.c
parent18ce121d4243358bc55a0474a529efe2580a0610 (diff)
downloadmagi-5cfe6cdf6af2d630d21871f9193fc1b4a7db24ff.tar
magi-5cfe6cdf6af2d630d21871f9193fc1b4a7db24ff.tar.xz
magi-5cfe6cdf6af2d630d21871f9193fc1b4a7db24ff.zip
[magi]
Diffstat (limited to 'src/loadfile.c')
-rw-r--r--src/loadfile.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/loadfile.c b/src/loadfile.c
index e8e0655..d76f562 100644
--- a/src/loadfile.c
+++ b/src/loadfile.c
@@ -1,6 +1,7 @@
#include "loadfile.h"
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
@@ -18,40 +19,40 @@ void magi_loadfiles_add(magi_loadfiles *table,
} else {
table->files = malloc(size);
}
- table->files[table->count].param_name = name;
- table->files[table->count].location = path;
- table->files[table->count].maximum = max;
+ table->files[table->count].name = name;
+ table->files[table->count].path = path;
+ table->files[table->count].max = max;
table->count++;
}
-void magi_loadfiles_destroy(magi_loadfiles *table)
+void magi_loadfiles_free(magi_loadfiles *table)
{
if (!table) {
return;
}
- free(table->table);
+ free(table->files);
+ table->count = 0;
}
-static void loadfiles(magi_file *file,
+static void loadfiles(void *userdata,
+ magi_file *file,
char *addon,
- int addon_len,
- int is_addon_last,
- void *userdata)
+ int addon_len)
{
magi_loadfiles *table = userdata;
int pos;
- if (!file->file_name || !strcmp(file->file_name, "")) {
+ if (!file->filename || !strcmp(file->filename, "")) {
return;
}
for (pos = 0; pos != table->count; ++pos) {
- if (!strcmp(table->files[pos].param_name, file->param_name)) {
+ if (!strcmp(table->files[pos].name, file->field)) {
static FILE *f = 0;
static int unlimited;
static int left;
if (!f) {
- const char * loc = table->files[pos].location;
- f = fopen(loc, "wb");
- left = table->files[pos].maximum;
+ const char *path = table->files[pos].path;
+ f = fopen(path, "wb");
+ left = table->files[pos].max;
unlimited = !left;
}
if (unlimited) {
@@ -61,7 +62,7 @@ static void loadfiles(magi_file *file,
fwrite(addon, 1, min, f);
left -= min;
}
- if (is_addon_last) {
+ if (!addon_len) {
fclose(f);
f = 0;
}
@@ -70,8 +71,8 @@ static void loadfiles(magi_file *file,
}
}
-void magi_request_setup_loadfiles(magi_request *request, magi_loadfiles *table)
+void magi_loadfiles_set(magi_request *request, magi_loadfiles *table)
{
- request->file_callback = loadfiles;
- request->file_callback_userdata = table;
+ request->callback.act = loadfiles;
+ request->callback.userdata = table;
}