//-----------------------------------------------------------------------------
// 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_header_var
//
// purpose	Build an HTTP header string from a va_list argument and place
//		it in the HTTP header queue.
//
// arguments	1 (int) priority (lowest first)
//		2 (const char *) header name
//		3 (va_list) va_list of strings ended with NULL
//
// returns	(int) -1 : error
//		(int)  0 : OK
//-----------------------------------------------------------------------------
int
http_header_var (
    int			arg_priority
    ,
    const char *	arg_header
    ,
    va_list		arg_str_list
    )
__PROTO_END__
{
    char	work_str	[ HTTP_MAX_HEADER_LENGTH ];

    //-- If HTTP is already done, return an error.
    if ( http_done ) return -1;

    //-- Start empty.
    work_str[0] = 0;

    //-- Append header name and ": " separator.
    if ( str_app_arg( work_str, HTTP_MAX_HEADER_LENGTH, arg_header, ": ", NULL ) == ~ (size_t) 0 ) return -1;

    //-- Append each string with " " between.
    if ( str_app_var_sep( work_str, HTTP_MAX_HEADER_LENGTH, " ", arg_str_list ) == ~ (size_t) 0 ) return -1;

    //-- Put string in HTTP header queue.
    return http_header_str( arg_priority, work_str );
}

