From b5e30edd03799ade6419df055716976dcbad0441 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Wed, 18 Nov 2020 12:59:33 -0800 Subject: [PATCH] add TDNFFindRepoById() and TDNFCurlErrorIsFatal() --- client/prototypes.h | 12 ++++++++ client/repoutils.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/client/prototypes.h b/client/prototypes.h index 5b4d8f7..cb003c7 100644 --- a/client/prototypes.h +++ b/client/prototypes.h @@ -193,6 +193,18 @@ TDNFRepoApplySSLSettings( CURL *pCurl ); +uint32_t +TDNFFindRepoById( + PTDNF pTdnf, + const char* pszRepo, + PTDNF_REPO_DATA_INTERNAL* ppRepo + ); + +uint32_t +TDNFCurlErrorIsFatal( + CURLcode curlError +); + //remoterepo.c uint32_t TDNFCheckRepoMDFileHashFromMetalink( diff --git a/client/repoutils.c b/client/repoutils.c index 08cf0d1..caeab91 100644 --- a/client/repoutils.c +++ b/client/repoutils.c @@ -791,3 +791,77 @@ cleanup: error: goto cleanup; } + +uint32_t +TDNFFindRepoById( + PTDNF pTdnf, + const char* pszRepo, + PTDNF_REPO_DATA_INTERNAL* ppRepo + ) +{ + uint32_t dwError = 0; + PTDNF_REPO_DATA_INTERNAL pRepos = NULL; + + if(!pTdnf || IsNullOrEmptyString(pszRepo)) + { + dwError = ERROR_TDNF_INVALID_PARAMETER; + BAIL_ON_TDNF_ERROR(dwError); + } + if(!pTdnf->pRepos) + { + dwError = ERROR_TDNF_NO_REPOS; + BAIL_ON_TDNF_ERROR(dwError); + } + pRepos = pTdnf->pRepos; + + while(pRepos) + { + if(!strcmp(pszRepo, pRepos->pszId)) + { + break; + } + pRepos = pRepos->pNext; + } + *ppRepo = pRepos; + +cleanup: + return dwError; +error: + goto cleanup; +} + +uint32_t +TDNFCurlErrorIsFatal( + CURLcode curlError +) +{ + uint32_t dwError = 0; + + switch(curlError) { + case CURLE_UNSUPPORTED_PROTOCOL: + case CURLE_FAILED_INIT: + case CURLE_URL_MALFORMAT: + case CURLE_FILE_COULDNT_READ_FILE: + case CURLE_FUNCTION_NOT_FOUND: + case CURLE_UNKNOWN_OPTION: + case CURLE_SSL_ENGINE_NOTFOUND: + case CURLE_RECURSIVE_API_CALL: + + case CURLE_ABORTED_BY_CALLBACK: + case CURLE_BAD_FUNCTION_ARGUMENT: + case CURLE_CONV_REQD: + case CURLE_COULDNT_RESOLVE_PROXY: + case CURLE_FILESIZE_EXCEEDED: + case CURLE_INTERFACE_FAILED: + case CURLE_NOT_BUILT_IN: + case CURLE_OUT_OF_MEMORY: + case CURLE_SSL_CACERT_BADFILE: + case CURLE_SSL_CRL_BADFILE: + case CURLE_WRITE_ERROR: + dwError = curlError; + break; + default: + break; + } + return dwError; +}