eudora-mac/downloadurl.c

1 line
19 KiB
C
Raw Permalink Normal View History

2018-05-23 09:59:15 +00:00
/* Copyright (c) 2017, Computer History Museum All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Computer History Museum nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /************************************************************************ * * Download a URL. Downloads only HTTP files at the moment. * ************************************************************************/ #include "downloadurl.h" #include "buildversion.h" #define FILE_NUM 117 /* Copyright (c) 1998 by QUALCOMM Incorporated */ #pragma segment DownURL /* * constants */ enum { kNotHTTPURLErr = -666, kWhatImplementationErr = -667, kTransferBufferSize = 4096 }; // Thread parameter struct typedef struct { char hostName[256]; char httpMethodCommand[512]; DownloadInfo info; short destFileRefNum; OSErr err; Ptr transferBuffer; long refCon; void (*FinishFunc)(long,OSErr,DownloadInfo*); ThreadID threadID; HTTPinfo HTTPstuff; Boolean aborted; Boolean completedDownload; } URLParms, *URLParmsPtr, **URLParmsHandle; // prototypes static pascal void *DownloadURLThread (void *threadParameter); static pascal void MyThreadTermination (ThreadID threadTerminated, void *terminationProcParam); static pascal void YieldingNotifier(void* contextPtr, OTEventCode code, OTResult result, void* cookie); static OSErr DownloadHTTPSimple(URLParmsHandle threadData,char *hostName,char *httpCommand, Boolean *redirect,HTTPinfo *pHTTPstuff); static OSErr ProcessHeader(Ptr *transferBuffer,long *bytesReceived,ResType *type,ResType *creator, URLParmsHandle threadData); static OSErr GetURLHost(const char *urlString, char *hostName,char *httpMethodCommand,Boolean doPOST); static short ParseHTTPHeader(StringPtr sHeader,char *sResult,Ptr p,long bufLen); /************************************************************************ * DownloadURL - download file specified by URL, supports HTTP only * * To use POST: Pass HTTPinfo. The handles for will be * disposed of automatically. Do not dispose from caller! ************************************************************************/ OSErr DownloadURL(const char *urlString, FSSpecPtr destSpec,long refCon,void (*FinishFunc)(long,OSErr,DownloadInfo*),long *pReference,HTTPinfo *pHTTPstuff) { URLParmsHandle threadData = nil; OSErr err = noErr; ThreadID threadID; short destFileRefNum = 0; DECLARE_UPP(DownloadURLThread,ThreadEntry); DECLARE_UPP(MyThreadTermination,ThreadTermination); if (TCPWillDial(true)) return -1; // Don't dial to download #ifdef DEBUG if (pHTTPstuff && pHTTPstuff->post) ComposeLogS(LOG_PLIST,nil,"\pDownloadURL: %s",urlSt