1
#ifndef __INKJAR_JAR_H_
2
#define __INKJAR_JAR_H_
4
* Copyright (C) 1999 Bryan Burns
5
* Copyright (C) 2004 Johan Ceuppens
6
* Released under GNU GPL, read the file 'COPYING' for more information
13
#if defined(WIN32) || defined(__WIN32__)
21
#ifdef HAVE_INTTYPES_H
22
# include <inttypes.h>
29
#include <glib/garray.h>
30
#include <glib/gtypes.h>
34
unsigned const RDSZ = 4096;
36
//#define DEBUG 1 //uncommment for debug messages
38
enum JarFileReaderState {CLOSED, OPEN};
40
//fixme: The following will be removed
45
#define LOC_EXTRA 6 /* extra bytes */
46
#define LOC_COMP 8 /* compression method */
47
#define LOC_MODTIME 10 /* last modification time */
48
#define LOC_MODDATE 12 /* last modification date */
49
#define LOC_CRC 14 /* CRC */
50
#define LOC_CSIZE 18 /* compressed size */
51
#define LOC_USIZE 22 /* uncompressed size */
52
#define LOC_FNLEN 26 /* filename length */
53
#define LOC_EFLEN 28 /* extra-field length */
55
#define CEN_COMP 10 /* compression method */
56
#define CEN_MODTIME 12
57
#define CEN_MODDATE 14
68
#define PACK_UB4(d, o, v) d[o] = (ub1)((v) & 0x000000ff); \
69
d[o + 1] = (ub1)(((v) & 0x0000ff00) >> 8); \
70
d[o + 2] = (ub1)(((v) & 0x00ff0000) >> 16); \
71
d[o + 3] = (ub1)(((v) & 0xff000000) >> 24)
73
#define PACK_UB2(d, o, v) d[o] = (ub1)((v) & 0x00ff); \
74
d[o + 1] = (ub1)(((v) & 0xff00) >> 8)
76
#define UNPACK_UB4(s, o) (ub4)s[o] + (((ub4)s[o + 1]) << 8) +\
77
(((ub4)s[o + 2]) << 16) + (((ub4)s[o + 3]) << 24)
79
#define UNPACK_UB2(s, o) (ub2)s[o] + (((ub2)s[o + 1]) << 8)
86
* This is a wrapper class for canonical jarfile functions like reading,
87
* writing, seeking etc. JarFile is a dumb class with no state information.
89
* All memory allocations are done with g_malloc.
95
JarFile() : fd(-1), _filename(NULL), _last_filename(NULL) {}
97
JarFile(gchar const *new_filename);
99
GByteArray *get_next_file_contents();
100
gchar *get_last_filename() const;
103
int read(guint8 *buf, int count);
105
JarFile(JarFile const &rhs);
106
JarFile &operator=(JarFile const &rhs);
113
gchar *_last_filename;
115
bool init_inflation();
116
bool read_signature();
117
guint32 get_crc(guint8 *bytes, guint16 flags);
118
guint8 *read_filename(guint16 filename_length);
119
bool check_compression_method(guint16 method, guint16 flags);
120
bool check_crc(guint32 oldcrc, guint32 crc, guint16 flags);
121
guint8 *get_compressed_file(guint32 compressed_size,
122
unsigned int &file_length,
123
guint32 oldcrc, guint16 flags);
124
guint8 *get_uncompressed_file(guint32 compressed_szie, guint32 crc,
125
guint16 eflen, guint16 flags);
132
* This provides some smarter functions for operating on a jarfile object
133
* It should be able to grep for files or return the contents of a specific
137
class JarFileReader {
140
JarFileReader(gchar const *new_filename)
141
: _state(CLOSED), _jarfile(new_filename) {}
142
JarFileReader() : _state(CLOSED) {}
143
virtual ~JarFileReader() { if (_state == OPEN) _jarfile.close(); }
144
//fixme return types are incorrect
145
GByteArray *get_next_file();//fixme clean up return type
146
void set_filename(gchar const *new_filename);
147
void set_jarfile(JarFile const &new_jarfile);
148
gchar *get_last_filename() const { return _jarfile.get_last_filename(); };
149
JarFileReader(JarFileReader const &rhs);
150
JarFileReader &operator=(JarFileReader const &rhs);
152
JarFileReaderState _state;
155
}; // class JarFileReader
157
} // namespace Inkjar
158
#endif // header guard
163
c-file-style:"stroustrup"
164
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
169
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :