2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
14 #include "internal/cryptlib.h"
15 #include <openssl/err.h>
17 long BIO_debug_callback(BIO *bio, int cmd, const char *argp,
18 int argi, long argl, long ret)
27 if (BIO_CB_RETURN & cmd)
30 len = BIO_snprintf(buf, sizeof buf, "BIO[%p]: ", (void *)bio);
32 /* Ignore errors and continue printing the other information. */
36 p_maxlen = sizeof(buf) - len;
40 BIO_snprintf(p, p_maxlen, "Free - %s\n", bio->method->name);
43 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
44 BIO_snprintf(p, p_maxlen, "read(%d,%lu) - %s fd=%d\n",
45 bio->num, (unsigned long)argi,
46 bio->method->name, bio->num);
48 BIO_snprintf(p, p_maxlen, "read(%d,%lu) - %s\n",
49 bio->num, (unsigned long)argi, bio->method->name);
52 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
53 BIO_snprintf(p, p_maxlen, "write(%d,%lu) - %s fd=%d\n",
54 bio->num, (unsigned long)argi,
55 bio->method->name, bio->num);
57 BIO_snprintf(p, p_maxlen, "write(%d,%lu) - %s\n",
58 bio->num, (unsigned long)argi, bio->method->name);
61 BIO_snprintf(p, p_maxlen, "puts() - %s\n", bio->method->name);
64 BIO_snprintf(p, p_maxlen, "gets(%lu) - %s\n", (unsigned long)argi,
68 BIO_snprintf(p, p_maxlen, "ctrl(%lu) - %s\n", (unsigned long)argi,
71 case BIO_CB_RETURN | BIO_CB_READ:
72 BIO_snprintf(p, p_maxlen, "read return %ld\n", ret);
74 case BIO_CB_RETURN | BIO_CB_WRITE:
75 BIO_snprintf(p, p_maxlen, "write return %ld\n", ret);
77 case BIO_CB_RETURN | BIO_CB_GETS:
78 BIO_snprintf(p, p_maxlen, "gets return %ld\n", ret);
80 case BIO_CB_RETURN | BIO_CB_PUTS:
81 BIO_snprintf(p, p_maxlen, "puts return %ld\n", ret);
83 case BIO_CB_RETURN | BIO_CB_CTRL:
84 BIO_snprintf(p, p_maxlen, "ctrl return %ld\n", ret);
87 BIO_snprintf(p, p_maxlen, "bio callback - unknown type (%d)\n", cmd);
91 b = (BIO *)bio->cb_arg;
93 BIO_write(b, buf, strlen(buf));
94 #if !defined(OPENSSL_NO_STDIO)