add cli lib

Change-Id: I52b14eafe9e7ca4e1f9171b1bd20222c7467ee4e
This commit is contained in:
Priyesh Padmavilasom 2017-02-19 06:18:44 +00:00 committed by rongrong qiu
parent 8fc9357f73
commit bb7ac75bd7
52 changed files with 2052 additions and 1438 deletions

View File

@ -3,7 +3,7 @@ ACLOCAL_AMFLAGS = -I m4
CLEANFILES =
EXTRA_DIST =
conf_DATA = tdnf.conf
pkginclude_HEADERS = include/tdnfclient.h include/tdnferror.h include/tdnftypes.h
pkginclude_HEADERS = include/*.h
pkgconfigdir = $(libdir)/pkgconfig
SUBDIRS = \
@ -12,8 +12,16 @@ SUBDIRS = \
tests \
tools
pkgconfig_DATA = tdnf.pc
pkgconfig_DATA = tdnf.pc tdnf-cli-libs.pc
tdnf.pc: $(top_srcdir)/tdnf.pc.in
./config.status --file=${subdir}/tdnf.pc:${subdir}/tdnf.pc.in
tdnf-cli-libs.pc: $(top_srcdir)/tdnf-cli-libs.pc.in
./config.status --file=${subdir}/tdnf-cli-libs.pc:${subdir}/tdnf-cli-libs.pc.in
CLEANFILES += tdnf.pc
CLEANFILES += tdnf-cli-libs.pc
EXTRA_DIST += tdnf.pc.in
EXTRA_DIST += tdnf-cli-libs.pc.in

View File

@ -1,9 +1,9 @@
lib_LTLIBRARIES = libtdnfclient.la
libtdnfclient_la_CPPFLAGS = -I$(top_srcdir)/include
lib_LTLIBRARIES = libtdnf.la
libtdnf_la_CPPFLAGS = -I$(top_srcdir)/include
AM_CFLAGS += $(LIBCURL_CFLAGS)
libtdnfclient_la_SOURCES = \
libtdnf_la_SOURCES = \
api.c \
clean.c \
client.c \
@ -23,7 +23,7 @@ libtdnfclient_la_SOURCES = \
search.c \
validate.c
libtdnfclient_la_LIBADD = \
libtdnf_la_LIBADD = \
$(top_builddir)/common/libcommon.la \
@LIBCURL_LIBS@ \
-lhawkey \

View File

@ -107,7 +107,6 @@ TDNFAlterCommand(
)
{
uint32_t dwError = 0;
if(!pTdnf || !pSolvedInfo)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
@ -724,7 +723,8 @@ TDNFRepoList(
PTDNF_REPO_DATA pReposAll = NULL;
PTDNF_REPO_DATA pRepoTemp = NULL;
PTDNF_REPO_DATA pRepoCurrent = NULL;
PTDNF_REPO_DATA pRepos = NULL;
PTDNF_REPO_DATA_INTERNAL pRepos = NULL;
int nAdd = 0;
if(!pTdnf || !pTdnf->pRepos || !ppReposAll)
@ -1196,7 +1196,7 @@ TDNFCloseHandle(
}
if(pTdnf->pRepos)
{
TDNFFreeRepos(pTdnf->pRepos);
TDNFFreeReposInternal(pTdnf->pRepos);
}
if(pTdnf->hSack)
{
@ -1214,50 +1214,9 @@ TDNFCloseHandle(
}
}
void
TDNFFreeCmdArgs(
PTDNF_CMD_ARGS pCmdArgs
)
{
int nIndex = 0;
if(pCmdArgs)
{
for(nIndex = 0; nIndex < pCmdArgs->nCmdCount; ++nIndex)
{
TDNF_SAFE_FREE_MEMORY(pCmdArgs->ppszCmds[nIndex]);
}
TDNF_SAFE_FREE_MEMORY(pCmdArgs->ppszCmds);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszInstallRoot);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszConfFile);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszReleaseVer);
if(pCmdArgs->pSetOpt)
{
TDNFFreeCmdOpt(pCmdArgs->pSetOpt);
}
TDNF_SAFE_FREE_MEMORY(pCmdArgs);
}
}
const char*
TDNFGetVersion(
)
{
return PACKAGE_VERSION;
}
void
TDNFFreeCmdOpt(
PTDNF_CMD_OPT pCmdOpt
)
{
PTDNF_CMD_OPT pCmdOptTemp = NULL;
while(pCmdOpt)
{
TDNF_SAFE_FREE_MEMORY(pCmdOpt->pszOptName);
TDNF_SAFE_FREE_MEMORY(pCmdOpt->pszOptValue);
pCmdOptTemp = pCmdOpt->pNext;
TDNF_SAFE_FREE_MEMORY(pCmdOpt);
pCmdOpt = pCmdOptTemp;
}
}

View File

@ -22,13 +22,13 @@
uint32_t
TDNFCopyEnabledRepos(
PTDNF_REPO_DATA pRepoData,
PTDNF_REPO_DATA_INTERNAL pRepoData,
char*** pppszReposUsed
)
{
uint32_t dwError = 0;
char** ppszReposUsed = NULL;
PTDNF_REPO_DATA pRepoTemp = NULL;
PTDNF_REPO_DATA_INTERNAL pRepoTemp = NULL;
int nCount = 0;
if(!pRepoData || !pppszReposUsed)
@ -83,15 +83,3 @@ error:
TDNF_SAFE_FREE_STRINGARRAY(ppszReposUsed);
goto cleanup;
}
void
TDNFFreeCleanInfo(
PTDNF_CLEAN_INFO pCleanInfo
)
{
if(pCleanInfo)
{
TDNF_SAFE_FREE_STRINGARRAY(pCleanInfo->ppszReposUsed);
TDNFFreeMemory(pCleanInfo);
}
}

View File

@ -121,85 +121,3 @@ cleanup:
error:
goto cleanup;
}
void
TDNFFreePackageInfo(
PTDNF_PKG_INFO pPkgInfo
)
{
while(pPkgInfo)
{
PTDNF_PKG_INFO pPkgInfoTemp = pPkgInfo;
pPkgInfo = pPkgInfo->pNext;
TDNFFreePackageInfoContents(pPkgInfoTemp);
TDNFFreeMemory(pPkgInfoTemp);
}
}
void
TDNFFreePackageInfoArray(
PTDNF_PKG_INFO pPkgInfoArray,
uint32_t unLength
)
{
uint32_t unIndex = 0;
if(pPkgInfoArray && unLength > 0)
{
for(unIndex = 0; unIndex < unLength; ++unIndex)
{
TDNFFreePackageInfoContents(&pPkgInfoArray[unIndex]);
}
}
TDNF_SAFE_FREE_MEMORY(pPkgInfoArray);
}
void
TDNFFreePackageInfoContents(
PTDNF_PKG_INFO pPkgInfo
)
{
if(pPkgInfo)
{
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszName);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszRepoName);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszVersion);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszArch);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszSummary);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszURL);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszLicense);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszDescription);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszFormattedSize);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszRelease);
}
}
void
TDNFFreeSolvedPackageInfo(
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo
)
{
int i = 0;
if(pSolvedPkgInfo)
{
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsNotAvailable);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsExisting);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsToInstall);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsToUpgrade);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsToDowngrade);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsToRemove);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsUnNeeded);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsToReinstall);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsObsoleted);
if(pSolvedPkgInfo->ppszPkgsNotResolved)
{
while(pSolvedPkgInfo->ppszPkgsNotResolved[i])
{
TDNF_SAFE_FREE_MEMORY(pSolvedPkgInfo->ppszPkgsNotResolved[i++]);
}
}
TDNF_SAFE_FREE_MEMORY(pSolvedPkgInfo->ppszPkgsNotResolved);
}
TDNF_SAFE_FREE_MEMORY(pSolvedPkgInfo);
}

View File

@ -101,12 +101,6 @@ typedef enum
} \
} while(0)
#define TDNF_SAFE_FREE_PKGINFO(pPkgInfo) \
do { \
if (pPkgInfo) { \
TDNFFreePackageInfo(pPkgInfo); \
} \
} while(0)
//Misc
#define TDNF_RPM_EXT ".rpm"
#define TDNF_NAME "tdnf"

View File

@ -73,7 +73,7 @@
//libcurl
#include <curl/curl.h>
#include <tdnfclient.h>
#include <tdnf.h>
#include "defines.h"
#include "structs.h"

View File

@ -240,10 +240,10 @@ error:
}
uint32_t
TNDFRefreshRepo(
TDNFRefreshRepo(
PTDNF pTdnf,
int nCleanMetadata,
PTDNF_REPO_DATA pRepo
PTDNF_REPO_DATA_INTERNAL pRepo
)
{
uint32_t dwError = 0;
@ -367,12 +367,12 @@ TDNFRefreshSack(
//If there is an empty repo directory, do nothing
if(pTdnf->pRepos)
{
PTDNF_REPO_DATA pTempRepo = pTdnf->pRepos;
PTDNF_REPO_DATA_INTERNAL pTempRepo = pTdnf->pRepos;
while(pTempRepo)
{
if(pTempRepo->nEnabled)
{
dwError = TNDFRefreshRepo(pTdnf, nCleanMetadata, pTempRepo);
dwError = TDNFRefreshRepo(pTdnf, nCleanMetadata, pTempRepo);
BAIL_ON_TDNF_ERROR(dwError);
}
pTempRepo = pTempRepo->pNext;

View File

@ -29,7 +29,7 @@ TDNFCheckLocalPackagesInternal(
//clean.c
uint32_t
TDNFCopyEnabledRepos(
PTDNF_REPO_DATA pRepoData,
PTDNF_REPO_DATA_INTERNAL pRepoData,
char*** pppszReposUsed
);
@ -101,10 +101,10 @@ TDNFLoadYumRepo(
);
uint32_t
TNDFRefreshRepo(
TDNFRefreshRepo(
PTDNF pTdnf,
int nCleanMetadata,
PTDNF_REPO_DATA pRepo
PTDNF_REPO_DATA_INTERNAL pRepo
);
uint32_t
@ -416,7 +416,7 @@ TDNFInitRepoFromMetadata(
uint32_t
TDNFInitRepo(
PTDNF pTdnf,
PTDNF_REPO_DATA pRepoData,
PTDNF_REPO_DATA_INTERNAL pRepoData,
HyRepo* phRepo
);
@ -432,13 +432,13 @@ uint32_t
TDNFGetRepoById(
PTDNF pTdnf,
const char* pszName,
PTDNF_REPO_DATA* ppRepo
PTDNF_REPO_DATA_INTERNAL* ppRepo
);
uint32_t
TDNFGetRepoMD(
PTDNF pTdnf,
PTDNF_REPO_DATA pRepoData,
PTDNF_REPO_DATA_INTERNAL pRepoData,
const char *pszRepoDataDir,
PTDNF_REPO_METADATA *ppRepoMD
);
@ -473,14 +473,14 @@ uint32_t
TDNFLoadReposFromFile(
PTDNF pTdnf,
char* pszRepoFile,
PTDNF_REPO_DATA* ppRepos
PTDNF_REPO_DATA_INTERNAL* ppRepos
);
uint32_t
TDNFLoadRepoData(
PTDNF pTdnf,
TDNF_REPOLISTFILTER nFilter,
PTDNF_REPO_DATA* ppReposAll
PTDNF_REPO_DATA_INTERNAL* ppReposAll
);
uint32_t
@ -490,17 +490,22 @@ TDNFRepoListFinalize(
uint32_t
TDNFAlterRepoState(
PTDNF_REPO_DATA pRepos,
PTDNF_REPO_DATA_INTERNAL pRepos,
int nEnable,
const char* pszId
);
uint32_t
TDNFCloneRepo(
PTDNF_REPO_DATA pRepoIn,
PTDNF_REPO_DATA_INTERNAL pRepoIn,
PTDNF_REPO_DATA* ppRepo
);
void
TDNFFreeReposInternal(
PTDNF_REPO_DATA_INTERNAL pRepos
);
//resolve.c
HySubject
hy_subject_create(
@ -689,11 +694,6 @@ TDNFFreeCachedRpmsArray(
);
//memory.c
void
TDNFFreePackageInfoContents(
PTDNF_PKG_INFO pPkgInfo
);
void
TDNFFreeCmdOpt(
PTDNF_CMD_OPT pCmdOpt

View File

@ -24,7 +24,7 @@
uint32_t
TDNFInitRepo(
PTDNF pTdnf,
PTDNF_REPO_DATA pRepoData,
PTDNF_REPO_DATA_INTERNAL pRepoData,
HyRepo* phRepo
)
{
@ -171,7 +171,7 @@ TDNFGetGPGCheck(
)
{
uint32_t dwError = 0;
PTDNF_REPO_DATA pRepo = NULL;
PTDNF_REPO_DATA_INTERNAL pRepo = NULL;
int nGPGCheck = 0;
char* pszUrlGPGKey = NULL;
@ -220,12 +220,12 @@ uint32_t
TDNFGetRepoById(
PTDNF pTdnf,
const char* pszId,
PTDNF_REPO_DATA* ppRepo
PTDNF_REPO_DATA_INTERNAL* ppRepo
)
{
uint32_t dwError = 0;
PTDNF_REPO_DATA pRepo = NULL;
PTDNF_REPO_DATA pRepos = NULL;
PTDNF_REPO_DATA_INTERNAL pRepo = NULL;
PTDNF_REPO_DATA_INTERNAL pRepos = NULL;
if(!pTdnf || IsNullOrEmptyString(pszId) || !ppRepo)
{
@ -268,7 +268,7 @@ error:
uint32_t
TDNFGetRepoMD(
PTDNF pTdnf,
PTDNF_REPO_DATA pRepoData,
PTDNF_REPO_DATA_INTERNAL pRepoData,
const char *pszRepoDataDir,
PTDNF_REPO_METADATA *ppRepoMD
)

View File

@ -25,14 +25,14 @@ uint32_t
TDNFLoadRepoData(
PTDNF pTdnf,
TDNF_REPOLISTFILTER nFilter,
PTDNF_REPO_DATA* ppReposAll
PTDNF_REPO_DATA_INTERNAL* ppReposAll
)
{
uint32_t dwError = 0;
char* pszRepoFilePath = NULL;
PTDNF_REPO_DATA pReposAll = NULL;
PTDNF_REPO_DATA pReposTemp = NULL;
PTDNF_REPO_DATA pRepos = NULL;
PTDNF_REPO_DATA_INTERNAL pReposAll = NULL;
PTDNF_REPO_DATA_INTERNAL pReposTemp = NULL;
PTDNF_REPO_DATA_INTERNAL pRepos = NULL;
PTDNF_CONF pConf = NULL;
DIR *pDir = NULL;
struct dirent *pEnt = NULL;
@ -80,7 +80,7 @@ TDNFLoadRepoData(
if((nFilter == REPOLISTFILTER_ENABLED && !pRepos->nEnabled) ||
(nFilter == REPOLISTFILTER_DISABLED && pRepos->nEnabled))
{
TDNFFreeRepos(pRepos);
TDNFFreeReposInternal(pRepos);
pRepos = NULL;
continue;
}
@ -117,7 +117,7 @@ error:
}
if(pReposAll)
{
TDNFFreeRepos(pReposAll);
TDNFFreeReposInternal(pReposAll);
}
goto cleanup;
}
@ -126,7 +126,7 @@ uint32_t
TDNFLoadReposFromFile(
PTDNF pTdnf,
char* pszRepoFile,
PTDNF_REPO_DATA* ppRepos
PTDNF_REPO_DATA_INTERNAL* ppRepos
)
{
uint32_t dwError = 0;
@ -134,8 +134,8 @@ TDNFLoadReposFromFile(
char* pszRepo = NULL;
char* pszMetadataExpire = NULL;
PTDNF_REPO_DATA pRepos = NULL;
PTDNF_REPO_DATA pRepo = NULL;
PTDNF_REPO_DATA_INTERNAL pRepos = NULL;
PTDNF_REPO_DATA_INTERNAL pRepo = NULL;
PCONF_DATA pData = NULL;
PCONF_SECTION pSections = NULL;
@ -149,7 +149,7 @@ TDNFLoadReposFromFile(
dwError = TDNFAllocateMemory(
1,
sizeof(TDNF_REPO_DATA),
sizeof(TDNF_REPO_DATA_INTERNAL),
(void**)&pRepo);
BAIL_ON_TDNF_ERROR(dwError);
@ -256,7 +256,7 @@ error:
TDNF_SAFE_FREE_MEMORY(pRepo);
if(pRepos)
{
TDNFFreeRepos(pRepos);
TDNFFreeReposInternal(pRepos);
}
goto cleanup;
}
@ -268,7 +268,7 @@ TDNFRepoListFinalize(
{
uint32_t dwError = 0;
PTDNF_CMD_OPT pSetOpt = NULL;
PTDNF_REPO_DATA pRepo = NULL;
PTDNF_REPO_DATA_INTERNAL pRepo = NULL;
if(!pTdnf || !pTdnf->pArgs || !pTdnf->pRepos)
{
@ -325,7 +325,7 @@ error:
uint32_t
TDNFAlterRepoState(
PTDNF_REPO_DATA pRepos,
PTDNF_REPO_DATA_INTERNAL pRepos,
int nEnable,
const char* pszId
)
@ -374,7 +374,7 @@ error:
uint32_t
TDNFCloneRepo(
PTDNF_REPO_DATA pRepoIn,
PTDNF_REPO_DATA_INTERNAL pRepoIn,
PTDNF_REPO_DATA* ppRepo
)
{
@ -387,7 +387,9 @@ TDNFCloneRepo(
BAIL_ON_TDNF_ERROR(dwError);
}
dwError = TDNFAllocateMemory(1, sizeof(TDNF_REPO_DATA), (void**)&pRepo);
dwError = TDNFAllocateMemory(1,
sizeof(TDNF_REPO_DATA),
(void**)&pRepo);
BAIL_ON_TDNF_ERROR(dwError);
pRepo->nEnabled = pRepoIn->nEnabled;
@ -407,12 +409,6 @@ TDNFCloneRepo(
dwError = TDNFSafeAllocateString(pRepoIn->pszUrlGPGKey, &pRepo->pszUrlGPGKey);
BAIL_ON_TDNF_ERROR(dwError);
dwError = TDNFSafeAllocateString(pRepoIn->pszUser, &pRepo->pszUser);
BAIL_ON_TDNF_ERROR(dwError);
dwError = TDNFSafeAllocateString(pRepoIn->pszPass, &pRepo->pszPass);
BAIL_ON_TDNF_ERROR(dwError);
*ppRepo = pRepo;
cleanup:
@ -430,29 +426,27 @@ error:
goto cleanup;
}
void
TDNFFreeRepos(
PTDNF_REPO_DATA pRepos
)
TDNFFreeReposInternal(
PTDNF_REPO_DATA_INTERNAL pRepos
)
{
PTDNF_REPO_DATA pRepo = NULL;
while(pRepos)
{
pRepo = pRepos;
TDNF_SAFE_FREE_MEMORY(pRepo->pszId);
TDNF_SAFE_FREE_MEMORY(pRepo->pszName);
TDNF_SAFE_FREE_MEMORY(pRepo->pszBaseUrl);
TDNF_SAFE_FREE_MEMORY(pRepo->pszMetaLink);
TDNF_SAFE_FREE_MEMORY(pRepo->pszUrlGPGKey);
TDNF_SAFE_FREE_MEMORY(pRepo->pszUser);
TDNF_SAFE_FREE_MEMORY(pRepo->pszPass);
if(pRepo->hRepo)
PTDNF_REPO_DATA_INTERNAL pRepo = NULL;
while(pRepos)
{
hy_repo_free(pRepo->hRepo);
pRepo = pRepos;
TDNF_SAFE_FREE_MEMORY(pRepo->pszId);
TDNF_SAFE_FREE_MEMORY(pRepo->pszName);
TDNF_SAFE_FREE_MEMORY(pRepo->pszBaseUrl);
TDNF_SAFE_FREE_MEMORY(pRepo->pszMetaLink);
TDNF_SAFE_FREE_MEMORY(pRepo->pszUrlGPGKey);
TDNF_SAFE_FREE_MEMORY(pRepo->pszUser);
TDNF_SAFE_FREE_MEMORY(pRepo->pszPass);
if(pRepo->hRepo)
{
hy_repo_free(pRepo->hRepo);
}
pRepos = pRepo->pNext;
TDNF_SAFE_FREE_MEMORY(pRepo);
}
pRepos = pRepo->pNext;
TDNF_SAFE_FREE_MEMORY(pRepo);
}
}

View File

@ -48,7 +48,7 @@ TDNFRepoGetBaseUrl(
{
uint32_t dwError = 0;
char* pszBaseUrl = NULL;
PTDNF_REPO_DATA pRepos = NULL;
PTDNF_REPO_DATA_INTERNAL pRepos = NULL;
if(!pTdnf || !pszRepo || !ppszBaseUrl)
{
@ -99,7 +99,7 @@ TDNFRepoGetUserPass(
{
uint32_t dwError = 0;
char* pszUserPass = NULL;
PTDNF_REPO_DATA pRepos = NULL;
PTDNF_REPO_DATA_INTERNAL pRepos = NULL;
if(!pTdnf || !pszRepo || !ppszUserPass)
{

View File

@ -178,31 +178,31 @@ error:
int
doCheck(PTDNFRPMTS pTS)
{
int nResult = 0;
rpmpsi psi = NULL;
rpmProblem prob = NULL;
nResult = rpmtsCheck(pTS->pTS);
int nResult = 0;
rpmpsi psi = NULL;
rpmProblem prob = NULL;
nResult = rpmtsCheck(pTS->pTS);
rpmps ps = rpmtsProblems(pTS->pTS);
if(ps)
{
int nProbs = rpmpsNumProblems(ps);
if(nProbs > 0)
rpmps ps = rpmtsProblems(pTS->pTS);
if(ps)
{
printf("Found %d problems\n", nProbs);
int nProbs = rpmpsNumProblems(ps);
if(nProbs > 0)
{
fprintf(stderr, "Found %d problems\n", nProbs);
psi = rpmpsInitIterator(ps);
while(rpmpsNextIterator(psi) >= 0)
{
prob = rpmpsGetProblem(psi);
printf("%s\n", rpmProblemString(prob));
rpmProblemFree(prob);
}
rpmpsFreeIterator(psi);
nResult = ERROR_TDNF_RPM_CHECK;
psi = rpmpsInitIterator(ps);
while(rpmpsNextIterator(psi) >= 0)
{
prob = rpmpsGetProblem(psi);
fprintf(stderr, "%s\n", rpmProblemString(prob));
rpmProblemFree(prob);
}
rpmpsFreeIterator(psi);
nResult = ERROR_TDNF_RPM_CHECK;
}
}
}
return nResult;
return nResult;
}
uint32_t

View File

@ -20,13 +20,31 @@
#pragma once
typedef struct _TDNF_REPO_DATA_INTERNAL_
{
int nEnabled;
int nSkipIfUnavailable;
int nGPGCheck;
long lMetadataExpire;
char* pszId;
char* pszName;
char* pszBaseUrl;
char* pszMetaLink;
char* pszUrlGPGKey;
char* pszUser;
char* pszPass;
HyRepo hRepo;
struct _TDNF_REPO_DATA_INTERNAL_* pNext;
}TDNF_REPO_DATA_INTERNAL, *PTDNF_REPO_DATA_INTERNAL;
typedef struct _TDNF_
{
HySack hSack;
HyGoal hGoal;
PTDNF_CMD_ARGS pArgs;
PTDNF_CONF pConf;
PTDNF_REPO_DATA pRepos;
PTDNF_REPO_DATA_INTERNAL pRepos;
}TDNF;
typedef struct _TDNF_CACHED_RPM_ENTRY

View File

@ -125,48 +125,6 @@ error:
goto cleanup;
}
void
TDNFFreeUpdateInfoSummary(
PTDNF_UPDATEINFO_SUMMARY pSummary
)
{
if(pSummary)
{
TDNFFreeMemory(pSummary);
}
}
void
TDNFFreeUpdateInfo(
PTDNF_UPDATEINFO pUpdateInfo
)
{
if(pUpdateInfo)
{
TDNF_SAFE_FREE_MEMORY(pUpdateInfo->pszID);
TDNF_SAFE_FREE_MEMORY(pUpdateInfo->pszDate);
TDNF_SAFE_FREE_MEMORY(pUpdateInfo->pszDescription);
TDNFFreeUpdateInfoReferences(pUpdateInfo->pReferences);
TDNFFreeUpdateInfoPackages(pUpdateInfo->pPackages);
TDNF_SAFE_FREE_MEMORY(pUpdateInfo);
}
}
void
TDNFFreeUpdateInfoReferences(
PTDNF_UPDATEINFO_REF pRef
)
{
if(pRef)
{
TDNF_SAFE_FREE_MEMORY(pRef->pszID);
TDNF_SAFE_FREE_MEMORY(pRef->pszLink);
TDNF_SAFE_FREE_MEMORY(pRef->pszTitle);
TDNF_SAFE_FREE_MEMORY(pRef->pszType);
}
}
uint32_t
TDNFGetUpdateInfoPackages(
HyAdvisory hAdv,
@ -275,23 +233,3 @@ error:
goto cleanup;
}
void
TDNFFreeUpdateInfoPackages(
PTDNF_UPDATEINFO_PKG pPkgs
)
{
PTDNF_UPDATEINFO_PKG pTemp = NULL;
while(pPkgs)
{
TDNF_SAFE_FREE_MEMORY(pPkgs->pszName);
TDNF_SAFE_FREE_MEMORY(pPkgs->pszFileName);
TDNF_SAFE_FREE_MEMORY(pPkgs->pszEVR);
TDNF_SAFE_FREE_MEMORY(pPkgs->pszArch);
pTemp = pPkgs;
pPkgs = pPkgs->pNext;
TDNF_SAFE_FREE_MEMORY(pTemp);
}
}

View File

@ -20,57 +20,6 @@
#include "includes.h"
uint32_t
TDNFUtilsFormatSize(
uint32_t unSize,
char** ppszFormattedSize
)
{
uint32_t dwError = 0;
char* pszFormattedSize = NULL;
char* pszSizes = "bkMG";
double dSize = unSize;
int nIndex = 0;
int nLimit = strlen(pszSizes);
double dKiloBytes = 1024.0;
int nMaxSize = 25;
if(!ppszFormattedSize)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
while(nIndex < nLimit && dSize > dKiloBytes)
{
dSize /= dKiloBytes;
nIndex++;
}
dwError = TDNFAllocateMemory(1, nMaxSize, (void**)&pszFormattedSize);
BAIL_ON_TDNF_ERROR(dwError);
if(sprintf(pszFormattedSize, "%.2f %c", dSize, pszSizes[nIndex]) < 0)
{
dwError = ERROR_TDNF_OUT_OF_MEMORY;
BAIL_ON_TDNF_ERROR(dwError);
}
*ppszFormattedSize = pszFormattedSize;
cleanup:
return dwError;
error:
if(ppszFormattedSize)
{
*ppszFormattedSize = NULL;
}
TDNF_SAFE_FREE_MEMORY(pszFormattedSize);
goto cleanup;
}
uint32_t
TDNFGetErrorString(
uint32_t dwErrorCode,

View File

@ -56,4 +56,11 @@
} \
} while(0)
#define TDNF_SAFE_FREE_PKGINFO(pPkgInfo) \
do { \
if (pPkgInfo) { \
TDNFFreePackageInfo(pPkgInfo); \
} \
} while(0)
#define TDNF_DEFAULT_MAX_STRING_LEN 16384000

View File

@ -14,6 +14,7 @@
#include <string.h>
#include <errno.h>
#include <tdnftypes.h>
#include <tdnferror.h>
#include "defines.h"

View File

@ -125,3 +125,14 @@ TDNFRightTrim(
const char *pszStart,
const char *pszEnd
);
uint32_t
TDNFUtilsFormatSize(
uint32_t unSize,
char** ppszFormattedSize
);
void
TDNFFreePackageInfoContents(
PTDNF_PKG_INFO pPkgInfo
);

View File

@ -80,3 +80,271 @@ TDNFRightTrim(
while(pszEnd > pszStart && isspace(*pszEnd)) pszEnd--;
return pszEnd;
}
uint32_t
TDNFUtilsFormatSize(
uint32_t unSize,
char** ppszFormattedSize
)
{
uint32_t dwError = 0;
char* pszFormattedSize = NULL;
char* pszSizes = "bkMG";
double dSize = unSize;
int nIndex = 0;
int nLimit = strlen(pszSizes);
double dKiloBytes = 1024.0;
int nMaxSize = 25;
if(!ppszFormattedSize)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
while(nIndex < nLimit && dSize > dKiloBytes)
{
dSize /= dKiloBytes;
nIndex++;
}
dwError = TDNFAllocateMemory(1, nMaxSize, (void**)&pszFormattedSize);
BAIL_ON_TDNF_ERROR(dwError);
if(sprintf(pszFormattedSize, "%.2f %c", dSize, pszSizes[nIndex]) < 0)
{
dwError = ERROR_TDNF_OUT_OF_MEMORY;
BAIL_ON_TDNF_ERROR(dwError);
}
*ppszFormattedSize = pszFormattedSize;
cleanup:
return dwError;
error:
if(ppszFormattedSize)
{
*ppszFormattedSize = NULL;
}
TDNF_SAFE_FREE_MEMORY(pszFormattedSize);
goto cleanup;
}
void
TDNFFreePackageInfo(
PTDNF_PKG_INFO pPkgInfo
)
{
while(pPkgInfo)
{
PTDNF_PKG_INFO pPkgInfoTemp = pPkgInfo;
pPkgInfo = pPkgInfo->pNext;
TDNFFreePackageInfoContents(pPkgInfoTemp);
TDNFFreeMemory(pPkgInfoTemp);
}
}
void
TDNFFreePackageInfoArray(
PTDNF_PKG_INFO pPkgInfoArray,
uint32_t unLength
)
{
uint32_t unIndex = 0;
if(pPkgInfoArray && unLength > 0)
{
for(unIndex = 0; unIndex < unLength; ++unIndex)
{
TDNFFreePackageInfoContents(&pPkgInfoArray[unIndex]);
}
}
TDNF_SAFE_FREE_MEMORY(pPkgInfoArray);
}
void
TDNFFreePackageInfoContents(
PTDNF_PKG_INFO pPkgInfo
)
{
if(pPkgInfo)
{
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszName);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszRepoName);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszVersion);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszArch);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszSummary);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszURL);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszLicense);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszDescription);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszFormattedSize);
TDNF_SAFE_FREE_MEMORY(pPkgInfo->pszRelease);
}
}
void
TDNFFreeSolvedPackageInfo(
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo
)
{
int i = 0;
if(pSolvedPkgInfo)
{
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsNotAvailable);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsExisting);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsToInstall);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsToUpgrade);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsToDowngrade);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsToRemove);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsUnNeeded);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsToReinstall);
TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsObsoleted);
if(pSolvedPkgInfo->ppszPkgsNotResolved)
{
while(pSolvedPkgInfo->ppszPkgsNotResolved[i])
{
TDNF_SAFE_FREE_MEMORY(pSolvedPkgInfo->ppszPkgsNotResolved[i++]);
}
}
TDNF_SAFE_FREE_MEMORY(pSolvedPkgInfo->ppszPkgsNotResolved);
}
TDNF_SAFE_FREE_MEMORY(pSolvedPkgInfo);
}
void
TDNFFreeUpdateInfoSummary(
PTDNF_UPDATEINFO_SUMMARY pSummary
)
{
if(pSummary)
{
TDNFFreeMemory(pSummary);
}
}
void
TDNFFreeUpdateInfoReferences(
PTDNF_UPDATEINFO_REF pRef
)
{
if(pRef)
{
TDNF_SAFE_FREE_MEMORY(pRef->pszID);
TDNF_SAFE_FREE_MEMORY(pRef->pszLink);
TDNF_SAFE_FREE_MEMORY(pRef->pszTitle);
TDNF_SAFE_FREE_MEMORY(pRef->pszType);
}
}
void
TDNFFreeUpdateInfoPackages(
PTDNF_UPDATEINFO_PKG pPkgs
)
{
PTDNF_UPDATEINFO_PKG pTemp = NULL;
while(pPkgs)
{
TDNF_SAFE_FREE_MEMORY(pPkgs->pszName);
TDNF_SAFE_FREE_MEMORY(pPkgs->pszFileName);
TDNF_SAFE_FREE_MEMORY(pPkgs->pszEVR);
TDNF_SAFE_FREE_MEMORY(pPkgs->pszArch);
pTemp = pPkgs;
pPkgs = pPkgs->pNext;
TDNF_SAFE_FREE_MEMORY(pTemp);
}
}
void
TDNFFreeUpdateInfo(
PTDNF_UPDATEINFO pUpdateInfo
)
{
if(pUpdateInfo)
{
TDNF_SAFE_FREE_MEMORY(pUpdateInfo->pszID);
TDNF_SAFE_FREE_MEMORY(pUpdateInfo->pszDate);
TDNF_SAFE_FREE_MEMORY(pUpdateInfo->pszDescription);
TDNFFreeUpdateInfoReferences(pUpdateInfo->pReferences);
TDNFFreeUpdateInfoPackages(pUpdateInfo->pPackages);
TDNF_SAFE_FREE_MEMORY(pUpdateInfo);
}
}
void
TDNFFreeCmdOpt(
PTDNF_CMD_OPT pCmdOpt
)
{
PTDNF_CMD_OPT pCmdOptTemp = NULL;
while(pCmdOpt)
{
TDNF_SAFE_FREE_MEMORY(pCmdOpt->pszOptName);
TDNF_SAFE_FREE_MEMORY(pCmdOpt->pszOptValue);
pCmdOptTemp = pCmdOpt->pNext;
TDNF_SAFE_FREE_MEMORY(pCmdOpt);
pCmdOpt = pCmdOptTemp;
}
}
void
TDNFFreeCmdArgs(
PTDNF_CMD_ARGS pCmdArgs
)
{
int nIndex = 0;
if(pCmdArgs)
{
for(nIndex = 0; nIndex < pCmdArgs->nCmdCount; ++nIndex)
{
TDNF_SAFE_FREE_MEMORY(pCmdArgs->ppszCmds[nIndex]);
}
TDNF_SAFE_FREE_MEMORY(pCmdArgs->ppszCmds);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszInstallRoot);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszConfFile);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszReleaseVer);
if(pCmdArgs->pSetOpt)
{
TDNFFreeCmdOpt(pCmdArgs->pSetOpt);
}
TDNF_SAFE_FREE_MEMORY(pCmdArgs);
}
}
void
TDNFFreeRepos(
PTDNF_REPO_DATA pRepos
)
{
PTDNF_REPO_DATA pRepo = NULL;
while(pRepos)
{
pRepo = pRepos;
TDNF_SAFE_FREE_MEMORY(pRepo->pszId);
TDNF_SAFE_FREE_MEMORY(pRepo->pszName);
TDNF_SAFE_FREE_MEMORY(pRepo->pszBaseUrl);
TDNF_SAFE_FREE_MEMORY(pRepo->pszMetaLink);
TDNF_SAFE_FREE_MEMORY(pRepo->pszUrlGPGKey);
pRepos = pRepo->pNext;
TDNF_SAFE_FREE_MEMORY(pRepo);
}
}
void
TDNFFreeCleanInfo(
PTDNF_CLEAN_INFO pCleanInfo
)
{
if(pCleanInfo)
{
TDNF_SAFE_FREE_STRINGARRAY(pCleanInfo->ppszReposUsed);
TDNFFreeMemory(pCleanInfo);
}
}

View File

@ -1,4 +1,4 @@
AC_INIT(tdnf, 1.1.0)
AC_INIT(tdnf, 1.2.0)
AC_MSG_NOTICE([tdnf configuration])
AC_CANONICAL_SYSTEM
@ -45,6 +45,7 @@ AC_CONFIG_FILES([Makefile
tests/Makefile
tools/Makefile
tools/cli/Makefile
tools/cli/lib/Makefile
])
#tdnf conf dir

View File

@ -1,19 +1,19 @@
/*
* Copyright (C) 2014-2015 VMware, Inc. All rights reserved.
* Copyright (C) 2014-2017 VMware, Inc. All rights reserved.
*
* Header : tdnfclient.h
* Header : tdnf.h
*
* Abstract :
*
* tdnfclientlib
* libtdnf
*
* public header
*
* Authors : Priyesh Padmavilasom (ppadmavilasom@vmware.com)
*
*/
#ifndef _TDNF_CLIENT_H_
#define _TDNF_CLIENT_H_
#ifndef _TDNF_H_
#define _TDNF_H_
#ifdef __cplusplus
extern "C" {
@ -183,14 +183,6 @@ TDNFGetErrorString(
char** ppszErrorString
);
//Format package size to suffix with
//K, M, G for Kilo, Mega, Giga bytes
uint32_t
TDNFUtilsFormatSize(
uint32_t dwSize,
char** ppszFormattedSize
);
void
TDNFCloseHandle(
PTDNF pTdnf
@ -252,4 +244,4 @@ TDNFUninit(
}
#endif
#endif//TDNF_CLIENT_H_
#endif//TDNF_H_

307
include/tdnfcli.h Normal file
View File

@ -0,0 +1,307 @@
/*
* Copyright (C) 2017 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
* of the License are located in the COPYING file of this distribution.
*/
#ifndef _TDNF_CLI_H_
#define _TDNF_CLI_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "tdnfclitypes.h"
#include "tdnfclierror.h"
//api.c
uint32_t
TDNFCliParseArgs(
int argc,
char* const* argv,
PTDNF_CMD_ARGS* ppCmdArgs
);
uint32_t
TDNFCliParseScope(
const char* pszScope,
TDNF_SCOPE* pnScope
);
uint32_t
TDNFCliParseListArgs(
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_LIST_ARGS* ppListArgs
);
uint32_t
TDNFCliParseInfoArgs(
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_LIST_ARGS* ppListArgs
);
void
TDNFCliFreeListArgs(
PTDNF_LIST_ARGS pListArgs
);
uint32_t
TDNFCliParseCleanType(
const char* pszCleanType,
TDNF_CLEANTYPE* pnCleanType
);
uint32_t
TDNFCliParseCleanArgs(
PTDNF_CMD_ARGS pCmdArgs,
TDNF_CLEANTYPE* pnCleanType
);
uint32_t
TDNFCliParseFilter(
const char* pszRepolistFilter,
TDNF_REPOLISTFILTER* pnFilter
);
uint32_t
TDNFCliParseRepoListArgs(
PTDNF_CMD_ARGS pCmdArgs,
TDNF_REPOLISTFILTER* pnFilter
);
uint32_t
TDNFCliParseMode(
const char* pszOutMode,
TDNF_UPDATEINFO_OUTPUT* pnOutMode
);
uint32_t
TDNFCliParseUpdateInfoArgs(
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_UPDATEINFO_ARGS* ppUpdateInfoArgs
);
uint32_t
TDNFCliParsePackageArgs(
PTDNF_CMD_ARGS pCmdArgs,
char*** pppszPackageArgs,
int* pnPackageCount
);
uint32_t
TDNFCliPrintError(
uint32_t dwErrorCode
);
uint32_t
TDNFCliGetErrorString(
uint32_t dwErrorCode,
char** ppszError
);
void
TDNFCliFreeUpdateInfoArgs(
PTDNF_UPDATEINFO_ARGS pUpdateInfoArgs
);
void
TDNFCliFreeSolvedPackageInfo(
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo
);
//Commands
uint32_t
TDNFCliAutoEraseCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliCleanCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliCountCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliListCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliInfoCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliSearchCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliRepoListCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliCheckLocalCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliCheckUpdateCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliMakeCacheCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliProvidesCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliUpdateInfoCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliHelpCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
//installcmd.c
uint32_t
TDNFCliDowngradeCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliEraseCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliInstallCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliReinstallCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliDistroSyncCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliUpgradeCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliAlterCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs,
TDNF_ALTERTYPE nType
);
uint32_t
PrintSolvedInfo(
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo
);
uint32_t
PrintNotAvailable(
char** ppszPkgsNotAvailable
);
uint32_t
PrintExistingPackagesSkipped(
PTDNF_PKG_INFO pPkgInfos
);
uint32_t
PrintNotAvailablePackages(
PTDNF_PKG_INFO pPkgInfos
);
uint32_t
PrintAction(
PTDNF_PKG_INFO pPkgInfos,
TDNF_ALTERTYPE nAlterType
);
//updateinfocmd.c
//output.c
void
ShowConsoleProps(
);
uint32_t
GetConsoleWidth(
int* pnWidth
);
int
CalculateColumnWidth(
int nTotalWidth,
int nRequestedPercent,
int nMinVal
);
uint32_t
GetColumnWidths(
int nCount,
int* pnColPercents,
int* pnColWidths
);
void
TDNFCliShowUsage(
);
void
TDNFCliShowHelp(
);
void
TDNFCliShowNoSuchCommand(
const char* pszCmd
);
#ifdef __cplusplus
}
#endif
#endif//TDNF_H_

