From 6da1cf4f7d5657968eb896105327afad353bd0eb Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Fri, 5 Jan 2024 13:24:47 -0800 Subject: [PATCH] use SET_STRING() macro for config and repo settings --- client/config.c | 12 ++++++------ client/repolist.c | 14 +++++++------- common/config.h | 2 ++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/client/config.c b/client/config.c index 6d2f3895..81eefeb4 100644 --- a/client/config.c +++ b/client/config.c @@ -119,15 +119,15 @@ TDNFConfigFromCnfTree(PTDNF_CONF pConf, struct cnfnode *cn_top) else if (strcmp(cn->name, TDNF_CONF_KEY_REPOSDIR) == 0 || strcmp(cn->name, TDNF_CONF_KEY_REPODIR) == 0) { - pConf->pszRepoDir = strdup(cn->value); + SET_STRING(pConf->pszRepoDir, cn->value); } else if (strcmp(cn->name, TDNF_CONF_KEY_CACHEDIR) == 0) { - pConf->pszCacheDir = strdup(cn->value); + SET_STRING(pConf->pszCacheDir, cn->value); } else if (strcmp(cn->name, TDNF_CONF_KEY_PERSISTDIR) == 0) { - pConf->pszPersistDir = strdup(cn->value); + SET_STRING(pConf->pszPersistDir, cn->value); } else if (strcmp(cn->name, TDNF_CONF_KEY_DISTROVERPKGS) == 0) { @@ -161,7 +161,7 @@ TDNFConfigFromCnfTree(PTDNF_CONF pConf, struct cnfnode *cn_top) } else if (strcmp(cn->name, TDNF_CONF_KEY_PROXY) == 0) { - pConf->pszProxy = strdup(cn->value); + SET_STRING(pConf->pszProxy, cn->value); } else if (strcmp(cn->name, TDNF_CONF_KEY_PROXY_USER) == 0) { @@ -189,11 +189,11 @@ TDNFConfigFromCnfTree(PTDNF_CONF pConf, struct cnfnode *cn_top) } else if (strcmp(cn->name, TDNF_CONF_KEY_PLUGIN_CONF_PATH) == 0) { - pConf->pszPluginConfPath = strdup(cn->value); + SET_STRING(pConf->pszPluginConfPath, cn->value); } else if (strcmp(cn->name, TDNF_CONF_KEY_PLUGIN_PATH) == 0) { - pConf->pszPluginPath = strdup(cn->value); + SET_STRING(pConf->pszPluginPath, cn->value); } } diff --git a/client/repolist.c b/client/repolist.c index 87fa3298..bbf9d7d0 100644 --- a/client/repolist.c +++ b/client/repolist.c @@ -539,7 +539,7 @@ TDNFLoadReposFromFile( } else if (strcmp(cn->name, TDNF_REPO_KEY_NAME) == 0) { - pRepo->pszName = strdup(cn->value); + SET_STRING(pRepo->pszName, cn->value); } else if (strcmp(cn->name, TDNF_REPO_KEY_BASEURL) == 0) { @@ -549,7 +549,7 @@ TDNFLoadReposFromFile( } else if (strcmp(cn->name, TDNF_REPO_KEY_METALINK) == 0) { - pRepo->pszMetaLink = strdup(cn->value); + SET_STRING(pRepo->pszMetaLink, cn->value); } else if (strcmp(cn->name, TDNF_REPO_KEY_MIRRORLIST) == 0) { @@ -571,11 +571,11 @@ TDNFLoadReposFromFile( } else if (strcmp(cn->name, TDNF_REPO_KEY_USERNAME) == 0) { - pRepo->pszUser = strdup(cn->value); + SET_STRING(pRepo->pszUser, cn->value); } else if (strcmp(cn->name, TDNF_REPO_KEY_PASSWORD) == 0) { - pRepo->pszPass = strdup(cn->value); + SET_STRING(pRepo->pszPass, cn->value); } else if (strcmp(cn->name, TDNF_REPO_KEY_PRIORITY) == 0) { @@ -603,15 +603,15 @@ TDNFLoadReposFromFile( } else if (strcmp(cn->name, TDNF_REPO_KEY_SSL_CA_CERT) == 0) { - pRepo->pszSSLCaCert = strdup(cn->value); + SET_STRING(pRepo->pszSSLCaCert, cn->value); } else if (strcmp(cn->name, TDNF_REPO_KEY_SSL_CLI_CERT) == 0) { - pRepo->pszSSLClientCert = strdup(cn->value); + SET_STRING(pRepo->pszSSLClientCert, cn->value); } else if (strcmp(cn->name, TDNF_REPO_KEY_SSL_CLI_KEY) == 0) { - pRepo->pszSSLClientKey = strdup(cn->value); + SET_STRING(pRepo->pszSSLClientKey, cn->value); } else if (strcmp(cn->name, TDNF_REPO_KEY_METADATA_EXPIRE) == 0) { diff --git a/common/config.h b/common/config.h index e506f408..f8a82640 100644 --- a/common/config.h +++ b/common/config.h @@ -1,5 +1,7 @@ #define STR_IS_TRUE(s) ((s) && (!strcmp((s), "1") || !strcasecmp((s), "true"))) +#define SET_STRING(s, v) {if (s) free(s); if(v) s = strdup(v); else s = NULL;} + //Misc #define TDNF_RPM_EXT ".rpm" #define TDNF_NAME "tdnf"