static int select_server_ctx(SSL *s, void *arg, int ignore)
{
    const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
    HANDSHAKE_EX_DATA *ex_data =
        (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
    if (servername == NULL) {
        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
        return SSL_TLSEXT_ERR_NOACK;
    }
    if (strcmp(servername, "server2") == 0) {
        SSL_CTX *new_ctx = (SSL_CTX*)arg;
        SSL_set_SSL_CTX(s, new_ctx);
        SSL_clear_options(s, 0xFFFFFFFFL);
        SSL_set_options(s, SSL_CTX_get_options(new_ctx));
        ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;
        return SSL_TLSEXT_ERR_OK;
    } else if (strcmp(servername, "server1") == 0) {
        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
        return SSL_TLSEXT_ERR_OK;
    } else if (ignore) {
        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
        return SSL_TLSEXT_ERR_NOACK;
    } else {
        return SSL_TLSEXT_ERR_ALERT_FATAL;
    }
}
['static int select_server_ctx(SSL *s, void *arg, int ignore)\n{\n    const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);\n    HANDSHAKE_EX_DATA *ex_data =\n        (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n    if (servername == NULL) {\n        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n        return SSL_TLSEXT_ERR_NOACK;\n    }\n    if (strcmp(servername, "server2") == 0) {\n        SSL_CTX *new_ctx = (SSL_CTX*)arg;\n        SSL_set_SSL_CTX(s, new_ctx);\n        SSL_clear_options(s, 0xFFFFFFFFL);\n        SSL_set_options(s, SSL_CTX_get_options(new_ctx));\n        ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;\n        return SSL_TLSEXT_ERR_OK;\n    } else if (strcmp(servername, "server1") == 0) {\n        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n        return SSL_TLSEXT_ERR_OK;\n    } else if (ignore) {\n        ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n        return SSL_TLSEXT_ERR_NOACK;\n    } else {\n        return SSL_TLSEXT_ERR_ALERT_FATAL;\n    }\n}', 'const char *SSL_get_servername(const SSL *s, const int type)\n{\n    if (type != TLSEXT_NAMETYPE_host_name)\n        return NULL;\n    return s->session && !s->ext.hostname ?\n        s->session->ext.hostname : s->ext.hostname;\n}', 'void *SSL_get_ex_data(const SSL *s, int idx)\n{\n    return CRYPTO_get_ex_data(&s->ex_data, idx);\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n    if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n        return NULL;\n    return sk_void_value(ad->sk, idx);\n}']