2 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
10 #define OPENSSL_SUPPRESS_DEPRECATED
15 #include "bio_local.h"
16 #include "internal/cryptlib.h"
17 #include <openssl/err.h>
19 long BIO_debug_callback_ex(BIO *bio, int cmd, const char *argp, size_t len,
20 int argi, long argl, int ret, size_t *processed)
28 if (processed != NULL)
31 left = BIO_snprintf(buf, sizeof(buf), "BIO[%p]: ", (void *)bio);
33 /* Ignore errors and continue printing the other information. */
37 left = sizeof(buf) - left;
41 BIO_snprintf(p, left, "Free - %s\n", bio->method->name);
44 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
45 BIO_snprintf(p, left, "read(%d,%zu) - %s fd=%d\n",
47 bio->method->name, bio->num);
49 BIO_snprintf(p, left, "read(%d,%zu) - %s\n",
50 bio->num, len, bio->method->name);
53 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
54 BIO_snprintf(p, left, "write(%d,%zu) - %s fd=%d\n",
56 bio->method->name, bio->num);
58 BIO_snprintf(p, left, "write(%d,%zu) - %s\n",
59 bio->num, len, bio->method->name);
62 BIO_snprintf(p, left, "puts() - %s\n", bio->method->name);
65 BIO_snprintf(p, left, "gets(%zu) - %s\n", len,
69 BIO_snprintf(p, left, "ctrl(%d) - %s\n", argi,
72 case BIO_CB_RETURN | BIO_CB_READ:
73 BIO_snprintf(p, left, "read return %d processed: %zu\n", ret, l);
75 case BIO_CB_RETURN | BIO_CB_WRITE:
76 BIO_snprintf(p, left, "write return %d processed: %zu\n", ret, l);
78 case BIO_CB_RETURN | BIO_CB_GETS:
79 BIO_snprintf(p, left, "gets return %d processed: %zu\n", ret, l);
81 case BIO_CB_RETURN | BIO_CB_PUTS:
82 BIO_snprintf(p, left, "puts return %d processed: %zu\n", ret, l);
84 case BIO_CB_RETURN | BIO_CB_CTRL:
85 BIO_snprintf(p, left, "ctrl return %d\n", ret);
88 BIO_snprintf(p, left, "bio callback - unknown type (%d)\n", cmd);
92 b = (BIO *)bio->cb_arg;
94 BIO_write(b, buf, strlen(buf));
95 #if !defined(OPENSSL_NO_STDIO)
102 #ifndef OPENSSL_NO_DEPRECATED_3_0
103 long BIO_debug_callback(BIO *bio, int cmd, const char *argp,
104 int argi, long argl, long ret)
106 size_t processed = 0;
109 processed = (size_t)ret;
110 BIO_debug_callback_ex(bio, cmd, argp, (size_t)argi,
111 argi, argl, ret > 0 ? 1 : (int)ret, &processed);