libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

zip_extractor.c
Go to the documentation of this file.
1 /*
2  * This file is part of libextractor.
3  * Copyright (C) 2012 Vidyut Samanta and Christian Grothoff
4  *
5  * libextractor is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 3, or (at your
8  * option) any later version.
9  *
10  * libextractor is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with libextractor; see the file COPYING. If not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 /**
21  * @file plugins/zip_extractor.c
22  * @brief plugin to support ZIP files
23  * @author Christian Grothoff
24  */
25 #include "platform.h"
26 #include <ctype.h>
27 #include "extractor.h"
28 #include "unzip.h"
29 
30 
31 /**
32  * Main entry method for the 'application/zip' extraction plugin.
33  *
34  * @param ec extraction context provided to the plugin
35  */
36 void
38 {
39  struct EXTRACTOR_UnzipFile *uf;
40  struct EXTRACTOR_UnzipFileInfo fi;
41  char fname[256];
42  char fcomment[256];
43 
44  if (NULL == (uf = EXTRACTOR_common_unzip_open (ec)))
45  return;
46  if ( (EXTRACTOR_UNZIP_OK ==
48  "meta.xml",
49  2)) ||
52  "META-INF/MANIFEST.MF",
53  2)) )
54  {
55  /* not a normal zip, might be odf, jar, etc. */
56  goto CLEANUP;
57  }
58  if (EXTRACTOR_UNZIP_OK !=
60  {
61  /* zip malformed? */
62  goto CLEANUP;
63  }
64  if (0 !=
65  ec->proc (ec->cls,
66  "zip",
69  "text/plain",
70  "application/zip",
71  strlen ("application/zip") + 1))
72  goto CLEANUP;
73  if (EXTRACTOR_UNZIP_OK ==
75  fcomment,
76  sizeof (fcomment)))
77  {
78  if ( (0 != strlen (fcomment)) &&
79  (0 !=
80  ec->proc (ec->cls,
81  "zip",
84  "text/plain",
85  fcomment,
86  strlen (fcomment) + 1)))
87  goto CLEANUP;
88  }
89  do
90  {
91  if (EXTRACTOR_UNZIP_OK ==
93  &fi,
94  fname,
95  sizeof (fname),
96  NULL, 0,
97  fcomment,
98  sizeof (fcomment)))
99  {
100  if ( (0 != strlen (fname)) &&
101  (0 !=
102  ec->proc (ec->cls,
103  "zip",
106  "text/plain",
107  fname,
108  strlen (fname) + 1)))
109  goto CLEANUP;
110  if ( (0 != strlen (fcomment)) &&
111  (0 !=
112  ec->proc (ec->cls,
113  "zip",
116  "text/plain",
117  fcomment,
118  strlen (fcomment) + 1)))
119  goto CLEANUP;
120  }
121  }
122  while (EXTRACTOR_UNZIP_OK ==
124 
125 CLEANUP:
126  (void) EXTRACTOR_common_unzip_close (uf);
127 }
128 
129 
130 /* end of zip_extractor.c */
@ EXTRACTOR_METAFORMAT_C_STRING
Definition: extractor.h:113
@ EXTRACTOR_METAFORMAT_UTF8
Definition: extractor.h:102
#define NULL
Definition: getopt1.c:60
@ EXTRACTOR_METATYPE_COMMENT
Definition: extractor.h:131
@ EXTRACTOR_METATYPE_FILENAME
Definition: extractor.h:130
@ EXTRACTOR_METATYPE_MIMETYPE
Definition: extractor.h:129
plaform specifics
EXTRACTOR_MetaDataProcessor proc
Definition: extractor.h:525
int EXTRACTOR_common_unzip_go_to_next_file(struct EXTRACTOR_UnzipFile *file)
Definition: unzip.c:933
int EXTRACTOR_common_unzip_go_find_local_file(struct EXTRACTOR_UnzipFile *file, const char *szFileName, int iCaseSensitivity)
Definition: unzip.c:969
int EXTRACTOR_common_unzip_get_current_file_info(struct EXTRACTOR_UnzipFile *file, struct EXTRACTOR_UnzipFileInfo *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition: unzip.c:908
struct EXTRACTOR_UnzipFile * EXTRACTOR_common_unzip_open(struct EXTRACTOR_ExtractContext *ec)
Definition: unzip.c:1421
int EXTRACTOR_common_unzip_go_to_first_file(struct EXTRACTOR_UnzipFile *file)
Definition: unzip.c:707
int EXTRACTOR_common_unzip_close(struct EXTRACTOR_UnzipFile *file)
Definition: unzip.c:854
int EXTRACTOR_common_unzip_get_global_comment(struct EXTRACTOR_UnzipFile *file, char *comment, size_t comment_len)
Definition: unzip.c:874
API to access ZIP archives.
#define EXTRACTOR_UNZIP_OK
Definition: unzip.h:37
void EXTRACTOR_zip_extract_method(struct EXTRACTOR_ExtractContext *ec)
Definition: zip_extractor.c:37