20
include/tdnfclierror.h Normal file
View File

@ -0,0 +1,20 @@
/*
* Copyright (C) 2017 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
* of the License are located in the COPYING file of this distribution.
*/
#define ERROR_TDNF_CLI_BASE 900
#define ERROR_TDNF_CLI_NO_MATCH (ERROR_TDNF_CLI_BASE + 1)
#define ERROR_TDNF_CLI_INVALID_ARGUMENT (ERROR_TDNF_CLI_BASE + 2)
#define ERROR_TDNF_CLI_CLEAN_REQUIRES_OPTION (ERROR_TDNF_CLI_BASE + 3)
#define ERROR_TDNF_CLI_NOT_ENOUGH_ARGS (ERROR_TDNF_CLI_BASE + 4)
#define ERROR_TDNF_CLI_NOTHING_TO_DO (ERROR_TDNF_CLI_BASE + 5)
#define ERROR_TDNF_CLI_CHECKLOCAL_EXPECT_DIR (ERROR_TDNF_CLI_BASE + 6)
#define ERROR_TDNF_CLI_PROVIDES_EXPECT_ARG (ERROR_TDNF_CLI_BASE + 7)
#define ERROR_TDNF_CLI_OPTION_NAME_INVALID (ERROR_TDNF_CLI_BASE + 8)
#define ERROR_TDNF_CLI_OPTION_ARG_REQUIRED (ERROR_TDNF_CLI_BASE + 9)
#define ERROR_TDNF_CLI_OPTION_ARG_UNEXPECTED (ERROR_TDNF_CLI_BASE + 10)
#define ERROR_TDNF_CLI_SETOPT_NO_EQUALS (ERROR_TDNF_CLI_BASE + 11)

