Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

dsZipMmap.h

Go to the documentation of this file.
00001 /*
00002  * $Id: dsZipMmap.h,v 1.3 2003/09/10 16:01:40 dsamersoff Exp $
00003  */
00004 #ifndef dsZipMmap_h
00005 #define dsZipMmap_h
00006 
00007 #ifdef HAVE_CONFIG_H
00008 # include <config.h>
00009 #endif
00010 
00011 #include <time.h>
00012 
00013 #include <zlib.h>
00014 #include <zconf.h>
00015 
00016 
00017 #include <dsMmap.h>
00018 #include <dsutil.h>
00019 
00020 DECLARE_EXCEPTION(dsZipMmap);
00021 
00022 #define ZIP_HEADER_SIZE     30
00023 #define ZIP_NAMELEN(pptr) (*(short *)((pptr) + 26))
00024 
00025 typedef struct tagLocal_header
00026 {
00027   int   sign;     /* local file header signature     4 bytes  (0x04034b50) */
00028   short nver;     /* version needed to extract       2 bytes*/  
00029   short flag;     /* general purpose bit flag        2 bytes*/
00030   short method;   /* compression method              2 bytes*/
00031   short lmtime;   /* last mod file time              2 bytes*/
00032   short lmdate;   /* last mod file date              2 bytes*/
00033   int   crc32;    /* crc-32                          4 bytes*/
00034   int   csize;    /* compressed size                 4 bytes*/
00035   int   usize;    /* uncompressed size               4 bytes*/
00036   short  namelen; /* filename length                 2 bytes*/
00037   short  extralen;/* extra field length              2 bytes*/
00038                   /* Total length:                  30 bytes*/   
00039 } local_header;
00040 
00041 /* Zip end of central directory header */
00042 typedef struct tagEOCD 
00043 {
00044  unsigned sign;        /*end of central dir signature         4 bytes (0x06054b50)*/
00045  short    this_disk;   /*number of this disk                  2 bytes*/
00046  short    first_disk;  /*number of the disk with the start of the cd 2 bytes*/
00047  short    entires;     /*total number of entries in the cd    2 bytes*/
00048  short    ondisik_ents;/*total number of entries in the cd    2 bytes*/
00049  int      cd_size;     /*size of the central directory        4 bytes*/
00050  int      cd_offs;     /*offset of start of central directory 4 bytes*/
00051  short    comment_len; /*zipfile comment length               2 bytes*/
00052 } endof_cd;
00053 
00054 
00055 /* gzip flag byte */
00056 #define GZ_ASCII G     0x01 /* bit 0 set: file probably ascii text */
00057 #define GZ_MULTIPART   0x02 /* bit 1 set: header CRC present */
00058 #define GZ_EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
00059 #define GZ_NAME        0x08 /* bit 3 set: original file name present */
00060 #define GZ_COMMENT     0x10 /* bit 4 set: file comment present */
00061 #define GZ_ENCRYPT     0x20 /* bit 5 set: file encripted */
00062 #define GZ_RESERVED    0xE0 /* bits 5..7: reserved */
00063 
00064 /************ End of oficial part ********************/
00065 
00066 /* path:
00067    /arcdir/arcname.zip/dir/file
00068  */
00069 
00070 enum{ AM_ZIP, AM_GZ, AM_PLAIN };
00071 
00072 struct ZIPFILE
00073 {
00074   char * name;
00075   size_t phdr;
00076   size_t next_ptr;  
00077  
00078   ZIPFILE(){ reset(); } 
00079   void reset(){ next_ptr = 0; }
00080 };
00081 
00086 class dsZipMmap: public dsMmapAnon 
00087 {
00088    int _arcmode;
00089    dsMmap *_srcMap;
00090    local_header _zipfh;
00091 
00092 protected:
00093    void zipReadFile(char *ptr);
00094    void gzRead();
00095 
00096 public:
00097    dsZipMmap(const char *path, const mode_t openmode = 0444, const int flags = 0, const int advize = MADV_NORMAL);
00098   ~dsZipMmap()
00099     { 
00100       if (_srcMap) delete _srcMap; 
00101     }
00102 
00103 
00104   dsMmap *src(){ return _srcMap; } 
00105   int type(){ return _arcmode; } 
00106 
00107   ZIPFILE *zipList(ZIPFILE *zf);
00108 
00109   int zipSeek(char *file);
00110   int zipSeek(size_t offs){ zipReadFile( ((char *) *_srcMap) + offs ); return 0; }
00111   int zipSeek(ZIPFILE *zf){ return zipSeek(zf->phdr); }
00112 
00113   void zipPack(char *buf, local_header * fi);
00114 };
00115 
00116 
00117 #endif

Generated on Mon May 16 18:26:58 2005 for libdms4 by doxygen1.3-rc2