static int rev_body(char *hostname, int s, int stype, unsigned char *context)
{
    char *buf = NULL;
    int i;
    int ret = 1;
    SSL *con;
    BIO *io, *ssl_bio, *sbio;
    buf = app_malloc(bufsize, "server rev buffer");
    io = BIO_new(BIO_f_buffer());
    ssl_bio = BIO_new(BIO_f_ssl());
    if ((io == NULL) || (ssl_bio == NULL))
        goto err;
    if (!BIO_set_write_buffer_size(io, bufsize))
        goto err;
    if ((con = SSL_new(ctx)) == NULL)
        goto err;
    if (s_tlsextdebug) {
        SSL_set_tlsext_debug_callback(con, tlsext_cb);
        SSL_set_tlsext_debug_arg(con, bio_s_out);
    }
    if (context && !SSL_set_session_id_context(con, context,
                        strlen((char *)context))) {
        ERR_print_errors(bio_err);
        goto err;
    }
    sbio = BIO_new_socket(s, BIO_NOCLOSE);
    SSL_set_bio(con, sbio, sbio);
    SSL_set_accept_state(con);
    BIO_set_ssl(ssl_bio, con, BIO_CLOSE);
    BIO_push(io, ssl_bio);
#ifdef CHARSET_EBCDIC
    io = BIO_push(BIO_new(BIO_f_ebcdic_filter()), io);
#endif
    if (s_debug) {
        SSL_set_debug(con, 1);
        BIO_set_callback(SSL_get_rbio(con), bio_dump_callback);
        BIO_set_callback_arg(SSL_get_rbio(con), (char *)bio_s_out);
    }
    if (s_msg) {
#ifndef OPENSSL_NO_SSL_TRACE
        if (s_msg == 2)
            SSL_set_msg_callback(con, SSL_trace);
        else
#endif
            SSL_set_msg_callback(con, msg_cb);
        SSL_set_msg_callback_arg(con, bio_s_msg ? bio_s_msg : bio_s_out);
    }
    for (;;) {
        i = BIO_do_handshake(io);
        if (i > 0)
            break;
        if (!BIO_should_retry(io)) {
            BIO_puts(bio_err, "CONNECTION FAILURE\n");
            ERR_print_errors(bio_err);
            goto end;
        }
#ifndef OPENSSL_NO_SRP
        if (BIO_should_io_special(io)
            && BIO_get_retry_reason(io) == BIO_RR_SSL_X509_LOOKUP) {
            BIO_printf(bio_s_out, "LOOKUP renego during accept\n");
            srp_callback_parm.user =
                SRP_VBASE_get_by_user(srp_callback_parm.vb,
                                      srp_callback_parm.login);
            if (srp_callback_parm.user)
                BIO_printf(bio_s_out, "LOOKUP done %s\n",
                           srp_callback_parm.user->info);
            else
                BIO_printf(bio_s_out, "LOOKUP not successful\n");
            continue;
        }
#endif
    }
    BIO_printf(bio_err, "CONNECTION ESTABLISHED\n");
    print_ssl_summary(con);
    for (;;) {
        i = BIO_gets(io, buf, bufsize - 1);
        if (i < 0) {
            if (!BIO_should_retry(io)) {
                if (!s_quiet)
                    ERR_print_errors(bio_err);
                goto err;
            } else {
                BIO_printf(bio_s_out, "read R BLOCK\n");
#ifndef OPENSSL_NO_SRP
                if (BIO_should_io_special(io)
                    && BIO_get_retry_reason(io) == BIO_RR_SSL_X509_LOOKUP) {
                    BIO_printf(bio_s_out, "LOOKUP renego during read\n");
                    srp_callback_parm.user =
                        SRP_VBASE_get_by_user(srp_callback_parm.vb,
                                              srp_callback_parm.login);
                    if (srp_callback_parm.user)
                        BIO_printf(bio_s_out, "LOOKUP done %s\n",
                                   srp_callback_parm.user->info);
                    else
                        BIO_printf(bio_s_out, "LOOKUP not successful\n");
                    continue;
                }
#endif
#if defined(OPENSSL_SYS_NETWARE)
                delay(1000);
#elif !defined(OPENSSL_SYS_MSDOS)
                sleep(1);
#endif
                continue;
            }
        } else if (i == 0) {
            ret = 1;
            BIO_printf(bio_err, "CONNECTION CLOSED\n");
            goto end;
        } else {
            char *p = buf + i - 1;
            while (i && (*p == '\n' || *p == '\r')) {
                p--;
                i--;
            }
            if (!s_ign_eof && (i == 5) && (strncmp(buf, "CLOSE", 5) == 0)) {
                ret = 1;
                BIO_printf(bio_err, "CONNECTION CLOSED\n");
                goto end;
            }
            BUF_reverse((unsigned char *)buf, NULL, i);
            buf[i] = '\n';
            BIO_write(io, buf, i + 1);
            for (;;) {
                i = BIO_flush(io);
                if (i > 0)
                    break;
                if (!BIO_should_retry(io))
                    goto end;
            }
        }
    }
 end:
    SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
 err:
    OPENSSL_free(buf);
    BIO_free_all(io);
    return (ret);
}
['static int rev_body(char *hostname, int s, int stype, unsigned char *context)\n{\n    char *buf = NULL;\n    int i;\n    int ret = 1;\n    SSL *con;\n    BIO *io, *ssl_bio, *sbio;\n    buf = app_malloc(bufsize, "server rev buffer");\n    io = BIO_new(BIO_f_buffer());\n    ssl_bio = BIO_new(BIO_f_ssl());\n    if ((io == NULL) || (ssl_bio == NULL))\n        goto err;\n    if (!BIO_set_write_buffer_size(io, bufsize))\n        goto err;\n    if ((con = SSL_new(ctx)) == NULL)\n        goto err;\n    if (s_tlsextdebug) {\n        SSL_set_tlsext_debug_callback(con, tlsext_cb);\n        SSL_set_tlsext_debug_arg(con, bio_s_out);\n    }\n    if (context && !SSL_set_session_id_context(con, context,\n                        strlen((char *)context))) {\n        ERR_print_errors(bio_err);\n        goto err;\n    }\n    sbio = BIO_new_socket(s, BIO_NOCLOSE);\n    SSL_set_bio(con, sbio, sbio);\n    SSL_set_accept_state(con);\n    BIO_set_ssl(ssl_bio, con, BIO_CLOSE);\n    BIO_push(io, ssl_bio);\n#ifdef CHARSET_EBCDIC\n    io = BIO_push(BIO_new(BIO_f_ebcdic_filter()), io);\n#endif\n    if (s_debug) {\n        SSL_set_debug(con, 1);\n        BIO_set_callback(SSL_get_rbio(con), bio_dump_callback);\n        BIO_set_callback_arg(SSL_get_rbio(con), (char *)bio_s_out);\n    }\n    if (s_msg) {\n#ifndef OPENSSL_NO_SSL_TRACE\n        if (s_msg == 2)\n            SSL_set_msg_callback(con, SSL_trace);\n        else\n#endif\n            SSL_set_msg_callback(con, msg_cb);\n        SSL_set_msg_callback_arg(con, bio_s_msg ? bio_s_msg : bio_s_out);\n    }\n    for (;;) {\n        i = BIO_do_handshake(io);\n        if (i > 0)\n            break;\n        if (!BIO_should_retry(io)) {\n            BIO_puts(bio_err, "CONNECTION FAILURE\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n#ifndef OPENSSL_NO_SRP\n        if (BIO_should_io_special(io)\n            && BIO_get_retry_reason(io) == BIO_RR_SSL_X509_LOOKUP) {\n            BIO_printf(bio_s_out, "LOOKUP renego during accept\\n");\n            srp_callback_parm.user =\n                SRP_VBASE_get_by_user(srp_callback_parm.vb,\n                                      srp_callback_parm.login);\n            if (srp_callback_parm.user)\n                BIO_printf(bio_s_out, "LOOKUP done %s\\n",\n                           srp_callback_parm.user->info);\n            else\n                BIO_printf(bio_s_out, "LOOKUP not successful\\n");\n            continue;\n        }\n#endif\n    }\n    BIO_printf(bio_err, "CONNECTION ESTABLISHED\\n");\n    print_ssl_summary(con);\n    for (;;) {\n        i = BIO_gets(io, buf, bufsize - 1);\n        if (i < 0) {\n            if (!BIO_should_retry(io)) {\n                if (!s_quiet)\n                    ERR_print_errors(bio_err);\n                goto err;\n            } else {\n                BIO_printf(bio_s_out, "read R BLOCK\\n");\n#ifndef OPENSSL_NO_SRP\n                if (BIO_should_io_special(io)\n                    && BIO_get_retry_reason(io) == BIO_RR_SSL_X509_LOOKUP) {\n                    BIO_printf(bio_s_out, "LOOKUP renego during read\\n");\n                    srp_callback_parm.user =\n                        SRP_VBASE_get_by_user(srp_callback_parm.vb,\n                                              srp_callback_parm.login);\n                    if (srp_callback_parm.user)\n                        BIO_printf(bio_s_out, "LOOKUP done %s\\n",\n                                   srp_callback_parm.user->info);\n                    else\n                        BIO_printf(bio_s_out, "LOOKUP not successful\\n");\n                    continue;\n                }\n#endif\n#if defined(OPENSSL_SYS_NETWARE)\n                delay(1000);\n#elif !defined(OPENSSL_SYS_MSDOS)\n                sleep(1);\n#endif\n                continue;\n            }\n        } else if (i == 0) {\n            ret = 1;\n            BIO_printf(bio_err, "CONNECTION CLOSED\\n");\n            goto end;\n        } else {\n            char *p = buf + i - 1;\n            while (i && (*p == \'\\n\' || *p == \'\\r\')) {\n                p--;\n                i--;\n            }\n            if (!s_ign_eof && (i == 5) && (strncmp(buf, "CLOSE", 5) == 0)) {\n                ret = 1;\n                BIO_printf(bio_err, "CONNECTION CLOSED\\n");\n                goto end;\n            }\n            BUF_reverse((unsigned char *)buf, NULL, i);\n            buf[i] = \'\\n\';\n            BIO_write(io, buf, i + 1);\n            for (;;) {\n                i = BIO_flush(io);\n                if (i > 0)\n                    break;\n                if (!BIO_should_retry(io))\n                    goto end;\n            }\n        }\n    }\n end:\n    SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);\n err:\n    OPENSSL_free(buf);\n    BIO_free_all(io);\n    return (ret);\n}', 'void* app_malloc(int sz, const char *what)\n{\n    void *vp = OPENSSL_malloc(sz);\n    if (vp == NULL) {\n        BIO_printf(bio_err, "%s: Could not allocate %d bytes for %s\\n",\n                opt_getprog(), sz, what);\n        ERR_print_errors(bio_err);\n        exit(1);\n    }\n    return vp;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}', 'BIO_METHOD *BIO_f_buffer(void)\n{\n    return (&methods_buffer);\n}', 'BIO *BIO_new(BIO_METHOD *method)\n{\n    BIO *ret = OPENSSL_malloc(sizeof(*ret));\n    if (ret == NULL) {\n        BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    if (!BIO_set(ret, method)) {\n        OPENSSL_free(ret);\n        ret = NULL;\n    }\n    return (ret);\n}', 'void CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}', 'BIO_METHOD *BIO_f_ssl(void)\n{\n    return (&methods_sslp);\n}']