Fix:core:Add comments and some #defines for constants
[profile/ivi/navit.git] / navit / navit / zipfile.h
1 /**
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2008 Navit Team
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19
20 #ifndef __ZIPFILE_H__
21 #define __ZIPFILE_H__
22
23 #ifdef HAVE_PRAGMA_PACK
24 #pragma pack(push)
25 #pragma pack(1)
26 #endif
27
28 #ifdef  __GNUC__
29 #define ATTRIBUTE_PACKED __attribute__ ((packed))
30 #else
31 #define ATTRIBUTE_PACKED
32 #endif
33
34 #define zip_split_sig 0x08074b50
35 #define zip_split_sig_rev 0x504b0708
36
37 struct zip_split {
38         int zipsplitsig;
39 };
40
41 #define zip_lfh_sig 0x04034b50
42 #define zip_lfh_sig_rev 0x504b0304
43
44
45 //! ZIP local file header structure.
46
47 //! See the documentation of the ZIP format for the meaning
48 //! of these fields.
49 struct zip_lfh {
50         int ziplocsig;             //!< local file header signature
51         short zipver;              //!< minimum zip spec version needed to extract
52         short zipgenfld;           //!< general purpose flags
53         short zipmthd;             //!< compression method
54         short ziptime;             //!< file modification time
55         short zipdate;             //!< file modification date
56         int zipcrc;                //!< CRC-32 checksum
57         unsigned int zipsize;      //!< file size (after compression)
58         unsigned int zipuncmp;     //!< file size (uncompressed)
59         unsigned short zipfnln;    //!< file name length
60         unsigned short zipxtraln;  //!< extra filed length (unused?)
61         char zipname[0];           //!< file name (length as given above)
62 } ATTRIBUTE_PACKED;
63
64 #define zip_cd_sig 0x02014b50
65 #define zip_cd_sig_rev 0x504b0102
66
67 //! ZIP central directory structure.
68
69 //! See the documentation of the ZIP format for the meaning
70 //! of these fields.
71 struct zip_cd {
72         int zipcensig;   //!< central directory signature
73         char zipcver;    //!< zip spec version of creating software
74         char zipcos;     //!< os compatibility of the file attribute information
75         char zipcvxt;    //!< minimum zip spec version needed to extract
76         char zipcexos;   //!< unused (?)
77         short zipcflg;   //!< general purpose flag
78         short zipcmthd;  //!< compression method
79         short ziptim;    //!< file modification time
80         short zipdat;    //!< file modification date
81         int zipccrc;     //!< CRC-32 checksum
82         unsigned int zipcsiz;   //!< file size (after compression)
83         unsigned int zipcunc;   //!< file size (uncompressed)
84         unsigned short zipcfnl; //!< file name length
85         unsigned short zipcxtl; //!< extra field length
86         unsigned short zipccml; //!< comment length
87         unsigned short zipdsk;  //!< disk number of file
88         unsigned short zipint;  //!< internal attributes
89         unsigned int zipext;    //!< external attributes
90         unsigned int zipofst;   //!< offset to start of local file header
91         char zipcfn[0];         //!< file name (length as given above)
92 } ATTRIBUTE_PACKED;
93
94 /**
95 * @brief Placeholder value for size field in the central directory if
96 * the size is 64bit. See the documentation for the Zip64 Extended
97 * Information Extra Field.
98 */
99 #define zip_size_64bit_placeholder 0xffffffff
100
101 /**
102 * @brief Header ID for extra field "ZIP64".
103 */
104 #define zip_extra_header_id_zip64 0x0001
105
106 //! ZIP extra field structure.
107
108 //! See the documentation of the ZIP format for the meaning
109 //! of these fields.
110 struct zip_cd_ext {
111         short tag;                   //!< extra field header ID
112         short size;                  //!< extra field data size
113         unsigned long long zipofst;  //!< offset to start of local file header (only valid if the struct is for a ZIP64 extra field)
114 } ATTRIBUTE_PACKED;
115
116 struct zip_enc {
117         short efield_header;
118         short efield_size;
119         short version;
120         char vendor_id1,vendor_id2;
121         char encryption_strength;
122         short compress_method; 
123 } ATTRIBUTE_PACKED;
124
125 #define zip_eoc_sig 0x6054b50
126 #define zip_eoc_sig_rev 0x504b0506
127
128 //! ZIP end of central directory structure.
129
130 //! See the documentation of the ZIP format for the meaning
131 //! of these fields.
132 struct zip_eoc {
133         int zipesig;            /* end of central dir signature */
134         unsigned short zipedsk; /* number of this disk */
135         unsigned short zipecen; /* number of the disk with the start of the central directory */
136         unsigned short zipenum; /* total number of entries in the central directory on this disk */
137         unsigned short zipecenn; /* total number of entries in the central directory */
138         unsigned int zipecsz;   /* size of the central directory */
139         unsigned int zipeofst;  /* offset of start of central directory with respect to the starting disk number */
140         short zipecoml;         /* .ZIP file comment length */
141         char zipecom[0];        /* .ZIP file comment */
142 } ATTRIBUTE_PACKED;
143
144 #define zip64_eoc_sig 0x6064b50
145 #define zip64_eoc_sig_rev 0x504b0606
146
147 struct zip64_eoc {
148         int zip64esig;                  /* zip64 end of central dir signature */
149         unsigned long long zip64esize;  /* size of zip64 end of central directory record */
150         unsigned short zip64ever;       /* version made by */
151         unsigned short zip64eneed;      /* version needed to extract */
152         unsigned int zip64edsk;         /* number of this disk */
153         unsigned int zip64ecen;         /* number of the disk with the start of the central directory */
154         unsigned long long zip64enum;   /* total number of entries in the central directory on this disk */
155         unsigned long long zip64ecenn;  /* total number of entries in the central directory */
156         unsigned long long zip64ecsz;   /* size of the central directory */
157         unsigned long long zip64eofst;  /* offset of start of central directory with respect to the starting disk number */
158         char zip64ecom[0];              /* zip64 extensible data sector */
159 } ATTRIBUTE_PACKED;
160
161 #define zip64_eocl_sig 0x07064b50
162
163 struct zip64_eocl {
164         int zip64lsig;
165         int zip64ldsk;
166         long long zip64lofst;
167         int zip74lnum;
168 } ATTRIBUTE_PACKED;
169
170 struct zip_alignment_check {
171         int x[sizeof(struct zip_cd) == 46 ? 1:-1];
172 };
173
174 #ifdef HAVE_PRAGMA_PACK
175 #pragma pack(pop)
176 #endif
177 #endif