Skip to content

Commit

Permalink
Merge pull request #495 from vmware/topic/okurth/set-string-macro
Browse files Browse the repository at this point in the history
use SET_STRING() macro for config and repo settings
  • Loading branch information
oliverkurth authored Sep 11, 2024
2 parents c9ce5af + 6da1cf4 commit 066bd38
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
12 changes: 6 additions & 6 deletions client/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}

Expand Down
14 changes: 7 additions & 7 deletions client/repolist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions common/config.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 066bd38

Please sign in to comment.