2016-05-18 02:52:22 +08:00
|
|
|
/*
|
2017-07-06 12:11:27 +08:00
|
|
|
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2018-12-06 20:20:10 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:52:22 +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>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "bio_local.h"
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/err.h>
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-13 06:29:26 +08:00
|
|
|
long BIO_debug_callback(BIO *bio, int cmd, const char *argp,
|
2015-01-22 11:40:55 +08:00
|
|
|
int argi, long argl, long ret)
|
|
|
|
{
|
|
|
|
BIO *b;
|
2015-01-24 00:58:26 +08:00
|
|
|
char buf[256];
|
2015-01-22 11:40:55 +08:00
|
|
|
char *p;
|
|
|
|
long r = 1;
|
2017-07-06 12:11:27 +08:00
|
|
|
int len, left;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (BIO_CB_RETURN & cmd)
|
|
|
|
r = ret;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2017-07-06 12:11:27 +08:00
|
|
|
len = BIO_snprintf(buf, sizeof(buf), "BIO[%p]: ", (void *)bio);
|
2014-09-21 14:14:11 +08:00
|
|
|
|
2016-03-09 06:44:57 +08:00
|
|
|
/* Ignore errors and continue printing the other information. */
|
|
|
|
if (len < 0)
|
|
|
|
len = 0;
|
2014-09-21 14:14:11 +08:00
|
|
|
p = buf + len;
|
2017-07-06 12:11:27 +08:00
|
|
|
left = sizeof(buf) - len;
|
2014-09-21 14:14:11 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case BIO_CB_FREE:
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "Free - %s\n", bio->method->name);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
case BIO_CB_READ:
|
|
|
|
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "read(%d,%lu) - %s fd=%d\n",
|
|
|
|
bio->num, (unsigned long)argi,
|
|
|
|
bio->method->name, bio->num);
|
2015-01-22 11:40:55 +08:00
|
|
|
else
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "read(%d,%lu) - %s\n",
|
2017-06-15 08:34:37 +08:00
|
|
|
bio->num, (unsigned long)argi, bio->method->name);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
case BIO_CB_WRITE:
|
|
|
|
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "write(%d,%lu) - %s fd=%d\n",
|
|
|
|
bio->num, (unsigned long)argi,
|
|
|
|
bio->method->name, bio->num);
|
2015-01-22 11:40:55 +08:00
|
|
|
else
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "write(%d,%lu) - %s\n",
|
|
|
|
bio->num, (unsigned long)argi, bio->method->name);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
case BIO_CB_PUTS:
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "puts() - %s\n", bio->method->name);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
case BIO_CB_GETS:
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "gets(%lu) - %s\n", (unsigned long)argi,
|
|
|
|
bio->method->name);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
case BIO_CB_CTRL:
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "ctrl(%lu) - %s\n", (unsigned long)argi,
|
|
|
|
bio->method->name);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
case BIO_CB_RETURN | BIO_CB_READ:
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "read return %ld\n", ret);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
case BIO_CB_RETURN | BIO_CB_WRITE:
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "write return %ld\n", ret);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
case BIO_CB_RETURN | BIO_CB_GETS:
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "gets return %ld\n", ret);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
case BIO_CB_RETURN | BIO_CB_PUTS:
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "puts return %ld\n", ret);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
case BIO_CB_RETURN | BIO_CB_CTRL:
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "ctrl return %ld\n", ret);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
default:
|
2017-07-06 12:11:27 +08:00
|
|
|
BIO_snprintf(p, left, "bio callback - unknown type (%d)\n", cmd);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
b = (BIO *)bio->cb_arg;
|
|
|
|
if (b != NULL)
|
|
|
|
BIO_write(b, buf, strlen(buf));
|
2015-01-13 06:29:26 +08:00
|
|
|
#if !defined(OPENSSL_NO_STDIO)
|
2015-01-22 11:40:55 +08:00
|
|
|
else
|
|
|
|
fputs(buf, stderr);
|
1998-12-21 18:52:47 +08:00
|
|
|
#endif
|
2017-07-06 12:11:27 +08:00
|
|
|
return r;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|