FreeBSD/contrib/serf/auth/auth.c
/* Read the headers of the response and try the available
   handlers if authentication or validation is needed. */
Read the headers of the response and try the available
handlers if authentication or validation is needed.
Read the headers of the response and try the available handlers if authentication or validation is needed .
apr_status_t serf__handle_auth_response(int *consumed_response,
                                        serf_request_t *request,
                                        serf_bucket_t *response,
                                        void *baton,
                                        apr_pool_t *pool)
{
    apr_status_t status;
    serf_status_line sl;
    *consumed_response = 0;
    status = serf_bucket_response_status(response, &sl);
    if (SERF_BUCKET_READ_ERROR(status)) {
        return status;
    }
    if (!sl.version && (APR_STATUS_IS_EOF(status) ||
                        APR_STATUS_IS_EAGAIN(status))) {
        return status;
    }
    status = serf_bucket_response_wait_for_headers(response);
    if (status) {
        if (!APR_STATUS_IS_EOF(status)) {
            return status;
        }
        return APR_SUCCESS;
    }
    if (sl.code == 401 || sl.code == 407) {
        status = discard_body(response);
        *consumed_response = 1;
        if (!APR_STATUS_IS_EOF(status)) {
            return status;
        }
        status = dispatch_auth(sl.code, request, response, baton, pool);
        if (status != APR_SUCCESS) {
            return status;
        }
        if (request->ssltunnel) {
            serf__ssltunnel_request_create(request->conn,
                                           request->setup,
                                           request->setup_baton);
        } else {
            serf_connection_priority_request_create(request->conn,
                                                    request->setup,
                                                    request->setup_baton);
        }
        return APR_EOF;
    } else {
        serf__validate_response_func_t validate_resp;
        serf_connection_t *conn = request->conn;
        serf_context_t *ctx = conn->ctx;
        serf__authn_info_t *authn_info;
        apr_status_t resp_status = APR_SUCCESS;
        authn_info = serf__get_authn_info_for_server(conn);
        if (authn_info->scheme) {
            validate_resp = authn_info->scheme->validate_response_func;
            resp_status = validate_resp(authn_info->scheme, HOST, sl.code,
                                        conn, request, response, pool);
        }
        authn_info = &ctx->proxy_authn_info;
        if (!resp_status && authn_info->scheme) {
            validate_resp = authn_info->scheme->validate_response_func;
            resp_status = validate_resp(authn_info->scheme, PROXY, sl.code,
                                        conn, request, response, pool);
        }
        if (resp_status) {
            status = discard_body(response);
            *consumed_response = 1;
            if (!APR_STATUS_IS_EOF(status)) {
                return status;
            }
            return resp_status;
        }
    }
    return APR_SUCCESS;
}
apr_status_t serf__handle_auth_response ( int * consumed_response , serf_request_t * request , serf_bucket_t * response , void * baton , apr_pool_t * pool ) { apr_status_t status ; serf_status_line sl ; * consumed_response = 0 ; status = serf_bucket_response_status ( response , & sl ) ; if ( SERF_BUCKET_READ_ERROR ( status ) ) { return status ; } if ( ! sl . version && ( APR_STATUS_IS_EOF ( status ) || APR_STATUS_IS_EAGAIN ( status ) ) ) { return status ; } status = serf_bucket_response_wait_for_headers ( response ) ; if ( status ) { if ( ! APR_STATUS_IS_EOF ( status ) ) { return status ; } return APR_SUCCESS ; } if ( sl . code == 401 || sl . code == 407 ) { status = discard_body ( response ) ; * consumed_response = 1 ; if ( ! APR_STATUS_IS_EOF ( status ) ) { return status ; } status = dispatch_auth ( sl . code , request , response , baton , pool ) ; if ( status != APR_SUCCESS ) { return status ; } if ( request -> ssltunnel ) { serf__ssltunnel_request_create ( request -> conn , request -> setup , request -> setup_baton ) ; } else { serf_connection_priority_request_create ( request -> conn , request -> setup , request -> setup_baton ) ; } return APR_EOF ; } else { serf__validate_response_func_t validate_resp ; serf_connection_t * conn = request -> conn ; serf_context_t * ctx = conn -> ctx ; serf__authn_info_t * authn_info ; apr_status_t resp_status = APR_SUCCESS ; authn_info = serf__get_authn_info_for_server ( conn ) ; if ( authn_info -> scheme ) { validate_resp = authn_info -> scheme -> validate_response_func ; resp_status = validate_resp ( authn_info -> scheme , HOST , sl . code , conn , request , response , pool ) ; } authn_info = & ctx -> proxy_authn_info ; if ( ! resp_status && authn_info -> scheme ) { validate_resp = authn_info -> scheme -> validate_response_func ; resp_status = validate_resp ( authn_info -> scheme , PROXY , sl . code , conn , request , response , pool ) ; } if ( resp_status ) { status = discard_body ( response ) ; * consumed_response = 1 ; if ( ! APR_STATUS_IS_EOF ( status ) ) { return status ; } return resp_status ; } } return APR_SUCCESS ; }
Read the headers of the response and try the available
handlers if authentication or validation is needed.
Read the headers of the response and try the available handlers if authentication or validation is needed .
/* TODO: the response bucket was created by the application, not at all
       guaranteed that this is of type response_bucket!! */ /* If status is APR_EOF, there were no headers to read.
           This can be ok in some situations, and it definitely
           means there's no authentication requested now. */ /* Authentication requested. */ /* Don't bother handling the authentication request if the response
           wasn't received completely yet. Serf will call serf__handle_auth_response
           again when more data is received. */ /* Discard all response body before processing authentication. */ /* Requeue the request with the necessary auth headers. */ /* ### Application doesn't know about this request! */ /* Validate the response server authn headers. */ /* Validate the response proxy authn headers. */ /* If there was an error in the final step of the authentication,
               consider the reponse body as invalid and discard it. */ /* The whole body was discarded, now return our error. */