static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
                          OPENSSL_LH_DOALL_FUNC func,
                          OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)
{
    int i;
    OPENSSL_LH_NODE *a, *n;
    if (lh == NULL)
        return;
    for (i = lh->num_nodes - 1; i >= 0; i--) {
        a = lh->b[i];
        while (a != NULL) {
            n = a->next;
            if (use_arg)
                func_arg(a->data, arg);
            else
                func(a->data);
            a = n;
        }
    }
}
['int s_server_main(int argc, char *argv[])\n{\n    ENGINE *engine = NULL;\n    EVP_PKEY *s_key = NULL, *s_dkey = NULL;\n    SSL_CONF_CTX *cctx = NULL;\n    const SSL_METHOD *meth = TLS_server_method();\n    SSL_EXCERT *exc = NULL;\n    STACK_OF(OPENSSL_STRING) *ssl_args = NULL;\n    STACK_OF(X509) *s_chain = NULL, *s_dchain = NULL;\n    STACK_OF(X509_CRL) *crls = NULL;\n    X509 *s_cert = NULL, *s_dcert = NULL;\n    X509_VERIFY_PARAM *vpm = NULL;\n    const char *CApath = NULL, *CAfile = NULL, *chCApath = NULL, *chCAfile = NULL;\n    char *dpassarg = NULL, *dpass = NULL, *inrand = NULL;\n    char *passarg = NULL, *pass = NULL, *vfyCApath = NULL, *vfyCAfile = NULL;\n    char *crl_file = NULL, *prog;\n#ifdef AF_UNIX\n    int unlink_unix_path = 0;\n#endif\n    do_server_cb server_cb;\n    int vpmtouched = 0, build_chain = 0, no_cache = 0, ext_cache = 0;\n#ifndef OPENSSL_NO_DH\n    char *dhfile = NULL;\n    int no_dhe = 0;\n#endif\n    int nocert = 0, ret = 1;\n    int noCApath = 0, noCAfile = 0;\n    int s_cert_format = FORMAT_PEM, s_key_format = FORMAT_PEM;\n    int s_dcert_format = FORMAT_PEM, s_dkey_format = FORMAT_PEM;\n    int rev = 0, naccept = -1, sdebug = 0;\n    int socket_family = AF_UNSPEC, socket_type = SOCK_STREAM;\n    int state = 0, crl_format = FORMAT_PEM, crl_download = 0;\n    char *host = NULL;\n    char *port = BUF_strdup(PORT);\n    unsigned char *context = NULL;\n    OPTION_CHOICE o;\n    EVP_PKEY *s_key2 = NULL;\n    X509 *s_cert2 = NULL;\n    tlsextctx tlsextcbp = { NULL, NULL, SSL_TLSEXT_ERR_ALERT_WARNING };\n    const char *ssl_config = NULL;\n    int read_buf_len = 0;\n#ifndef OPENSSL_NO_NEXTPROTONEG\n    const char *next_proto_neg_in = NULL;\n    tlsextnextprotoctx next_proto = { NULL, 0 };\n#endif\n    const char *alpn_in = NULL;\n    tlsextalpnctx alpn_ctx = { NULL, 0 };\n#ifndef OPENSSL_NO_PSK\n    static char *psk_identity_hint = NULL;\n    char *p;\n#endif\n#ifndef OPENSSL_NO_SRP\n    char *srpuserseed = NULL;\n    char *srp_verifier_file = NULL;\n#endif\n    int min_version = 0, max_version = 0, prot_opt = 0, no_prot_opt = 0;\n    int s_server_verify = SSL_VERIFY_NONE;\n    int s_server_session_id_context = 1;\n    const char *s_cert_file = TEST_CERT, *s_key_file = NULL, *s_chain_file = NULL;\n    const char *s_cert_file2 = TEST_CERT2, *s_key_file2 = NULL;\n    char *s_dcert_file = NULL, *s_dkey_file = NULL, *s_dchain_file = NULL;\n#ifndef OPENSSL_NO_OCSP\n    int s_tlsextstatus = 0;\n#endif\n    int no_resume_ephemeral = 0;\n    unsigned int split_send_fragment = 0, max_pipelines = 0;\n    const char *s_serverinfo_file = NULL;\n    const char *keylog_file = NULL;\n    local_argc = argc;\n    local_argv = argv;\n    ctx = ctx2 = NULL;\n    s_nbio = s_nbio_test = 0;\n    www = 0;\n    bio_s_out = NULL;\n    s_debug = 0;\n    s_msg = 0;\n    s_quiet = 0;\n    s_brief = 0;\n    async = 0;\n    cctx = SSL_CONF_CTX_new();\n    vpm = X509_VERIFY_PARAM_new();\n    if (cctx == NULL || vpm == NULL)\n        goto end;\n    SSL_CONF_CTX_set_flags(cctx,\n                           SSL_CONF_FLAG_SERVER | SSL_CONF_FLAG_CMDLINE);\n    prog = opt_init(argc, argv, s_server_options);\n    while ((o = opt_next()) != OPT_EOF) {\n        if (IS_PROT_FLAG(o) && ++prot_opt > 1) {\n            BIO_printf(bio_err, "Cannot supply multiple protocol flags\\n");\n            goto end;\n        }\n        if (IS_NO_PROT_FLAG(o))\n            no_prot_opt++;\n        if (prot_opt == 1 && no_prot_opt) {\n            BIO_printf(bio_err,\n                       "Cannot supply both a protocol flag and \'-no_<prot>\'\\n");\n            goto end;\n        }\n        switch (o) {\n        case OPT_EOF:\n        case OPT_ERR:\n opthelp:\n            BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n            goto end;\n        case OPT_HELP:\n            opt_help(s_server_options);\n            ret = 0;\n            goto end;\n        case OPT_4:\n#ifdef AF_UNIX\n            if (socket_family == AF_UNIX) {\n                OPENSSL_free(host); host = NULL;\n                OPENSSL_free(port); port = NULL;\n            }\n#endif\n            socket_family = AF_INET;\n            break;\n        case OPT_6:\n            if (1) {\n#ifdef AF_INET6\n#ifdef AF_UNIX\n                if (socket_family == AF_UNIX) {\n                    OPENSSL_free(host); host = NULL;\n                    OPENSSL_free(port); port = NULL;\n                }\n#endif\n                socket_family = AF_INET6;\n            } else {\n#endif\n                BIO_printf(bio_err, "%s: IPv6 domain sockets unsupported\\n", prog);\n                goto end;\n            }\n            break;\n        case OPT_PORT:\n#ifdef AF_UNIX\n            if (socket_family == AF_UNIX) {\n                socket_family = AF_UNSPEC;\n            }\n#endif\n            OPENSSL_free(port); port = NULL;\n            OPENSSL_free(host); host = NULL;\n            if (BIO_parse_hostserv(opt_arg(), NULL, &port, BIO_PARSE_PRIO_SERV) < 1) {\n                BIO_printf(bio_err,\n                           "%s: -port argument malformed or ambiguous\\n",\n                           port);\n                goto end;\n            }\n            break;\n        case OPT_ACCEPT:\n#ifdef AF_UNIX\n            if (socket_family == AF_UNIX) {\n                socket_family = AF_UNSPEC;\n            }\n#endif\n            OPENSSL_free(port); port = NULL;\n            OPENSSL_free(host); host = NULL;\n            if (BIO_parse_hostserv(opt_arg(), &host, &port, BIO_PARSE_PRIO_SERV) < 1) {\n                BIO_printf(bio_err,\n                           "%s: -accept argument malformed or ambiguous\\n",\n                           port);\n                goto end;\n            }\n            break;\n#ifdef AF_UNIX\n        case OPT_UNIX:\n            socket_family = AF_UNIX;\n            OPENSSL_free(host); host = BUF_strdup(opt_arg());\n            OPENSSL_free(port); port = NULL;\n            break;\n        case OPT_UNLINK:\n            unlink_unix_path = 1;\n            break;\n#endif\n        case OPT_NACCEPT:\n            naccept = atol(opt_arg());\n            break;\n        case OPT_VERIFY:\n            s_server_verify = SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE;\n            verify_args.depth = atoi(opt_arg());\n            if (!s_quiet)\n                BIO_printf(bio_err, "verify depth is %d\\n", verify_args.depth);\n            break;\n        case OPT_UPPER_V_VERIFY:\n            s_server_verify =\n                SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT |\n                SSL_VERIFY_CLIENT_ONCE;\n            verify_args.depth = atoi(opt_arg());\n            if (!s_quiet)\n                BIO_printf(bio_err,\n                           "verify depth is %d, must return a certificate\\n",\n                           verify_args.depth);\n            break;\n        case OPT_CONTEXT:\n            context = (unsigned char *)opt_arg();\n            break;\n        case OPT_CERT:\n            s_cert_file = opt_arg();\n            break;\n        case OPT_CRL:\n            crl_file = opt_arg();\n            break;\n        case OPT_CRL_DOWNLOAD:\n            crl_download = 1;\n            break;\n        case OPT_SERVERINFO:\n            s_serverinfo_file = opt_arg();\n            break;\n        case OPT_CERTFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &s_cert_format))\n                goto opthelp;\n            break;\n        case OPT_KEY:\n            s_key_file = opt_arg();\n            break;\n        case OPT_KEYFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_ANY, &s_key_format))\n                goto opthelp;\n            break;\n        case OPT_PASS:\n            passarg = opt_arg();\n            break;\n        case OPT_CERT_CHAIN:\n            s_chain_file = opt_arg();\n            break;\n        case OPT_DHPARAM:\n#ifndef OPENSSL_NO_DH\n            dhfile = opt_arg();\n#endif\n            break;\n        case OPT_DCERTFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &s_dcert_format))\n                goto opthelp;\n            break;\n        case OPT_DCERT:\n            s_dcert_file = opt_arg();\n            break;\n        case OPT_DKEYFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &s_dkey_format))\n                goto opthelp;\n            break;\n        case OPT_DPASS:\n            dpassarg = opt_arg();\n            break;\n        case OPT_DKEY:\n            s_dkey_file = opt_arg();\n            break;\n        case OPT_DCERT_CHAIN:\n            s_dchain_file = opt_arg();\n            break;\n        case OPT_NOCERT:\n            nocert = 1;\n            break;\n        case OPT_CAPATH:\n            CApath = opt_arg();\n            break;\n        case OPT_NOCAPATH:\n            noCApath = 1;\n            break;\n        case OPT_CHAINCAPATH:\n            chCApath = opt_arg();\n            break;\n        case OPT_VERIFYCAPATH:\n            vfyCApath = opt_arg();\n            break;\n        case OPT_NO_CACHE:\n            no_cache = 1;\n            break;\n        case OPT_EXT_CACHE:\n            ext_cache = 1;\n            break;\n        case OPT_CRLFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &crl_format))\n                goto opthelp;\n            break;\n        case OPT_S_CASES:\n            if (ssl_args == NULL)\n                ssl_args = sk_OPENSSL_STRING_new_null();\n            if (ssl_args == NULL\n                || !sk_OPENSSL_STRING_push(ssl_args, opt_flag())\n                || !sk_OPENSSL_STRING_push(ssl_args, opt_arg())) {\n                BIO_printf(bio_err, "%s: Memory allocation failure\\n", prog);\n                goto end;\n            }\n            break;\n        case OPT_V_CASES:\n            if (!opt_verify(o, vpm))\n                goto end;\n            vpmtouched++;\n            break;\n        case OPT_X_CASES:\n            if (!args_excert(o, &exc))\n                goto end;\n            break;\n        case OPT_VERIFY_RET_ERROR:\n            verify_args.return_error = 1;\n            break;\n        case OPT_VERIFY_QUIET:\n            verify_args.quiet = 1;\n            break;\n        case OPT_BUILD_CHAIN:\n            build_chain = 1;\n            break;\n        case OPT_CAFILE:\n            CAfile = opt_arg();\n            break;\n        case OPT_NOCAFILE:\n            noCAfile = 1;\n            break;\n        case OPT_CHAINCAFILE:\n            chCAfile = opt_arg();\n            break;\n        case OPT_VERIFYCAFILE:\n            vfyCAfile = opt_arg();\n            break;\n        case OPT_NBIO:\n            s_nbio = 1;\n            break;\n        case OPT_NBIO_TEST:\n            s_nbio = s_nbio_test = 1;\n            break;\n        case OPT_IGN_EOF:\n            s_ign_eof = 1;\n            break;\n        case OPT_NO_IGN_EOF:\n            s_ign_eof = 0;\n            break;\n        case OPT_DEBUG:\n            s_debug = 1;\n            break;\n        case OPT_TLSEXTDEBUG:\n            s_tlsextdebug = 1;\n            break;\n        case OPT_STATUS:\n#ifndef OPENSSL_NO_OCSP\n            s_tlsextstatus = 1;\n#endif\n            break;\n        case OPT_STATUS_VERBOSE:\n#ifndef OPENSSL_NO_OCSP\n            s_tlsextstatus = tlscstatp.verbose = 1;\n#endif\n            break;\n        case OPT_STATUS_TIMEOUT:\n#ifndef OPENSSL_NO_OCSP\n            s_tlsextstatus = 1;\n            tlscstatp.timeout = atoi(opt_arg());\n#endif\n            break;\n        case OPT_STATUS_URL:\n#ifndef OPENSSL_NO_OCSP\n            s_tlsextstatus = 1;\n            if (!OCSP_parse_url(opt_arg(),\n                                &tlscstatp.host,\n                                &tlscstatp.port,\n                                &tlscstatp.path, &tlscstatp.use_ssl)) {\n                BIO_printf(bio_err, "Error parsing URL\\n");\n                goto end;\n            }\n#endif\n            break;\n        case OPT_STATUS_FILE:\n#ifndef OPENSSL_NO_OCSP\n            s_tlsextstatus = 1;\n            tlscstatp.respin = opt_arg();\n#endif\n            break;\n        case OPT_MSG:\n            s_msg = 1;\n            break;\n        case OPT_MSGFILE:\n            bio_s_msg = BIO_new_file(opt_arg(), "w");\n            break;\n        case OPT_TRACE:\n#ifndef OPENSSL_NO_SSL_TRACE\n            s_msg = 2;\n#endif\n            break;\n        case OPT_SECURITY_DEBUG:\n            sdebug = 1;\n            break;\n        case OPT_SECURITY_DEBUG_VERBOSE:\n            sdebug = 2;\n            break;\n        case OPT_STATE:\n            state = 1;\n            break;\n        case OPT_CRLF:\n            s_crlf = 1;\n            break;\n        case OPT_QUIET:\n            s_quiet = 1;\n            break;\n        case OPT_BRIEF:\n            s_quiet = s_brief = verify_args.quiet = 1;\n            break;\n        case OPT_NO_DHE:\n#ifndef OPENSSL_NO_DH\n            no_dhe = 1;\n#endif\n            break;\n        case OPT_NO_RESUME_EPHEMERAL:\n            no_resume_ephemeral = 1;\n            break;\n        case OPT_PSK_HINT:\n#ifndef OPENSSL_NO_PSK\n            psk_identity_hint = opt_arg();\n#endif\n            break;\n        case OPT_PSK:\n#ifndef OPENSSL_NO_PSK\n            for (p = psk_key = opt_arg(); *p; p++) {\n                if (isxdigit(_UC(*p)))\n                    continue;\n                BIO_printf(bio_err, "Not a hex number \'%s\'\\n", *argv);\n                goto end;\n            }\n#endif\n            break;\n        case OPT_SRPVFILE:\n#ifndef OPENSSL_NO_SRP\n            srp_verifier_file = opt_arg();\n            if (min_version < TLS1_VERSION)\n                min_version = TLS1_VERSION;\n#endif\n            break;\n        case OPT_SRPUSERSEED:\n#ifndef OPENSSL_NO_SRP\n            srpuserseed = opt_arg();\n            if (min_version < TLS1_VERSION)\n                min_version = TLS1_VERSION;\n#endif\n            break;\n        case OPT_REV:\n            rev = 1;\n            break;\n        case OPT_WWW:\n            www = 1;\n            break;\n        case OPT_UPPER_WWW:\n            www = 2;\n            break;\n        case OPT_HTTP:\n            www = 3;\n            break;\n        case OPT_SSL_CONFIG:\n            ssl_config = opt_arg();\n            break;\n        case OPT_SSL3:\n            min_version = SSL3_VERSION;\n            max_version = SSL3_VERSION;\n            break;\n        case OPT_TLS1_3:\n            min_version = TLS1_3_VERSION;\n            max_version = TLS1_3_VERSION;\n            break;\n        case OPT_TLS1_2:\n            min_version = TLS1_2_VERSION;\n            max_version = TLS1_2_VERSION;\n            break;\n        case OPT_TLS1_1:\n            min_version = TLS1_1_VERSION;\n            max_version = TLS1_1_VERSION;\n            break;\n        case OPT_TLS1:\n            min_version = TLS1_VERSION;\n            max_version = TLS1_VERSION;\n            break;\n        case OPT_DTLS:\n#ifndef OPENSSL_NO_DTLS\n            meth = DTLS_server_method();\n            socket_type = SOCK_DGRAM;\n#endif\n            break;\n        case OPT_DTLS1:\n#ifndef OPENSSL_NO_DTLS\n            meth = DTLS_server_method();\n            min_version = DTLS1_VERSION;\n            max_version = DTLS1_VERSION;\n            socket_type = SOCK_DGRAM;\n#endif\n            break;\n        case OPT_DTLS1_2:\n#ifndef OPENSSL_NO_DTLS\n            meth = DTLS_server_method();\n            min_version = DTLS1_2_VERSION;\n            max_version = DTLS1_2_VERSION;\n            socket_type = SOCK_DGRAM;\n#endif\n            break;\n        case OPT_TIMEOUT:\n#ifndef OPENSSL_NO_DTLS\n            enable_timeouts = 1;\n#endif\n            break;\n        case OPT_MTU:\n#ifndef OPENSSL_NO_DTLS\n            socket_mtu = atol(opt_arg());\n#endif\n            break;\n        case OPT_LISTEN:\n#ifndef OPENSSL_NO_DTLS\n            dtlslisten = 1;\n#endif\n            break;\n        case OPT_ID_PREFIX:\n            session_id_prefix = opt_arg();\n            break;\n        case OPT_ENGINE:\n            engine = setup_engine(opt_arg(), 1);\n            break;\n        case OPT_RAND:\n            inrand = opt_arg();\n            break;\n        case OPT_SERVERNAME:\n            tlsextcbp.servername = opt_arg();\n            break;\n        case OPT_SERVERNAME_FATAL:\n            tlsextcbp.extension_error = SSL_TLSEXT_ERR_ALERT_FATAL;\n            break;\n        case OPT_CERT2:\n            s_cert_file2 = opt_arg();\n            break;\n        case OPT_KEY2:\n            s_key_file2 = opt_arg();\n            break;\n        case OPT_NEXTPROTONEG:\n# ifndef OPENSSL_NO_NEXTPROTONEG\n            next_proto_neg_in = opt_arg();\n#endif\n            break;\n        case OPT_ALPN:\n            alpn_in = opt_arg();\n            break;\n        case OPT_SRTP_PROFILES:\n#ifndef OPENSSL_NO_SRTP\n            srtp_profiles = opt_arg();\n#endif\n            break;\n        case OPT_KEYMATEXPORT:\n            keymatexportlabel = opt_arg();\n            break;\n        case OPT_KEYMATEXPORTLEN:\n            keymatexportlen = atoi(opt_arg());\n            break;\n        case OPT_ASYNC:\n            async = 1;\n            break;\n        case OPT_SPLIT_SEND_FRAG:\n            split_send_fragment = atoi(opt_arg());\n            if (split_send_fragment == 0) {\n                split_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH + 1;\n            }\n            break;\n        case OPT_MAX_PIPELINES:\n            max_pipelines = atoi(opt_arg());\n            break;\n        case OPT_READ_BUF:\n            read_buf_len = atoi(opt_arg());\n            break;\n        case OPT_KEYLOG_FILE:\n            keylog_file = opt_arg();\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n#ifndef OPENSSL_NO_DTLS\n    if (www && socket_type == SOCK_DGRAM) {\n        BIO_printf(bio_err, "Can\'t use -HTTP, -www or -WWW with DTLS\\n");\n        goto end;\n    }\n    if (dtlslisten && socket_type != SOCK_DGRAM) {\n        BIO_printf(bio_err, "Can only use -listen with DTLS\\n");\n        goto end;\n    }\n#endif\n#ifdef AF_UNIX\n    if (socket_family == AF_UNIX && socket_type != SOCK_STREAM) {\n        BIO_printf(bio_err,\n                   "Can\'t use unix sockets and datagrams together\\n");\n        goto end;\n    }\n#endif\n    if (split_send_fragment > SSL3_RT_MAX_PLAIN_LENGTH) {\n        BIO_printf(bio_err, "Bad split send fragment size\\n");\n        goto end;\n    }\n    if (max_pipelines > SSL_MAX_PIPELINES) {\n        BIO_printf(bio_err, "Bad max pipelines value\\n");\n        goto end;\n    }\n    if (!app_passwd(passarg, dpassarg, &pass, &dpass)) {\n        BIO_printf(bio_err, "Error getting password\\n");\n        goto end;\n    }\n    if (s_key_file == NULL)\n        s_key_file = s_cert_file;\n    if (s_key_file2 == NULL)\n        s_key_file2 = s_cert_file2;\n    if (!load_excert(&exc))\n        goto end;\n    if (nocert == 0) {\n        s_key = load_key(s_key_file, s_key_format, 0, pass, engine,\n                         "server certificate private key file");\n        if (!s_key) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        s_cert = load_cert(s_cert_file, s_cert_format,\n                           "server certificate file");\n        if (!s_cert) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        if (s_chain_file) {\n            if (!load_certs(s_chain_file, &s_chain, FORMAT_PEM, NULL,\n                            "server certificate chain"))\n                goto end;\n        }\n        if (tlsextcbp.servername) {\n            s_key2 = load_key(s_key_file2, s_key_format, 0, pass, engine,\n                              "second server certificate private key file");\n            if (!s_key2) {\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n            s_cert2 = load_cert(s_cert_file2, s_cert_format,\n                                "second server certificate file");\n            if (!s_cert2) {\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n        }\n    }\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n    if (next_proto_neg_in) {\n        size_t len;\n        next_proto.data = next_protos_parse(&len, next_proto_neg_in);\n        if (next_proto.data == NULL)\n            goto end;\n        next_proto.len = len;\n    } else {\n        next_proto.data = NULL;\n    }\n#endif\n    alpn_ctx.data = NULL;\n    if (alpn_in) {\n        size_t len;\n        alpn_ctx.data = next_protos_parse(&len, alpn_in);\n        if (alpn_ctx.data == NULL)\n            goto end;\n        alpn_ctx.len = len;\n    }\n    if (crl_file) {\n        X509_CRL *crl;\n        crl = load_crl(crl_file, crl_format);\n        if (!crl) {\n            BIO_puts(bio_err, "Error loading CRL\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        crls = sk_X509_CRL_new_null();\n        if (!crls || !sk_X509_CRL_push(crls, crl)) {\n            BIO_puts(bio_err, "Error adding CRL\\n");\n            ERR_print_errors(bio_err);\n            X509_CRL_free(crl);\n            goto end;\n        }\n    }\n    if (s_dcert_file) {\n        if (s_dkey_file == NULL)\n            s_dkey_file = s_dcert_file;\n        s_dkey = load_key(s_dkey_file, s_dkey_format,\n                          0, dpass, engine, "second certificate private key file");\n        if (!s_dkey) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        s_dcert = load_cert(s_dcert_file, s_dcert_format,\n                            "second server certificate file");\n        if (!s_dcert) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        if (s_dchain_file) {\n            if (!load_certs(s_dchain_file, &s_dchain, FORMAT_PEM, NULL,\n                            "second server certificate chain"))\n                goto end;\n        }\n    }\n    if (!app_RAND_load_file(NULL, 1) && inrand == NULL\n        && !RAND_status()) {\n        BIO_printf(bio_err,\n                   "warning, not much extra random data, consider using the -rand option\\n");\n    }\n    if (inrand != NULL)\n        BIO_printf(bio_err, "%ld semi-random bytes loaded\\n",\n                   app_RAND_load_files(inrand));\n    if (bio_s_out == NULL) {\n        if (s_quiet && !s_debug) {\n            bio_s_out = BIO_new(BIO_s_null());\n            if (s_msg && !bio_s_msg)\n                bio_s_msg = dup_bio_out(FORMAT_TEXT);\n        } else {\n            if (bio_s_out == NULL)\n                bio_s_out = dup_bio_out(FORMAT_TEXT);\n        }\n    }\n#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)\n    if (nocert)\n#endif\n    {\n        s_cert_file = NULL;\n        s_key_file = NULL;\n        s_dcert_file = NULL;\n        s_dkey_file = NULL;\n        s_cert_file2 = NULL;\n        s_key_file2 = NULL;\n    }\n    ctx = SSL_CTX_new(meth);\n    if (ctx == NULL) {\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (sdebug)\n        ssl_ctx_security_debug(ctx, sdebug);\n    if (ssl_config) {\n        if (SSL_CTX_config(ctx, ssl_config) == 0) {\n            BIO_printf(bio_err, "Error using configuration \\"%s\\"\\n",\n                       ssl_config);\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    if (SSL_CTX_set_min_proto_version(ctx, min_version) == 0)\n        goto end;\n    if (SSL_CTX_set_max_proto_version(ctx, max_version) == 0)\n        goto end;\n    if (session_id_prefix) {\n        if (strlen(session_id_prefix) >= 32)\n            BIO_printf(bio_err,\n                       "warning: id_prefix is too long, only one new session will be possible\\n");\n        if (!SSL_CTX_set_generate_session_id(ctx, generate_session_id)) {\n            BIO_printf(bio_err, "error setting \'id_prefix\'\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        BIO_printf(bio_err, "id_prefix \'%s\' set.\\n", session_id_prefix);\n    }\n    SSL_CTX_set_quiet_shutdown(ctx, 1);\n    if (exc)\n        ssl_ctx_set_excert(ctx, exc);\n    if (state)\n        SSL_CTX_set_info_callback(ctx, apps_ssl_info_callback);\n    if (no_cache)\n        SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);\n    else if (ext_cache)\n        init_session_cache_ctx(ctx);\n    else\n        SSL_CTX_sess_set_cache_size(ctx, 128);\n    if (async) {\n        SSL_CTX_set_mode(ctx, SSL_MODE_ASYNC);\n    }\n    if (split_send_fragment > 0) {\n        SSL_CTX_set_split_send_fragment(ctx, split_send_fragment);\n    }\n    if (max_pipelines > 0) {\n        SSL_CTX_set_max_pipelines(ctx, max_pipelines);\n    }\n    if (read_buf_len > 0) {\n        SSL_CTX_set_default_read_buffer_len(ctx, read_buf_len);\n    }\n#ifndef OPENSSL_NO_SRTP\n    if (srtp_profiles != NULL) {\n        if (SSL_CTX_set_tlsext_use_srtp(ctx, srtp_profiles) != 0) {\n            BIO_printf(bio_err, "Error setting SRTP profile\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n#endif\n    if (!ctx_set_verify_locations(ctx, CAfile, CApath, noCAfile, noCApath)) {\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (vpmtouched && !SSL_CTX_set1_param(ctx, vpm)) {\n        BIO_printf(bio_err, "Error setting verify params\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    ssl_ctx_add_crls(ctx, crls, 0);\n    if (!config_ctx(cctx, ssl_args, ctx))\n        goto end;\n    if (!ssl_load_stores(ctx, vfyCApath, vfyCAfile, chCApath, chCAfile,\n                         crls, crl_download)) {\n        BIO_printf(bio_err, "Error loading store locations\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (s_cert2) {\n        ctx2 = SSL_CTX_new(meth);\n        if (ctx2 == NULL) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    if (ctx2) {\n        BIO_printf(bio_s_out, "Setting secondary ctx parameters\\n");\n        if (sdebug)\n            ssl_ctx_security_debug(ctx, sdebug);\n        if (session_id_prefix) {\n            if (strlen(session_id_prefix) >= 32)\n                BIO_printf(bio_err,\n                           "warning: id_prefix is too long, only one new session will be possible\\n");\n            if (!SSL_CTX_set_generate_session_id(ctx2, generate_session_id)) {\n                BIO_printf(bio_err, "error setting \'id_prefix\'\\n");\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n            BIO_printf(bio_err, "id_prefix \'%s\' set.\\n", session_id_prefix);\n        }\n        SSL_CTX_set_quiet_shutdown(ctx2, 1);\n        if (exc)\n            ssl_ctx_set_excert(ctx2, exc);\n        if (state)\n            SSL_CTX_set_info_callback(ctx2, apps_ssl_info_callback);\n        if (no_cache)\n            SSL_CTX_set_session_cache_mode(ctx2, SSL_SESS_CACHE_OFF);\n        else if (ext_cache)\n            init_session_cache_ctx(ctx2);\n        else\n            SSL_CTX_sess_set_cache_size(ctx2, 128);\n        if (async)\n            SSL_CTX_set_mode(ctx2, SSL_MODE_ASYNC);\n        if (!ctx_set_verify_locations(ctx2, CAfile, CApath, noCAfile,\n                                      noCApath)) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        if (vpmtouched && !SSL_CTX_set1_param(ctx2, vpm)) {\n            BIO_printf(bio_err, "Error setting verify params\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        ssl_ctx_add_crls(ctx2, crls, 0);\n        if (!config_ctx(cctx, ssl_args, ctx2))\n            goto end;\n    }\n#ifndef OPENSSL_NO_NEXTPROTONEG\n    if (next_proto.data)\n        SSL_CTX_set_next_protos_advertised_cb(ctx, next_proto_cb,\n                                              &next_proto);\n#endif\n    if (alpn_ctx.data)\n        SSL_CTX_set_alpn_select_cb(ctx, alpn_cb, &alpn_ctx);\n#ifndef OPENSSL_NO_DH\n    if (!no_dhe) {\n        DH *dh = NULL;\n        if (dhfile)\n            dh = load_dh_param(dhfile);\n        else if (s_cert_file)\n            dh = load_dh_param(s_cert_file);\n        if (dh != NULL) {\n            BIO_printf(bio_s_out, "Setting temp DH parameters\\n");\n        } else {\n            BIO_printf(bio_s_out, "Using default temp DH parameters\\n");\n        }\n        (void)BIO_flush(bio_s_out);\n        if (dh == NULL)\n            SSL_CTX_set_dh_auto(ctx, 1);\n        else if (!SSL_CTX_set_tmp_dh(ctx, dh)) {\n            BIO_puts(bio_err, "Error setting temp DH parameters\\n");\n            ERR_print_errors(bio_err);\n            DH_free(dh);\n            goto end;\n        }\n        if (ctx2) {\n            if (!dhfile) {\n                DH *dh2 = load_dh_param(s_cert_file2);\n                if (dh2 != NULL) {\n                    BIO_printf(bio_s_out, "Setting temp DH parameters\\n");\n                    (void)BIO_flush(bio_s_out);\n                    DH_free(dh);\n                    dh = dh2;\n                }\n            }\n            if (dh == NULL)\n                SSL_CTX_set_dh_auto(ctx2, 1);\n            else if (!SSL_CTX_set_tmp_dh(ctx2, dh)) {\n                BIO_puts(bio_err, "Error setting temp DH parameters\\n");\n                ERR_print_errors(bio_err);\n                DH_free(dh);\n                goto end;\n            }\n        }\n        DH_free(dh);\n    }\n#endif\n    if (!set_cert_key_stuff(ctx, s_cert, s_key, s_chain, build_chain))\n        goto end;\n    if (s_serverinfo_file != NULL\n        && !SSL_CTX_use_serverinfo_file(ctx, s_serverinfo_file)) {\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (ctx2 && !set_cert_key_stuff(ctx2, s_cert2, s_key2, NULL, build_chain))\n        goto end;\n    if (s_dcert != NULL) {\n        if (!set_cert_key_stuff(ctx, s_dcert, s_dkey, s_dchain, build_chain))\n            goto end;\n    }\n    if (no_resume_ephemeral) {\n        SSL_CTX_set_not_resumable_session_callback(ctx,\n                                                   not_resumable_sess_cb);\n        if (ctx2)\n            SSL_CTX_set_not_resumable_session_callback(ctx2,\n                                                       not_resumable_sess_cb);\n    }\n#ifndef OPENSSL_NO_PSK\n    if (psk_key != NULL) {\n        if (s_debug)\n            BIO_printf(bio_s_out, "PSK key given, setting server callback\\n");\n        SSL_CTX_set_psk_server_callback(ctx, psk_server_cb);\n    }\n    if (!SSL_CTX_use_psk_identity_hint(ctx, psk_identity_hint)) {\n        BIO_printf(bio_err, "error setting PSK identity hint to context\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n#endif\n    SSL_CTX_set_verify(ctx, s_server_verify, verify_callback);\n    if (!SSL_CTX_set_session_id_context(ctx,\n                                        (void *)&s_server_session_id_context,\n                                        sizeof s_server_session_id_context)) {\n        BIO_printf(bio_err, "error setting session id context\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    SSL_CTX_set_cookie_generate_cb(ctx, generate_cookie_callback);\n    SSL_CTX_set_cookie_verify_cb(ctx, verify_cookie_callback);\n    if (ctx2) {\n        SSL_CTX_set_verify(ctx2, s_server_verify, verify_callback);\n        if (!SSL_CTX_set_session_id_context(ctx2,\n                    (void *)&s_server_session_id_context,\n                    sizeof s_server_session_id_context)) {\n            BIO_printf(bio_err, "error setting session id context\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        tlsextcbp.biodebug = bio_s_out;\n        SSL_CTX_set_tlsext_servername_callback(ctx2, ssl_servername_cb);\n        SSL_CTX_set_tlsext_servername_arg(ctx2, &tlsextcbp);\n        SSL_CTX_set_tlsext_servername_callback(ctx, ssl_servername_cb);\n        SSL_CTX_set_tlsext_servername_arg(ctx, &tlsextcbp);\n    }\n#ifndef OPENSSL_NO_SRP\n    if (srp_verifier_file != NULL) {\n        srp_callback_parm.vb = SRP_VBASE_new(srpuserseed);\n        srp_callback_parm.user = NULL;\n        srp_callback_parm.login = NULL;\n        if ((ret =\n             SRP_VBASE_init(srp_callback_parm.vb,\n                            srp_verifier_file)) != SRP_NO_ERROR) {\n            BIO_printf(bio_err,\n                       "Cannot initialize SRP verifier file \\"%s\\":ret=%d\\n",\n                       srp_verifier_file, ret);\n            goto end;\n        }\n        SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, verify_callback);\n        SSL_CTX_set_srp_cb_arg(ctx, &srp_callback_parm);\n        SSL_CTX_set_srp_username_callback(ctx, ssl_srp_server_param_cb);\n    } else\n#endif\n    if (CAfile != NULL) {\n        SSL_CTX_set_client_CA_list(ctx, SSL_load_client_CA_file(CAfile));\n        if (ctx2)\n            SSL_CTX_set_client_CA_list(ctx2, SSL_load_client_CA_file(CAfile));\n    }\n#ifndef OPENSSL_NO_OCSP\n    if (s_tlsextstatus) {\n        SSL_CTX_set_tlsext_status_cb(ctx, cert_status_cb);\n        SSL_CTX_set_tlsext_status_arg(ctx, &tlscstatp);\n        if (ctx2) {\n            SSL_CTX_set_tlsext_status_cb(ctx2, cert_status_cb);\n            SSL_CTX_set_tlsext_status_arg(ctx2, &tlscstatp);\n        }\n    }\n#endif\n    if (set_keylog_file(ctx, keylog_file))\n        goto end;\n    BIO_printf(bio_s_out, "ACCEPT\\n");\n    (void)BIO_flush(bio_s_out);\n    if (rev)\n        server_cb = rev_body;\n    else if (www)\n        server_cb = www_body;\n    else\n        server_cb = sv_body;\n#ifdef AF_UNIX\n    if (socket_family == AF_UNIX\n        && unlink_unix_path)\n        unlink(host);\n#endif\n    do_server(&accept_socket, host, port, socket_family, socket_type,\n              server_cb, context, naccept);\n    print_stats(bio_s_out, ctx);\n    ret = 0;\n end:\n    SSL_CTX_free(ctx);\n    set_keylog_file(NULL, NULL);\n    X509_free(s_cert);\n    sk_X509_CRL_pop_free(crls, X509_CRL_free);\n    X509_free(s_dcert);\n    EVP_PKEY_free(s_key);\n    EVP_PKEY_free(s_dkey);\n    sk_X509_pop_free(s_chain, X509_free);\n    sk_X509_pop_free(s_dchain, X509_free);\n    OPENSSL_free(pass);\n    OPENSSL_free(dpass);\n    OPENSSL_free(host);\n    OPENSSL_free(port);\n    X509_VERIFY_PARAM_free(vpm);\n    free_sessions();\n    OPENSSL_free(tlscstatp.host);\n    OPENSSL_free(tlscstatp.port);\n    OPENSSL_free(tlscstatp.path);\n    SSL_CTX_free(ctx2);\n    X509_free(s_cert2);\n    EVP_PKEY_free(s_key2);\n#ifndef OPENSSL_NO_NEXTPROTONEG\n    OPENSSL_free(next_proto.data);\n#endif\n    OPENSSL_free(alpn_ctx.data);\n    ssl_excert_free(exc);\n    sk_OPENSSL_STRING_free(ssl_args);\n    SSL_CONF_CTX_free(cctx);\n    release_engine(engine);\n    BIO_free(bio_s_out);\n    bio_s_out = NULL;\n    BIO_free(bio_s_msg);\n    bio_s_msg = NULL;\n#ifdef CHARSET_EBCDIC\n    BIO_meth_free(methods_ebcdic);\n#endif\n    return (ret);\n}', 'int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file)\n{\n    int error_code;\n    STACK_OF(SRP_gN) *SRP_gN_tab = sk_SRP_gN_new_null();\n    char *last_index = NULL;\n    int i;\n    char **pp;\n    SRP_gN *gN = NULL;\n    SRP_user_pwd *user_pwd = NULL;\n    TXT_DB *tmpdb = NULL;\n    BIO *in = BIO_new(BIO_s_file());\n    error_code = SRP_ERR_OPEN_FILE;\n    if (in == NULL || BIO_read_filename(in, verifier_file) <= 0)\n        goto err;\n    error_code = SRP_ERR_VBASE_INCOMPLETE_FILE;\n    if ((tmpdb = TXT_DB_read(in, DB_NUMBER)) == NULL)\n        goto err;\n    error_code = SRP_ERR_MEMORY;\n    if (vb->seed_key) {\n        last_index = SRP_get_default_gN(NULL)->id;\n    }\n    for (i = 0; i < sk_OPENSSL_PSTRING_num(tmpdb->data); i++) {\n        pp = sk_OPENSSL_PSTRING_value(tmpdb->data, i);\n        if (pp[DB_srptype][0] == DB_SRP_INDEX) {\n            if ((gN = OPENSSL_malloc(sizeof(*gN))) == NULL)\n                goto err;\n            if ((gN->id = OPENSSL_strdup(pp[DB_srpid])) == NULL\n                || (gN->N = SRP_gN_place_bn(vb->gN_cache, pp[DB_srpverifier]))\n                        == NULL\n                || (gN->g = SRP_gN_place_bn(vb->gN_cache, pp[DB_srpsalt]))\n                        == NULL\n                || sk_SRP_gN_insert(SRP_gN_tab, gN, 0) == 0)\n                goto err;\n            gN = NULL;\n            if (vb->seed_key != NULL) {\n                last_index = pp[DB_srpid];\n            }\n        } else if (pp[DB_srptype][0] == DB_SRP_VALID) {\n            const SRP_gN *lgN;\n            if ((lgN = SRP_get_gN_by_id(pp[DB_srpgN], SRP_gN_tab)) != NULL) {\n                error_code = SRP_ERR_MEMORY;\n                if ((user_pwd = SRP_user_pwd_new()) == NULL)\n                    goto err;\n                SRP_user_pwd_set_gN(user_pwd, lgN->g, lgN->N);\n                if (!SRP_user_pwd_set_ids\n                    (user_pwd, pp[DB_srpid], pp[DB_srpinfo]))\n                    goto err;\n                error_code = SRP_ERR_VBASE_BN_LIB;\n                if (!SRP_user_pwd_set_sv\n                    (user_pwd, pp[DB_srpsalt], pp[DB_srpverifier]))\n                    goto err;\n                if (sk_SRP_user_pwd_insert(vb->users_pwd, user_pwd, 0) == 0)\n                    goto err;\n                user_pwd = NULL;\n            }\n        }\n    }\n    if (last_index != NULL) {\n        if (((gN = SRP_get_gN_by_id(last_index, SRP_gN_tab)) == NULL)) {\n            error_code = SRP_ERR_VBASE_BN_LIB;\n            goto err;\n        }\n        vb->default_g = gN->g;\n        vb->default_N = gN->N;\n        gN = NULL;\n    }\n    error_code = SRP_NO_ERROR;\n err:\n    if (gN != NULL) {\n        OPENSSL_free(gN->id);\n        OPENSSL_free(gN);\n    }\n    SRP_user_pwd_free(user_pwd);\n    TXT_DB_free(tmpdb);\n    BIO_free_all(in);\n    sk_SRP_gN_free(SRP_gN_tab);\n    return error_code;\n}', 'void TXT_DB_free(TXT_DB *db)\n{\n    int i, n;\n    char **p, *max;\n    if (db == NULL)\n        return;\n    if (db->index != NULL) {\n        for (i = db->num_fields - 1; i >= 0; i--)\n            lh_OPENSSL_STRING_free(db->index[i]);\n        OPENSSL_free(db->index);\n    }\n    OPENSSL_free(db->qual);\n    if (db->data != NULL) {\n        for (i = sk_OPENSSL_PSTRING_num(db->data) - 1; i >= 0; i--) {\n            p = sk_OPENSSL_PSTRING_value(db->data, i);\n            max = p[db->num_fields];\n            if (max == NULL) {\n                for (n = 0; n < db->num_fields; n++)\n                    OPENSSL_free(p[n]);\n            } else {\n                for (n = 0; n < db->num_fields; n++) {\n                    if (((p[n] < (char *)p) || (p[n] > max)))\n                        OPENSSL_free(p[n]);\n                }\n            }\n            OPENSSL_free(sk_OPENSSL_PSTRING_value(db->data, i));\n        }\n        sk_OPENSSL_PSTRING_free(db->data);\n    }\n    OPENSSL_free(db);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n    int i;\n    if (a == NULL)\n        return;\n    CRYPTO_DOWN_REF(&a->references, &i, a->lock);\n    REF_PRINT_COUNT("SSL_CTX", a);\n    if (i > 0)\n        return;\n    REF_ASSERT_ISNT(i < 0);\n    X509_VERIFY_PARAM_free(a->param);\n    dane_ctx_final(&a->dane);\n    if (a->sessions != NULL)\n        SSL_CTX_flush_sessions(a, 0);\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n    lh_SSL_SESSION_free(a->sessions);\n    X509_STORE_free(a->cert_store);\n#ifndef OPENSSL_NO_CT\n    CTLOG_STORE_free(a->ctlog_store);\n#endif\n    sk_SSL_CIPHER_free(a->cipher_list);\n    sk_SSL_CIPHER_free(a->cipher_list_by_id);\n    ssl_cert_free(a->cert);\n    sk_X509_NAME_pop_free(a->client_CA, X509_NAME_free);\n    sk_X509_pop_free(a->extra_certs, X509_free);\n    a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n    sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n    SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n    ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n    OPENSSL_free(a->ext.ecpointformats);\n    OPENSSL_free(a->ext.supportedgroups);\n#endif\n    OPENSSL_free(a->ext.alpn);\n    CRYPTO_THREAD_lock_free(a->lock);\n    OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n    unsigned long i;\n    TIMEOUT_PARAM tp;\n    tp.ctx = s;\n    tp.cache = s->sessions;\n    if (tp.cache == NULL)\n        return;\n    tp.time = t;\n    CRYPTO_THREAD_write_lock(s->lock);\n    i = lh_SSL_SESSION_get_down_load(s->sessions);\n    lh_SSL_SESSION_set_down_load(s->sessions, 0);\n    lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);\n    lh_SSL_SESSION_set_down_load(s->sessions, i);\n    CRYPTO_THREAD_unlock(s->lock);\n}', 'IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM)', 'void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)\n{\n    doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);\n}', 'static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,\n                          OPENSSL_LH_DOALL_FUNC func,\n                          OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)\n{\n    int i;\n    OPENSSL_LH_NODE *a, *n;\n    if (lh == NULL)\n        return;\n    for (i = lh->num_nodes - 1; i >= 0; i--) {\n        a = lh->b[i];\n        while (a != NULL) {\n            n = a->next;\n            if (use_arg)\n                func_arg(a->data, arg);\n            else\n                func(a->data);\n            a = n;\n        }\n    }\n}']