aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/odf_extractor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/odf_extractor.c')
-rw-r--r--src/plugins/odf_extractor.c85
1 files changed, 30 insertions, 55 deletions
diff --git a/src/plugins/odf_extractor.c b/src/plugins/odf_extractor.c
index 7903ce5..06da7d8 100644
--- a/src/plugins/odf_extractor.c
+++ b/src/plugins/odf_extractor.c
@@ -28,11 +28,6 @@
28#include "unzip.h" 28#include "unzip.h"
29 29
30/** 30/**
31 * Should filenames be treated as case sensitive?
32 */
33#define CASESENSITIVITY 0
34
35/**
36 * Maximum length of a filename allowed inside the ZIP archive. 31 * Maximum length of a filename allowed inside the ZIP archive.
37 */ 32 */
38#define MAXFILENAME 256 33#define MAXFILENAME 256
@@ -90,17 +85,17 @@ static struct Matches tmap[] = {
90 * @return NULL if no mimetype could be found, otherwise the mime type 85 * @return NULL if no mimetype could be found, otherwise the mime type
91 */ 86 */
92static char * 87static char *
93libextractor_oo_getmimetype (EXTRACTOR_unzip_file uf) 88libextractor_oo_getmimetype (struct EXTRACTOR_UnzipFile * uf)
94{ 89{
95 char filename_inzip[MAXFILENAME]; 90 char filename_inzip[MAXFILENAME];
96 EXTRACTOR_unzip_file_info file_info; 91 struct EXTRACTOR_UnzipFileInfo file_info;
97 char *buf; 92 char *buf;
98 size_t buf_size; 93 size_t buf_size;
99 94
100 if (EXTRACTOR_UNZIP_OK != 95 if (EXTRACTOR_UNZIP_OK !=
101 EXTRACTOR_common_unzip_local_file (uf, 96 EXTRACTOR_common_unzip_go_find_local_file (uf,
102 "mimetype", 97 "mimetype",
103 CASESENSITIVITY)) 98 2))
104 return NULL; 99 return NULL;
105 if (EXTRACTOR_UNZIP_OK != 100 if (EXTRACTOR_UNZIP_OK !=
106 EXTRACTOR_common_unzip_get_current_file_info (uf, 101 EXTRACTOR_common_unzip_get_current_file_info (uf,
@@ -113,11 +108,8 @@ libextractor_oo_getmimetype (EXTRACTOR_unzip_file uf)
113 0)) 108 0))
114 return NULL; 109 return NULL;
115 if (EXTRACTOR_UNZIP_OK != 110 if (EXTRACTOR_UNZIP_OK !=
116 EXTRACTOR_common_unzip_open_current_file3 (uf, NULL, NULL, 0)) 111 EXTRACTOR_common_unzip_open_current_file (uf))
117 { 112 return NULL;
118 EXTRACTOR_common_unzip_close_current_file (uf);
119 return NULL;
120 }
121 buf_size = file_info.uncompressed_size; 113 buf_size = file_info.uncompressed_size;
122 if (buf_size > 1024) 114 if (buf_size > 1024)
123 { 115 {
@@ -164,40 +156,25 @@ void
164EXTRACTOR_odf_extract_method (struct EXTRACTOR_ExtractContext *ec) 156EXTRACTOR_odf_extract_method (struct EXTRACTOR_ExtractContext *ec)
165{ 157{
166 char filename_inzip[MAXFILENAME]; 158 char filename_inzip[MAXFILENAME];
167 EXTRACTOR_unzip_file uf; 159 struct EXTRACTOR_UnzipFile *uf;
168 EXTRACTOR_unzip_file_info file_info; 160 struct EXTRACTOR_UnzipFileInfo file_info;
169 char *buf; 161 char *buf;
170 char *pbuf; 162 char *pbuf;
171 size_t buf_size; 163 size_t buf_size;
172 unsigned int i; 164 unsigned int i;
173 EXTRACTOR_unzip_filefunc_def io;
174 char *mimetype; 165 char *mimetype;
175 166
176 if (size < 100) 167 if (NULL == (uf = EXTRACTOR_common_unzip_open (ec)))
177 return 0;
178 if ( !( ('P'==data[0]) && ('K'==data[1]) && (0x03==data[2]) && (0x04==data[3])) )
179 return 0;
180
181 io.zopen_file = &EXTRACTOR_common_unzip_zlib_open_file_func;
182 io.zread_file = &EXTRACTOR_common_unzip_zlib_read_file_func;
183 io.zwrite_file = NULL;
184 io.ztell_file = &EXTRACTOR_common_unzip_zlib_tell_file_func;
185 io.zseek_file = &EXTRACTOR_common_unzip_zlib_seek_file_func;
186 io.zclose_file = &EXTRACTOR_common_unzip_zlib_close_file_func;
187 io.zerror_file = &EXTRACTOR_common_unzip_zlib_testerror_file_func;
188 io.opaque = ec;
189
190 if (NULL == (uf = EXTRACTOR_common_unzip_open2 ("ERROR", &io)))
191 return; 168 return;
192 if (NULL != (mimetype = libextractor_oo_getmimetype (uf))) 169 if (NULL != (mimetype = libextractor_oo_getmimetype (uf)))
193 { 170 {
194 if (0 != proc (proc_cls, 171 if (0 != ec->proc (ec->cls,
195 "deb", 172 "odf",
196 EXTRACTOR_METATYPE_MIMETYPE, 173 EXTRACTOR_METATYPE_MIMETYPE,
197 EXTRACTOR_METAFORMAT_UTF8, 174 EXTRACTOR_METAFORMAT_UTF8,
198 "text/plain", 175 "text/plain",
199 mimetype, 176 mimetype,
200 strlen (mimetype) + 1)) 177 strlen (mimetype) + 1))
201 { 178 {
202 EXTRACTOR_common_unzip_close (uf); 179 EXTRACTOR_common_unzip_close (uf);
203 free (mimetype); 180 free (mimetype);
@@ -206,9 +183,9 @@ EXTRACTOR_odf_extract_method (struct EXTRACTOR_ExtractContext *ec)
206 free (mimetype); 183 free (mimetype);
207 } 184 }
208 if (EXTRACTOR_UNZIP_OK != 185 if (EXTRACTOR_UNZIP_OK !=
209 EXTRACTOR_common_unzip_local_file (uf, 186 EXTRACTOR_common_unzip_go_find_local_file (uf,
210 METAFILE, 187 METAFILE,
211 CASESENSITIVITY)) 188 2))
212 { 189 {
213 /* metafile not found */ 190 /* metafile not found */
214 EXTRACTOR_common_unzip_close (uf); 191 EXTRACTOR_common_unzip_close (uf);
@@ -219,14 +196,14 @@ EXTRACTOR_odf_extract_method (struct EXTRACTOR_ExtractContext *ec)
219 &file_info, 196 &file_info,
220 filename_inzip, 197 filename_inzip,
221 sizeof (filename_inzip), 198 sizeof (filename_inzip),
222 NULL,0,NULL,0)) 199 NULL, 0, NULL, 0))
223 { 200 {
224 /* problems accessing metafile */ 201 /* problems accessing metafile */
225 EXTRACTOR_common_unzip_close (uf); 202 EXTRACTOR_common_unzip_close (uf);
226 return; 203 return;
227 } 204 }
228 if (EXTRACTOR_UNZIP_OK != 205 if (EXTRACTOR_UNZIP_OK !=
229 EXTRACTOR_common_unzip_open_current_file3 (uf, NULL, NULL, 0)) 206 EXTRACTOR_common_unzip_open_current_file (uf))
230 { 207 {
231 /* problems with unzip */ 208 /* problems with unzip */
232 EXTRACTOR_common_unzip_close (uf); 209 EXTRACTOR_common_unzip_close (uf);
@@ -320,16 +297,14 @@ EXTRACTOR_odf_extract_method (struct EXTRACTOR_ExtractContext *ec)
320 297
321 memcpy(key, spos, epos-spos); 298 memcpy(key, spos, epos-spos);
322 key[epos-spos] = '\0'; 299 key[epos-spos] = '\0';
323 if (0 != proc (proc_cls, 300 if (0 != ec->proc (ec->cls,
324 "odf", 301 "odf",
325 tmap[i].type, 302 tmap[i].type,
326 EXTRACTOR_METAFORMAT_UTF8, 303 EXTRACTOR_METAFORMAT_UTF8,
327 "text/plain", 304 "text/plain",
328 key, 305 key,
329 epos - spos + 1)) 306 epos - spos + 1))
330 { 307 goto CLEANUP;
331 goto CLEANUP;
332 }
333 pbuf = epos; 308 pbuf = epos;
334 } 309 }
335 else 310 else