- slightly improved debugging output

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1399 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
okir 2003-08-29 12:55:17 +00:00
parent ef42ba2010
commit 8fcab2199b
2 changed files with 19 additions and 16 deletions

View File

@ -474,7 +474,13 @@ int sc_create_file(struct sc_card *card, struct sc_file *file)
int r;
assert(card != NULL);
SC_FUNC_CALLED(card->ctx, 1);
if (card->ctx->debug >= 1) {
const sc_path_t *in_path = &file->path;
sc_debug(card->ctx, "called; type=%d, path=%s\n",
in_path->type,
sc_print_path(in_path));
}
if (card->ops->create_file == NULL)
SC_FUNC_RETURN(card->ctx, 1, SC_ERROR_NOT_SUPPORTED);
r = card->ops->create_file(card, file);
@ -486,7 +492,11 @@ int sc_delete_file(struct sc_card *card, const struct sc_path *path)
int r;
assert(card != NULL);
SC_FUNC_CALLED(card->ctx, 1);
if (card->ctx->debug >= 1) {
sc_debug(card->ctx, "called; type=%d, path=%s\n",
path->type,
sc_print_path(path));
}
if (card->ops->delete_file == NULL)
SC_FUNC_RETURN(card->ctx, 1, SC_ERROR_NOT_SUPPORTED);
r = card->ops->delete_file(card, path);
@ -623,6 +633,11 @@ int sc_select_file(struct sc_card *card,
int r;
assert(card != NULL && in_path != NULL);
if (card->ctx->debug >= 1) {
sc_debug(card->ctx, "called; type=%d, path=%s\n",
in_path->type,
sc_print_path(in_path));
}
if (in_path->len > SC_MAX_PATH_SIZE)
SC_FUNC_RETURN(card->ctx, 2, SC_ERROR_INVALID_ARGUMENTS);
if (in_path->type == SC_PATH_TYPE_PATH) {
@ -637,25 +652,13 @@ int sc_select_file(struct sc_card *card,
SC_FUNC_RETURN(card->ctx, 2, SC_ERROR_INVALID_ARGUMENTS);
}
}
if (card->ctx->debug >= 2) {
size_t i;
char line[128], *linep = line;
linep += sprintf(linep, "called with type %d, path ", in_path->type);
for (i = 0; i < in_path->len; i++) {
sprintf(linep, "%02X", in_path->value[i]);
linep += 2;
}
strcpy(linep, "\n");
sc_debug(card->ctx, line);
}
if (card->ops->select_file == NULL)
SC_FUNC_RETURN(card->ctx, 2, SC_ERROR_NOT_SUPPORTED);
r = card->ops->select_file(card, in_path, file);
/* Remember file path */
if (r == 0 && file && *file)
(*file)->path = *in_path;
SC_FUNC_RETURN(card->ctx, 2, r);
SC_FUNC_RETURN(card->ctx, 1, r);
}
int sc_get_challenge(struct sc_card *card, u8 *rnd, size_t len)

View File

@ -62,7 +62,7 @@ void sc_hex_dump(struct sc_context *ctx, const u8 * buf, size_t len, char *out,
#define SC_FUNC_RETURN(ctx, level, r) { \
int _ret = r; \
if (_ret < 0) { \
if (_ret < 0 && ctx->log_errors) { \
sc_do_log(ctx, SC_LOG_TYPE_ERROR, __FILE__, __LINE__, __FUNCTION__, "returning with: %s\n", sc_strerror(_ret)); \
} else if (ctx->debug >= level) { \
sc_do_log(ctx, SC_LOG_TYPE_DEBUG, __FILE__, __LINE__, __FUNCTION__, "returning with: %d\n", _ret); \