diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-03-25 13:10:23 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-03-25 13:10:23 +0200 |
commit | 3f6b2f8c7b7b79a59664e16d6d350acb54802171 (patch) | |
tree | 2e7a9c906fa383049a154f58476ef25c83689c85 /rpmio | |
parent | c9146aa580ab87b93ba5d68cde5b606652c93cd8 (diff) | |
download | librpm-tizen-3f6b2f8c7b7b79a59664e16d6d350acb54802171.tar.gz librpm-tizen-3f6b2f8c7b7b79a59664e16d6d350acb54802171.tar.bz2 librpm-tizen-3f6b2f8c7b7b79a59664e16d6d350acb54802171.zip |
Implement fdUpdateDigests() and friends using digest bundle
Diffstat (limited to 'rpmio')
-rw-r--r-- | rpmio/digest.c | 90 | ||||
-rw-r--r-- | rpmio/rpmio.c | 31 | ||||
-rw-r--r-- | rpmio/rpmio_internal.h | 4 |
3 files changed, 45 insertions, 80 deletions
diff --git a/rpmio/digest.c b/rpmio/digest.c index 707d6e0d1..0779b90de 100644 --- a/rpmio/digest.c +++ b/rpmio/digest.c @@ -251,25 +251,19 @@ DPRINTF((stderr, "*** Final(%p,%p,%p,%zd) hashctx %p digest %p\n", ctx, datap, l void fdInitDigest(FD_t fd, pgpHashAlgo hashalgo, int flags) { - if (fd->ndigests < FDDIGEST_MAX) { - fd->digests[fd->ndigests] = rpmDigestInit(hashalgo, flags); - fd->ndigests++; - fdstat_enter(fd, FDSTAT_DIGEST); - fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) 0); + if (fd->digests == NULL) { + fd->digests = rpmDigestBundleNew(); } + fdstat_enter(fd, FDSTAT_DIGEST); + rpmDigestBundleAdd(fd->digests, hashalgo, flags); + fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) 0); } void fdUpdateDigests(FD_t fd, const unsigned char * buf, size_t buflen) { - int i; - - if (buf != NULL && buflen > 0) - for (i = fd->ndigests - 1; i >= 0; i--) { - DIGEST_CTX ctx = fd->digests[i]; - if (ctx == NULL) - continue; + if (fd && fd->digests) { fdstat_enter(fd, FDSTAT_DIGEST); - (void) rpmDigestUpdate(ctx, buf, buflen); + rpmDigestBundleUpdate(fd->digests, buf, buflen); fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) buflen); } } @@ -279,56 +273,38 @@ void fdFiniDigest(FD_t fd, pgpHashAlgo hashalgo, size_t * lenp, int asAscii) { - int imax = -1; - int i; - - for (i = fd->ndigests - 1; i >= 0; i--) { - DIGEST_CTX ctx = fd->digests[i]; - if (ctx == NULL) - continue; - if (i > imax) imax = i; - if (ctx->algo != hashalgo) - continue; + if (fd && fd->digests) { fdstat_enter(fd, FDSTAT_DIGEST); - (void) rpmDigestFinal(ctx, datap, lenp, asAscii); + rpmDigestBundleFinal(fd->digests, hashalgo, datap, lenp, asAscii); fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) 0); - fd->digests[i] = NULL; - break; - } - if (i < 0) { - if (datap) *datap = NULL; - if (lenp) *lenp = 0; } - - fd->ndigests = imax; - if (i < imax) - fd->ndigests++; /* convert index to count */ } - void fdStealDigest(FD_t fd, pgpDig dig) { - int i; - for (i = fd->ndigests - 1; i >= 0; i--) { - DIGEST_CTX ctx = fd->digests[i]; - if (ctx == NULL) - continue; - switch (ctx->algo) { - case PGPHASHALGO_MD5: -assert(dig->md5ctx == NULL); - dig->md5ctx = ctx; - fd->digests[i] = NULL; - break; - case PGPHASHALGO_SHA1: - case PGPHASHALGO_SHA256: - case PGPHASHALGO_SHA384: - case PGPHASHALGO_SHA512: -assert(dig->sha1ctx == NULL); - dig->sha1ctx = ctx; - fd->digests[i] = NULL; - break; - default: - break; - } + if (fd && fd->digests) { + rpmDigestBundle bundle = fd->digests; + for (int i = bundle->index_max; i >= bundle->index_min; i--) { + DIGEST_CTX ctx = bundle->digests[i]; + if (ctx == NULL) + continue; + switch (ctx->algo) { + case PGPHASHALGO_MD5: + assert(dig->md5ctx == NULL); + dig->md5ctx = ctx; + bundle->digests[i] = NULL; + break; + case PGPHASHALGO_SHA1: + case PGPHASHALGO_SHA256: + case PGPHASHALGO_SHA384: + case PGPHASHALGO_SHA512: + assert(dig->sha1ctx == NULL); + dig->sha1ctx = ctx; + bundle->digests[i] = NULL; + break; + default: + break; + } + } } } diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index c7040302e..95f0b8d8f 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -241,8 +241,6 @@ DBGREFS(fd, (stderr, "--> fd %p ++ %d %s %s\n", fd, fd->nrefs, msg, fdbg(fd))) */ FD_t fdFree( FD_t fd, const char *msg) { - int i; - if (fd == NULL) DBGREFS(0, (stderr, "--> fd %p -- %d %s\n", fd, FDNREFS(fd), msg)); FDSANE(fd); @@ -251,14 +249,9 @@ DBGREFS(fd, (stderr, "--> fd %p -- %d %s %s\n", fd, fd->nrefs, msg, fdbg(fd))); if (--fd->nrefs > 0) return fd; fd->stats = _free(fd->stats); - for (i = fd->ndigests - 1; i >= 0; i--) { - DIGEST_CTX *ctxp = fd->digests + i; - if (*ctxp == NULL) - continue; - (void) rpmDigestFinal(*ctxp, NULL, NULL, 0); - *ctxp = NULL; + if (fd->digests) { + fd->digests = rpmDigestBundleFree(fd->digests); } - fd->ndigests = 0; free(fd); } return NULL; @@ -288,9 +281,7 @@ FD_t fdNew(const char * msg) fd->syserrno = 0; fd->errcookie = NULL; fd->stats = xcalloc(1, sizeof(*fd->stats)); - - fd->ndigests = 0; - memset(fd->digests, 0, sizeof(fd->digests)); + fd->digests = NULL; fd->fd_cpioPos = 0; @@ -310,7 +301,7 @@ static ssize_t fdRead(void * cookie, char * buf, size_t count) rc = read(fdFileno(fd), buf, (count > fd->bytesRemain ? fd->bytesRemain : count)); fdstat_exit(fd, FDSTAT_READ, rc); - if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc); + if (fd->digests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc); DBGIO(fd, (stderr, "==>\tfdRead(%p,%p,%ld) rc %ld %s\n", cookie, buf, (long)count, (long)rc, fdbg(fd))); @@ -327,7 +318,7 @@ static ssize_t fdWrite(void * cookie, const char * buf, size_t count) if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ - if (fd->ndigests && count > 0) fdUpdateDigests(fd, (void *)buf, count); + if (fd->digests && count > 0) fdUpdateDigests(fd, (void *)buf, count); if (count == 0) return 0; @@ -870,7 +861,7 @@ DBGIO(fd, (stderr, "==>\tgzdRead(%p,%p,%u) rc %lx %s\n", cookie, buf, (unsigned) } } else if (rc >= 0) { fdstat_exit(fd, FDSTAT_READ, rc); - if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc); + if (fd->digests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc); } return rc; } @@ -883,7 +874,7 @@ static ssize_t gzdWrite(void * cookie, const char * buf, size_t count) if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ - if (fd->ndigests && count > 0) fdUpdateDigests(fd, (void *)buf, count); + if (fd->digests && count > 0) fdUpdateDigests(fd, (void *)buf, count); gzfile = gzdFileno(fd); if (gzfile == NULL) return -2; /* XXX can't happen */ @@ -1071,7 +1062,7 @@ static ssize_t bzdRead(void * cookie, char * buf, size_t count) fd->errcookie = bzerror(bzfile, &zerror); } else if (rc >= 0) { fdstat_exit(fd, FDSTAT_READ, rc); - if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc); + if (fd->digests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc); } return rc; } @@ -1084,7 +1075,7 @@ static ssize_t bzdWrite(void * cookie, const char * buf, size_t count) if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ - if (fd->ndigests && count > 0) fdUpdateDigests(fd, (void *)buf, count); + if (fd->digests && count > 0) fdUpdateDigests(fd, (void *)buf, count); bzfile = bzdFileno(fd); fdstat_enter(fd, FDSTAT_WRITE); @@ -1460,7 +1451,7 @@ static ssize_t lzdRead(void * cookie, char * buf, size_t count) fd->errcookie = "Lzma: decoding error"; } else if (rc >= 0) { fdstat_exit(fd, FDSTAT_READ, rc); - if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc); + if (fd->digests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc); } return rc; } @@ -1473,7 +1464,7 @@ static ssize_t lzdWrite(void * cookie, const char * buf, size_t count) if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ - if (fd->ndigests && count > 0) fdUpdateDigests(fd, (void *)buf, count); + if (fd->digests && count > 0) fdUpdateDigests(fd, (void *)buf, count); lzfile = lzdFileno(fd); diff --git a/rpmio/rpmio_internal.h b/rpmio/rpmio_internal.h index 82dd43381..b00c35d7a 100644 --- a/rpmio/rpmio_internal.h +++ b/rpmio/rpmio_internal.h @@ -50,9 +50,7 @@ struct _FD_s { FDSTAT_t stats; /* I/O statistics */ - int ndigests; -#define FDDIGEST_MAX 4 - DIGEST_CTX digests[FDDIGEST_MAX]; + rpmDigestBundle digests; rpm_loff_t fd_cpioPos; /* cpio: */ }; |