Rizin
unix-like reverse engineering framework and cli tools
zip_progress.c File Reference
#include <stdlib.h>
#include "zipint.h"

Go to the source code of this file.

Classes

struct  zip_progress
 
struct  legacy_ud
 

Macros

#define _ZIP_COMPILING_DEPRECATED
 

Functions

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_cancel_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 _zip_progress_end (zip_progress_t *progress)
 
void _zip_progress_free (zip_progress_t *progress)
 
int _zip_progress_start (zip_progress_t *progress)
 
int _zip_progress_subrange (zip_progress_t *progress, double start, double end)
 
int _zip_progress_update (zip_progress_t *progress, double sub_current)
 
ZIP_EXTERN int zip_register_progress_callback_with_state (zip_t *za, double precision, zip_progress_callback callback, void(*ud_free)(void *), void *ud)
 
ZIP_EXTERN int zip_register_cancel_callback_with_state (zip_t *za, zip_cancel_callback callback, void(*ud_free)(void *), void *ud)
 
static void _zip_legacy_progress_callback (zip_t *za, double progress, void *vud)
 
ZIP_EXTERN void zip_register_progress_callback (zip_t *za, zip_progress_callback_t progress_callback)
 

Macro Definition Documentation

◆ _ZIP_COMPILING_DEPRECATED

#define _ZIP_COMPILING_DEPRECATED

Definition at line 38 of file zip_progress.c.

Function Documentation

◆ _zip_legacy_progress_callback()

static void _zip_legacy_progress_callback ( zip_t za,
double  progress,
void *  vud 
)
static

Definition at line 270 of file zip_progress.c.

270  {
271  struct legacy_ud *ud = (struct legacy_ud *)vud;
272 
273  ud->callback(progress);
274 }
zip_progress_callback_t callback
Definition: zip_progress.c:265

References legacy_ud::callback.

Referenced by zip_register_progress_callback().

◆ _zip_progress_end()

void _zip_progress_end ( zip_progress_t progress)

Definition at line 68 of file zip_progress.c.

68  {
69  _zip_progress_update(progress, 1.0);
70 }
int _zip_progress_update(zip_progress_t *progress, double sub_current)
Definition: zip_progress.c:184

References _zip_progress_update().

Referenced by zip_close().

◆ _zip_progress_free()

void _zip_progress_free ( zip_progress_t progress)

Definition at line 74 of file zip_progress.c.

