//-----------------------------------------------------------------------------
// Copyright © 2003 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/http
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	phil at ipal dot org
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 112 columns wide.
//-----------------------------------------------------------------------------

#include "http_lib.h"

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	http_auth_fail
//
// purpose	Handle HTTP authorization authentication failure by prompting
//		for a username and password.
//
// arguments	1 (const char *) NULL or alternate realm name to use.
//
// returns	(int) 0
//-----------------------------------------------------------------------------
int
http_auth_fail (
    const char *	arg_realm
)
__PROTO_END__
{
    //-- If HTTP is already done, return an error.
    if ( http_done ) return -1;

    //-- If not specified, choose a default realm.
    if ( ! arg_realm ) arg_realm = http_auth_realm;
    if ( ! arg_realm ) arg_realm = "user_login";

    //-- Force authorization prompt.
    http_discard();
    http_response_str( HTTP_RESPONSE_401 );
    http_header( -128, "WWW-Authenticate", "Basic realm=\"", arg_realm, "\"", NULL );
    http_no_cache();
    http_header( 0, "Content-Type", "text/html", NULL );
    http_commit_put();

    return 0;
}

