htdocs/archive: added download

This commit is contained in:
Daniel Marjamäki 2013-07-22 08:22:06 +02:00
parent e54bc77ad2
commit 464dccc188
3 changed files with 5125 additions and 0 deletions

View File

@ -0,0 +1,69 @@
#include "webarchive.h"
#include "miniz.c"
#include <stdio.h>
#include <stdlib.h>
#define ALL_ZIP "all.zip"
int main()
{
mz_zip_archive zip_archive = {0};
FILE *f = fopen("data.txt", "rt");
if (f == NULL) {
generatepage("failed to load data");
return EXIT_FAILURE;
}
int first = 1;
char line[MAX_LINE_LEN] = {0};
while (fgets(line,sizeof(line)-2,f)) {
char name[MAX_NAME_LEN+10];
sprintf(name, "cfg/%s.cfg", getname(line));
char data[MAX_LINE_LEN] = {0};
unencode(line,data);
const char *xmldata = strstr(data, "&data=");
xmldata = xmldata ? (xmldata + 6) : "";
if (first == 1) {
int status = 1;
first = 0;
if (!mz_zip_writer_init_file(&zip_archive, ALL_ZIP, 0)) {
generatepage("internal error: init_file failed");
return EXIT_FAILURE;
}
if (!mz_zip_writer_add_mem_ex(&zip_archive, name, xmldata, strlen(xmldata), NULL, 0U, MZ_BEST_COMPRESSION, 0, 0)) {
generatepage("internal error: add_mem_ex failed");
return EXIT_FAILURE;
}
if (!mz_zip_writer_finalize_archive(&zip_archive)) {
generatepage("internal error: finalize_archive failed");
return EXIT_FAILURE;
}
if (!mz_zip_writer_end(&zip_archive)) {
generatepage("internal error: writer_end failed");
return EXIT_FAILURE;
}
} else if (!mz_zip_add_mem_to_archive_file_in_place(ALL_ZIP, name, xmldata, strlen(xmldata), NULL, 0U, MZ_BEST_COMPRESSION)) {
generatepage("failed to add data");
return EXIT_FAILURE;
}
}
fclose(f);
f = fopen("all.zip","rb");
if (!f) {
generatepage("internal error: failed to load zip");
return EXIT_FAILURE;
}
puts("Content-type: application/zip\r\n\r");
int c;
while ((c = fgetc(f)) != EOF)
putc(c,stdout);
return EXIT_SUCCESS;
}

View File

@ -44,6 +44,8 @@ uninitialized variables, unused functions" />
archive. Feel free to add any library or rule here.</p> archive. Feel free to add any library or rule here.</p>
<? virtual('../cgi-bin/report.cgi') ?> <? virtual('../cgi-bin/report.cgi') ?>
<p><a href="/cgi-bin/createzip.cgi">Download all</a></p>
</div> <!-- .wrap --> </div> <!-- .wrap -->
</div> <!-- #content --> </div> <!-- #content -->
</body> </body>

5054
htdocs/archive/miniz.c Normal file

File diff suppressed because it is too large Load Diff