diff options
author | Stef Walter <stefw@redhat.com> | 2014-09-04 15:56:02 +0200 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2014-09-10 08:03:09 +0200 |
commit | 9ba2165ef75c63960ce95c9b1b085a0a630cfb14 (patch) | |
tree | 514ceec29b9c99fe85e335252b7b002b9a1a9a82 /common | |
parent | 1ede9a957c5a4f2c44b6bc88ba380a41c145a81b (diff) |
common: Add support for multiple field names (ie: nicks) per constant
This allows us to have old/new names for a given constant.
https://bugs.freedesktop.org/show_bug.cgi?id=83495
Diffstat (limited to 'common')
-rw-r--r-- | common/constants.c | 31 | ||||
-rw-r--r-- | common/constants.h | 2 | ||||
-rw-r--r-- | common/test-constants.c | 10 |
3 files changed, 22 insertions, 21 deletions
diff --git a/common/constants.c b/common/constants.c index ca956d3..a2427c9 100644 --- a/common/constants.c +++ b/common/constants.c @@ -50,7 +50,8 @@ * test to verify everything is in order. */ -#define CT(x, n) { x, #x, n }, +#define CT(x, n) { x, #x, { n } }, +#define CT2(x, n, n2) { x, #x, { n, n2 } }, const p11_constant p11_constant_types[] = { CT (CKA_CLASS, "class") @@ -254,10 +255,10 @@ const p11_constant p11_constant_asserts[] = { }; const p11_constant p11_constant_categories[] = { - { 0, "unspecified", "unspecified" }, - { 1, "token-user", "token-user" }, - { 2, "authority", "authority" }, - { 3, "other-entry", "other-entry" }, + { 0, "unspecified", { "unspecified" } }, + { 1, "token-user", { "token-user" } }, + { 2, "authority", { "authority" } }, + { 3, "other-entry", { "other-entry" } }, { CKA_INVALID }, }; @@ -629,7 +630,7 @@ static const p11_constant * lookup_info (const p11_constant *table, CK_ATTRIBUTE_TYPE type) { - p11_constant match = { type, NULL, NULL }; + p11_constant match = { type, NULL, { NULL } }; int length = -1; int i; @@ -657,7 +658,7 @@ p11_constant_nick (const p11_constant *constants, CK_ULONG type) { const p11_constant *constant = lookup_info (constants, type); - return constant ? constant->nick : NULL; + return constant ? constant->nicks[0] : NULL; } p11_dict * @@ -665,9 +666,8 @@ p11_constant_reverse (bool nick) { const p11_constant *table; p11_dict *lookups; - void *string; int length = -1; - int i, j; + int i, j, k; lookups = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL); return_val_if_fail (lookups != NULL, NULL); @@ -678,14 +678,15 @@ p11_constant_reverse (bool nick) for (j = 0; j < length; j++) { if (nick) { - if (!table[j].nick) - continue; - string = (void *)table[j].nick; + for (k = 0; table[j].nicks[k] != NULL; k++) { + if (!p11_dict_set (lookups, (void *)table[j].nicks[k], + (void *)&table[j].value)) + return_val_if_reached (NULL); + } } else { - string = (void *)table[j].name; + if (!p11_dict_set (lookups, (void *)table[j].name, (void *)&table[j].value)) + return_val_if_reached (NULL); } - if (!p11_dict_set (lookups, string, (void *)&table[j].value)) - return_val_if_reached (NULL); } } diff --git a/common/constants.h b/common/constants.h index 5b0f3a5..1526373 100644 --- a/common/constants.h +++ b/common/constants.h @@ -43,7 +43,7 @@ typedef struct { CK_ULONG value; const char *name; - const char *nick; + const char *nicks[4]; } p11_constant; const char * p11_constant_name (const p11_constant *constants, diff --git a/common/test-constants.c b/common/test-constants.c index 9adc81a..577d611 100644 --- a/common/test-constants.c +++ b/common/test-constants.c @@ -49,7 +49,7 @@ test_constants (void *arg) const p11_constant *constant = arg; p11_dict *nicks, *names; CK_ULONG check; - int i; + int i, j; nicks = p11_constant_reverse (true); names = p11_constant_reverse (false); @@ -61,16 +61,16 @@ test_constants (void *arg) for (i = 0; constant[i].value != CKA_INVALID; i++) { assert_ptr_not_null (constant[i].name); - if (constant[i].nick) { - assert_str_eq (constant[i].nick, + if (constant[i].nicks[0]) { + assert_str_eq (constant[i].nicks[0], p11_constant_nick (constant, constant[i].value)); } assert_str_eq (constant[i].name, p11_constant_name (constant, constant[i].value)); - if (constant[i].nick) { - check = p11_constant_resolve (nicks, constant[i].nick); + for (j = 0; constant[i].nicks[j] != NULL; j++) { + check = p11_constant_resolve (nicks, constant[i].nicks[j]); assert_num_eq (constant[i].value, check); } |