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)
27 BIO_MMSG_CB_ARGS *args;
30 if (processed != NULL)
33 left = BIO_snprintf(buf, sizeof(buf), "BIO[%p]: ", (void *)bio);
35 /* Ignore errors and continue printing the other information. */
39 left = sizeof(buf) - left;
43 BIO_snprintf(p, left, "Free - %s\n", bio->method->name);
46 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
47 BIO_snprintf(p, left, "read(%d,%zu) - %s fd=%d\n",
49 bio->method->name, bio->num);
51 BIO_snprintf(p, left, "read(%d,%zu) - %s\n",
52 bio->num, len, bio->method->name);
55 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
56 BIO_snprintf(p, left, "write(%d,%zu) - %s fd=%d\n",
58 bio->method->name, bio->num);
60 BIO_snprintf(p, left, "write(%d,%zu) - %s\n",
61 bio->num, len, bio->method->name);
64 BIO_snprintf(p, left, "puts() - %s\n", bio->method->name);
67 BIO_snprintf(p, left, "gets(%zu) - %s\n", len,
71 BIO_snprintf(p, left, "ctrl(%d) - %s\n", argi,
75 args = (BIO_MMSG_CB_ARGS *)argp;
76 BIO_snprintf(p, left, "recvmmsg(%zu) - %s",
77 args->num_msg, bio->method->name);
80 args = (BIO_MMSG_CB_ARGS *)argp;
81 BIO_snprintf(p, left, "sendmmsg(%zu) - %s",
82 args->num_msg, bio->method->name);
84 case BIO_CB_RETURN | BIO_CB_READ:
85 BIO_snprintf(p, left, "read return %d processed: %zu\n", ret, l);
87 case BIO_CB_RETURN | BIO_CB_WRITE:
88 BIO_snprintf(p, left, "write return %d processed: %zu\n", ret, l);
90 case BIO_CB_RETURN | BIO_CB_GETS:
91 BIO_snprintf(p, left, "gets return %d processed: %zu\n", ret, l);
93 case BIO_CB_RETURN | BIO_CB_PUTS:
94 BIO_snprintf(p, left, "puts return %d processed: %zu\n", ret, l);
96 case BIO_CB_RETURN | BIO_CB_CTRL:
97 BIO_snprintf(p, left, "ctrl return %d\n", ret);
99 case BIO_CB_RETURN | BIO_CB_RECVMMSG:
100 BIO_snprintf(p, left, "recvmmsg processed: %zu\n", len);
103 case BIO_CB_RETURN | BIO_CB_SENDMMSG:
104 BIO_snprintf(p, left, "sendmmsg processed: %zu\n", len);
108 BIO_snprintf(p, left, "bio callback - unknown type (%d)\n", cmd);
112 b = (BIO *)bio->cb_arg;
114 BIO_write(b, buf, strlen(buf));
115 #if !defined(OPENSSL_NO_STDIO)
122 #ifndef OPENSSL_NO_DEPRECATED_3_0
123 long BIO_debug_callback(BIO *bio, int cmd, const char *argp,
124 int argi, long argl, long ret)
126 size_t processed = 0;
129 processed = (size_t)ret;
130 BIO_debug_callback_ex(bio, cmd, argp, (size_t)argi,
131 argi, argl, ret > 0 ? 1 : (int)ret, &processed);