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)
26 if (BIO_CB_RETURN & cmd)
29 len = sprintf(buf, "BIO[%p]: ", (void *)bio);
31 /* Ignore errors and continue printing the other information. */
38 sprintf(p, "Free - %s\n", bio->method->name);
41 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
42 sprintf(p, "read(%d,%lu) - %s fd=%d\n",
43 bio->num, (unsigned long)argi,
44 bio->method->name, bio->num);
46 sprintf(p, "read(%d,%lu) - %s\n",
47 bio->num, (unsigned long)argi, bio->method->name);
50 if (bio->method->type & BIO_TYPE_DESCRIPTOR)
51 sprintf(p, "write(%d,%lu) - %s fd=%d\n",
52 bio->num, (unsigned long)argi,
53 bio->method->name, bio->num);
55 sprintf(p, "write(%d,%lu) - %s\n",
56 bio->num, (unsigned long)argi, bio->method->name);
59 sprintf(p, "puts() - %s\n", bio->method->name);
62 sprintf(p, "gets(%lu) - %s\n", (unsigned long)argi,
66 sprintf(p, "ctrl(%lu) - %s\n", (unsigned long)argi,
69 case BIO_CB_RETURN | BIO_CB_READ:
70 sprintf(p, "read return %ld\n", ret);
72 case BIO_CB_RETURN | BIO_CB_WRITE:
73 sprintf(p, "write return %ld\n", ret);
75 case BIO_CB_RETURN | BIO_CB_GETS:
76 sprintf(p, "gets return %ld\n", ret);
78 case BIO_CB_RETURN | BIO_CB_PUTS:
79 sprintf(p, "puts return %ld\n", ret);
81 case BIO_CB_RETURN | BIO_CB_CTRL:
82 sprintf(p, "ctrl return %ld\n", ret);
85 sprintf(p, "bio callback - unknown type (%d)\n", cmd);
89 b = (BIO *)bio->cb_arg;
91 BIO_write(b, buf, strlen(buf));
92 #if !defined(OPENSSL_NO_STDIO)