Skip to content

Commit

Permalink
organize code: add common lib
Browse files Browse the repository at this point in the history
Change-Id: I140537d46704714ae0f5bbd06fe72b8e0fac2328
  • Loading branch information
Priyesh Padmavilasom committed Nov 4, 2016
1 parent 09a7539 commit e255292
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 180 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ ltmain.sh
libtool
ar-lib

/common/.deps
/common/.libs
/client/.deps
/client/.libs
/tools/cli/.deps
Expand Down
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
ACLOCAL_AMFLAGS = -I m4

conf_DATA = tdnf.conf
include_HEADERS = include/tdnfclient.h include/tdnferror.h include/tdnftypes.h
pkginclude_HEADERS = include/tdnfclient.h include/tdnferror.h include/tdnftypes.h

SUBDIRS = \
common \
client \
tests \
tools
3 changes: 1 addition & 2 deletions client/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@ libtdnfclient_la_SOURCES = \
goal.c \
gpgcheck.c \
init.c \
memory.c \
packageutils.c \
repo.c \
remoterepo.c \
repolist.c \
repoutils.c \
resolve.c \
rpmtrans.c \
strings.c \
updateinfo.c \
utils.c \
search.c \
validate.c

libtdnfclient_la_LIBADD = \
$(top_builddir)/common/libcommon.la \
-lhawkey \
-lrepo \
-lrpm
82 changes: 82 additions & 0 deletions client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,85 @@ TDNFApplyPackageFilter(
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);
}
1 change: 0 additions & 1 deletion client/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ typedef enum
#define TDNF_DEFAULT_CACHE_LOCATION "/var/cache/tdnf"
#define TDNF_DEFAULT_DISTROVERPKG "photon-release"
#define TDNF_DEFAULT_DISTROARCHPKG "x86_64"
#define TDNF_DEFAULT_MAX_STRING_LEN 16384000
#define TDNF_RPM_CACHE_DIR_NAME "rpms"
#define TDNF_REPODATA_DIR_NAME "repodata"
//var names
Expand Down
1 change: 1 addition & 0 deletions client/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@
#include "defines.h"
#include "structs.h"
#include "prototypes.h"
#include "../common/prototypes.h"
157 changes: 0 additions & 157 deletions client/memory.c

This file was deleted.

11 changes: 11 additions & 0 deletions common/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
noinst_LTLIBRARIES = libcommon.la

libcommon_la_SOURCES = \
memory.c \
strings.c

libcommon_la_CPPFLAGS = \
-I$(top_srcdir)/include

libcommon_la_LDFLAGS = \
-static
57 changes: 57 additions & 0 deletions common/defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2015 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.
*/

/*
* Header : defines.h
*
* Abstract :
*
* commonlib
*
* common library
*
* Authors : Priyesh Padmavilasom (ppadmavilasom@vmware.com)
*/

#pragma once

#define IsNullOrEmptyString(str) (!(str) || !(*str))

#define BAIL_ON_TDNF_ERROR(dwError) \
do { \
if (dwError) \
{ \
goto error; \
} \
} while(0)

#define BAIL_ON_TDNF_SYSTEM_ERROR(dwError) \
do { \
if (dwError) \
{ \
dwError = ERROR_TDNF_SYSTEM_BASE + dwError; \
goto error; \
} \
} while(0)


#define TDNF_SAFE_FREE_MEMORY(pMemory) \
do { \
if (pMemory) { \
TDNFFreeMemory(pMemory); \
} \
} while(0)

#define TDNF_SAFE_FREE_STRINGARRAY(ppArray) \
do { \
if (ppArray) { \
TDNFFreeStringArray(ppArray); \
} \
} while(0)

#define TDNF_DEFAULT_MAX_STRING_LEN 16384000
19 changes: 19 additions & 0 deletions common/includes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2015 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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>

#include <tdnferror.h>

#include "defines.h"
#include "prototypes.h"
Loading

0 comments on commit e255292

Please sign in to comment.