"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/zip_progress.c" between
libzip-1.5.2.tar.xz and libzip-1.6.0.tar.xz

About: libzip is a C library for reading, creating, and modifying zip archives.

zip_progress.c  (libzip-1.5.2.tar.xz):zip_progress.c  (libzip-1.6.0.tar.xz)
/* /*
zip_progress.c -- progress reporting zip_progress.c -- progress reporting
Copyright (C) 2017-2018 Dieter Baron and Thomas Klausner Copyright (C) 2017-2020 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives. This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at> The authors can be contacted at <libzip@nih.at>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
skipping to change at line 41 skipping to change at line 41
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <stdlib.h> #include <stdlib.h>
#define _ZIP_COMPILING_DEPRECATED #define _ZIP_COMPILING_DEPRECATED
#include "zipint.h" #include "zipint.h"
struct zip_progress { struct zip_progress {
zip_t *za; zip_t *za;
zip_progress_callback callback;
void (*ud_free)(void *);
void *ud; zip_progress_callback callback_progress;
void (*ud_progress_free)(void *);
void *ud_progress;
zip_cancel_callback callback_cancel;
void (*ud_cancel_free)(void *);
void *ud_cancel;
double precision; double precision;
/* state */ /* state */
double last_update; /* last value callback function was called with */ double last_update; /* last value callback function was called with */
double start; /* start of sub-progress section */ double start; /* start of sub-progress section */
double end; /* end of sub-progress section */ double end; /* end of sub-progress section */
}; };
static void _zip_progress_free_cancel_callback(zip_progress_t *progress);
static void _zip_progress_free_progress_callback(zip_progress_t *progress);
static zip_progress_t *_zip_progress_new(zip_t *za);
static void _zip_progress_set_cancel_callback(zip_progress_t *progress, zip_canc
el_callback callback, void (*ud_free)(void *), void *ud);
static void _zip_progress_set_progress_callback(zip_progress_t *progress, double
precision, zip_progress_callback callback, void (*ud_free)(void *), void *ud);
void void
_zip_progress_end(zip_progress_t *progress) { _zip_progress_end(zip_progress_t *progress) {
_zip_progress_update(progress, 1.0); _zip_progress_update(progress, 1.0);
} }
void void
_zip_progress_free(zip_progress_t *progress) { _zip_progress_free(zip_progress_t *progress) {
if (progress == NULL) { if (progress == NULL) {
return; return;
} }
if (progress->ud_free) { _zip_progress_free_progress_callback(progress);
progress->ud_free(progress->ud); _zip_progress_free_cancel_callback(progress);
}
free(progress); free(progress);
} }
zip_progress_t * static zip_progress_t *
_zip_progress_new(zip_t *za, double precision, zip_progress_callback callback, v _zip_progress_new(zip_t *za) {
oid (*ud_free)(void *), void *ud) {
zip_progress_t *progress = (zip_progress_t *)malloc(sizeof(*progress)); zip_progress_t *progress = (zip_progress_t *)malloc(sizeof(*progress));
if (progress == NULL) { if (progress == NULL) {
zip_error_set(&za->error, ZIP_ER_MEMORY, 0); zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
return NULL; return NULL;
} }
progress->za = za; progress->za = za;
progress->callback = callback;
progress->ud_free = ud_free; progress->callback_progress = NULL;
progress->ud = ud; progress->ud_progress_free = NULL;
progress->precision = precision; progress->ud_progress = NULL;
progress->precision = 0.0;
progress->callback_cancel = NULL;
progress->ud_cancel_free = NULL;
progress->ud_cancel = NULL;
return progress; return progress;
} }
static void
_zip_progress_free_progress_callback(zip_progress_t *progress) {
if (progress->ud_progress_free) {
progress->ud_progress_free(progress->ud_progress);
}
progress->callback_progress = NULL;
progress->ud_progress = NULL;
progress->ud_progress_free = NULL;
}
static void
_zip_progress_free_cancel_callback(zip_progress_t *progress) {
if (progress->ud_cancel_free) {
progress->ud_cancel_free(progress->ud_cancel);
}
progress->callback_cancel = NULL;
progress->ud_cancel = NULL;
progress->ud_cancel_free = NULL;
}
static void
_zip_progress_set_progress_callback(zip_progress_t *progress, double precision,
zip_progress_callback callback, void (*ud_free)(void *), void *ud) {
_zip_progress_free_progress_callback(progress);
progress->callback_progress = callback;
progress->ud_progress_free = ud_free;
progress->ud_progress = ud;
progress->precision = precision;
}
void void
_zip_progress_set_cancel_callback(zip_progress_t *progress, zip_cancel_callback
callback, void (*ud_free)(void *), void *ud) {
_zip_progress_free_cancel_callback(progress);
progress->callback_cancel = callback;
progress->ud_cancel_free = ud_free;
progress->ud_cancel = ud;
}
int
_zip_progress_start(zip_progress_t *progress) { _zip_progress_start(zip_progress_t *progress) {
if (progress == NULL) { if (progress == NULL) {
return; return 0;
}
if (progress->callback_progress != NULL) {
progress->last_update = 0.0;
progress->callback_progress(progress->za, 0.0, progress->ud_progress);
}
if (progress->callback_cancel != NULL) {
if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
return -1;
}
} }
progress->last_update = 0.0; return 0;
progress->callback(progress->za, 0.0, progress->ud);
} }
void int
_zip_progress_subrange(zip_progress_t *progress, double start, double end) { _zip_progress_subrange(zip_progress_t *progress, double start, double end) {
if (progress == NULL) { if (progress == NULL) {
return; return 0;
} }
progress->start = start; progress->start = start;
progress->end = end; progress->end = end;
_zip_progress_update(progress, 0.0); return _zip_progress_update(progress, 0.0);
} }
void int
_zip_progress_update(zip_progress_t *progress, double sub_current) { _zip_progress_update(zip_progress_t *progress, double sub_current) {
double current; double current;
if (progress == NULL) { if (progress == NULL) {
return; return 0;
} }
current = ZIP_MIN(ZIP_MAX(sub_current, 0.0), 1.0) * (progress->end - progres if (progress->callback_progress != NULL) {
s->start) + progress->start; current = ZIP_MIN(ZIP_MAX(sub_current, 0.0), 1.0) * (progress->end - prog
ress->start) + progress->start;
if (current - progress->last_update > progress->precision) {
progress->callback_progress(progress->za, current, progress->ud_progr
ess);
progress->last_update = current;
}
}
if (current - progress->last_update > progress->precision) { if (progress->callback_cancel != NULL) {
progress->callback(progress->za, current, progress->ud); if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
progress->last_update = current; return -1;
}
} }
return 0;
} }
ZIP_EXTERN int ZIP_EXTERN int
zip_register_progress_callback_with_state(zip_t *za, double precision, zip_progr ess_callback callback, void (*ud_free)(void *), void *ud) { zip_register_progress_callback_with_state(zip_t *za, double precision, zip_progr ess_callback callback, void (*ud_free)(void *), void *ud) {
zip_progress_t *progress = NULL; zip_progress_t *progress = NULL;
if (callback != NULL) { if (callback != NULL) {
if ((progress = _zip_progress_new(za, precision, callback, ud_free, ud)) if (za->progress == NULL) {
== NULL) { if ((za->progress = _zip_progress_new(za)) == NULL) {
return -1; return -1;
}
}
_zip_progress_set_progress_callback(za->progress, precision, callback, ud
_free, ud);
}
else {
if (za->progress != NULL) {
if (za->progress->callback_cancel == NULL) {
_zip_progress_free(za->progress);
za->progress = NULL;
}
else {
_zip_progress_free_progress_callback(za->progress);
}
} }
} }
_zip_progress_free(za->progress); return 0;
za->progress = progress; }
ZIP_EXTERN int
zip_register_cancel_callback_with_state(zip_t *za, zip_cancel_callback callback,
void (*ud_free)(void *), void *ud) {
zip_progress_t *progress = NULL;
if (callback != NULL) {
if (za->progress == NULL) {
if ((za->progress = _zip_progress_new(za)) == NULL) {
return -1;
}
}
_zip_progress_set_cancel_callback(za->progress, callback, ud_free, ud);
}
else {
if (za->progress != NULL) {
if (za->progress->callback_progress == NULL) {
_zip_progress_free(za->progress);
za->progress = NULL;
}
else {
_zip_progress_free_cancel_callback(za->progress);
}
}
}
return 0; return 0;
} }
struct legacy_ud { struct legacy_ud {
zip_progress_callback_t callback; zip_progress_callback_t callback;
}; };
static void static void
_zip_legacy_progress_callback(zip_t *za, double progress, void *vud) { _zip_legacy_progress_callback(zip_t *za, double progress, void *vud) {
 End of changes. 21 change blocks. 
32 lines changed or deleted 152 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)