74  {
75  if (progress == NULL) {
76  return;
77  }
78 
81 
82  free(progress);
83 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static void _zip_progress_free_progress_callback(zip_progress_t *progress)
Definition: zip_progress.c:110
static void _zip_progress_free_cancel_callback(zip_progress_t *progress)
Definition: zip_progress.c:121

References _zip_progress_free_cancel_callback(), _zip_progress_free_progress_callback(), free(), and NULL.

Referenced by zip_discard(), zip_register_cancel_callback_with_state(), and zip_register_progress_callback_with_state().

◆ _zip_progress_free_cancel_callback()

static void _zip_progress_free_cancel_callback ( zip_progress_t progress)
static

Definition at line 121 of file zip_progress.c.

121  {
122  if (progress->ud_cancel_free) {
123  progress->ud_cancel_free(progress->ud_cancel);
124  }
125 
126  progress->callback_cancel = NULL;
127  progress->ud_cancel = NULL;
128  progress->ud_cancel_free = NULL;
129 }
void(* ud_cancel_free)(void *)
Definition: zip_progress.c:49
zip_cancel_callback callback_cancel
Definition: zip_progress.c:48
void * ud_cancel
Definition: zip_progress.c:50

References zip_progress::callback_cancel, NULL, zip_progress::ud_cancel, and zip_progress::ud_cancel_free.

Referenced by _zip_progress_free(), _zip_progress_set_cancel_callback(), and zip_register_cancel_callback_with_state().

◆ _zip_progress_free_progress_callback()

static void _zip_progress_free_progress_callback ( zip_progress_t progress)
static

Definition at line 110 of file zip_progress.c.

110  {
111  if (progress->ud_progress_free) {
112  progress->ud_progress_free(progress->ud_progress);
113  }
114 
115  progress->callback_progress = NULL;
116  progress->ud_progress = NULL;
117  progress->ud_progress_free = NULL;
118 }
void(* ud_progress_free)(void *)
Definition: zip_progress.c:45
void * ud_progress
Definition: zip_progress.c:46
zip_progress_callback callback_progress
Definition: zip_progress.c:44

References zip_progress::callback_progress, NULL, zip_progress::ud_progress, and zip_progress::ud_progress_free.

Referenced by _zip_progress_free(), _zip_progress_set_progress_callback(), and zip_register_progress_callback_with_state().

◆ _zip_progress_new()

static zip_progress_t * _zip_progress_new ( zip_t za)
static

Definition at line 87 of file zip_progress.c.

87  {
88  zip_progress_t *progress = (zip_progress_t *)malloc(sizeof(*progress));
89 
90  if (progress == NULL) {
92  return NULL;
93  }
94 
95  progress->za = za;
96 
97  progress->callback_progress = NULL;
98  progress->ud_progress_free = NULL;
99  progress->ud_progress = NULL;
100  progress->precision = 0.0;
101 
102  progress->callback_cancel = NULL;
103  progress->ud_cancel_free = NULL;
104  progress->ud_cancel = NULL;
105 
106  return progress;
107 }
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
#define ZIP_ER_MEMORY
Definition: zip.h:119
void * malloc(size_t size)
Definition: malloc.c:123
double precision
Definition: zip_progress.c:52
zip_t * za
Definition: zip_progress.c:42
zip_error_t error
Definition: zipint.h:281
zip_t * za
Definition: ziptool.c:79

References zip_progress::callback_cancel, zip_progress::callback_progress, zip::error, malloc(), NULL, zip_progress::precision, zip_progress::ud_cancel, zip_progress::ud_cancel_free, zip_progress::ud_progress, zip_progress::ud_progress_free, zip_progress::za, za, ZIP_ER_MEMORY, and zip_error_set().

Referenced by zip_register_cancel_callback_with_state(), and zip_register_progress_callback_with_state().

◆ _zip_progress_set_cancel_callback()

void _zip_progress_set_cancel_callback ( zip_progress_t progress,
zip_cancel_callback  callback,
void(*)(void *)  ud_free,
void *  ud 
)
static

Definition at line 142 of file zip_progress.c.

142  {
144 
145  progress->callback_cancel = callback;
146  progress->ud_cancel_free = ud_free;
147  progress->ud_cancel = ud;
148 }

References _zip_progress_free_cancel_callback(), zip_progress::callback_cancel, zip_progress::ud_cancel, and zip_progress::ud_cancel_free.

Referenced by zip_register_cancel_callback_with_state().

◆ _zip_progress_set_progress_callback()

static void _zip_progress_set_progress_callback ( zip_progress_t progress,
double  precision,
zip_progress_callback  callback,
void(*)(void *)  ud_free,
void *  ud 
)
static

Definition at line 132 of file zip_progress.c.

132  {
134 
135  progress->callback_progress = callback;
136  progress->ud_progress_free = ud_free;
137  progress->ud_progress = ud;
138  progress->precision = precision;
139 }

References _zip_progress_free_progress_callback(), zip_progress::callback_progress, zip_progress::precision, zip_progress::ud_progress, and zip_progress::ud_progress_free.

Referenced by zip_register_progress_callback_with_state().

◆ _zip_progress_start()

int _zip_progress_start ( zip_progress_t progress)

Definition at line 151 of file zip_progress.c.

151  {
152  if (progress == NULL) {
153  return 0;
154  }
155 
156  if (progress->callback_progress != NULL) {
157  progress->last_update = 0.0;
158  progress->callback_progress(progress->za, 0.0, progress->ud_progress);
159  }
160 
161  if (progress->callback_cancel != NULL) {
162  if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
163  return -1;
164  }
165  }
166 
167  return 0;
168 }
double last_update
Definition: zip_progress.c:55

References zip_progress::callback_cancel, zip_progress::callback_progress, zip_progress::last_update, NULL, zip_progress::ud_cancel, zip_progress::ud_progress, and zip_progress::za.

Referenced by zip_close().

◆ _zip_progress_subrange()

int _zip_progress_subrange ( zip_progress_t progress,
double  start,
double  end 
)

Definition at line 172 of file zip_progress.c.

