-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip.c
35 lines (28 loc) · 1.18 KB
/
zip.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "zip.h"
#include "transform.h"
#include "stopif.h"
int processContent(struct archive *archiveIn, const char *fileMask) {
struct archive_entry *entryIn;
while (archive_read_next_header(archiveIn, &entryIn) == ARCHIVE_OK) {
const char* path = archive_entry_pathname(entryIn);
int64_t size = archive_entry_size(entryIn);
char buf[size];
Stopif(archive_read_data(archiveIn, buf, size) != size, return 0, "Archive entry has no size (%s)!\n", path);
if (strstr(path, fileMask) != NULL) {
XMLBuff *slide = XMLBuffNew();
*slide = (XMLBuff){.data=buf, .size=size, .name=path};
Stopif(!transformXML(slide), return 0, "Can't process file (%s)!\n", path);
XMLBuffFree(slide);
}
}
return 1;
}
int readZIP(char const *infile, const char *fileMask) {
struct archive *archiveIn;
archiveIn = archive_read_new();
archive_read_support_format_zip(archiveIn);
Stopif(archive_read_open_filename(archiveIn, infile, 10240) != ARCHIVE_OK, return 0, "Can't read file %s!\n", infile);
Stopif(!processContent(archiveIn, fileMask), return 0, "Can't process file %s!\n", infile);
Stopif(archive_read_free(archiveIn) != ARCHIVE_OK, return 0, "Can't free %s!\n", infile);
return 1;
}