From 59224e484253b32432743248672d8d8ba69f110b Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Sat, 30 Nov 2019 18:53:03 +0300 Subject: [magi] fix --- src/request.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/request.c') diff --git a/src/request.c b/src/request.c index e905e53..0db1e70 100644 --- a/src/request.c +++ b/src/request.c @@ -21,6 +21,7 @@ void magi_request_setup(struct magi_request * request) } } + void magi_tempfiles_add(struct magi_tempfiles * tmps, const char * name, const char * path, @@ -46,6 +47,16 @@ void magi_tempfiles_add(struct magi_tempfiles * tmps, tmps->maximums[tmps->count - 1] = max; } +void magi_tempfiles_destroy(struct magi_tempfiles * tmps) +{ + if (!tmps) { + return; + } + free(tmps->param_names); + free(tmps->locations); + free(tmps->maximums); +} + static void tempfiles(struct magi_file * file, char * addon, int addon_len, -- cgit v1.2.3 From b9a0844fe25cf717cdd796018bea2ae6eff58896 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Fri, 6 Dec 2019 15:52:55 +0300 Subject: [magi] change of cookies and tempfile callback --- src/request.c | 150 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 72 insertions(+), 78 deletions(-) (limited to 'src/request.c') diff --git a/src/request.c b/src/request.c index 0db1e70..d8e6d69 100644 --- a/src/request.c +++ b/src/request.c @@ -22,84 +22,6 @@ void magi_request_setup(struct magi_request * request) } -void magi_tempfiles_add(struct magi_tempfiles * tmps, - const char * name, - const char * path, - int max) -{ - if (!tmps) { - return; - } - if (tmps->count++) { - tmps->param_names = realloc(tmps->param_names, - sizeof(*tmps->param_names) * tmps->count); - tmps->locations = - realloc(tmps->locations, sizeof(*tmps->locations) * tmps->count); - tmps->maximums = - realloc(tmps->maximums, sizeof(*tmps->maximums) * tmps->count); - } else { - tmps->param_names = malloc(sizeof(*tmps->param_names)); - tmps->locations = malloc(sizeof(*tmps->locations)); - tmps->maximums = malloc(sizeof(*tmps->maximums)); - } - tmps->param_names[tmps->count - 1] = name; - tmps->locations[tmps->count - 1] = path; - tmps->maximums[tmps->count - 1] = max; -} - -void magi_tempfiles_destroy(struct magi_tempfiles * tmps) -{ - if (!tmps) { - return; - } - free(tmps->param_names); - free(tmps->locations); - free(tmps->maximums); -} - -static void tempfiles(struct magi_file * file, - char * addon, - int addon_len, - int is_addon_last, - void * userdata) -{ - struct magi_tempfiles * table = userdata; - int pos; - for (pos = 0; pos != table->count; ++pos) { - if (!strcmp(table->param_names[pos], file->param_name)) { - static FILE * f = 0; - static int unlimited; - static int left; - if (!f) { - const char * loc = table->locations[pos]; - f = fopen(loc, "wb"); - left = table->maximums[pos]; - unlimited = !left; - } - if (unlimited) { - fwrite(addon, 1, addon_len, f); - } else { - int min = left < addon_len ? left : addon_len; - fwrite(addon, 1, min, f); - left -= min; - } - if (is_addon_last) { - fclose(f); - f = 0; - } - return; - } - } -} - -void magi_request_setup_tempfiles(struct magi_request * request, - struct magi_tempfiles * table) -{ - request->file_callback = tempfiles; - request->file_callback_userdata = table; -} - - static void request_free(struct magi_request * request) { free(request->cookies); @@ -158,3 +80,75 @@ void magi_request_destroy(struct magi_request * request) request_annul(request); } } + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Tempfiles Callback + */ +void magi_tempfiles_add(struct magi_tempfiles * tmps, + const char * name, + const char * path, + int max) +{ + if (!tmps) { + return; + } + if (tmps->count++) { + tmps->tmps = realloc(tmps->tmps, sizeof(*tmps->tmps) * tmps->count); + } else { + tmps->tmps = malloc(sizeof(*tmps->tmps)); + } + tmps->tmps[tmps->count - 1].param_name = name; + tmps->tmps[tmps->count - 1].location = path; + tmps->tmps[tmps->count - 1].maximum = max; +} + +void magi_tempfiles_destroy(struct magi_tempfiles * tmps) +{ + if (!tmps) { + return; + } + free(tmps->tmps); +} + +static void tempfiles(struct magi_file * file, + char * addon, + int addon_len, + int is_addon_last, + void * userdata) +{ + struct magi_tempfiles * table = userdata; + int pos; + for (pos = 0; pos != table->count; ++pos) { + if (!strcmp(table->tmps[pos].param_name, file->param_name)) { + static FILE * f = 0; + static int unlimited; + static int left; + if (!f) { + const char * loc = table->tmps[pos].location; + f = fopen(loc, "wb"); + left = table->tmps[pos].maximum; + unlimited = !left; + } + if (unlimited) { + fwrite(addon, 1, addon_len, f); + } else { + int min = left < addon_len ? left : addon_len; + fwrite(addon, 1, min, f); + left -= min; + } + if (is_addon_last) { + fclose(f); + f = 0; + } + return; + } + } +} + +void magi_request_setup_tempfiles(struct magi_request * request, + struct magi_tempfiles * table) +{ + request->file_callback = tempfiles; + request->file_callback_userdata = table; +} -- cgit v1.2.3 From 26405332102756912ab2c175874555d6eb8c332f Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Fri, 6 Dec 2019 16:46:19 +0300 Subject: [magi] fix tempfiles callback --- src/request.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/request.c') diff --git a/src/request.c b/src/request.c index d8e6d69..8c3a101 100644 --- a/src/request.c +++ b/src/request.c @@ -119,6 +119,9 @@ static void tempfiles(struct magi_file * file, { struct magi_tempfiles * table = userdata; int pos; + if (!file->file_name || !strcmp(file->file_name, "")) { + return; + } for (pos = 0; pos != table->count; ++pos) { if (!strcmp(table->tmps[pos].param_name, file->param_name)) { static FILE * f = 0; -- cgit v1.2.3