Add p11_kit_uri_message() function.
authorStef Walter <stefw@collabora.co.uk>
Wed, 25 May 2011 09:44:40 +0000 (11:44 +0200)
committerStef Walter <stefw@collabora.co.uk>
Wed, 25 May 2011 09:44:40 +0000 (11:44 +0200)
Gets messages for p11-kit error codes.

p11-kit/debug.c
p11-kit/debug.h
p11-kit/p11-kit-uri.c
p11-kit/p11-kit-uri.h

index a7b75adb438dfd66e2b07b497218746af41fb43c..eb7eef05877262ee02c1303223247a961ec496c6 100644 (file)
@@ -53,6 +53,7 @@ struct DebugKey {
 static struct DebugKey debug_keys[] = {
        { "lib", DEBUG_LIB },
        { "conf", DEBUG_CONF },
+       { "uri", DEBUG_URI },
        { 0, }
 };
 
index 5d244f3b9560a9bf31f15ec2a09f223adae3b056..47e5cc4b8312e60aab241b3e3c34a0cf191187f8 100644 (file)
@@ -38,7 +38,8 @@
 /* Please keep this enum in sync with keys in debug.c */
 typedef enum {
        DEBUG_LIB = 1 << 1,
-       DEBUG_CONF = 1 << 2
+       DEBUG_CONF = 1 << 2,
+       DEBUG_URI = 1 << 3
 } DebugFlags;
 
 extern int        debug_current_flags;
index 5004ba123a1c9c2290ad4f9b2ae6c69d5b8c1436..0e9010c55b242310261139d1a8ff3396ca84dff1 100644 (file)
@@ -34,6 +34,8 @@
 
 #include "config.h"
 
+#define DEBUG_FLAG DEBUG_URI
+#include "debug.h"
 #include "pkcs11.h"
 #include "p11-kit-uri.h"
 #include "util.h"
@@ -1193,3 +1195,39 @@ p11_kit_uri_free (P11KitUri *uri)
 
        free (uri);
 }
+
+/**
+ * p11_kit_uri_message:
+ * @code: The error code
+ *
+ * Lookup a message for the uri error code. These codes are the P11_KIT_URI_XXX
+ * error codes that can be returned from p11_kit_uri_parse() or
+ * p11_kit_uri_format(). As a special case %NULL, will be returned for
+ * %P11_KIT_URI_OK.
+ *
+ * Returns: The message for the error code. This string is owned by the p11-kit
+ *      library.
+ */
+const char*
+p11_kit_uri_message (int code)
+{
+       switch (code) {
+       case P11_KIT_URI_OK:
+               return NULL;
+       case P11_KIT_URI_NO_MEMORY:
+               return "Out of memory";
+       case P11_KIT_URI_BAD_SCHEME:
+               return "URI scheme must be 'pkcs11:'";
+       case P11_KIT_URI_BAD_ENCODING:
+               return "URI encoding invalid or corrupted";
+       case P11_KIT_URI_BAD_SYNTAX:
+               return "URI syntax is invalid";
+       case P11_KIT_URI_BAD_VERSION:
+               return "URI version component is invalid";
+       case P11_KIT_URI_NOT_FOUND:
+               return "The URI component was not found";
+       default:
+               debug ("unknown error code: %d", code);
+               return "Unknown error";
+       }
+}
index 27abf6ca10f37c397e58f934f820cf859e68e619..b6af4ffb557d85819defff321d071b766d839e20 100644 (file)
@@ -115,6 +115,8 @@ int                 p11_kit_uri_parse                       (const char *string,
 
 void                p11_kit_uri_free                        (P11KitUri *uri);
 
+const char*         p11_kit_uri_message                     (int code);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif