SecureDownload.cpp [plain text]
#include <Security/Security.h>
#include <security_utilities/security_utilities.h>
#include <security_cdsa_utilities/cssmbridge.h>
#include <../../base/SecBase.h>
#include "Download.h"
#include "SecureDownload.h"
#define API_BEGIN \
try {
#define API_END \
} \
catch (const MacOSError &err) { return err.osStatus(); } \
catch (const std::bad_alloc &) { return errSecAllocate; } \
catch (...) { return errSecInternalComponent; } \
return errSecSuccess;
#define API_END_GENERIC_CATCH } catch (...) { return; }
#define API_END_ERROR_CATCH(bad) } catch (...) { return bad; }
OSStatus SecureDownloadCreateWithTicket (CFDataRef ticket,
SecureDownloadTrustSetupCallback setup,
void* setupContext,
SecureDownloadTrustEvaluateCallback evaluate,
void* evaluateContext,
SecureDownloadRef* downloadRef)
{
API_BEGIN
Download* sd = new Download ();
sd->Initialize (ticket, setup, setupContext, evaluate, evaluateContext);
Required (downloadRef) = sd;
API_END
}
OSStatus SecureDownloadCopyURLs (SecureDownloadRef downloadRef, CFArrayRef* urls)
{
API_BEGIN
Required (downloadRef);
Download* d = (Download*) downloadRef;
Required (urls) = d->CopyURLs ();
API_END
}
OSStatus SecureDownloadCopyName (SecureDownloadRef downloadRef, CFStringRef* name)
{
API_BEGIN
Required (downloadRef);
Download* d = (Download*) downloadRef;
Required (name) = d->CopyName ();
API_END
}
OSStatus SecureDownloadCopyCreationDate (SecureDownloadRef downloadRef, CFDateRef* date)
{
API_BEGIN
Required (downloadRef);
Download* d = (Download*) downloadRef;
Required (date) = d->CopyDate ();
API_END
}
OSStatus SecureDownloadGetDownloadSize (SecureDownloadRef downloadRef, SInt64* size)
{
API_BEGIN
Required (downloadRef);
Download* d = (Download*) downloadRef;
Required (size) = d->GetDownloadSize ();
API_END
}
OSStatus SecureDownloadUpdateWithData (SecureDownloadRef downloadRef, CFDataRef data)
{
API_BEGIN
Required (downloadRef);
Required (data);
Download* d = (Download*) downloadRef;
d->UpdateWithData (data);
API_END
}
OSStatus SecureDownloadFinished (SecureDownloadRef downloadRef)
{
API_BEGIN
Required (downloadRef);
Download* d = (Download*) downloadRef;
d->Finalize ();
API_END
}
OSStatus SecureDownloadRelease (SecureDownloadRef downloadRef)
{
API_BEGIN
Required (downloadRef);
delete (Download*) downloadRef;
API_END
}
OSStatus SecureDownloadCopyTicketLocation (CFURLRef url, CFURLRef *ticketLocation)
{
API_BEGIN
Required (ticketLocation);
Required (url);
CFStringRef resourceSpecifier = CFURLCopyResourceSpecifier (url);
if (resourceSpecifier == NULL)
{
CFError::throwMe ();
}
*ticketLocation = CFURLCreateWithString (NULL, resourceSpecifier, NULL);
if (*ticketLocation == NULL)
{
CFError::throwMe ();
}
CFStringRef scheme = CFURLCopyScheme (*ticketLocation);
if (scheme != NULL)
{
CFComparisonResult equal = CFStringCompare (scheme, CFSTR("file"), kCFCompareCaseInsensitive);
CFRelease (scheme);
if (equal == kCFCompareEqualTo)
{
CFRelease (*ticketLocation);
*ticketLocation = NULL;
MacOSError::throwMe (errSecureDownloadInvalidDownload);
}
}
CFRelease (resourceSpecifier);
API_END
}