static void ssl_handle_id_based_session_resumption( mbedtls_ssl_context *ssl )
{
    int ret;
    mbedtls_ssl_session session_tmp;
    mbedtls_ssl_session * const session = ssl->session_negotiate;

    /* Resume is 0  by default, see ssl_handshake_init().
     * It may be already set to 1 by ssl_parse_session_ticket_ext(). */
    if( ssl->handshake->resume == 1 )
        return;
    if( session->id_len == 0 )
        return;
    if( ssl->conf->f_get_cache == NULL )
        return;
#if defined(MBEDTLS_SSL_RENEGOTIATION)
    if( ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE )
        return;
#endif

    mbedtls_ssl_session_init( &session_tmp );

    session_tmp.id_len = session->id_len;
    memcpy( session_tmp.id, session->id, session->id_len );

    ret = ssl->conf->f_get_cache( ssl->conf->p_cache,
                                  &session_tmp );
    if( ret != 0 )
        goto exit;

    if( session->ciphersuite != session_tmp.ciphersuite ||
        session->compression != session_tmp.compression )
    {
        /* Mismatch between cached and negotiated session */
        goto exit;
    }

    /* Move semantics */
    mbedtls_ssl_session_free( session );
    *session = session_tmp;
    memset( &session_tmp, 0, sizeof( session_tmp ) );

    MBEDTLS_SSL_DEBUG_MSG( 3, ( "session successfully restored from cache" ) );
    ssl->handshake->resume = 1;

exit:

    mbedtls_ssl_session_free( &session_tmp );
}
static void ssl_handle_id_based_session_resumption( mbedtls_ssl_context *ssl )
{
    int ret;
    mbedtls_ssl_session session_tmp;
    mbedtls_ssl_session * const session = ssl->session_negotiate;

     
    if( ssl->handshake->resume == 1 )
        return;
    if( session->id_len == 0 )
        return;
    if( ssl->conf->f_get_cache == NULL )
        return;
#if defined(MBEDTLS_SSL_RENEGOTIATION)
    if( ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE )
        return;
#endif

    mbedtls_ssl_session_init( &session_tmp );

    session_tmp.id_len = session->id_len;
    memcpy( session_tmp.id, session->id, session->id_len );

    ret = ssl->conf->f_get_cache( ssl->conf->p_cache,
                                  &session_tmp );
    if( ret != 0 )
        goto exit;

    if( session->ciphersuite != session_tmp.ciphersuite ||
        session->compression != session_tmp.compression )
    {
         
        goto exit;
    }

     
    mbedtls_ssl_session_free( session );
    *session = session_tmp;
    memset( &session_tmp, 0, sizeof( session_tmp ) );

    MBEDTLS_SSL_DEBUG_MSG( 3, ( "session successfully restored from cache" ) );
    ssl->handshake->resume = 1;

exit:

    mbedtls_ssl_session_free( &session_tmp );
}