[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r1645 - Extractor/src/plugins/ole2
From: |
grothoff |
Subject: |
[GNUnet-SVN] r1645 - Extractor/src/plugins/ole2 |
Date: |
Sat, 13 Aug 2005 17:40:20 -0700 (PDT) |
Author: grothoff
Date: 2005-08-13 17:40:17 -0700 (Sat, 13 Aug 2005)
New Revision: 1645
Removed:
Extractor/src/plugins/ole2/gsf-impl-utils.h
Extractor/src/plugins/ole2/gsf-infile-impl.h
Extractor/src/plugins/ole2/gsf-infile.h
Extractor/src/plugins/ole2/gsf-input-impl.h
Extractor/src/plugins/ole2/gsf-input-memory.c
Extractor/src/plugins/ole2/gsf-input-memory.h
Extractor/src/plugins/ole2/gsf-msole-impl.h
Extractor/src/plugins/ole2/gsf-shared-memory.c
Extractor/src/plugins/ole2/gsf-shared-memory.h
Extractor/src/plugins/ole2/gsf.h
Modified:
Extractor/src/plugins/ole2/Makefile.am
Extractor/src/plugins/ole2/gsf-infile-msole.c
Extractor/src/plugins/ole2/gsf-infile-msole.h
Extractor/src/plugins/ole2/gsf-input.c
Extractor/src/plugins/ole2/gsf-input.h
Extractor/src/plugins/ole2/gsf-utils.c
Extractor/src/plugins/ole2/gsf-utils.h
Extractor/src/plugins/ole2/ole2extractor.c
Log:
big code cleanup
Modified: Extractor/src/plugins/ole2/Makefile.am
===================================================================
--- Extractor/src/plugins/ole2/Makefile.am 2005-08-13 13:49:03 UTC (rev
1644)
+++ Extractor/src/plugins/ole2/Makefile.am 2005-08-14 00:40:17 UTC (rev
1645)
@@ -13,36 +13,19 @@
AM_CFLAGS = $(GLIB_CFLAGS)
-if MINGW
- WINFLAGS = -lgobject-2.0
-endif
-
libextractor_ole2_la_CFLAGS = \
$(GLIB_CFLAGS)
libextractor_ole2_la_LIBADD = \
- $(LIBADD) $(GLIB_LIBS) $(WINFLAGS) \
+ $(LIBADD) $(GLIB_LIBS) -lgobject-2.0 \
$(top_builddir)/src/main/libextractor.la
-# Ok, linking this one is complicated, see Mantis #787.
libextractor_ole2_la_LDFLAGS = \
- -Wl,-Bstatic -Wl,-lgobject-2.0 -Wl,-lglib-2.0 -Wl,-Bdynamic \
- -Wl,-Bsymbolic -avoid-version -module
+ -export-dynamic -avoid-version -module
# Note that we're NOT using PLUGINFLAGS here to avoid -export-dynamic!
libextractor_ole2_la_SOURCES = \
ole2extractor.c \
- gsf.h \
gsf-utils.c \
gsf-utils.h \
- gsf-impl-utils.h \
gsf-input.c \
gsf-input.h \
- gsf-input-impl.h \
- gsf-input-memory.c \
- gsf-input-memory.h \
- gsf-infile.h \
- gsf-infile.c \
- gsf-infile-impl.h \
gsf-infile-msole.c \
- gsf-infile-msole.h \
- gsf-msole-impl.h \
- gsf-shared-memory.c \
- gsf-shared-memory.h
+ gsf-infile-msole.h
Deleted: Extractor/src/plugins/ole2/gsf-impl-utils.h
===================================================================
--- Extractor/src/plugins/ole2/gsf-impl-utils.h 2005-08-13 13:49:03 UTC (rev
1644)
+++ Extractor/src/plugins/ole2/gsf-impl-utils.h 2005-08-14 00:40:17 UTC (rev
1645)
@@ -1,100 +0,0 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t;
c-basic-offset: 8 -*- */
-/*
- * gsf-impl-utils.h:
- *
- * Copyright (C) 2002-2004 Jody Goldberg (address@hidden)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef GSF_IMPL_UTILS_H
-#define GSF_IMPL_UTILS_H
-
-#include "gsf.h"
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define GSF_CLASS_FULL(name, prefix, class_init, instance_init,
parent_type, \
- abstract, interface_decl) \
-GType \
-prefix ## _get_type (void) \
-{ \
- static GType type = 0; \
- if (type == 0) { \
- static GTypeInfo const object_info = { \
- sizeof (name ## Class), \
- (GBaseInitFunc) NULL, \
- (GBaseFinalizeFunc) NULL, \
- (GClassInitFunc) class_init, \
- (GClassFinalizeFunc) NULL, \
- NULL, /* class_data */ \
- sizeof (name), \
- 0, /* n_preallocs */ \
- (GInstanceInitFunc) instance_init, \
- NULL \
- }; \
- type = g_type_register_static (parent_type, #name, \
- &object_info, (GTypeFlags) abstract); \
- interface_decl \
- } \
- return type; \
-}
-
-#define GSF_CLASS(name, prefix, class_init, instance_init, parent) \
- GSF_CLASS_FULL(name, prefix, class_init, instance_init, parent, \
- 0, {})
-#define GSF_CLASS_ABSTRACT(name, prefix, class_init, instance_init,
parent) \
- GSF_CLASS_FULL(name, prefix, class_init, instance_init, parent, \
- G_TYPE_FLAG_ABSTRACT, {})
-
-#define GSF_DYNAMIC_CLASS_FULL(name, prefix, class_init, instance_init,
parent_type, \
- abstract, interface_decl, plugin, type) \
- if (type == 0) { \
- static GTypeInfo const type_info = { \
- sizeof (name ## Class), \
- (GBaseInitFunc) NULL, \
- (GBaseFinalizeFunc) NULL, \
- (GClassInitFunc) class_init, \
- (GClassFinalizeFunc) NULL, \
- NULL, /* class_data */ \
- sizeof (name), \
- 0, /* n_preallocs */ \
- (GInstanceInitFunc) instance_init, \
- NULL \
- }; \
- type = g_type_module_register_type (plugin, parent_type, #name,
\
- &type_info, (GTypeFlags) abstract); \
- interface_decl \
- }
-
-#define GSF_DYNAMIC_CLASS(name, prefix, class_init, instance_init,
parent, plugin, type) \
- GSF_DYNAMIC_CLASS_FULL(name, prefix, class_init, instance_init, parent,
\
- 0, {}, plugin, type)
-#define GSF_DYNAMIC_CLASS_ABSTRACT(name, prefix, class_init,
instance_init, parent, plugin, type) \
- GSF_DYNAMIC_CLASS_FULL(name, prefix, class_init, instance_init, parent,
\
- G_TYPE_FLAG_ABSTRACT, {}, plugin, type)
-
-#define GSF_INTERFACE_FULL(type, init_func, iface_type) { \
- static GInterfaceInfo const iface = { \
- (GInterfaceInitFunc) init_func, NULL, NULL }; \
- g_type_add_interface_static (type, iface_type, &iface); \
-}
-#define GSF_INTERFACE(init_func, iface_type) \
- GSF_INTERFACE_FULL(type, init_func, iface_type)
-
-G_END_DECLS
-
-#endif /* GSF_IMPL_UTILS_H */
Deleted: Extractor/src/plugins/ole2/gsf-infile-impl.h
===================================================================
--- Extractor/src/plugins/ole2/gsf-infile-impl.h 2005-08-13 13:49:03 UTC
(rev 1644)
+++ Extractor/src/plugins/ole2/gsf-infile-impl.h 2005-08-14 00:40:17 UTC
(rev 1645)
@@ -1,50 +0,0 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t;
c-basic-offset: 8 -*- */
-/*
- * gsf-infile-impl.h:
- *
- * Copyright (C) 2002-2004 Jody Goldberg (address@hidden)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef GSF_INFILE_IMPL_H
-#define GSF_INFILE_IMPL_H
-
-#include "gsf.h"
-#include "gsf-input-impl.h"
-#include "gsf-infile.h"
-
-G_BEGIN_DECLS
-
-struct _GsfInfile {
- GsfInput parent;
-};
-
-typedef struct {
- GsfInputClass input_class;
- int (*num_children) (GsfInfile *infile);
- const char *(*name_by_index) (GsfInfile *infile, int i);
- GsfInput *(*child_by_index) (GsfInfile *infile,
- int i, GError **err);
- GsfInput *(*child_by_name) (GsfInfile *infile,
- char const *name, GError **err);
-} GsfInfileClass;
-
-#define GSF_INFILE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GSF_INFILE_TYPE,
GsfInfileClass))
-#define GSF_IS_INFILE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSF_INFILE_TYPE))
-
-G_END_DECLS
-
-#endif /* GSF_INFILE_IMPL_H */
Modified: Extractor/src/plugins/ole2/gsf-infile-msole.c
===================================================================
--- Extractor/src/plugins/ole2/gsf-infile-msole.c 2005-08-13 13:49:03 UTC
(rev 1644)
+++ Extractor/src/plugins/ole2/gsf-infile-msole.c 2005-08-14 00:40:17 UTC
(rev 1645)
@@ -20,21 +20,70 @@
*/
#include "platform.h"
-#include "gsf-infile-impl.h"
+#include <glib-object.h>
+#include "gsf-input.h"
#include "gsf-infile-msole.h"
-#include "gsf-impl-utils.h"
#include "gsf-utils.h"
-#include "gsf-msole-impl.h"
#include <string.h>
#include <stdio.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "libgsf:msole"
+#define OLE_HEADER_SIZE 0x200 /* independent of big block
size size */
+#define OLE_HEADER_SIGNATURE 0x00
+#define OLE_HEADER_CLSID 0x08 /* See ReadClassStg */
+#define OLE_HEADER_MINOR_VER 0x18 /* 0x33 and 0x3e have been seen */
+#define OLE_HEADER_MAJOR_VER 0x1a /* 0x3 been seen in wild */
+#define OLE_HEADER_BYTE_ORDER 0x1c /* 0xfe 0xff == Intel Little Endian */
+#define OLE_HEADER_BB_SHIFT 0x1e
+#define OLE_HEADER_SB_SHIFT 0x20
+/* 0x22..0x27 reserved == 0 */
+#define OLE_HEADER_CSECTDIR 0x28
+#define OLE_HEADER_NUM_BAT 0x2c
+#define OLE_HEADER_DIRENT_START 0x30
+/* 0x34..0x37 transacting signature must be 0 */
+#define OLE_HEADER_THRESHOLD 0x38
+#define OLE_HEADER_SBAT_START 0x3c
+#define OLE_HEADER_NUM_SBAT 0x40
+#define OLE_HEADER_METABAT_BLOCK 0x44
+#define OLE_HEADER_NUM_METABAT 0x48
+#define OLE_HEADER_START_BAT 0x4c
+#define BAT_INDEX_SIZE 4
+#define OLE_HEADER_METABAT_SIZE ((OLE_HEADER_SIZE -
OLE_HEADER_START_BAT) / BAT_INDEX_SIZE)
+#define DIRENT_MAX_NAME_SIZE 0x40
+#define DIRENT_DETAILS_SIZE 0x40
+#define DIRENT_SIZE (DIRENT_MAX_NAME_SIZE + DIRENT_DETAILS_SIZE)
+#define DIRENT_NAME_LEN 0x40 /* length in bytes incl 0
terminator */
+#define DIRENT_TYPE 0x42
+#define DIRENT_COLOUR 0x43
+#define DIRENT_PREV 0x44
+#define DIRENT_NEXT 0x48
+#define DIRENT_CHILD 0x4c
+#define DIRENT_CLSID 0x50 /* only for dirs */
+#define DIRENT_USERFLAGS 0x60 /* only for dirs */
+#define DIRENT_CREATE_TIME 0x64 /* for files */
+#define DIRENT_MODIFY_TIME 0x6c /* for files */
+#define DIRENT_FIRSTBLOCK 0x74
+#define DIRENT_FILE_SIZE 0x78
+/* 0x7c..0x7f reserved == 0 */
-static GObjectClass *parent_class;
+#define DIRENT_TYPE_INVALID 0
+#define DIRENT_TYPE_DIR 1
+#define DIRENT_TYPE_FILE 2
+#define DIRENT_TYPE_LOCKBYTES 3 /* ? */
+#define DIRENT_TYPE_PROPERTY 4 /* ? */
+#define DIRENT_TYPE_ROOTDIR 5
+#define DIRENT_MAGIC_END 0xffffffff
+/* flags in the block allocation list to denote special blocks */
+#define BAT_MAGIC_UNUSED 0xffffffff /* -1 */
+#define BAT_MAGIC_END_OF_CHAIN 0xfffffffe /* -2 */
+#define BAT_MAGIC_BAT 0xfffffffd /* a bat block, -3 */
+#define BAT_MAGIC_METABAT 0xfffffffc /* a metabat block -4 */
+
+
+
+
typedef struct {
guint32 *block;
guint32 num_blocks;
@@ -59,44 +108,36 @@
unsigned filter;
size_t size;
} bb, sb;
- gsf_off_t max_block;
+ off_t max_block;
guint32 threshold; /* transition between small and big blocks */
guint32 sbat_start, num_sbat;
MSOleDirent *root_dir;
- GsfInput *sb_file;
+ struct GsfInput *sb_file;
int ref_count;
} MSOleInfo;
-struct _GsfInfileMSOle {
- GsfInfile parent;
-
- GsfInput *input;
+typedef struct GsfInfileMSOle {
+ off_t size;
+ off_t cur_offset;
+ struct GsfInput *input;
MSOleInfo *info;
MSOleDirent *dirent;
MSOleBAT bat;
- gsf_off_t cur_block;
+ off_t cur_block;
struct {
guint8 *buf;
size_t buf_size;
} stream;
-};
+} GsfInfileMSOle;
-typedef struct {
- GsfInfileClass parent_class;
-} GsfInfileMSOleClass;
-
-#define GSF_INFILE_MSOLE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k),
GSF_INFILE_MSOLE_TYPE, GsfInfileMSOleClass))
-#define GSF_IS_INFILE_MSOLE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k),
GSF_INFILE_MSOLE_TYPE))
-
/* utility macros */
#define OLE_BIG_BLOCK(index, ole) ((index) >> ole->info->bb.shift)
-static GsfInput *gsf_infile_msole_new_child (GsfInfileMSOle *parent,
- MSOleDirent *dirent, GError **err);
-static void ole_info_unref (MSOleInfo *info);
+static struct GsfInput *gsf_infile_msole_new_child (GsfInfileMSOle *parent,
+ MSOleDirent *dirent);
/**
* ole_get_block :
@@ -107,16 +148,16 @@
* Read a block of data from the underlying input.
* Be really anal.
**/
-static guint8 const *
-ole_get_block (GsfInfileMSOle const *ole, guint32 block, guint8 *buffer)
+static const guint8 *
+ole_get_block (const GsfInfileMSOle *ole, guint32 block, guint8 *buffer)
{
g_return_val_if_fail (block < ole->info->max_block, NULL);
/* OLE_HEADER_SIZE is fixed at 512, but the sector containing the
* header is padded out to bb.size (sector size) when bb.size > 512. */
if (gsf_input_seek (ole->input,
- (gsf_off_t)(MAX (OLE_HEADER_SIZE, ole->info->bb.size) + (block
<< ole->info->bb.shift)),
- G_SEEK_SET) < 0)
+ (off_t)(MAX (OLE_HEADER_SIZE, ole->info->bb.size) + (block <<
ole->info->bb.shift)),
+ SEEK_SET) < 0)
return NULL;
return gsf_input_read (ole->input, ole->info->bb.size, buffer);
@@ -132,7 +173,7 @@
* Walk the linked list of the supplied block allocation table and build up a
* table for the list starting in @block.
*
- * Retrurns TRUE on error.
+ * Returns TRUE on error.
*/
static gboolean
ole_make_bat (MSOleBAT const *metabat, size_t size_guess, guint32 block,
@@ -227,7 +268,7 @@
*dst++ = GSF_LE_GET_GUINT32 (src);
}
-static GsfInput *
+static struct GsfInput *
ole_info_get_sb_file (GsfInfileMSOle *parent)
{
MSOleBAT meta_sbat;
@@ -236,16 +277,19 @@
return parent->info->sb_file;
parent->info->sb_file = gsf_infile_msole_new_child (parent,
- parent->info->root_dir, NULL);
+ parent->info->root_dir);
- /* avoid creating a circular reference */
- ole_info_unref (((GsfInfileMSOle *)parent->info->sb_file)->info);
+ if (NULL == parent->info->sb_file)
+ return NULL;
g_return_val_if_fail (parent->info->sb.bat.block == NULL, NULL);
if (ole_make_bat (&parent->info->bb.bat,
- parent->info->num_sbat, parent->info->sbat_start,
&meta_sbat))
+ parent->info->num_sbat,
+ parent->info->sbat_start,
+ &meta_sbat)) {
return NULL;
+ }
parent->info->sb.bat.num_blocks = meta_sbat.num_blocks *
(parent->info->bb.size / BAT_INDEX_SIZE);
parent->info->sb.bat.block = g_new0 (guint32,
parent->info->sb.bat.num_blocks);
@@ -258,7 +302,7 @@
}
static gint
-ole_dirent_cmp (MSOleDirent const *a, MSOleDirent const *b)
+ole_dirent_cmp (const MSOleDirent *a, const MSOleDirent *b)
{
g_return_val_if_fail (a, 0);
g_return_val_if_fail (b, 0);
@@ -301,14 +345,16 @@
if (type != DIRENT_TYPE_DIR &&
type != DIRENT_TYPE_FILE &&
type != DIRENT_TYPE_ROOTDIR) {
+#if 0
g_warning ("Unknown stream type 0x%x", type);
+#endif
return NULL;
}
/* It looks like directory (and root directory) sizes are sometimes
bogus */
size = GSF_LE_GET_GUINT32 (data + DIRENT_FILE_SIZE);
g_return_val_if_fail (type == DIRENT_TYPE_DIR || type ==
DIRENT_TYPE_ROOTDIR ||
- size <= (guint32)ole->input->size, NULL);
+ size <= (guint32)gsf_input_size(ole->input),
NULL);
dirent = g_new0 (MSOleDirent, 1);
dirent->index = entry;
@@ -351,37 +397,18 @@
dirent->name = g_strdup ("");
dirent->collation_name = g_utf8_collate_key (dirent->name, -1);
-#if 0
- printf ("%c '%s' :\tsize = %d\tfirst_block = 0x%x\n",
- dirent->is_directory ? 'd' : ' ',
- dirent->name, dirent->size, dirent->first_block);
-#endif
-
if (parent != NULL)
parent->children = g_list_insert_sorted (parent->children,
dirent, (GCompareFunc)ole_dirent_cmp);
/* NOTE : These links are a tree, not a linked list */
- if (prev == entry) {
-#if 0
- g_warning ("Invalid OLE file with a cycle in its directory
tree");
-#endif
- } else
+ if (prev != entry)
ole_dirent_new (ole, prev, parent);
- if (next == entry) {
-#if 0
- g_warning ("Invalid OLE file with a cycle in its directory
tree");
-#endif
- } else
+ if (next != entry)
ole_dirent_new (ole, next, parent);
if (dirent->is_directory)
ole_dirent_new (ole, child, dirent);
-#if 0
- else if (child != DIRENT_MAGIC_END)
- g_warning ("A non directory stream with children ?");
-#endif
-
return dirent;
}
@@ -415,7 +442,7 @@
info->root_dir = NULL;
}
if (info->sb_file != NULL) {
- g_object_unref (G_OBJECT (info->sb_file));
+ gsf_input_finalize(info->sb_file);
info->sb_file = NULL;
}
g_free (info);
@@ -428,6 +455,20 @@
return info;
}
+static void
+gsf_infile_msole_init (GsfInfileMSOle * ole)
+{
+ ole->cur_offset = 0;
+ ole->size = 0;
+ ole->input = NULL;
+ ole->info = NULL;
+ ole->bat.block = NULL;
+ ole->bat.num_blocks = 0;
+ ole->cur_block = BAT_MAGIC_UNUSED;
+ ole->stream.buf = NULL;
+ ole->stream.buf_size = 0;
+}
+
/**
* ole_dup :
* @src :
@@ -438,22 +479,22 @@
* Return value: the partial duplicate.
**/
static GsfInfileMSOle *
-ole_dup (GsfInfileMSOle const *src, GError **err)
+ole_dup (GsfInfileMSOle const * src)
{
GsfInfileMSOle *dst;
- GsfInput *input;
+ struct GsfInput *input;
g_return_val_if_fail (src != NULL, NULL);
- dst = (GsfInfileMSOle *)g_object_new (GSF_INFILE_MSOLE_TYPE, NULL);
+ dst = malloc(sizeof(GsfInfileMSOle));
if (dst == NULL)
return NULL;
-
- input = gsf_input_dup (src->input, err);
- if (input == NULL)
+ gsf_infile_msole_init(dst);
+ input = gsf_input_dup (src->input);
+ if (input == NULL) {
+ gsf_infile_msole_finalize(dst);
return NULL;
-
-
+ }
dst->input = input;
dst->info = ole_info_ref (src->info);
@@ -461,19 +502,18 @@
return dst;
}
-
+
/**
* ole_init_info :
* @ole :
- * @err : optionally NULL
*
* Read an OLE header and do some sanity checking
* along the way.
*
- * Return value: TRUE on error setting @err if it is supplied.
+ * Return value: TRUE on error
**/
static gboolean
-ole_init_info (GsfInfileMSOle *ole, GError **err)
+ole_init_info (GsfInfileMSOle *ole)
{
static guint8 const signature[] =
{ 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1 };
@@ -484,12 +524,9 @@
guint32 metabat_block, *ptr;
/* check the header */
- if (gsf_input_seek (ole->input, (gsf_off_t) 0, G_SEEK_SET) ||
+ if (gsf_input_seek (ole->input, (off_t) 0, SEEK_SET) ||
NULL == (header = gsf_input_read (ole->input, OLE_HEADER_SIZE,
NULL)) ||
0 != memcmp (header, signature, sizeof (signature))) {
- if (err != NULL)
- *err = g_error_new (gsf_input_error (), 0,
- "No OLE2 signature");
return TRUE;
}
@@ -506,9 +543,6 @@
* Maybe relax this later, but not much.
*/
if (6 > bb_shift || bb_shift >= 31 || sb_shift > bb_shift) {
- if (err != NULL)
- *err = g_error_new (gsf_input_error (), 0,
- "Unreasonable block sizes");
return TRUE;
}
@@ -583,78 +617,44 @@
}
if (ptr == NULL) {
- if (err != NULL)
- *err = g_error_new (gsf_input_error (), 0,
- "Inconsistent block allocation table");
return TRUE;
}
/* Read the directory's bat, we do not know the size */
if (ole_make_bat (&info->bb.bat, 0, dirent_start, &ole->bat)) {
- if (err != NULL)
- *err = g_error_new (gsf_input_error (), 0,
- "Problems making block allocation table");
return TRUE;
}
/* Read the directory */
ole->dirent = info->root_dir = ole_dirent_new (ole, 0, NULL);
if (ole->dirent == NULL) {
- if (err != NULL)
- *err = g_error_new (gsf_input_error (), 0,
- "Problems reading directory");
return TRUE;
}
return FALSE;
}
-static void
-gsf_infile_msole_finalize (GObject *obj)
+void
+gsf_infile_msole_finalize (GsfInfileMSOle * ole)
{
- GsfInfileMSOle *ole = GSF_INFILE_MSOLE (obj);
-
if (ole->input != NULL) {
- g_object_unref (G_OBJECT (ole->input));
+ gsf_input_finalize(ole->input);
ole->input = NULL;
}
- if (ole->info != NULL &&
- ole->info->sb_file != (GsfInput *)ole) {
+ if (ole->info != NULL) {
ole_info_unref (ole->info);
ole->info = NULL;
}
ols_bat_release (&ole->bat);
g_free (ole->stream.buf);
-
- parent_class->finalize (obj);
+ free(ole);
}
-
-static GsfInput *
-gsf_infile_msole_dup (GsfInput *src_input, GError **err)
-{
- GsfInfileMSOle const *src = GSF_INFILE_MSOLE (src_input);
- GsfInfileMSOle *dst = ole_dup (src, err);
-
- if (dst == NULL)
- return NULL;
-
- if (src->bat.block != NULL) {
- dst->bat.block = g_new (guint32, src->bat.num_blocks),
- memcpy (dst->bat.block, src->bat.block,
- sizeof (guint32) * src->bat.num_blocks);
- }
- dst->bat.num_blocks = src->bat.num_blocks;
- dst->dirent = src->dirent;
-
- return GSF_INPUT (dst);
-}
-
+
static guint8 const *
-gsf_infile_msole_read (GsfInput *input, size_t num_bytes, guint8 *buffer)
+gsf_infile_msole_read (GsfInfileMSOle *ole, size_t num_bytes, guint8 *buffer)
{
- GsfInfileMSOle *ole = GSF_INFILE_MSOLE (input);
- gsf_off_t first_block, last_block, raw_block, offset, i;
+ off_t first_block, last_block, raw_block, offset, i;
guint8 const *data;
guint8 *ptr;
size_t count;
@@ -662,16 +662,19 @@
/* small block files are preload */
if (ole->dirent != NULL && ole->dirent->use_sb) {
if (buffer != NULL) {
- memcpy (buffer, ole->stream.buf + input->cur_offset,
num_bytes);
+ memcpy (buffer, ole->stream.buf + ole->cur_offset,
num_bytes);
+ ole->cur_offset += num_bytes;
return buffer;
}
- return ole->stream.buf + input->cur_offset;
+ data = ole->stream.buf + ole->cur_offset;
+ ole->cur_offset += num_bytes;
+ return data;
}
/* GsfInput guarantees that num_bytes > 0 */
- first_block = OLE_BIG_BLOCK (input->cur_offset, ole);
- last_block = OLE_BIG_BLOCK (input->cur_offset + num_bytes - 1, ole);
- offset = input->cur_offset & ole->info->bb.filter;
+ first_block = OLE_BIG_BLOCK (ole->cur_offset, ole);
+ last_block = OLE_BIG_BLOCK (ole->cur_offset + num_bytes - 1, ole);
+ offset = ole->cur_offset & ole->info->bb.filter;
/* optimization : are all the raw blocks contiguous */
i = first_block;
@@ -682,8 +685,8 @@
/* optimization don't seek if we don't need to */
if (ole->cur_block != first_block) {
if (gsf_input_seek (ole->input,
- (gsf_off_t)(MAX (OLE_HEADER_SIZE,
ole->info->bb.size) + (ole->bat.block [first_block] << ole->info->bb.shift) +
offset),
- G_SEEK_SET) < 0)
+ (off_t)(MAX (OLE_HEADER_SIZE,
ole->info->bb.size) + (ole->bat.block [first_block] << ole->info->bb.shift) +
offset),
+ SEEK_SET) < 0)
return NULL;
}
ole->cur_block = last_block;
@@ -715,53 +718,39 @@
offset = 0;
}
ole->cur_block = BAT_MAGIC_UNUSED;
-
+ ole->cur_offset += num_bytes;
return buffer;
}
-
-static gboolean
-gsf_infile_msole_seek (GsfInput *input, gsf_off_t offset, GSeekType whence)
-{
- GsfInfileMSOle *ole = GSF_INFILE_MSOLE (input);
-
- (void) offset;
- (void) whence;
-
- ole->cur_block = BAT_MAGIC_UNUSED;
- return FALSE;
-}
-
-static GsfInput *
+
+static struct GsfInput *
gsf_infile_msole_new_child (GsfInfileMSOle *parent,
- MSOleDirent *dirent, GError **err)
+ MSOleDirent *dirent)
{
- GsfInfileMSOle *child;
+ GsfInfileMSOle * child;
MSOleInfo *info;
MSOleBAT const *metabat;
- GsfInput *sb_file = NULL;
+ struct GsfInput *sb_file = NULL;
size_t size_guess;
+ char * buf;
+
- child = ole_dup (parent, err);
- child->dirent = dirent;
- gsf_input_set_size (GSF_INPUT (child), (gsf_off_t) dirent->size);
-
- /* The root dirent defines the small block file */
- if (dirent->index != 0) {
- gsf_input_set_name (GSF_INPUT (child), dirent->name);
- gsf_input_set_container (GSF_INPUT (child), GSF_INFILE
(parent));
-
- if (dirent->is_directory) {
- /* be wary. It seems as if some implementations
pretend that the
- * directories contain data */
- gsf_input_set_size (GSF_INPUT (child), 0);
- return GSF_INPUT (child);
- }
+ if ( (dirent->index != 0) &&
+ (dirent->is_directory) ) {
+ /* be wary. It seems as if some implementations pretend that
the
+ * directories contain data */
+ return gsf_input_new("",
+ (off_t) 0,
+ 0);
}
-
+ child = ole_dup (parent);
+ if (child == NULL)
+ return NULL;
+ child->dirent = dirent;
+ child->size = (off_t) dirent->size;
+
info = parent->info;
- /* build the bat */
- if (dirent->use_sb) {
+ if (dirent->use_sb) { /* build the bat */
metabat = &info->sb.bat;
size_guess = dirent->size >> info->sb.shift;
sb_file = ole_info_get_sb_file (parent);
@@ -770,55 +759,65 @@
size_guess = dirent->size >> info->bb.shift;
}
if (ole_make_bat (metabat, size_guess + 1, dirent->first_block,
&child->bat)) {
- g_object_unref (G_OBJECT (child));
+ gsf_infile_msole_finalize(child);
return NULL;
}
if (dirent->use_sb) {
unsigned i;
guint8 const *data;
+
+ if (sb_file == NULL) {
+ gsf_infile_msole_finalize(child);
+ return NULL;
+ }
- g_return_val_if_fail (sb_file != NULL, NULL);
-
child->stream.buf_size = info->threshold;
child->stream.buf = g_new (guint8, info->threshold);
for (i = 0 ; i < child->bat.num_blocks; i++)
- if (gsf_input_seek (GSF_INPUT (sb_file),
- (gsf_off_t)(child->bat.block [i] <<
info->sb.shift), G_SEEK_SET) < 0 ||
- (data = gsf_input_read (GSF_INPUT (sb_file),
- info->sb.size,
+ if (gsf_input_seek (sb_file,
+ (off_t)(child->bat.block [i] <<
info->sb.shift), SEEK_SET) < 0 ||
+ (data = gsf_input_read (sb_file,
+ info->sb.size,
child->stream.buf + (i << info->sb.shift))) ==
NULL) {
-
-#if 0
- g_warning ("failure reading block %d", i);
-#endif
-
- g_object_unref (G_OBJECT (child));
+ gsf_infile_msole_finalize(child);
return NULL;
}
}
-
- return GSF_INPUT (child);
+ buf = malloc(child->size);
+ if (buf == NULL) {
+ gsf_infile_msole_finalize(child);
+ return NULL;
+ }
+ if (NULL == gsf_infile_msole_read(child,
+ child->size,
+ buf)) {
+ gsf_infile_msole_finalize(child);
+ return NULL;
+ }
+ gsf_infile_msole_finalize(child);
+ return gsf_input_new(buf,
+ (off_t) dirent->size,
+ 1);
}
+
-static GsfInput *
-gsf_infile_msole_child_by_index (GsfInfile *infile, int target, GError **err)
+struct GsfInput *
+gsf_infile_msole_child_by_index (GsfInfileMSOle * ole, int target)
{
- GsfInfileMSOle *ole = GSF_INFILE_MSOLE (infile);
GList *p;
for (p = ole->dirent->children; p != NULL ; p = p->next)
if (target-- <= 0)
return gsf_infile_msole_new_child (ole,
- (MSOleDirent *)p->data, err);
+ (MSOleDirent *)p->data);
return NULL;
}
-static char const *
-gsf_infile_msole_name_by_index (GsfInfile *infile, int target)
+char const *
+gsf_infile_msole_name_by_index (GsfInfileMSOle * ole, int target)
{
- GsfInfileMSOle *ole = GSF_INFILE_MSOLE (infile);
GList *p;
for (p = ole->dirent->children; p != NULL ; p = p->next)
@@ -827,25 +826,9 @@
return NULL;
}
-static GsfInput *
-gsf_infile_msole_child_by_name (GsfInfile *infile, char const *name, GError
**err)
+int
+gsf_infile_msole_num_children (GsfInfileMSOle * ole)
{
- GsfInfileMSOle *ole = GSF_INFILE_MSOLE (infile);
- GList *p;
-
- for (p = ole->dirent->children; p != NULL ; p = p->next) {
- MSOleDirent *dirent = p->data;
- if (dirent->name != NULL && !strcmp (name, dirent->name))
- return gsf_infile_msole_new_child (ole, dirent, err);
- }
- return NULL;
-}
-
-static int
-gsf_infile_msole_num_children (GsfInfile *infile)
-{
- GsfInfileMSOle *ole = GSF_INFILE_MSOLE (infile);
-
g_return_val_if_fail (ole->dirent != NULL, -1);
if (!ole->dirent->is_directory)
@@ -853,76 +836,34 @@
return g_list_length (ole->dirent->children);
}
-static void
-gsf_infile_msole_init (GObject *obj)
-{
- GsfInfileMSOle *ole = GSF_INFILE_MSOLE (obj);
- ole->input = NULL;
- ole->info = NULL;
- ole->bat.block = NULL;
- ole->bat.num_blocks = 0;
- ole->cur_block = BAT_MAGIC_UNUSED;
- ole->stream.buf = NULL;
- ole->stream.buf_size = 0;
-}
-
-static void
-gsf_infile_msole_class_init (GObjectClass *gobject_class)
-{
- GsfInputClass *input_class = GSF_INPUT_CLASS (gobject_class);
- GsfInfileClass *infile_class = GSF_INFILE_CLASS (gobject_class);
-
- gobject_class->finalize = gsf_infile_msole_finalize;
- input_class->Dup = gsf_infile_msole_dup;
- input_class->Read = gsf_infile_msole_read;
- input_class->Seek = gsf_infile_msole_seek;
- infile_class->num_children = gsf_infile_msole_num_children;
- infile_class->name_by_index = gsf_infile_msole_name_by_index;
- infile_class->child_by_index = gsf_infile_msole_child_by_index;
- infile_class->child_by_name = gsf_infile_msole_child_by_name;
-
- parent_class = g_type_class_peek_parent (gobject_class);
-}
-
-GSF_CLASS (GsfInfileMSOle, gsf_infile_msole,
- gsf_infile_msole_class_init, gsf_infile_msole_init,
- GSF_INFILE_TYPE)
-
/**
* gsf_infile_msole_new :
* @source :
- * @err :
*
* Opens the root directory of an MS OLE file.
* NOTE : adds a reference to @source
*
* Returns : the new ole file handler
**/
-GsfInfile *
-gsf_infile_msole_new (GsfInput *source, GError **err)
+GsfInfileMSOle *
+gsf_infile_msole_new (struct GsfInput *source)
{
- GsfInfileMSOle *ole;
- gsf_off_t calling_pos;
+ GsfInfileMSOle * ole;
- g_return_val_if_fail (GSF_IS_INPUT (source), NULL);
-
- ole = (GsfInfileMSOle *)g_object_new (GSF_INFILE_MSOLE_TYPE, NULL);
+ ole = malloc(sizeof(GsfInfileMSOle));
if (ole == NULL)
return NULL;
- g_object_ref (G_OBJECT (source));
+ gsf_infile_msole_init(ole);
ole->input = source;
- gsf_input_set_size (GSF_INPUT (ole), (gsf_off_t) 0);
+ ole->size = (off_t) 0;
- calling_pos = gsf_input_tell (source);
- if (ole_init_info (ole, err)) {
- gsf_input_seek (source, calling_pos, G_SEEK_SET);
-
- g_object_unref (G_OBJECT (ole));
+ if (ole_init_info (ole)) {
+ gsf_infile_msole_finalize(ole);
return NULL;
}
- return GSF_INFILE (ole);
+ return ole;
}
/**
@@ -935,12 +876,13 @@
*
* Returns TRUE on success
**/
-gboolean
-gsf_infile_msole_get_class_id (GsfInfileMSOle const *ole, guint8 *res)
+int
+gsf_infile_msole_get_class_id (const GsfInfileMSOle *ole,
+ unsigned char * res)
{
- g_return_val_if_fail (ole != NULL && ole->dirent != NULL, FALSE);
+ g_return_val_if_fail (ole != NULL && ole->dirent != NULL, 0);
memcpy (res, ole->dirent->clsid,
sizeof(ole->dirent->clsid));
- return TRUE;
+ return 1;
}
Modified: Extractor/src/plugins/ole2/gsf-infile-msole.h
===================================================================
--- Extractor/src/plugins/ole2/gsf-infile-msole.h 2005-08-13 13:49:03 UTC
(rev 1644)
+++ Extractor/src/plugins/ole2/gsf-infile-msole.h 2005-08-14 00:40:17 UTC
(rev 1645)
@@ -22,21 +22,39 @@
#ifndef GSF_INFILE_MSOLE_H
#define GSF_INFILE_MSOLE_H
-#include "gsf.h"
+#include "gsf-input.h"
-G_BEGIN_DECLS
+struct GsfInfileMSOle;
-typedef struct _GsfInfileMSOle GsfInfileMSOle;
+struct GsfInfileMSOle * gsf_infile_msole_new (struct GsfInput *source);
+int gsf_infile_msole_get_class_id (const struct GsfInfileMSOle * ole,
+ unsigned char * res);
-#define GSF_INFILE_MSOLE_TYPE (gsf_infile_msole_get_type ())
-#define GSF_INFILE_MSOLE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),
GSF_INFILE_MSOLE_TYPE, GsfInfileMSOle))
-#define GSF_IS_INFILE_MSOLE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o),
GSF_INFILE_MSOLE_TYPE))
+int
+gsf_infile_msole_num_children (struct GsfInfileMSOle *infile);
-GType gsf_infile_msole_get_type (void);
-GsfInfile *gsf_infile_msole_new (GsfInput *source, GError
**err);
-gboolean gsf_infile_msole_get_class_id (GsfInfileMSOle const *ole,
- guint8 *res);
+struct GsfInput *
+gsf_infile_msole_child_by_index (struct GsfInfileMSOle *infile, int target);
-G_END_DECLS
+char const *
+gsf_infile_msole_name_by_index (struct GsfInfileMSOle *infile, int target);
+
+void
+gsf_infile_msole_finalize (struct GsfInfileMSOle * ole);
+
+/**
+ * gsf_infile_msole_get_class_id :
+ * @ole: a #GsfInfileMSOle
+ * @res: 16 byte identifier (often a GUID in MS Windows apps)
+ *
+ * Retrieves the 16 byte indentifier (often a GUID in MS Windows apps)
+ * stored within the directory associated with @ole and stores it in @res.
+ *
+ * Returns TRUE on success
+ **/
+int
+gsf_infile_msole_get_class_id (const struct GsfInfileMSOle *ole,
+ unsigned char *res);
+
#endif /* GSF_INFILE_MSOLE_H */
Deleted: Extractor/src/plugins/ole2/gsf-infile.h
===================================================================
--- Extractor/src/plugins/ole2/gsf-infile.h 2005-08-13 13:49:03 UTC (rev
1644)
+++ Extractor/src/plugins/ole2/gsf-infile.h 2005-08-14 00:40:17 UTC (rev
1645)
@@ -1,44 +0,0 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t;
c-basic-offset: 8 -*- */
-/*
- * gsf-infile.h:
- *
- * Copyright (C) 2002-2004 Jody Goldberg (address@hidden)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef GSF_INFILE_H
-#define GSF_INFILE_H
-
-#include "gsf.h"
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define GSF_INFILE_TYPE (gsf_infile_get_type ())
-#define GSF_INFILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),
GSF_INFILE_TYPE, GsfInfile))
-#define GSF_IS_INFILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o),
GSF_INFILE_TYPE))
-
-GType gsf_infile_get_type (void);
-
-int gsf_infile_num_children (GsfInfile *infile);
-char const *gsf_infile_name_by_index (GsfInfile *infile, int i);
-GsfInput *gsf_infile_child_by_index (GsfInfile *infile, int i);
-GsfInput *gsf_infile_child_by_name (GsfInfile *infile, char const *name);
-GsfInput *gsf_infile_child_by_vname (GsfInfile *infile, char const *name,
...);
-
-G_END_DECLS
-
-#endif /* GSF_INFILE_H */
Deleted: Extractor/src/plugins/ole2/gsf-input-impl.h
===================================================================
--- Extractor/src/plugins/ole2/gsf-input-impl.h 2005-08-13 13:49:03 UTC (rev
1644)
+++ Extractor/src/plugins/ole2/gsf-input-impl.h 2005-08-14 00:40:17 UTC (rev
1645)
@@ -1,67 +0,0 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t;
c-basic-offset: 8 -*- */
-/*
- * gsf-input.h-impl.h: interface for used by the ole layer to read raw data
- *
- * Copyright (C) 2002-2004 Jody Goldberg (address@hidden)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef GSF_INPUT_IMPL_H
-#define GSF_INPUT_IMPL_H
-
-#include "gsf.h"
-#include "gsf-input.h"
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-struct _GsfInput {
- GObject g_object;
-
- gsf_off_t size, cur_offset;
- char *name;
- GsfInfile *container;
-};
-
-typedef struct {
- GObjectClass g_object_class;
-
- GsfInput *(*Dup) (GsfInput *input, GError **err);
- const guint8 *(*Read) (GsfInput *input, size_t num_bytes,
- guint8 *optional_buffer);
- gboolean (*Seek) (GsfInput *input, gsf_off_t offset,
- GSeekType whence);
- GsfInput *(*OpenSibling) (GsfInput *input, char const *path,
GError **err);
-
- /* Padding for future expansion */
- void (*_gsf_reserved0) (void);
- void (*_gsf_reserved1) (void);
- void (*_gsf_reserved2) (void);
- void (*_gsf_reserved3) (void);
-} GsfInputClass;
-
-#define GSF_INPUT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GSF_INPUT_TYPE,
GsfInputClass))
-#define GSF_IS_INPUT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSF_INPUT_TYPE))
-
-/* protected */
-gboolean gsf_input_set_name (GsfInput *input, char const *name);
-gboolean gsf_input_set_container (GsfInput *input, GsfInfile *container);
-gboolean gsf_input_set_size (GsfInput *input, gsf_off_t size);
-gboolean gsf_input_seek_emulate (GsfInput *input, gsf_off_t pos);
-
-G_END_DECLS
-
-#endif /* GSF_INPUT_IMPL_H */
Deleted: Extractor/src/plugins/ole2/gsf-input-memory.c
===================================================================
--- Extractor/src/plugins/ole2/gsf-input-memory.c 2005-08-13 13:49:03 UTC
(rev 1644)
+++ Extractor/src/plugins/ole2/gsf-input-memory.c 2005-08-14 00:40:17 UTC
(rev 1645)
@@ -1,155 +0,0 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t;
c-basic-offset: 8 -*- */
-/*
- * gsf-input-memory.c:
- *
- * Copyright (C) 2002-2004 Jody Goldberg (address@hidden)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#include "platform.h"
-#include <string.h>
-#include "gsf-input-memory.h"
-#include "gsf-input-impl.h"
-#include "gsf-impl-utils.h"
-#include "gsf-utils.h"
-#include "gsf-shared-memory.h"
-
-static GObjectClass *parent_class;
-
-struct _GsfInputMemory {
- GsfInput parent;
- GsfSharedMemory *shared;
-};
-typedef GsfInputClass GsfInputMemoryClass;
-
-/**
- * gsf_input_memory_new:
- * @buf: The input bytes
- * @length: The length of @buf
- * @needs_free: Whether you want this memory to be free'd at object destruction
- *
- * Returns: A new #GsfInputMemory
- */
-GsfInput *
-gsf_input_memory_new (guint8 const *buf, gsf_off_t length, gboolean needs_free)
-{
- GsfInputMemory *mem = g_object_new (GSF_INPUT_MEMORY_TYPE, NULL);
- if (mem == NULL)
- return NULL;
- mem->shared = gsf_shared_memory_new ((void *)buf, length, needs_free);
- gsf_input_set_size (GSF_INPUT (mem), length);
- return GSF_INPUT (mem);
-}
-
-/**
- * gsf_input_memory_new_clone:
- * @buf: The input bytes
- * @length: The length of @buf
- *
- * Returns: A new #GsfInputMemory
- */
-GsfInput *
-gsf_input_memory_new_clone (guint8 const *buf, gsf_off_t length)
-{
- GsfInputMemory *mem = NULL;
- guint8 * cpy = g_try_malloc (length * sizeof (guint8));
- if (cpy == NULL)
- return NULL;
-
- memcpy (cpy, buf, length);
- mem = g_object_new (GSF_INPUT_MEMORY_TYPE, NULL);
- if (mem == NULL)
- return NULL;
- mem->shared = gsf_shared_memory_new ((void *)cpy, length, TRUE);
- gsf_input_set_size (GSF_INPUT (mem), length);
- return GSF_INPUT (mem);
-}
-
-static void
-gsf_input_memory_finalize (GObject *obj)
-{
- GsfInputMemory *mem = (GsfInputMemory *) (obj);
-
- if (mem->shared)
- g_object_unref (G_OBJECT (mem->shared));
-
- parent_class->finalize (obj);
-}
-
-static GsfInput *
-gsf_input_memory_dup (GsfInput *src_input, GError **err)
-{
- GsfInputMemory const *src = (GsfInputMemory *) (src_input);
- GsfInputMemory *dst = g_object_new (GSF_INPUT_MEMORY_TYPE, NULL);
- if (dst == NULL)
- return NULL;
- (void) err;
-
- dst->shared = src->shared;
- g_object_ref (G_OBJECT (dst->shared));
-
- return GSF_INPUT (dst);
-}
-
-static guint8 const *
-gsf_input_memory_read (GsfInput *input, size_t num_bytes, guint8
*optional_buffer)
-{
- GsfInputMemory *mem = (GsfInputMemory *) (input);
- guchar const *src = mem->shared->buf;
-
- if (src == NULL)
- return NULL;
- if (optional_buffer) {
- memcpy (optional_buffer, src + input->cur_offset, num_bytes);
- return optional_buffer;
- } else
- return src + input->cur_offset;
-}
-
-static gboolean
-gsf_input_memory_seek (G_GNUC_UNUSED GsfInput *input,
- G_GNUC_UNUSED gsf_off_t offset,
- G_GNUC_UNUSED GSeekType whence)
-{
- return FALSE;
-}
-
-static void
-gsf_input_memory_init (GObject *obj)
-{
- GsfInputMemory *mem = (GsfInputMemory *) (obj);
- mem->shared = NULL;
-
-}
-
-static void
-gsf_input_memory_class_init (GObjectClass *gobject_class)
-{
- GsfInputClass *input_class = GSF_INPUT_CLASS (gobject_class);
-
- gobject_class->finalize = gsf_input_memory_finalize;
- input_class->Dup = gsf_input_memory_dup;
- input_class->Read = gsf_input_memory_read;
- input_class->Seek = gsf_input_memory_seek;
-
- parent_class = g_type_class_peek_parent (gobject_class);
-}
-
-GSF_CLASS (GsfInputMemory, gsf_input_memory,
- gsf_input_memory_class_init, gsf_input_memory_init,
- GSF_INPUT_TYPE)
-
-
Deleted: Extractor/src/plugins/ole2/gsf-input-memory.h
===================================================================
--- Extractor/src/plugins/ole2/gsf-input-memory.h 2005-08-13 13:49:03 UTC
(rev 1644)
+++ Extractor/src/plugins/ole2/gsf-input-memory.h 2005-08-14 00:40:17 UTC
(rev 1645)
@@ -1,43 +0,0 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t;
c-basic-offset: 8 -*- */
-/*
- * gsf-input-memory.h: interface for used by the ole layer to read raw data
- *
- * Copyright (C) 2002-2004 Jody Goldberg (address@hidden)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef GSF_INPUT_MEMORY_H
-#define GSF_INPUT_MEMORY_H
-
-#include "gsf-input.h"
-
-G_BEGIN_DECLS
-
-#define GSF_INPUT_MEMORY_TYPE (gsf_input_memory_get_type ())
-#define GSF_INPUT_MEMORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),
GSF_INPUT_MEMORY_TYPE, GsfInputMemory))
-#define GSF_IS_INPUT_MEMORY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o),
GSF_INPUT_MEMORY_TYPE))
-
-typedef struct _GsfInputMemory GsfInputMemory;
-
-GType gsf_input_memory_get_type (void);
-GsfInput *gsf_input_memory_new (guint8 const *buf, gsf_off_t length,
- gboolean needs_free);
-GsfInput *gsf_input_memory_new_clone (guint8 const *buf, gsf_off_t length);
-GsfInput *gsf_input_mmap_new (char const *filename, GError **err);
-
-G_END_DECLS
-
-#endif /* GSF_INPUT_MEMORY_H */
Modified: Extractor/src/plugins/ole2/gsf-input.c
===================================================================
--- Extractor/src/plugins/ole2/gsf-input.c 2005-08-13 13:49:03 UTC (rev
1644)
+++ Extractor/src/plugins/ole2/gsf-input.c 2005-08-14 00:40:17 UTC (rev
1645)
@@ -20,201 +20,110 @@
*/
#include "platform.h"
-#include "gsf-input-impl.h"
-#include "gsf-impl-utils.h"
+#include "gsf-input.h"
+#include "gsf-utils.h"
#include <string.h>
-#ifdef HAVE_BZIP
-#include <gsf/gsf-input-bzip.h>
-#endif
+typedef struct GsfInput {
+ off_t size;
+ off_t cur_offset;
+ char * name;
+ const unsigned char * buf;
+ int needs_free;
+} GsfInput;
-#define GET_CLASS(instance) G_TYPE_INSTANCE_GET_CLASS (instance,
GSF_INPUT_TYPE, GsfInputClass)
-static GObjectClass *parent_class;
-
-enum {
- PROP_0,
- PROP_NAME,
- PROP_SIZE,
- PROP_EOF,
- PROP_REMAINING,
- PROP_POS
-};
-
-#if 0
static void
-gsf_input_set_property (GObject *object,
- guint property_id,
- GValue const *value,
- GParamSpec *pspec)
+gsf_input_init (GsfInput * input)
{
- switch (property_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
pspec);
- break;
- }
+ input->size = 0;
+ input->cur_offset = 0;
+ input->name = NULL;
+ input->buf = NULL;
}
-#endif
-static void
-gsf_input_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+/**
+ * gsf_input_memory_new:
+ * @buf: The input bytes
+ * @length: The length of @buf
+ * @needs_free: Whether you want this memory to be free'd at object destruction
+ *
+ * Returns: A new #GsfInputMemory
+ */
+GsfInput *
+gsf_input_new (const unsigned char * buf,
+ off_t length,
+ int needs_free)
{
- /* gsf_off_t is typedef'd to gint64 */
- switch (property_id) {
- case PROP_NAME:
- g_value_set_string (value, gsf_input_name (GSF_INPUT (object)));
- break;
- case PROP_SIZE:
- g_value_set_int64 (value, gsf_input_size (GSF_INPUT (object)));
- break;
- case PROP_EOF:
- g_value_set_boolean (value, gsf_input_eof (GSF_INPUT (object)));
- break;
- case PROP_REMAINING:
- g_value_set_int64 (value, gsf_input_remaining (GSF_INPUT
(object)));
- break;
- case PROP_POS:
- g_value_set_int64 (value, gsf_input_tell (GSF_INPUT (object)));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ GsfInput *mem = malloc(sizeof(GsfInput));
+ if (mem == NULL)
+ return NULL;
+ gsf_input_init(mem);
+ mem->buf = buf;
+ mem->size = length;
+ mem->needs_free = needs_free;
+ return mem;
}
-static void
-gsf_input_finalize (GObject *obj)
+void
+gsf_input_finalize (GsfInput * input)
{
- GsfInput *input = GSF_INPUT (obj);
-
if (input->name != NULL) {
- g_free (input->name);
+ free (input->name);
input->name = NULL;
}
- if (input->container != NULL) {
- g_object_unref (G_OBJECT (input->container));
- input->container = NULL;
- }
- parent_class->finalize (obj);
+ if ( (input->buf) && input->needs_free)
+ free((void*) input->buf);
+ free(input);
}
-static void
-gsf_input_init (GObject *obj)
+GsfInput *
+gsf_input_dup (GsfInput *src)
{
- GsfInput *input = GSF_INPUT (obj);
-
- input->size = 0;
- input->cur_offset = 0;
- input->name = NULL;
- input->container = NULL;
+ GsfInput * dst = malloc(sizeof(GsfInput));
+ if (dst == NULL)
+ return NULL;
+ gsf_input_init(dst);
+ dst->buf = src->buf;
+ dst->needs_free = 0;
+ dst->size = src->size;
+ if (src->name != NULL)
+ gsf_input_set_name (dst, src->name);
+ dst->cur_offset = src->cur_offset;
+ return dst;
}
-static void
-gsf_input_class_init (GObjectClass *gobject_class)
+const unsigned char *
+gsf_input_read (GsfInput * mem, size_t num_bytes, unsigned char *
optional_buffer)
{
- parent_class = g_type_class_peek_parent (gobject_class);
+ const unsigned char *src = mem->buf;
+ if (src == NULL)
+ return NULL;
+ if (optional_buffer) {
+ memcpy (optional_buffer, src + mem->cur_offset, num_bytes);
+ mem->cur_offset += num_bytes;
- gobject_class->finalize = gsf_input_finalize;
- /* gobject_class->set_property = gsf_input_set_property; */
- gobject_class->get_property = gsf_input_get_property;
-
- g_object_class_install_property (gobject_class,
- PROP_NAME,
- g_param_spec_string ("name", "Name",
- "The Input's
Name",
- NULL,
-
G_PARAM_READABLE));
- g_object_class_install_property (gobject_class,
- PROP_SIZE,
- g_param_spec_int64 ("size", "Size",
- "The Input's Size",
- 0, G_MAXINT64, 0,
- G_PARAM_READABLE));
- g_object_class_install_property (gobject_class,
- PROP_EOF,
- g_param_spec_boolean ("eof", "OEF",
- "End Of File",
- FALSE,
-
G_PARAM_READABLE));
- g_object_class_install_property (gobject_class,
- PROP_REMAINING,
- g_param_spec_int64 ("remaining",
"Remaining",
- "Amount of Data
Remaining",
- 0, G_MAXINT64, 0,
- G_PARAM_READABLE));
- g_object_class_install_property (gobject_class,
- PROP_POS,
- g_param_spec_int64 ("position",
"Position",
- "The Output's
Current Position",
- 0, G_MAXINT64, 0,
- G_PARAM_READABLE));
+ return optional_buffer;
+ } else {
+ const unsigned char * ret = src + mem->cur_offset;
+ mem->cur_offset += num_bytes;
+ return ret;
+ }
}
-GSF_CLASS_ABSTRACT (GsfInput, gsf_input,
- gsf_input_class_init, gsf_input_init,
- G_TYPE_OBJECT)
-
/**
* gsf_input_name :
* @input :
*
* Returns @input's name in utf8 form, DO NOT FREE THIS STRING
**/
-char const *
+const char *
gsf_input_name (GsfInput *input)
{
- g_return_val_if_fail (GSF_IS_INPUT (input), NULL);
return input->name;
}
/**
- * gsf_input_container :
- * @input :
- *
- * Returns, but does not add a reference to @input's container.
- * Potentially NULL
- **/
-GsfInfile *
-gsf_input_container (GsfInput *input)
-{
- g_return_val_if_fail (GSF_IS_INPUT (input), NULL);
- return input->container;
-}
-
-/**
- * gsf_input_dup :
- * @input : The input to duplicate
- * @err : optionally NULL
- *
- * Duplicates input @src leaving the new one at the same offset.
- *
- * Returns : the duplicate, or NULL on error
- **/
-GsfInput *
-gsf_input_dup (GsfInput *input, GError **err)
-{
- GsfInput *dst;
-
- g_return_val_if_fail (input != NULL, NULL);
-
- dst = GET_CLASS (input)->Dup (input, err);
- if (dst != NULL) {
- dst->size = input->size;
- if (input->name != NULL)
- gsf_input_set_name (dst, input->name);
- dst->container = input->container;
- if (dst->container != NULL)
- g_object_ref (G_OBJECT (dst->container));
- gsf_input_seek (dst, (gsf_off_t)input->cur_offset, G_SEEK_SET);
- }
- return dst;
-}
-
-/**
* gsf_input_size :
* @input : The input
*
@@ -222,7 +131,7 @@
*
* Returns : the size or -1 on error
**/
-gsf_off_t
+off_t
gsf_input_size (GsfInput *input)
{
g_return_val_if_fail (input != NULL, -1);
@@ -237,52 +146,21 @@
*
* Returns : TRUE if the input is at the eof.
**/
-gboolean
+int
gsf_input_eof (GsfInput *input)
{
- g_return_val_if_fail (input != NULL, FALSE);
+ g_return_val_if_fail (input != NULL, 0);
return input->cur_offset >= input->size;
}
/**
- * gsf_input_read :
- * @input :
- * @num_bytes :
- * @optional_buffer : If supplied copy the data into it
- *
- * Read at at least @num_bytes. Does not change the current position if there
- * is an error. Will only read if the entire amount can be read. Invalidates
- * the buffer associated with previous calls to gsf_input_read.
- *
- * Returns : pointer to the buffer or NULL if there is an error or 0 bytes are
- * requested.
- **/
-guint8 const *
-gsf_input_read (GsfInput *input, size_t num_bytes, guint8 *optional_buffer)
-{
- guint8 const *res;
-
- g_return_val_if_fail (input != NULL, NULL);
-
- if (num_bytes == 0 || (input->cur_offset + num_bytes) > input->size)
- return NULL;
- res = GET_CLASS (input)->Read (input, num_bytes, optional_buffer);
- if (res == NULL)
- return NULL;
-
- input->cur_offset += num_bytes;
- return res;
-
-}
-
-/**
* gsf_input_remaining :
* @input :
*
* Returns the number of bytes left in the file.
**/
-gsf_off_t
+off_t
gsf_input_remaining (GsfInput *input)
{
g_return_val_if_fail (input != NULL, 0);
@@ -296,7 +174,7 @@
*
* Returns the current offset in the file.
**/
-gsf_off_t
+off_t
gsf_input_tell (GsfInput *input)
{
g_return_val_if_fail (input != NULL, 0);
@@ -312,34 +190,32 @@
*
* Returns TRUE on error.
**/
-gboolean
-gsf_input_seek (GsfInput *input, gsf_off_t offset, GSeekType whence)
+int
+gsf_input_seek (GsfInput *input, off_t offset, int whence)
{
- gsf_off_t pos = offset;
+ off_t pos = offset;
- g_return_val_if_fail (input != NULL, TRUE);
+ g_return_val_if_fail (input != NULL, 1);
switch (whence) {
- case G_SEEK_SET : break;
- case G_SEEK_CUR : pos += input->cur_offset; break;
- case G_SEEK_END : pos += input->size; break;
- default : return TRUE;
+ case SEEK_SET : break;
+ case SEEK_CUR : pos += input->cur_offset; break;
+ case SEEK_END : pos += input->size; break;
+ default : return 1;
}
if (pos < 0 || pos > input->size)
- return TRUE;
+ return 1;
/*
* If we go nowhere, just return. This in particular handles null
* seeks for streams with no seek method.
*/
if (pos == input->cur_offset)
- return FALSE;
+ return 0;
- if (GET_CLASS (input)->Seek (input, offset, whence))
- return TRUE;
input->cur_offset = pos;
- return FALSE;
+ return 0;
}
/**
@@ -351,197 +227,33 @@
*
* Returns : TRUE if the assignment was ok.
**/
-gboolean
+int
gsf_input_set_name (GsfInput *input, char const *name)
{
char *buf;
- g_return_val_if_fail (input != NULL, FALSE);
+ g_return_val_if_fail (input != NULL, 0);
- buf = g_strdup (name);
+ buf = strdup (name);
if (input->name != NULL)
- g_free (input->name);
+ free (input->name);
input->name = buf;
- return TRUE;
+ return 1;
}
/**
- * gsf_input_set_container :
- * @input :
- * @container :
- *
- * Returns : TRUE if the assignment was ok.
- */
-gboolean
-gsf_input_set_container (GsfInput *input, GsfInfile *container)
-{
- g_return_val_if_fail (input != NULL, FALSE);
-
- if (container != NULL)
- g_object_ref (G_OBJECT (container));
- if (input->container != NULL)
- g_object_unref (G_OBJECT (input->container));
- input->container = container;
- return TRUE;
-}
-
-/**
* gsf_input_set_size :
* @input :
* @size :
*
* Returns : TRUE if the assignment was ok.
*/
-gboolean
-gsf_input_set_size (GsfInput *input, gsf_off_t size)
+int
+gsf_input_set_size (GsfInput *input, off_t size)
{
- g_return_val_if_fail (input != NULL, FALSE);
+ g_return_val_if_fail (input != NULL, 0);
input->size = size;
- return TRUE;
+ return 1;
}
-/**
- * gsf_input_seek_emulate: Emulate forward seeks by reading.
- * @input :
- * @pos :
- *
- * Returns : TRUE if the emulation worked.
- */
-gboolean
-gsf_input_seek_emulate (GsfInput *input, gsf_off_t pos)
-{
- if (pos < input->cur_offset)
- return TRUE;
-
- while (pos > input->cur_offset) {
- gsf_off_t readcount = MIN (pos - input->cur_offset, 8192);
- if (!gsf_input_read (input, readcount, NULL))
- return TRUE;
- }
- return FALSE;
-}
-
-/****************************************************************************/
-
-/**
- * gsf_input_error :
- *
- * Returns : A utility quark to flag a GError as being an input problem.
- */
-GQuark
-gsf_input_error (void)
-{
- static GQuark quark;
- if (!quark)
- quark = g_quark_from_static_string ("gsf_input_error");
- return quark;
-}
-
-/****************************************************************************/
-
-#define GSF_READ_BUFSIZE (1024 * 4)
-
-
-/****************************************************************************/
-
-/**
- * gsf_input_uncompress: maybe uncompress stream.
- * @src: stream to be uncompressed.
- *
- * Returns: A stream equivalent to the source stream, but uncompressed if
- * the source was compressed.
- *
- * This functions takes ownership of the incoming reference and yields a
- * new one as its output.
- */
-GsfInput *
-gsf_input_uncompress (GsfInput *src)
-{
- gsf_off_t cur_offset = src->cur_offset;
- const guint8 *data;
-
- if (gsf_input_seek (src, (gsf_off_t) 0, G_SEEK_SET))
- goto error;
-
- /* Read header up front, so we avoid extra seeks in tests. */
- data = gsf_input_read (src, 4, NULL);
- if (!data)
- goto error;
-
-#if 0
- /* Let's try gzip. */
- {
- const unsigned char gzip_sig[2] = { 0x1f, 0x8b };
-
- if (memcmp (gzip_sig, data, sizeof (gzip_sig)) == 0) {
- GsfInput *res = gsf_input_gzip_new (src, NULL);
- if (res) {
- g_object_unref (G_OBJECT (src));
- return gsf_input_uncompress (res);
- }
- }
- }
-#endif
-
-#ifdef HAVE_BZIP
- /* Let's try bzip. */
- {
- guint8 const *bzip_sig = "BZh";
-
- if (memcmp (gzip_sig, data, strlen (bzip_sig)) == 0) {
- GsfInput *res = gsf_input_memory_new_from_bzip (src,
NULL);
- if (res) {
- g_object_unref (G_OBJECT (src));
- return gsf_input_uncompress (res);
- }
- }
- }
-#endif
-
- /* Other methods go here. */
-
- error:
- (void)gsf_input_seek (src, cur_offset, G_SEEK_SET);
- return src;
-}
-
-#if 0
-
-#include <gsf/gsf-input-stdio.h>
-
-#ifdef HAVE_GNOME
-#include <gsf-gnome/gsf-input-gnomevfs.h>
-#endif
-
-GsfInput *
-gsf_input_new_for_uri (char const * uri, GError ** err)
-{
- GsfInput * input = NULL;
- size_t len;
-
- g_return_val_if_fail (uri, NULL);
-
- len = strlen (uri);
- g_return_val_if_fail (len, NULL);
-
- if (len > 3 && !strstr (uri, ":/")) {
- /* assume plain file */
- input = gsf_input_stdio_new (uri, err);
- } else {
-#if HAVE_GNOME
- /* have gnome, let GnomeVFS deal with this */
- input = gsf_input_gnomevfs_new (uri, err);
-#else
- if (len > 7 && !strncmp (uri, "file:/", 6)) {
- /* dumb attempt to translate this into a local path */
- input = gsf_input_stdio_new (uri+7, err);
- }
- /* else: unknown or unhandled protocol - bail */
-#endif
- }
-
- return input;
-}
-
-#endif
Modified: Extractor/src/plugins/ole2/gsf-input.h
===================================================================
--- Extractor/src/plugins/ole2/gsf-input.h 2005-08-13 13:49:03 UTC (rev
1644)
+++ Extractor/src/plugins/ole2/gsf-input.h 2005-08-14 00:40:17 UTC (rev
1645)
@@ -22,38 +22,40 @@
#ifndef GSF_INPUT_H
#define GSF_INPUT_H
-#include "gsf.h"
-#include <glib-object.h>
#include <sys/types.h>
+#include <unistd.h>
-G_BEGIN_DECLS
+struct GsfInput;
-#define GSF_INPUT_TYPE (gsf_input_get_type ())
-#define GSF_INPUT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),
GSF_INPUT_TYPE, GsfInput))
-#define GSF_IS_INPUT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o),
GSF_INPUT_TYPE))
+/**
+ * gsf_input_memory_new:
+ * @buf: The input bytes
+ * @length: The length of @buf
+ * @needs_free: Whether you want this memory to be free'd at object destruction
+ *
+ * Returns: A new #GsfInputMemory
+ */
+struct GsfInput *
+gsf_input_new (const unsigned char *buf,
+ off_t length,
+ int needs_free);
-GType gsf_input_get_type (void);
+char const * gsf_input_name (struct GsfInput *input);
+struct GsfInput * gsf_input_dup (struct GsfInput *input);
+void gsf_input_finalize (struct GsfInput *input);
+struct GsfInput * gsf_input_sibling (const struct GsfInput *input, char
const *name);
+off_t gsf_input_size (struct GsfInput *input);
+int gsf_input_eof (struct GsfInput *input);
+const unsigned char * gsf_input_read (struct GsfInput *input,
+ size_t num_bytes,
+ unsigned char * optional_buffer);
+off_t gsf_input_remaining (struct GsfInput *input);
+off_t gsf_input_tell (struct GsfInput *input);
+int gsf_input_seek (struct GsfInput *input,
+ off_t offset,
+ int whence);
+int gsf_input_set_name (struct GsfInput *input, char const
*name);
+int gsf_input_set_size (struct GsfInput *input, off_t size);
-char const *gsf_input_name (GsfInput *input);
-GsfInfile *gsf_input_container (GsfInput *input);
-GsfInput *gsf_input_dup (GsfInput *input, GError **err);
-GsfInput *gsf_input_sibling (GsfInput const *input, char const
*name, GError **err);
-gsf_off_t gsf_input_size (GsfInput *input);
-gboolean gsf_input_eof (GsfInput *input);
-guint8 const *gsf_input_read (GsfInput *input, size_t num_bytes,
- guint8 *optional_buffer);
-gsf_off_t gsf_input_remaining (GsfInput *input);
-gsf_off_t gsf_input_tell (GsfInput *input);
-gboolean gsf_input_seek (GsfInput *input,
- gsf_off_t offset, GSeekType whence);
-
-/* Utilities */
-gboolean gsf_input_copy (GsfInput *input, GsfOutput *output);
-GsfInput *gsf_input_uncompress (GsfInput *src);
-
-GQuark gsf_input_error (void);
-
-G_END_DECLS
-
#endif /* GSF_INPUT_H */
Deleted: Extractor/src/plugins/ole2/gsf-msole-impl.h
===================================================================
--- Extractor/src/plugins/ole2/gsf-msole-impl.h 2005-08-13 13:49:03 UTC (rev
1644)
+++ Extractor/src/plugins/ole2/gsf-msole-impl.h 2005-08-14 00:40:17 UTC (rev
1645)
@@ -1,84 +0,0 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t;
c-basic-offset: 8 -*- */
-/*
- * gsf-msole-impl.h:
- *
- * Copyright (C) 2002-2004 Jody Goldberg (address@hidden)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef GSF_MSOLE_IMPL_H
-#define GSF_MSOLE_IMPL_H
-
-#include "gsf.h"
-
-G_BEGIN_DECLS
-
-#define OLE_HEADER_SIZE 0x200 /* independent of big block
size size */
-#define OLE_HEADER_SIGNATURE 0x00
-#define OLE_HEADER_CLSID 0x08 /* See ReadClassStg */
-#define OLE_HEADER_MINOR_VER 0x18 /* 0x33 and 0x3e have been seen */
-#define OLE_HEADER_MAJOR_VER 0x1a /* 0x3 been seen in wild */
-#define OLE_HEADER_BYTE_ORDER 0x1c /* 0xfe 0xff == Intel Little Endian */
-#define OLE_HEADER_BB_SHIFT 0x1e
-#define OLE_HEADER_SB_SHIFT 0x20
-/* 0x22..0x27 reserved == 0 */
-#define OLE_HEADER_CSECTDIR 0x28
-#define OLE_HEADER_NUM_BAT 0x2c
-#define OLE_HEADER_DIRENT_START 0x30
-/* 0x34..0x37 transacting signature must be 0 */
-#define OLE_HEADER_THRESHOLD 0x38
-#define OLE_HEADER_SBAT_START 0x3c
-#define OLE_HEADER_NUM_SBAT 0x40
-#define OLE_HEADER_METABAT_BLOCK 0x44
-#define OLE_HEADER_NUM_METABAT 0x48
-#define OLE_HEADER_START_BAT 0x4c
-#define BAT_INDEX_SIZE 4
-#define OLE_HEADER_METABAT_SIZE ((OLE_HEADER_SIZE -
OLE_HEADER_START_BAT) / BAT_INDEX_SIZE)
-
-#define DIRENT_MAX_NAME_SIZE 0x40
-#define DIRENT_DETAILS_SIZE 0x40
-#define DIRENT_SIZE (DIRENT_MAX_NAME_SIZE + DIRENT_DETAILS_SIZE)
-#define DIRENT_NAME_LEN 0x40 /* length in bytes incl 0
terminator */
-#define DIRENT_TYPE 0x42
-#define DIRENT_COLOUR 0x43
-#define DIRENT_PREV 0x44
-#define DIRENT_NEXT 0x48
-#define DIRENT_CHILD 0x4c
-#define DIRENT_CLSID 0x50 /* only for dirs */
-#define DIRENT_USERFLAGS 0x60 /* only for dirs */
-#define DIRENT_CREATE_TIME 0x64 /* for files */
-#define DIRENT_MODIFY_TIME 0x6c /* for files */
-#define DIRENT_FIRSTBLOCK 0x74
-#define DIRENT_FILE_SIZE 0x78
-/* 0x7c..0x7f reserved == 0 */
-
-#define DIRENT_TYPE_INVALID 0
-#define DIRENT_TYPE_DIR 1
-#define DIRENT_TYPE_FILE 2
-#define DIRENT_TYPE_LOCKBYTES 3 /* ? */
-#define DIRENT_TYPE_PROPERTY 4 /* ? */
-#define DIRENT_TYPE_ROOTDIR 5
-#define DIRENT_MAGIC_END 0xffffffff
-
-/* flags in the block allocation list to denote special blocks */
-#define BAT_MAGIC_UNUSED 0xffffffff /* -1 */
-#define BAT_MAGIC_END_OF_CHAIN 0xfffffffe /* -2 */
-#define BAT_MAGIC_BAT 0xfffffffd /* a bat block, -3 */
-#define BAT_MAGIC_METABAT 0xfffffffc /* a metabat block -4 */
-
-G_END_DECLS
-
-#endif /* GSF_MSOLE_IMPL_H */
Deleted: Extractor/src/plugins/ole2/gsf-shared-memory.c
===================================================================
--- Extractor/src/plugins/ole2/gsf-shared-memory.c 2005-08-13 13:49:03 UTC
(rev 1644)
+++ Extractor/src/plugins/ole2/gsf-shared-memory.c 2005-08-14 00:40:17 UTC
(rev 1645)
@@ -1,74 +0,0 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t;
c-basic-offset: 8 -*- */
-/*
- * gsf-shared-memory.c:
- *
- * Copyright (C) 2002-2004 Morten Welinder (address@hidden)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#include "platform.h"
-#include "gsf-shared-memory.h"
-#include "gsf-impl-utils.h"
-
-typedef struct {
- GObjectClass g_object_class;
-} GsfSharedMemoryClass;
-
-static GObjectClass *parent_class;
-
-GsfSharedMemory *
-gsf_shared_memory_new (void *buf, gsf_off_t size, gboolean needs_free)
-{
- GsfSharedMemory *mem = g_object_new (GSF_SHARED_MEMORY_TYPE, NULL);
- if (mem == NULL)
- return NULL;
- mem->buf = buf;
- mem->size = size;
- mem->needs_free = needs_free;
- return mem;
-}
-
-static void
-gsf_shared_memory_finalize (GObject *obj)
-{
- GsfSharedMemory *mem = (GsfSharedMemory *) (obj);
-
- if (mem->buf != NULL) {
- if (mem->needs_free)
- g_free (mem->buf);
- }
-
- G_OBJECT_CLASS (parent_class)->finalize (obj);
-}
-
-static void
-gsf_shared_memory_init (GObject *obj)
-{
- GsfSharedMemory *mem = (GsfSharedMemory *) (obj);
- mem->buf = NULL;
-}
-
-static void
-gsf_shared_memory_class_init (GObjectClass *gobject_class)
-{
- parent_class = g_type_class_peek_parent (gobject_class);
-
- gobject_class->finalize = gsf_shared_memory_finalize;
-}
-
-GSF_CLASS (GsfSharedMemory, gsf_shared_memory,
- gsf_shared_memory_class_init, gsf_shared_memory_init,
- G_TYPE_OBJECT)
Deleted: Extractor/src/plugins/ole2/gsf-shared-memory.h
===================================================================
--- Extractor/src/plugins/ole2/gsf-shared-memory.h 2005-08-13 13:49:03 UTC
(rev 1644)
+++ Extractor/src/plugins/ole2/gsf-shared-memory.h 2005-08-14 00:40:17 UTC
(rev 1645)
@@ -1,48 +0,0 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t;
c-basic-offset: 8 -*- */
-/*
- * gsf-shared-memory.h
- *
- * Copyright (C) 2002-2004 Morten Welinder (address@hidden)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef GSF_SHARED_MEMORY_H
-#define GSF_SHARED_MEMORY_H
-
-#include "gsf.h"
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define GSF_SHARED_MEMORY_TYPE (gsf_shared_memory_get_type ())
-#define GSF_SHARED_MEMORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),
GSF_SHARED_MEMORY_TYPE, GsfSharedMemory))
-#define GSF_IS_SHARED_MEMORY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o),
GSF_SHARED_MEMORY_TYPE))
-
-typedef struct _GsfSharedMemory GsfSharedMemory;
-struct _GsfSharedMemory {
- GObject g_object;
- void *buf;
- gsf_off_t size;
-
- gboolean needs_free;
-};
-
-GType gsf_shared_memory_get_type (void);
-GsfSharedMemory *gsf_shared_memory_new (void *buf, gsf_off_t size, gboolean
needs_free);
-
-G_END_DECLS
-
-#endif /* GSF_SHARED_MEMORY_H */
Modified: Extractor/src/plugins/ole2/gsf-utils.c
===================================================================
--- Extractor/src/plugins/ole2/gsf-utils.c 2005-08-13 13:49:03 UTC (rev
1644)
+++ Extractor/src/plugins/ole2/gsf-utils.c 2005-08-14 00:40:17 UTC (rev
1645)
@@ -38,76 +38,6 @@
#define G_FLOAT_BYTE_ORDER G_BYTE_ORDER
#endif
-
-static void base64_init (void);
-
-
-
-static void
-gsf_mem_dump_full (guint8 const *ptr, size_t len, unsigned offset)
-{
- size_t i, j, off;
-
- for (i = 0 ; i < (len+15)/16 ; i++) {
- g_print ("%8x | ", i*16 + offset);
- for (j = 0;j < 16; j++) {
- off = j + (i << 4);
- off<len ? g_print("%2x ", ptr[off]) : g_print("XX ");
- }
- g_print ("| ");
- for (j = 0 ; j < 16 ; j++) {
- off = j + (i<<4);
- g_print ("%c", off < len ? (ptr[off] >= '!' && ptr[off]
< 127 ? ptr[off] : '.') : '*');
- }
- g_print ("\n");
- }
-}
-
-/**
- * gsf_mem_dump :
- * @ptr: memory area to be dumped.
- * @len: how many bytes will be dumped.
- *
- * Dump @len bytes from the memory location given by @ptr.
- **/
-void
-gsf_mem_dump (guint8 const *ptr, size_t len)
-{
- gsf_mem_dump_full (ptr, len, 0);
-}
-
-/**
- * gsf_input_dump :
- * @input: a #GsfInput
- * @dump_as_hex: If TRUE, dump in hexidecmal format
- *
- * Dumps @input's contents to STDOUT, optionally in hex format.
- */
-void
-gsf_input_dump (GsfInput *input, gboolean dump_as_hex)
-{
- size_t size, count, offset = 0;
- guint8 const *data;
-
- /* read in small blocks to excercise things */
- size = gsf_input_size (GSF_INPUT (input));
- while (size > 0) {
- count = size;
- if (count > 0x100)
- count = 0x100;
- data = gsf_input_read (GSF_INPUT (input), count, NULL);
- g_return_if_fail (data != NULL);
- if (dump_as_hex)
- gsf_mem_dump_full (data, count, offset);
- else
- fwrite (data, 1, count, stdout);
- size -= count;
- offset += count;
- }
- if (!dump_as_hex)
- fflush (stdout);
-}
-
guint64
gsf_le_get_guint64 (void const *p)
{
Modified: Extractor/src/plugins/ole2/gsf-utils.h
===================================================================
--- Extractor/src/plugins/ole2/gsf-utils.h 2005-08-13 13:49:03 UTC (rev
1644)
+++ Extractor/src/plugins/ole2/gsf-utils.h 2005-08-14 00:40:17 UTC (rev
1645)
@@ -22,10 +22,8 @@
#ifndef GSF_UTILS_H
#define GSF_UTILS_H
-#include "gsf.h"
+#include <glib-object.h>
-G_BEGIN_DECLS
-
/* Do this the ugly way so that we don't have to worry about alignment */
#define GSF_LE_GET_GUINT8(p) (*(guint8 const *)(p))
#define GSF_LE_GET_GUINT16(p) \
@@ -64,18 +62,12 @@
void gsf_le_set_float (void *p, float f);
void gsf_le_set_double (void *p, double d);
-/* Debugging utilities */
-void gsf_mem_dump (guint8 const *ptr, size_t len);
-void gsf_input_dump (GsfInput *input, gboolean dump_as_hex);
-
char const *gsf_extension_pointer (char const * path);
void gsf_iconv_close (GIConv handle);
-G_END_DECLS
-
#undef g_return_val_if_fail
-#define g_return_val_if_fail(cond,ret) do{if (cond) return ret;}while(0)
+#define g_return_val_if_fail(cond,ret) do{if (!(cond)) return ret;}while(0)
#endif /* GSF_UTILS_H */
Deleted: Extractor/src/plugins/ole2/gsf.h
===================================================================
--- Extractor/src/plugins/ole2/gsf.h 2005-08-13 13:49:03 UTC (rev 1644)
+++ Extractor/src/plugins/ole2/gsf.h 2005-08-14 00:40:17 UTC (rev 1645)
@@ -1,48 +0,0 @@
-/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t;
c-basic-offset: 8 -*- */
-/*
- * gsf.h:
- *
- * Copyright (C) 2002-2004 Jody Goldberg (address@hidden)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef GSF_H
-#define GSF_H
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-typedef struct _GsfInput GsfInput;
-typedef struct _GsfInfile GsfInfile;
-
-typedef struct _GsfOutput GsfOutput;
-typedef struct _GsfOutfile GsfOutfile;
-
-typedef struct _GsfDocProp GsfDocProp;
-typedef struct _GsfDocMetaData GsfDocMetaData;
-typedef struct _GsfTimestamp GsfTimestamp;
-
-/* FIXME:
- * gsf_off_t is really supposed to be the widest type off_t can be configured
- * to on the platform
- */
-typedef gint64 gsf_off_t;
-#define GSF_OFF_T_FORMAT G_GINT64_FORMAT
-
-G_END_DECLS
-
-#endif /* GSF_H */
Modified: Extractor/src/plugins/ole2/ole2extractor.c
===================================================================
--- Extractor/src/plugins/ole2/ole2extractor.c 2005-08-13 13:49:03 UTC (rev
1644)
+++ Extractor/src/plugins/ole2/ole2extractor.c 2005-08-14 00:40:17 UTC (rev
1645)
@@ -20,10 +20,7 @@
#include "platform.h"
#include "extractor.h"
-
-#include "gsf-utils.h"
-#include "gsf-input-memory.h"
-#include "gsf-infile.h"
+#include <glib-object.h>
#include "gsf-infile-msole.h"
#include "gsf-input.h"
#include "gsf-utils.h"
@@ -41,7 +38,7 @@
/* using libgobject, needs init! */
void __attribute__ ((constructor)) ole_gobject_init(void) {
- g_type_init();
+ g_type_init();
}
static struct EXTRACTOR_Keywords *
@@ -139,12 +136,12 @@
typedef struct {
guint32 id;
- gsf_off_t offset;
+ off_t offset;
} GsfMSOleMetaDataProp;
typedef struct {
GsfMSOleMetaDataType type;
- gsf_off_t offset;
+ off_t offset;
guint32 size, num_props;
GIConv iconv_handle;
unsigned char_size;
@@ -295,8 +292,7 @@
n = GSF_LE_GET_GUINT32 (*data);
*data += 4;
- d (printf (" array with %d elem\n", n);
- gsf_mem_dump (*data, (unsigned)(data_end - *data)););
+ d (printf (" array with %d elem\n", n););
for (i = 0 ; i < n ; i++) {
GValue *v;
d (printf ("\t[%d] ", i););
@@ -523,7 +519,7 @@
}
static GValue *
-msole_prop_read (GsfInput *in,
+msole_prop_read (struct GsfInput *in,
GsfMSOleMetaDataSection *section,
GsfMSOleMetaDataProp *props,
unsigned i)
@@ -531,7 +527,7 @@
guint32 type;
guint8 const *data;
/* TODO : why size-4 ? I must be missing something */
- gsf_off_t size = ((i+1) >= section->num_props)
+ off_t size = ((i+1) >= section->num_props)
? section->size-4 : props[i+1].offset;
char const *prop_name;
@@ -539,7 +535,7 @@
g_return_val_if_fail (size >= props[i].offset + 4, NULL);
size -= props[i].offset; /* includes the type id */
- if (gsf_input_seek (in, section->offset+props[i].offset, G_SEEK_SET) ||
+ if (gsf_input_seek (in, section->offset+props[i].offset, SEEK_SET) ||
NULL == (data = gsf_input_read (in, size, NULL))) {
warning ("failed to read prop #%d", i);
return NULL;
@@ -561,7 +557,6 @@
g_direct_hash, g_direct_equal,
NULL, g_free);
- d (gsf_mem_dump (data-4, size););
n = type;
for (i = 0 ; i < n ; i++) {
id = GSF_LE_GET_GUINT32 (data);
@@ -675,7 +670,7 @@
-static struct EXTRACTOR_Keywords * process(GsfInput * in,
+static struct EXTRACTOR_Keywords * process(struct GsfInput * in,
struct EXTRACTOR_Keywords * prev) {
guint8 const *data = gsf_input_read (in, 28, NULL);
guint16 version;
@@ -720,7 +715,6 @@
else {
sections [i].type = GSF_MSOLE_META_DATA_USER;
warning ("Unknown property section type, treating it as USER");
- d(gsf_mem_dump (data, 16););
}
sections [i].offset = GSF_LE_GET_GUINT32 (data + 16);
@@ -729,7 +723,7 @@
#endif
}
for (i = 0 ; i < num_sections ; i++) {
- if (gsf_input_seek (in, sections[i].offset, G_SEEK_SET) ||
+ if (gsf_input_seek (in, sections[i].offset, SEEK_SET) ||
NULL == (data = gsf_input_read (in, 8, NULL))) {
return prev;
}
@@ -870,9 +864,9 @@
return prev;
}
-static struct EXTRACTOR_Keywords * processSO(GsfInput * src,
+static struct EXTRACTOR_Keywords * processSO(struct GsfInput * src,
struct EXTRACTOR_Keywords * prev) {
- gsf_off_t size;
+ off_t size;
char * buf;
size = gsf_input_size(src);
@@ -923,46 +917,45 @@
char * date,
size_t size,
struct EXTRACTOR_Keywords * prev) {
- GsfInput *input;
- GsfInfile *infile;
+ struct GsfInput *input;
+ struct GsfInfileMSOle * infile;
+ struct GsfInput * src;
+ const char * name;
int i;
- input = gsf_input_memory_new((guint8 const *) date,
- (gsf_off_t) size,
- FALSE);
+ input = gsf_input_new((const unsigned char*) date,
+ (off_t) size,
+ 0);
if (input == NULL)
return prev;
- infile = gsf_infile_msole_new(input, NULL);
- g_object_unref(G_OBJECT(input));
-
+ infile = gsf_infile_msole_new(input);
if (infile == NULL)
return prev;
- if (GSF_IS_INFILE(infile) &&
- gsf_infile_num_children (GSF_INFILE (infile)) > 0) {
- GsfInfile * in = GSF_INFILE (infile);
- GsfInput * src;
- const char * name;
-
- for (i=0;i<gsf_infile_num_children(in);i++) {
- src = gsf_infile_child_by_index (in, i);
- name = gsf_infile_name_by_index (in, i);
-
- if ( (0 == strcmp(name, "\005SummaryInformation"))
- || (0 == strcmp(name, "\005DocumentSummaryInformation")) ) {
+ for (i=0;i<gsf_infile_msole_num_children(infile);i++) {
+ name = gsf_infile_msole_name_by_index (infile, i);
+ src = NULL;
+ if (name == NULL)
+ continue;
+ if ( (0 == strcmp(name, "\005SummaryInformation"))
+ || (0 == strcmp(name, "\005DocumentSummaryInformation")) ) {
+ src = gsf_infile_msole_child_by_index (infile, i);
+ if (src != NULL)
prev = process(src,
- prev);
- }
- if (0 == strcmp(name, "SfxDocumentInfo")) {
+ prev);
+ }
+ if (0 == strcmp(name, "SfxDocumentInfo")) {
+ src = gsf_infile_msole_child_by_index (infile, i);
+ if (src != NULL)
prev = processSO(src,
prev);
- }
- g_object_unref(src);
}
- }
- g_object_unref(G_OBJECT(infile));
+ if (src != NULL)
+ gsf_input_finalize(src);
+ }
+ gsf_infile_msole_finalize(infile);
return prev;
}
-
+/* end of ole2extractor.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r1645 - Extractor/src/plugins/ole2,
grothoff <=