Hello,

I would like to commit the attached patch. It enables the textual output
of SC_ERROR return codes in debug messages. Any objections?

Regards
Andre

Index: src/pkcs11/misc.c
===================================================================
--- src/pkcs11/misc.c	(revision 4939)
+++ src/pkcs11/misc.c	(working copy)
@@ -56,7 +56,7 @@
 
 static CK_RV sc_to_cryptoki_error_common(int rc)
 {
-	sc_debug(context, SC_LOG_DEBUG_NORMAL, "opensc error: %s (%d)\n", sc_strerror(rc), rc);
+	sc_debug(context, SC_LOG_DEBUG_NORMAL, "libopensc return value: %d (%s)\n", rc, sc_strerror(rc));
 	switch (rc) {
 	case SC_SUCCESS:
 		return CKR_OK;
Index: src/libopensc/errors.c
===================================================================
--- src/libopensc/errors.c	(revision 4939)
+++ src/libopensc/errors.c	(working copy)
@@ -116,7 +116,7 @@
 		"Unknown error",
 		"PKCS#15 compatible smart card not found",
 	};
-	const char *no_errors = "No errors";
+	const char *no_errors = "Success";
 	const int misc_base = -SC_ERROR_UNKNOWN;
 	const char **errors = NULL;
 	int count = 0, err_base = 0;
Index: src/libopensc/log.h
===================================================================
--- src/libopensc/log.h	(revision 4939)
+++ src/libopensc/log.h	(working copy)
@@ -65,14 +65,21 @@
 
 #define SC_FUNC_RETURN(ctx, level, r) do { \
 	int _ret = r; \
-	sc_do_log(ctx, level, __FILE__, __LINE__, __FUNCTION__, "returning with: %d\n", _ret); \
+	if (_ret <= 0) { \
+		sc_do_log(ctx, level, __FILE__, __LINE__, __FUNCTION__, \
+			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
+	} else { \
+		sc_do_log(ctx, level, __FILE__, __LINE__, __FUNCTION__, \
+			"returning with: %d\n", _ret); \
+	} \
 	return _ret; \
 } while(0)
 
 #define SC_TEST_RET(ctx, level, r, text) do { \
 	int _ret = (r); \
 	if (_ret < 0) { \
-		sc_do_log(ctx, level, __FILE__, __LINE__, __FUNCTION__, "%s: %s\n", (text), sc_strerror(_ret)); \
+		sc_do_log(ctx, level, __FILE__, __LINE__, __FUNCTION__, \
+			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
 		return _ret; \
 	} \
 } while(0)
_______________________________________________
opensc-devel mailing list
[email protected]
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to