/
niceSOFT
/
tdnf
Обзор
Документация
Войти
/
niceSOFT
/
tdnf
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
tools/cli/lib/parseupdateinfo.c
186 строк
5 KB
Oliver Kurth
replace PTDNF_CMD_OPT with llconf nodes
18 окт 2025, 01:55
18 окт 2025, 01:55
9b7032e
Код
Авторство
О чём код?
/* * Copyright (C) 2015-2023 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. */ #include "includes.h" #include "../llconf/nodes.h" uint32_t TDNFCliParseUpdateInfoArgs( PTDNF_CMD_ARGS pCmdArgs, PTDNF_UPDATEINFO_ARGS* ppUpdateInfoArgs ) { uint32_t dwError = 0; PTDNF_UPDATEINFO_ARGS pUpdateInfoArgs = NULL; struct cnfnode *cn = NULL; int nStartIndex = 1; int nPackageCount = 0; int nIndex = 0; if(!pCmdArgs || pCmdArgs->nCmdCount < 1) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_CLI_ERROR(dwError); } dwError = TDNFAllocateMemory( 1, sizeof(TDNF_UPDATEINFO_ARGS), (void**)&pUpdateInfoArgs); BAIL_ON_CLI_ERROR(dwError); pUpdateInfoArgs->nMode = OUTPUT_SUMMARY; pUpdateInfoArgs->nScope = SCOPE_AVAILABLE; /* scope and mode can be given as options */ for (cn = pCmdArgs->cn_setopts->first_child; cn; cn = cn->next) { dwError = TDNFCliParseScope( cn->name, &pUpdateInfoArgs->nScope); if (dwError == 0) { continue; } if(dwError == ERROR_TDNF_CLI_NO_MATCH) { dwError = 0; } BAIL_ON_CLI_ERROR(dwError); dwError = TDNFCliParseMode( cn->name, &pUpdateInfoArgs->nMode); if(dwError == ERROR_TDNF_CLI_NO_MATCH) { dwError = 0; } BAIL_ON_CLI_ERROR(dwError); } //Assume first arg as mode //(tdnf updateinfo <mode> <availability> <type> <pkgnamespecs>) if(pCmdArgs->nCmdCount > nStartIndex) { dwError = TDNFCliParseMode( pCmdArgs->ppszCmds[nStartIndex], &pUpdateInfoArgs->nMode); if(dwError == ERROR_TDNF_CLI_NO_MATCH) { dwError = 0; //There was no valid mode. Let the next arg start here. --nStartIndex; } BAIL_ON_CLI_ERROR(dwError); ++nStartIndex; } //Next arg should be availability if(pCmdArgs->nCmdCount > nStartIndex) { dwError = TDNFCliParseScope( pCmdArgs->ppszCmds[nStartIndex], &pUpdateInfoArgs->nScope); if(dwError == ERROR_TDNF_CLI_NO_MATCH) { dwError = 0; //There was no valid availability. Let the next arg start here. --nStartIndex; } BAIL_ON_CLI_ERROR(dwError); ++nStartIndex; } //Copy the rest of the args as package name specs nPackageCount = pCmdArgs->nCmdCount - nStartIndex; dwError = TDNFAllocateMemory( nPackageCount + 1, sizeof(char*), (void**)&pUpdateInfoArgs->ppszPackageNameSpecs); BAIL_ON_CLI_ERROR(dwError); for(nIndex = 0; nIndex < nPackageCount; ++nIndex) { dwError = TDNFAllocateString( pCmdArgs->ppszCmds[nStartIndex++], &pUpdateInfoArgs->ppszPackageNameSpecs[nIndex]); BAIL_ON_CLI_ERROR(dwError); } *ppUpdateInfoArgs = pUpdateInfoArgs; cleanup: return dwError; error: if(ppUpdateInfoArgs) { *ppUpdateInfoArgs = NULL; } if(pUpdateInfoArgs) { TDNFCliFreeUpdateInfoArgs(pUpdateInfoArgs); } goto cleanup; } uint32_t TDNFCliParseMode( const char* pszMode, TDNF_UPDATEINFO_OUTPUT* pnMode ) { uint32_t dwError = 0; int nIndex = 0; int nCount = 0; TDNF_UPDATEINFO_OUTPUT nMode = OUTPUT_SUMMARY; stTemp stModes[] = { {"summary", OUTPUT_SUMMARY}, {"list", OUTPUT_LIST}, {"info", OUTPUT_INFO} }; if(IsNullOrEmptyString(pszMode) || !pnMode) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_CLI_ERROR(dwError); } nCount = ARRAY_SIZE(stModes); for(nIndex = 0; nIndex < nCount; ++nIndex) { if(!strcasecmp(stModes[nIndex].pszTypeName, pszMode)) { nMode = stModes[nIndex].nType; break; } } if(nIndex >= nCount) { dwError = ERROR_TDNF_CLI_NO_MATCH; } BAIL_ON_CLI_ERROR(dwError); *pnMode = nMode; cleanup: return dwError; error: goto cleanup; } void TDNFCliFreeUpdateInfoArgs( PTDNF_UPDATEINFO_ARGS pUpdateInfoArgs ) { if(pUpdateInfoArgs) { TDNF_CLI_SAFE_FREE_STRINGARRAY(pUpdateInfoArgs->ppszPackageNameSpecs); TDNFFreeMemory(pUpdateInfoArgs); } }