libmspack: /tmp/libmspack-20060924/mspack/mspack.h Source File

- Main Page
- Data Structures
- Files

- File List
- Globals

# /tmp/libmspack-20060924/mspack/mspack.h

Go to the documentation of this file.

    00001 /* libmspack -- a library for working with Microsoft compression formats.
    00002  * (C) 2003-2004 Stuart Caie <kyzer@4u.net>
    00003  *
    00004  * libmspack is free software; you can redistribute it and/or modify it under
    00005  * the terms of the GNU Lesser General Public License (LGPL) version 2.1
    00006  *
    00007  * This program is distributed in the hope that it will be useful,
    00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00010  * GNU Lesser General Public License for more details.
    00011  *
    00012  * You should have received a copy of the GNU Lesser General Public License
    00013  * along with this program; if not, write to the Free Software
    00014  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00015  */
    00016
    00118 #ifndef LIB_MSPACK_H
    00119 #define LIB_MSPACK_H 1
    00120
    00121 #ifdef __cplusplus
    00122 extern "C" {
    00123 #endif
    00124
    00125 #include <sys/types.h>
    00126 #include <stdlib.h>
    00127 #ifndef _MSC_VER
    00128 # include <unistd.h>
    00129 #endif /* _MSC_VER */
    00130
    00131 #include <unistd.h>
    00132
    00156 #define MSPACK_SYS_SELFTEST(result)  do { \
    00157   (result) = mspack_sys_selftest_internal(sizeof(off_t)); \
    00158 } while (0)
    00159
    00161 extern int mspack_sys_selftest_internal(int);
    00162
    00192 extern int mspack_version(int entity);
    00193
    00195 #define MSPACK_VER_LIBRARY   (0)
    00196
    00197 #define MSPACK_VER_SYSTEM    (1)
    00198
    00199 #define MSPACK_VER_MSCABD    (2)
    00200
    00201 #define MSPACK_VER_MSCABC    (3)
    00202
    00203 #define MSPACK_VER_MSCHMD    (4)
    00204
    00205 #define MSPACK_VER_MSCHMC    (5)
    00206
    00207 #define MSPACK_VER_MSLITD    (6)
    00208
    00209 #define MSPACK_VER_MSLITC    (7)
    00210
    00211 #define MSPACK_VER_MSHLPD    (8)
    00212
    00213 #define MSPACK_VER_MSHLPC    (9)
    00214
    00215 #define MSPACK_VER_MSSZDDD   (10)
    00216
    00217 #define MSPACK_VER_MSSZDDC   (11)
    00218
    00219 #define MSPACK_VER_MSKWAJD   (12)
    00220
    00221 #define MSPACK_VER_MSKWAJC   (13)
    00222
    00223 /* --- file I/O abstraction ------------------------------------------------ */
    00224
    00244 struct mspack_system {
    00269   struct mspack_file * (*open)(struct mspack_system *self,
    00270                                char *filename,
    00271                                int mode);
    00272
    00280   void (*close)(struct mspack_file *file);
    00281
    00293   int (*read)(struct mspack_file *file,
    00294               void *buffer,
    00295               int bytes);
    00296
    00310   int (*write)(struct mspack_file *file,
    00311                void *buffer,
    00312                int bytes);
    00313
    00337   int (*seek)(struct mspack_file *file,
    00338               off_t offset,
    00339               int mode);
    00340
    00348   off_t (*tell)(struct mspack_file *file);
    00349
    00364   void (*message)(struct mspack_file *file,
    00365                   char *format,
    00366                   ...);
    00367
    00378   void * (*alloc)(struct mspack_system *self,
    00379                   size_t bytes);
    00380
    00387   void (*free)(void *ptr);
    00388
    00401   void (*copy)(void *src,
    00402                void *dest,
    00403                size_t bytes);
    00404
    00411   void *null_ptr;
    00412 };
    00413
    00415 #define MSPACK_SYS_OPEN_READ   (0)
    00416
    00417 #define MSPACK_SYS_OPEN_WRITE  (1)
    00418
    00419 #define MSPACK_SYS_OPEN_UPDATE (2)
    00420
    00421 #define MSPACK_SYS_OPEN_APPEND (3)
    00422
    00424 #define MSPACK_SYS_SEEK_START  (0)
    00425
    00426 #define MSPACK_SYS_SEEK_CUR    (1)
    00427
    00428 #define MSPACK_SYS_SEEK_END    (2)
    00429
    00435 struct mspack_file {
    00436   int dummy;
    00437 };
    00438
    00439 /* --- error codes --------------------------------------------------------- */
    00440
    00442 #define MSPACK_ERR_OK          (0)
    00443
    00444 #define MSPACK_ERR_ARGS        (1)
    00445
    00446 #define MSPACK_ERR_OPEN        (2)
    00447
    00448 #define MSPACK_ERR_READ        (3)
    00449
    00450 #define MSPACK_ERR_WRITE       (4)
    00451
    00452 #define MSPACK_ERR_SEEK        (5)
    00453
    00454 #define MSPACK_ERR_NOMEMORY    (6)
    00455
    00456 #define MSPACK_ERR_SIGNATURE   (7)
    00457
    00458 #define MSPACK_ERR_DATAFORMAT  (8)
    00459
    00460 #define MSPACK_ERR_CHECKSUM    (9)
    00461
    00462 #define MSPACK_ERR_CRUNCH      (10)
    00463
    00464 #define MSPACK_ERR_DECRUNCH    (11)
    00465
    00466 /* --- functions available in library -------------------------------------- */
    00467
    00472 extern struct mscab_compressor *
    00473   mspack_create_cab_compressor(struct mspack_system *sys);
    00474
    00479 extern struct mscab_decompressor *
    00480   mspack_create_cab_decompressor(struct mspack_system *sys);
    00481
    00485 extern void mspack_destroy_cab_compressor(struct mscab_compressor *self);
    00486
    00490 extern void mspack_destroy_cab_decompressor(struct mscab_decompressor *self);
    00491
    00492
    00497 extern struct mschm_compressor *
    00498   mspack_create_chm_compressor(struct mspack_system *sys);
    00499
    00504 extern struct mschm_decompressor *
    00505   mspack_create_chm_decompressor(struct mspack_system *sys);
    00506
    00510 extern void mspack_destroy_chm_compressor(struct mschm_compressor *self);
    00511
    00515 extern void mspack_destroy_chm_decompressor(struct mschm_decompressor *self);
    00516
    00517
    00522 extern struct mslit_compressor *
    00523   mspack_create_lit_compressor(struct mspack_system *sys);
    00524
    00529 extern struct mslit_decompressor *
    00530   mspack_create_lit_decompressor(struct mspack_system *sys);
    00531
    00535 extern void mspack_destroy_lit_compressor(struct mslit_compressor *self);
    00536
    00540 extern void mspack_destroy_lit_decompressor(struct mslit_decompressor *self);
    00541
    00542
    00547 extern struct mshlp_compressor *
    00548   mspack_create_hlp_compressor(struct mspack_system *sys);
    00549
    00554 extern struct mshlp_decompressor *
    00555   mspack_create_hlp_decompressor(struct mspack_system *sys);
    00556
    00560 extern void mspack_destroy_hlp_compressor(struct mshlp_compressor *self);
    00561
    00565 extern void mspack_destroy_hlp_decompressor(struct mshlp_decompressor *self);
    00566
    00567
    00572 extern struct msszdd_compressor *
    00573   mspack_create_szdd_compressor(struct mspack_system *sys);
    00574
    00579 extern struct msszdd_decompressor *
    00580   mspack_create_szdd_decompressor(struct mspack_system *sys);
    00581
    00585 extern void mspack_destroy_szdd_compressor(struct msszdd_compressor *self);
    00586
    00590 extern void mspack_destroy_szdd_decompressor(struct msszdd_decompressor *self);
    00591
    00592
    00597 extern struct mskwaj_compressor *
    00598   mspack_create_kwaj_compressor(struct mspack_system *sys);
    00599
    00604 extern struct mskwaj_decompressor *
    00605   mspack_create_kwaj_decompressor(struct mspack_system *sys);
    00606
    00610 extern void mspack_destroy_kwaj_compressor(struct mskwaj_compressor *self);
    00611
    00615 extern void mspack_destroy_kwaj_decompressor(struct mskwaj_decompressor *self);
    00616
    00617
    00618 /* --- support for .CAB (MS Cabinet) file format --------------------------- */
    00619
    00631 struct mscabd_cabinet {
    00637   struct mscabd_cabinet *next;
    00638
    00644   char *filename;
    00645
    00647   off_t base_offset;
    00648
    00650   unsigned int length;
    00651
    00653   struct mscabd_cabinet *prevcab;
    00654
    00656   struct mscabd_cabinet *nextcab;
    00657
    00659   char *prevname;
    00660
    00662   char *nextname;
    00663
    00667   char *previnfo;
    00668
    00672   char *nextinfo;
    00673
    00675   struct mscabd_file *files;
    00676
    00678   struct mscabd_folder *folders;
    00679
    00684   unsigned short set_id;
    00685
    00691   unsigned short set_index;
    00692
    00703   unsigned short header_resv;
    00704
    00716   int flags;
    00717 };
    00718
    00720 #define MSCAB_HDR_RESV_OFFSET (0x28)
    00721
    00723 #define MSCAB_HDR_PREVCAB (0x01)
    00724
    00725 #define MSCAB_HDR_NEXTCAB (0x02)
    00726
    00727 #define MSCAB_HDR_RESV    (0x04)
    00728
    00738 struct mscabd_folder {
    00743   struct mscabd_folder *next;
    00744
    00754   int comp_type;
    00755
    00761   unsigned int num_blocks;
    00762 };
    00763
    00771 #define MSCABD_COMP_METHOD(comp_type) ((comp_type) & 0x0F)
    00772
    00779 #define MSCABD_COMP_LEVEL(comp_type) (((comp_type) >> 8) & 0x1F)
    00780
    00782 #define MSCAB_COMP_NONE       (0)
    00783
    00784 #define MSCAB_COMP_MSZIP      (1)
    00785
    00786 #define MSCAB_COMP_QUANTUM    (2)
    00787
    00788 #define MSCAB_COMP_LZX        (3)
    00789
    00795 struct mscabd_file {
    00800   struct mscabd_file *next;
    00801
    00810   char *filename;
    00811
    00813   unsigned int length;
    00814
    00827   int attribs;
    00828
    00830   char time_h;
    00832   char time_m;
    00834   char time_s;
    00835
    00837   char date_d;
    00839   char date_m;
    00841   int date_y;
    00842
    00844   struct mscabd_folder *folder;
    00845
    00847   unsigned int offset;
    00848 };
    00849
    00851 #define MSCAB_ATTRIB_RDONLY   (0x01)
    00852
    00853 #define MSCAB_ATTRIB_HIDDEN   (0x02)
    00854
    00855 #define MSCAB_ATTRIB_SYSTEM   (0x04)
    00856
    00857 #define MSCAB_ATTRIB_ARCH     (0x20)
    00858
    00859 #define MSCAB_ATTRIB_EXEC     (0x40)
    00860
    00861 #define MSCAB_ATTRIB_UTF_NAME (0x80)
    00862
    00864 #define MSCABD_PARAM_SEARCHBUF (0)
    00865
    00866 #define MSCABD_PARAM_FIXMSZIP  (1)
    00867
    00868 #define MSCABD_PARAM_DECOMPBUF (2)
    00869
    00871 struct mscab_compressor {
    00872   int dummy;
    00873 };
    00874
    00882 struct mscab_decompressor {
    00903   struct mscabd_cabinet * (*open) (struct mscab_decompressor *self,
    00904                                    char *filename);
    00905
    00935   void (*close)(struct mscab_decompressor *self,
    00936                 struct mscabd_cabinet *cab);
    00937
    00972   struct mscabd_cabinet * (*search) (struct mscab_decompressor *self,
    00973                                      char *filename);
    00974
    01015   int (*append) (struct mscab_decompressor *self,
    01016                  struct mscabd_cabinet *cab,
    01017                  struct mscabd_cabinet *nextcab);
    01018
    01037   int (*prepend) (struct mscab_decompressor *self,
    01038                   struct mscabd_cabinet *cab,
    01039                   struct mscabd_cabinet *prevcab);
    01040
    01063   int (*extract)(struct mscab_decompressor *self,
    01064                  struct mscabd_file *file,
    01065                  char *filename);
    01066
    01089   int (*set_param)(struct mscab_decompressor *self,
    01090                    int param,
    01091                    int value);
    01092
    01104   int (*last_error)(struct mscab_decompressor *self);
    01105 };
    01106
    01107 /* --- support for .CHM (HTMLHelp) file format ----------------------------- */
    01108
    01117 struct mschmc_file {
    01119   int section;
    01120
    01123   char *filename;
    01124
    01127   char *chm_filename;
    01128
    01132   off_t length;
    01133 };
    01134
    01143 struct mschmd_section {
    01145   struct mschmd_header *chm;
    01146
    01152   unsigned int id;
    01153 };
    01154
    01160 struct mschmd_sec_uncompressed {
    01162   struct mschmd_section base;
    01163
    01165   off_t offset;
    01166 };
    01167
    01173 struct mschmd_sec_mscompressed {
    01175   struct mschmd_section base;
    01176
    01178   struct mschmd_file *content;
    01179
    01181   struct mschmd_file *control;
    01182
    01184   struct mschmd_file *rtable;
    01185 };
    01186
    01192 struct mschmd_header {
    01194   unsigned int version;
    01195
    01203   unsigned int timestamp;
    01204
    01209   unsigned int language;
    01210
    01215   char *filename;
    01216
    01218   off_t length;
    01219
    01221   struct mschmd_file *files;
    01222
    01229   struct mschmd_file *sysfiles;
    01230
    01232   struct mschmd_sec_uncompressed sec0;
    01233
    01235   struct mschmd_sec_mscompressed sec1;
    01236
    01238   off_t dir_offset;
    01239
    01241   unsigned int num_chunks;
    01242
    01244   unsigned int chunk_size;
    01245
    01247   unsigned int density;
    01248
    01257   unsigned int depth;
    01258
    01264   unsigned int index_root;
    01265 };
    01266
    01272 struct mschmd_file {
    01277   struct mschmd_file *next;
    01278
    01283   struct mschmd_section *section;
    01284
    01286   off_t offset;
    01287
    01289   off_t length;
    01290
    01292   char *filename;
    01293 };
    01294
    01296 #define MSCHMC_ENDLIST   (0)
    01297
    01298 #define MSCHMC_UNCOMP    (1)
    01299
    01300 #define MSCHMC_MSCOMP    (2)
    01301
    01303 #define MSCHMC_PARAM_TIMESTAMP  (0)
    01304
    01305 #define MSCHMC_PARAM_LANGUAGE   (1)
    01306
    01307 #define MSCHMC_PARAM_LZXWINDOW  (2)
    01308
    01309 #define MSCHMC_PARAM_DENSITY    (3)
    01310
    01311 #define MSCHMC_PARAM_INDEX      (4)
    01312
    01320 struct mschm_compressor {
    01352   int (*generate)(struct mschm_compressor *self,
    01353                   struct mschmc_file file_list[],
    01354                   char *output_file);
    01355
    01409   int (*use_temporary_file)(struct mschm_compressor *self,
    01410                             int use_temp_file,
    01411                             char *temp_file);
    01457   int (*set_param)(struct mschm_compressor *self,
    01458                    int param,
    01459                    unsigned int value);
    01460
    01469   int (*last_error)(struct mschm_compressor *self);
    01470 };
    01471
    01479 struct mschm_decompressor {
    01500   struct mschmd_header *(*open)(struct mschm_decompressor *self,
    01501                                 char *filename);
    01502
    01520   void (*close)(struct mschm_decompressor *self,
    01521                 struct mschmd_header *chm);
    01522
    01541   int (*extract)(struct mschm_decompressor *self,
    01542                  struct mschmd_file *file,
    01543                  char *filename);
    01544
    01556   int (*last_error)(struct mschm_decompressor *self);
    01557
    01580   struct mschmd_header *(*fast_open)(struct mschm_decompressor *self,
    01581                                      char *filename);
    01582
    01621   int (*fast_find)(struct mschm_decompressor *self,
    01622                    struct mschmd_header *chm,
    01623                    char *filename,
    01624                    struct mschmd_file *f_ptr,
    01625                    int f_size);
    01626 };
    01627
    01628 /* --- support for .LIT (EBook) file format -------------------------------- */
    01629
    01631 struct mslit_compressor {
    01632   int dummy;
    01633 };
    01634
    01636 struct mslit_decompressor {
    01637   int dummy;
    01638 };
    01639
    01640
    01641 /* --- support for .HLP (MS Help) file format ------------------------------ */
    01642
    01644 struct mshlp_compressor {
    01645   int dummy;
    01646 };
    01647
    01649 struct mshlp_decompressor {
    01650   int dummy;
    01651 };
    01652
    01653
    01654 /* --- support for SZDD file format ---------------------------------------- */
    01655
    01657 #define MSSZDDC_PARAM_MISSINGCHAR (0)
    01658
    01664 struct msszddd_header {
    01666   off_t length;
    01667
    01675   char missing_char;
    01676 };
    01677
    01685 struct msszdd_compressor {
    01721   int (*compress)(struct msszdd_compressor *self,
    01722                   char *input,
    01723                   char *output,
    01724                   off_t length);
    01725
    01747   int (*set_param)(struct msszdd_compressor *self,
    01748                    int param,
    01749                    unsigned int value);
    01750
    01759   int (*last_error)(struct mschm_decompressor *self);
    01760 };
    01761
    01769 struct msszdd_decompressor {
    01789   struct msszddd_header *(*open)(struct msszdd_decompressor *self,
    01790                                  char *filename);
    01791
    01807   void (*close)(struct msszdd_decompressor *self,
    01808                 struct msszddd_header *szdd);
    01809
    01823   int (*extract)(struct msszdd_decompressor *self,
    01824                  struct msszddd_header *szdd,
    01825                  char *filename);
    01826
    01844   int (*decompress)(struct msszdd_decompressor *self,
    01845                     char *input,
    01846                     char *output);
    01847
    01859   int (*last_error)(struct msszdd_decompressor *self);
    01860 };
    01861
    01862 /* --- support for KWAJ file format ---------------------------------------- */
    01863
    01865 struct mskwaj_compressor {
    01866   int dummy;
    01867 };
    01868
    01870 struct mskwaj_decompressor {
    01871   int dummy;
    01872 };
    01873
    01874 #ifdef __cplusplus
    01875 };
    01876 #endif
    01877
    01878 #endif