Back to index

php5  5.3.10
zip_stat_index.c
Go to the documentation of this file.
00001 /*
00002   zip_stat_index.c -- get information about file by index
00003   Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
00004 
00005   This file is part of libzip, a library to manipulate ZIP archives.
00006   The authors can be contacted at <libzip@nih.at>
00007 
00008   Redistribution and use in source and binary forms, with or without
00009   modification, are permitted provided that the following conditions
00010   are met:
00011   1. Redistributions of source code must retain the above copyright
00012      notice, this list of conditions and the following disclaimer.
00013   2. Redistributions in binary form must reproduce the above copyright
00014      notice, this list of conditions and the following disclaimer in
00015      the documentation and/or other materials provided with the
00016      distribution.
00017   3. The names of the authors may not be used to endorse or promote
00018      products derived from this software without specific prior
00019      written permission.
00020  
00021   THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
00022   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
00025   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00027   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00029   IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00030   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00031   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 */
00033 
00034 
00035 
00036 #include "zipint.h"
00037 
00038 
00039 
00040 ZIP_EXTERN(int)
00041 zip_stat_index(struct zip *za, int index, int flags, struct zip_stat *st)
00042 {
00043     const char *name;
00044     
00045     if (index < 0 || index >= za->nentry) {
00046        _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
00047        return -1;
00048     }
00049 
00050     if ((name=zip_get_name(za, index, flags)) == NULL)
00051        return -1;
00052     
00053 
00054     if ((flags & ZIP_FL_UNCHANGED) == 0
00055        && ZIP_ENTRY_DATA_CHANGED(za->entry+index)) {
00056        if (za->entry[index].source->f(za->entry[index].source->ud,
00057                                  st, sizeof(*st), ZIP_SOURCE_STAT) < 0) {
00058            _zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
00059            return -1;
00060        }
00061     }
00062     else {
00063        if (za->cdir == NULL || index >= za->cdir->nentry) {
00064            _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
00065            return -1;
00066        }
00067        
00068        st->crc = za->cdir->entry[index].crc;
00069        st->size = za->cdir->entry[index].uncomp_size;
00070        st->mtime = za->cdir->entry[index].last_mod;
00071        st->comp_size = za->cdir->entry[index].comp_size;
00072        st->comp_method = za->cdir->entry[index].comp_method;
00073        if (za->cdir->entry[index].bitflags & ZIP_GPBF_ENCRYPTED) {
00074            if (za->cdir->entry[index].bitflags & ZIP_GPBF_STRONG_ENCRYPTION) {
00075               /* XXX */
00076               st->encryption_method = ZIP_EM_UNKNOWN;
00077            }
00078            else
00079               st->encryption_method = ZIP_EM_TRAD_PKWARE;
00080        }
00081        else
00082            st->encryption_method = ZIP_EM_NONE;
00083        /* st->bitflags = za->cdir->entry[index].bitflags; */
00084     }
00085 
00086     st->index = index;
00087     st->name = name;
00088     
00089     return 0;
00090 }