156
include/tdnfclitypes.h Normal file
View File

@ -0,0 +1,156 @@
/*
* Copyright (C) 2017 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
* of the License are located in the COPYING file of this distribution.
*/
#ifndef _TDNF_CLI_TYPES_H_
#define _TDNF_CLI_TYPES_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "tdnftypes.h"
typedef void * HTDNF;
typedef struct _TDNF_CLI_CONTEXT_ *PTDNF_CLI_CONTEXT;
typedef uint32_t (*PFN_CMD)(PTDNF_CLI_CONTEXT, PTDNF_CMD_ARGS);
//Map command name to client function
typedef struct _TDNF_CLI_CMD_MAP
{
char* pszCmdName;
PFN_CMD pFnCmd;
}TDNF_CLI_CMD_MAP, *PTDNF_CLI_CMD_MAP;
typedef struct _TDNF_LIST_ARGS
{
TDNF_SCOPE nScope;
char** ppszPackageNameSpecs;
}TDNF_LIST_ARGS, *PTDNF_LIST_ARGS;
typedef struct _TDNF_UPDATEINFO_ARGS
{
TDNF_UPDATEINFO_OUTPUT nMode;
TDNF_SCOPE nScope;
TDNF_UPDATEINFO_TYPE nType;
char** ppszPackageNameSpecs;
}TDNF_UPDATEINFO_ARGS, *PTDNF_UPDATEINFO_ARGS;
typedef uint32_t
(*PFN_TDNF_ALTER)(
PTDNF_CLI_CONTEXT,
TDNF_ALTERTYPE,
PTDNF_SOLVED_PKG_INFO);
typedef uint32_t
(*PFN_TDNF_CHECK_LOCAL)(
PTDNF_CLI_CONTEXT,
const char *);
typedef uint32_t
(*PFN_TDNF_CHECK_UPDATE)(
PTDNF_CLI_CONTEXT,
char **,
PTDNF_PKG_INFO *,
uint32_t *
);
typedef uint32_t
(*PFN_TDNF_CLEAN)(
PTDNF_CLI_CONTEXT,
TDNF_CLEANTYPE,
PTDNF_CLEAN_INFO *
);
typedef uint32_t
(*PFN_TDNF_COUNT)(
PTDNF_CLI_CONTEXT,
uint32_t *);
typedef uint32_t
(*PFN_TDNF_INFO)(
PTDNF_CLI_CONTEXT,
PTDNF_LIST_ARGS,
PTDNF_PKG_INFO *,
uint32_t *
);
typedef uint32_t
(*PFN_TDNF_LIST)(
PTDNF_CLI_CONTEXT,
PTDNF_LIST_ARGS,
PTDNF_PKG_INFO *,
uint32_t *
);
typedef uint32_t
(*PFN_TDNF_PROVIDES)(
PTDNF_CLI_CONTEXT,
const char *,
PTDNF_PKG_INFO *
);
typedef uint32_t
(*PFN_TDNF_REPOLIST)(
PTDNF_CLI_CONTEXT,
TDNF_REPOLISTFILTER,
PTDNF_REPO_DATA *
);
typedef uint32_t
(*PFN_TDNF_RESOLVE)(
PTDNF_CLI_CONTEXT,
TDNF_ALTERTYPE,
PTDNF_SOLVED_PKG_INFO *);
typedef uint32_t
(*PFN_TDNF_SEARCH)(
PTDNF_CLI_CONTEXT,
PTDNF_CMD_ARGS,
PTDNF_PKG_INFO *,
uint32_t *);
typedef uint32_t
(*PFN_TDNF_UPDATEINFO)(
PTDNF_CLI_CONTEXT,
PTDNF_UPDATEINFO_ARGS,
PTDNF_UPDATEINFO *);
typedef uint32_t
(*PFN_TDNF_UPDATEINFO_SUMMARY)(
PTDNF_CLI_CONTEXT,
TDNF_AVAIL,
PTDNF_UPDATEINFO_ARGS,
PTDNF_UPDATEINFO_SUMMARY *);
typedef struct _TDNF_CLI_CONTEXT_
{
HTDNF hTdnf;
void *pUserData;
PFN_TDNF_ALTER pFnAlter;
PFN_TDNF_CHECK_LOCAL pFnCheckLocal;
PFN_TDNF_CHECK_UPDATE pFnCheckUpdate;
PFN_TDNF_CLEAN pFnClean;
PFN_TDNF_COUNT pFnCount;
PFN_TDNF_INFO pFnInfo;
PFN_TDNF_LIST pFnList;
PFN_TDNF_PROVIDES pFnProvides;
PFN_TDNF_REPOLIST pFnRepoList;
PFN_TDNF_RESOLVE pFnResolve;
PFN_TDNF_SEARCH pFnSearch;
PFN_TDNF_UPDATEINFO pFnUpdateInfo;
PFN_TDNF_UPDATEINFO_SUMMARY pFnUpdateInfoSummary;
}TDNF_CLI_CONTEXT, *PTDNF_CLI_CONTEXT;
#ifdef __cplusplus
}
#endif
#endif//TDNF_CLI_TYPES_H_

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2015 VMware, Inc. All rights reserved.
* Copyright (C) 2014-2017 VMware, Inc. All rights reserved.
*
* Header : tdnferror.h
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2015 VMware, Inc. All rights reserved.
* Copyright (C) 2014-2017 VMware, Inc. All rights reserved.
*
* Header : tdnftypes.h
*
@ -143,7 +143,6 @@ typedef enum
}TDNF_CMDOPT_TYPE;
typedef struct _TDNF_ *PTDNF;
typedef struct _HyRepo * HyRepo;
typedef struct _TDNF_PKG_INFO
{
@ -246,9 +245,6 @@ typedef struct _TDNF_REPO_DATA
char* pszBaseUrl;
char* pszMetaLink;
char* pszUrlGPGKey;
char* pszUser;
char* pszPass;
HyRepo hRepo;
struct _TDNF_REPO_DATA* pNext;
}TDNF_REPO_DATA, *PTDNF_REPO_DATA;

