diff options
author | Michael Schroeder <mls@suse.de> | 2014-04-07 12:50:06 +0200 |
---|---|---|
committer | Michael Schroeder <mls@suse.de> | 2014-04-07 12:50:06 +0200 |
commit | 657a22165436c4f0791c869ca953c55b43d55aee (patch) | |
tree | 2d5268705c5354137affde715b8f7f51082a1f09 | |
parent | 721f58c32a0d29fa6aa4f96c8a389d5cd09e5b04 (diff) | |
download | libsolv-657a22165436c4f0791c869ca953c55b43d55aee.tar.gz libsolv-657a22165436c4f0791c869ca953c55b43d55aee.tar.bz2 libsolv-657a22165436c4f0791c869ca953c55b43d55aee.zip |
simplyfy checksum code
Also change dumpsolv to use solv_chksum_type2str instead of printing
the internal type.
-rw-r--r-- | src/chksum.h | 12 | ||||
-rw-r--r-- | src/repodata.c | 47 | ||||
-rw-r--r-- | tools/dumpsolv.c | 33 | ||||
-rw-r--r-- | tools/repomdxml2solv.c | 10 |
4 files changed, 34 insertions, 68 deletions
diff --git a/src/chksum.h b/src/chksum.h index 455e9ae..02f1504 100644 --- a/src/chksum.h +++ b/src/chksum.h @@ -29,6 +29,18 @@ const char *solv_chksum_type2str(Id type); Id solv_chksum_str2type(const char *str); int solv_chksum_len(Id type); +#ifdef LIBSOLV_INTERNAL + +#define case_CHKSUM_TYPES \ + case REPOKEY_TYPE_MD5: \ + case REPOKEY_TYPE_SHA1: \ + case REPOKEY_TYPE_SHA224: \ + case REPOKEY_TYPE_SHA256: \ + case REPOKEY_TYPE_SHA384: \ + case REPOKEY_TYPE_SHA512 + +#endif + #ifdef __cplusplus } #endif diff --git a/src/repodata.c b/src/repodata.c index 7ef29f8..85e9103 100644 --- a/src/repodata.c +++ b/src/repodata.c @@ -743,12 +743,7 @@ repodata_lookup_bin_checksum(Repodata *data, Id solvid, Id keyname, Id *typep) return 0; switch (key->type) { - case REPOKEY_TYPE_MD5: - case REPOKEY_TYPE_SHA1: - case REPOKEY_TYPE_SHA224: - case REPOKEY_TYPE_SHA256: - case REPOKEY_TYPE_SHA384: - case REPOKEY_TYPE_SHA512: + case_CHKSUM_TYPES: break; default: return 0; @@ -892,12 +887,7 @@ repodata_stringify(Pool *pool, Repodata *data, Repokey *key, KeyValue *kv, int f kv->str = repodata_dir2str(data, kv->id, kv->str); kv->num = 1; /* mark stringification */ return 1; - case REPOKEY_TYPE_MD5: - case REPOKEY_TYPE_SHA1: - case REPOKEY_TYPE_SHA224: - case REPOKEY_TYPE_SHA256: - case REPOKEY_TYPE_SHA384: - case REPOKEY_TYPE_SHA512: + case_CHKSUM_TYPES: if (!(flags & SEARCH_CHECKSUMS)) return 0; /* skip em */ if (kv->num) @@ -1996,12 +1986,7 @@ dataiterator_strdup(Dataiterator *di) return; switch (di->key->type) { - case REPOKEY_TYPE_MD5: - case REPOKEY_TYPE_SHA1: - case REPOKEY_TYPE_SHA224: - case REPOKEY_TYPE_SHA256: - case REPOKEY_TYPE_SHA384: - case REPOKEY_TYPE_SHA512: + case_CHKSUM_TYPES: case REPOKEY_TYPE_DIRSTRARRAY: if (di->kv.num) /* was it stringified into tmp space? */ l = strlen(di->kv.str) + 1; @@ -2017,23 +2002,8 @@ dataiterator_strdup(Dataiterator *di) case REPOKEY_TYPE_DIRSTRARRAY: l = strlen(di->kv.str) + 1; break; - case REPOKEY_TYPE_MD5: - l = SIZEOF_MD5; - break; - case REPOKEY_TYPE_SHA1: - l = SIZEOF_SHA1; - break; - case REPOKEY_TYPE_SHA224: - l = SIZEOF_SHA224; - break; - case REPOKEY_TYPE_SHA256: - l = SIZEOF_SHA256; - break; - case REPOKEY_TYPE_SHA384: - l = SIZEOF_SHA384; - break; - case REPOKEY_TYPE_SHA512: - l = SIZEOF_SHA512; + case_CHKSUM_TYPES: + l = solv_chksum_len(di->key->type); break; case REPOKEY_TYPE_BINARY: l = di->kv.num; @@ -3427,12 +3397,7 @@ repodata_create_stubs(Repodata *data) case REPOKEY_TYPE_NUM: repodata_set_num(sdata, SOLVID_META, di.key->name, SOLV_KV_NUM64(&di.kv)); break; - case REPOKEY_TYPE_MD5: - case REPOKEY_TYPE_SHA1: - case REPOKEY_TYPE_SHA224: - case REPOKEY_TYPE_SHA256: - case REPOKEY_TYPE_SHA384: - case REPOKEY_TYPE_SHA512: + case_CHKSUM_TYPES: repodata_set_bin_checksum(sdata, SOLVID_META, di.key->name, di.key->type, (const unsigned char *)di.kv.str); break; case REPOKEY_TYPE_IDARRAY: diff --git a/tools/dumpsolv.c b/tools/dumpsolv.c index db2ce94..1aaee16 100644 --- a/tools/dumpsolv.c +++ b/tools/dumpsolv.c @@ -14,6 +14,7 @@ static int with_attr; static int dump_json; #include "pool.h" +#include "chksum.h" #include "repo_solv.h" @@ -50,14 +51,6 @@ dump_attr(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv) case REPOKEY_TYPE_STR: printf("%s: %s\n", keyname, kv->str); break; - case REPOKEY_TYPE_MD5: - case REPOKEY_TYPE_SHA1: - case REPOKEY_TYPE_SHA224: - case REPOKEY_TYPE_SHA256: - case REPOKEY_TYPE_SHA384: - case REPOKEY_TYPE_SHA512: - printf("%s: %s (%s)\n", keyname, repodata_chk2str(data, key->type, (unsigned char *)kv->str), pool_id2str(repo->pool, key->type)); - break; case REPOKEY_TYPE_VOID: printf("%s: (void)\n", keyname); break; @@ -92,6 +85,11 @@ dump_attr(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv) printf("\n"); break; default: + if (solv_chksum_len(key->type)) + { + printf("%s: %s (%s)\n", keyname, repodata_chk2str(data, key->type, (unsigned char *)kv->str), solv_chksum_type2str(key->type)); + break; + } printf("%s: ?\n", keyname); break; } @@ -224,17 +222,6 @@ dump_attr_json(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv, struct cb str = kv->str; printf("%s", jsonstring(pool, str)); break; - case REPOKEY_TYPE_MD5: - case REPOKEY_TYPE_SHA1: - case REPOKEY_TYPE_SHA224: - case REPOKEY_TYPE_SHA256: - case REPOKEY_TYPE_SHA384: - case REPOKEY_TYPE_SHA512: - printf("{\n"); - printf("%*s \"value\": %s,\n", indent, "", jsonstring(pool, repodata_chk2str(data, key->type, (unsigned char *)kv->str))); - printf("%*s \"type\": %s\n", indent, "", jsonstring(pool, pool_id2str(repo->pool, key->type))); - printf("%*s}", indent, ""); - break; case REPOKEY_TYPE_VOID: printf("null"); break; @@ -276,6 +263,14 @@ dump_attr_json(Repo *repo, Repodata *data, Repokey *key, KeyValue *kv, struct cb printf("%*s]", indent, ""); break; default: + if (solv_chksum_len(key->type)) + { + printf("{\n"); + printf("%*s \"value\": %s,\n", indent, "", jsonstring(pool, repodata_chk2str(data, key->type, (unsigned char *)kv->str))); + printf("%*s \"type\": %s\n", indent, "", jsonstring(pool, solv_chksum_type2str(key->type))); + printf("%*s}", indent, ""); + break; + } printf("\"?\""); break; } diff --git a/tools/repomdxml2solv.c b/tools/repomdxml2solv.c index 4bd131c..f32c35d 100644 --- a/tools/repomdxml2solv.c +++ b/tools/repomdxml2solv.c @@ -76,15 +76,9 @@ doquery(Pool *pool, Repo *repo, const char *query) case REPOKEY_TYPE_CONSTANT: printf("%llu\n", SOLV_KV_NUM64(&di.kv)); break; - case REPOKEY_TYPE_MD5: - case REPOKEY_TYPE_SHA1: - case REPOKEY_TYPE_SHA224: - case REPOKEY_TYPE_SHA256: - case REPOKEY_TYPE_SHA384: - case REPOKEY_TYPE_SHA512: - printf("%s:%s\n", solv_chksum_type2str(di.key->type), repodata_chk2str(di.data, di.key->type, (unsigned char *)di.kv.str)); - break; default: + if (solv_chksum_len(di.key->type)) + printf("%s:%s\n", solv_chksum_type2str(di.key->type), repodata_chk2str(di.data, di.key->type, (unsigned char *)di.kv.str)); break; } } |