summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-06-28 18:05:17 +0300
committerTimo Teras <timo.teras@iki.fi>2009-06-28 18:52:40 +0300
commitfac4cdb3fad6037e0841724a50d5364d16603f07 (patch)
tree3d180deab279e6e0046ebba1cdc9a02e97d85516
parent7a29678aac20ac9e113704f8a5743f6051edef8d (diff)
downloadapk-tools-fac4cdb3fad6037e0841724a50d5364d16603f07.tar.bz2
apk-tools-fac4cdb3fad6037e0841724a50d5364d16603f07.tar.xz
blob: function to checksum a blob
And use it in couple of places. Some whitespace fixes too.
-rw-r--r--src/add.c10
-rw-r--r--src/apk_blob.h2
-rw-r--r--src/blob.c11
-rw-r--r--src/database.c20
4 files changed, 21 insertions, 22 deletions
diff --git a/src/add.c b/src/add.c
index bc9f042..fbb95ff 100644
--- a/src/add.c
+++ b/src/add.c
@@ -41,14 +41,6 @@ static int add_parse(void *ctx, int optch, int optindex, const char *optarg)
return 0;
}
-static void md5_str(const char *str, md5sum_t csum)
-{
- struct md5_ctx ctx;
- md5_init(&ctx);
- md5_process(&ctx, str, strlen(str));
- md5_finish(&ctx, csum);
-}
-
static int cup(void)
{
/* compressed/uncompressed size is 259/1213 */
@@ -111,7 +103,7 @@ static int add_main(void *ctx, int argc, char **argv)
goto err;
}
virtpkg->name = apk_db_get_name(&db, APK_BLOB_STR(actx->virtpkg));
- md5_str(virtpkg->name->name, virtpkg->csum);
+ apk_blob_csum(APK_BLOB_STR(virtpkg->name->name), virtpkg->csum);
virtpkg->version = strdup("0");
virtpkg->description = strdup("virtual meta package");
virtdep = apk_dep_from_pkg(&db, virtpkg);
diff --git a/src/apk_blob.h b/src/apk_blob.h
index 29da722..e4a598f 100644
--- a/src/apk_blob.h
+++ b/src/apk_blob.h
@@ -13,6 +13,7 @@
#define APK_BLOB_H
#include <string.h>
+#include "apk_defines.h"
struct apk_blob {
unsigned int len;
@@ -43,6 +44,7 @@ int apk_blob_rsplit(apk_blob_t blob, char split, apk_blob_t *l, apk_blob_t *r);
unsigned apk_blob_uint(apk_blob_t blob, int base);
unsigned long apk_blob_hash(apk_blob_t str);
int apk_blob_compare(apk_blob_t a, apk_blob_t b);
+void apk_blob_csum(apk_blob_t blob, csum_t csum);
int apk_blob_for_each_segment(apk_blob_t blob, const char *split,
apk_blob_cb cb, void *ctx);
diff --git a/src/blob.c b/src/blob.c
index 3aa61c7..6f05dfe 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -4,7 +4,7 @@
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
- * This program is free software; you can redistribute it and/or modify it
+ * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
@@ -165,6 +165,15 @@ unsigned apk_blob_uint(apk_blob_t blob, int base)
return val;
}
+void apk_blob_csum(apk_blob_t blob, csum_t csum)
+{
+ csum_ctx_t ctx;
+
+ csum_init(&ctx);
+ csum_process(&ctx, blob.ptr, blob.len);
+ csum_finish(&ctx, csum);
+}
+
int apk_hexdump_parse(apk_blob_t to, apk_blob_t from)
{
int i;
diff --git a/src/database.c b/src/database.c
index b1cdf85..00faf97 100644
--- a/src/database.c
+++ b/src/database.c
@@ -4,7 +4,7 @@
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
- * This program is free software; you can redistribute it and/or modify it
+ * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
@@ -903,7 +903,7 @@ static struct apk_bstream *apk_db_cache_open(struct apk_database *db,
if (db->root == NULL)
return NULL;
- snprintf(tmp, sizeof(tmp), "%s/var/lib/apk/%s", db->root, file);
+ snprintf(tmp, sizeof(tmp), "%s/var/lib/apk/%s", db->root, file);
return apk_bstream_from_file(tmp);
}
@@ -977,7 +977,7 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t repository)
char buf[2*sizeof(csum_t)+32], *name;
int r, n;
- if (repository.ptr == NULL || *repository.ptr == '\0'
+ if (repository.ptr == NULL || *repository.ptr == '\0'
|| *repository.ptr == '#')
return 0;
@@ -991,14 +991,10 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t repository)
};
if (apk_url_local_file(db->repos[r].url) == NULL) {
- csum_ctx_t csum;
- csum_t res;
-
- csum_init(&csum);
- csum_process(&csum, repository.ptr, repository.len);
- csum_finish(&csum, res);
+ csum_t cs;
- n = apk_hexdump_format(sizeof(buf), buf, APK_BLOB_BUF(res)) - 1;
+ apk_blob_csum(repository, cs);
+ n = apk_hexdump_format(sizeof(buf), buf, APK_BLOB_BUF(cs)) - 1;
snprintf(&buf[n], sizeof(buf) - n, ".index.gz");
db->repos[r].cache = strdup(buf);
@@ -1156,7 +1152,7 @@ static int apk_db_install_archive_entry(void *_ctx,
apk_db_file_change_owner(db, file, diri,
&ctx->file_diri_node);
}
-
+
if (apk_verbosity > 1)
printf("%s\n", ae->name);
@@ -1272,7 +1268,7 @@ static int apk_db_unpack_pkg(struct apk_database *db,
ctx = (struct install_ctx) {
.db = db,
.pkg = newpkg,
- .script = upgrade ?
+ .script = upgrade ?
APK_SCRIPT_PRE_UPGRADE : APK_SCRIPT_PRE_INSTALL,
.cb = cb,
.cb_ctx = cb_ctx,