diff options
author | Stef Walter <stefw@collabora.co.uk> | 2011-05-25 11:44:40 +0200 |
---|---|---|
committer | Stef Walter <stefw@collabora.co.uk> | 2011-05-25 11:44:40 +0200 |
commit | 7c2a8a5b3ad134b6e3093761d617936dcbd21adf (patch) | |
tree | 20061e7726a61ca86a211b8549315d97d3f138d4 /p11-kit | |
parent | a01f4351e34fee946d1ffb81baa31a756e2851be (diff) |
Add p11_kit_uri_message() function.
Gets messages for p11-kit error codes.
Diffstat (limited to 'p11-kit')
-rw-r--r-- | p11-kit/debug.c | 1 | ||||
-rw-r--r-- | p11-kit/debug.h | 3 | ||||
-rw-r--r-- | p11-kit/p11-kit-uri.c | 38 | ||||
-rw-r--r-- | p11-kit/p11-kit-uri.h | 2 |
4 files changed, 43 insertions, 1 deletions
diff --git a/p11-kit/debug.c b/p11-kit/debug.c index a7b75ad..eb7eef0 100644 --- a/p11-kit/debug.c +++ b/p11-kit/debug.c @@ -53,6 +53,7 @@ struct DebugKey { static struct DebugKey debug_keys[] = { { "lib", DEBUG_LIB }, { "conf", DEBUG_CONF }, + { "uri", DEBUG_URI }, { 0, } }; diff --git a/p11-kit/debug.h b/p11-kit/debug.h index 5d244f3..47e5cc4 100644 --- a/p11-kit/debug.h +++ b/p11-kit/debug.h @@ -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; diff --git a/p11-kit/p11-kit-uri.c b/p11-kit/p11-kit-uri.c index 5004ba1..0e9010c 100644 --- a/p11-kit/p11-kit-uri.c +++ b/p11-kit/p11-kit-uri.c @@ -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"; + } +} diff --git a/p11-kit/p11-kit-uri.h b/p11-kit/p11-kit-uri.h index 27abf6c..b6af4ff 100644 --- a/p11-kit/p11-kit-uri.h +++ b/p11-kit/p11-kit-uri.h @@ -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 |