Fixed typos
[gnumeric.git] / plugins / excel / ms-biff.h
blob5f111f652d0c10d1fa39e6a8789e856f7f43f7f4
1 /* vim: set sw=8 ts=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /**
3 * ms-biff.h: MS Excel BIFF support for Gnumeric
5 * Authors:
6 * Jody Goldberg (jody@gnome.org)
7 * Michael Meeks (michael@ximian.com)
9 * (C) 1998-2001 Michael Meeks
10 * (C) 2002-2005 Jody Goldberg
11 **/
12 #ifndef GNM_BIFF_H
13 #define GNM_BIFF_H
15 #include "rc4.h"
17 typedef enum { MS_BIFF_CRYPTO_NONE = 0,
18 MS_BIFF_CRYPTO_XOR,
19 MS_BIFF_CRYPTO_RC4,
20 MS_BIFF_CRYPTO_UNKNOWN } MsBiffCrypto ;
22 typedef enum {
23 MS_BIFF_V_UNKNOWN = 0,
24 MS_BIFF_V2 = 2,
25 MS_BIFF_V3 = 3,
26 MS_BIFF_V4 = 4,
27 MS_BIFF_V5 = 5, /* Excel 5.0 */
28 MS_BIFF_V7 = 7, /* Excel 95 */
29 MS_BIFF_V8 = 8 /* Excel 97, 2000, XP, 2003 */
30 } MsBiffVersion;
32 /*****************************************************************************/
33 /* Read Side */
34 /*****************************************************************************/
36 /**
37 * Returns query data, it is imperative that copies of
38 * 'data *' should _not_ be kept.
39 **/
40 typedef struct {
41 guint16 opcode;
42 guint32 length;
43 gboolean data_malloced, non_decrypted_data_malloced;
44 guint8 *data, *non_decrypted_data;
46 guint32 streamPos;
47 GsfInput *input;
49 MsBiffCrypto encryption;
50 guint8 xor_key[16];
51 RC4_KEY rc4_key;
52 unsigned char md5_digest[16];
53 int block;
54 gboolean dont_decrypt_next_record;
55 } BiffQuery;
57 /* Sets up a query on a stream */
58 BiffQuery *ms_biff_query_new (GsfInput *);
59 gboolean ms_biff_query_set_decrypt (BiffQuery *q, MsBiffVersion version,
60 guint8 const *password);
61 void ms_biff_query_copy_decrypt (BiffQuery *dst, BiffQuery const *src);
63 /* Updates the BiffQuery structure with the next BIFF record
64 * returns: TRUE for succes, and FALSE for EOS(tream) */
65 gboolean ms_biff_query_next (BiffQuery *);
66 gboolean ms_biff_query_peek_next (BiffQuery *, guint16 *opcode);
67 void ms_biff_query_destroy (BiffQuery *);
68 void ms_biff_query_dump (BiffQuery *);
69 guint32 ms_biff_query_bound_check (BiffQuery *q,
70 guint32 offset, unsigned len);
72 /*****************************************************************************/
73 /* Write Side */
74 /*****************************************************************************/
76 typedef struct _BiffPut {
77 guint16 opcode;
78 gsf_off_t streamPos;
79 unsigned curpos; /* Curpos is offset from beginning of header */
80 int len_fixed;
81 GsfOutput *output;
82 MsBiffVersion version;
85 * Records are stored here until committed at which time they may
86 * by split using BIFF_CONTINUE records.
88 GString *record;
90 int codepage;
91 GIConv convert;
92 } BiffPut;
94 /* Sets up a record on a stream */
95 BiffPut *ms_biff_put_new (GsfOutput *, MsBiffVersion version, int codepage);
96 void ms_biff_put_destroy (BiffPut *bp);
98 /**
99 * If between the 'next' and 'commit' ls / ms_op are changed they will be
100 * written correctly.
102 /* For known length records shorter than 0x2000 bytes. */
103 guint8 *ms_biff_put_len_next (BiffPut *bp, guint16 opcode, guint32 len);
104 /* For unknown length records */
105 void ms_biff_put_var_next (BiffPut *bp, guint16 opcode);
106 void ms_biff_put_var_write (BiffPut *bp, guint8 const *dat, guint32 len);
107 /* Seeks to pos bytes after the beggining of the record */
108 void ms_biff_put_var_seekto (BiffPut *bp, int pos);
109 /* Must commit after each record */
110 void ms_biff_put_commit (BiffPut *bp);
112 /* convenience routines for simple records */
113 void ms_biff_put_empty (BiffPut *bp, guint16 opcode);
114 void ms_biff_put_2byte (BiffPut *bp, guint16 opcode, guint16 data);
116 unsigned ms_biff_max_record_len (BiffPut const *bp);
118 void ms_biff_put_abs_write (BiffPut *bp, gsf_off_t pos, gconstpointer buf, gsize size);
120 #endif /* GNM_BIFF_H */