00001
00002 #include "zipios++/zipios-config.h"
00003
00004 #include "zipios++/meta-iostreams.h"
00005 #include <iterator>
00006 #include <string>
00007
00008 #include "zipios_common.h"
00009 #include "zipios++/ziphead.h"
00010 #include "zipios++/zipheadio.h"
00011 #include "zipios++/zipios_defs.h"
00012
00013 #include "outputstringstream.h"
00014
00015 namespace zipios {
00016
00017 using std::ios ;
00018
00019 bool operator== ( const ZipLocalEntry &zlh, const ZipCDirEntry &ze ) {
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 return ( zlh.extract_version == ze.extract_version &&
00040 zlh.gp_bitfield == ze.gp_bitfield &&
00041 zlh.compress_method == ze.compress_method &&
00042 zlh.last_mod_ftime == ze.last_mod_ftime &&
00043 zlh.last_mod_fdate == ze.last_mod_fdate &&
00044 zlh.filename_len == ze.filename_len &&
00045
00046 zlh.filename == ze.filename ) ;
00047 }
00048
00049
00050
00051
00052
00053 const uint32 ZipLocalEntry::signature = 0x04034b50 ;
00054
00055
00056
00057 void ZipLocalEntry::setDefaultExtract() {
00058 extract_version = 20 ;
00059 }
00060
00061 string ZipLocalEntry::getComment() const {
00062 return "" ;
00063 }
00064
00065 uint32 ZipLocalEntry::getCompressedSize() const {
00066 return compress_size ;
00067 }
00068
00069 uint32 ZipLocalEntry::getCrc() const {
00070 return crc_32 ;
00071 }
00072
00073 vector< unsigned char > ZipLocalEntry::getExtra() const {
00074 return extra_field ;
00075 }
00076
00077 StorageMethod ZipLocalEntry::getMethod() const {
00078 return static_cast< StorageMethod >( compress_method ) ;
00079 }
00080
00081 string ZipLocalEntry::getName() const {
00082 return filename ;
00083 }
00084
00085 string ZipLocalEntry::getFileName() const {
00086 if ( isDirectory() )
00087 return string() ;
00088 string::size_type pos ;
00089 pos = filename.find_last_of( separator ) ;
00090 if ( pos != string::npos ) {
00091
00092 return filename.substr( pos + 1 ) ;
00093 } else {
00094 return filename ;
00095 }
00096 }
00097
00098 uint32 ZipLocalEntry::getSize() const {
00099 return uncompress_size ;
00100 }
00101
00102 int ZipLocalEntry::getTime() const {
00103 return ( last_mod_fdate << 16 ) + last_mod_ftime ;
00104
00105 }
00106
00107 bool ZipLocalEntry::isValid() const {
00108 return _valid ;
00109 }
00110
00111 bool ZipLocalEntry::isDirectory() const {
00112 assert( filename.size() != 0 ) ;
00113 return filename[ filename.size() - 1 ] == separator ;
00114 }
00115
00116
00117 void ZipLocalEntry::setComment( const string &comment ) {
00118
00119 }
00120
00121 void ZipLocalEntry::setCompressedSize( uint32 size ) {
00122 compress_size = size ;
00123 }
00124
00125 void ZipLocalEntry::setCrc( uint32 crc ) {
00126 crc_32 = crc ;
00127 }
00128
00129 void ZipLocalEntry::setExtra( const vector< unsigned char > &extra ) {
00130 extra_field = extra ;
00131 extra_field_len = extra_field.size() ;
00132 }
00133
00134 void ZipLocalEntry::setMethod( StorageMethod method ) {
00135 compress_method = static_cast< uint16 >( method ) ;
00136 }
00137
00138 void ZipLocalEntry::setName( const string &name ) {
00139 filename = name ;
00140 filename_len = filename.size() ;
00141 }
00142
00143 void ZipLocalEntry::setSize( uint32 size ) {
00144 uncompress_size = size ;
00145 }
00146
00147 void ZipLocalEntry::setTime( int time ) {
00148
00149
00150 }
00151
00152 string ZipLocalEntry::toString() const {
00153 OutputStringStream sout ;
00154 sout << filename << " (" << uncompress_size << " bytes, " ;
00155 sout << compress_size << " bytes compressed)" ;
00156 return sout.str() ;
00157 }
00158
00159 int ZipLocalEntry::getLocalHeaderSize() const {
00160 return 30 + filename.size() + extra_field.size() ;
00161 }
00162
00163 bool ZipLocalEntry::trailingDataDescriptor() const {
00164
00165
00166
00167 if ( ( gp_bitfield & 4 ) == 1 )
00168 return true ;
00169 else
00170 return false ;
00171 }
00172
00173 FileEntry *ZipLocalEntry::clone() const {
00174 return new ZipLocalEntry( *this ) ;
00175 }
00176
00177
00178
00179
00180
00181
00182 const uint32 ZipCDirEntry::signature = 0x02014b50 ;
00183
00184 void ZipCDirEntry::setDefaultWriter() {
00185 writer_version = 0 ;
00186 #ifdef WIN32
00187 writer_version |= static_cast< uint16 >( 0 ) << 8 ;
00188 #else
00189 writer_version |= static_cast< uint16 >( 3 ) << 8 ;
00190 #endif
00191 writer_version |= 20 ;
00192 }
00193
00194 string ZipCDirEntry::getComment() const {
00195 return file_comment ;
00196 }
00197
00198 uint32 ZipCDirEntry::getLocalHeaderOffset() const {
00199 return rel_offset_loc_head ;
00200 }
00201
00202 void ZipCDirEntry::setLocalHeaderOffset( uint32 offset ) {
00203 rel_offset_loc_head = offset ;
00204 }
00205
00206
00207 void ZipCDirEntry::setComment( const string &comment ) {
00208 file_comment = comment ;
00209 file_comment_len = file_comment.size() ;
00210 }
00211
00212
00213 string ZipCDirEntry::toString() const {
00214 OutputStringStream sout ;
00215 sout << filename << " (" << uncompress_size << " bytes, " ;
00216 sout << compress_size << " bytes compressed)" ;
00217 return sout.str() ;
00218 }
00219
00220
00221 int ZipCDirEntry::getCDirHeaderSize() const {
00222 return 46 + filename.size() + extra_field.size() + file_comment.size() ;
00223 }
00224
00225
00226 FileEntry *ZipCDirEntry::clone() const {
00227 return new ZipCDirEntry( *this ) ;
00228 }
00229
00230
00231
00232
00233
00234
00235 const uint32 EndOfCentralDirectory::signature = 0x06054b50 ;
00236
00237 bool EndOfCentralDirectory::read( vector<unsigned char> &buf, int pos ) {
00238 if ( ( buf.size() - pos < sizeof( uint32 ) ) ||
00239 ( ! checkSignature( &( buf[ pos ] ) ) ) )
00240 return false ;
00241
00242 eocd_offset_from_end = buf.size() - pos ;
00243 pos += sizeof( uint32 ) ;
00244 disk_num = ztohs( &( buf[ pos ] ) ) ; pos += sizeof( uint16 ) ;
00245 cdir_disk_num = ztohs( &( buf[ pos ] ) ) ; pos += sizeof( uint16 ) ;
00246 cdir_entries = ztohs( &( buf[ pos ] ) ) ; pos += sizeof( uint16 ) ;
00247 cdir_tot_entries = ztohs( &( buf[ pos ] ) ) ; pos += sizeof( uint16 ) ;
00248 cdir_size = ztohl( &( buf[ pos ] ) ) ; pos += sizeof( uint32 ) ;
00249 cdir_offset = ztohl( &( buf[ pos ] ) ) ; pos += sizeof( uint32 ) ;
00250 zip_comment_len = ztohs( &( buf[ pos ] ) ) ; pos += sizeof( uint16 ) ;
00251
00252
00253
00254 return true ;
00255 }
00256
00257 bool EndOfCentralDirectory::checkSignature ( unsigned char *buf ) const {
00258
00259 return checkSignature( ztohl( buf ) ) ;
00260 }
00261
00262
00263
00264 }
00265
00266
00267
00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290