2016-05-17 18:52:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 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;
|
2014-09-21 06:14:11 +00:00
|
|
|
int len;
|
2015-01-22 03:40:55 +00:00
|
|
|
size_t p_maxlen;
|
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
|
|
|
|
2016-07-28 19:15:52 +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;
|
|
|
|
p_maxlen = sizeof(buf) - len;
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case BIO_CB_FREE:
|
|
|
|
BIO_snprintf(p, p_maxlen, "Free - %s\n", bio->method->name);
|
|
|
|
break;
|
|
|
|
case BIO_CB_READ:
|
|
|
|
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
|
|
|
|
BIO_snprintf(p, p_maxlen, "read(%d,%lu) - %s fd=%d\n",
|
|
|
|
bio->num, (unsigned long)argi,
|
|
|
|
bio->method->name, bio->num);
|
|
|
|
else
|
|
|
|
BIO_snprintf(p, p_maxlen, "read(%d,%lu) - %s\n",
|
|
|
|
bio->num, (unsigned long)argi, bio->method->name);
|
|
|
|
break;
|
|
|
|
case BIO_CB_WRITE:
|
|
|
|
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
|
|
|
|
BIO_snprintf(p, p_maxlen, "write(%d,%lu) - %s fd=%d\n",
|
|
|
|
bio->num, (unsigned long)argi,
|
|
|
|
bio->method->name, bio->num);
|
|
|
|
else
|
|
|
|
BIO_snprintf(p, p_maxlen, "write(%d,%lu) - %s\n",
|
|
|
|
bio->num, (unsigned long)argi, bio->method->name);
|
|
|
|
break;
|
|
|
|
case BIO_CB_PUTS:
|
|
|
|
BIO_snprintf(p, p_maxlen, "puts() - %s\n", bio->method->name);
|
|
|
|
break;
|
|
|
|
case BIO_CB_GETS:
|
|
|
|
BIO_snprintf(p, p_maxlen, "gets(%lu) - %s\n", (unsigned long)argi,
|
|
|
|
bio->method->name);
|
|
|
|
break;
|
|
|
|
case BIO_CB_CTRL:
|
|
|
|
BIO_snprintf(p, p_maxlen, "ctrl(%lu) - %s\n", (unsigned long)argi,
|
|
|
|
bio->method->name);
|
|
|
|
break;
|
|
|
|
case BIO_CB_RETURN | BIO_CB_READ:
|
|
|
|
BIO_snprintf(p, p_maxlen, "read return %ld\n", ret);
|
|
|
|
break;
|
|
|
|
case BIO_CB_RETURN | BIO_CB_WRITE:
|
|
|
|
BIO_snprintf(p, p_maxlen, "write return %ld\n", ret);
|
|
|
|
break;
|
|
|
|
case BIO_CB_RETURN | BIO_CB_GETS:
|
|
|
|
BIO_snprintf(p, p_maxlen, "gets return %ld\n", ret);
|
|
|
|
break;
|
|
|
|
case BIO_CB_RETURN | BIO_CB_PUTS:
|
|
|
|
BIO_snprintf(p, p_maxlen, "puts return %ld\n", ret);
|
|
|
|
break;
|
|
|
|
case BIO_CB_RETURN | BIO_CB_CTRL:
|
|
|
|
BIO_snprintf(p, p_maxlen, "ctrl return %ld\n", ret);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BIO_snprintf(p, p_maxlen, "bio callback - unknown type (%d)\n", cmd);
|
|
|
|
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
|
2015-01-22 03:40:55 +00:00
|
|
|
return (r);
|
|
|
|
}
|