summaryrefslogtreecommitdiff
path: root/p11-kit
diff options
context:
space:
mode:
Diffstat (limited to 'p11-kit')
-rw-r--r--p11-kit/conf.c58
-rw-r--r--p11-kit/conf.h6
-rw-r--r--p11-kit/modules.c32
-rw-r--r--p11-kit/pin.c22
-rw-r--r--p11-kit/tests/conf-test.c19
-rw-r--r--p11-kit/tests/mock-module.c14
-rw-r--r--p11-kit/tests/uri-test.c41
-rw-r--r--p11-kit/uri.c118
8 files changed, 186 insertions, 124 deletions
diff --git a/p11-kit/conf.c b/p11-kit/conf.c
index 1d92942..45b1404 100644
--- a/p11-kit/conf.c
+++ b/p11-kit/conf.c
@@ -222,7 +222,7 @@ read_config_file (const char* filename, int flags)
return config;
}
-int
+bool
_p11_conf_merge_defaults (p11_dict *map,
p11_dict *defaults)
{
@@ -236,14 +236,14 @@ _p11_conf_merge_defaults (p11_dict *map,
if (p11_dict_get (map, key))
continue;
key = strdup (key);
- return_val_if_fail (key != NULL, -1);
+ return_val_if_fail (key != NULL, false);
value = strdup (value);
- return_val_if_fail (key != NULL, -1);
+ return_val_if_fail (key != NULL, false);
if (!p11_dict_set (map, key, value))
- return_val_if_reached (-1);
+ return_val_if_reached (false);
}
- return 0;
+ return true;
}
p11_dict *
@@ -441,7 +441,7 @@ _p11_conf_load_globals (const char *system_conf, const char *user_conf,
/* If merging, then supplement user config with system values */
if (mode == CONF_USER_MERGE) {
- if (_p11_conf_merge_defaults (uconfig, config) < 0) {
+ if (!_p11_conf_merge_defaults (uconfig, config)) {
error = errno;
goto finished;
}
@@ -509,7 +509,7 @@ calc_name_from_filename (const char *fname)
return name;
}
-static int
+static bool
load_config_from_file (const char *configfile,
const char *name,
p11_dict *configs,
@@ -526,22 +526,22 @@ load_config_from_file (const char *configfile,
if (key == NULL) {
p11_message ("invalid config filename, will be ignored in the future: %s", configfile);
key = strdup (name);
- return_val_if_fail (key != NULL, -1);
+ return_val_if_fail (key != NULL, false);
}
config = _p11_conf_parse_file (configfile, flags);
if (!config) {
free (key);
- return -1;
+ return false;
}
prev = p11_dict_get (configs, key);
if (prev == NULL) {
if (!p11_dict_set (configs, key, config))
- return_val_if_reached (-1);
+ return_val_if_reached (false);
config = NULL;
} else {
- if (_p11_conf_merge_defaults (prev, config) < 0)
+ if (!_p11_conf_merge_defaults (prev, config))
error = errno;
free (key);
}
@@ -551,13 +551,13 @@ load_config_from_file (const char *configfile,
if (error) {
errno = error;
- return -1;
+ return false;
}
- return 0;
+ return true;
}
-static int
+static bool
load_configs_from_directory (const char *directory,
p11_dict *configs,
int flags)
@@ -566,7 +566,7 @@ load_configs_from_directory (const char *directory,
struct stat st;
DIR *dir;
int error = 0;
- int is_dir;
+ bool is_dir;
char *path;
int count = 0;
@@ -579,24 +579,24 @@ load_configs_from_directory (const char *directory,
if ((flags & CONF_IGNORE_MISSING) &&
(errno == ENOENT || errno == ENOTDIR)) {
p11_debug ("module configs do not exist");
- return 0;
+ return true;
} else if ((flags & CONF_IGNORE_ACCESS_DENIED) &&
(errno == EPERM || errno == EACCES)) {
p11_debug ("couldn't list inacessible module configs");
- return 0;
+ return true;
}
p11_message ("couldn't list directory: %s: %s", directory,
strerror (error));
errno = error;
- return -1;
+ return false;
}
/* We're within a global mutex, so readdir is safe */
while ((dp = readdir(dir)) != NULL) {
path = strconcat (directory, "/", dp->d_name, NULL);
- return_val_if_fail (path != NULL, -1);
+ return_val_if_fail (path != NULL, false);
- is_dir = 0;
+ is_dir = false;
#ifdef HAVE_STRUCT_DIRENT_D_TYPE
if(dp->d_type != DT_UNKNOWN) {
is_dir = (dp->d_type == DT_DIR);
@@ -612,7 +612,7 @@ load_configs_from_directory (const char *directory,
is_dir = S_ISDIR (st.st_mode);
}
- if (!is_dir && load_config_from_file (path, dp->d_name, configs, flags) < 0) {
+ if (!is_dir && !load_config_from_file (path, dp->d_name, configs, flags)) {
error = errno;
free (path);
break;
@@ -626,10 +626,10 @@ load_configs_from_directory (const char *directory,
if (error) {
errno = error;
- return -1;
+ return false;
}
- return count;
+ return true;
}
p11_dict *
@@ -650,7 +650,7 @@ _p11_conf_load_modules (int mode, const char *system_dir, const char *user_dir)
path = expand_user_path (user_dir);
if (!path)
error = errno;
- else if (load_configs_from_directory (path, configs, flags) < 0)
+ else if (!load_configs_from_directory (path, configs, flags))
error = errno;
free (path);
if (error != 0) {
@@ -667,7 +667,7 @@ _p11_conf_load_modules (int mode, const char *system_dir, const char *user_dir)
*/
if (mode != CONF_USER_ONLY) {
flags = CONF_IGNORE_MISSING;
- if (load_configs_from_directory (system_dir, configs, flags) < 0) {
+ if (!load_configs_from_directory (system_dir, configs, flags)) {
error = errno;
p11_dict_free (configs);
errno = error;
@@ -678,17 +678,17 @@ _p11_conf_load_modules (int mode, const char *system_dir, const char *user_dir)
return configs;
}
-int
+bool
_p11_conf_parse_boolean (const char *string,
- int default_value)
+ bool default_value)
{
if (!string)
return default_value;
if (strcmp (string, "yes") == 0) {
- return 1;
+ return true;
} else if (strcmp (string, "no") == 0) {
- return 0;
+ return false;
} else {
p11_message ("invalid setting '%s' defaulting to '%s'",
string, default_value ? "yes" : "no");
diff --git a/p11-kit/conf.h b/p11-kit/conf.h
index b70666d..3895b0c 100644
--- a/p11-kit/conf.h
+++ b/p11-kit/conf.h
@@ -50,7 +50,7 @@ enum {
CONF_USER_ONLY
};
-int _p11_conf_merge_defaults (p11_dict *config,
+bool _p11_conf_merge_defaults (p11_dict *config,
p11_dict *defaults);
/* Returns a hash of char *key -> char *value */
@@ -67,7 +67,7 @@ p11_dict * _p11_conf_load_modules (int user_mode,
const char *system_dir,
const char *user_dir);
-int _p11_conf_parse_boolean (const char *string,
- int default_value);
+bool _p11_conf_parse_boolean (const char *string,
+ bool default_value);
#endif /* __CONF_H__ */
diff --git a/p11-kit/modules.c b/p11-kit/modules.c
index e4b0f66..292bf28 100644
--- a/p11-kit/modules.c
+++ b/p11-kit/modules.c
@@ -109,7 +109,7 @@ typedef struct _Module {
/* Initialization, mutex must be held */
p11_mutex_t initialize_mutex;
- int initialize_called;
+ bool initialize_called;
p11_thread_id_t initialize_thread;
} Module;
@@ -183,7 +183,7 @@ free_module_unlocked (void *data)
assert (mod != NULL);
/* Module must be finalized */
- assert (mod->initialize_called == 0);
+ assert (!mod->initialize_called);
assert (mod->initialize_thread == 0);
/* Module must have no outstanding references */
@@ -336,7 +336,7 @@ is_list_delimiter (char ch)
return ch == ',' || isspace (ch);
}
-static int
+static bool
is_string_in_list (const char *list,
const char *string)
{
@@ -344,31 +344,31 @@ is_string_in_list (const char *list,
where = strstr (list, string);
if (where == NULL)
- return 0;
+ return false;
/* Has to be at beginning/end of string, and delimiter before/after */
if (where != list && !is_list_delimiter (*(where - 1)))
- return 0;
+ return false;
where += strlen (string);
return (*where == '\0' || is_list_delimiter (*where));
}
-static int
+static bool
is_module_enabled_unlocked (const char *name,
p11_dict *config)
{
const char *progname;
const char *enable_in;
const char *disable_in;
- int enable = 0;
+ bool enable = false;
enable_in = p11_dict_get (config, "enable-in");
disable_in = p11_dict_get (config, "disable-in");
/* Defaults to enabled if neither of these are set */
if (!enable_in && !disable_in)
- return 1;
+ return true;
progname = _p11_get_progname_unlocked ();
if (enable_in && disable_in)
@@ -475,7 +475,7 @@ load_registered_modules_unlocked (void)
p11_dict *config;
int mode;
CK_RV rv;
- int critical;
+ bool critical;
if (gl.config)
return CKR_OK;
@@ -508,7 +508,7 @@ load_registered_modules_unlocked (void)
assert_not_reached ();
/* Is this a critical module, should abort loading of others? */
- critical = _p11_conf_parse_boolean (p11_dict_get (config, "critical"), 0);
+ critical = _p11_conf_parse_boolean (p11_dict_get (config, "critical"), false);
rv = take_config_and_load_module_unlocked (&name, &config);
@@ -575,7 +575,7 @@ initialize_module_unlocked_reentrant (Module *mod)
/* Module was initialized and C_Finalize should be called */
if (rv == CKR_OK)
- mod->initialize_called = 1;
+ mod->initialize_called = true;
/* Module was already initialized, we don't call C_Finalize */
else if (rv == CKR_CRYPTOKI_ALREADY_INITIALIZED)
@@ -608,7 +608,7 @@ reinitialize_after_fork (void)
if (gl.modules) {
p11_dict_iterate (gl.modules, &iter);
while (p11_dict_next (&iter, NULL, (void **)&mod))
- mod->initialize_called = 0;
+ mod->initialize_called = false;
}
p11_unlock ();
@@ -621,7 +621,7 @@ reinitialize_after_fork (void)
static CK_RV
init_globals_unlocked (void)
{
- static int once = 0;
+ static bool once = false;
if (!gl.modules) {
gl.modules = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal,
@@ -635,7 +635,7 @@ init_globals_unlocked (void)
#ifdef OS_UNIX
pthread_atfork (NULL, NULL, reinitialize_after_fork);
#endif
- once = 1;
+ once = true;
return CKR_OK;
}
@@ -689,7 +689,7 @@ finalize_module_unlocked_reentrant (Module *mod)
assert (mod->funcs);
mod->funcs->C_Finalize (NULL);
- mod->initialize_called = 0;
+ mod->initialize_called = false;
}
p11_mutex_unlock (&mod->initialize_mutex);
@@ -748,7 +748,7 @@ _p11_kit_initialize_registered_unlocked_reentrant (void)
p11_message ("failed to initialize module: %s: %s",
mod->name, p11_kit_strerror (rv));
- critical = _p11_conf_parse_boolean (p11_dict_get (mod->config, "critical"), 0);
+ critical = _p11_conf_parse_boolean (p11_dict_get (mod->config, "critical"), false);
if (!critical) {
p11_debug ("ignoring failure, non-critical module: %s", mod->name);
rv = CKR_OK;
diff --git a/p11-kit/pin.c b/p11-kit/pin.c
index a8be64b..bb65e4c 100644
--- a/p11-kit/pin.c
+++ b/p11-kit/pin.c
@@ -170,7 +170,7 @@ unref_pin_callback (void *pointer)
}
}
-static int
+static bool
register_callback_unlocked (const char *pin_source,
PinCallback *cb)
{
@@ -178,12 +178,12 @@ register_callback_unlocked (const char *pin_source,
char *name;
name = strdup (pin_source);
- return_val_if_fail (name != NULL, -1);
+ return_val_if_fail (name != NULL, false);
if (gl.pin_sources == NULL) {
gl.pin_sources = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal,
free, (p11_destroyer)p11_array_free);
- return_val_if_fail (gl.pin_sources != NULL, -1);
+ return_val_if_fail (gl.pin_sources != NULL, false);
}
if (gl.pin_sources != NULL)
@@ -191,15 +191,15 @@ register_callback_unlocked (const char *pin_source,
if (callbacks == NULL) {
callbacks = p11_array_new (unref_pin_callback);
- return_val_if_fail (callbacks != NULL, -1);
+ return_val_if_fail (callbacks != NULL, false);
if (!p11_dict_set (gl.pin_sources, name, callbacks))
- return_val_if_reached (-1);
+ return_val_if_reached (false);
}
- if (p11_array_push (callbacks, cb) < 0)
- return_val_if_reached (-1);
+ if (!p11_array_push (callbacks, cb))
+ return_val_if_reached (false);
- return 0;
+ return true;
}
/**
@@ -227,7 +227,7 @@ p11_kit_pin_register_callback (const char *pin_source,
p11_kit_pin_destroy_func callback_destroy)
{
PinCallback *cb;
- int ret;
+ bool ret;
return_val_if_fail (pin_source != NULL, -1);
return_val_if_fail (callback != NULL, -1);
@@ -246,7 +246,7 @@ p11_kit_pin_register_callback (const char *pin_source,
p11_unlock ();
- return ret;
+ return ret ? 0 : -1;
}
/**
@@ -685,7 +685,7 @@ p11_kit_pin_ref (P11KitPin *pin)
void
p11_kit_pin_unref (P11KitPin *pin)
{
- int last = 0;
+ bool last = false;
p11_lock ();
diff --git a/p11-kit/tests/conf-test.c b/p11-kit/tests/conf-test.c
index ab3b31d..704313d 100644
--- a/p11-kit/tests/conf-test.c
+++ b/p11-kit/tests/conf-test.c
@@ -107,7 +107,7 @@ test_merge_defaults (CuTest *tc)
p11_dict_set (defaults, strdup ("two"), strdup ("default2"));
p11_dict_set (defaults, strdup ("three"), strdup ("default3"));
- if (_p11_conf_merge_defaults (values, defaults) < 0)
+ if (!_p11_conf_merge_defaults (values, defaults))
CuFail (tc, "should not be reached");
p11_dict_free (defaults);
@@ -247,13 +247,11 @@ test_load_globals_user_sets_invalid (CuTest *tc)
p11_dict_free (config);
}
-static int
+static bool
assert_msg_contains (const char *msg,
const char *text)
{
- if (msg == NULL)
- return 0;
- return strstr (msg, text) ? 1 : 0;
+ return (msg && strstr (msg, text)) ? true : false;
}
static void
@@ -378,6 +376,16 @@ test_load_modules_no_user (CuTest *tc)
p11_dict_free (configs);
}
+static void
+test_parse_boolean (CuTest *tc)
+{
+ p11_message_quiet ();
+
+ CuAssertIntEquals (tc, true, _p11_conf_parse_boolean ("yes", false));
+ CuAssertIntEquals (tc, false, _p11_conf_parse_boolean ("no", true));
+ CuAssertIntEquals (tc, true, _p11_conf_parse_boolean ("!!!", true));
+}
+
int
main (void)
{
@@ -402,6 +410,7 @@ main (void)
SUITE_ADD_TEST (suite, test_load_modules_no_user);
SUITE_ADD_TEST (suite, test_load_modules_user_only);
SUITE_ADD_TEST (suite, test_load_modules_user_none);
+ SUITE_ADD_TEST (suite, test_parse_boolean);
p11_kit_be_quiet ();
diff --git a/p11-kit/tests/mock-module.c b/p11-kit/tests/mock-module.c
index 1a74806..15db600 100644
--- a/p11-kit/tests/mock-module.c
+++ b/p11-kit/tests/mock-module.c
@@ -53,7 +53,7 @@
static p11_mutex_t init_mutex;
/* Whether we've been initialized, and on what process id it happened */
-static int pkcs11_initialized = 0;
+static bool pkcs11_initialized = false;
static pid_t pkcs11_initialized_pid = 0;
/* -----------------------------------------------------------------------------
@@ -141,10 +141,10 @@ mock_C_Initialize (CK_VOID_PTR init_args)
done:
/* Mark us as officially initialized */
if (ret == CKR_OK) {
- pkcs11_initialized = 1;
+ pkcs11_initialized = true;
pkcs11_initialized_pid = pid;
} else if (ret != CKR_CRYPTOKI_ALREADY_INITIALIZED) {
- pkcs11_initialized = 0;
+ pkcs11_initialized = false;
pkcs11_initialized_pid = 0;
}
@@ -158,13 +158,13 @@ CK_RV
mock_C_Finalize (CK_VOID_PTR reserved)
{
debug (("C_Finalize: enter"));
- return_val_if_fail (pkcs11_initialized != 0, CKR_CRYPTOKI_NOT_INITIALIZED);
+ return_val_if_fail (pkcs11_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
return_val_if_fail (reserved == NULL, CKR_ARGUMENTS_BAD);
p11_mutex_lock (&init_mutex);
/* This should stop all other calls in */
- pkcs11_initialized = 0;
+ pkcs11_initialized = false;
pkcs11_initialized_pid = 0;
p11_mutex_unlock (&init_mutex);
@@ -890,9 +890,9 @@ CK_FUNCTION_LIST mock_module_no_slots = {
void
mock_module_init (void)
{
- static int initialized = 0;
+ static bool initialized = false;
if (!initialized) {
p11_mutex_init (&init_mutex);
- initialized = 1;
+ initialized = true;
}
}
diff --git a/p11-kit/tests/uri-test.c b/p11-kit/tests/uri-test.c
index 1920412..11fdebe 100644
--- a/p11-kit/tests/uri-test.c
+++ b/p11-kit/tests/uri-test.c
@@ -210,18 +210,18 @@ test_uri_parse_with_bad_hex_encoding (CuTest *tc)
p11_kit_uri_free (uri);
}
-static int
+static bool
is_space_string (CK_UTF8CHAR_PTR string, CK_ULONG size, const char *check)
{
size_t i, len = strlen (check);
if (len > size)
- return 0;
+ return false;
if (memcmp (string, check, len) != 0)
- return 0;
+ return false;
for (i = len; i < size; ++i)
if (string[i] != ' ')
- return 0;
- return 1;
+ return false;
+ return true;
}
static void
@@ -909,6 +909,36 @@ test_uri_match_module (CuTest *tc)
}
static void
+test_uri_match_version (CuTest *tc)
+{
+ CK_INFO info;
+ P11KitUri *uri;
+ int ret;
+
+ memset (&info, 0, sizeof (info));
+
+ uri = p11_kit_uri_new ();
+ CuAssertPtrNotNull (tc, uri);
+
+ ret = p11_kit_uri_parse ("pkcs11:library-version=5.8", P11_KIT_URI_FOR_ANY, uri);
+ CuAssertIntEquals (tc, P11_KIT_URI_OK, ret);
+
+ info.libraryVersion.major = 5;
+ info.libraryVersion.minor = 8;
+
+ ret = p11_kit_uri_match_module_info (uri, &info);
+ CuAssertIntEquals (tc, 1, ret);
+
+ info.libraryVersion.major = 2;
+ info.libraryVersion.minor = 3;
+
+ ret = p11_kit_uri_match_module_info (uri, &info);
+ CuAssertIntEquals (tc, 0, ret);
+
+ p11_kit_uri_free (uri);
+}
+
+static void
test_uri_match_attributes (CuTest *tc)
{
CK_ATTRIBUTE attrs[4];
@@ -1208,6 +1238,7 @@ main (void)
SUITE_ADD_TEST (suite, test_uri_get_set_unrecognized);
SUITE_ADD_TEST (suite, test_uri_match_token);
SUITE_ADD_TEST (suite, test_uri_match_module);
+ SUITE_ADD_TEST (suite, test_uri_match_version);
SUITE_ADD_TEST (suite, test_uri_match_attributes);
SUITE_ADD_TEST (suite, test_uri_get_set_attribute);
SUITE_ADD_TEST (suite, test_uri_get_set_attributes);
diff --git a/p11-kit/uri.c b/p11-kit/uri.c
index 8828188..9678358 100644
--- a/p11-kit/uri.c
+++ b/p11-kit/uri.c
@@ -136,7 +136,7 @@
*/
struct p11_kit_uri {
- int unrecognized;
+ bool unrecognized;
CK_INFO module;
CK_TOKEN_INFO token;
CK_ATTRIBUTE *attrs;
@@ -202,8 +202,11 @@ url_decode (const char *value, const char *end,
return P11_KIT_URI_OK;
}
-static char*
-url_encode (const unsigned char *value, const unsigned char *end, size_t *length, int force)
+static char *
+url_encode (const unsigned char *value,
+ const unsigned char *end,
+ size_t *length,
+ bool force)
{
char *p;
char *result;
@@ -262,7 +265,7 @@ key_decode (const char *value, const char *end)
return key;
}
-static int
+static bool
match_struct_string (const unsigned char *inuri, const unsigned char *real,
size_t length)
{
@@ -272,19 +275,19 @@ match_struct_string (const unsigned char *inuri, const unsigned char *real,
/* NULL matches anything */
if (inuri[0] == 0)
- return 1;
+ return true;
- return memcmp (inuri, real, length) == 0 ? 1 : 0;
+ return memcmp (inuri, real, length) == 0 ? true : false;
}
-static int
+static bool
match_struct_version (CK_VERSION_PTR inuri, CK_VERSION_PTR real)
{
/* This matches anything */
if (inuri->major == (CK_BYTE)-1 && inuri->minor == (CK_BYTE)-1)
- return 1;
+ return true;
- return memcmp (inuri, real, sizeof (CK_VERSION));
+ return memcmp (inuri, real, sizeof (CK_VERSION)) == 0 ? true : false;
}
/**
@@ -594,7 +597,7 @@ void
p11_kit_uri_set_unrecognized (P11KitUri *uri, int unrecognized)
{
return_if_fail (uri != NULL);
- uri->unrecognized = unrecognized;
+ uri->unrecognized = unrecognized ? true : false;
}
/**
@@ -700,22 +703,25 @@ p11_kit_uri_new (void)
return uri;
}
-static int
-format_raw_string (char **string, size_t *length, int *is_first,
- const char *name, const char *value)
+static bool
+format_raw_string (char **string,
+ size_t *length,
+ bool *is_first,
+ const char *name,
+ const char *value)
{
size_t namelen;
size_t vallen;
/* Not set */
if (!value)
- return 1;
+ return true;
namelen = strlen (name);
vallen = strlen (value);
*string = realloc (*string, *length + namelen + vallen + 3);
- return_val_if_fail (*string != NULL, 0);
+ return_val_if_fail (*string != NULL, false);
if (!*is_first)
(*string)[(*length)++] = ';';
@@ -725,21 +731,25 @@ format_raw_string (char **string, size_t *length, int *is_first,
memcpy ((*string) + *length, value, vallen);
*length += vallen;
(*string)[*length] = 0;
- *is_first = 0;
+ *is_first = false;
- return 1;
+ return true;
}
-static int
-format_encode_string (char **string, size_t *length, int *is_first,
- const char *name, const unsigned char *value,
- size_t n_value, int force)
+static bool
+format_encode_string (char **string,
+ size_t *length,
+ bool *is_first,
+ const char *name,
+ const unsigned char *value,
+ size_t n_value,
+ bool force)
{
char *encoded;
- int ret;
+ bool ret;
encoded = url_encode (value, value + n_value, NULL, force);
- return_val_if_fail (encoded != NULL, 0);
+ return_val_if_fail (encoded != NULL, false);
ret = format_raw_string (string, length, is_first, name, encoded);
free (encoded);
@@ -747,45 +757,54 @@ format_encode_string (char **string, size_t *length, int *is_first,
}
-static int
-format_struct_string (char **string, size_t *length, int *is_first,
- const char *name, const unsigned char *value,
+static bool
+format_struct_string (char **string,
+ size_t *length,
+ bool *is_first,
+ const char *name,
+ const unsigned char *value,
size_t value_max)
{
size_t len;
/* Not set */
if (!value[0])
- return 1;
+ return true;
len = p11_kit_space_strlen (value, value_max);
- return format_encode_string (string, length, is_first, name, value, len, 0);
+ return format_encode_string (string, length, is_first, name, value, len, false);
}
-static int
-format_attribute_string (char **string, size_t *length, int *is_first,
- const char *name, CK_ATTRIBUTE_PTR attr,
- int force)
+static bool
+format_attribute_string (char **string,
+ size_t *length,
+ bool *is_first,
+ const char *name,
+ CK_ATTRIBUTE_PTR attr,
+ bool force)
{
/* Not set */;
if (attr == NULL)
- return 1;
+ return true;
return format_encode_string (string, length, is_first, name,
attr->pValue, attr->ulValueLen,
force);
}
-static int
-format_attribute_class (char **string, size_t *length, int *is_first,
- const char *name, CK_ATTRIBUTE_PTR attr)
+static bool
+format_attribute_class (char **string,
+ size_t *length,
+ bool *is_first,
+ const char *name,
+ CK_ATTRIBUTE_PTR attr)
{
CK_OBJECT_CLASS klass;
const char *value;
/* Not set */;
if (attr == NULL)
- return 1;
+ return true;
klass = *((CK_OBJECT_CLASS*)attr->pValue);
switch (klass) {
@@ -805,21 +824,24 @@ format_attribute_class (char **string, size_t *length, int *is_first,
value = "private";
break;
default:
- return 1;
+ return true;
}
return format_raw_string (string, length, is_first, name, value);
}
-static int
-format_struct_version (char **string, size_t *length, int *is_first,
- const char *name, CK_VERSION_PTR version)
+static bool
+format_struct_version (char **string,
+ size_t *length,
+ bool *is_first,
+ const char *name,
+ CK_VERSION_PTR version)
{
char buffer[64];
/* Not set */
if (version->major == (CK_BYTE)-1 && version->minor == (CK_BYTE)-1)
- return 1;
+ return true;
snprintf (buffer, sizeof (buffer), "%d.%d",
(int)version->major, (int)version->minor);
@@ -859,7 +881,7 @@ p11_kit_uri_format (P11KitUri *uri, P11KitUriType uri_type, char **string)
{
char *result = NULL;
size_t length = 0;
- int is_first = 1;
+ bool is_first = true;
return_val_if_fail (uri != NULL, P11_KIT_URI_UNEXPECTED);
return_val_if_fail (string != NULL, P11_KIT_URI_UNEXPECTED);
@@ -910,10 +932,10 @@ p11_kit_uri_format (P11KitUri *uri, P11KitUriType uri_type, char **string)
if ((uri_type & P11_KIT_URI_FOR_OBJECT) == P11_KIT_URI_FOR_OBJECT) {
if (!format_attribute_string (&result, &length, &is_first, "id",
p11_kit_uri_get_attribute (uri, CKA_ID),
- 1) ||
+ true) ||
!format_attribute_string (&result, &length, &is_first, "object",
p11_kit_uri_get_attribute (uri, CKA_LABEL),
- 0)) {
+ false)) {
return_val_if_reached (P11_KIT_URI_UNEXPECTED);
}
@@ -992,7 +1014,7 @@ parse_class_attribute (const char *name, const char *start, const char *end,
klass = CKO_DATA;
else {
free (value);
- uri->unrecognized = 1;
+ uri->unrecognized = true;
return 1;
}
@@ -1026,7 +1048,7 @@ parse_struct_info (unsigned char *where, size_t length, const char *start,
/* Too long, shouldn't match anything */
if (value_length > length) {
free (value);
- uri->unrecognized = 1;
+ uri->unrecognized = true;
return 1;
}
@@ -1266,7 +1288,7 @@ p11_kit_uri_parse (const char *string, P11KitUriType uri_type,
if (ret < 0)
return ret;
if (ret == 0)
- uri->unrecognized = 1;
+ uri->unrecognized = true;
if (*spos == '\0')
break;