2016-05-18 03:38:09 +08:00
|
|
|
/*
|
2019-06-20 09:24:17 +08:00
|
|
|
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2018-12-06 20:39:21 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 03:38:09 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/crypto.h>
|
|
|
|
#include <openssl/buffer.h>
|
|
|
|
#include <openssl/err.h>
|
2019-09-05 04:14:21 +08:00
|
|
|
#include "err_locl.h"
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
|
|
|
|
void *u)
|
|
|
|
{
|
2019-06-20 09:24:17 +08:00
|
|
|
CRYPTO_THREAD_ID tid = CRYPTO_THREAD_get_current_id();
|
2015-01-22 11:40:55 +08:00
|
|
|
unsigned long l;
|
2019-09-05 04:14:21 +08:00
|
|
|
char buf[4096], *hex;
|
|
|
|
const char *lib, *reason;
|
|
|
|
const char *file, *data, *func;
|
2015-01-22 11:40:55 +08:00
|
|
|
int line, flags;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2019-09-05 04:14:21 +08:00
|
|
|
while ((l = ERR_get_error_all(&file, &line, &func, &data, &flags)) != 0) {
|
|
|
|
lib = ERR_lib_error_string(l);
|
|
|
|
reason = ERR_reason_error_string(l);
|
|
|
|
if (func == NULL)
|
|
|
|
func = "unknown function";
|
|
|
|
if ((flags & ERR_TXT_STRING) == 0)
|
|
|
|
data = "";
|
2019-06-20 09:24:17 +08:00
|
|
|
hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
|
2019-09-05 04:14:21 +08:00
|
|
|
BIO_snprintf(buf, sizeof(buf), "%s:error:%s:%s:%s:%s:%d:%s\n",
|
|
|
|
hex, lib, func, reason, file, line, data);
|
2019-06-20 09:24:17 +08:00
|
|
|
OPENSSL_free(hex);
|
2019-09-05 04:14:21 +08:00
|
|
|
if (cb(buf, strlen(buf), u) <= 0)
|
2015-01-22 11:40:55 +08:00
|
|
|
break; /* abort outputting the error report */
|
|
|
|
}
|
|
|
|
}
|
2001-06-23 23:06:17 +08:00
|
|
|
|
2001-06-25 18:09:55 +08:00
|
|
|
static int print_bio(const char *str, size_t len, void *bp)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
return BIO_write((BIO *)bp, str, len);
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
void ERR_print_errors(BIO *bp)
|
|
|
|
{
|
|
|
|
ERR_print_errors_cb(print_bio, bp);
|
|
|
|
}
|
2016-03-19 07:40:11 +08:00
|
|
|
|
|
|
|
#ifndef OPENSSL_NO_STDIO
|
|
|
|
void ERR_print_errors_fp(FILE *fp)
|
|
|
|
{
|
|
|
|
BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE);
|
|
|
|
if (bio == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ERR_print_errors_cb(print_bio, bio);
|
|
|
|
BIO_free(bio);
|
|
|
|
}
|
|
|
|
#endif
|