Back to index

lightning-sunbird  0.9+nobinonly
nsMsgBinHex.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org Code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 /*
00039 *      The head file for Bin Hex 4.0 encode/decode 
00040 *      -------------------------------------------
00041 *      
00042 *             10sep95       mym    created
00043 */
00044 
00045 #ifndef       binhex_h
00046 #define       binhex_h
00047 
00048 #include "nsFileSpec.h"
00049 #include "nsFileStream.h"
00050 
00051 #ifdef XP_MAC
00052 #if PRAGMA_ALIGN_SUPPORTED
00053 #pragma options align=mac68k
00054 #endif
00055 #endif /* XP_MAC */
00056 
00057 #define BINHEX_STATE_START         0
00058 #define BINHEX_STATE_FNAME         1
00059 #define BINHEX_STATE_HEADER        2
00060 #define BINHEX_STATE_HCRC          3
00061 #define BINHEX_STATE_DFORK         4
00062 #define BINHEX_STATE_DCRC          5
00063 #define BINHEX_STATE_RFORK         6
00064 #define BINHEX_STATE_RCRC          7
00065 #define BINHEX_STATE_FINISH        8
00066 #define BINHEX_STATE_DONE          9
00067 /* #define BINHEX_STATE_ERROR             10 */
00068 
00069 /*
00070 **     The Definitions for the binhex encoder
00071 */
00072 typedef struct _binhex_header
00073 {
00074        uint32 type, creator;
00075        uint16  flags;
00076        int32  dlen, rlen ;
00077 
00078 } binhex_header;
00079 
00080 typedef       struct _binhex_encode_object
00081 {
00082        int           state;                      /*     progress state.                           */
00083        
00084        int    state86;                    /*     binhex encode state.        */
00085        unsigned long CRC;                 /*  accumulated CRC                       */
00086        int           line_length;         /*     the line length count              */
00087        char   saved_bits;
00088        
00089        int           s_inbuff;                   /*     the inbuff size                           */
00090        int           pos_inbuff;                 /*  the inbuff position                   */
00091        char*  inbuff;                            /*     the inbuff pool                           */
00092        
00093        int           s_outbuff;                  /*     the outbuff size                   */
00094        int           pos_outbuff;         /*     the outbuff position        */
00095        char*  outbuff;                    /*     the outbuf pool                           */
00096        
00097        int           s_overflow;                 /*     the real size of overflow   */
00098        char   overflow[32];        /*     a small overflow buffer            */
00099        
00100        char   c[2];
00101        char   newline[4];                 /*     the new line char seq.             */
00102 
00103        /* -- for last fix up. -- */
00104 
00105        char                 name[64];
00106        binhex_header head;
00107        
00108 } binhex_encode_object;
00109 
00110 /*
00111 **     The defination for the binhex decoder.
00112 **     NOTE:  This define is for Mac only.
00113 */
00114 
00115 typedef union 
00116 {
00117        unsigned char c[4];
00118        uint32                 val;
00119 
00120 } longbuf;
00121 
00122 #define MAX_BUFF_SIZE                     256
00123 
00124 typedef struct _binhex_decode_object
00125 {
00126        int        state;                  /* current state                                        */
00127        uint16  CRC;                /* cumulative CRC                                       */
00128        uint16  fileCRC;            /* CRC value from file                                  */
00129 
00130        longbuf octetbuf;           /* buffer for decoded 6-bit values               */
00131        int16  octetin;             /* current input position in octetbuf     */
00132        int16  donepos;             /* ending position in octetbuf                   */
00133        int16  inCRC;               /* flag set when reading a CRC                   */
00134 
00135        int32  count;               /* generic counter                                      */
00136        int16  marker;                     /* flag indicating maker                         */
00137        unsigned char rlebuf;       /* buffer for last run length encoding value */
00138 
00139        binhex_header head;         /* buffer for header                                    */
00140 
00141 #ifdef XP_MAC
00142        FSSpec*  mSpec;
00143        char   name[64];            /* fsspec for the output file             */
00144        int16  vRefNum;
00145        int32  parID ;
00146        int16  fileId;                     /* the refnum of the output file          */
00147 #else
00148        nsFileSpec      *name;                    /* file spec for the output file in non-mac OS */
00149        nsIOFileStream  *fileId;                  /* the file if for the outpur file. non-mac OS */
00150 #endif
00151        
00152        int32  s_inbuff;            /* the valid size of the inbuff                  */
00153        int32  pos_inbuff;          /* the index of the inbuff.                      */
00154        char*  inbuff;                     /* the inbuff pointer.                                  */
00155        int32  pos_outbuff;  /* the position of the out buff.          */            
00156        char   outbuff[MAX_BUFF_SIZE];
00157        
00158 } binhex_decode_object;
00159 
00160 XP_BEGIN_PROTOS
00161 
00162 /*
00163 **  The binhex file encode prototypes. 
00164 */
00165 int binhex_encode_init(binhex_encode_object *p_bh_encode_obj);
00166 
00167 int binhex_encode_next(binhex_encode_object *p_bh_encode_obj, 
00168                                    char   *in_buff,
00169                                    int32  in_size,
00170                                    char   *out_buff, 
00171                                    int32  buff_size,
00172                                    int32  *real_size);
00173                                    
00174 int binhex_encode_end (binhex_encode_object *p_bh_encode_obj, 
00175                                    XP_Bool is_aborting);
00176                                    
00177 int binhex_reencode_head(
00178                                    binhex_encode_object *p_bh_encode_obj,
00179                                    char*  outbuff,
00180                                    int32  buff_size,
00181                                    int32*  real_size);
00182 
00183 
00184 /*
00185 **     The binhex stream decode prototypes. 
00186 */
00187 
00188 int binhex_decode_init(binhex_decode_object *p_bh_decode_env);
00189                                    
00190 int binhex_decode_next(binhex_decode_object *p_bh_decode_env, 
00191                                    const char    *in_buff, 
00192                                    int32         buff_size); 
00193 int binhex_decode_end (binhex_decode_object *p_bh_decode_env, 
00194                                    XP_Bool       is_aborting);
00195 
00196 XP_END_PROTOS
00197 
00198 #ifdef XP_MAC
00199 #if PRAGMA_ALIGN_SUPPORTED
00200 #pragma options align=reset
00201 #endif
00202 #endif /* XP_MAC */
00203 
00204 #endif /* binhex_h */