|
| static std::string | FetchUrl (const std::string &url) |
| | GETs a URL and returns the body, or "" on any failure.
|
| static bool | IsAllowedUrl (const std::string &url, std::string &reason) |
| | The rule every fetch and download checks first: https://, at most 2048 characters, printable ASCII without quoting metacharacters.
|
| static bool | DownloadFile (const std::string &url, const std::string &localPath, std::atomic< bool > *cancelFlag=nullptr, HttpStatusCallback status=nullptr) |
| | Downloads a URL to a local file.
|
| static bool | DownloadFileVerified (const std::string &url, const std::string &localPath, const std::string &expectedSha256, std::atomic< bool > *cancelFlag=nullptr, HttpStatusCallback status=nullptr, bool allowUnpinned=false) |
| | Downloads and checks the file against an expected lowercase hex SHA-256.
|
| static std::string | Sha256File (const std::string &path) |
| | SHA-256 of a file as lowercase hex, or "" if it cannot be read.
|
| static bool | ExtractZip (const std::string &zipPath, const std::string &destDir, HttpStatusCallback status=nullptr, std::string *error=nullptr) |
| | Extracts a zip into destDir.
|
| static bool | ParseArchiveLinks (const std::string &names, const std::string &verbose, std::vector< ArchiveLink > &out, std::string &error) |
| | The links in an archive, read from tar -tf (its entry names, one per line) and tar -tvf (the same entries in the same order; a link's line starts with 'l' and ends "name -> target").
|
| static bool | MaterializeArchiveLinks (const std::string &destDir, const std::vector< ArchiveLink > &links, std::string &error) |
| | Puts a copy of each link's target where the link would be, under destDir: a file is copied, a directory copied whole, and a link to another link once that one is in place.
|
| static bool | ZipEntriesAreSafe (const std::string &zipPath, std::string &reason) |
| | Lists the archive and applies IsSafeArchiveEntry to every entry.
|
| static bool | IsSafeArchiveEntry (const std::string &entry) |
| | Checks one archive entry name: no absolute path, drive letter, UNC prefix, control character or ".." segment (either separator).
|
| static bool | ParseGitHubRelease (const std::string &json, const std::string &assetPattern, const std::string &repo, std::string &outVersion, std::string &outDownloadUrl) |
| | Reads GitHub "latest release" JSON: the tag, and the first asset whose browser_download_url contains assetPattern.
|
HTTP and archive helpers for the whole editor.
The one place that uses WinHTTP (Windows) and curl (Unix).
| bool DekiEditor::EditorHttpUtils::DownloadFileVerified |
( |
const std::string & | url, |
|
|
const std::string & | localPath, |
|
|
const std::string & | expectedSha256, |
|
|
std::atomic< bool > * | cancelFlag = nullptr, |
|
|
HttpStatusCallback | status = nullptr, |
|
|
bool | allowUnpinned = false ) |
|
static |
Downloads and checks the file against an expected lowercase hex SHA-256.
What is fetched here gets run (toolchain archives become the compilers that build the user's firmware), so an unchecked download trusts both the network and the mirror. On a mismatch the file is deleted and this returns false.
An empty expectedSha256 is refused unless allowUnpinned is set (only for board-pack sources the user added); then the check is skipped and logged, so an unpinned download is visible. The built-in toolchain definitions pin every archive.
| bool DekiEditor::EditorHttpUtils::ExtractZip |
( |
const std::string & | zipPath, |
|
|
const std::string & | destDir, |
|
|
HttpStatusCallback | status = nullptr, |
|
|
std::string * | error = nullptr ) |
|
static |
Extracts a zip into destDir.
Before writing anything, refuses an archive with entries that would land outside destDir (ZipEntriesAreSafe). On Windows a symbolic link in the archive is extracted as a copy of what it points to (MaterializeArchiveLinks): tar.exe cannot create links without administrator rights or Developer Mode, and failing on them failed the whole extract. error, when given, says why it failed.
| bool DekiEditor::EditorHttpUtils::MaterializeArchiveLinks |
( |
const std::string & | destDir, |
|
|
const std::vector< ArchiveLink > & | links, |
|
|
std::string & | error ) |
|
static |
Puts a copy of each link's target where the link would be, under destDir: a file is copied, a directory copied whole, and a link to another link once that one is in place.
False, with error, when a target is absolute or outside destDir. A link to nothing is left out, as such a link would lead nowhere either.