summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/package.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/package.c')
-rw-r--r--lib/libalpm/package.c86
1 files changed, 59 insertions, 27 deletions
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index f2f15af4..8c927c11 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -23,13 +23,9 @@
#include "config.h"
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
-#include <errno.h>
#include <sys/types.h>
-#include <sys/stat.h>
/* libalpm */
#include "package.h"
@@ -40,6 +36,7 @@
#include "delta.h"
#include "handle.h"
#include "deps.h"
+#include "base64.h"
/** \addtogroup alpm_packages Package Functions
* @brief Functions to manipulate libalpm packages
@@ -58,7 +55,7 @@ int SYMEXPORT alpm_pkg_free(pmpkg_t *pkg)
_alpm_pkg_free(pkg);
}
- return(0);
+ return 0;
}
/** Check the integrity (with md5) of a package from the sync cache. */
@@ -78,13 +75,13 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg)
retval = _alpm_test_md5sum(fpath, alpm_pkg_get_md5sum(pkg));
if(retval == 0) {
- return(0);
- } else if (retval == 1) {
+ return 0;
+ } else if(retval == 1) {
pm_errno = PM_ERR_PKG_INVALID;
retval = -1;
}
- return(retval);
+ return retval;
}
/* Default package accessor functions. These will get overridden by any
@@ -92,8 +89,6 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg)
* a lazy-load cache. However, the defaults will work just fine for fully-
* populated package structures. */
static const char *_pkg_get_filename(pmpkg_t *pkg) { return pkg->filename; }
-static const char *_pkg_get_name(pmpkg_t *pkg) { return pkg->name; }
-static const char *_pkg_get_version(pmpkg_t *pkg) { return pkg->version; }
static const char *_pkg_get_desc(pmpkg_t *pkg) { return pkg->desc; }
static const char *_pkg_get_url(pmpkg_t *pkg) { return pkg->url; }
static time_t _pkg_get_builddate(pmpkg_t *pkg) { return pkg->builddate; }
@@ -126,8 +121,6 @@ static int _pkg_changelog_close(const pmpkg_t *pkg, void *fp) { return EOF; }
*/
struct pkg_operations default_pkg_ops = {
.get_filename = _pkg_get_filename,
- .get_name = _pkg_get_name,
- .get_version = _pkg_get_version,
.get_desc = _pkg_get_desc,
.get_url = _pkg_get_url,
.get_builddate = _pkg_get_builddate,
@@ -166,12 +159,12 @@ const char SYMEXPORT *alpm_pkg_get_filename(pmpkg_t *pkg)
const char SYMEXPORT *alpm_pkg_get_name(pmpkg_t *pkg)
{
- return pkg->ops->get_name(pkg);
+ return pkg->name;
}
const char SYMEXPORT *alpm_pkg_get_version(pmpkg_t *pkg)
{
- return pkg->ops->get_version(pkg);
+ return pkg->version;
}
const char SYMEXPORT *alpm_pkg_get_desc(pmpkg_t *pkg)
@@ -204,6 +197,43 @@ const char SYMEXPORT *alpm_pkg_get_md5sum(pmpkg_t *pkg)
return pkg->ops->get_md5sum(pkg);
}
+static int decode_pgpsig(pmpkg_t *pkg) {
+ const int len = strlen(pkg->pgpsig.base64_data);
+ const unsigned char *usline = (const unsigned char *)pkg->pgpsig.base64_data;
+ int ret, destlen = 0;
+ /* get the necessary size for the buffer by passing 0 */
+ ret = base64_decode(NULL, &destlen, usline, len);
+ /* alloc our memory and repeat the call to decode */
+ MALLOC(pkg->pgpsig.data, (size_t)destlen, goto error);
+ ret = base64_decode(pkg->pgpsig.data, &destlen, usline, len);
+ pkg->pgpsig.len = destlen;
+ if(ret != 0) {
+ goto error;
+ }
+
+ /* we no longer have a need for this */
+ FREE(pkg->pgpsig.base64_data);
+ return 0;
+
+error:
+ FREE(pkg->pgpsig.data);
+ pkg->pgpsig.len = 0;
+ return 1;
+}
+
+const pmpgpsig_t SYMEXPORT *alpm_pkg_get_pgpsig(pmpkg_t *pkg)
+{
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL));
+
+ if(pkg->pgpsig.data == NULL && pkg->pgpsig.base64_data != NULL) {
+ decode_pgpsig(pkg);
+ }
+ return &(pkg->pgpsig);
+}
+
const char SYMEXPORT *alpm_pkg_get_arch(pmpkg_t *pkg)
{
return pkg->ops->get_arch(pkg);
@@ -277,10 +307,10 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_backup(pmpkg_t *pkg)
pmdb_t SYMEXPORT *alpm_pkg_get_db(pmpkg_t *pkg)
{
/* Sanity checks */
- ASSERT(pkg != NULL, return(NULL));
- ASSERT(pkg->origin != PKG_FROM_FILE, return(NULL));
+ ASSERT(pkg != NULL, return NULL);
+ ASSERT(pkg->origin != PKG_FROM_FILE, return NULL);
- return(pkg->origin_data.db);
+ return pkg->origin_data.db;
}
/** Open a package changelog for reading. */
@@ -356,7 +386,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
reqs = alpm_list_msort(reqs, alpm_list_count(reqs), _alpm_str_cmp);
}
}
- return(reqs);
+ return reqs;
}
/** @} */
@@ -369,7 +399,7 @@ pmpkg_t *_alpm_pkg_new(void)
CALLOC(pkg, 1, sizeof(pmpkg_t), RET_ERR(PM_ERR_MEMORY, NULL));
- return(pkg);
+ return pkg;
}
pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
@@ -420,7 +450,7 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
}
newpkg->infolevel = pkg->infolevel;
- return(newpkg);
+ return newpkg;
}
void _alpm_pkg_free(pmpkg_t *pkg)
@@ -438,6 +468,8 @@ void _alpm_pkg_free(pmpkg_t *pkg)
FREE(pkg->url);
FREE(pkg->packager);
FREE(pkg->md5sum);
+ FREE(pkg->pgpsig.base64_data);
+ FREE(pkg->pgpsig.data);
FREE(pkg->arch);
FREELIST(pkg->licenses);
FREELIST(pkg->replaces);
@@ -497,7 +529,7 @@ int _alpm_pkg_cmp(const void *p1, const void *p2)
{
pmpkg_t *pkg1 = (pmpkg_t *)p1;
pmpkg_t *pkg2 = (pmpkg_t *)p2;
- return(strcoll(pkg1->name, pkg2->name));
+ return strcoll(pkg1->name, pkg2->name);
}
/* Test for existence of a package in a alpm_list_t*
@@ -511,7 +543,7 @@ pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle)
ALPM_LOG_FUNC;
if(needle == NULL || haystack == NULL) {
- return(NULL);
+ return NULL;
}
needle_hash = _alpm_hash_sdbm(needle);
@@ -527,11 +559,11 @@ pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle)
/* finally: we had hash match, verify string match */
if(strcmp(info->name, needle) == 0) {
- return(info);
+ return info;
}
}
}
- return(NULL);
+ return NULL;
}
/** Test if a package should be ignored.
@@ -549,18 +581,18 @@ int _alpm_pkg_should_ignore(pmpkg_t *pkg)
/* first see if the package is ignored */
if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(pkg))) {
- return(1);
+ return 1;
}
/* next see if the package is in a group that is ignored */
for(groups = handle->ignoregrp; groups; groups = alpm_list_next(groups)) {
char *grp = (char *)alpm_list_getdata(groups);
if(alpm_list_find_str(alpm_pkg_get_groups(pkg), grp)) {
- return(1);
+ return 1;
}
}
- return(0);
+ return 0;
}
/* vim: set ts=2 sw=2 noet: */