11
tdnf-cli-libs.pc.in Normal file
View File

@ -0,0 +1,11 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@/tdnf
Name: tdnf-cli-libs
Description: tdnf cli libs
Version: @VERSION@
Requires:
Libs: -L${libdir} -ltdnfcli
Cflags: -I${includedir}

View File

@ -7,5 +7,5 @@ Name: tdnf
Description: tiny dandified yum
Version: @VERSION@
Requires:hawkey rpm
Libs: -L${libdir} -ltdnfclient
Libs: -L${libdir} -ltdnf
Cflags: -I${includedir}

29
tests/repolist.at Normal file
View File

@ -0,0 +1,29 @@
#
# Copyright (C) 2017 VMware, Inc. All Rights Reserved.
#
# Licensed under the GNU Lesser General Public License v2.1 (the "License");
# you may not use this file except in compliance with the License. The terms
# of the License are located in the COPYING file of this distribution.
#
AT_BANNER(tdnf repolist tests)
# check tdnf repolist commands
AT_SETUP([repolist])
AT_KEYWORDS([repolist])
AT_CHECK([
TDNF_CHROOT_CLEAN
TDNF_CHROOT_INIT
TDNF_BUILD_INSTALL_RPMS
TDNF_CLI_W_CHROOT repolist
],
[0],
[ignore],
[ignore])
AT_CLEANUP
AT_SETUP([repolist all])
AT_KEYWORDS([repolist])
AT_CHECK([TDNF_CLI_W_CHROOT repolist all],\
[0], [ignore], [ignore])
AT_CLEANUP

View File

@ -7,6 +7,7 @@
#
m4_include([init.at])
m4_include([version.at])
m4_include([repolist.at])
m4_include([list.at])
m4_include([install.at])
m4_include([erase.at])

View File

@ -2,18 +2,12 @@ bin_PROGRAMS = tdnf
tdnf_CPPFLAGS = -I$(top_srcdir)/include
tdnf_SOURCES = \
help.c \
installcmd.c \
main.c \
options.c \
output.c \
parseargs.c \
parsecleanargs.c \
parselistargs.c \
parserepolistargs.c \
parseupdateinfo.c \
setopt.c \
updateinfocmd.c
main.c
SUBDIRS = \
lib
tdnf_LDADD = \
$(top_builddir)/common/libcommon.la \
$(top_builddir)/client/libtdnfclient.la
$(top_builddir)/client/libtdnf.la \
$(top_builddir)/tools/cli/lib/libtdnfcli.la

View File

