Back to index

lightning-sunbird  0.9+nobinonly
nsMsgAppleDouble.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 /* 
00040 *   AppleDouble.h
00041 *      -------------
00042 *
00043 *        The header file for a stream based apple single/double encodor/decodor.
00044 *             
00045 *             2aug95 mym           
00046 *             
00047 */
00048 
00049 
00050 #ifndef AppleDouble_h
00051 #define AppleDouble_h
00052 
00053 #include "msgCore.h"
00054 #include "nsFileSpec.h"
00055 #include "nsFileStream.h"
00056 #include "nsMsgComposeStringBundle.h"
00057 
00058 
00059 #define NOERR               0
00060 #define errDone                    1
00061                                                         /* Done with current operation.    */
00062 #define errEOB                     2
00063                                                         /*     End of a buffer.                   */
00064 #define errEOP                     3      
00065                                                         /*     End of a Part.                            */
00066 
00067                                    
00068 #define errFileOpen         NS_MSG_UNABLE_TO_OPEN_TMP_FILE
00069 #define errFileWrite -202 /*Error writing temporary file.*/
00070 #define errUsrCancel -2  /*MK_INTERRUPTED */
00071 #define errDecoding         -1
00072 
00073 /*
00074 ** The envirment block data type. 
00075 */
00076 enum 
00077 { 
00078        kInit, 
00079        kDoingHeaderPortion, 
00080        kDoneHeaderPortion, 
00081        kDoingDataPortion, 
00082        kDoneDataPortion 
00083 };
00084 
00085 typedef struct _appledouble_encode_object 
00086 {
00087        char   fname[64];
00088        PRInt32       dirId; 
00089        PRInt16       vRefNum;
00090        PRInt16       fileId;                            /* the id for the open file (data/resource fork) */
00091 
00092        int    state;
00093        int           text_file_type;             /* if the file has a text file type with it.     */
00094        char   *boundary;                  /* the boundary string.                                               */
00095 
00096        int           status;                            /* the error code if anyerror happens.                  */
00097        char   b_overflow[200];
00098        int           s_overflow;
00099        
00100        int           state64;                    /* the left over state of base64 enocding               */
00101        int           ct;                                /* the character count of base64 encoding        */
00102        int    c1, c2;                            /* the left of the last base64 encoding          */            
00103 
00104        char   *outbuff;                   /* the outbuff by the caller.                    */
00105        int           s_outbuff;                  /* the size of the buffer.                                     */
00106        int           pos_outbuff;         /* the offset in the current buffer.                    */ 
00107 
00108 } appledouble_encode_object;
00109 
00110 /* The possible content transfer encodings */
00111 
00112 enum 
00113 { 
00114        kEncodeNone,
00115        kEncodeQP,
00116        kEncodeBase64,
00117        kEncodeUU
00118 };
00119 
00120 enum 
00121 { 
00122        kGeneralMine,
00123        kAppleDouble,
00124        kAppleSingle
00125 };
00126 
00127 enum 
00128 { 
00129        kInline,
00130        kDontCare
00131 };
00132 
00133 enum 
00134 { 
00135        kHeaderPortion,
00136        kDataPortion
00137 };
00138 
00139 /* the decode states.       */
00140 enum 
00141 { 
00142        kBeginParseHeader = 3,
00143        kParsingHeader,
00144        kBeginSeekBoundary,
00145        kSeekingBoundary,
00146        kBeginHeaderPortion, 
00147        kProcessingHeaderPortion, 
00148        kBeginDataPortion, 
00149        kProcessingDataPortion, 
00150        kFinishing
00151 };
00152 
00153 /* uuencode states */
00154 enum
00155 {
00156        kWaitingForBegin = (int) 0,
00157        kBegin,
00158        kMainBody,
00159        kEnd
00160 };
00161 
00162 typedef struct _appledouble_decode_object 
00163 {
00164        int           is_binary;
00165        int           is_apple_single;     /* if the object encoded is in apple single             */
00166        int           write_as_binhex;
00167        
00168        int           messagetype;
00169        char*  boundary0;                  /* the boundary for the enclosure.                      */
00170        int           deposition;                 /* the deposition.                                                    */
00171        int           encoding;                   /* the encoding method.                                               */
00172        int           which_part;
00173        
00174        char   fname[256];
00175 #ifdef XP_MAC
00176        FSSpec* mSpec;                     /* the filespec to save the file to*/
00177        PRInt16       vRefNum;
00178        PRInt32       dirId; 
00179        PRInt16       fileId;                            /* the id for the open file (data/resource fork) */
00180 #endif
00181        nsIOFileStream *fileSpec;                               /* the stream for data fork work.                               */
00182 
00183        int    state;
00184        
00185        int           rksize;                            /* the resource fork size count.                        */
00186        int           dksize;                            /* the data fork size count.                                   */
00187         
00188        int           status;                            /* the error code if anyerror happens.                  */
00189        char   b_leftover[256];
00190        int           s_leftover;
00191        
00192        int           encode;                            /* the encode type of the message.                      */
00193        int           state64;                    /* the left over state of base64 enocding               */
00194        int           left;                       /* the character count of base64 encoding        */
00195        int    c[4];                       /* the left of the last base64 encoding          */            
00196        int           uu_starts_line;             /* is decoder at the start of a line? (uuencode) */
00197        int           uu_state;                   /* state w/r/t the uuencode body */
00198        int           uu_bytes_written;    /* bytes written from the current tuple (uuencode) */
00199        int           uu_line_bytes;              /* encoded bytes remaining in the current line (uuencode) */
00200 
00201        char   *inbuff;                    /* the outbuff by the caller.                    */
00202        int           s_inbuff;                   /* the size of the buffer.                                     */
00203        int           pos_inbuff;                 /* the offset in the current buffer.                    */ 
00204 
00205 
00206        nsFileSpec          *tmpFileSpec;         /* the temp file to hold the decode data fork    */
00207                                                                               /* when doing the binhex exporting.                           */
00208   nsIOFileStream      *tmpFileStream; /* The output File Stream */
00209        PRInt32                   data_size;                    /* the size of the data in the tmp file.         */
00210 
00211 } appledouble_decode_object;
00212 
00213 
00214 /*
00215 **     The protypes.
00216 */
00217 
00218 PR_BEGIN_EXTERN_C
00219 
00220 int ap_encode_init(appledouble_encode_object *p_ap_encode_obj, 
00221                                    const char* fname,
00222                                    char* separator);
00223 
00224 int ap_encode_next(appledouble_encode_object* p_ap_encode_obj, 
00225                                    char   *to_buff,
00226                                    PRInt32       buff_size,
00227                                    PRInt32*      real_size);
00228 
00229 int ap_encode_end(appledouble_encode_object* p_ap_encode_obj,
00230                                    PRBool is_aborting);
00231 
00232 int ap_decode_init(appledouble_decode_object* p_ap_decode_obj,
00233                                    PRBool is_apple_single,
00234                                    PRBool write_as_bin_hex,
00235                                    void   *closure);
00236 
00237 int ap_decode_next(appledouble_decode_object* p_ap_decode_obj, 
00238                                    char   *in_buff, 
00239                                    PRInt32       buff_size);
00240 
00241 int ap_decode_end(appledouble_decode_object* p_ap_decode_obj, 
00242                                    PRBool is_aborting);
00243 
00244 PR_END_EXTERN_C
00245 
00246 #endif