Here is the terminate handler and the calling function:
int
HRWWWTransferInterfaceImpl::terminateCB(
HTRequest * request,
HTResponse * response,
void * param,
int status)
{
HRWWWTransferInterfaceImpl* pThis = (HRWWWTransferInterfaceImpl *)
HTRequest
_context(request);
// the status/100 == 2 trick was in the libwww sample; I assume it
means
// that all 200-series error codes are "good", while all others are
"bad"
pThis->i_errStatus = (status/100 == 2) ? HRERR_OK :
HRERR_HTTP_TRANSFER;
HTEventList_stopLoop();
return HT_OK;
}
HRError
HRWWWTransferInterfaceImpl::getFile(
const RWCString & strURL,
const RWCString & strOutputFilename,
HRProgressMonitor *pProgress /* = NULL */)
{
// Request init
HTRequest * request = HTRequest_new();
if (request == NULL)
return HRERR_WWW_NO_SERVER;
HTRequest_setOutputFormat(request, DEFAULT_FORMAT);
HTRequest_setContext (request, (void*)this);
// If we crap out before calling the terminate callback with a
successful
// load, we want some sort of general failure
i_pProgress = pProgress;
// If we crap out before calling the terminate callback with a
successful
// load, we want some sort of general failure
i_pProgress = pProgress;
HTParentAnchor * anchor = (HTParentAnchor *)
HTAnchor_findAddress(strURL);
FILE * outputFile = fopen(strOutputFilename, "wb");
if (outputFile == NULL)
{
HTRequest_delete(request);
HRError errStatus = HRERR_CANT_OPEN_FILE;
errStatus << strOutputFilename;
errStatus.logError();
return errStatus;
}
HTRequest_setOutputStream(request, HTFWriter_new(request,
outputFile, YES));
int status = HTLoadAnchor((HTAnchor *) anchor, request);
if (status != YES)
{
HTRequest_delete(request);
HRSystem::getSystem().deleteFile(strOutputFilename);
HRError errStatus = HRERR_WWW_NO_SERVER;
errStatus.logError();
return errStatus;
}
// Go into the event loop...
HTEventList_loop(request);
HTEventList_unregisterAll();
HTRequest_delete(request);
fclose(outputFile);
HRError err = getStatus();
if (err.bad())
{
HRSystem::getSystem().deleteFile(strOutputFilename);
err = HRERR_HTTP_TRANSFER;
err << strURL;
err.logError();
return err;
}
return HRERR_OK;
}
--
Warren Ho Algorithmics Inc.
Software Engineer 185 Spadina Avenue
email: warrenh@algorithmics.com Toronto, Ontario
phone: (416)-217-4353 Canada M5T 2C6
Forwarded message 1
Would anyone help me out with this problem?
I tried to download a file from a server which requires access
authentication using http protocol. My program works fine if I download
it from a server which does not require authentication. However when I
tried to do it from a server which requires one, the program receive the
following traces and hangs:
Thread Id - 1: libwww trace: "Net After... calling 6c604c (request
c575d0, response c4fb50, status -1, context 0)
"
Thread Id - 1: libwww output: "Fatal Error: 401 Unauthorized
"
Thread Id - 1: libwww trace: "Load End.... Request ended with code -1
"
Thread Id - 1: libwww trace: "Net After... calling 1658c8 (request
c575d0, response c4fb50, status -1, context 0)
"
It seems the program is able to complete the terminate handler, but it
doesn't know how to return to the function that specifies the terminate
callback. I am trying to return the status back to the GUI, so I don't
want to exit the program in the terminate handler.
Any help would be greatly appreciated.
Thanks,
Warren
--
Warren Ho Algorithmics Inc.
Software Engineer 185 Spadina Avenue
email: warrenh@algorithmics.com Toronto, Ontario
phone: (416)-217-4353 Canada M5T 2C6