@ -21,18 +21,6 @@
#pragma once
#define ERROR_TDNF_CLI_BASE 900
#define ERROR_TDNF_CLI_NO_MATCH (ERROR_TDNF_CLI_BASE + 1)
#define ERROR_TDNF_CLI_INVALID_ARGUMENT (ERROR_TDNF_CLI_BASE + 2)
#define ERROR_TDNF_CLI_CLEAN_REQUIRES_OPTION (ERROR_TDNF_CLI_BASE + 3)
#define ERROR_TDNF_CLI_NOT_ENOUGH_ARGS (ERROR_TDNF_CLI_BASE + 4)
#define ERROR_TDNF_CLI_NOTHING_TO_DO (ERROR_TDNF_CLI_BASE + 5)
#define ERROR_TDNF_CLI_CHECKLOCAL_EXPECT_DIR (ERROR_TDNF_CLI_BASE + 6)
#define ERROR_TDNF_CLI_PROVIDES_EXPECT_ARG (ERROR_TDNF_CLI_BASE + 7)
#define ERROR_TDNF_CLI_OPTION_NAME_INVALID (ERROR_TDNF_CLI_BASE + 8)
#define ERROR_TDNF_CLI_OPTION_ARG_REQUIRED (ERROR_TDNF_CLI_BASE + 9)
#define ERROR_TDNF_CLI_OPTION_ARG_UNEXPECTED (ERROR_TDNF_CLI_BASE + 10)
#define ERROR_TDNF_CLI_SETOPT_NO_EQUALS (ERROR_TDNF_CLI_BASE + 11)
#define ENABLEREPO "enablerepo"
#define DISABLEREPO "disablerepo"
@ -64,8 +52,6 @@
} \
while(0)
typedef uint32_t (*PFN_CMD)(PTDNF, PTDNF_CMD_ARGS);
#define TDNF_CLI_ERROR_TABLE \
{ \
{ERROR_TDNF_CLI_BASE, "ERROR_TDNF_CLI_BASE", "Generic base error."}, \

View File

@ -28,10 +28,10 @@
#include <unistd.h>
#include <string.h>
#include <tdnfclient.h>
#include <tdnf.h>
#include <tdnfcli.h>
#include "defines.h"
#include "structs.h"
#include "prototypes.h"
#include "../common/structs.h"
#include "../common/prototypes.h"

19
tools/cli/lib/Makefile.am Normal file
View File

@ -0,0 +1,19 @@
lib_LTLIBRARIES = libtdnfcli.la
libtdnfcli_la_CPPFLAGS = -I$(top_srcdir)/include
libtdnfcli_la_SOURCES = \
api.c \
help.c \
installcmd.c \
options.c \
output.c \
parseargs.c \
parsecleanargs.c \
parselistargs.c \
parserepolistargs.c \
parseupdateinfo.c \
setopt.c \
updateinfocmd.c
libtdnfcli_la_LIBADD = \
$(top_builddir)/common/libcommon.la

532
tools/cli/lib/api.c Normal file
View File

@ -0,0 +1,532 @@
/*
* Copyright (C) 2017 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
* of the License are located in the COPYING file of this distribution.
*/
#include "includes.h"
void
TDNFCliFreeSolvedPackageInfo(
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo
)
{
TDNFFreeSolvedPackageInfo(pSolvedPkgInfo);
}
uint32_t
TDNFCliGetErrorString(
uint32_t dwErrorCode,
char** ppszError
)
{
uint32_t dwError = 0;
char* pszError = NULL;
int i = 0;
int nCount = 0;
TDNF_ERROR_DESC arErrorDesc[] = TDNF_CLI_ERROR_TABLE;
nCount = sizeof(arErrorDesc)/sizeof(arErrorDesc[0]);
for(i = 0; i < nCount; i++)
{
if (dwErrorCode == arErrorDesc[i].nCode)
{
dwError = TDNFAllocateString(arErrorDesc[i].pszDesc, &pszError);
BAIL_ON_CLI_ERROR(dwError);
break;
}
}
*ppszError = pszError;
cleanup:
return dwError;
error:
TDNF_CLI_SAFE_FREE_MEMORY(pszError);
goto cleanup;
}
uint32_t
TDNFCliCleanCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
TDNF_CLEANTYPE nCleanType = CLEANTYPE_NONE;
PTDNF_CLEAN_INFO pTDNFCleanInfo = NULL;
char** ppszReposUsed = NULL;
if(!pContext || !pContext->hTdnf || !pContext->pFnClean)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = TDNFCliParseCleanArgs(pCmdArgs, &nCleanType);
BAIL_ON_CLI_ERROR(dwError);
dwError = pContext->pFnClean(pContext, nCleanType, &pTDNFCleanInfo);
BAIL_ON_CLI_ERROR(dwError);
//Print clean info
printf("Cleaning repos:");
ppszReposUsed = pTDNFCleanInfo->ppszReposUsed;
while(*ppszReposUsed)
{
printf(" %s", *ppszReposUsed);
++ppszReposUsed;
}
printf("\n");
if(pTDNFCleanInfo->nCleanAll)
{
printf("Cleaning up everything\n");
}
cleanup:
if(pTDNFCleanInfo)
{
TDNFFreeCleanInfo(pTDNFCleanInfo);
}
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliCountCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
uint32_t dwCount = 0;
if(!pContext || !pContext->hTdnf || !pContext->pFnCount)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = pContext->pFnCount(pContext, &dwCount);
BAIL_ON_CLI_ERROR(dwError);
printf("Package count = %d\n", dwCount);
cleanup:
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliListCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
PTDNF_PKG_INFO pPkgInfo = NULL;
PTDNF_PKG_INFO pPkg = NULL;
uint32_t dwCount = 0;
uint32_t dwIndex = 0;
PTDNF_LIST_ARGS pListArgs = NULL;
#define MAX_COL_LEN 256
char szNameAndArch[MAX_COL_LEN] = {0};
char szVersionAndRelease[MAX_COL_LEN] = {0};
#define COL_COUNT 3
//Name.Arch | Version-Release | Repo
int nColPercents[COL_COUNT] = {55, 25, 15};
int nColWidths[COL_COUNT] = {0};
if(!pContext || !pContext->hTdnf || !pContext->pFnList)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = TDNFCliParseListArgs(pCmdArgs, &pListArgs);
BAIL_ON_CLI_ERROR(dwError);
dwError = pContext->pFnList(pContext, pListArgs, &pPkgInfo, &dwCount);
BAIL_ON_CLI_ERROR(dwError);
dwError = GetColumnWidths(COL_COUNT, nColPercents, nColWidths);
BAIL_ON_CLI_ERROR(dwError);
for(dwIndex = 0; dwIndex < dwCount; ++dwIndex)
{
pPkg = &pPkgInfo[dwIndex];
memset(szNameAndArch, 0, MAX_COL_LEN);
if(snprintf(
szNameAndArch,
MAX_COL_LEN,
"%s.%s",
pPkg->pszName,
pPkg->pszArch) < 0)
{
dwError = errno;
BAIL_ON_CLI_ERROR(dwError);
}
memset(szVersionAndRelease, 0, MAX_COL_LEN);
if(snprintf(
szVersionAndRelease,
MAX_COL_LEN,
"%s-%s",
pPkg->pszVersion,
pPkg->pszRelease) < 0)
{
dwError = errno;
BAIL_ON_CLI_ERROR(dwError);
}
printf(
"%-*s%-*s%*s\n",
nColWidths[0],
szNameAndArch,
nColWidths[1],
szVersionAndRelease,
nColWidths[2],
pPkg->pszRepoName);
}
cleanup:
if(pListArgs)
{
TDNFCliFreeListArgs(pListArgs);
}
if(pPkgInfo)
{
TDNFFreePackageInfoArray(pPkgInfo, dwCount);
}
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliInfoCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
char* pszFormattedSize = NULL;
PTDNF_PKG_INFO pPkgInfo = NULL;
PTDNF_PKG_INFO pPkg = NULL;
PTDNF_LIST_ARGS pInfoArgs = NULL;
uint32_t dwCount = 0;
uint32_t dwIndex = 0;
uint32_t dwTotalSize = 0;
if(!pContext || !pContext->hTdnf || !pContext->pFnInfo)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = TDNFCliParseInfoArgs(pCmdArgs, &pInfoArgs);
BAIL_ON_CLI_ERROR(dwError);
dwError = pContext->pFnInfo(pContext, pInfoArgs, &pPkgInfo, &dwCount);
BAIL_ON_CLI_ERROR(dwError);
for(dwIndex = 0; dwIndex < dwCount; ++dwIndex)
{
pPkg = &pPkgInfo[dwIndex];
printf("Name : %s\n", pPkg->pszName);
printf("Arch : %s\n", pPkg->pszArch);
printf("Epoch : %d\n", pPkg->dwEpoch);
printf("Version : %s\n", pPkg->pszVersion);
printf("Release : %s\n", pPkg->pszRelease);
printf("Install Size : %s (%u)\n", pPkg->pszFormattedSize, pPkg->dwInstallSizeBytes);
printf("Repo : %s\n", pPkg->pszRepoName);
printf("Summary : %s\n", pPkg->pszSummary);
printf("URL : %s\n", pPkg->pszURL);
printf("License : %s\n", pPkg->pszLicense);
printf("Description : %s\n", pPkg->pszDescription);
printf("\n");
dwTotalSize += pPkg->dwInstallSizeBytes;
}
dwError = TDNFUtilsFormatSize(dwTotalSize, &pszFormattedSize);
BAIL_ON_CLI_ERROR(dwError);
printf("\nTotal Size: %s (%u)\n", pszFormattedSize, dwTotalSize);
cleanup:
if(pInfoArgs)
{
TDNFCliFreeListArgs(pInfoArgs);
}
if(pPkgInfo)
{
TDNFFreePackageInfoArray(pPkgInfo, dwCount);
}
TDNF_CLI_SAFE_FREE_MEMORY(pszFormattedSize);
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliRepoListCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
PTDNF_REPO_DATA pRepos = NULL;
PTDNF_REPO_DATA pReposTemp = NULL;
TDNF_REPOLISTFILTER nFilter = REPOLISTFILTER_ENABLED;
if(!pContext || !pContext->hTdnf || !pContext->pFnRepoList)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = TDNFCliParseRepoListArgs(pCmdArgs, &nFilter);
BAIL_ON_CLI_ERROR(dwError);
dwError = pContext->pFnRepoList(pContext, nFilter, &pRepos);
BAIL_ON_CLI_ERROR(dwError);
pReposTemp = pRepos;
if(pReposTemp)
{
printf("%-20s%-40s%-10s\n", "repo id", "repo name", "status");
}
while(pReposTemp)
{
printf(
"%-20s%-40s%-10s\n",
pReposTemp->pszId,
pReposTemp->pszName,
pReposTemp->nEnabled ? "enabled" : "disabled");
pReposTemp = pReposTemp->pNext;
}
cleanup:
TDNFFreeRepos(pRepos);
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliSearchCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
uint32_t dwCount = 0;
uint32_t dwIndex = 0;
PTDNF_PKG_INFO pPkgInfo = NULL;
PTDNF_PKG_INFO pPkg = NULL;
if(!pContext || !pContext->hTdnf || !pContext->pFnSearch)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = pContext->pFnSearch(pContext, pCmdArgs, &pPkgInfo, &dwCount);
BAIL_ON_CLI_ERROR(dwError);
for(dwIndex = 0; dwIndex < dwCount; ++dwIndex)
{
pPkg = &pPkgInfo[dwIndex];
printf("%s : %s\n", pPkg->pszName, pPkg->pszSummary);
}
cleanup:
TDNFFreePackageInfoArray(pPkgInfo, dwCount);
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliCheckLocalCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
if(!pContext || !pContext->hTdnf || !pCmdArgs || !pContext->pFnCheckLocal)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
if(pCmdArgs->nCmdCount < 2)
{
dwError = ERROR_TDNF_CLI_CHECKLOCAL_EXPECT_DIR;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = pContext->pFnCheckLocal(pContext, pCmdArgs->ppszCmds[1]);
BAIL_ON_CLI_ERROR(dwError);
fprintf(stdout, "Check completed without issues\n");
cleanup:
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliProvidesCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
PTDNF_PKG_INFO pPkgInfo = NULL;
PTDNF_PKG_INFO pPkgInfos = NULL;
if(!pContext || !pContext->hTdnf || !pCmdArgs || !pContext->pFnProvides)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
if(pCmdArgs->nCmdCount < 2)
{
dwError = ERROR_TDNF_CLI_PROVIDES_EXPECT_ARG;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = pContext->pFnProvides(pContext,
pCmdArgs->ppszCmds[1],
&pPkgInfos);
BAIL_ON_CLI_ERROR(dwError);
pPkgInfo = pPkgInfos;
while(pPkgInfo)
{
fprintf(
stdout,
"%s-%s-%s.%s : %s\n",
pPkgInfo->pszName,
pPkgInfo->pszVersion,
pPkgInfo->pszRelease,
pPkgInfo->pszArch,
pPkgInfo->pszSummary);
fprintf(stdout, "Repo\t : %s\n", pPkgInfo->pszRepoName);
pPkgInfo = pPkgInfo->pNext;
}
cleanup:
if(pPkgInfos)
{
TDNFFreePackageInfo(pPkgInfos);
}
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliCheckUpdateCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
PTDNF_PKG_INFO pPkgInfo = NULL;
PTDNF_PKG_INFO pPkg = NULL;
uint32_t dwCount = 0;
uint32_t dwIndex = 0;
char** ppszPackageArgs = NULL;
int nPackageCount = 0;
if(!pContext || !pContext->hTdnf || !pCmdArgs || !pContext->pFnCheckUpdate)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = TDNFCliParsePackageArgs(
pCmdArgs,
&ppszPackageArgs,
&nPackageCount);
BAIL_ON_CLI_ERROR(dwError);
dwError = pContext->pFnCheckUpdate(pContext,
ppszPackageArgs,
&pPkgInfo,
&dwCount);
BAIL_ON_CLI_ERROR(dwError);
for(dwIndex = 0; dwIndex < dwCount; ++dwIndex)
{
pPkg = &pPkgInfo[dwIndex];
printf("%*s\r", 80, pPkg->pszRepoName);
printf("%*s-%s\r", 50, pPkg->pszVersion, pPkg->pszRelease);
printf("%s.%s", pPkg->pszName, pPkg->pszArch);
printf("\n");
}
cleanup:
TDNF_CLI_SAFE_FREE_STRINGARRAY(ppszPackageArgs);
if(pPkgInfo)
{
TDNFFreePackageInfoArray(pPkgInfo, dwCount);
}
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliMakeCacheCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
if(!pContext || !pContext->hTdnf || !pCmdArgs)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
//Empty as refresh flag is set for makecache command
//and will execute refresh on all enabled repos
fprintf(stdout, "Metadata cache created.\n");
cleanup:
return dwError;
error:
goto cleanup;
}

View File

@ -86,9 +86,10 @@ TDNFCliShowNoSuchOption(
{
printf("No such option: %s. Please use /usr/bin/tdnf --help\n", pszOption);
}
uint32_t
TDNFCliHelpCommand(
PTDNF pTdnf,
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{

37
tools/cli/lib/includes.h Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright (C) 2017 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU General Public License v2 (the "License");
* you may not use this file except in compliance with the License. The terms
* of the License are located in the COPYING file of this distribution.
*/
/*
* Header : includes.h
*
* Abstract :
*
* tdnf
*
* command line tool
*
* Authors : Priyesh Padmavilasom (ppadmavilasom@vmware.com)
*
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>
#include <tdnf.h>
#include <tdnfcli.h>
#include "../defines.h"
#include "prototypes.h"
#include "../common/structs.h"
#include "../common/prototypes.h"

View File

@ -23,13 +23,13 @@
uint32_t
TDNFCliInstallCommand(
PTDNF pTdnf,
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
dwError = TDNFCliAlterCommand(pTdnf, pCmdArgs, ALTER_INSTALL);
dwError = TDNFCliAlterCommand(pContext, pCmdArgs, ALTER_INSTALL);
BAIL_ON_CLI_ERROR(dwError);
cleanup:
@ -41,13 +41,13 @@ error:
uint32_t
TDNFCliEraseCommand(
PTDNF pTdnf,
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
dwError = TDNFCliAlterCommand(pTdnf, pCmdArgs, ALTER_ERASE);
dwError = TDNFCliAlterCommand(pContext, pCmdArgs, ALTER_ERASE);
BAIL_ON_CLI_ERROR(dwError);
cleanup:
@ -59,7 +59,7 @@ error:
uint32_t
TDNFCliUpgradeCommand(
PTDNF pTdnf,
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
@ -71,7 +71,7 @@ TDNFCliUpgradeCommand(
nAlterType = ALTER_UPGRADEALL;
}
dwError = TDNFCliAlterCommand(pTdnf, pCmdArgs, nAlterType);
dwError = TDNFCliAlterCommand(pContext, pCmdArgs, nAlterType);
BAIL_ON_CLI_ERROR(dwError);
cleanup:
@ -83,13 +83,13 @@ error:
uint32_t
TDNFCliDistroSyncCommand(
PTDNF pTdnf,
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
dwError = TDNFCliAlterCommand(pTdnf, pCmdArgs, ALTER_DISTRO_SYNC);
dwError = TDNFCliAlterCommand(pContext, pCmdArgs, ALTER_DISTRO_SYNC);
BAIL_ON_CLI_ERROR(dwError);
cleanup:
@ -101,7 +101,7 @@ error:
uint32_t
TDNFCliDowngradeCommand(
PTDNF pTdnf,
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
@ -113,7 +113,7 @@ TDNFCliDowngradeCommand(
nAlterType = ALTER_DOWNGRADEALL;
}
dwError = TDNFCliAlterCommand(pTdnf, pCmdArgs, nAlterType);
dwError = TDNFCliAlterCommand(pContext, pCmdArgs, nAlterType);
BAIL_ON_CLI_ERROR(dwError);
cleanup:
@ -125,13 +125,13 @@ error:
uint32_t
TDNFCliAutoEraseCommand(
PTDNF pTdnf,
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
dwError = TDNFCliAlterCommand(pTdnf, pCmdArgs, ALTER_AUTOERASE);
dwError = TDNFCliAlterCommand(pContext, pCmdArgs, ALTER_AUTOERASE);
BAIL_ON_CLI_ERROR(dwError);
cleanup:
@ -143,13 +143,13 @@ error:
uint32_t
TDNFCliReinstallCommand(
PTDNF pTdnf,
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
dwError = TDNFCliAlterCommand(pTdnf, pCmdArgs, ALTER_REINSTALL);
dwError = TDNFCliAlterCommand(pContext, pCmdArgs, ALTER_REINSTALL);
BAIL_ON_CLI_ERROR(dwError);
cleanup:
@ -161,7 +161,7 @@ error:
uint32_t
TDNFCliAlterCommand(
PTDNF pTdnf,
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs,
TDNF_ALTERTYPE nAlterType
)
@ -173,7 +173,7 @@ TDNFCliAlterCommand(
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo = NULL;
int nSilent = 0;
if(!pTdnf || !pCmdArgs)
if(!pContext || !pContext->hTdnf || !pCmdArgs)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_CLI_ERROR(dwError);
@ -187,7 +187,10 @@ TDNFCliAlterCommand(
&nPackageCount);
BAIL_ON_CLI_ERROR(dwError);
dwError = TDNFResolve(pTdnf, nAlterType, &pSolvedPkgInfo);
dwError = pContext->pFnResolve(
pContext,
nAlterType,
&pSolvedPkgInfo);
BAIL_ON_CLI_ERROR(dwError);
if(!nSilent && pSolvedPkgInfo->ppszPkgsNotResolved)
@ -230,9 +233,14 @@ TDNFCliAlterCommand(
{
fprintf(stdout, "\nDownloading:\n");
}
dwError = TDNFAlterCommand(pTdnf, nAlterType, pSolvedPkgInfo);
dwError = pContext->pFnAlter(
pContext,
nAlterType,
pSolvedPkgInfo);
BAIL_ON_CLI_ERROR(dwError);
if(!nSilent)
{
fprintf(stdout, "\nComplete!\n");
@ -246,7 +254,7 @@ TDNFCliAlterCommand(
cleanup:
TDNF_CLI_SAFE_FREE_STRINGARRAY(ppszPackageArgs);
TDNFFreeSolvedPackageInfo(pSolvedPkgInfo);
TDNFCliFreeSolvedPackageInfo(pSolvedPkgInfo);
return dwError;
error:

View File

@ -235,69 +235,6 @@ error:
goto cleanup;
}
uint32_t
TDNFCliParseInfoArgs(
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_LIST_ARGS* ppListArgs
)
{
return TDNFCliParseListArgs(
pCmdArgs,
ppListArgs);
}
uint32_t
TDNFCliParsePackageArgs(
PTDNF_CMD_ARGS pCmdArgs,
char*** pppszPackageArgs,
int* pnPackageCount
)
{
uint32_t dwError = 0;
char** ppszPackageArgs = NULL;
int nPackageCount = 0;
int nIndex = 0;
if(!pCmdArgs || !pppszPackageArgs || !pnPackageCount)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_CLI_ERROR(dwError);
}
nPackageCount = pCmdArgs->nCmdCount - 1;
if(nPackageCount < 0)
{
dwError = ERROR_TDNF_CLI_NOT_ENOUGH_ARGS;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = TDNFAllocateMemory(
nPackageCount + 1,
sizeof(char*),
(void**)&ppszPackageArgs);
BAIL_ON_CLI_ERROR(dwError);
for(nIndex = 0; nIndex < nPackageCount; ++nIndex)
{
dwError = TDNFAllocateString(
pCmdArgs->ppszCmds[nIndex+1],
&ppszPackageArgs[nIndex]);
BAIL_ON_CLI_ERROR(dwError);
}
*pppszPackageArgs = ppszPackageArgs;
cleanup:
return dwError;
error:
if(pppszPackageArgs)
{
*pppszPackageArgs = NULL;
}
TDNF_CLI_SAFE_FREE_STRINGARRAY(ppszPackageArgs);
goto cleanup;
}
uint32_t
ParseOption(
const char* pszName,

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2017 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU General Public License v2 (the "License");
* you may not use this file except in compliance with the License. The terms
@ -44,7 +44,7 @@ TDNFCliParseCleanArgs(
//Should have type argument (tdnf clean <type>)
if(pCmdArgs->nCmdCount > 1)
{
dwError = ParseCleanType(pCmdArgs->ppszCmds[1], &nCleanType);
dwError = TDNFCliParseCleanType(pCmdArgs->ppszCmds[1], &nCleanType);
BAIL_ON_CLI_ERROR(dwError);
}
@ -62,7 +62,7 @@ error:
}
uint32_t
ParseCleanType(
TDNFCliParseCleanType(
const char* pszCleanType,
TDNF_CLEANTYPE* pnCleanType
)

View File

@ -21,6 +21,69 @@
#include "includes.h"
uint32_t
TDNFCliParseInfoArgs(
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_LIST_ARGS* ppListArgs
)
{
return TDNFCliParseListArgs(
pCmdArgs,
ppListArgs);
}
uint32_t
TDNFCliParsePackageArgs(
PTDNF_CMD_ARGS pCmdArgs,
char*** pppszPackageArgs,
int* pnPackageCount
)
{
uint32_t dwError = 0;
char** ppszPackageArgs = NULL;
int nPackageCount = 0;
int nIndex = 0;
if(!pCmdArgs || !pppszPackageArgs || !pnPackageCount)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_CLI_ERROR(dwError);
}
nPackageCount = pCmdArgs->nCmdCount - 1;
if(nPackageCount < 0)
{
dwError = ERROR_TDNF_CLI_NOT_ENOUGH_ARGS;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = TDNFAllocateMemory(
nPackageCount + 1,
sizeof(char*),
(void**)&ppszPackageArgs);
BAIL_ON_CLI_ERROR(dwError);
for(nIndex = 0; nIndex < nPackageCount; ++nIndex)
{
dwError = TDNFAllocateString(
pCmdArgs->ppszCmds[nIndex+1],
&ppszPackageArgs[nIndex]);
BAIL_ON_CLI_ERROR(dwError);
}
*pppszPackageArgs = ppszPackageArgs;
cleanup:
return dwError;
error:
if(pppszPackageArgs)
{
*pppszPackageArgs = NULL;
}
TDNF_CLI_SAFE_FREE_STRINGARRAY(ppszPackageArgs);
goto cleanup;
}
uint32_t
TDNFCliParseListArgs(
PTDNF_CMD_ARGS pCmdArgs,
@ -48,7 +111,7 @@ TDNFCliParseListArgs(
if(pCmdArgs->nCmdCount > 1)
{
nStartIndex = 2;
dwError = ParseScope(pCmdArgs->ppszCmds[1], &pListArgs->nScope);
dwError = TDNFCliParseScope(pCmdArgs->ppszCmds[1], &pListArgs->nScope);
if(dwError == ERROR_TDNF_CLI_NO_MATCH)
{
dwError = 0;
@ -84,13 +147,13 @@ error:
}
if(pListArgs)
{
TDNFFreeListArgs(pListArgs);
TDNFCliFreeListArgs(pListArgs);
}
goto cleanup;
}
uint32_t
ParseScope(
TDNFCliParseScope(
const char* pszScope,
TDNF_SCOPE* pnScope
)
@ -143,7 +206,7 @@ error:
}
void
TDNFFreeListArgs(
TDNFCliFreeListArgs(
PTDNF_LIST_ARGS pListArgs
)
{

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2017 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU General Public License v2 (the "License");
* you may not use this file except in compliance with the License. The terms
@ -40,7 +40,7 @@ TDNFCliParseRepoListArgs(
//assume REPOLISTFILTER_ENABLED if not specified.
if(pCmdArgs->nCmdCount > 1)
{
dwError = ParseFilter(pCmdArgs->ppszCmds[1], &nFilter);
dwError = TDNFCliParseFilter(pCmdArgs->ppszCmds[1], &nFilter);
BAIL_ON_CLI_ERROR(dwError);
}
@ -58,7 +58,7 @@ error:
}
uint32_t
ParseFilter(
TDNFCliParseFilter(
const char* pszFilter,
TDNF_REPOLISTFILTER* pnFilter
)

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2017 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU General Public License v2 (the "License");
* you may not use this file except in compliance with the License. The terms
@ -49,7 +49,7 @@ TDNFCliParseUpdateInfoArgs(
//(tdnf updateinfo <mode> <availability> <type> <pkgnamespecs>)
if(pCmdArgs->nCmdCount > nStartIndex)
{
dwError = ParseMode(
dwError = TDNFCliParseMode(
pCmdArgs->ppszCmds[nStartIndex],
&pUpdateInfoArgs->nMode);
if(dwError == ERROR_TDNF_CLI_NO_MATCH)
@ -65,7 +65,7 @@ TDNFCliParseUpdateInfoArgs(
//Next arg should be availability
if(pCmdArgs->nCmdCount > nStartIndex)
{
dwError = ParseScope(
dwError = TDNFCliParseScope(
pCmdArgs->ppszCmds[nStartIndex],
&pUpdateInfoArgs->nScope);
if(dwError == ERROR_TDNF_CLI_NO_MATCH)
@ -106,13 +106,13 @@ error:
}
if(pUpdateInfoArgs)
{
TDNFFreeUpdateInfoArgs(pUpdateInfoArgs);
TDNFCliFreeUpdateInfoArgs(pUpdateInfoArgs);
}
goto cleanup;
}
uint32_t
ParseMode(
TDNFCliParseMode(
const char* pszMode,
TDNF_UPDATEINFO_OUTPUT* pnMode
)
@ -166,7 +166,7 @@ error:
}
void
TDNFFreeUpdateInfoArgs(
TDNFCliFreeUpdateInfoArgs(
PTDNF_UPDATEINFO_ARGS pUpdateInfoArgs
)
{

127
tools/cli/lib/prototypes.h Normal file
View File

@ -0,0 +1,127 @@
/*
* Copyright (C) 2015-2017 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU General Public License v2 (the "License");
* you may not use this file except in compliance with the License. The terms
* of the License are located in the COPYING file of this distribution.
*/
/*
* Header : prototypes.h
*
* Abstract :
*
* tdnf
*
* command line tool
*
* Authors : Priyesh Padmavilasom (ppadmavilasom@vmware.com)
*
*/
#pragma once
//parseargs.c
uint32_t
TDNFCopyOptions(
PTDNF_CMD_ARGS pOptionArgs,
PTDNF_CMD_ARGS pArgs
);
uint32_t
ParseOption(
const char* pszName,
const char* pszArg,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
ParseRpmVerbosity(
const char* pszVerbosity,
int* pnVerbosity
);
uint32_t
HandleOptionsError(
const char* pszName,
const char* pszArg,
struct option* pstOptions
);
//updateinfocmd.c
char*
TDNFGetUpdateInfoType(
int nType
);
uint32_t
TDNFCliUpdateInfoList(
PTDNF_UPDATEINFO pUpdateInfo
);
uint32_t
TDNFCliUpdateInfoSummary(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_UPDATEINFO_ARGS pInfoArgs
);
uint32_t
TDNFCliUpdateInfoInfo(
PTDNF_UPDATEINFO pInfo
);
//help.c
void
TDNFCliShowNoSuchOption(
const char* pszOption
);
//options.c
uint32_t
_TDNFCliGetOptionByName(
const char* pszName,
struct option* pKnownOptions,
struct option** ppOption
);
uint32_t
TDNFCliValidateOptionName(
const char* pszOptionName,
struct option* pKnownOptions
);
uint32_t
TDNFCliValidateOptionArg(
const char* pszOption,
const char* pszArg,
struct option* pKnownOptions
);
uint32_t
TDNFCliValidateOptions(
const char* pszOption,
const char* pszArg,
struct option* pKnownOptions
);
//setopt.c
uint32_t
AddSetOpt(
PTDNF_CMD_ARGS pCmdArgs,
const char* pszOptArg
);
uint32_t
AddSetOptWithValues(
PTDNF_CMD_ARGS pCmdArgs,
int nType,
const char* pszOptArg,
const char* pszOptValue
);
uint32_t
GetOptionAndValue(
const char* pszOptArg,
PTDNF_CMD_OPT* ppCmdOpt
);

View File

@ -47,7 +47,7 @@ TDNFGetUpdateInfoType(
uint32_t
TDNFCliUpdateInfoCommand(
PTDNF pTdnf,
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
@ -61,17 +61,15 @@ TDNFCliUpdateInfoCommand(
if(pInfoArgs->nMode == OUTPUT_SUMMARY)
{
dwError = TDNFCliUpdateInfoSummary(pTdnf, pCmdArgs, pInfoArgs);
dwError = TDNFCliUpdateInfoSummary(pContext, pCmdArgs, pInfoArgs);
BAIL_ON_CLI_ERROR(dwError);
}
else
{
dwError = TDNFUpdateInfo(
pTdnf,
pInfoArgs->nMode,
pInfoArgs->nScope,
pInfoArgs->ppszPackageNameSpecs,
&pUpdateInfo);
dwError = pContext->pFnUpdateInfo(
pContext,
pInfoArgs,
&pUpdateInfo);
BAIL_ON_CLI_ERROR(dwError);
if(pInfoArgs->nMode == OUTPUT_LIST)
{
@ -87,7 +85,7 @@ TDNFCliUpdateInfoCommand(
cleanup:
if(pInfoArgs)
{
TDNFFreeUpdateInfoArgs(pInfoArgs);
TDNFCliFreeUpdateInfoArgs(pInfoArgs);
}
TDNFFreeUpdateInfo(pUpdateInfo);
return dwError;
@ -103,7 +101,7 @@ error:
uint32_t
TDNFCliUpdateInfoSummary(
PTDNF pTdnf,
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_UPDATEINFO_ARGS pInfoArgs
)
@ -112,16 +110,16 @@ TDNFCliUpdateInfoSummary(
int i = 0;
PTDNF_UPDATEINFO_SUMMARY pSummary = NULL;
if(!pTdnf || !pCmdArgs)
if(!pContext || !pCmdArgs)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = TDNFUpdateInfoSummary(
pTdnf,
dwError = pContext->pFnUpdateInfoSummary(
pContext,
AVAIL_AVAILABLE,
pInfoArgs->ppszPackageNameSpecs,
pInfoArgs,
&pSummary);
BAIL_ON_CLI_ERROR(dwError);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2017 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU General Public License v2 (the "License");
* you may not use this file except in compliance with the License. The terms
@ -21,6 +21,8 @@
#include "includes.h"
TDNF_CLI_CONTEXT _context = {0};
int main(int argc, char* argv[])
{
uint32_t dwError = 0;
@ -53,11 +55,28 @@ int main(int argc, char* argv[])
{"upgrade-to", TDNFCliUpgradeCommand},
{"updateinfo", TDNFCliUpdateInfoCommand},
};
int nCommandCount = sizeof(arCmdMap)/sizeof(TDNF_CLI_CMD_MAP);
const char* pszCmd = NULL;
PTDNF pTdnf = NULL;
int nFound = 0;
_context.pFnCheckLocal = TDNFCliInvokeCheckLocal;
_context.pFnCheckUpdate = TDNFCliInvokeCheckUpdate;
_context.pFnClean = TDNFCliInvokeClean;
_context.pFnCount = TDNFCliInvokeCount;
_context.pFnInfo = TDNFCliInvokeInfo;
_context.pFnList = TDNFCliInvokeList;
_context.pFnProvides = TDNFCliInvokeProvides;
_context.pFnRepoList = TDNFCliInvokeRepoList;
//Alter and resolve will address commands like
//install, upgrade, erase, downgrade, distrosync
_context.pFnAlter = TDNFCliInvokeAlter;
_context.pFnResolve = TDNFCliInvokeResolve;
_context.pFnSearch = TDNFCliInvokeSearch;
_context.pFnUpdateInfo = TDNFCliInvokeUpdateInfo;
_context.pFnUpdateInfoSummary = TDNFCliInvokeUpdateInfoSummary;
dwError = TDNFCliParseArgs(argc, argv, &pCmdArgs);
BAIL_ON_CLI_ERROR(dwError);
@ -91,13 +110,15 @@ int main(int argc, char* argv[])
dwError = TDNFOpenHandle(pCmdArgs, &pTdnf);
BAIL_ON_CLI_ERROR(dwError);
_context.hTdnf = pTdnf;
if(pCmdArgs->nVerbose)
{
dwError = TDNFCliVerboseShowEnv(pCmdArgs);
BAIL_ON_CLI_ERROR(dwError);
}
dwError = arCmdMap[nCommandCount].pFnCmd(pTdnf, pCmdArgs);
dwError = arCmdMap[nCommandCount].pFnCmd(&_context, pCmdArgs);
BAIL_ON_CLI_ERROR(dwError);
break;
}
@ -125,7 +146,7 @@ cleanup:
return dwError;
error:
PrintError(dwError);
TDNFCliPrintError(dwError);
if (dwError == ERROR_TDNF_CLI_NOTHING_TO_DO)
{
// Nothing to do should not return an error code
@ -135,463 +156,7 @@ error:
}
uint32_t
TDNFCliCleanCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
TDNF_CLEANTYPE nCleanType = CLEANTYPE_NONE;
PTDNF_CLEAN_INFO pTDNFCleanInfo = NULL;
char** ppszReposUsed = NULL;
dwError = TDNFCliParseCleanArgs(pCmdArgs, &nCleanType);
BAIL_ON_CLI_ERROR(dwError);
dwError = TDNFClean(pTdnf, nCleanType, &pTDNFCleanInfo);
BAIL_ON_CLI_ERROR(dwError);
//Print clean info
printf("Cleaning repos:");
ppszReposUsed = pTDNFCleanInfo->ppszReposUsed;
while(*ppszReposUsed)
{
printf(" %s", *ppszReposUsed);
++ppszReposUsed;
}
printf("\n");
if(pTDNFCleanInfo->nCleanAll)
{
printf("Cleaning up everything\n");
}
cleanup:
if(pTDNFCleanInfo)
{
TDNFFreeCleanInfo(pTDNFCleanInfo);
}
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliCountCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
uint32_t unCount = 0;
dwError = TDNFCountCommand(pTdnf, &unCount);
BAIL_ON_CLI_ERROR(dwError);
printf("Package count = %d\n", unCount);
cleanup:
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliListCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
PTDNF_PKG_INFO pPkgInfo = NULL;
PTDNF_PKG_INFO pPkg = NULL;
uint32_t unCount = 0;
uint32_t dwIndex = 0;
PTDNF_LIST_ARGS pListArgs = NULL;
#define MAX_COL_LEN 256
char szNameAndArch[MAX_COL_LEN] = {0};
char szVersionAndRelease[MAX_COL_LEN] = {0};
#define COL_COUNT 3
//Name.Arch | Version-Release | Repo
int nColPercents[COL_COUNT] = {55, 25, 15};
int nColWidths[COL_COUNT] = {0};
dwError = TDNFCliParseListArgs(pCmdArgs, &pListArgs);
BAIL_ON_CLI_ERROR(dwError);
dwError = TDNFList(
pTdnf,
pListArgs->nScope,
pListArgs->ppszPackageNameSpecs,
&pPkgInfo,
&unCount);
BAIL_ON_CLI_ERROR(dwError);
dwError = GetColumnWidths(COL_COUNT, nColPercents, nColWidths);
BAIL_ON_CLI_ERROR(dwError);
for(dwIndex = 0; dwIndex < unCount; ++dwIndex)
{
pPkg = &pPkgInfo[dwIndex];
memset(szNameAndArch, 0, MAX_COL_LEN);
if(snprintf(
szNameAndArch,
MAX_COL_LEN,
"%s.%s",
pPkg->pszName,
pPkg->pszArch) < 0)
{
dwError = errno;
BAIL_ON_CLI_ERROR(dwError);
}
memset(szVersionAndRelease, 0, MAX_COL_LEN);
if(snprintf(
szVersionAndRelease,
MAX_COL_LEN,
"%s-%s",
pPkg->pszVersion,
pPkg->pszRelease) < 0)
{
dwError = errno;
BAIL_ON_CLI_ERROR(dwError);
}
printf(
"%-*s%-*s%*s\n",
nColWidths[0],
szNameAndArch,
nColWidths[1],
szVersionAndRelease,
nColWidths[2],
pPkg->pszRepoName);
}
cleanup:
if(pListArgs)
{
TDNFFreeListArgs(pListArgs);
}
if(pPkgInfo)
{
TDNFFreePackageInfoArray(pPkgInfo, unCount);
}
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliInfoCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
char* pszFormattedSize = NULL;
PTDNF_PKG_INFO pPkgInfo = NULL;
PTDNF_PKG_INFO pPkg = NULL;
PTDNF_LIST_ARGS pInfoArgs = NULL;
uint32_t unCount = 0;
uint32_t dwIndex = 0;
uint32_t unTotalSize = 0;
dwError = TDNFCliParseInfoArgs(pCmdArgs, &pInfoArgs);
BAIL_ON_CLI_ERROR(dwError);
dwError = TDNFInfo(
pTdnf,
pInfoArgs->nScope,
pInfoArgs->ppszPackageNameSpecs,
&pPkgInfo,
&unCount);
BAIL_ON_CLI_ERROR(dwError);
for(dwIndex = 0; dwIndex < unCount; ++dwIndex)
{
pPkg = &pPkgInfo[dwIndex];
printf("Name : %s\n", pPkg->pszName);
printf("Arch : %s\n", pPkg->pszArch);
printf("Epoch : %d\n", pPkg->dwEpoch);
printf("Version : %s\n", pPkg->pszVersion);
printf("Release : %s\n", pPkg->pszRelease);
printf("Install Size : %s (%u)\n", pPkg->pszFormattedSize, pPkg->dwInstallSizeBytes);
printf("Repo : %s\n", pPkg->pszRepoName);
printf("Summary : %s\n", pPkg->pszSummary);
printf("URL : %s\n", pPkg->pszURL);
printf("License : %s\n", pPkg->pszLicense);
printf("Description : %s\n", pPkg->pszDescription);
printf("\n");
unTotalSize += pPkg->dwInstallSizeBytes;
}
dwError = TDNFUtilsFormatSize(unTotalSize, &pszFormattedSize);
BAIL_ON_CLI_ERROR(dwError);
printf("\nTotal Size: %s (%u)\n", pszFormattedSize, unTotalSize);
cleanup:
if(pInfoArgs)
{
TDNFFreeListArgs(pInfoArgs);
}
if(pPkgInfo)
{
TDNFFreePackageInfoArray(pPkgInfo, unCount);
}
TDNF_CLI_SAFE_FREE_MEMORY(pszFormattedSize);
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliRepoListCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
PTDNF_REPO_DATA pRepos = NULL;
PTDNF_REPO_DATA pReposTemp = NULL;
TDNF_REPOLISTFILTER nFilter = REPOLISTFILTER_ENABLED;
dwError = TDNFCliParseRepoListArgs(pCmdArgs, &nFilter);
BAIL_ON_CLI_ERROR(dwError);
dwError = TDNFRepoList(pTdnf, nFilter, &pRepos);
BAIL_ON_CLI_ERROR(dwError);
pReposTemp = pRepos;
if(pReposTemp)
{
printf("%-20s%-40s%-10s\n", "repo id", "repo name", "status");
}
while(pReposTemp)
{
printf(
"%-20s%-40s%-10s\n",
pReposTemp->pszId,
pReposTemp->pszName,
pReposTemp->nEnabled ? "enabled" : "disabled");
pReposTemp = pReposTemp->pNext;
}
cleanup:
TDNFFreeRepos(pRepos);
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliSearchCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t unError = 0;
PTDNF_PKG_INFO pPkgInfo = NULL;
PTDNF_PKG_INFO pPkg = NULL;
uint32_t unCount = 0;
uint32_t unIndex = 0;
unError = TDNFSearchCommand(pTdnf, pCmdArgs, &pPkgInfo, &unCount);
BAIL_ON_CLI_ERROR(unError);
for(unIndex = 0; unIndex < unCount; ++unIndex)
{
pPkg = &pPkgInfo[unIndex];
printf("%s : %s\n", pPkg->pszName, pPkg->pszSummary);
}
cleanup:
TDNFFreePackageInfoArray(pPkgInfo, unCount);
return unError;
error:
goto cleanup;
}
uint32_t
TDNFCliCheckLocalCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
if(!pTdnf || !pCmdArgs)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
if(pCmdArgs->nCmdCount < 2)
{
dwError = ERROR_TDNF_CLI_CHECKLOCAL_EXPECT_DIR;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = TDNFCheckLocalPackages(pTdnf, pCmdArgs->ppszCmds[1]);
BAIL_ON_CLI_ERROR(dwError);
fprintf(stdout, "Check completed without issues\n");
cleanup:
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliProvidesCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
PTDNF_PKG_INFO pPkgInfo = NULL;
PTDNF_PKG_INFO pPkgInfos = NULL;
if(!pTdnf || !pCmdArgs)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
if(pCmdArgs->nCmdCount < 2)
{
dwError = ERROR_TDNF_CLI_PROVIDES_EXPECT_ARG;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = TDNFProvides(pTdnf, pCmdArgs->ppszCmds[1], &pPkgInfos);
BAIL_ON_CLI_ERROR(dwError);
pPkgInfo = pPkgInfos;
while(pPkgInfo)
{
fprintf(
stdout,
"%s-%s-%s.%s : %s\n",
pPkgInfo->pszName,
pPkgInfo->pszVersion,
pPkgInfo->pszRelease,
pPkgInfo->pszArch,
pPkgInfo->pszSummary);
fprintf(stdout, "Repo\t : %s\n", pPkgInfo->pszRepoName);
pPkgInfo = pPkgInfo->pNext;
}
cleanup:
if(pPkgInfos)
{
TDNFFreePackageInfo(pPkgInfos);
}
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliCheckUpdateCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
PTDNF_PKG_INFO pPkgInfo = NULL;
PTDNF_PKG_INFO pPkg = NULL;
uint32_t unCount = 0;
uint32_t dwIndex = 0;
char** ppszPackageArgs = NULL;
int nPackageCount = 0;
if(!pTdnf || !pCmdArgs)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
dwError = TDNFCliParsePackageArgs(
pCmdArgs,
&ppszPackageArgs,
&nPackageCount);
BAIL_ON_CLI_ERROR(dwError);
dwError = TDNFCheckUpdates(
pTdnf,
ppszPackageArgs,
&pPkgInfo,
&unCount);
BAIL_ON_CLI_ERROR(dwError);
for(dwIndex = 0; dwIndex < unCount; ++dwIndex)
{
pPkg = &pPkgInfo[dwIndex];
printf("%*s\r", 80, pPkg->pszRepoName);
printf("%*s-%s\r", 50, pPkg->pszVersion, pPkg->pszRelease);
printf("%s.%s", pPkg->pszName, pPkg->pszArch);
printf("\n");
}
cleanup:
TDNF_CLI_SAFE_FREE_STRINGARRAY(ppszPackageArgs);
if(pPkgInfo)
{
TDNFFreePackageInfoArray(pPkgInfo, unCount);
}
return dwError;
error:
goto cleanup;
}
uint32_t
TDNFCliMakeCacheCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;
if(!pTdnf || !pCmdArgs)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}
//Empty as refresh flag is set for makecache command
//and will execute refresh on all enabled repos
fprintf(stdout, "Metadata cache created.\n");
cleanup:
return dwError;
error:
goto cleanup;
}
uint32_t
PrintError(
TDNFCliPrintError(
uint32_t dwErrorCode
)
{
@ -614,11 +179,11 @@ PrintError(
}
if(dwErrorCode)
{
printf("Error(%d) : %s\n", dwErrorCode, pszError);
fprintf(stderr, "Error(%d) : %s\n", dwErrorCode, pszError);
}
else
{
printf("%s\n", pszError);
fprintf(stderr, "%s\n", pszError);
}
cleanup:
@ -626,45 +191,14 @@ cleanup:
return dwError;
error:
printf(
fprintf(
stderr,
"Retrieving error string for %d failed with %d\n",
dwErrorCode,
dwError);
goto cleanup;
}
uint32_t
TDNFCliGetErrorString(
uint32_t dwErrorCode,
char** ppszError
)
{
uint32_t dwError = 0;
char* pszError = NULL;
int i = 0;
int nCount = 0;
TDNF_ERROR_DESC arErrorDesc[] = TDNF_CLI_ERROR_TABLE;
nCount = sizeof(arErrorDesc)/sizeof(arErrorDesc[0]);
for(i = 0; i < nCount; i++)
{
if (dwErrorCode == arErrorDesc[i].nCode)
{
dwError = TDNFAllocateString(arErrorDesc[i].pszDesc, &pszError);
BAIL_ON_CLI_ERROR(dwError);
break;
}
}
*ppszError = pszError;
cleanup:
return dwError;
error:
TDNF_CLI_SAFE_FREE_MEMORY(pszError);
goto cleanup;
}
void
TDNFCliShowVersion(
)
@ -703,3 +237,156 @@ cleanup:
error:
goto cleanup;
}
uint32_t
TDNFCliInvokeCheckLocal(
PTDNF_CLI_CONTEXT pContext,
const char *pszFolder
)
{
return TDNFCheckLocalPackages(pContext->hTdnf, pszFolder);
}
uint32_t
TDNFCliInvokeCheckUpdate(
PTDNF_CLI_CONTEXT pContext,
char** ppszPackageArgs,
PTDNF_PKG_INFO *ppPkgInfo,
uint32_t *pdwCount
)
{
return TDNFCheckUpdates(pContext->hTdnf,
ppszPackageArgs,
ppPkgInfo,
pdwCount);
}
uint32_t
TDNFCliInvokeClean(
PTDNF_CLI_CONTEXT pContext,
TDNF_CLEANTYPE nCleanType,
PTDNF_CLEAN_INFO *ppTDNFCleanInfo
)
{
return TDNFClean(pContext->hTdnf, nCleanType, ppTDNFCleanInfo);
}
uint32_t
TDNFCliInvokeCount(
PTDNF_CLI_CONTEXT pContext,
uint32_t *pnCount
)
{
return TDNFCountCommand(pContext->hTdnf, pnCount);
}
uint32_t
TDNFCliInvokeAlter(
PTDNF_CLI_CONTEXT pContext,
TDNF_ALTERTYPE nAlterType,
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo
)
{
return TDNFAlterCommand(pContext->hTdnf, nAlterType, pSolvedPkgInfo);
}
uint32_t
TDNFCliInvokeInfo(
PTDNF_CLI_CONTEXT pContext,
PTDNF_LIST_ARGS pInfoArgs,
PTDNF_PKG_INFO *ppPkgInfo,
uint32_t *pdwCount
)
{
return TDNFInfo(pContext->hTdnf,
pInfoArgs->nScope,
pInfoArgs->ppszPackageNameSpecs,
ppPkgInfo,
pdwCount);
}
uint32_t
TDNFCliInvokeList(
PTDNF_CLI_CONTEXT pContext,
PTDNF_LIST_ARGS pListArgs,
PTDNF_PKG_INFO *ppPkgInfo,
uint32_t *pdwCount
)
{
return TDNFList(pContext->hTdnf,
pListArgs->nScope,
pListArgs->ppszPackageNameSpecs,
ppPkgInfo,
pdwCount);
}
uint32_t
TDNFCliInvokeProvides(
PTDNF_CLI_CONTEXT pContext,
const char *pszProvides,
PTDNF_PKG_INFO *ppPkgInfos
)
{
return TDNFProvides(pContext->hTdnf, pszProvides, ppPkgInfos);
}
uint32_t
TDNFCliInvokeRepoList(
PTDNF_CLI_CONTEXT pContext,
TDNF_REPOLISTFILTER nFilter,
PTDNF_REPO_DATA *ppRepos
)
{
return TDNFRepoList(pContext->hTdnf, nFilter, ppRepos);
}
uint32_t
TDNFCliInvokeResolve(
PTDNF_CLI_CONTEXT pContext,
TDNF_ALTERTYPE nAlterType,
PTDNF_SOLVED_PKG_INFO *ppSolvedPkgInfo
)
{
return TDNFResolve(pContext->hTdnf, nAlterType, ppSolvedPkgInfo);
}
uint32_t
TDNFCliInvokeSearch(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_PKG_INFO *ppPkgInfo,
uint32_t *pdwCount
)
{
return TDNFSearchCommand(pContext->hTdnf, pCmdArgs, ppPkgInfo, pdwCount);
}
uint32_t
TDNFCliInvokeUpdateInfo(
PTDNF_CLI_CONTEXT pContext,
PTDNF_UPDATEINFO_ARGS pInfoArgs,
PTDNF_UPDATEINFO *ppUpdateInfo
)
{
return TDNFUpdateInfo(
pContext->hTdnf,
pInfoArgs->nMode,
pInfoArgs->nScope,
pInfoArgs->ppszPackageNameSpecs,
ppUpdateInfo);
}
uint32_t
TDNFCliInvokeUpdateInfoSummary(
PTDNF_CLI_CONTEXT pContext,
TDNF_AVAIL nAvail,
PTDNF_UPDATEINFO_ARGS pInfoArgs,
PTDNF_UPDATEINFO_SUMMARY *ppSummary
)
{
return TDNFUpdateInfoSummary(
pContext->hTdnf,
nAvail,
pInfoArgs->ppszPackageNameSpecs,
ppSummary);
}

View File

@ -21,191 +21,103 @@
#pragma once
//invoke tdnf library methods
uint32_t
TDNFCliAutoEraseCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliCleanCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliCountCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliEraseCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliListCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliInfoCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliInstallCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliSearchCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliRepoListCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliUpgradeCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliDistroSyncCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliDowngradeCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliReinstallCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliAlterCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs,
TDNF_ALTERTYPE nType
);
uint32_t
TDNFCliCheckLocalCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliCheckUpdateCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliMakeCacheCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliProvidesCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliUpdateInfoCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
TDNFCliUpdateInfoInfo(
PTDNF_UPDATEINFO pInfo
);
//help.c
void
TDNFCliShowUsage(
);
void
TDNFCliShowHelp(
);
void
TDNFCliShowNoSuchCommand(
const char* pszCmd
);
void
TDNFCliShowNoSuchOption(
const char* pszOption
);
uint32_t
TDNFCliHelpCommand(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs
);
//installcmd.c
uint32_t
PrintSolvedInfo(
TDNFCliInvokeAlter(
PTDNF_CLI_CONTEXT pContext,
TDNF_ALTERTYPE nAlterType,
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo
);
uint32_t
PrintNotAvailable(
char** ppszPkgsNotAvailable
TDNFCliInvokeCheckLocal(
PTDNF_CLI_CONTEXT pContext,
const char *pszFolder
);
uint32_t
PrintExistingPackagesSkipped(
PTDNF_PKG_INFO pPkgInfos
TDNFCliInvokeCheckUpdate(
PTDNF_CLI_CONTEXT pContext,
char** ppszPackageArgs,
PTDNF_PKG_INFO *ppPkgInfo,
uint32_t *pdwCount
);
uint32_t
PrintNotAvailablePackages(
PTDNF_PKG_INFO pPkgInfos
TDNFCliInvokeClean(
PTDNF_CLI_CONTEXT pContext,
TDNF_CLEANTYPE nCleanType,
PTDNF_CLEAN_INFO *ppTDNFCleanInfo
);
uint32_t
PrintAction(
PTDNF_PKG_INFO pPkgInfos,
TDNF_ALTERTYPE nAlterType
TDNFCliInvokeCount(
PTDNF_CLI_CONTEXT pContext,
uint32_t *pnCount
);
uint32_t
TDNFCliInvokeInfo(
PTDNF_CLI_CONTEXT pContext,
PTDNF_LIST_ARGS pInfoArgs,
PTDNF_PKG_INFO *ppPkgInfo,
uint32_t *pdwCount
);
uint32_t
TDNFCliInvokeList(
PTDNF_CLI_CONTEXT pContext,
PTDNF_LIST_ARGS pListArgs,
PTDNF_PKG_INFO *ppPkgInfo,
uint32_t *pdwCount
);
uint32_t
TDNFCliInvokeProvides(
PTDNF_CLI_CONTEXT pContext,
const char *pszProvides,
PTDNF_PKG_INFO *ppPkgInfos
);
uint32_t
TDNFCliInvokeRepoList(
PTDNF_CLI_CONTEXT pContext,
TDNF_REPOLISTFILTER nFilter,
PTDNF_REPO_DATA *ppRepos
);
uint32_t
TDNFCliInvokeResolve(
PTDNF_CLI_CONTEXT pContext,
TDNF_ALTERTYPE nAlterType,
PTDNF_SOLVED_PKG_INFO *ppSolvedPkgInfo
);
uint32_t
TDNFCliInvokeSearch(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_PKG_INFO *ppPkgInfo,
uint32_t *pdwCount
);
uint32_t
TDNFCliInvokeUpdateInfo(
PTDNF_CLI_CONTEXT pContext,
PTDNF_UPDATEINFO_ARGS pInfoArgs,
PTDNF_UPDATEINFO *ppUpdateInfo
);
uint32_t
TDNFCliInvokeUpdateInfoSummary(
PTDNF_CLI_CONTEXT pContext,
TDNF_AVAIL nAvail,
PTDNF_UPDATEINFO_ARGS pInfoArgs,
PTDNF_UPDATEINFO_SUMMARY *ppSummary
);
//main.c
uint32_t
PrintError(
uint32_t dwErrorCode
);
uint32_t
TDNFCliGetErrorString(
uint32_t dwErrorCode,
char** ppszError
);
void
TDNFCliShowVersion(
);
@ -214,203 +126,3 @@ uint32_t
TDNFCliVerboseShowEnv(
PTDNF_CMD_ARGS pCmdArgs
);
//options.c
uint32_t
_TDNFCliGetOptionByName(
const char* pszName,
struct option* pKnownOptions,
struct option** ppOption
);
uint32_t
TDNFCliValidateOptionName(
const char* pszOptionName,
struct option* pKnownOptions
);
uint32_t
TDNFCliValidateOptionArg(
const char* pszOption,
const char* pszArg,
struct option* pKnownOptions
);
uint32_t
TDNFCliValidateOptions(
const char* pszOption,
const char* pszArg,
struct option* pKnownOptions
);
//output.c
void
ShowConsoleProps(
);
uint32_t
GetConsoleWidth(
int* pnWidth
);
int
CalculateColumnWidth(
int nTotalWidth,
int nRequestedPercent,
int nMinVal
);
uint32_t
GetColumnWidths(
int nCount,
int* pnColPercents,
int* pnColWidths
);
//parseargs.c
uint32_t
TDNFCopyOptions(
PTDNF_CMD_ARGS pOptionArgs,
PTDNF_CMD_ARGS pArgs
);
uint32_t
ParseOption(
const char* pszName,
const char* pszArg,
PTDNF_CMD_ARGS pCmdArgs
);
uint32_t
ParseRpmVerbosity(
const char* pszVerbosity,
int* pnVerbosity
);
uint32_t
HandleOptionsError(
const char* pszName,
const char* pszArg,
struct option* pstOptions
);
uint32_t
TDNFCliParseArgs(
int argc,
char* const* argv,
PTDNF_CMD_ARGS* ppCmdArgs
);
uint32_t
TDNFCliParsePackageArgs(
PTDNF_CMD_ARGS pCmdArgs,
char*** pppszPackageArgs,
int* pnPackageCount
);
//parsecleanargs.c
uint32_t
ParseCleanType(
const char* pszCleanType,
TDNF_CLEANTYPE* pnCleanType
);
uint32_t
TDNFCliParseCleanArgs(
PTDNF_CMD_ARGS pCmdArgs,
TDNF_CLEANTYPE* pnCleanType
);
//parselistargs.c
uint32_t
ParseScope(
const char* pszScope,
TDNF_SCOPE* pnScope
);
uint32_t
TDNFCliParseListArgs(
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_LIST_ARGS* ppListArgs
);
uint32_t
TDNFCliParseInfoArgs(
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_LIST_ARGS* ppListArgs
);
//parserepolistargs.c
uint32_t
ParseFilter(
const char* pszRepolistFilter,
TDNF_REPOLISTFILTER* pnFilter
);
uint32_t
TDNFCliParseRepoListArgs(
PTDNF_CMD_ARGS pCmdArgs,
TDNF_REPOLISTFILTER* pnFilter
);
//parseupdateinfo.c
uint32_t
ParseMode(
const char* pszOutMode,
TDNF_UPDATEINFO_OUTPUT* pnOutMode
);
uint32_t
TDNFCliParseUpdateInfoArgs(
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_UPDATEINFO_ARGS* ppUpdateInfoArgs
);
void
TDNFFreeUpdateInfoArgs(
PTDNF_UPDATEINFO_ARGS pUpdateInfoArgs
);
//updateinfocmd.c
char*
TDNFGetUpdateInfoType(
int nType
);
uint32_t
TDNFCliUpdateInfoList(
PTDNF_UPDATEINFO pUpdateInfo
);
uint32_t
TDNFCliUpdateInfoSummary(
PTDNF pTdnf,
PTDNF_CMD_ARGS pCmdArgs,
PTDNF_UPDATEINFO_ARGS pInfoArgs
);
void
TDNFFreeListArgs(
PTDNF_LIST_ARGS pListArgs
);
//setopt.c
uint32_t
AddSetOpt(
PTDNF_CMD_ARGS pCmdArgs,
const char* pszOptArg
);
uint32_t
AddSetOptWithValues(
PTDNF_CMD_ARGS pCmdArgs,
int nType,
const char* pszOptArg,
const char* pszOptValue
);
uint32_t
GetOptionAndValue(
const char* pszOptArg,
PTDNF_CMD_OPT* ppCmdOpt
);

View File

@ -1,53 +0,0 @@
/*
* Copyright (C) 2015 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU General Public License v2 (the "License");
* you may not use this file except in compliance with the License. The terms
* of the License are located in the COPYING file of this distribution.
*/
/*
* Header : structs.h
*
* Abstract :
*
* tdnf
*
* command line tool
*
* Authors : Priyesh Padmavilasom (ppadmavilasom@vmware.com)
*
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
//Map command name to client function
typedef struct _TDNF_CLI_CMD_MAP
{
char* pszCmdName;
PFN_CMD pFnCmd;
}TDNF_CLI_CMD_MAP, *PTDNF_CLI_CMD_MAP;
typedef struct _TDNF_LIST_ARGS
{
TDNF_SCOPE nScope;
char** ppszPackageNameSpecs;
}TDNF_LIST_ARGS, *PTDNF_LIST_ARGS;
typedef struct _TDNF_UPDATEINFO_ARGS
{
TDNF_UPDATEINFO_OUTPUT nMode;
TDNF_SCOPE nScope;
TDNF_UPDATEINFO_TYPE nType;
char** ppszPackageNameSpecs;
}TDNF_UPDATEINFO_ARGS, *PTDNF_UPDATEINFO_ARGS;
#ifdef __cplusplus
}
#endif