Commit 5f3d678a authored by Michael Meeks's avatar Michael Meeks

More work on libole's API,

fixed 'ole' & re-included it in the make,
culled some old & dangerous code.
parent 24a6508b
1999-09-20 Michael Meeks <michael@nuclecu.unam.mx>
* ole.c: massive, huge, big clean to new API; ahh that feels good,
add 'help' command. Break escher debug for now.
* Makefile.am: re-enabled 'ole'
* ms-biff.h: removed all mention of quirks.
* ms-biff.c (ms_biff_query_copy): dangerous: removed, clean quirk stuff.
1999-09-20 Jody Goldberg <jgoldberg@home.com>
* ms-obj.[ch]: Remove a few #if ENABLE_BONOBO checks
......
......@@ -37,18 +37,18 @@ libexcel_a_SOURCES = \
ms-summary.c \
ms-summary.h
#noinst_PROGRAMS = \
# ole
#
#ole_SOURCES = \
# ole.c
#
#
#ole_LDADD = \
# ms-biff.o \
# libole2/libole2.a \
# $(GNOME_LIBDIR) \
# $(GNOME_LIBS) \
# $(INTLLIBS)
#
noinst_PROGRAMS = \
ole
ole_SOURCES = \
ole.c
ole_LDADD = \
ms-biff.o \
libole2/libole2.a \
$(GNOME_LIBDIR) \
$(GNOME_LIBS) \
$(INTLLIBS)
SUBDIRS = libole2
1999-09-20 Michael Meeks <michael@nuclecu.unam.mx>
* ms-ole.c (path_to_pps): add degenerate no file case.
(ms_ole_unlink): stub (ms_ole_directory): implemented.
(ms_ole_stat): implemented.
1999-09-20 Michael Meeks <michael@nuclecu.unam.mx>
* ms-ole.c (ms_ole_destroy): Paper bag error.
......
......@@ -58,9 +58,6 @@ struct _MsOle
};
typedef guint32 PPS_IDX ;
typedef enum _PPSType { MsOlePPSStorage = 1,
MsOlePPSStream = 2,
MsOlePPSRoot = 5} PPSType ;
#if OLE_DEBUG > 0
/* Very grim, but quite necessary */
......@@ -98,7 +95,7 @@ struct _PPS {
PPS *parent;
guint32 size;
BLP start;
PPSType type;
MsOleType type;
PPS_IDX idx; /* Only used on write */
};
......@@ -260,7 +257,7 @@ get_block_ptr (MsOle *f, BLP b, gboolean forwrite)
/* These get other interesting stuff from the PPS record */
#define PPS_GET_STARTBLOCK(p) ( MS_OLE_GET_GUINT32(p + 0x74))
#define PPS_GET_SIZE(p) ( MS_OLE_GET_GUINT32(p + 0x78))
#define PPS_GET_TYPE(p) ((PPSType)( MS_OLE_GET_GUINT8(p + 0x42)))
#define PPS_GET_TYPE(p) ((MsOleType)( MS_OLE_GET_GUINT8(p + 0x42)))
#define PPS_SET_STARTBLOCK(p,i) ( MS_OLE_SET_GUINT32(p + 0x74, i))
#define PPS_SET_SIZE(p,i) ( MS_OLE_SET_GUINT32(p + 0x78, i))
#define PPS_SET_TYPE(p,i) ( MS_OLE_SET_GUINT8 (p + 0x42, i))
......@@ -882,7 +879,7 @@ pps_encode_tree_chain (MsOle *f, GList *list)
#if OLE_DEBUG > 0
printf ("Chaining previous for '%s'\n", p->name);
#endif
if (p->type == MsOlePPSStorage)
if (p->type == MsOleStorageT)
pps_encode_tree_chain (f, l);
mem = get_pps_ptr (f, p->idx, TRUE);
......@@ -918,7 +915,7 @@ pps_encode_tree_chain (MsOle *f, GList *list)
#if OLE_DEBUG > 0
printf ("Chaining next for '%s'\n", p->name);
#endif
if (p->type == MsOlePPSStorage)
if (p->type == MsOleStorageT)
pps_encode_tree_chain (f, l);
mem = get_pps_ptr (f, p->idx, TRUE);
......@@ -1356,7 +1353,7 @@ ms_ole_create (MsOle **f, const char *name)
p->sig = PPS_SIG;
p->name = g_strdup ("Root Entry");
p->start = END_OF_CHAIN;
p->type = MsOlePPSRoot;
p->type = MsOleRootT;
p->size = 0;
p->children = NULL;
p->parent = NULL;
......@@ -1992,7 +1989,7 @@ ms_ole_write_sb (MsOleStream *s, guint8 *ptr, MsOlePos length)
* Return value: error status
**/
static MsOleErr
pps_create (GList **p, GList *parent, const char *name, PPSType type)
pps_create (GList **p, GList *parent, const char *name, MsOleType type)
{
PPS *pps, *par;
......@@ -2043,8 +2040,8 @@ find_in_pps (GList *l, const char *name)
pps = l->data;
g_return_val_if_fail (IS_PPS (pps), NULL);
if (pps->type == MsOlePPSStorage ||
pps->type == MsOlePPSRoot)
if (pps->type == MsOleStorageT ||
pps->type == MsOleRootT)
cur = pps->children;
else {
g_warning ("trying to enter a stream '%s'",
......@@ -2106,7 +2103,7 @@ path_to_pps (PPS **pps, MsOle *f, const char *path,
cur = find_in_pps (parent, dirs[lp]);
if (!cur && create_if_not_found &&
pps_create (&cur, parent, dirs[lp], MsOlePPSStorage) !=
pps_create (&cur, parent, dirs[lp], MsOleStorageT) !=
MS_OLE_ERR_OK)
cur = NULL;
/* else carry on not finding them before dropping out */
......@@ -2118,6 +2115,12 @@ path_to_pps (PPS **pps, MsOle *f, const char *path,
if (!cur || !cur->data)
return MS_OLE_ERR_EXIST;
if (file[0] == '\0') { /* We just want a directory */
*pps = cur->data;
g_return_val_if_fail (IS_PPS (cur->data), MS_OLE_ERR_INVALID);
return MS_OLE_ERR_OK;
}
parent = cur;
cur = find_in_pps (parent, file);
......@@ -2125,7 +2128,7 @@ path_to_pps (PPS **pps, MsOle *f, const char *path,
if (!cur) {
if (create_if_not_found) {
MsOleErr result;
result = pps_create (&cur, parent, file, MsOlePPSStream);
result = pps_create (&cur, parent, file, MsOleStreamT);
if (result == MS_OLE_ERR_OK) {
*pps = cur->data;
g_return_val_if_fail (IS_PPS (cur->data),
......@@ -2146,6 +2149,75 @@ path_to_pps (PPS **pps, MsOle *f, const char *path,
return MS_OLE_ERR_EXIST;
}
MsOleErr
ms_ole_unlink (MsOle *f, const char *path)
{
g_warning ("Unimplemented");
return MS_OLE_ERR_NOTEMPTY;
}
MsOleErr
ms_ole_directory (char ***names, MsOle *f, const char *path)
{
char **ans;
PPS *pps;
MsOleErr result;
GList *l;
int lp;
g_return_val_if_fail (f != NULL, MS_OLE_ERR_BADARG);
g_return_val_if_fail (path != NULL, MS_OLE_ERR_BADARG);
if ((result = path_to_pps (&pps, f, path, "", FALSE)) !=
MS_OLE_ERR_OK)
return result;
if (!pps)
return MS_OLE_ERR_INVALID;
l = pps->children;
ans = g_new (char *, g_list_length (l) + 1);
lp = 0;
for (; l; l = g_list_next (l)) {
pps = (PPS *)l->data;
if (!pps->name)
continue;
ans[lp] = g_strdup (pps->name);
lp++;
}
ans[lp] = NULL;
*names = ans;
return MS_OLE_ERR_OK;
}
MsOleErr
ms_ole_stat (MsOleStat *stat, MsOle *f, const char *path,
const char *file)
{
PPS *pps;
MsOleErr result;
g_return_val_if_fail (f != NULL, MS_OLE_ERR_BADARG);
g_return_val_if_fail (file != NULL, MS_OLE_ERR_BADARG);
g_return_val_if_fail (path != NULL, MS_OLE_ERR_BADARG);
g_return_val_if_fail (stat != NULL, MS_OLE_ERR_BADARG);
if ((result = path_to_pps (&pps, f, path, file, FALSE)) !=
MS_OLE_ERR_OK)
return result;
if (!pps)
return MS_OLE_ERR_INVALID;
stat->type = pps->type;
stat->size = pps->size;
return MS_OLE_ERR_OK;
}
/**
* ms_ole_stream_open:
* @d: directory entry handle
......@@ -2313,6 +2385,7 @@ ms_ole_stream_duplicate (MsOleStream **s, const MsOleStream * const stream)
if (!s || !stream)
return MS_OLE_ERR_BADARG;
/* Lets face it having two pointers to the same file is a nightmare anyway :-) */
g_warning ("Do NOT use this function, it is unsafe with the blocks array");
if (!(*s = g_new (MsOleStream, 1)))
......
......@@ -42,6 +42,7 @@ typedef enum { MS_OLE_ERR_OK,
MS_OLE_ERR_PERM,
MS_OLE_ERR_MEM,
MS_OLE_ERR_SPACE,
MS_OLE_ERR_NOTEMPTY,
MS_OLE_ERR_BADARG } MsOleErr;
/* Block pointer */
......@@ -66,6 +67,16 @@ typedef enum { MsOleSeekSet, MsOleSeekCur, MsOleSeekEnd } MsOleSeek;
};
#endif /* MS_OLE_H_IMPLEMENTATION */
typedef enum { MsOleStorageT = 1,
MsOleStreamT = 2,
MsOleRootT = 5} MsOleType ;
typedef struct {
MsOleType type;
/* Valid only for Streams */
MsOlePos size;
} MsOleStat;
/* Create new OLE file */
extern MsOleErr ms_ole_create (MsOle **, const char *name) ;
/* Open existing OLE file */
......@@ -73,6 +84,10 @@ extern MsOleErr ms_ole_open (MsOle **, const char *name) ;
extern void ms_ole_ref (MsOle *);
extern void ms_ole_unref (MsOle *);
extern void ms_ole_destroy (MsOle **);
extern MsOleErr ms_ole_unlink (MsOle *f, const char *path);
extern MsOleErr ms_ole_directory (char ***names, MsOle *f, const char *path);
extern MsOleErr ms_ole_stat (MsOleStat *stat, MsOle *f, const char *path,
const char *file);
struct _MsOleStream
{
......@@ -114,9 +129,6 @@ extern MsOleErr ms_ole_stream_open (MsOleStream ** const stream, MsOle *f,
extern MsOleErr ms_ole_stream_close (MsOleStream ** const stream);
extern MsOleErr ms_ole_stream_duplicate (MsOleStream ** const copy,
const MsOleStream * const stream);
extern MsOleErr ms_ole_storage_unlink (MsOle *f, const char *path);
extern MsOleErr ms_ole_stream_unlink (MsOle *f, const char *path);
extern MsOleErr ms_ole_storage_directory (char ***names, const char *path);
extern void dump (guint8 const *ptr, guint32 len) ;
......
......@@ -71,12 +71,6 @@ dump_biff (BiffQuery *bq)
/* Read Side */
/*******************************************************************************/
/*static guint16
no_quirks (const BiffQuery *q, guint16 op)
{
return 0;
}*/
BiffQuery *
ms_biff_query_new (MsOleStream *ptr)
{
......@@ -90,43 +84,12 @@ ms_biff_query_new (MsOleStream *ptr)
/* bq->padding = 0; */
bq->num_merges = 0;
bq->pos = ptr;
/* bq->quirk = no_quirks;*/
#if BIFF_DEBUG > 0
dump_biff(bq);
#endif
return bq;
}
/*void
ms_biff_query_set_quirk (BiffQuery *bq, BiffQuirkFn *quirk)
{
g_return_if_fail (bq != NULL);
bq->quirk = quirk;
}*/
BiffQuery *
ms_biff_query_copy (const BiffQuery *p)
{
BiffQuery *bf = g_new (BiffQuery, 1);
memcpy (bf, p, sizeof (BiffQuery));
if (p->data_malloced) {
bf->data = (guint8 *)g_malloc (p->length);
memcpy (bf->data, p->data, p->length);
}
if (ms_ole_stream_duplicate (&bf->pos, p->pos) !=
MS_OLE_ERR_OK) {
g_free (bf->data);
g_free (bf);
return NULL;
}
return bf;
}
/**
* I know this is ugly but its not so much my fault !
**/
......@@ -156,8 +119,6 @@ ms_biff_merge_continues (BiffQuery *bq, guint32 len)
total_len = chunk.length;
g_array_append_val (contin, chunk);
/* bq->padding = bq->quirk (bq, bq->opcode); */
/* Subsequent continue blocks */
chunk.length = len;
do {
......@@ -333,7 +294,7 @@ ms_biff_put_new (MsOleStream *s)
bp->data_malloced = 0;
bp->len_fixed = 0;
bp->pos = s;
/* bp->quirk = no_quirks;*/
return bp;
}
......
......@@ -28,8 +28,6 @@ extern void biff_setdouble (guint8 *p, double d);
typedef struct _BiffQuery BiffQuery;
typedef guint16 (BiffQuirkFn) (const BiffQuery *, guint16 op);
/**
* Returns query data, it is imperative that copies of
* 'data *' should _not_ be kept.
......@@ -45,15 +43,10 @@ struct _BiffQuery {
/* gint16 padding;*/
int data_malloced; /* is *data a copy ? */
MsOleStream *pos;
BiffQuirkFn *quirk; /* Ugly ! */
};
/* Sets up a query on a stream */
extern BiffQuery *ms_biff_query_new (MsOleStream *);
/*extern void ms_biff_query_set_quirk (BiffQuery *,
BiffQuirkFn *);*/
/* Duplicates this query, so chaining can re-commence here */
extern BiffQuery *ms_biff_query_copy (const BiffQuery *p);
/* Updates the BiffQuery structure with the next BIFF record
* returns: 1 for succes, and 0 for EOS(tream) */
extern int ms_biff_query_next_merge (BiffQuery *, gboolean do_merge);
......@@ -80,7 +73,6 @@ typedef struct _BiffPut
int data_malloced;
int len_fixed;
MsOleStream *pos;
BiffQuirkFn *quirk; /* Ugly ! */
} BiffPut;
/* Sets up a record on a stream */
......
......@@ -117,30 +117,34 @@ get_escher_opcode_name (guint16 opcode)
static void
list_files (MsOle *ole)
{
MsOleDirectory *dir = ms_ole_path_decode (ole, cur_dir);
g_assert (dir);
while (ms_ole_directory_next(dir)) {
if (dir->type == MsOlePPSStream)
printf ("'%25s : length %d bytes\n", dir->name, dir->length);
else if (dir->type == MsOlePPSStorage)
printf ("'[%s] : Storage ( directory )\n", dir->name);
char **names;
MsOleErr result;
int lp;
result = ms_ole_directory (&names, ole, cur_dir);
if (result != MS_OLE_ERR_OK) {
g_warning ("Failed dir");
return;
}
if (!names[0])
g_warning ("You entered a file !");
for (lp = 0; names[lp]; lp++) {
MsOleStat s;
result = ms_ole_stat (&s, ole, cur_dir, names[lp]);
if (s.type == MsOleStreamT)
printf ("'%25s : length %d bytes\n", names[lp], s.size);
else
printf ("Wierd - '%25s' : type %d, length %d bytes\n", dir->name, dir->type, dir->length);
printf ("'[%s] : Storage ( directory )\n", names [lp]);
}
}
static void
syntax_error(char *err)
list_commands ()
{
if (err) {
printf("Error; '%s'\n",err);
exit(1);
}
printf ("Sytax:\n");
printf (" ole <ole-file> [-i] [commands...]\n\n");
printf (" -i: Interactive, queries for fresh commands\n\n");
printf ("command can be one or all of:\n");
printf (" * ls: list files\n");
printf (" * cd: enter storage\n");
......@@ -156,6 +160,20 @@ syntax_error(char *err)
printf (" * copyin [<fname>,]...\n");
printf (" * copyout [<fname>,]...\n");
printf (" * quit,exit,bye: exit\n");
}
static void
syntax_error(char *err)
{
if (err) {
printf("Error; '%s'\n",err);
exit(1);
}
printf ("Sytax:\n");
printf (" ole <ole-file> [-i] [commands...]\n\n");
printf (" -i: Interactive, queries for fresh commands\n\n");
list_commands ();
exit(1);
}
......@@ -241,7 +259,7 @@ esh_header_destroy (ESH_HEADER *h)
static int
biff_to_flat_data (const BiffQuery *q, guint8 **data, guint32 *length)
{
BiffQuery *nq = ms_biff_query_copy (q);
/* BiffQuery *nq = ms_biff_query_copy (q);
guint8 *ptr;
int cnt=0;
......@@ -264,8 +282,10 @@ biff_to_flat_data (const BiffQuery *q, guint8 **data, guint32 *length)
ms_biff_query_next(nq);
} while (nq->opcode == BIFF_CONTINUE ||
nq->opcode == BIFF_MS_O_DRAWING ||
nq->opcode == BIFF_MS_O_DRAWING_GROUP);
return cnt;
nq->opcode == BIFF_MS_O_DRAWING_GROUP);*/
g_warning ("This needs re-implementing by Jody");
return 0;
}
/* ---------------------------- End cut ---------------------------- */
......@@ -301,7 +321,6 @@ static void
enter_dir (MsOle *ole)
{
char *newpath, *ptr;
MsOleDirectory *dir;
ptr = strtok (NULL, delim);
if (!ptr) {
......@@ -327,51 +346,80 @@ enter_dir (MsOle *ole)
cur_dir = newp->str;
g_string_free (newp, FALSE);
} else {
MsOleStat s;
MsOleErr result;
newpath = g_strconcat (cur_dir, ptr, "/", NULL);
dir = ms_ole_path_decode (ole, newpath);
if (!dir) {
result = ms_ole_stat (&s, ole, newpath, "");
if (result == MS_OLE_ERR_EXIST) {
printf ("Storage '%s' not found\n", ptr);
ms_ole_directory_destroy (dir);
} else {
g_free (cur_dir);
cur_dir = newpath;
g_free (newpath);
return;
}
if (result != MS_OLE_ERR_OK) {
g_warning ("internal error");
g_free (newpath);
return;
}
if (s.type != MsOleStorageT ||
s.type != MsOleRootT) {
printf ("Trying to enter a stream");
g_free (newpath);
return;
}
g_free (cur_dir);
cur_dir = newpath;
}
}
static void
do_dump (MsOle *ole)
{
char *ptr;
MsOleDirectory *dir;
char *ptr;
MsOleStream *stream;
guint8 *buffer;
ptr = strtok (NULL, delim);
if ((dir = ms_ole_file_decode (ole, cur_dir, ptr)))
{
MsOleStream *stream = ms_ole_stream_open (dir, 'r');
guint8 *buffer = g_malloc (dir->length);
stream->read_copy (stream, buffer, dir->length);
printf ("Stream : '%s' length 0x%x\n", ptr, dir->length);
if (buffer)
dump (buffer, dir->length);
else
printf ("Failed read\n");
ms_ole_stream_close (stream);
} else
if (!ptr) {
printf ("Need a stream name\n");
return;
}
if (ms_ole_stream_open (&stream, ole, cur_dir, ptr, 'r') !=
MS_OLE_ERR_OK) {
printf ("Error opening '%s'\n", ptr);
return;
}
buffer = g_malloc (stream->size);
stream->read_copy (stream, buffer, stream->size);
printf ("Stream : '%s' length 0x%x\n", ptr, stream->size);
if (buffer)
dump (buffer, stream->size);
else
printf ("Failed read\n");
ms_ole_stream_close (&stream);
}
static void
do_biff (MsOle *ole)
{
char *ptr;
MsOleDirectory *dir;
MsOleStream *stream;
ptr = strtok (NULL, delim);
if ((dir = ms_ole_file_decode (ole, cur_dir, ptr)))
if (!ptr) {
printf ("Need a stream name\n");
return;
}
if (ms_ole_stream_open (&stream, ole, cur_dir, ptr, 'r') !=
MS_OLE_ERR_OK) {
printf ("Error opening '%s'\n", ptr);
return;
}
{
MsOleStream *stream = ms_ole_stream_open (dir, 'r');
BiffQuery *q = ms_biff_query_new (stream);
guint16 last_opcode=0xffff;
guint32 last_length=0;
......@@ -393,21 +441,28 @@ do_biff (MsOle *ole)
last_length=q->length;
}
printf ("\n");
ms_ole_stream_close (stream);
} else
printf ("Need a stream name\n");
ms_ole_stream_close (&stream);
}
}
static void
do_biff_raw (MsOle *ole)
{
char *ptr;
MsOleDirectory *dir;
MsOleStream *stream;
ptr = strtok (NULL, delim);
if ((dir = ms_ole_file_decode (ole, cur_dir, ptr)))
if (!ptr) {
printf ("Need a stream name\n");
return;
}
if (ms_ole_stream_open (&stream, ole, cur_dir, ptr, 'r') !=
MS_OLE_ERR_OK) {
printf ("Error opening '%s'\n", ptr);
return;
}
{
MsOleStream *stream = ms_ole_stream_open (dir, 'r');
guint8 data[4], *buffer;
buffer = g_new (guint8, 65550);
......@@ -421,21 +476,27 @@ do_biff_raw (MsOle *ole)
buffer[0]=0;
buffer[len-1]=0;
}
ms_ole_stream_close (stream);
} else
printf ("Need a stream name\n");
ms_ole_stream_close (&stream);
}
}
static void
do_draw (MsOle *ole, gboolean raw)
{
char *ptr;
MsOleDirectory *dir;
MsOleStream *stream;
ptr = strtok (NULL, delim);