in source/ota_http.c [78:116]
OtaErr_t requestDataBlock_Http( OtaAgentContext_t * pAgentCtx )
{
OtaHttpStatus_t httpStatus = OtaHttpSuccess;
/* Values for the "Range" field in HTTP header. */
uint32_t rangeStart = 0;
uint32_t rangeEnd = 0;
OtaFileContext_t * fileContext = NULL;
assert( ( pAgentCtx != NULL ) && ( pAgentCtx->pOtaInterface != NULL ) && ( pAgentCtx->pOtaInterface->http.request != NULL ) );
LogDebug( ( "Invoking requestDataBlock_Http" ) );
fileContext = &( pAgentCtx->fileContext );
/* Calculate ranges. */
rangeStart = currBlock * OTA_FILE_BLOCK_SIZE;
if( fileContext->blocksRemaining == 1U )
{
rangeEnd = fileContext->fileSize - 1U;
}
else
{
rangeEnd = rangeStart + OTA_FILE_BLOCK_SIZE - 1U;
}
/* Request file data over HTTP using the rangeStart and rangeEnd. */
httpStatus = pAgentCtx->pOtaInterface->http.request( rangeStart, rangeEnd );
if( httpStatus != OtaHttpSuccess )
{
LogError( ( "Error occured while requesting data block:"
"OtaHttpStatus_t=%s"
, OTA_HTTP_strerror( httpStatus ) ) );
}
return ( httpStatus == OtaHttpSuccess ) ? OtaErrNone : OtaErrRequestFileBlockFailed;
}