Add two flags: ZIP_ZF_CRC and ZIP_ZF_DECOMP to note if we want to check the CRC of a file and if a file should get decompressed. Adapt code. Removes some XXX. From dillo. --HG-- branch : HEAD
diff --git a/lib/zip_fclose.c b/lib/zip_fclose.c index 9c6bbb5..d7b73a2 100644 --- a/lib/zip_fclose.c +++ b/lib/zip_fclose.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_fclose.c,v 1.11 2004/04/17 19:15:30 dillo Exp $ + $NiH: zip_fclose.c,v 1.12 2004/11/18 17:11:21 wiz Exp $ zip_fclose.c -- close file in zip archive Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner @@ -60,12 +60,14 @@ } } - /* if EOF, compare CRC */ - /* XXX: also compare for stored */ - if ((zf->flags & ZIP_ZF_COMP) == 0 && (zf->flags & ZIP_ZF_EOF)) - ret = (zf->crc_orig == zf->crc); - else + ret = 0; + if (zf->error.zip_err) ret = zf->error.zip_err; + else if ((zf->flags & ZIP_ZF_CRC) && (zf->flags & ZIP_ZF_EOF)) { + /* if EOF, compare CRC */ + if (zf->crc_orig != zf->crc) + ret = ZIP_ER_CRC; + } free(zf); return ret;
diff --git a/lib/zip_fopen_index.c b/lib/zip_fopen_index.c index 9ff4ffd..8ff5cdb 100644 --- a/lib/zip_fopen_index.c +++ b/lib/zip_fopen_index.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_fopen_index.c,v 1.20 2004/11/17 21:55:11 wiz Exp $ + $NiH: zip_fopen_index.c,v 1.21 2004/11/18 17:11:21 wiz Exp $ zip_fopen_index.c -- open file in zip archive for reading by index Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner @@ -69,15 +69,16 @@ return NULL; } - if ((flags & ZIP_FL_COMPRESSED) - || (za->cdir->entry[fileno].comp_method == ZIP_CM_STORE)) - zfflags = ZIP_ZF_COMP; - else { - if (za->cdir->entry[fileno].comp_method != ZIP_CM_DEFLATE) { - _zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0); - return NULL; + zfflags = 0; + if ((flags & ZIP_FL_COMPRESSED) == 0) { + zfflags |= ZIP_ZF_CRC; + if (za->cdir->entry[fileno].comp_method != ZIP_CM_STORE) { + if (za->cdir->entry[fileno].comp_method != ZIP_CM_DEFLATE) { + _zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0); + return NULL; + } + zfflags |= ZIP_ZF_DECOMP; } - zfflags = 0; } zf = _zip_file_new(za); @@ -94,7 +95,7 @@ return NULL; } - if (zf->flags & ZIP_ZF_COMP) + if ((zf->flags & ZIP_ZF_DECOMP) == 0) zf->bytes_left = zf->cbytes_left; else { if ((zf->buffer=(char *)malloc(BUFSIZE)) == NULL) {
diff --git a/lib/zip_fread.c b/lib/zip_fread.c index 11ad594..96f32c5 100644 --- a/lib/zip_fread.c +++ b/lib/zip_fread.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_fread.c,v 1.12 2004/11/17 21:55:11 wiz Exp $ + $NiH: zip_fread.c,v 1.13 2004/11/18 17:11:21 wiz Exp $ zip_fread.c -- read from file Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner @@ -56,8 +56,7 @@ if (zf->bytes_left == 0) { zf->flags |= ZIP_ZF_EOF; - if ((zf->flags & ZIP_ZF_COMP) == 0) { - /* XXX: compare for stored */ + if (zf->flags & ZIP_ZF_CRC) { if (zf->crc != zf->crc_orig) { _zip_error_set(&zf->error, ZIP_ER_CRC, 0); return -1; @@ -66,13 +65,11 @@ return 0; } - if (zf->flags & ZIP_ZF_COMP) { + if ((zf->flags & ZIP_ZF_DECOMP) == 0) { ret = _zip_file_fillbuf(outbuf, toread, zf); if (ret > 0) { -#if 0 - /* XXX: compute for stored */ - zf->crc = crc32(zf->crc, outbuf, ret); -#endif + if (zf->flags & ZIP_ZF_CRC) + zf->crc = crc32(zf->crc, outbuf, ret); zf->bytes_left -= ret; } return ret; @@ -94,7 +91,8 @@ have a header */ len = zf->zstr->total_out - out_before; if (len >= zf->bytes_left || len >= toread) { - zf->crc = crc32(zf->crc, outbuf, len); + if (zf->flags & ZIP_ZF_CRC) + zf->crc = crc32(zf->crc, outbuf, len); zf->bytes_left -= len; return len; }
diff --git a/lib/zipint.h b/lib/zipint.h index acb370d..6be5dc8 100644 --- a/lib/zipint.h +++ b/lib/zipint.h
@@ -2,7 +2,7 @@ #define _HAD_ZIPINT_H /* - $NiH: zipint.h,v 1.37 2005/01/11 18:00:38 dillo Exp $ + $NiH: zipint.h,v 1.38 2005/01/11 18:38:16 wiz Exp $ zipint.h -- internal declarations. Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner @@ -63,7 +63,8 @@ /* constants for struct zip_file's member flags */ #define ZIP_ZF_EOF 1 /* EOF reached */ -#define ZIP_ZF_COMP 2 /* read compressed data */ +#define ZIP_ZF_DECOMP 2 /* decompress data */ +#define ZIP_ZF_CRC 4 /* compute and compare CRC */ /* error information */