cordova-plugin-mserviceinterface-2.0 1.0.21 → 1.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +28 -28
- package/plugin.xml +153 -153
- package/src/android/CallbackProgressDialog.java +53 -53
- package/src/android/FileProvider.java +7 -7
- package/src/android/backgroundNotification.java +120 -120
- package/src/android/doubleogradle.gradle +5 -5
- package/src/android/mInterface.java +2087 -2066
- package/src/android/mInterfaceReceiver.java +59 -59
- package/src/android/mInterfaceService.java +749 -749
- package/src/android/mInterfaceUtil.java +1686 -1688
- package/src/android/res/xml/network_security_config.xml +8 -8
- package/src/android/res/xml/opener_paths.xml +16 -16
- package/src/ios/InternetConnection.h +64 -64
- package/src/ios/InternetConnection.m +242 -242
- package/src/ios/SSZipArchive.h +146 -146
- package/src/ios/SSZipArchive.m +1180 -1180
- package/src/ios/SSZipCommon.h +66 -66
- package/src/ios/UICKeyChainStore.h +64 -64
- package/src/ios/UICKeyChainStore.m +434 -434
- package/src/ios/XMLConverter.h +61 -61
- package/src/ios/XMLConverter.m +243 -243
- package/src/ios/ZipArchive.h +19 -19
- package/src/ios/aes/aes.h +270 -270
- package/src/ios/aes/aes_ni.c +687 -687
- package/src/ios/aes/aes_ni.h +59 -59
- package/src/ios/aes/aescrypt.c +301 -301
- package/src/ios/aes/aeskey.c +554 -554
- package/src/ios/aes/aesopt.h +776 -776
- package/src/ios/aes/aestab.c +418 -418
- package/src/ios/aes/aestab.h +173 -173
- package/src/ios/aes/brg_endian.h +127 -127
- package/src/ios/aes/brg_types.h +191 -191
- package/src/ios/aes/fileenc.c +145 -145
- package/src/ios/aes/fileenc.h +121 -121
- package/src/ios/aes/hmac.c +209 -209
- package/src/ios/aes/hmac.h +119 -119
- package/src/ios/aes/prng.c +155 -155
- package/src/ios/aes/prng.h +82 -82
- package/src/ios/aes/pwd2key.c +181 -181
- package/src/ios/aes/pwd2key.h +45 -45
- package/src/ios/aes/sha1.c +283 -283
- package/src/ios/aes/sha1.h +72 -72
- package/src/ios/mInterface.h +2 -0
- package/src/ios/mInterface.m +18 -1
- package/src/ios/minizip/crypt.c +146 -146
- package/src/ios/minizip/crypt.h +66 -66
- package/src/ios/minizip/ioapi.c +353 -353
- package/src/ios/minizip/ioapi.h +154 -154
- package/src/ios/minizip/ioapi_buf.c +452 -452
- package/src/ios/minizip/ioapi_buf.h +52 -52
- package/src/ios/minizip/ioapi_mem.c +167 -167
- package/src/ios/minizip/ioapi_mem.h +52 -52
- package/src/ios/minizip/minishared.c +292 -292
- package/src/ios/minizip/minishared.h +50 -50
- package/src/ios/minizip/unzip.c +2007 -2007
- package/src/ios/minizip/unzip.h +254 -254
- package/src/ios/minizip/zip.c +2007 -2007
- package/src/ios/minizip/zip.h +215 -215
- package/www/mInterface.js +3 -3
package/src/ios/minizip/ioapi.c
CHANGED
|
@@ -1,353 +1,353 @@
|
|
|
1
|
-
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
|
2
|
-
part of the MiniZip project
|
|
3
|
-
|
|
4
|
-
Copyright (C) 2012-2017 Nathan Moinvaziri
|
|
5
|
-
https://github.com/nmoinvaz/minizip
|
|
6
|
-
Modifications for Zip64 support
|
|
7
|
-
Copyright (C) 2009-2010 Mathias Svensson
|
|
8
|
-
http://result42.com
|
|
9
|
-
Copyright (C) 1998-2010 Gilles Vollant
|
|
10
|
-
http://www.winimage.com/zLibDll/minizip.html
|
|
11
|
-
|
|
12
|
-
This program is distributed under the terms of the same license as zlib.
|
|
13
|
-
See the accompanying LICENSE file for the full text of the license.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
#include <stdlib.h>
|
|
17
|
-
#include <string.h>
|
|
18
|
-
|
|
19
|
-
#if defined unix || defined __APPLE__
|
|
20
|
-
#include <sys/types.h>
|
|
21
|
-
#include <unistd.h>
|
|
22
|
-
#endif
|
|
23
|
-
|
|
24
|
-
#include "ioapi.h"
|
|
25
|
-
|
|
26
|
-
#if defined(_WIN32)
|
|
27
|
-
# define snprintf _snprintf
|
|
28
|
-
#endif
|
|
29
|
-
|
|
30
|
-
voidpf call_zopen64(const zlib_filefunc64_32_def *pfilefunc, const void *filename, int mode)
|
|
31
|
-
{
|
|
32
|
-
if (pfilefunc->zfile_func64.zopen64_file != NULL)
|
|
33
|
-
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque, filename, mode);
|
|
34
|
-
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque, (const char*)filename, mode);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
voidpf call_zopendisk64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint32_t number_disk, int mode)
|
|
38
|
-
{
|
|
39
|
-
if (pfilefunc->zfile_func64.zopendisk64_file != NULL)
|
|
40
|
-
return (*(pfilefunc->zfile_func64.zopendisk64_file)) (pfilefunc->zfile_func64.opaque, filestream, number_disk, mode);
|
|
41
|
-
return (*(pfilefunc->zopendisk32_file))(pfilefunc->zfile_func64.opaque, filestream, number_disk, mode);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
long call_zseek64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint64_t offset, int origin)
|
|
45
|
-
{
|
|
46
|
-
uint32_t offset_truncated = 0;
|
|
47
|
-
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
|
48
|
-
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
|
|
49
|
-
offset_truncated = (uint32_t)offset;
|
|
50
|
-
if (offset_truncated != offset)
|
|
51
|
-
return -1;
|
|
52
|
-
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream, offset_truncated, origin);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
uint64_t call_ztell64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream)
|
|
56
|
-
{
|
|
57
|
-
uint64_t position;
|
|
58
|
-
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
|
59
|
-
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque, filestream);
|
|
60
|
-
position = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque, filestream);
|
|
61
|
-
if ((position) == UINT32_MAX)
|
|
62
|
-
return (uint64_t)-1;
|
|
63
|
-
return position;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32)
|
|
67
|
-
{
|
|
68
|
-
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
|
|
69
|
-
p_filefunc64_32->zfile_func64.zopendisk64_file = NULL;
|
|
70
|
-
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
|
|
71
|
-
p_filefunc64_32->zopendisk32_file = p_filefunc32->zopendisk_file;
|
|
72
|
-
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
|
73
|
-
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
|
|
74
|
-
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
|
|
75
|
-
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
|
|
76
|
-
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
|
|
77
|
-
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
|
|
78
|
-
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
|
79
|
-
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
|
|
80
|
-
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
|
|
81
|
-
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
static voidpf ZCALLBACK fopen_file_func(ZIP_UNUSED voidpf opaque, const char *filename, int mode);
|
|
85
|
-
static uint32_t ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uint32_t size);
|
|
86
|
-
static uint32_t ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void *buf, uint32_t size);
|
|
87
|
-
static uint64_t ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream);
|
|
88
|
-
static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, uint64_t offset, int origin);
|
|
89
|
-
static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream);
|
|
90
|
-
static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream);
|
|
91
|
-
|
|
92
|
-
typedef struct
|
|
93
|
-
{
|
|
94
|
-
FILE *file;
|
|
95
|
-
int filenameLength;
|
|
96
|
-
void *filename;
|
|
97
|
-
} FILE_IOPOSIX;
|
|
98
|
-
|
|
99
|
-
static voidpf file_build_ioposix(FILE *file, const char *filename)
|
|
100
|
-
{
|
|
101
|
-
FILE_IOPOSIX *ioposix = NULL;
|
|
102
|
-
if (file == NULL)
|
|
103
|
-
return NULL;
|
|
104
|
-
ioposix = (FILE_IOPOSIX*)malloc(sizeof(FILE_IOPOSIX));
|
|
105
|
-
ioposix->file = file;
|
|
106
|
-
ioposix->filenameLength = (int)strlen(filename) + 1;
|
|
107
|
-
ioposix->filename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
|
108
|
-
strncpy((char*)ioposix->filename, filename, ioposix->filenameLength);
|
|
109
|
-
return (voidpf)ioposix;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
static voidpf ZCALLBACK fopen_file_func(ZIP_UNUSED voidpf opaque, const char *filename, int mode)
|
|
113
|
-
{
|
|
114
|
-
FILE* file = NULL;
|
|
115
|
-
const char *mode_fopen = NULL;
|
|
116
|
-
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
|
117
|
-
mode_fopen = "rb";
|
|
118
|
-
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
|
119
|
-
mode_fopen = "r+b";
|
|
120
|
-
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
|
121
|
-
mode_fopen = "wb";
|
|
122
|
-
|
|
123
|
-
if ((filename != NULL) && (mode_fopen != NULL))
|
|
124
|
-
{
|
|
125
|
-
file = fopen(filename, mode_fopen);
|
|
126
|
-
return file_build_ioposix(file, filename);
|
|
127
|
-
}
|
|
128
|
-
return file;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
static voidpf ZCALLBACK fopen64_file_func(ZIP_UNUSED voidpf opaque, const void *filename, int mode)
|
|
132
|
-
{
|
|
133
|
-
FILE* file = NULL;
|
|
134
|
-
const char *mode_fopen = NULL;
|
|
135
|
-
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
|
136
|
-
mode_fopen = "rb";
|
|
137
|
-
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
|
138
|
-
mode_fopen = "r+b";
|
|
139
|
-
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
|
140
|
-
mode_fopen = "wb";
|
|
141
|
-
|
|
142
|
-
if ((filename != NULL) && (mode_fopen != NULL))
|
|
143
|
-
{
|
|
144
|
-
file = fopen64((const char*)filename, mode_fopen);
|
|
145
|
-
return file_build_ioposix(file, (const char*)filename);
|
|
146
|
-
}
|
|
147
|
-
return file;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
static voidpf ZCALLBACK fopendisk64_file_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode)
|
|
151
|
-
{
|
|
152
|
-
FILE_IOPOSIX *ioposix = NULL;
|
|
153
|
-
char *diskFilename = NULL;
|
|
154
|
-
voidpf ret = NULL;
|
|
155
|
-
int i = 0;
|
|
156
|
-
|
|
157
|
-
if (stream == NULL)
|
|
158
|
-
return NULL;
|
|
159
|
-
ioposix = (FILE_IOPOSIX*)stream;
|
|
160
|
-
diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
|
161
|
-
strncpy(diskFilename, (const char*)ioposix->filename, ioposix->filenameLength);
|
|
162
|
-
for (i = ioposix->filenameLength - 1; i >= 0; i -= 1)
|
|
163
|
-
{
|
|
164
|
-
if (diskFilename[i] != '.')
|
|
165
|
-
continue;
|
|
166
|
-
snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02u", number_disk + 1);
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
if (i >= 0)
|
|
170
|
-
ret = fopen64_file_func(opaque, diskFilename, mode);
|
|
171
|
-
free(diskFilename);
|
|
172
|
-
return ret;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
static voidpf ZCALLBACK fopendisk_file_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode)
|
|
176
|
-
{
|
|
177
|
-
FILE_IOPOSIX *ioposix = NULL;
|
|
178
|
-
char *diskFilename = NULL;
|
|
179
|
-
voidpf ret = NULL;
|
|
180
|
-
int i = 0;
|
|
181
|
-
|
|
182
|
-
if (stream == NULL)
|
|
183
|
-
return NULL;
|
|
184
|
-
ioposix = (FILE_IOPOSIX*)stream;
|
|
185
|
-
diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
|
186
|
-
strncpy(diskFilename, (const char*)ioposix->filename, ioposix->filenameLength);
|
|
187
|
-
for (i = ioposix->filenameLength - 1; i >= 0; i -= 1)
|
|
188
|
-
{
|
|
189
|
-
if (diskFilename[i] != '.')
|
|
190
|
-
continue;
|
|
191
|
-
snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02u", number_disk + 1);
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
if (i >= 0)
|
|
195
|
-
ret = fopen_file_func(opaque, diskFilename, mode);
|
|
196
|
-
free(diskFilename);
|
|
197
|
-
return ret;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
static uint32_t ZCALLBACK fread_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, void* buf, uint32_t size)
|
|
201
|
-
{
|
|
202
|
-
FILE_IOPOSIX *ioposix = NULL;
|
|
203
|
-
uint32_t read = (uint32_t)-1;
|
|
204
|
-
if (stream == NULL)
|
|
205
|
-
return read;
|
|
206
|
-
ioposix = (FILE_IOPOSIX*)stream;
|
|
207
|
-
read = (uint32_t)fread(buf, 1, (size_t)size, ioposix->file);
|
|
208
|
-
return read;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
static uint32_t ZCALLBACK fwrite_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, const void *buf, uint32_t size)
|
|
212
|
-
{
|
|
213
|
-
FILE_IOPOSIX *ioposix = NULL;
|
|
214
|
-
uint32_t written = (uint32_t)-1;
|
|
215
|
-
if (stream == NULL)
|
|
216
|
-
return written;
|
|
217
|
-
ioposix = (FILE_IOPOSIX*)stream;
|
|
218
|
-
written = (uint32_t)fwrite(buf, 1, (size_t)size, ioposix->file);
|
|
219
|
-
return written;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
static long ZCALLBACK ftell_file_func(ZIP_UNUSED voidpf opaque, voidpf stream)
|
|
223
|
-
{
|
|
224
|
-
FILE_IOPOSIX *ioposix = NULL;
|
|
225
|
-
long ret = -1;
|
|
226
|
-
if (stream == NULL)
|
|
227
|
-
return ret;
|
|
228
|
-
ioposix = (FILE_IOPOSIX*)stream;
|
|
229
|
-
ret = ftell(ioposix->file);
|
|
230
|
-
return ret;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
static uint64_t ZCALLBACK ftell64_file_func(ZIP_UNUSED voidpf opaque, voidpf stream)
|
|
234
|
-
{
|
|
235
|
-
FILE_IOPOSIX *ioposix = NULL;
|
|
236
|
-
uint64_t ret = (uint64_t)-1;
|
|
237
|
-
if (stream == NULL)
|
|
238
|
-
return ret;
|
|
239
|
-
ioposix = (FILE_IOPOSIX*)stream;
|
|
240
|
-
ret = ftello64(ioposix->file);
|
|
241
|
-
return ret;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
static long ZCALLBACK fseek_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, uint32_t offset, int origin)
|
|
245
|
-
{
|
|
246
|
-
FILE_IOPOSIX *ioposix = NULL;
|
|
247
|
-
int fseek_origin = 0;
|
|
248
|
-
long ret = 0;
|
|
249
|
-
|
|
250
|
-
if (stream == NULL)
|
|
251
|
-
return -1;
|
|
252
|
-
ioposix = (FILE_IOPOSIX*)stream;
|
|
253
|
-
|
|
254
|
-
switch (origin)
|
|
255
|
-
{
|
|
256
|
-
case ZLIB_FILEFUNC_SEEK_CUR:
|
|
257
|
-
fseek_origin = SEEK_CUR;
|
|
258
|
-
break;
|
|
259
|
-
case ZLIB_FILEFUNC_SEEK_END:
|
|
260
|
-
fseek_origin = SEEK_END;
|
|
261
|
-
break;
|
|
262
|
-
case ZLIB_FILEFUNC_SEEK_SET:
|
|
263
|
-
fseek_origin = SEEK_SET;
|
|
264
|
-
break;
|
|
265
|
-
default:
|
|
266
|
-
return -1;
|
|
267
|
-
}
|
|
268
|
-
if (fseek(ioposix->file, offset, fseek_origin) != 0)
|
|
269
|
-
ret = -1;
|
|
270
|
-
return ret;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
static long ZCALLBACK fseek64_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, uint64_t offset, int origin)
|
|
274
|
-
{
|
|
275
|
-
FILE_IOPOSIX *ioposix = NULL;
|
|
276
|
-
int fseek_origin = 0;
|
|
277
|
-
long ret = 0;
|
|
278
|
-
|
|
279
|
-
if (stream == NULL)
|
|
280
|
-
return -1;
|
|
281
|
-
ioposix = (FILE_IOPOSIX*)stream;
|
|
282
|
-
|
|
283
|
-
switch (origin)
|
|
284
|
-
{
|
|
285
|
-
case ZLIB_FILEFUNC_SEEK_CUR:
|
|
286
|
-
fseek_origin = SEEK_CUR;
|
|
287
|
-
break;
|
|
288
|
-
case ZLIB_FILEFUNC_SEEK_END:
|
|
289
|
-
fseek_origin = SEEK_END;
|
|
290
|
-
break;
|
|
291
|
-
case ZLIB_FILEFUNC_SEEK_SET:
|
|
292
|
-
fseek_origin = SEEK_SET;
|
|
293
|
-
break;
|
|
294
|
-
default:
|
|
295
|
-
return -1;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (fseeko64(ioposix->file, offset, fseek_origin) != 0)
|
|
299
|
-
ret = -1;
|
|
300
|
-
|
|
301
|
-
return ret;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
static int ZCALLBACK fclose_file_func(ZIP_UNUSED voidpf opaque, voidpf stream)
|
|
305
|
-
{
|
|
306
|
-
FILE_IOPOSIX *ioposix = NULL;
|
|
307
|
-
int ret = -1;
|
|
308
|
-
if (stream == NULL)
|
|
309
|
-
return ret;
|
|
310
|
-
ioposix = (FILE_IOPOSIX*)stream;
|
|
311
|
-
if (ioposix->filename != NULL)
|
|
312
|
-
free(ioposix->filename);
|
|
313
|
-
ret = fclose(ioposix->file);
|
|
314
|
-
free(ioposix);
|
|
315
|
-
return ret;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
static int ZCALLBACK ferror_file_func(ZIP_UNUSED voidpf opaque, voidpf stream)
|
|
319
|
-
{
|
|
320
|
-
FILE_IOPOSIX *ioposix = NULL;
|
|
321
|
-
int ret = -1;
|
|
322
|
-
if (stream == NULL)
|
|
323
|
-
return ret;
|
|
324
|
-
ioposix = (FILE_IOPOSIX*)stream;
|
|
325
|
-
ret = ferror(ioposix->file);
|
|
326
|
-
return ret;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
|
|
330
|
-
{
|
|
331
|
-
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
|
332
|
-
pzlib_filefunc_def->zopendisk_file = fopendisk_file_func;
|
|
333
|
-
pzlib_filefunc_def->zread_file = fread_file_func;
|
|
334
|
-
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
|
335
|
-
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
|
336
|
-
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
|
337
|
-
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
|
338
|
-
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
|
339
|
-
pzlib_filefunc_def->opaque = NULL;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
|
|
343
|
-
{
|
|
344
|
-
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
|
|
345
|
-
pzlib_filefunc_def->zopendisk64_file = fopendisk64_file_func;
|
|
346
|
-
pzlib_filefunc_def->zread_file = fread_file_func;
|
|
347
|
-
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
|
348
|
-
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
|
|
349
|
-
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
|
|
350
|
-
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
|
351
|
-
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
|
352
|
-
pzlib_filefunc_def->opaque = NULL;
|
|
353
|
-
}
|
|
1
|
+
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
|
2
|
+
part of the MiniZip project
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2012-2017 Nathan Moinvaziri
|
|
5
|
+
https://github.com/nmoinvaz/minizip
|
|
6
|
+
Modifications for Zip64 support
|
|
7
|
+
Copyright (C) 2009-2010 Mathias Svensson
|
|
8
|
+
http://result42.com
|
|
9
|
+
Copyright (C) 1998-2010 Gilles Vollant
|
|
10
|
+
http://www.winimage.com/zLibDll/minizip.html
|
|
11
|
+
|
|
12
|
+
This program is distributed under the terms of the same license as zlib.
|
|
13
|
+
See the accompanying LICENSE file for the full text of the license.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#include <stdlib.h>
|
|
17
|
+
#include <string.h>
|
|
18
|
+
|
|
19
|
+
#if defined unix || defined __APPLE__
|
|
20
|
+
#include <sys/types.h>
|
|
21
|
+
#include <unistd.h>
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#include "ioapi.h"
|
|
25
|
+
|
|
26
|
+
#if defined(_WIN32)
|
|
27
|
+
# define snprintf _snprintf
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
voidpf call_zopen64(const zlib_filefunc64_32_def *pfilefunc, const void *filename, int mode)
|
|
31
|
+
{
|
|
32
|
+
if (pfilefunc->zfile_func64.zopen64_file != NULL)
|
|
33
|
+
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque, filename, mode);
|
|
34
|
+
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque, (const char*)filename, mode);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
voidpf call_zopendisk64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint32_t number_disk, int mode)
|
|
38
|
+
{
|
|
39
|
+
if (pfilefunc->zfile_func64.zopendisk64_file != NULL)
|
|
40
|
+
return (*(pfilefunc->zfile_func64.zopendisk64_file)) (pfilefunc->zfile_func64.opaque, filestream, number_disk, mode);
|
|
41
|
+
return (*(pfilefunc->zopendisk32_file))(pfilefunc->zfile_func64.opaque, filestream, number_disk, mode);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
long call_zseek64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint64_t offset, int origin)
|
|
45
|
+
{
|
|
46
|
+
uint32_t offset_truncated = 0;
|
|
47
|
+
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
|
48
|
+
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
|
|
49
|
+
offset_truncated = (uint32_t)offset;
|
|
50
|
+
if (offset_truncated != offset)
|
|
51
|
+
return -1;
|
|
52
|
+
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream, offset_truncated, origin);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
uint64_t call_ztell64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream)
|
|
56
|
+
{
|
|
57
|
+
uint64_t position;
|
|
58
|
+
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
|
59
|
+
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque, filestream);
|
|
60
|
+
position = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque, filestream);
|
|
61
|
+
if ((position) == UINT32_MAX)
|
|
62
|
+
return (uint64_t)-1;
|
|
63
|
+
return position;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32)
|
|
67
|
+
{
|
|
68
|
+
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
|
|
69
|
+
p_filefunc64_32->zfile_func64.zopendisk64_file = NULL;
|
|
70
|
+
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
|
|
71
|
+
p_filefunc64_32->zopendisk32_file = p_filefunc32->zopendisk_file;
|
|
72
|
+
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
|
73
|
+
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
|
|
74
|
+
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
|
|
75
|
+
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
|
|
76
|
+
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
|
|
77
|
+
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
|
|
78
|
+
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
|
79
|
+
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
|
|
80
|
+
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
|
|
81
|
+
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static voidpf ZCALLBACK fopen_file_func(ZIP_UNUSED voidpf opaque, const char *filename, int mode);
|
|
85
|
+
static uint32_t ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uint32_t size);
|
|
86
|
+
static uint32_t ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void *buf, uint32_t size);
|
|
87
|
+
static uint64_t ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream);
|
|
88
|
+
static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, uint64_t offset, int origin);
|
|
89
|
+
static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream);
|
|
90
|
+
static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream);
|
|
91
|
+
|
|
92
|
+
typedef struct
|
|
93
|
+
{
|
|
94
|
+
FILE *file;
|
|
95
|
+
int filenameLength;
|
|
96
|
+
void *filename;
|
|
97
|
+
} FILE_IOPOSIX;
|
|
98
|
+
|
|
99
|
+
static voidpf file_build_ioposix(FILE *file, const char *filename)
|
|
100
|
+
{
|
|
101
|
+
FILE_IOPOSIX *ioposix = NULL;
|
|
102
|
+
if (file == NULL)
|
|
103
|
+
return NULL;
|
|
104
|
+
ioposix = (FILE_IOPOSIX*)malloc(sizeof(FILE_IOPOSIX));
|
|
105
|
+
ioposix->file = file;
|
|
106
|
+
ioposix->filenameLength = (int)strlen(filename) + 1;
|
|
107
|
+
ioposix->filename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
|
108
|
+
strncpy((char*)ioposix->filename, filename, ioposix->filenameLength);
|
|
109
|
+
return (voidpf)ioposix;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static voidpf ZCALLBACK fopen_file_func(ZIP_UNUSED voidpf opaque, const char *filename, int mode)
|
|
113
|
+
{
|
|
114
|
+
FILE* file = NULL;
|
|
115
|
+
const char *mode_fopen = NULL;
|
|
116
|
+
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
|
117
|
+
mode_fopen = "rb";
|
|
118
|
+
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
|
119
|
+
mode_fopen = "r+b";
|
|
120
|
+
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
|
121
|
+
mode_fopen = "wb";
|
|
122
|
+
|
|
123
|
+
if ((filename != NULL) && (mode_fopen != NULL))
|
|
124
|
+
{
|
|
125
|
+
file = fopen(filename, mode_fopen);
|
|
126
|
+
return file_build_ioposix(file, filename);
|
|
127
|
+
}
|
|
128
|
+
return file;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static voidpf ZCALLBACK fopen64_file_func(ZIP_UNUSED voidpf opaque, const void *filename, int mode)
|
|
132
|
+
{
|
|
133
|
+
FILE* file = NULL;
|
|
134
|
+
const char *mode_fopen = NULL;
|
|
135
|
+
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
|
136
|
+
mode_fopen = "rb";
|
|
137
|
+
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
|
138
|
+
mode_fopen = "r+b";
|
|
139
|
+
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
|
140
|
+
mode_fopen = "wb";
|
|
141
|
+
|
|
142
|
+
if ((filename != NULL) && (mode_fopen != NULL))
|
|
143
|
+
{
|
|
144
|
+
file = fopen64((const char*)filename, mode_fopen);
|
|
145
|
+
return file_build_ioposix(file, (const char*)filename);
|
|
146
|
+
}
|
|
147
|
+
return file;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static voidpf ZCALLBACK fopendisk64_file_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode)
|
|
151
|
+
{
|
|
152
|
+
FILE_IOPOSIX *ioposix = NULL;
|
|
153
|
+
char *diskFilename = NULL;
|
|
154
|
+
voidpf ret = NULL;
|
|
155
|
+
int i = 0;
|
|
156
|
+
|
|
157
|
+
if (stream == NULL)
|
|
158
|
+
return NULL;
|
|
159
|
+
ioposix = (FILE_IOPOSIX*)stream;
|
|
160
|
+
diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
|
161
|
+
strncpy(diskFilename, (const char*)ioposix->filename, ioposix->filenameLength);
|
|
162
|
+
for (i = ioposix->filenameLength - 1; i >= 0; i -= 1)
|
|
163
|
+
{
|
|
164
|
+
if (diskFilename[i] != '.')
|
|
165
|
+
continue;
|
|
166
|
+
snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02u", number_disk + 1);
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
if (i >= 0)
|
|
170
|
+
ret = fopen64_file_func(opaque, diskFilename, mode);
|
|
171
|
+
free(diskFilename);
|
|
172
|
+
return ret;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static voidpf ZCALLBACK fopendisk_file_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode)
|
|
176
|
+
{
|
|
177
|
+
FILE_IOPOSIX *ioposix = NULL;
|
|
178
|
+
char *diskFilename = NULL;
|
|
179
|
+
voidpf ret = NULL;
|
|
180
|
+
int i = 0;
|
|
181
|
+
|
|
182
|
+
if (stream == NULL)
|
|
183
|
+
return NULL;
|
|
184
|
+
ioposix = (FILE_IOPOSIX*)stream;
|
|
185
|
+
diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
|
186
|
+
strncpy(diskFilename, (const char*)ioposix->filename, ioposix->filenameLength);
|
|
187
|
+
for (i = ioposix->filenameLength - 1; i >= 0; i -= 1)
|
|
188
|
+
{
|
|
189
|
+
if (diskFilename[i] != '.')
|
|
190
|
+
continue;
|
|
191
|
+
snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02u", number_disk + 1);
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
if (i >= 0)
|
|
195
|
+
ret = fopen_file_func(opaque, diskFilename, mode);
|
|
196
|
+
free(diskFilename);
|
|
197
|
+
return ret;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
static uint32_t ZCALLBACK fread_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, void* buf, uint32_t size)
|
|
201
|
+
{
|
|
202
|
+
FILE_IOPOSIX *ioposix = NULL;
|
|
203
|
+
uint32_t read = (uint32_t)-1;
|
|
204
|
+
if (stream == NULL)
|
|
205
|
+
return read;
|
|
206
|
+
ioposix = (FILE_IOPOSIX*)stream;
|
|
207
|
+
read = (uint32_t)fread(buf, 1, (size_t)size, ioposix->file);
|
|
208
|
+
return read;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
static uint32_t ZCALLBACK fwrite_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, const void *buf, uint32_t size)
|
|
212
|
+
{
|
|
213
|
+
FILE_IOPOSIX *ioposix = NULL;
|
|
214
|
+
uint32_t written = (uint32_t)-1;
|
|
215
|
+
if (stream == NULL)
|
|
216
|
+
return written;
|
|
217
|
+
ioposix = (FILE_IOPOSIX*)stream;
|
|
218
|
+
written = (uint32_t)fwrite(buf, 1, (size_t)size, ioposix->file);
|
|
219
|
+
return written;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
static long ZCALLBACK ftell_file_func(ZIP_UNUSED voidpf opaque, voidpf stream)
|
|
223
|
+
{
|
|
224
|
+
FILE_IOPOSIX *ioposix = NULL;
|
|
225
|
+
long ret = -1;
|
|
226
|
+
if (stream == NULL)
|
|
227
|
+
return ret;
|
|
228
|
+
ioposix = (FILE_IOPOSIX*)stream;
|
|
229
|
+
ret = ftell(ioposix->file);
|
|
230
|
+
return ret;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
static uint64_t ZCALLBACK ftell64_file_func(ZIP_UNUSED voidpf opaque, voidpf stream)
|
|
234
|
+
{
|
|
235
|
+
FILE_IOPOSIX *ioposix = NULL;
|
|
236
|
+
uint64_t ret = (uint64_t)-1;
|
|
237
|
+
if (stream == NULL)
|
|
238
|
+
return ret;
|
|
239
|
+
ioposix = (FILE_IOPOSIX*)stream;
|
|
240
|
+
ret = ftello64(ioposix->file);
|
|
241
|
+
return ret;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static long ZCALLBACK fseek_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, uint32_t offset, int origin)
|
|
245
|
+
{
|
|
246
|
+
FILE_IOPOSIX *ioposix = NULL;
|
|
247
|
+
int fseek_origin = 0;
|
|
248
|
+
long ret = 0;
|
|
249
|
+
|
|
250
|
+
if (stream == NULL)
|
|
251
|
+
return -1;
|
|
252
|
+
ioposix = (FILE_IOPOSIX*)stream;
|
|
253
|
+
|
|
254
|
+
switch (origin)
|
|
255
|
+
{
|
|
256
|
+
case ZLIB_FILEFUNC_SEEK_CUR:
|
|
257
|
+
fseek_origin = SEEK_CUR;
|
|
258
|
+
break;
|
|
259
|
+
case ZLIB_FILEFUNC_SEEK_END:
|
|
260
|
+
fseek_origin = SEEK_END;
|
|
261
|
+
break;
|
|
262
|
+
case ZLIB_FILEFUNC_SEEK_SET:
|
|
263
|
+
fseek_origin = SEEK_SET;
|
|
264
|
+
break;
|
|
265
|
+
default:
|
|
266
|
+
return -1;
|
|
267
|
+
}
|
|
268
|
+
if (fseek(ioposix->file, offset, fseek_origin) != 0)
|
|
269
|
+
ret = -1;
|
|
270
|
+
return ret;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
static long ZCALLBACK fseek64_file_func(ZIP_UNUSED voidpf opaque, voidpf stream, uint64_t offset, int origin)
|
|
274
|
+
{
|
|
275
|
+
FILE_IOPOSIX *ioposix = NULL;
|
|
276
|
+
int fseek_origin = 0;
|
|
277
|
+
long ret = 0;
|
|
278
|
+
|
|
279
|
+
if (stream == NULL)
|
|
280
|
+
return -1;
|
|
281
|
+
ioposix = (FILE_IOPOSIX*)stream;
|
|
282
|
+
|
|
283
|
+
switch (origin)
|
|
284
|
+
{
|
|
285
|
+
case ZLIB_FILEFUNC_SEEK_CUR:
|
|
286
|
+
fseek_origin = SEEK_CUR;
|
|
287
|
+
break;
|
|
288
|
+
case ZLIB_FILEFUNC_SEEK_END:
|
|
289
|
+
fseek_origin = SEEK_END;
|
|
290
|
+
break;
|
|
291
|
+
case ZLIB_FILEFUNC_SEEK_SET:
|
|
292
|
+
fseek_origin = SEEK_SET;
|
|
293
|
+
break;
|
|
294
|
+
default:
|
|
295
|
+
return -1;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (fseeko64(ioposix->file, offset, fseek_origin) != 0)
|
|
299
|
+
ret = -1;
|
|
300
|
+
|
|
301
|
+
return ret;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
static int ZCALLBACK fclose_file_func(ZIP_UNUSED voidpf opaque, voidpf stream)
|
|
305
|
+
{
|
|
306
|
+
FILE_IOPOSIX *ioposix = NULL;
|
|
307
|
+
int ret = -1;
|
|
308
|
+
if (stream == NULL)
|
|
309
|
+
return ret;
|
|
310
|
+
ioposix = (FILE_IOPOSIX*)stream;
|
|
311
|
+
if (ioposix->filename != NULL)
|
|
312
|
+
free(ioposix->filename);
|
|
313
|
+
ret = fclose(ioposix->file);
|
|
314
|
+
free(ioposix);
|
|
315
|
+
return ret;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
static int ZCALLBACK ferror_file_func(ZIP_UNUSED voidpf opaque, voidpf stream)
|
|
319
|
+
{
|
|
320
|
+
FILE_IOPOSIX *ioposix = NULL;
|
|
321
|
+
int ret = -1;
|
|
322
|
+
if (stream == NULL)
|
|
323
|
+
return ret;
|
|
324
|
+
ioposix = (FILE_IOPOSIX*)stream;
|
|
325
|
+
ret = ferror(ioposix->file);
|
|
326
|
+
return ret;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
|
|
330
|
+
{
|
|
331
|
+
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
|
332
|
+
pzlib_filefunc_def->zopendisk_file = fopendisk_file_func;
|
|
333
|
+
pzlib_filefunc_def->zread_file = fread_file_func;
|
|
334
|
+
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
|
335
|
+
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
|
336
|
+
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
|
337
|
+
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
|
338
|
+
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
|
339
|
+
pzlib_filefunc_def->opaque = NULL;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
|
|
343
|
+
{
|
|
344
|
+
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
|
|
345
|
+
pzlib_filefunc_def->zopendisk64_file = fopendisk64_file_func;
|
|
346
|
+
pzlib_filefunc_def->zread_file = fread_file_func;
|
|
347
|
+
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
|
348
|
+
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
|
|
349
|
+
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
|
|
350
|
+
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
|
351
|
+
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
|
352
|
+
pzlib_filefunc_def->opaque = NULL;
|
|
353
|
+
}
|