summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@collabora.co.uk>2011-06-07 12:58:38 +0000
committerStef Walter <stefw@collabora.co.uk>2011-06-07 12:58:38 +0000
commitb9a8a140cf09780671402e872130a51ec4f4b014 (patch)
tree63f7d4bbb427ef90f473b6c30e1567ff5281839a
parentb315f99c90d01104d6baa91ca0f2cfb32c920abd (diff)
Add p11_kit_space_strdup() function, and rename p11_kit_space_strlen()
* Print out module info in p11-kit tool.
-rw-r--r--p11-kit/p11-kit.h6
-rw-r--r--p11-kit/uri.c15
-rw-r--r--p11-kit/uri.h3
-rw-r--r--p11-kit/util.c34
-rw-r--r--tools/p11-kit.c28
5 files changed, 69 insertions, 17 deletions
diff --git a/p11-kit/p11-kit.h b/p11-kit/p11-kit.h
index f60e4ae..96b9df3 100644
--- a/p11-kit/p11-kit.h
+++ b/p11-kit/p11-kit.h
@@ -72,6 +72,12 @@ CK_RV p11_kit_load_initialize_module (const char *module_p
const char* p11_kit_strerror (CK_RV rv);
+size_t p11_kit_space_strlen (const unsigned char *string,
+ size_t max_length);
+
+char* p11_kit_space_strdup (const unsigned char *string,
+ size_t max_length);
+
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/p11-kit/uri.c b/p11-kit/uri.c
index 4f8e251..3075cae 100644
--- a/p11-kit/uri.c
+++ b/p11-kit/uri.c
@@ -37,6 +37,7 @@
#define DEBUG_FLAG DEBUG_URI
#include "debug.h"
#include "pkcs11.h"
+#include "p11-kit.h"
#include "uri.h"
#include "util.h"
@@ -733,18 +734,6 @@ p11_kit_uri_new (void)
return uri;
}
-size_t
-p11_kit_uri_space_strlen (const unsigned char *string, size_t max_length)
-{
- size_t i = max_length - 1;
-
- assert (string);
-
- while (i > 0 && string[i] == ' ')
- --i;
- return i + 1;
-}
-
static int
format_raw_string (char **string, size_t *length, int *is_first,
const char *name, const char *value)
@@ -805,7 +794,7 @@ format_struct_string (char **string, size_t *length, int *is_first,
if (!value[0])
return 1;
- len = p11_kit_uri_space_strlen (value, value_max);
+ len = p11_kit_space_strlen (value, value_max);
return format_encode_string (string, length, is_first, name, value, len);
}
diff --git a/p11-kit/uri.h b/p11-kit/uri.h
index 2ce56e6..9f1f516 100644
--- a/p11-kit/uri.h
+++ b/p11-kit/uri.h
@@ -143,9 +143,6 @@ void p11_kit_uri_free (P11KitUri *uri);
const char* p11_kit_uri_message (int code);
-size_t p11_kit_uri_space_strlen (const unsigned char *string,
- size_t max_length);
-
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/p11-kit/util.c b/p11-kit/util.c
index 2b9e79c..ead18cc 100644
--- a/p11-kit/util.c
+++ b/p11-kit/util.c
@@ -36,9 +36,12 @@
#include "config.h"
+#include "p11-kit.h"
#include "util.h"
+#include <assert.h>
#include <stdlib.h>
+#include <string.h>
void*
xrealloc (void *memory, size_t length)
@@ -48,3 +51,34 @@ xrealloc (void *memory, size_t length)
free (memory);
return allocated;
}
+
+size_t
+p11_kit_space_strlen (const unsigned char *string, size_t max_length)
+{
+ size_t i = max_length - 1;
+
+ assert (string);
+
+ while (i > 0 && string[i] == ' ')
+ --i;
+ return i + 1;
+}
+
+char*
+p11_kit_space_strdup (const unsigned char *string, size_t max_length)
+{
+ size_t length;
+ char *result;
+
+ assert (string);
+
+ length = p11_kit_space_strlen (string, max_length);
+
+ result = malloc (length + 1);
+ if (!result)
+ return NULL;
+
+ memcpy (result, string, length);
+ result[length] = 0;
+ return result;
+}
diff --git a/tools/p11-kit.c b/tools/p11-kit.c
index 175b561..298c56d 100644
--- a/tools/p11-kit.c
+++ b/tools/p11-kit.c
@@ -41,7 +41,8 @@
#include <stdlib.h>
#include <unistd.h>
-#include "p11-kit.h"
+#include "p11-kit/p11-kit.h"
+#include "p11-kit/uri.h"
typedef int (*operation) (int argc, char *argv[]);
int verbose = 0;
@@ -54,6 +55,30 @@ usage (void)
exit (2);
}
+static void
+print_module_info (CK_FUNCTION_LIST_PTR module)
+{
+ CK_INFO info;
+ char *value;
+ CK_RV rv;
+
+ rv = (module->C_GetInfo) (&info);
+ if (rv != CKR_OK) {
+ warnx ("couldn't load module info: %s", p11_kit_strerror (rv));
+ return;
+ }
+
+ value = p11_kit_space_strdup (info.libraryDescription,
+ sizeof (info.libraryDescription));
+ printf ("\tlibrary-description: %s\n", value);
+ free (value);
+
+ value = p11_kit_space_strdup (info.manufacturerID,
+ sizeof (info.manufacturerID));
+ printf ("\tlibrary-manufacturer: %s\n", value);
+ free (value);
+}
+
static int
list_modules (int argc, char *argv[])
{
@@ -79,6 +104,7 @@ list_modules (int argc, char *argv[])
printf ("%s: %s\n",
name ? name : "(null)",
path ? path : "(null)");
+ print_module_info (module_list[i]);
free (name);
free (path);