FreeBSD/contrib/serf/auth/auth.c
/**
 * handle_auth_header is called for each header in the response. It filters
 * out the Authenticate headers (WWW or Proxy depending on what's needed) and
 * tries to find a matching scheme handler.
 *
 * Returns a non-0 value of a matching handler was found.
 */
handle_auth_header is called for each header in the response. It filters
out the Authenticate headers (WWW or Proxy depending on what's needed) and
tries to find a matching scheme handler.

Returns a non-0 value of a matching handler was found.
handle_auth_header is called for each header in the response . It filters out the Authenticate headers ( WWW or Proxy depending on what ' s needed ) and tries to find a matching scheme handler . Returns a non - 0 value of a matching handler was found .
static int handle_auth_headers(int code,
                               void *baton,
                               apr_hash_t *hdrs,
                               serf_request_t *request,
                               serf_bucket_t *response,
                               apr_pool_t *pool)
{
    const serf__authn_scheme_t *scheme;
    serf_connection_t *conn = request->conn;
    serf_context_t *ctx = conn->ctx;
    apr_status_t status;
    status = SERF_ERROR_AUTHN_NOT_SUPPORTED;
    for (scheme = serf_authn_schemes; scheme->name != 0; ++scheme) {
        const char *auth_hdr;
        serf__auth_handler_func_t handler;
        serf__authn_info_t *authn_info;
        if (! (ctx->authn_types & scheme->type))
            continue;
        serf__log_skt(AUTH_VERBOSE, __FILE__, conn->skt,
                      "Client supports: %s\n", scheme->name);
        auth_hdr = apr_hash_get(hdrs, scheme->key, APR_HASH_KEY_STRING);
        if (!auth_hdr)
            continue;
        if (code == 401) {
            authn_info = serf__get_authn_info_for_server(conn);
        } else {
            authn_info = &ctx->proxy_authn_info;
        }
        if (authn_info->failed_authn_types & scheme->type) {
            continue;
        }
        status = APR_SUCCESS;
        handler = scheme->handle_func;
        serf__log_skt(AUTH_VERBOSE, __FILE__, conn->skt,
                      "... matched: %s\n", scheme->name);
        if (authn_info->scheme != scheme) {
            status = scheme->init_ctx_func(code, ctx, ctx->pool);
            if (!status) {
                status = scheme->init_conn_func(scheme, code, conn,
                                                conn->pool);
                if (!status)
                    authn_info->scheme = scheme;
                else
                    authn_info->scheme = NULL;
            }
        }
        if (!status) {
            const char *auth_attr = strchr(auth_hdr, ' ');
            if (auth_attr) {
                auth_attr++;
            }
            status = handler(code, request, response,
                             auth_hdr, auth_attr, baton, ctx->pool);
        }
        if (status == APR_SUCCESS)
            break;
        serf__log_skt(AUTH_VERBOSE, __FILE__, conn->skt,
                      "%s authentication failed.\n", scheme->name);
        request->auth_baton = NULL;
        authn_info->failed_authn_types |= scheme->type;
    }
    return status;
}
static int handle_auth_headers ( int code , void * baton , apr_hash_t * hdrs , serf_request_t * request , serf_bucket_t * response , apr_pool_t * pool ) { const serf__authn_scheme_t * scheme ; serf_connection_t * conn = request -> conn ; serf_context_t * ctx = conn -> ctx ; apr_status_t status ; status = SERF_ERROR_AUTHN_NOT_SUPPORTED ; for ( scheme = serf_authn_schemes ; scheme -> name != 0 ; ++ scheme ) { const char * auth_hdr ; serf__auth_handler_func_t handler ; serf__authn_info_t * authn_info ; if ( ! ( ctx -> authn_types & scheme -> type ) ) continue ; serf__log_skt ( AUTH_VERBOSE , __FILE__ , conn -> skt , " \n " , scheme -> name ) ; auth_hdr = apr_hash_get ( hdrs , scheme -> key , APR_HASH_KEY_STRING ) ; if ( ! auth_hdr ) continue ; if ( code == 401 ) { authn_info = serf__get_authn_info_for_server ( conn ) ; } else { authn_info = & ctx -> proxy_authn_info ; } if ( authn_info -> failed_authn_types & scheme -> type ) { continue ; } status = APR_SUCCESS ; handler = scheme -> handle_func ; serf__log_skt ( AUTH_VERBOSE , __FILE__ , conn -> skt , " \n " , scheme -> name ) ; if ( authn_info -> scheme != scheme ) { status = scheme -> init_ctx_func ( code , ctx , ctx -> pool ) ; if ( ! status ) { status = scheme -> init_conn_func ( scheme , code , conn , conn -> pool ) ; if ( ! status ) authn_info -> scheme = scheme ; else authn_info -> scheme = NULL ; } } if ( ! status ) { const char * auth_attr = strchr ( auth_hdr , ' ' ) ; if ( auth_attr ) { auth_attr ++ ; } status = handler ( code , request , response , auth_hdr , auth_attr , baton , ctx -> pool ) ; } if ( status == APR_SUCCESS ) break ; serf__log_skt ( AUTH_VERBOSE , __FILE__ , conn -> skt , " \n " , scheme -> name ) ; request -> auth_baton = NULL ; authn_info -> failed_authn_types |= scheme -> type ; } return status ; }
handle_auth_header is called for each header in the response.
handle_auth_header is called for each header in the response .
/* Find the matching authentication handler.
       Note that we don't reuse the auth scheme stored in the context,
       as that may have changed. (ex. fallback from ntlm to basic.) */ /* Skip this authn type since we already tried it before. */ /* Found a matching scheme */ /* If this is the first time we use this scheme on this context and/or
           this connection, make sure to initialize the authentication handler 
           first. */ /* No success authenticating with this scheme, try the next.
           If no more authn schemes are found the status of this scheme will be
           returned.
        */ /* Clear per-request auth_baton when switching to next auth scheme. */ /* Remember failed auth types to skip in future. */