More AppleDouble work - NOT PART OF THE BUILD

This commit is contained in:
rhp%netscape.com 2000-02-02 22:31:28 +00:00
Родитель befa7aa6e8
Коммит a596d8dc76
6 изменённых файлов: 106 добавлений и 763 удалений

Просмотреть файл

@ -785,19 +785,21 @@ int ap_decode_file_infor(appledouble_decode_object *p_ap_decode_obj)
{
if (p_ap_decode_obj->rksize != 0)
{
/* we need a temp file to hold all the resource data, because the */
p_ap_decode_obj->tmpfname
= WH_TempName(xpTemporary, "apmail");
p_ap_decode_obj->tmpfd
= XP_FileOpen(p_ap_decode_obj->tmpfname,
xpTemporary,
XP_FILE_TRUNCATE_BIN);
if (p_ap_decode_obj->tmpfd == NULL)
return errFileOpen;
/* we need a temp file to hold all the resource data, because the */
p_ap_decode_obj->tmpFileSpec = nsMsgCreateTempFileSpec("apmail");
if (!p_ap_decode_obj->tmpFileSpec)
return errFileOpen;
p_ap_decode_obj->tmpFileStream = new nsIOFileStream(*(p_ap_decode_obj->tmpFileSpec));
if ( (!p_ap_decode_obj->tmpFileStream) ||
(p_ap_decode_obj->tmpFileStream->is_open()) )
{
delete p_ap_decode_obj->tmpFileSpec;
return errFileOpen;
}
}
}
return NOERR;
}
@ -867,13 +869,12 @@ int ap_decode_process_header(
** Write to the temp file first, because the resource fork appears after
** the data fork in the binhex encoding.
*/
if (XP_FileWrite(wr_buff,
in_count,
p_ap_decode_obj->tmpfd) != in_count)
{
if (p_ap_decode_obj->tmpFileStream->write(wr_buff, in_count) != in_count)
{
status = errFileWrite;
break;
}
p_ap_decode_obj->data_size += in_count;
}
else
@ -881,9 +882,7 @@ int ap_decode_process_header(
#ifdef XP_MAC
long howMuch = in_count;
if (FSWrite(p_ap_decode_obj->fileId,
&howMuch,
wr_buff) != NOERR)
if (FSWrite(p_ap_decode_obj->fileId, &howMuch, wr_buff) != NOERR)
{
status = errFileWrite;
break;
@ -905,8 +904,8 @@ int ap_decode_process_header(
** with tempfile yet, just seek back to the start point,
** -- ready for a readback later
*/
if (p_ap_decode_obj->tmpfd)
XP_FileSeek(p_ap_decode_obj->tmpfd, 0L, 1);
if (p_ap_decode_obj->tmpFileStream)
p_ap_decode_obj->tmpFileStream->seek(PR_SEEK_SET, 0);
}
#ifdef XP_MAC
@ -949,20 +948,23 @@ int ap_decode_process_data(
PL_strcpy((char*)fspec.name+1, p_ap_decode_obj->fname);
filename = my_PathnameFromFSSpec(&fspec);
nsFileSpec tFileSpec(filename+7);
if (p_ap_decode_obj->is_binary)
p_ap_decode_obj->fd =
XP_FileOpen(filename+7, xpURL, XP_FILE_TRUNCATE_BIN);
p_ap_decode_obj->fileStream = new nsIOFileStream(tFileSpec, (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE));
else
p_ap_decode_obj->fd =
XP_FileOpen(filename+7, xpURL, XP_FILE_TRUNCATE);
p_ap_decode_obj->fileStream = new nsIOFileStream(tFileSpec, (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE));
// RICHIE XP_FileOpen(filename+7, xpURL, XP_FILE_TRUNCATE);
PR_FREEIF(filename);
#else
nsFileSpec tFileSpec(p_ap_decode_obj->fname);
if (p_ap_decode_obj->is_binary)
p_ap_decode_obj->fd =
XP_FileOpen(p_ap_decode_obj->fname, xpURL, XP_FILE_TRUNCATE_BIN);
p_ap_decode_obj->fileStream = new nsIOFileStream(tFileSpec, (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE));
// RICHIE XP_FileOpen(p_ap_decode_obj->fname, xpURL, XP_FILE_TRUNCATE_BIN);
else
p_ap_decode_obj->fd =
XP_FileOpen(p_ap_decode_obj->fname, xpURL, XP_FILE_TRUNCATE);
p_ap_decode_obj->fileStream = new nsIOFileStream(tFileSpec, (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE));
// RICHIE XP_FileOpen(p_ap_decode_obj->fname, xpURL, XP_FILE_TRUNCATE);
#endif
}
else
@ -994,9 +996,7 @@ int ap_decode_process_data(
wr_buff,
in_count);
else
status = XP_FileWrite(wr_buff,
in_count,
p_ap_decode_obj->fd) == in_count ? NOERR : errFileWrite;
status = p_ap_decode_obj->fileStream(wr_buff, in_count) == in_count ? NOERR : errFileWrite;
if (retval == errEOP || /* for apple double, we meet the boundary */
( p_ap_decode_obj->is_apple_single &&
@ -1019,10 +1019,10 @@ int ap_decode_process_data(
if (status != NOERR)
return status;
}
else if (p_ap_decode_obj->fd)
else if (p_ap_decode_obj->fileStream)
{
XP_FileClose(p_ap_decode_obj->fd);
p_ap_decode_obj->fd = 0;
p_ap_decode_obj->fileStream->close();
delete p_ap_decode_obj->fileStream;
}
status = errDone;

Просмотреть файл

@ -1,3 +1,11 @@
DON'T COMPILE ME!!!
RICHIE
RICHIE
RICHIE OLD FE INTERFACES TO APPLEDOUBLE ENCODE/DECODE
RICHIE
RICHIE
RICHIE
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
@ -35,7 +43,7 @@
extern int MK_MSG_SAVE_ATTACH_AS;
#ifdef XP_MAC
#ifdef RICHIE_XP_MAC
#pragma warn_unusedarg off
extern int MK_UNABLE_TO_OPEN_TMP_FILE;
@ -57,7 +65,7 @@ typedef struct _AppledoubleEncodeObject
char* buff; /* the working buff. */
PRInt32 s_buff; /* the working buff size. */
XP_File fp; /* file to hold the encoding */
RICHIE_XP_File fp; /* file to hold the encoding */
char *fname; /* and the file name. */
} AppleDoubleEncodeObject;
@ -88,7 +96,7 @@ net_AppleDouble_Encode_Write (
/*
* we get the encode data, so call the next stream to write it to the disk.
*/
if (XP_FileWrite(obj->buff, count, obj->fp) != count)
if (RICHIE_XP_FileWrite(obj->buff, count, obj->fp) != count)
return errFileWrite;
}
@ -117,7 +125,7 @@ PRIVATE void net_AppleDouble_Encode_Complete (void *stream)
if (obj->fp)
{
XP_FileClose(obj->fp); /* done with the target file */
RICHIE_XP_FileClose(obj->fp); /* done with the target file */
PR_FREEIF(obj->fname); /* and the file name too */
}
@ -134,9 +142,9 @@ PRIVATE void net_AppleDouble_Encode_Abort (void *stream, int status)
if (obj->fp)
{
XP_FileClose(obj->fp);
RICHIE_XP_FileClose(obj->fp);
XP_FileRemove (obj->fname, xpURL); /* remove the partial file. */
RICHIE_XP_FileRemove (obj->fname, xpURL); /* remove the partial file. */
PR_FREEIF(obj->fname);
}
@ -202,7 +210,7 @@ fe_MakeAppleDoubleEncodeStream (int format_out,
stream->data_object = obj;
stream->window_id = window_id;
obj->fp = XP_FileOpen(dst_filename, xpFileToPost, XP_FILE_WRITE_BIN);
obj->fp = RICHIE_XP_FileOpen(dst_filename, xpFileToPost, RICHIE_XP_FILE_WRITE_BIN);
if (obj->fp == NULL)
{
PR_FREEIF (working_buff);
@ -356,7 +364,7 @@ net_AppleDouble_Decode_Abort (
** In other OS, the stream will decode apple double object,
** then encode it in binhex format, and save to the file.
*/
#ifndef XP_MAC
#ifndef RICHIE_XP_MAC
static void
simple_copy(MWContext* context, char* saveName, void* closure)
{
@ -371,7 +379,7 @@ fe_MakeAppleDoubleDecodeStream_1 (int format_out,
URL_Struct *URL_s,
MWContext *window_id)
{
#ifdef XP_MAC
#ifdef RICHIE_XP_MAC
return fe_MakeAppleDoubleDecodeStream(format_out,
data_obj,
URL_s,
@ -412,7 +420,7 @@ fe_MakeAppleDoubleDecodeStream_1 (int format_out,
/***** RICHIE - CONVERT THIS
if (FE_PromptForFileName(window_id,
XP_GetString(MK_MSG_SAVE_ATTACH_AS),
RICHIE_XP_GetString(MK_MSG_SAVE_ATTACH_AS),
0,
FALSE,
FALSE,
@ -521,10 +529,10 @@ fe_MakeAppleDoubleDecodeStream (int format_out,
if (dst_filename)
{
XP_STRNCPY_SAFE(obj->ap_decode_obj.fname, dst_filename,
RICHIE_XP_STRNCPY_SAFE(obj->ap_decode_obj.fname, dst_filename,
sizeof(obj->ap_decode_obj.fname));
}
#ifdef XP_MAC
#ifdef RICHIE_XP_MAC
obj->ap_decode_obj.mSpec = (FSSpec*)( URL_s->fe_data );
#endif
TRACEMSG(("Returning stream from NET_AppleDoubleDecode\n"));
@ -550,7 +558,7 @@ fe_MakeAppleSingleDecodeStream_1 (int format_out,
URL_Struct *URL_s,
MWContext *window_id)
{
#ifdef XP_MAC
#ifdef RICHIE_XP_MAC
return fe_MakeAppleSingleDecodeStream(format_out,
data_obj,
URL_s,
@ -588,8 +596,8 @@ fe_MakeAppleSingleDecodeStream_1 (int format_out,
defaultPath = URL_s->content_name;
#ifdef XP_WIN16
if (XP_FileNameContainsBadChars(defaultPath))
#ifdef RICHIE_XP_WIN16
if (RICHIE_XP_FileNameContainsBadChars(defaultPath))
defaultPath = 0;
#endif
@ -599,7 +607,7 @@ fe_MakeAppleSingleDecodeStream_1 (int format_out,
/***** RICHIE - CONVERT THIS
if (FE_PromptForFileName(window_id,
XP_GetString(MK_MSG_SAVE_ATTACH_AS),
RICHIE_XP_GetString(MK_MSG_SAVE_ATTACH_AS),
defaultPath,
FALSE,
FALSE,
@ -642,11 +650,11 @@ fe_MakeAppleSingleDecodeStream (int format_out,
TRACEMSG(("Setting up apple single decode stream. Have URL: %s\n", URL_s->address));
stream = XP_NEW(NET_StreamClass);
stream = RICHIE_XP_NEW(NET_StreamClass);
if(stream == NULL)
return(NULL);
obj = XP_NEW(AppleDoubleDecodeObject);
obj = RICHIE_XP_NEW(AppleDoubleDecodeObject);
if (obj == NULL)
{
PR_FREEIF(stream);
@ -702,19 +710,19 @@ fe_MakeAppleSingleDecodeStream (int format_out,
TRUE,
FALSE,
window_id);
#ifndef XP_MAC
#ifndef RICHIE_XP_MAC
obj->ap_decode_obj.is_binary = TRUE;
#endif
}
if (dst_filename)
{
XP_STRNCPY_SAFE(obj->ap_decode_obj.fname, dst_filename,
RICHIE_XP_STRNCPY_SAFE(obj->ap_decode_obj.fname, dst_filename,
sizeof(obj->ap_decode_obj.fname));
}
/* If we are of a broken content-type, impose its encoding. */
if (URL_s->content_type
&& !XP_STRNCASECMP(URL_s->content_type, "x-uuencode-apple-single", 23))
&& !RICHIE_XP_STRNCASECMP(URL_s->content_type, "x-uuencode-apple-single", 23))
obj->ap_decode_obj.encoding = kEncodeUU;
else
obj->ap_decode_obj.encoding = kEncodeNone;

Просмотреть файл

@ -1,673 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
*
* apple-double.c
* --------------
*
* The codes to do apple double encoding/decoding.
*
* 02aug95 mym created.
* 27sep95 mym Add the XP_Mac to ensure the cross-platform.
*
*/
#include "nsID.h"
#include "nsCRT.h"
#include "nscore.h"
#include "msgCore.h"
#include "nsMsgAppleDouble.h"
#include "nsMsgAppleCodes.h"
#include "nsFileSpec.h"
#include "nsMsgCompUtils.h"
#ifdef XP_MAC
#pragma warn_unusedarg off
#include "m_cvstrm.h"
#pragma cplusplus on
//RICHIEDELETE #include "InternetConfig.h"
//RICHIEDELETE #include "ufilemgr.h"
//RICHIEDELETE #include "BufferStream.h"
//RICHIEDELETE #include "Umimemap.h"
//RICHIEDELETE #include "uprefd.h"
//RICHIEDELETE #include "ulaunch.h"
void DecodingDone( appledouble_decode_object* p_ap_decode_obj );
OSErr my_FSSpecFromPathname(char* src_filename, FSSpec* fspec)
{
/* don't resolve aliases... */
return CFileMgr::FSSpecFromLocalUnixPath(src_filename, fspec, false);
}
char* my_PathnameFromFSSpec(FSSpec* fspec)
{
return CFileMgr::GetURLFromFileSpec(*fspec);
}
//
// Returns true if the resource fork should be sent!
//
// RICHIEHACK: for now, this is a temporary solution that should be
// replaced by calls to the MIME service! We look for files that typically
// don't have resource forks and if it is one of these types, we go with
// it, but otherwise, we are going to do the fancy encoding!
//
PRBool
nsMsgIsMacFile(char *aUrlString)
{
Boolean returnValue = PR_FALSE;
char *ext = nsMsgGetExtensionFromFileURL(nsString(aUrlString));
if ( (!ext) || (!*ext) )
return PR_TRUE;
if (
(!PL_strcasecmp(ext, "JPG")) ||
(!PL_strcasecmp(ext, "GIF")) ||
(!PL_strcasecmp(ext, "TIF")) ||
(!PL_strcasecmp(ext, "HTM")) ||
(!PL_strcasecmp(ext, "HTML")) ||
(!PL_strcasecmp(ext, "ART")) ||
(!PL_strcasecmp(ext, "XUL")) ||
(!PL_strcasecmp(ext, "XML")) ||
(!PL_strcasecmp(ext, "XUL"))
)
return PR_FALSE;
else
return PR_TRUE;
}
/* Netlib utility routine, should be ripped out */
void MacGetFileType(nsFileSpec *path,
PRBool *useDefault,
char **fileType,
char **encoding)
{
if ((path == NULL) || (fileType == NULL) || (encoding == NULL))
return;
*useDefault = TRUE;
*fileType = NULL;
*encoding = NULL;
char *pathPart = NET_ParseURL( path, GET_PATH_PART);
if (pathPart == NULL)
return;
nsFilePath thePath(pathPart);
nsNativeFileSpec spec(thePath);
XP_FREE(pathPart);
CMimeMapper * mapper = CPrefs::sMimeTypes.FindMimeType(spec);
if (mapper != NULL)
{
*useDefault = FALSE;
*fileType = nsCRT::strdup(mapper->GetMimeName());
}
else
{
FInfo fndrInfo;
OSErr err = FSpGetFInfo( &spec, &fndrInfo );
if ( (err != noErr) || (fndrInfo.fdType == 'TEXT') )
*fileType = nsCRT::strdup(APPLICATION_OCTET_STREAM);
else
{
// Time to call IC to see if it knows anything
ICMapEntry ICMapper;
ICError error = 0;
CStr255 fileName( spec.name );
error = CInternetConfigInterface::GetInternetConfigFileMapping(
fndrInfo.fdType, fndrInfo.fdCreator, fileName , &ICMapper );
if( error != icPrefNotFoundErr && StrLength(ICMapper.MIME_type) )
{
*useDefault = FALSE;
CStr255 mimeName( ICMapper.MIME_type );
*fileType = nsCRT::strdup( mimeName );
}
else
{
// That failed try using the creator type
mapper = CPrefs::sMimeTypes.FindCreator(fndrInfo.fdCreator);
if( mapper)
{
*useDefault = FALSE;
*fileType = nsCRT::strdup(mapper->GetMimeName());
}
else
{
// don't have a mime mapper
*fileType = nsCRT::strdup(APPLICATION_OCTET_STREAM);
}
}
}
}
}
void DecodingDone( appledouble_decode_object* p_ap_decode_obj )
{
FSSpec fspec;
fspec.vRefNum = p_ap_decode_obj->vRefNum;
fspec.parID = p_ap_decode_obj->dirId;
fspec.name[0] = nsCRT::strlen(p_ap_decode_obj->fname);
XP_STRCPY((char*)fspec.name+1, p_ap_decode_obj->fname);
CMimeMapper * mapper = CPrefs::sMimeTypes.FindMimeType(fspec);
if( mapper && (mapper->GetLoadAction() == CMimeMapper::Launch ) )
{
LFileBufferStream file( fspec );
LaunchFile( &file );
}
}
#pragma cplusplus reset
/*
* ap_encode_init
* --------------
*
* Setup the encode envirment
*/
int ap_encode_init( appledouble_encode_object *p_ap_encode_obj,
char *fname,
char *separator)
{
FSSpec fspec;
if (my_FSSpecFromPathname(fname, &fspec) != noErr )
return -1;
nsCRT::memset(p_ap_encode_obj, 0, sizeof(appledouble_encode_object));
/*
** Fill out the source file inforamtion.
*/
nsCRT::memcpy(p_ap_encode_obj->fname, fspec.name+1, *fspec.name);
p_ap_encode_obj->fname[*fspec.name] = '\0';
p_ap_encode_obj->vRefNum = fspec.vRefNum;
p_ap_encode_obj->dirId = fspec.parID;
p_ap_encode_obj->boundary = nsCRT::strdup(separator);
return noErr;
}
/*
** ap_encode_next
** --------------
**
** return :
** noErr : everything is ok
** errDone : when encoding is done.
** errors : otherwise.
*/
int ap_encode_next(
appledouble_encode_object* p_ap_encode_obj,
char *to_buff,
PRInt32 buff_size,
PRInt32* real_size)
{
int status;
/*
** install the out buff now.
*/
p_ap_encode_obj->outbuff = to_buff;
p_ap_encode_obj->s_outbuff = buff_size;
p_ap_encode_obj->pos_outbuff = 0;
/*
** first copy the outstandind data in the overflow buff to the out buffer.
*/
if (p_ap_encode_obj->s_overflow)
{
status = write_stream(p_ap_encode_obj,
p_ap_encode_obj->b_overflow,
p_ap_encode_obj->s_overflow);
if (status != noErr)
return status;
p_ap_encode_obj->s_overflow = 0;
}
/*
** go the next processing stage based on the current state.
*/
switch (p_ap_encode_obj->state)
{
case kInit:
/*
** We are in the starting position, fill out the header.
*/
status = fill_apple_mime_header(p_ap_encode_obj);
if (status != noErr)
break; /* some error happens */
p_ap_encode_obj->state = kDoingHeaderPortion;
status = ap_encode_header(p_ap_encode_obj, true);
/* it is the first time to calling */
if (status == errDone)
{
p_ap_encode_obj->state = kDoneHeaderPortion;
}
else
{
break; /* we need more work on header portion. */
}
/*
** we are done with the header, so let's go to the data port.
*/
p_ap_encode_obj->state = kDoingDataPortion;
status = ap_encode_data(p_ap_encode_obj, true);
/* it is first time call do data portion */
if (status == errDone)
{
p_ap_encode_obj->state = kDoneDataPortion;
status = noErr;
}
break;
case kDoingHeaderPortion:
status = ap_encode_header(p_ap_encode_obj, false);
/* continue with the header portion. */
if (status == errDone)
{
p_ap_encode_obj->state = kDoneHeaderPortion;
}
else
{
break; /* we need more work on header portion. */
}
/*
** start the data portion.
*/
p_ap_encode_obj->state = kDoingDataPortion;
status = ap_encode_data(p_ap_encode_obj, true);
/* it is the first time calling */
if (status == errDone)
{
p_ap_encode_obj->state = kDoneDataPortion;
status = noErr;
}
break;
case kDoingDataPortion:
status = ap_encode_data(p_ap_encode_obj, false);
/* it is not the first time */
if (status == errDone)
{
p_ap_encode_obj->state = kDoneDataPortion;
status = noErr;
}
break;
case kDoneDataPortion:
#if 0
status = write_stream(p_ap_encode_obj,
"\n-----\n\n",
8);
if (status == noErr)
#endif
status = errDone; /* we are really done. */
break;
}
*real_size = p_ap_encode_obj->pos_outbuff;
return status;
}
/*
** ap_encode_end
** -------------
**
** clear the apple encoding.
*/
int ap_encode_end(
appledouble_encode_object *p_ap_encode_obj,
PRBool is_aborting)
{
/*
** clear up the apple doubler.
*/
if (p_ap_encode_obj == NULL)
return noErr;
if (p_ap_encode_obj->fileId) /* close the file if it is open. */
FSClose(p_ap_encode_obj->fileId);
PR_FREEIF(p_ap_encode_obj->boundary); /* the boundary string. */
return noErr;
}
#endif /* the ifdef of XP_MAC */
/*
** The initial of the apple double decoder.
**
** Set up the next output stream based on the input.
*/
int ap_decode_init(
appledouble_decode_object* p_ap_decode_obj,
PRBool is_apple_single,
PRBool write_as_binhex,
void *closure)
{
nsCRT::memset(p_ap_decode_obj, 0, sizeof(appledouble_decode_object));
/* presume first buff starts a line */
p_ap_decode_obj->uu_starts_line = TRUE;
if (write_as_binhex)
{
p_ap_decode_obj->write_as_binhex = TRUE;
p_ap_decode_obj->binhex_stream = (NET_StreamClass*)closure;
p_ap_decode_obj->data_size = 0;
}
else
{
p_ap_decode_obj->write_as_binhex = FALSE;
p_ap_decode_obj->binhex_stream = NULL;
p_ap_decode_obj->context = (MWContext*)closure;
}
p_ap_decode_obj->is_apple_single = is_apple_single;
if (is_apple_single)
{
p_ap_decode_obj->encoding = kEncodeNone;
}
return NOERR;
}
static int ap_decode_state_machine(appledouble_decode_object* p_ap_decode_obj);
/*
* process the buffer
*/
int ap_decode_next(
appledouble_decode_object* p_ap_decode_obj,
char *in_buff,
PRInt32 buff_size)
{
/*
** install the buff to the decoder.
*/
p_ap_decode_obj->inbuff = in_buff;
p_ap_decode_obj->s_inbuff = buff_size;
p_ap_decode_obj->pos_inbuff = 0;
/*
** run off the decode state machine
*/
return ap_decode_state_machine(p_ap_decode_obj);
}
PRIVATE int ap_decode_state_machine(
appledouble_decode_object* p_ap_decode_obj)
{
int status = NOERR;
PRInt32 size;
switch (p_ap_decode_obj->state)
{
case kInit:
/*
** Make sure that there are stuff in the buff
** before we can parse the file head .
*/
if (p_ap_decode_obj->s_inbuff <=1 )
return NOERR;
if (p_ap_decode_obj->is_apple_single)
{
p_ap_decode_obj->state = kBeginHeaderPortion;
}
else
{
status = ap_seek_part_start(p_ap_decode_obj);
if (status != errDone)
return status;
p_ap_decode_obj->state = kBeginParseHeader;
}
status = ap_decode_state_machine(p_ap_decode_obj);
break;
case kBeginSeekBoundary:
p_ap_decode_obj->state = kSeekingBoundary;
status = ap_seek_to_boundary(p_ap_decode_obj, TRUE);
if (status == errDone)
{
p_ap_decode_obj->state = kBeginParseHeader;
status = ap_decode_state_machine(p_ap_decode_obj);
}
break;
case kSeekingBoundary:
status = ap_seek_to_boundary(p_ap_decode_obj, FALSE);
if (status == errDone)
{
p_ap_decode_obj->state = kBeginParseHeader;
status = ap_decode_state_machine(p_ap_decode_obj);
}
break;
case kBeginParseHeader:
p_ap_decode_obj->state = kParsingHeader;
status = ap_parse_header(p_ap_decode_obj, TRUE);
if (status == errDone)
{
if (p_ap_decode_obj->which_part == kDataPortion)
p_ap_decode_obj->state = kBeginDataPortion;
else if (p_ap_decode_obj->which_part == kHeaderPortion)
p_ap_decode_obj->state = kBeginHeaderPortion;
else
p_ap_decode_obj->state = kFinishing;
status = ap_decode_state_machine(p_ap_decode_obj);
}
break;
case kParsingHeader:
status = ap_parse_header(p_ap_decode_obj, FALSE);
if (status == errDone)
{
if (p_ap_decode_obj->which_part == kDataPortion)
p_ap_decode_obj->state = kBeginDataPortion;
else if (p_ap_decode_obj->which_part == kHeaderPortion)
p_ap_decode_obj->state = kBeginHeaderPortion;
else
p_ap_decode_obj->state = kFinishing;
status = ap_decode_state_machine(p_ap_decode_obj);
}
break;
case kBeginHeaderPortion:
p_ap_decode_obj->state = kProcessingHeaderPortion;
status = ap_decode_process_header(p_ap_decode_obj, TRUE);
if (status == errDone)
{
if (p_ap_decode_obj->is_apple_single)
p_ap_decode_obj->state = kBeginDataPortion;
else
p_ap_decode_obj->state = kBeginSeekBoundary;
status = ap_decode_state_machine(p_ap_decode_obj);
}
break;
case kProcessingHeaderPortion:
status = ap_decode_process_header(p_ap_decode_obj, FALSE);
if (status == errDone)
{
if (p_ap_decode_obj->is_apple_single)
p_ap_decode_obj->state = kBeginDataPortion;
else
p_ap_decode_obj->state = kBeginSeekBoundary;
status = ap_decode_state_machine(p_ap_decode_obj);
}
break;
case kBeginDataPortion:
p_ap_decode_obj->state = kProcessingDataPortion;
status = ap_decode_process_data(p_ap_decode_obj, TRUE);
if (status == errDone)
{
if (p_ap_decode_obj->is_apple_single)
p_ap_decode_obj->state = kFinishing;
else
p_ap_decode_obj->state = kBeginSeekBoundary;
status = ap_decode_state_machine(p_ap_decode_obj);
}
break;
case kProcessingDataPortion:
status = ap_decode_process_data(p_ap_decode_obj, FALSE);
if (status == errDone)
{
if (p_ap_decode_obj->is_apple_single)
p_ap_decode_obj->state = kFinishing;
else
p_ap_decode_obj->state = kBeginSeekBoundary;
status = ap_decode_state_machine(p_ap_decode_obj);
}
break;
case kFinishing:
if (p_ap_decode_obj->write_as_binhex)
{
if (p_ap_decode_obj->tmpfd)
{
/*
** It is time to append the data fork to bin hex encoder.
**
** The reason behind this dirt work is resource fork is the last
** piece in the binhex, while it is the first piece in apple double.
*/
XP_FileSeek(p_ap_decode_obj->tmpfd, 0L, SEEK_SET);
while (p_ap_decode_obj->data_size > 0)
{
char buff[1024];
size = PR_MIN(1024, p_ap_decode_obj->data_size);
XP_FileRead(buff, size, p_ap_decode_obj->tmpfd);
status = (*p_ap_decode_obj->binhex_stream->put_block)
(p_ap_decode_obj->binhex_stream->data_object,
buff,
size);
p_ap_decode_obj->data_size -= size;
}
}
if (p_ap_decode_obj->data_size <= 0)
{
/* CALL put_block with size == 0 to close a part. */
status = (*p_ap_decode_obj->binhex_stream->put_block)
(p_ap_decode_obj->binhex_stream->data_object,
NULL,
0);
if (status != NOERR)
break;
/* and now we are really done. */
status = errDone;
}
else
status = NOERR;
}
break;
}
return (status == errEOB) ? NOERR : status;
}
int ap_decode_end(
appledouble_decode_object* p_ap_decode_obj,
PRBool is_aborting)
{
/*
** clear up the apple doubler object.
*/
if (p_ap_decode_obj == NULL)
return NOERR;
PR_FREEIF(p_ap_decode_obj->boundary0);
#ifdef XP_MAC
if (p_ap_decode_obj->fileId)
FSClose(p_ap_decode_obj->fileId);
if( p_ap_decode_obj->vRefNum )
FlushVol(nil, p_ap_decode_obj->vRefNum );
#endif
if (p_ap_decode_obj->write_as_binhex)
{
/*
** make sure close the binhex stream too.
*/
if (is_aborting)
{
(*p_ap_decode_obj->binhex_stream->abort)
(p_ap_decode_obj->binhex_stream->data_object, 0);
}
else
{
(*p_ap_decode_obj->binhex_stream->complete)
(p_ap_decode_obj->binhex_stream->data_object);
}
if (p_ap_decode_obj->tmpfd)
XP_FileClose(p_ap_decode_obj->tmpfd);
if (p_ap_decode_obj->tmpfname)
{
XP_FileRemove(p_ap_decode_obj->tmpfname, xpTemporary);
/* remove tmp file if we used it */
PR_FREEIF(p_ap_decode_obj->tmpfname); /* and release the file name too. */
}
}
else if (p_ap_decode_obj->fd)
{
XP_FileClose(p_ap_decode_obj->fd);
}
#ifdef XP_MAC
if( !is_aborting )
DecodingDone( p_ap_decode_obj);
#endif
return NOERR;
}

Просмотреть файл

@ -31,8 +31,10 @@
#define AppleDouble_h
#include "xp.h"
#include "xp_file.h"
#include "msgCore.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"
#define NOERR 0
#define errDone 1
@ -161,10 +163,12 @@ typedef struct _appledouble_decode_object
PRInt32 dirId;
PRInt16 fileId; /* the id for the open file (data/resource fork) */
#endif
XP_File fd; /* the fd for data fork work. */
nsIOFileStream *fileSpec; /* the stream for data fork work. */
// RICHIE - REMOVE THIS OLD STUFF!!!
MWContext *context;
NET_StreamClass* binhex_stream; /* the stream to output as binhex output.*/
NET_StreamClass* binhex_stream; /* the stream to output as binhex output.*/
// RICHIE - REMOVE THIS OLD STUFF!!!
int state;
@ -189,10 +193,10 @@ typedef struct _appledouble_decode_object
int pos_inbuff; /* the offset in the current buffer. */
char* tmpfname; /* the temp file to hold the decode data fork */
/* when doing the binhex exporting. */
XP_File tmpfd;
PRInt32 data_size; /* the size of the data in the tmp file. */
nsFileSpec *tmpFileSpec; /* the temp file to hold the decode data fork */
/* when doing the binhex exporting. */
nsIOFileStream *tmpFileStream; /* The output File Stream */
PRInt32 data_size; /* the size of the data in the tmp file. */
} appledouble_decode_object;

Просмотреть файл

@ -613,12 +613,11 @@ PRIVATE void binhex_process(
/* only output data fork in the non-mac system. */
if (p_bh_decode_obj->state == BINHEX_STATE_DFORK)
{
status = XP_FileWrite(p_bh_decode_obj->outbuff,
p_bh_decode_obj->pos_outbuff,
p_bh_decode_obj->fileId)
== p_bh_decode_obj->pos_outbuff ? NOERR : errFileWrite;
status = p_bh_decode_obj->fileId->write(p_bh_decode_obj->outbuff,
p_bh_decode_obj->pos_outbuff)
== p_bh_decode_obj->pos_outbuff ? NOERR : errFileWrite;
XP_FileClose(p_bh_decode_obj->fileId);
p_bh_decode_obj->fileId->close();
}
else
{
@ -646,10 +645,9 @@ PRIVATE void binhex_process(
#else
if (p_bh_decode_obj->state == BINHEX_STATE_DFORK)
{
status = XP_FileWrite(p_bh_decode_obj->outbuff,
p_bh_decode_obj->pos_outbuff,
p_bh_decode_obj->fileId)
== p_bh_decode_obj->pos_outbuff ? NOERR : errFileWrite;
status = p_bh_decode_obj->fileId->write(p_bh_decode_obj->outbuff,
p_bh_decode_obj->pos_outbuff)
== p_bh_decode_obj->pos_outbuff ? NOERR : errFileWrite;
}
else
{
@ -681,7 +679,7 @@ PRIVATE void binhex_process(
p_bh_decode_obj->parID,
(unsigned char*)p_bh_decode_obj->name);
#else
XP_FileRemove(p_bh_decode_obj->name, xpURL);
p_bh_decode_obj->name->Delete(PR_FALSE);
#endif
}
p_bh_decode_obj->state = errDecoding;
@ -769,16 +767,20 @@ PRIVATE void binhex_process(
break;
}
FREEIF(p_bh_decode_obj->name);
p_bh_decode_obj->name = XP_STRDUP(filename);
p_bh_decode_obj->fileId
= XP_FileOpen(filename,
xpURL,
XP_FILE_TRUNCATE_BIN);
if (p_bh_decode_obj->fileId == NULL)
status = errFileOpen;
else
status = NOERR;
if (p_bh_decode_obj->name)
delete p_bh_decode_obj->fileId;
p_bh_decode_obj->name = new nsFileSpec(filename);
if (!p_bh_decode_obj->name)
status = errFileOpen;
else
{
p_bh_decode_obj->fileId = new nsIOFileStream(*(p_bh_decode_obj->name), (PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE));
if (p_bh_decode_obj->fileId == NULL)
status = errFileOpen;
else
status = NOERR;
}
XP_FREE(filename);
@ -997,9 +999,9 @@ int binhex_decode_next (
p_bh_decode_obj->parID,
(unsigned char*)p_bh_decode_obj->name);
#else
XP_FileClose(p_bh_decode_obj->fileId);
p_bh_decode_obj->fileId = 0;
XP_FileRemove(p_bh_decode_obj->name, xpURL);
p_bh_decode_obj->fileId->close();
delete p_bh_decode_obj->fileId;
p_bh_decode_obj->name->delete(PR_FALSE);
#endif
}
@ -1030,11 +1032,10 @@ int binhex_decode_end (
if (p_bh_decode_obj->fileId)
{
XP_FileClose(p_bh_decode_obj->fileId);
p_bh_decode_obj->fileId = NULL;
p_bh_decode_obj->fileId->close();
if (is_aborting)
XP_FileRemove(p_bh_decode_obj->name, xpURL);
p_bh_decode_obj->name->Delete(PR_FALSE);
}
FREEIF(p_bh_decode_obj->name);
#endif

Просмотреть файл

@ -25,6 +25,9 @@
#ifndef binhex_h
#define binhex_h
#include "nsFileSpec.h"
#include "nsFileStream.h"
#ifdef XP_MAC
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=mac68k
@ -122,8 +125,8 @@ typedef struct _binhex_decode_object
int32 parID ;
int16 fileId; /* the refnum of the output file */
#else
char *name; /* file name for the output file in non-mac OS */
XP_File fileId; /* the file if for the outpur file. non-mac OS */
nsFileSpec *name; /* file spec for the output file in non-mac OS */
nsIOFileStream *fileId; /* the file if for the outpur file. non-mac OS */
#endif
MWContext* context; /* context for call back function. */