]> granicus.if.org Git - p11-kit/commitdiff
Add p11_kit_space_strdup() function, and rename p11_kit_space_strlen()
authorStef Walter <stefw@collabora.co.uk>
Tue, 7 Jun 2011 12:58:38 +0000 (12:58 +0000)
committerStef Walter <stefw@collabora.co.uk>
Tue, 7 Jun 2011 12:58:38 +0000 (12:58 +0000)
 * Print out module info in p11-kit tool.

p11-kit/p11-kit.h
p11-kit/uri.c
p11-kit/uri.h
p11-kit/util.c
tools/p11-kit.c

index f60e4ae69408e4d3b752b1058ab8615a2e958948..96b9df35be0c9a7e1948d4ff64588cab32007614 100644 (file)
@@ -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
index 4f8e251216a05977f3bc41b6a73fb49d1de61b55..3075cae36ceea42fcf18de6b3e000ebc7a235dc4 100644 (file)
@@ -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);
 }
 
index 2ce56e6886a8d42c00eb46103995ccfeec65dff0..9f1f51679b67169328e197fae201895afb17cd0e 100644 (file)
@@ -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
index 2b9e79cd1645da387dd28dcbd19e6c66c058ce19..ead18cc6b98dc9b015edfeea235c8d301820b97f 100644 (file)
 
 #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;
+}
index 175b561fae98967ad03a0f5500571ab0c35181ef..298c56d46bf141f560a8f0f03ba195a7a1ba3018 100644 (file)
@@ -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);