172  {
173  if (progress == NULL) {
174  return 0;
175  }
176 
177  progress->start = start;
178  progress->end = end;
179 
180  return _zip_progress_update(progress, 0.0);
181 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
Definition: sflib.h:133
double start
Definition: zip_progress.c:57

References _zip_progress_update(), test_evm::end, zip_progress::end, NULL, start, and zip_progress::start.

Referenced by zip_close().

◆ _zip_progress_update()

int _zip_progress_update ( zip_progress_t progress,
double  sub_current 
)

Definition at line 184 of file zip_progress.c.

184  {
185  double current;
186 
187  if (progress == NULL) {
188  return 0;
189  }
190 
191  if (progress->callback_progress != NULL) {
192  current = ZIP_MIN(ZIP_MAX(sub_current, 0.0), 1.0) * (progress->end - progress->start) + progress->start;
193 
194  if (current - progress->last_update > progress->precision) {
195  progress->callback_progress(progress->za, current, progress->ud_progress);
196  progress->last_update = current;
197  }
198  }
199 
200  if (progress->callback_cancel != NULL) {
201  if (progress->callback_cancel(progress->za, progress->ud_cancel)) {
202  return -1;
203  }
204  }
205 
206  return 0;
207 }
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
#define ZIP_MAX(a, b)
Definition: zipint.h:472
#define ZIP_MIN(a, b)
Definition: zipint.h:473

References zip_progress::callback_cancel, zip_progress::callback_progress, zip_progress::end, if(), zip_progress::last_update, NULL, zip_progress::precision, zip_progress::start, zip_progress::ud_cancel, zip_progress::ud_progress, zip_progress::za, ZIP_MAX, and ZIP_MIN.

Referenced by _zip_progress_end(), _zip_progress_subrange(), copy_data(), and copy_source().

◆ zip_register_cancel_callback_with_state()

ZIP_EXTERN int zip_register_cancel_callback_with_state ( zip_t za,
zip_cancel_callback  callback,
void(*)(void *)  ud_free,
void *  ud 
)

Definition at line 238 of file zip_progress.c.

238  {
239  if (callback != NULL) {
240  if (za->progress == NULL) {
241  if ((za->progress = _zip_progress_new(za)) == NULL) {
242  return -1;
243  }
244  }
245 
246  _zip_progress_set_cancel_callback(za->progress, callback, ud_free, ud);
247  }
248  else {
249  if (za->progress != NULL) {
250  if (za->progress->callback_progress == NULL) {
252  za->progress = NULL;
253  }
254  else {
256  }
257  }
258  }
259 
260  return 0;
261 }
zip_progress_t * progress
Definition: zipint.h:302
static void _zip_progress_set_cancel_callback(zip_progress_t *progress, zip_cancel_callback callback, void(*ud_free)(void *), void *ud)
Definition: zip_progress.c:142
static zip_progress_t * _zip_progress_new(zip_t *za)
Definition: zip_progress.c:87
void _zip_progress_free(zip_progress_t *progress)
Definition: zip_progress.c:74

References _zip_progress_free(), _zip_progress_free_cancel_callback(), _zip_progress_new(), _zip_progress_set_cancel_callback(), zip_progress::callback_progress, NULL, zip::progress, and za.

◆ zip_register_progress_callback()

ZIP_EXTERN void zip_register_progress_callback ( zip_t za,
zip_progress_callback_t  progress_callback 
)

Definition at line 277 of file zip_progress.c.

277  {
278  struct legacy_ud *ud;
279 
280  if (progress_callback == NULL) {
282  }
283 
284  if ((ud = (struct legacy_ud *)malloc(sizeof(*ud))) == NULL) {
285  return;
286  }
287 
289 
291  free(ud);
292  }
293 }
ZIP_EXTERN int zip_register_progress_callback_with_state(zip_t *za, double precision, zip_progress_callback callback, void(*ud_free)(void *), void *ud)
Definition: zip_progress.c:211
static void _zip_legacy_progress_callback(zip_t *za, double progress, void *vud)
Definition: zip_progress.c:270
static void progress_callback(zip_t *archive, double percentage, void *ud)
Definition: ziptool.c:398

References _zip_legacy_progress_callback(), legacy_ud::callback, free(), malloc(), NULL, progress_callback(), za, and zip_register_progress_callback_with_state().

◆ zip_register_progress_callback_with_state()

ZIP_EXTERN int zip_register_progress_callback_with_state ( zip_t za,
double  precision,
zip_progress_callback  callback,
void(*)(void *)  ud_free,
void *  ud 
)

Definition at line 211 of file zip_progress.c.

211  {
212  if (callback != NULL) {
213  if (za->progress == NULL) {
214  if ((za->progress = _zip_progress_new(za)) == NULL) {
215  return -1;
216  }
217  }
218 
219  _zip_progress_set_progress_callback(za->progress, precision, callback, ud_free, ud);
220  }
221  else {
222  if (za->progress != NULL) {
223  if (za->progress->callback_cancel == NULL) {
225  za->progress = NULL;
226  }
227  else {
229  }
230  }
231  }
232 
233  return 0;
234 }
static void _zip_progress_set_progress_callback(zip_progress_t *progress, double precision, zip_progress_callback callback, void(*ud_free)(void *), void *ud)
Definition: zip_progress.c:132

References _zip_progress_free(), _zip_progress_free_progress_callback(), _zip_progress_new(), _zip_progress_set_progress_callback(), zip_progress::callback_cancel, NULL, zip::progress, and za.

Referenced by zip_register_progress_callback().