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