2016-05-17 19:38:09 +00:00
|
|
|
/*
|
2017-09-28 21:27:04 +00:00
|
|
|
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 10:52:47 +00:00
|
|
|
*
|
2018-12-06 12:39:21 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 19:38:09 +00: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 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/crypto.h>
|
|
|
|
#include <openssl/buffer.h>
|
|
|
|
#include <openssl/err.h>
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
|
|
|
|
void *u)
|
|
|
|
{
|
|
|
|
unsigned long l;
|
|
|
|
char buf[256];
|
|
|
|
char buf2[4096];
|
|
|
|
const char *file, *data;
|
|
|
|
int line, flags;
|
2016-03-09 10:35:53 +00:00
|
|
|
/*
|
|
|
|
* We don't know what kind of thing CRYPTO_THREAD_ID is. Here is our best
|
|
|
|
* attempt to convert it into something we can print.
|
|
|
|
*/
|
|
|
|
union {
|
|
|
|
CRYPTO_THREAD_ID tid;
|
|
|
|
unsigned long ltid;
|
|
|
|
} tid;
|
|
|
|
|
|
|
|
tid.ltid = 0;
|
|
|
|
tid.tid = CRYPTO_THREAD_get_current_id();
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
|
2017-12-07 18:39:34 +00:00
|
|
|
ERR_error_string_n(l, buf, sizeof(buf));
|
2016-03-09 10:35:53 +00:00
|
|
|
BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", tid.ltid, buf,
|
2015-01-22 03:40:55 +00:00
|
|
|
file, line, (flags & ERR_TXT_STRING) ? data : "");
|
|
|
|
if (cb(buf2, strlen(buf2), u) <= 0)
|
|
|
|
break; /* abort outputting the error report */
|
|
|
|
}
|
|
|
|
}
|
2001-06-23 15:06:17 +00:00
|
|
|
|
2001-06-25 10:09:55 +00:00
|
|
|
static int print_bio(const char *str, size_t len, void *bp)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
return BIO_write((BIO *)bp, str, len);
|
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
void ERR_print_errors(BIO *bp)
|
|
|
|
{
|
|
|
|
ERR_print_errors_cb(print_bio, bp);
|
|
|
|
}
|
2016-03-18 23:40:11 +00: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
|