Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor --setopts handling #464

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Prev Previous commit
remove unused functions in setopt.c
  • Loading branch information
oliverkurth committed Sep 11, 2024
commit 66b469f777fe598a406ed7aa20f4ed4771128dbb
22 changes: 0 additions & 22 deletions common/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,28 +262,6 @@ TDNFHasOpt(
int *pnHasOpt
);

uint32_t
TDNFSetOpt(
PTDNF_CMD_ARGS pArgs,
const char *pszOptName,
const char *pszOptValue
);

uint32_t
TDNFGetCmdOptValue(
PTDNF_CMD_ARGS pArgs,
const char *pszOptName,
char **ppszOptValue
);

uint32_t
TDNFGetOptWithDefault(
PTDNF_CMD_ARGS pArgs,
const char *pszOptName,
const char *pszDefault,
char **ppszOptValue
);

//log.c
void
GlobalSetQuiet(
Expand Down
108 changes: 0 additions & 108 deletions common/setopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,111 +230,3 @@ TDNFHasOpt(
}
goto cleanup;
}

uint32_t
TDNFGetCmdOptValue(
PTDNF_CMD_ARGS pArgs,
const char *pszOptName,
char **ppszOptValue
)
{
uint32_t dwError = 0;
PTDNF_CMD_OPT pOpt = NULL;
char *pszOptValue = NULL;

if(!pArgs || !pArgs->pSetOpt ||
IsNullOrEmptyString(pszOptName) || !ppszOptValue)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

dwError = _TDNFGetCmdOpt(pArgs, pszOptName, &pOpt);
BAIL_ON_TDNF_ERROR(dwError);

if (pOpt->pszOptValue)
{
dwError = TDNFAllocateString(pOpt->pszOptValue, &pszOptValue);
BAIL_ON_TDNF_ERROR(dwError);
}

*ppszOptValue = pszOptValue;

cleanup:
return dwError;

error:
TDNF_SAFE_FREE_MEMORY(pszOptValue);
goto cleanup;
}

/*
* if get fails, use the default value (if supplied)
*/
uint32_t
TDNFGetOptWithDefault(
PTDNF_CMD_ARGS pArgs,
const char *pszOptName,
const char *pszDefault,
char **ppszOptValue
)
{
uint32_t dwError = 0;
char *pszOptValue = NULL;

dwError = TDNFGetCmdOptValue(pArgs, pszOptName, &pszOptValue);
if (!IsNullOrEmptyString(pszDefault) &&
dwError == ERROR_TDNF_OPT_NOT_FOUND)
{
dwError = TDNFAllocateString(pszDefault, &pszOptValue);
}
BAIL_ON_TDNF_ERROR(dwError);

*ppszOptValue = pszOptValue;
error:
return dwError;
}

uint32_t
TDNFSetOpt(
PTDNF_CMD_ARGS pArgs,
const char *pszOptName,
const char *pszOptValue
)
{
uint32_t dwError = 0;
PTDNF_CMD_OPT pOpt = NULL;

if (!pArgs || IsNullOrEmptyString(pszOptName) ||
IsNullOrEmptyString(pszOptValue))
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

dwError = _TDNFGetCmdOpt(pArgs, pszOptName, &pOpt);
if (dwError == ERROR_TDNF_OPT_NOT_FOUND)
{
dwError = 0;
}
BAIL_ON_TDNF_ERROR(dwError);

if (pOpt)
{
TDNF_SAFE_FREE_MEMORY(pOpt->pszOptValue);

dwError = TDNFAllocateString(pszOptValue, &pOpt->pszOptValue);
BAIL_ON_TDNF_ERROR(dwError);
}
else
{
dwError = AddSetOptWithValues(pArgs, pszOptName, pszOptValue);
BAIL_ON_TDNF_ERROR(dwError);
}

cleanup:
return dwError;

error:
goto cleanup;
}
Loading