Blame libsoup/soup-message-headers.c

rpm-build 4f3c61
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
rpm-build 4f3c61
/*
rpm-build 4f3c61
 * soup-message-headers.c: HTTP message header arrays
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Copyright (C) 2007, 2008 Red Hat, Inc.
rpm-build 4f3c61
 */
rpm-build 4f3c61
rpm-build 4f3c61
#ifdef HAVE_CONFIG_H
rpm-build 4f3c61
#include <config.h>
rpm-build 4f3c61
#endif
rpm-build 4f3c61
rpm-build 4f3c61
#include <string.h>
rpm-build 4f3c61
rpm-build 4f3c61
#include "soup-message-headers.h"
rpm-build 4f3c61
#include "soup.h"
rpm-build 4f3c61
#include "soup-misc-private.h"
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * SECTION:soup-message-headers
rpm-build 4f3c61
 * @short_description: HTTP message headers
rpm-build 4f3c61
 * @see_also: #SoupMessage
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * #SoupMessageHeaders represents the HTTP message headers associated
rpm-build 4f3c61
 * with a request or response.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * SoupMessageHeaders:
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * The HTTP message headers associated with a request or response.
rpm-build 4f3c61
 */
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * SoupMessageHeadersType:
rpm-build 4f3c61
 * @SOUP_MESSAGE_HEADERS_REQUEST: request headers
rpm-build 4f3c61
 * @SOUP_MESSAGE_HEADERS_RESPONSE: response headers
rpm-build 4f3c61
 * @SOUP_MESSAGE_HEADERS_MULTIPART: multipart body part headers
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Value passed to soup_message_headers_new() to set certain default
rpm-build 4f3c61
 * behaviors.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
rpm-build 4f3c61
typedef void (*SoupHeaderSetter) (SoupMessageHeaders *, const char *);
rpm-build 4f3c61
static const char *intern_header_name (const char *name, SoupHeaderSetter *setter);
rpm-build 4f3c61
static void clear_special_headers (SoupMessageHeaders *hdrs);
rpm-build 4f3c61
rpm-build 4f3c61
typedef struct {
rpm-build 4f3c61
	const char *name;
rpm-build 4f3c61
	char *value;
rpm-build 4f3c61
} SoupHeader;
rpm-build 4f3c61
rpm-build 4f3c61
struct SoupMessageHeaders {
rpm-build 4f3c61
	GArray *array;
rpm-build 4f3c61
	GHashTable *concat;
rpm-build 4f3c61
	SoupMessageHeadersType type;
rpm-build 4f3c61
rpm-build 4f3c61
	SoupEncoding encoding;
rpm-build 4f3c61
	goffset content_length;
rpm-build 4f3c61
	SoupExpectation expectations;
rpm-build 4f3c61
	char *content_type;
rpm-build 4f3c61
rpm-build 4f3c61
	int ref_count;
rpm-build 4f3c61
};
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_new:
rpm-build 4f3c61
 * @type: the type of headers
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Creates a #SoupMessageHeaders. (#SoupMessage does this
rpm-build 4f3c61
 * automatically for its own headers. You would only need to use this
rpm-build 4f3c61
 * method if you are manually parsing or generating message headers.)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: a new #SoupMessageHeaders
rpm-build 4f3c61
 **/
rpm-build 4f3c61
SoupMessageHeaders *
rpm-build 4f3c61
soup_message_headers_new (SoupMessageHeadersType type)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupMessageHeaders *hdrs;
rpm-build 4f3c61
rpm-build 4f3c61
	hdrs = g_slice_new0 (SoupMessageHeaders);
rpm-build 4f3c61
	/* FIXME: is "5" a good default? */
rpm-build 4f3c61
	hdrs->array = g_array_sized_new (TRUE, FALSE, sizeof (SoupHeader), 5);
rpm-build 4f3c61
	hdrs->type = type;
rpm-build 4f3c61
	hdrs->encoding = -1;
rpm-build 4f3c61
	hdrs->ref_count = 1;
rpm-build 4f3c61
rpm-build 4f3c61
	return hdrs;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static SoupMessageHeaders *
rpm-build 4f3c61
soup_message_headers_copy (SoupMessageHeaders *hdrs)
rpm-build 4f3c61
{
rpm-build 4f3c61
	g_atomic_int_inc (&hdrs->ref_count);
rpm-build 4f3c61
	return hdrs;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_free:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Frees @hdrs.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_free (SoupMessageHeaders *hdrs)
rpm-build 4f3c61
{
rpm-build 4f3c61
	if (!g_atomic_int_dec_and_test (&hdrs->ref_count))
rpm-build 4f3c61
		return;
rpm-build 4f3c61
rpm-build 4f3c61
	soup_message_headers_clear (hdrs);
rpm-build 4f3c61
	g_array_free (hdrs->array, TRUE);
rpm-build 4f3c61
	g_clear_pointer (&hdrs->concat, g_hash_table_destroy);
rpm-build 4f3c61
	g_slice_free (SoupMessageHeaders, hdrs);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
G_DEFINE_BOXED_TYPE (SoupMessageHeaders, soup_message_headers, soup_message_headers_copy, soup_message_headers_free)
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_get_headers_type:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Gets the type of headers.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: the header's type.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.50
rpm-build 4f3c61
 **/
rpm-build 4f3c61
SoupMessageHeadersType
rpm-build 4f3c61
soup_message_headers_get_headers_type (SoupMessageHeaders *hdrs)
rpm-build 4f3c61
{
rpm-build 4f3c61
	return hdrs->type;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_clear:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Clears @hdrs.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_clear (SoupMessageHeaders *hdrs)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupHeader *hdr_array = (SoupHeader *)hdrs->array->data;
rpm-build 4f3c61
	guint i;
rpm-build 4f3c61
rpm-build 4f3c61
	for (i = 0; i < hdrs->array->len; i++)
rpm-build 4f3c61
		g_free (hdr_array[i].value);
rpm-build 4f3c61
	g_array_set_size (hdrs->array, 0);
rpm-build 4f3c61
rpm-build 4f3c61
	if (hdrs->concat)
rpm-build 4f3c61
		g_hash_table_remove_all (hdrs->concat);
rpm-build 4f3c61
rpm-build 4f3c61
	clear_special_headers (hdrs);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_clean_connection_headers:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Removes all the headers listed in the Connection header.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.36
rpm-build 4f3c61
 */
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_clean_connection_headers (SoupMessageHeaders *hdrs)
rpm-build 4f3c61
{
rpm-build 4f3c61
	/* RFC 2616 14.10 */
rpm-build 4f3c61
	const char *connection;
rpm-build 4f3c61
	GSList *tokens, *t;
rpm-build 4f3c61
rpm-build 4f3c61
	connection = soup_message_headers_get_list (hdrs, "Connection");
rpm-build 4f3c61
	if (!connection)
rpm-build 4f3c61
		return;
rpm-build 4f3c61
rpm-build 4f3c61
	tokens = soup_header_parse_list (connection);
rpm-build 4f3c61
	for (t = tokens; t; t = t->next)
rpm-build 4f3c61
		soup_message_headers_remove (hdrs, t->data);
rpm-build 4f3c61
	soup_header_free_list (tokens);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_append:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @name: the header name to add
rpm-build 4f3c61
 * @value: the new value of @name
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Appends a new header with name @name and value @value to @hdrs. (If
rpm-build 4f3c61
 * there is an existing header with name @name, then this creates a
rpm-build 4f3c61
 * second one, which is only allowed for list-valued headers; see also
rpm-build 4f3c61
 * soup_message_headers_replace().)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * The caller is expected to make sure that @name and @value are
rpm-build 4f3c61
 * syntactically correct.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_append (SoupMessageHeaders *hdrs,
rpm-build 4f3c61
			     const char *name, const char *value)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupHeader header;
rpm-build 4f3c61
	SoupHeaderSetter setter;
rpm-build 4f3c61
rpm-build 4f3c61
	g_return_if_fail (name != NULL);
rpm-build 4f3c61
	g_return_if_fail (value != NULL);
rpm-build 4f3c61
rpm-build 4f3c61
	/* Setting a syntactically invalid header name or value is
rpm-build 4f3c61
	 * considered to be a programming error. However, it can also
rpm-build 4f3c61
	 * be a security hole, so we want to fail here even if
rpm-build 4f3c61
	 * compiled with G_DISABLE_CHECKS.
rpm-build 4f3c61
	 */
rpm-build 4f3c61
#ifndef G_DISABLE_CHECKS
rpm-build 4f3c61
	g_return_if_fail (*name && strpbrk (name, " \t\r\n:") == NULL);
rpm-build 4f3c61
	g_return_if_fail (strpbrk (value, "\r\n") == NULL);
rpm-build 4f3c61
#else
rpm-build 4f3c61
	if (*name && strpbrk (name, " \t\r\n:")) {
rpm-build 4f3c61
		g_warning ("soup_message_headers_append: Ignoring bad name '%s'", name);
rpm-build 4f3c61
		return;
rpm-build 4f3c61
	}
rpm-build 4f3c61
	if (strpbrk (value, "\r\n")) {
rpm-build 4f3c61
		g_warning ("soup_message_headers_append: Ignoring bad value '%s'", value);
rpm-build 4f3c61
		return;
rpm-build 4f3c61
	}
rpm-build 4f3c61
#endif
rpm-build 4f3c61
rpm-build 4f3c61
	header.name = intern_header_name (name, &setter);
rpm-build 4f3c61
	header.value = g_strdup (value);
rpm-build 4f3c61
	g_array_append_val (hdrs->array, header);
rpm-build 4f3c61
	if (hdrs->concat)
rpm-build 4f3c61
		g_hash_table_remove (hdrs->concat, header.name);
rpm-build 4f3c61
	if (setter)
rpm-build 4f3c61
		setter (hdrs, header.value);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_replace:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @name: the header name to replace
rpm-build 4f3c61
 * @value: the new value of @name
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Replaces the value of the header @name in @hdrs with @value. (See
rpm-build 4f3c61
 * also soup_message_headers_append().)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * The caller is expected to make sure that @name and @value are
rpm-build 4f3c61
 * syntactically correct.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_replace (SoupMessageHeaders *hdrs,
rpm-build 4f3c61
			      const char *name, const char *value)
rpm-build 4f3c61
{
rpm-build 4f3c61
	soup_message_headers_remove (hdrs, name);
rpm-build 4f3c61
	soup_message_headers_append (hdrs, name, value);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static int
rpm-build 4f3c61
find_header (SoupHeader *hdr_array, const char *interned_name, int nth)
rpm-build 4f3c61
{
rpm-build 4f3c61
	int i;
rpm-build 4f3c61
rpm-build 4f3c61
	for (i = 0; hdr_array[i].name; i++) {
rpm-build 4f3c61
		if (hdr_array[i].name == interned_name) {
rpm-build 4f3c61
			if (nth-- == 0)
rpm-build 4f3c61
				return i;
rpm-build 4f3c61
		}
rpm-build 4f3c61
	}
rpm-build 4f3c61
	return -1;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static int
rpm-build 4f3c61
find_last_header (SoupHeader *hdr_array, guint length, const char *interned_name, int nth)
rpm-build 4f3c61
{
rpm-build 4f3c61
	int i;
rpm-build 4f3c61
rpm-build 4f3c61
	for (i = length; i >= 0; i--) {
rpm-build 4f3c61
		if (hdr_array[i].name == interned_name) {
rpm-build 4f3c61
			if (nth-- == 0)
rpm-build 4f3c61
				return i;
rpm-build 4f3c61
		}
rpm-build 4f3c61
	}
rpm-build 4f3c61
	return -1;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_remove:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @name: the header name to remove
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Removes @name from @hdrs. If there are multiple values for @name,
rpm-build 4f3c61
 * they are all removed.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_remove (SoupMessageHeaders *hdrs, const char *name)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupHeader *hdr_array = (SoupHeader *)(hdrs->array->data);
rpm-build 4f3c61
	SoupHeaderSetter setter;
rpm-build 4f3c61
	int index;
rpm-build 4f3c61
rpm-build 4f3c61
	g_return_if_fail (name != NULL);
rpm-build 4f3c61
rpm-build 4f3c61
	name = intern_header_name (name, &setter);
rpm-build 4f3c61
	while ((index = find_header (hdr_array, name, 0)) != -1) {
rpm-build 4f3c61
		g_free (hdr_array[index].value);
rpm-build 4f3c61
		g_array_remove_index (hdrs->array, index);
rpm-build 4f3c61
	}
rpm-build 4f3c61
	if (hdrs->concat)
rpm-build 4f3c61
		g_hash_table_remove (hdrs->concat, name);
rpm-build 4f3c61
	if (setter)
rpm-build 4f3c61
		setter (hdrs, NULL);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_get_one:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @name: header name
rpm-build 4f3c61
 * 
rpm-build 4f3c61
 * Gets the value of header @name in @hdrs. Use this for headers whose
rpm-build 4f3c61
 * values are <emphasis>not</emphasis> comma-delimited lists, and
rpm-build 4f3c61
 * which therefore can only appear at most once in the headers. For
rpm-build 4f3c61
 * list-valued headers, use soup_message_headers_get_list().
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * If @hdrs does erroneously contain multiple copies of the header, it
rpm-build 4f3c61
 * is not defined which one will be returned. (Ideally, it will return
rpm-build 4f3c61
 * whichever one makes libsoup most compatible with other HTTP
rpm-build 4f3c61
 * implementations.)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: (nullable): the header's value or %NULL if not found.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.28
rpm-build 4f3c61
 **/
rpm-build 4f3c61
const char *
rpm-build 4f3c61
soup_message_headers_get_one (SoupMessageHeaders *hdrs, const char *name)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupHeader *hdr_array = (SoupHeader *)(hdrs->array->data);
rpm-build 4f3c61
	guint hdr_length = hdrs->array->len;
rpm-build 4f3c61
	int index;
rpm-build 4f3c61
rpm-build 4f3c61
	g_return_val_if_fail (name != NULL, NULL);
rpm-build 4f3c61
rpm-build 4f3c61
	name = intern_header_name (name, NULL);
rpm-build 4f3c61
rpm-build 4f3c61
	index = find_last_header (hdr_array, hdr_length, name, 0);
rpm-build 4f3c61
rpm-build 4f3c61
	return (index == -1) ? NULL : hdr_array[index].value;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_header_contains:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @name: header name
rpm-build 4f3c61
 * @token: token to look for
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Checks whether the list-valued header @name is present in @hdrs,
rpm-build 4f3c61
 * and contains a case-insensitive match for @token.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * (If @name is present in @hdrs, then this is equivalent to calling
rpm-build 4f3c61
 * soup_header_contains() on its value.)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: %TRUE if the header is present and contains @token,
rpm-build 4f3c61
 *   %FALSE otherwise.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.50
rpm-build 4f3c61
 **/
rpm-build 4f3c61
gboolean
rpm-build 4f3c61
soup_message_headers_header_contains (SoupMessageHeaders *hdrs, const char *name, const char *token)
rpm-build 4f3c61
{
rpm-build 4f3c61
	const char *value;
rpm-build 4f3c61
rpm-build 4f3c61
	value = soup_message_headers_get_list (hdrs, name);
rpm-build 4f3c61
	if (!value)
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
	return soup_header_contains (value, token);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_header_equals:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @name: header name
rpm-build 4f3c61
 * @value: expected value
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Checks whether the header @name is present in @hdrs and is
rpm-build 4f3c61
 * (case-insensitively) equal to @value.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: %TRUE if the header is present and its value is
rpm-build 4f3c61
 *   @value, %FALSE otherwise.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.50
rpm-build 4f3c61
 **/
rpm-build 4f3c61
gboolean
rpm-build 4f3c61
soup_message_headers_header_equals (SoupMessageHeaders *hdrs, const char *name, const char *value)
rpm-build 4f3c61
{
rpm-build 4f3c61
        const char *internal_value;
rpm-build 4f3c61
rpm-build 4f3c61
        internal_value = soup_message_headers_get_list (hdrs, name);
rpm-build 4f3c61
	if (!internal_value)
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
        return !g_ascii_strcasecmp (internal_value, value);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_get_list:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @name: header name
rpm-build 4f3c61
 * 
rpm-build 4f3c61
 * Gets the value of header @name in @hdrs. Use this for headers whose
rpm-build 4f3c61
 * values are comma-delimited lists, and which are therefore allowed
rpm-build 4f3c61
 * to appear multiple times in the headers. For non-list-valued
rpm-build 4f3c61
 * headers, use soup_message_headers_get_one().
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * If @name appears multiple times in @hdrs,
rpm-build 4f3c61
 * soup_message_headers_get_list() will concatenate all of the values
rpm-build 4f3c61
 * together, separated by commas. This is sometimes awkward to parse
rpm-build 4f3c61
 * (eg, WWW-Authenticate, Set-Cookie), but you have to be able to deal
rpm-build 4f3c61
 * with it anyway, because the HTTP spec explicitly states that this
rpm-build 4f3c61
 * transformation is allowed, and so an upstream proxy could do the
rpm-build 4f3c61
 * same thing.
rpm-build 4f3c61
 * 
rpm-build 4f3c61
 * Return value: (nullable): the header's value or %NULL if not found.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.28
rpm-build 4f3c61
 **/
rpm-build 4f3c61
const char *
rpm-build 4f3c61
soup_message_headers_get_list (SoupMessageHeaders *hdrs, const char *name)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupHeader *hdr_array = (SoupHeader *)(hdrs->array->data);
rpm-build 4f3c61
	GString *concat;
rpm-build 4f3c61
	char *value;
rpm-build 4f3c61
	int index, i;
rpm-build 4f3c61
rpm-build 4f3c61
	g_return_val_if_fail (name != NULL, NULL);
rpm-build 4f3c61
rpm-build 4f3c61
	name = intern_header_name (name, NULL);
rpm-build 4f3c61
	if (hdrs->concat) {
rpm-build 4f3c61
		value = g_hash_table_lookup (hdrs->concat, name);
rpm-build 4f3c61
		if (value)
rpm-build 4f3c61
			return value;
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	index = find_header (hdr_array, name, 0);
rpm-build 4f3c61
	if (index == -1)
rpm-build 4f3c61
		return NULL;
rpm-build 4f3c61
	else if (find_header (hdr_array, name, 1) == -1)
rpm-build 4f3c61
		return hdr_array[index].value;
rpm-build 4f3c61
rpm-build 4f3c61
	concat = g_string_new (NULL);
rpm-build 4f3c61
	for (i = 0; (index = find_header (hdr_array, name, i)) != -1; i++) {
rpm-build 4f3c61
		if (i != 0)
rpm-build 4f3c61
			g_string_append (concat, ", ");
rpm-build 4f3c61
		g_string_append (concat, hdr_array[index].value);
rpm-build 4f3c61
	}
rpm-build 4f3c61
	value = g_string_free (concat, FALSE);
rpm-build 4f3c61
rpm-build 4f3c61
	if (!hdrs->concat)
rpm-build 4f3c61
		hdrs->concat = g_hash_table_new_full (NULL, NULL, NULL, g_free);
rpm-build 4f3c61
	g_hash_table_insert (hdrs->concat, (gpointer)name, value);
rpm-build 4f3c61
	return value;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_get:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @name: header name
rpm-build 4f3c61
 * 
rpm-build 4f3c61
 * Gets the value of header @name in @hdrs.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * This method was supposed to work correctly for both single-valued
rpm-build 4f3c61
 * and list-valued headers, but because some HTTP clients/servers
rpm-build 4f3c61
 * mistakenly send multiple copies of headers that are supposed to be
rpm-build 4f3c61
 * single-valued, it sometimes returns incorrect results. To fix this,
rpm-build 4f3c61
 * the methods soup_message_headers_get_one() and
rpm-build 4f3c61
 * soup_message_headers_get_list() were introduced, so callers can
rpm-build 4f3c61
 * explicitly state which behavior they are expecting.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: (nullable): as with soup_message_headers_get_list().
rpm-build 4f3c61
 * 
rpm-build 4f3c61
 * Deprecated: Use soup_message_headers_get_one() or
rpm-build 4f3c61
 * soup_message_headers_get_list() instead.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
const char *
rpm-build 4f3c61
soup_message_headers_get (SoupMessageHeaders *hdrs, const char *name)
rpm-build 4f3c61
{
rpm-build 4f3c61
	return soup_message_headers_get_list (hdrs, name);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * SoupMessageHeadersIter:
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * An opaque type used to iterate over a %SoupMessageHeaders
rpm-build 4f3c61
 * structure.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * After intializing the iterator with
rpm-build 4f3c61
 * soup_message_headers_iter_init(), call
rpm-build 4f3c61
 * soup_message_headers_iter_next() to fetch data from it.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * You may not modify the headers while iterating over them.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
rpm-build 4f3c61
typedef struct {
rpm-build 4f3c61
	SoupMessageHeaders *hdrs;
rpm-build 4f3c61
	int index;
rpm-build 4f3c61
} SoupMessageHeadersIterReal;
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_iter_init:
rpm-build 4f3c61
 * @iter: (out) (transfer none): a pointer to a %SoupMessageHeadersIter
rpm-build 4f3c61
 * structure
rpm-build 4f3c61
 * @hdrs: a %SoupMessageHeaders
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Initializes @iter for iterating @hdrs.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_iter_init (SoupMessageHeadersIter *iter,
rpm-build 4f3c61
				SoupMessageHeaders *hdrs)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupMessageHeadersIterReal *real = (SoupMessageHeadersIterReal *)iter;
rpm-build 4f3c61
rpm-build 4f3c61
	real->hdrs = hdrs;
rpm-build 4f3c61
	real->index = 0;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_iter_next:
rpm-build 4f3c61
 * @iter: (inout) (transfer none): a %SoupMessageHeadersIter
rpm-build 4f3c61
 * @name: (out) (transfer none): pointer to a variable to return
rpm-build 4f3c61
 * the header name in
rpm-build 4f3c61
 * @value: (out) (transfer none): pointer to a variable to return
rpm-build 4f3c61
 * the header value in
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Yields the next name/value pair in the %SoupMessageHeaders being
rpm-build 4f3c61
 * iterated by @iter. If @iter has already yielded the last header,
rpm-build 4f3c61
 * then soup_message_headers_iter_next() will return %FALSE and @name
rpm-build 4f3c61
 * and @value will be unchanged.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: %TRUE if another name and value were returned, %FALSE
rpm-build 4f3c61
 * if the end of the headers has been reached.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
gboolean
rpm-build 4f3c61
soup_message_headers_iter_next (SoupMessageHeadersIter *iter,
rpm-build 4f3c61
				const char **name, const char **value)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupMessageHeadersIterReal *real = (SoupMessageHeadersIterReal *)iter;
rpm-build 4f3c61
	SoupHeader *hdr_array = (SoupHeader *)real->hdrs->array->data;
rpm-build 4f3c61
rpm-build 4f3c61
	if (real->index >= real->hdrs->array->len)
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
rpm-build 4f3c61
	*name = hdr_array[real->index].name;
rpm-build 4f3c61
	*value = hdr_array[real->index].value;
rpm-build 4f3c61
	real->index++;
rpm-build 4f3c61
	return TRUE;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * SoupMessageHeadersForeachFunc:
rpm-build 4f3c61
 * @name: the header name
rpm-build 4f3c61
 * @value: the header value
rpm-build 4f3c61
 * @user_data: the data passed to soup_message_headers_foreach()
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * The callback passed to soup_message_headers_foreach().
rpm-build 4f3c61
 **/
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_foreach:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @func: (scope call): callback function to run for each header
rpm-build 4f3c61
 * @user_data: data to pass to @func
rpm-build 4f3c61
 * 
rpm-build 4f3c61
 * Calls @func once for each header value in @hdrs.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Beware that unlike soup_message_headers_get(), this processes the
rpm-build 4f3c61
 * headers in exactly the way they were added, rather than
rpm-build 4f3c61
 * concatenating multiple same-named headers into a single value.
rpm-build 4f3c61
 * (This is intentional; it ensures that if you call
rpm-build 4f3c61
 * soup_message_headers_append() multiple times with the same name,
rpm-build 4f3c61
 * then the I/O code will output multiple copies of the header when
rpm-build 4f3c61
 * sending the message to the remote implementation, which may be
rpm-build 4f3c61
 * required for interoperability in some cases.)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * You may not modify the headers from @func.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_foreach (SoupMessageHeaders *hdrs,
rpm-build 4f3c61
			      SoupMessageHeadersForeachFunc func,
rpm-build 4f3c61
			      gpointer            user_data)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupHeader *hdr_array = (SoupHeader *)hdrs->array->data;
rpm-build 4f3c61
	guint i;
rpm-build 4f3c61
rpm-build 4f3c61
	for (i = 0; i < hdrs->array->len; i++)
rpm-build 4f3c61
		func (hdr_array[i].name, hdr_array[i].value, user_data);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
rpm-build 4f3c61
G_LOCK_DEFINE_STATIC (header_pool);
rpm-build 4f3c61
static GHashTable *header_pool, *header_setters;
rpm-build 4f3c61
rpm-build 4f3c61
static void transfer_encoding_setter (SoupMessageHeaders *, const char *);
rpm-build 4f3c61
static void content_length_setter (SoupMessageHeaders *, const char *);
rpm-build 4f3c61
static void expectation_setter (SoupMessageHeaders *, const char *);
rpm-build 4f3c61
static void content_type_setter (SoupMessageHeaders *, const char *);
rpm-build 4f3c61
rpm-build 4f3c61
static char *
rpm-build 4f3c61
intern_header_locked (const char *name)
rpm-build 4f3c61
{
rpm-build 4f3c61
	char *interned;
rpm-build 4f3c61
rpm-build 4f3c61
	interned = g_hash_table_lookup (header_pool, name);
rpm-build 4f3c61
	if (!interned) {
rpm-build 4f3c61
		char *dup = g_strdup (name);
rpm-build 4f3c61
		g_hash_table_insert (header_pool, dup, dup);
rpm-build 4f3c61
		interned = dup;
rpm-build 4f3c61
	}
rpm-build 4f3c61
	return interned;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static const char *
rpm-build 4f3c61
intern_header_name (const char *name, SoupHeaderSetter *setter)
rpm-build 4f3c61
{
rpm-build 4f3c61
	const char *interned;
rpm-build 4f3c61
rpm-build 4f3c61
	G_LOCK (header_pool);
rpm-build 4f3c61
rpm-build 4f3c61
	if (!header_pool) {
rpm-build 4f3c61
		header_pool = g_hash_table_new (soup_str_case_hash, soup_str_case_equal);
rpm-build 4f3c61
		header_setters = g_hash_table_new (NULL, NULL);
rpm-build 4f3c61
		g_hash_table_insert (header_setters,
rpm-build 4f3c61
				     intern_header_locked ("Transfer-Encoding"),
rpm-build 4f3c61
				     transfer_encoding_setter);
rpm-build 4f3c61
		g_hash_table_insert (header_setters,
rpm-build 4f3c61
				     intern_header_locked ("Content-Length"),
rpm-build 4f3c61
				     content_length_setter);
rpm-build 4f3c61
		g_hash_table_insert (header_setters,
rpm-build 4f3c61
				     intern_header_locked ("Expect"),
rpm-build 4f3c61
				     expectation_setter);
rpm-build 4f3c61
		g_hash_table_insert (header_setters,
rpm-build 4f3c61
				     intern_header_locked ("Content-Type"),
rpm-build 4f3c61
				     content_type_setter);
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	interned = intern_header_locked (name);
rpm-build 4f3c61
	if (setter)
rpm-build 4f3c61
		*setter = g_hash_table_lookup (header_setters, interned);
rpm-build 4f3c61
rpm-build 4f3c61
	G_UNLOCK (header_pool);
rpm-build 4f3c61
	return interned;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
clear_special_headers (SoupMessageHeaders *hdrs)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupHeaderSetter setter;
rpm-build 4f3c61
	GHashTableIter iter;
rpm-build 4f3c61
	gpointer key, value;
rpm-build 4f3c61
rpm-build 4f3c61
	/* Make sure header_setters has been initialized */
rpm-build 4f3c61
	intern_header_name ("", NULL);
rpm-build 4f3c61
rpm-build 4f3c61
	g_hash_table_iter_init (&iter, header_setters);
rpm-build 4f3c61
	while (g_hash_table_iter_next (&iter, &key, &value)) {
rpm-build 4f3c61
		setter = value;
rpm-build 4f3c61
		setter (hdrs, NULL);
rpm-build 4f3c61
	}
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/* Specific headers */
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
transfer_encoding_setter (SoupMessageHeaders *hdrs, const char *value)
rpm-build 4f3c61
{
rpm-build 4f3c61
	if (value) {
rpm-build 4f3c61
		if (g_ascii_strcasecmp (value, "chunked") == 0)
rpm-build 4f3c61
			hdrs->encoding = SOUP_ENCODING_CHUNKED;
rpm-build 4f3c61
		else
rpm-build 4f3c61
			hdrs->encoding = SOUP_ENCODING_UNRECOGNIZED;
rpm-build 4f3c61
	} else
rpm-build 4f3c61
		hdrs->encoding = -1;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
content_length_setter (SoupMessageHeaders *hdrs, const char *value)
rpm-build 4f3c61
{
rpm-build 4f3c61
	/* Transfer-Encoding trumps Content-Length */
rpm-build 4f3c61
	if (hdrs->encoding == SOUP_ENCODING_CHUNKED)
rpm-build 4f3c61
		return;
rpm-build 4f3c61
rpm-build 4f3c61
	if (value) {
rpm-build 4f3c61
		char *end;
rpm-build 4f3c61
rpm-build 4f3c61
		hdrs->content_length = g_ascii_strtoull (value, &end, 10);
rpm-build 4f3c61
		if (*end)
rpm-build 4f3c61
			hdrs->encoding = SOUP_ENCODING_UNRECOGNIZED;
rpm-build 4f3c61
		else
rpm-build 4f3c61
			hdrs->encoding = SOUP_ENCODING_CONTENT_LENGTH;
rpm-build 4f3c61
	} else
rpm-build 4f3c61
		hdrs->encoding = -1;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * SoupEncoding:
rpm-build 4f3c61
 * @SOUP_ENCODING_UNRECOGNIZED: unknown / error
rpm-build 4f3c61
 * @SOUP_ENCODING_NONE: no body is present (which is not the same as a
rpm-build 4f3c61
 * 0-length body, and only occurs in certain places)
rpm-build 4f3c61
 * @SOUP_ENCODING_CONTENT_LENGTH: Content-Length encoding
rpm-build 4f3c61
 * @SOUP_ENCODING_EOF: Response body ends when the connection is closed
rpm-build 4f3c61
 * @SOUP_ENCODING_CHUNKED: chunked encoding (currently only supported
rpm-build 4f3c61
 * for response)
rpm-build 4f3c61
 * @SOUP_ENCODING_BYTERANGES: multipart/byteranges (Reserved for future
rpm-build 4f3c61
 * use: NOT CURRENTLY IMPLEMENTED)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * How a message body is encoded for transport
rpm-build 4f3c61
 **/
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_get_encoding:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Gets the message body encoding that @hdrs declare. This may not
rpm-build 4f3c61
 * always correspond to the encoding used on the wire; eg, a HEAD
rpm-build 4f3c61
 * response may declare a Content-Length or Transfer-Encoding, but
rpm-build 4f3c61
 * it will never actually include a body.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: the encoding declared by @hdrs.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
SoupEncoding
rpm-build 4f3c61
soup_message_headers_get_encoding (SoupMessageHeaders *hdrs)
rpm-build 4f3c61
{
rpm-build 4f3c61
	const char *header;
rpm-build 4f3c61
rpm-build 4f3c61
	if (hdrs->encoding != -1)
rpm-build 4f3c61
		return hdrs->encoding;
rpm-build 4f3c61
rpm-build 4f3c61
	/* If Transfer-Encoding was set, hdrs->encoding would already
rpm-build 4f3c61
	 * be set. So we don't need to check that possibility.
rpm-build 4f3c61
	 */
rpm-build 4f3c61
	header = soup_message_headers_get_one (hdrs, "Content-Length");
rpm-build 4f3c61
	if (header) {
rpm-build 4f3c61
		content_length_setter (hdrs, header);
rpm-build 4f3c61
		if (hdrs->encoding != -1)
rpm-build 4f3c61
			return hdrs->encoding;
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	/* Per RFC 2616 4.4, a response body that doesn't indicate its
rpm-build 4f3c61
	 * encoding otherwise is terminated by connection close, and a
rpm-build 4f3c61
	 * request that doesn't indicate otherwise has no body. Note
rpm-build 4f3c61
	 * that SoupMessage calls soup_message_headers_set_encoding()
rpm-build 4f3c61
	 * to override the response body default for our own
rpm-build 4f3c61
	 * server-side messages.
rpm-build 4f3c61
	 */
rpm-build 4f3c61
	hdrs->encoding = (hdrs->type == SOUP_MESSAGE_HEADERS_RESPONSE) ?
rpm-build 4f3c61
		SOUP_ENCODING_EOF : SOUP_ENCODING_NONE;
rpm-build 4f3c61
	return hdrs->encoding;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_set_encoding:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @encoding: a #SoupEncoding
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Sets the message body encoding that @hdrs will declare. In particular,
rpm-build 4f3c61
 * you should use this if you are going to send a request or response in
rpm-build 4f3c61
 * chunked encoding.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_set_encoding (SoupMessageHeaders *hdrs,
rpm-build 4f3c61
				   SoupEncoding        encoding)
rpm-build 4f3c61
{
rpm-build 4f3c61
	if (encoding == hdrs->encoding)
rpm-build 4f3c61
		return;
rpm-build 4f3c61
rpm-build 4f3c61
	switch (encoding) {
rpm-build 4f3c61
	case SOUP_ENCODING_NONE:
rpm-build 4f3c61
	case SOUP_ENCODING_EOF:
rpm-build 4f3c61
		soup_message_headers_remove (hdrs, "Transfer-Encoding");
rpm-build 4f3c61
		soup_message_headers_remove (hdrs, "Content-Length");
rpm-build 4f3c61
		break;
rpm-build 4f3c61
rpm-build 4f3c61
	case SOUP_ENCODING_CONTENT_LENGTH:
rpm-build 4f3c61
		soup_message_headers_remove (hdrs, "Transfer-Encoding");
rpm-build 4f3c61
		break;
rpm-build 4f3c61
rpm-build 4f3c61
	case SOUP_ENCODING_CHUNKED:
rpm-build 4f3c61
		soup_message_headers_remove (hdrs, "Content-Length");
rpm-build 4f3c61
		soup_message_headers_replace (hdrs, "Transfer-Encoding", "chunked");
rpm-build 4f3c61
		break;
rpm-build 4f3c61
rpm-build 4f3c61
	default:
rpm-build 4f3c61
		g_return_if_reached ();
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	hdrs->encoding = encoding;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_get_content_length:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Gets the message body length that @hdrs declare. This will only
rpm-build 4f3c61
 * be non-0 if soup_message_headers_get_encoding() returns
rpm-build 4f3c61
 * %SOUP_ENCODING_CONTENT_LENGTH.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: the message body length declared by @hdrs.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
goffset
rpm-build 4f3c61
soup_message_headers_get_content_length (SoupMessageHeaders *hdrs)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupEncoding encoding;
rpm-build 4f3c61
rpm-build 4f3c61
	encoding = soup_message_headers_get_encoding (hdrs);
rpm-build 4f3c61
	if (encoding == SOUP_ENCODING_CONTENT_LENGTH)
rpm-build 4f3c61
		return hdrs->content_length;
rpm-build 4f3c61
	else
rpm-build 4f3c61
		return 0;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_set_content_length:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @content_length: the message body length
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Sets the message body length that @hdrs will declare, and sets
rpm-build 4f3c61
 * @hdrs's encoding to %SOUP_ENCODING_CONTENT_LENGTH.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * You do not normally need to call this; if @hdrs is set to use
rpm-build 4f3c61
 * Content-Length encoding, libsoup will automatically set its
rpm-build 4f3c61
 * Content-Length header for you immediately before sending the
rpm-build 4f3c61
 * headers. One situation in which this method is useful is when
rpm-build 4f3c61
 * generating the response to a HEAD request; Calling
rpm-build 4f3c61
 * soup_message_headers_set_content_length() allows you to put the
rpm-build 4f3c61
 * correct content length into the response without needing to waste
rpm-build 4f3c61
 * memory by filling in a response body which won't actually be sent.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_set_content_length (SoupMessageHeaders *hdrs,
rpm-build 4f3c61
					 goffset             content_length)
rpm-build 4f3c61
{
rpm-build 4f3c61
	char length[128];
rpm-build 4f3c61
rpm-build 4f3c61
	g_snprintf (length, sizeof (length), "%" G_GUINT64_FORMAT,
rpm-build 4f3c61
		    content_length);
rpm-build 4f3c61
	soup_message_headers_remove (hdrs, "Transfer-Encoding");
rpm-build 4f3c61
	soup_message_headers_replace (hdrs, "Content-Length", length);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
expectation_setter (SoupMessageHeaders *hdrs, const char *value)
rpm-build 4f3c61
{
rpm-build 4f3c61
	if (value) {
rpm-build 4f3c61
		if (!g_ascii_strcasecmp (value, "100-continue"))
rpm-build 4f3c61
			hdrs->expectations = SOUP_EXPECTATION_CONTINUE;
rpm-build 4f3c61
		else
rpm-build 4f3c61
			hdrs->expectations = SOUP_EXPECTATION_UNRECOGNIZED;
rpm-build 4f3c61
	} else
rpm-build 4f3c61
		hdrs->expectations = 0;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * SoupExpectation:
rpm-build 4f3c61
 * @SOUP_EXPECTATION_CONTINUE: "100-continue"
rpm-build 4f3c61
 * @SOUP_EXPECTATION_UNRECOGNIZED: any unrecognized expectation
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Represents the parsed value of the "Expect" header.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_get_expectations:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Gets the expectations declared by @hdrs's "Expect" header.
rpm-build 4f3c61
 * Currently this will either be %SOUP_EXPECTATION_CONTINUE or
rpm-build 4f3c61
 * %SOUP_EXPECTATION_UNRECOGNIZED.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: the contents of @hdrs's "Expect" header
rpm-build 4f3c61
 **/
rpm-build 4f3c61
SoupExpectation
rpm-build 4f3c61
soup_message_headers_get_expectations (SoupMessageHeaders *hdrs)
rpm-build 4f3c61
{
rpm-build 4f3c61
	return hdrs->expectations;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_set_expectations:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @expectations: the expectations to set
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Sets @hdrs's "Expect" header according to @expectations.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Currently %SOUP_EXPECTATION_CONTINUE is the only known expectation
rpm-build 4f3c61
 * value. You should set this value on a request if you are sending a
rpm-build 4f3c61
 * large message body (eg, via POST or PUT), and want to give the
rpm-build 4f3c61
 * server a chance to reject the request after seeing just the headers
rpm-build 4f3c61
 * (eg, because it will require authentication before allowing you to
rpm-build 4f3c61
 * post, or because you're POSTing to a URL that doesn't exist). This
rpm-build 4f3c61
 * saves you from having to transmit the large request body when the
rpm-build 4f3c61
 * server is just going to ignore it anyway.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_set_expectations (SoupMessageHeaders *hdrs,
rpm-build 4f3c61
				       SoupExpectation     expectations)
rpm-build 4f3c61
{
rpm-build 4f3c61
	g_return_if_fail ((expectations & ~SOUP_EXPECTATION_CONTINUE) == 0);
rpm-build 4f3c61
rpm-build 4f3c61
	if (expectations & SOUP_EXPECTATION_CONTINUE)
rpm-build 4f3c61
		soup_message_headers_replace (hdrs, "Expect", "100-continue");
rpm-build 4f3c61
	else
rpm-build 4f3c61
		soup_message_headers_remove (hdrs, "Expect");
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * SoupRange:
rpm-build 4f3c61
 * @start: the start of the range
rpm-build 4f3c61
 * @end: the end of the range
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Represents a byte range as used in the Range header.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * If @end is non-negative, then @start and @end represent the bounds
rpm-build 4f3c61
 * of of the range, counting from 0. (Eg, the first 500 bytes would be
rpm-build 4f3c61
 * represented as @start = 0 and @end = 499.)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * If @end is -1 and @start is non-negative, then this represents a
rpm-build 4f3c61
 * range starting at @start and ending with the last byte of the
rpm-build 4f3c61
 * requested resource body. (Eg, all but the first 500 bytes would be
rpm-build 4f3c61
 * @start = 500, and @end = -1.)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * If @end is -1 and @start is negative, then it represents a "suffix
rpm-build 4f3c61
 * range", referring to the last -@start bytes of the resource body.
rpm-build 4f3c61
 * (Eg, the last 500 bytes would be @start = -500 and @end = -1.)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.26
rpm-build 4f3c61
 **/
rpm-build 4f3c61
rpm-build 4f3c61
static int
rpm-build 4f3c61
sort_ranges (gconstpointer a, gconstpointer b)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupRange *ra = (SoupRange *)a;
rpm-build 4f3c61
	SoupRange *rb = (SoupRange *)b;
rpm-build 4f3c61
rpm-build 4f3c61
	return ra->start - rb->start;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/* like soup_message_headers_get_ranges(), except it returns:
rpm-build 4f3c61
 *   SOUP_STATUS_OK if there is no Range or it should be ignored.
rpm-build 4f3c61
 *   SOUP_STATUS_PARTIAL_CONTENT if there is at least one satisfiable range.
rpm-build 4f3c61
 *   SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE if @check_satisfiable
rpm-build 4f3c61
 *     is %TRUE and the request is not satisfiable given @total_length.
rpm-build 4f3c61
 */
rpm-build 4f3c61
guint
rpm-build 4f3c61
soup_message_headers_get_ranges_internal (SoupMessageHeaders  *hdrs,
rpm-build 4f3c61
					  goffset              total_length,
rpm-build 4f3c61
					  gboolean             check_satisfiable,
rpm-build 4f3c61
					  SoupRange          **ranges,
rpm-build 4f3c61
					  int                 *length)
rpm-build 4f3c61
{
rpm-build 4f3c61
	const char *range = soup_message_headers_get_one (hdrs, "Range");
rpm-build 4f3c61
	GSList *range_list, *r;
rpm-build 4f3c61
	GArray *array;
rpm-build 4f3c61
	char *spec, *end;
rpm-build 4f3c61
	guint status = SOUP_STATUS_OK;
rpm-build 4f3c61
rpm-build 4f3c61
	if (!range || strncmp (range, "bytes", 5) != 0)
rpm-build 4f3c61
		return status;
rpm-build 4f3c61
rpm-build 4f3c61
	range += 5;
rpm-build 4f3c61
	while (g_ascii_isspace (*range))
rpm-build 4f3c61
		range++;
rpm-build 4f3c61
	if (*range++ != '=')
rpm-build 4f3c61
		return status;
rpm-build 4f3c61
	while (g_ascii_isspace (*range))
rpm-build 4f3c61
		range++;
rpm-build 4f3c61
rpm-build 4f3c61
	range_list = soup_header_parse_list (range);
rpm-build 4f3c61
	if (!range_list)
rpm-build 4f3c61
		return status;
rpm-build 4f3c61
rpm-build 4f3c61
	array = g_array_new (FALSE, FALSE, sizeof (SoupRange));
rpm-build 4f3c61
	for (r = range_list; r; r = r->next) {
rpm-build 4f3c61
		SoupRange cur;
rpm-build 4f3c61
rpm-build 4f3c61
		spec = r->data;
rpm-build 4f3c61
		if (*spec == '-') {
rpm-build 4f3c61
			cur.start = g_ascii_strtoll (spec, &end, 10) + total_length;
rpm-build 4f3c61
			cur.end = total_length - 1;
rpm-build 4f3c61
		} else {
rpm-build 4f3c61
			cur.start = g_ascii_strtoull (spec, &end, 10);
rpm-build 4f3c61
			if (*end == '-')
rpm-build 4f3c61
				end++;
rpm-build 4f3c61
			if (*end) {
rpm-build 4f3c61
				cur.end = g_ascii_strtoull (end, &end, 10);
rpm-build 4f3c61
				if (cur.end < cur.start) {
rpm-build 4f3c61
					status = SOUP_STATUS_OK;
rpm-build 4f3c61
					break;
rpm-build 4f3c61
				}
rpm-build 4f3c61
			} else
rpm-build 4f3c61
				cur.end = total_length - 1;
rpm-build 4f3c61
		}
rpm-build 4f3c61
		if (*end) {
rpm-build 4f3c61
			status = SOUP_STATUS_OK;
rpm-build 4f3c61
			break;
rpm-build 4f3c61
		} else if (check_satisfiable && cur.start >= total_length) {
rpm-build 4f3c61
			if (status == SOUP_STATUS_OK)
rpm-build 4f3c61
				status = SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE;
rpm-build 4f3c61
			continue;
rpm-build 4f3c61
		}
rpm-build 4f3c61
rpm-build 4f3c61
		g_array_append_val (array, cur);
rpm-build 4f3c61
		status = SOUP_STATUS_PARTIAL_CONTENT;
rpm-build 4f3c61
	}
rpm-build 4f3c61
	soup_header_free_list (range_list);
rpm-build 4f3c61
rpm-build 4f3c61
	if (status != SOUP_STATUS_PARTIAL_CONTENT) {
rpm-build 4f3c61
		g_array_free (array, TRUE);
rpm-build 4f3c61
		return status;
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	if (total_length) {
rpm-build 4f3c61
		guint i;
rpm-build 4f3c61
rpm-build 4f3c61
		g_array_sort (array, sort_ranges);
rpm-build 4f3c61
		for (i = 1; i < array->len; i++) {
rpm-build 4f3c61
			SoupRange *cur = &((SoupRange *)array->data)[i];
rpm-build 4f3c61
			SoupRange *prev = &((SoupRange *)array->data)[i - 1];
rpm-build 4f3c61
rpm-build 4f3c61
			if (cur->start <= prev->end) {
rpm-build 4f3c61
				prev->end = MAX (prev->end, cur->end);
rpm-build 4f3c61
				g_array_remove_index (array, i);
rpm-build 4f3c61
			}
rpm-build 4f3c61
		}
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	*ranges = (SoupRange *)array->data;
rpm-build 4f3c61
	*length = array->len;
rpm-build 4f3c61
rpm-build 4f3c61
	g_array_free (array, FALSE);
rpm-build 4f3c61
	return SOUP_STATUS_PARTIAL_CONTENT;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_get_ranges:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @total_length: the total_length of the response body
rpm-build 4f3c61
 * @ranges: (out) (array length=length): return location for an array
rpm-build 4f3c61
 * of #SoupRange
rpm-build 4f3c61
 * @length: the length of the returned array
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Parses @hdrs's Range header and returns an array of the requested
rpm-build 4f3c61
 * byte ranges. The returned array must be freed with
rpm-build 4f3c61
 * soup_message_headers_free_ranges().
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * If @total_length is non-0, its value will be used to adjust the
rpm-build 4f3c61
 * returned ranges to have explicit start and end values, and the
rpm-build 4f3c61
 * returned ranges will be sorted and non-overlapping. If
rpm-build 4f3c61
 * @total_length is 0, then some ranges may have an end value of -1,
rpm-build 4f3c61
 * as described under #SoupRange, and some of the ranges may be
rpm-build 4f3c61
 * redundant.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Beware that even if given a @total_length, this function does not
rpm-build 4f3c61
 * check that the ranges are satisfiable.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * <note><para>
rpm-build 4f3c61
 * #SoupServer has built-in handling for range requests. If your
rpm-build 4f3c61
 * server handler returns a %SOUP_STATUS_OK response containing the
rpm-build 4f3c61
 * complete response body (rather than pausing the message and
rpm-build 4f3c61
 * returning some of the response body later), and there is a Range
rpm-build 4f3c61
 * header in the request, then libsoup will automatically convert the
rpm-build 4f3c61
 * response to a %SOUP_STATUS_PARTIAL_CONTENT response containing only
rpm-build 4f3c61
 * the range(s) requested by the client.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * The only time you need to process the Range header yourself is if
rpm-build 4f3c61
 * either you need to stream the response body rather than returning
rpm-build 4f3c61
 * it all at once, or you do not already have the complete response
rpm-build 4f3c61
 * body available, and only want to generate the parts that were
rpm-build 4f3c61
 * actually requested by the client.
rpm-build 4f3c61
 * </para></note>
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: %TRUE if @hdrs contained a syntactically-valid
rpm-build 4f3c61
 * "Range" header, %FALSE otherwise (in which case @range and @length
rpm-build 4f3c61
 * will not be set).
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.26
rpm-build 4f3c61
 **/
rpm-build 4f3c61
gboolean
rpm-build 4f3c61
soup_message_headers_get_ranges (SoupMessageHeaders  *hdrs,
rpm-build 4f3c61
				 goffset              total_length,
rpm-build 4f3c61
				 SoupRange          **ranges,
rpm-build 4f3c61
				 int                 *length)
rpm-build 4f3c61
{
rpm-build 4f3c61
	guint status;
rpm-build 4f3c61
rpm-build 4f3c61
	status = soup_message_headers_get_ranges_internal (hdrs, total_length, FALSE, ranges, length);
rpm-build 4f3c61
	return status == SOUP_STATUS_PARTIAL_CONTENT;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_free_ranges:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @ranges: an array of #SoupRange
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Frees the array of ranges returned from soup_message_headers_get_ranges().
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.26
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_free_ranges (SoupMessageHeaders  *hdrs,
rpm-build 4f3c61
				  SoupRange           *ranges)
rpm-build 4f3c61
{
rpm-build 4f3c61
	g_free (ranges);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_set_ranges:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @ranges: an array of #SoupRange
rpm-build 4f3c61
 * @length: the length of @range
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Sets @hdrs's Range header to request the indicated ranges. (If you
rpm-build 4f3c61
 * only want to request a single range, you can use
rpm-build 4f3c61
 * soup_message_headers_set_range().)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.26
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_set_ranges (SoupMessageHeaders  *hdrs,
rpm-build 4f3c61
				 SoupRange           *ranges,
rpm-build 4f3c61
				 int                  length)
rpm-build 4f3c61
{
rpm-build 4f3c61
	GString *header;
rpm-build 4f3c61
	int i;
rpm-build 4f3c61
rpm-build 4f3c61
	header = g_string_new ("bytes=");
rpm-build 4f3c61
	for (i = 0; i < length; i++) {
rpm-build 4f3c61
		if (i > 0)
rpm-build 4f3c61
			g_string_append_c (header, ',');
rpm-build 4f3c61
		if (ranges[i].end >= 0) {
rpm-build 4f3c61
			g_string_append_printf (header, "%" G_GINT64_FORMAT "-%" G_GINT64_FORMAT,
rpm-build 4f3c61
						ranges[i].start, ranges[i].end);
rpm-build 4f3c61
		} else if (ranges[i].start >= 0) {
rpm-build 4f3c61
			g_string_append_printf (header,"%" G_GINT64_FORMAT "-",
rpm-build 4f3c61
						ranges[i].start);
rpm-build 4f3c61
		} else {
rpm-build 4f3c61
			g_string_append_printf (header, "%" G_GINT64_FORMAT,
rpm-build 4f3c61
						ranges[i].start);
rpm-build 4f3c61
		}
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	soup_message_headers_replace (hdrs, "Range", header->str);
rpm-build 4f3c61
	g_string_free (header, TRUE);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_set_range:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @start: the start of the range to request
rpm-build 4f3c61
 * @end: the end of the range to request
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Sets @hdrs's Range header to request the indicated range.
rpm-build 4f3c61
 * @start and @end are interpreted as in a #SoupRange.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * If you need to request multiple ranges, use
rpm-build 4f3c61
 * soup_message_headers_set_ranges().
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.26
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_set_range (SoupMessageHeaders  *hdrs,
rpm-build 4f3c61
				goffset              start,
rpm-build 4f3c61
				goffset              end)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupRange range;
rpm-build 4f3c61
rpm-build 4f3c61
	range.start = start;
rpm-build 4f3c61
	range.end = end;
rpm-build 4f3c61
	soup_message_headers_set_ranges (hdrs, &range, 1);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_get_content_range:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @start: (out): return value for the start of the range
rpm-build 4f3c61
 * @end: (out): return value for the end of the range
rpm-build 4f3c61
 * @total_length: (out) (optional): return value for the total length of the
rpm-build 4f3c61
 * resource, or %NULL if you don't care.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Parses @hdrs's Content-Range header and returns it in @start,
rpm-build 4f3c61
 * @end, and @total_length. If the total length field in the header
rpm-build 4f3c61
 * was specified as "*", then @total_length will be set to -1.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: %TRUE if @hdrs contained a "Content-Range" header
rpm-build 4f3c61
 * containing a byte range which could be parsed, %FALSE otherwise.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.26
rpm-build 4f3c61
 **/
rpm-build 4f3c61
gboolean
rpm-build 4f3c61
soup_message_headers_get_content_range (SoupMessageHeaders  *hdrs,
rpm-build 4f3c61
					goffset             *start,
rpm-build 4f3c61
					goffset             *end,
rpm-build 4f3c61
					goffset             *total_length)
rpm-build 4f3c61
{
rpm-build 4f3c61
	const char *header = soup_message_headers_get_one (hdrs, "Content-Range");
rpm-build 4f3c61
	goffset length;
rpm-build 4f3c61
	char *p;
rpm-build 4f3c61
rpm-build 4f3c61
	if (!header || strncmp (header, "bytes ", 6) != 0)
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
rpm-build 4f3c61
	header += 6;
rpm-build 4f3c61
	while (g_ascii_isspace (*header))
rpm-build 4f3c61
		header++;
rpm-build 4f3c61
	if (!g_ascii_isdigit (*header))
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
rpm-build 4f3c61
	*start = g_ascii_strtoull (header, &p, 10);
rpm-build 4f3c61
	if (*p != '-')
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
	*end = g_ascii_strtoull (p + 1, &p, 10);
rpm-build 4f3c61
	if (*p != '/')
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
	p++;
rpm-build 4f3c61
	if (*p == '*') {
rpm-build 4f3c61
		length = -1;
rpm-build 4f3c61
		p++;
rpm-build 4f3c61
	} else
rpm-build 4f3c61
		length = g_ascii_strtoull (p, &p, 10);
rpm-build 4f3c61
rpm-build 4f3c61
	if (total_length)
rpm-build 4f3c61
		*total_length = length;
rpm-build 4f3c61
	return *p == '\0';
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_set_content_range:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @start: the start of the range
rpm-build 4f3c61
 * @end: the end of the range
rpm-build 4f3c61
 * @total_length: the total length of the resource, or -1 if unknown
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Sets @hdrs's Content-Range header according to the given values.
rpm-build 4f3c61
 * (Note that @total_length is the total length of the entire resource
rpm-build 4f3c61
 * that this is a range of, not simply @end - @start + 1.)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * <note><para>
rpm-build 4f3c61
 * #SoupServer has built-in handling for range requests, and you do
rpm-build 4f3c61
 * not normally need to call this function youself. See
rpm-build 4f3c61
 * soup_message_headers_get_ranges() for more details.
rpm-build 4f3c61
 * </para></note>
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.26
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_set_content_range (SoupMessageHeaders  *hdrs,
rpm-build 4f3c61
					goffset              start,
rpm-build 4f3c61
					goffset              end,
rpm-build 4f3c61
					goffset              total_length)
rpm-build 4f3c61
{
rpm-build 4f3c61
	char *header;
rpm-build 4f3c61
rpm-build 4f3c61
	if (total_length >= 0) {
rpm-build 4f3c61
		header = g_strdup_printf ("bytes %" G_GINT64_FORMAT "-%"
rpm-build 4f3c61
					  G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
rpm-build 4f3c61
					  start, end, total_length);
rpm-build 4f3c61
	} else {
rpm-build 4f3c61
		header = g_strdup_printf ("bytes %" G_GINT64_FORMAT "-%"
rpm-build 4f3c61
					  G_GINT64_FORMAT "/*", start, end);
rpm-build 4f3c61
	}
rpm-build 4f3c61
	soup_message_headers_replace (hdrs, "Content-Range", header);
rpm-build 4f3c61
	g_free (header);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static gboolean
rpm-build 4f3c61
parse_content_foo (SoupMessageHeaders *hdrs, const char *header_name,
rpm-build 4f3c61
		   char **foo, GHashTable **params)
rpm-build 4f3c61
{
rpm-build 4f3c61
	const char *header;
rpm-build 4f3c61
	char *semi;
rpm-build 4f3c61
rpm-build 4f3c61
	header = soup_message_headers_get_one (hdrs, header_name);
rpm-build 4f3c61
	if (!header)
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
rpm-build 4f3c61
	if (foo) {
rpm-build 4f3c61
		*foo = g_strdup (header);
rpm-build 4f3c61
		semi = strchr (*foo, ';');
rpm-build 4f3c61
		if (semi) {
rpm-build 4f3c61
			char *p = semi;
rpm-build 4f3c61
rpm-build 4f3c61
			*semi++ = '\0';
rpm-build 4f3c61
			while (p - 1 > *foo && g_ascii_isspace(p[-1]))
rpm-build 4f3c61
				*(--p) = '\0';
rpm-build 4f3c61
		}
rpm-build 4f3c61
	} else {
rpm-build 4f3c61
		semi = strchr (header, ';');
rpm-build 4f3c61
		if (semi)
rpm-build 4f3c61
			semi++;
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	if (!params)
rpm-build 4f3c61
		return TRUE;
rpm-build 4f3c61
rpm-build 4f3c61
	if (!semi) {
rpm-build 4f3c61
		*params = soup_header_parse_semi_param_list ("");
rpm-build 4f3c61
		return TRUE;
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	*params = soup_header_parse_semi_param_list (semi);
rpm-build 4f3c61
	return TRUE;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
set_content_foo (SoupMessageHeaders *hdrs, const char *header_name,
rpm-build 4f3c61
		 const char *foo, GHashTable *params)
rpm-build 4f3c61
{
rpm-build 4f3c61
	GString *str;
rpm-build 4f3c61
	GHashTableIter iter;
rpm-build 4f3c61
	gpointer key, value;
rpm-build 4f3c61
rpm-build 4f3c61
	str = g_string_new (foo);
rpm-build 4f3c61
	if (params) {
rpm-build 4f3c61
		g_hash_table_iter_init (&iter, params);
rpm-build 4f3c61
		while (g_hash_table_iter_next (&iter, &key, &value)) {
rpm-build 4f3c61
			g_string_append (str, "; ");
rpm-build 4f3c61
			soup_header_g_string_append_param (str, key, value);
rpm-build 4f3c61
		}
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	soup_message_headers_replace (hdrs, header_name, str->str);
rpm-build 4f3c61
	g_string_free (str, TRUE);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
content_type_setter (SoupMessageHeaders *hdrs, const char *value)
rpm-build 4f3c61
{
rpm-build 4f3c61
	g_free (hdrs->content_type);
rpm-build 4f3c61
	if (value) {
rpm-build 4f3c61
		char *content_type, *p;
rpm-build 4f3c61
rpm-build 4f3c61
		parse_content_foo (hdrs, "Content-Type", &content_type, NULL);
rpm-build 4f3c61
		p = strpbrk (content_type, " /");
rpm-build 4f3c61
		if (!p || *p != '/' || strpbrk (p + 1, " /")) {
rpm-build 4f3c61
			g_free (content_type);
rpm-build 4f3c61
			hdrs->content_type = NULL;
rpm-build 4f3c61
		} else
rpm-build 4f3c61
			hdrs->content_type = content_type;
rpm-build 4f3c61
	} else
rpm-build 4f3c61
		hdrs->content_type = NULL;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_get_content_type:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @params: (out) (element-type utf8 utf8) (allow-none) (transfer full):
rpm-build 4f3c61
 *   return location for the Content-Type parameters (eg, "charset"), or
rpm-build 4f3c61
 *   %NULL
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Looks up the "Content-Type" header in @hdrs, parses it, and returns
rpm-build 4f3c61
 * its value in *@content_type and *@params. @params can be %NULL if you
rpm-build 4f3c61
 * are only interested in the content type itself.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: (nullable): a string with the value of the
rpm-build 4f3c61
 * "Content-Type" header or %NULL if @hdrs does not contain that
rpm-build 4f3c61
 * header or it cannot be parsed (in which case *@params will be
rpm-build 4f3c61
 * unchanged).
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.26
rpm-build 4f3c61
 **/
rpm-build 4f3c61
const char *
rpm-build 4f3c61
soup_message_headers_get_content_type (SoupMessageHeaders  *hdrs,
rpm-build 4f3c61
				       GHashTable         **params)
rpm-build 4f3c61
{
rpm-build 4f3c61
	if (!hdrs->content_type)
rpm-build 4f3c61
		return NULL;
rpm-build 4f3c61
rpm-build 4f3c61
	if (params)
rpm-build 4f3c61
		parse_content_foo (hdrs, "Content-Type", NULL, params);
rpm-build 4f3c61
	return hdrs->content_type;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_set_content_type:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @content_type: the MIME type
rpm-build 4f3c61
 * @params: (allow-none) (element-type utf8 utf8): additional
rpm-build 4f3c61
 * parameters, or %NULL
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Sets the "Content-Type" header in @hdrs to @content_type,
rpm-build 4f3c61
 * optionally with additional parameters specified in @params.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.26
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_set_content_type (SoupMessageHeaders  *hdrs,
rpm-build 4f3c61
				       const char          *content_type,
rpm-build 4f3c61
				       GHashTable          *params)
rpm-build 4f3c61
{
rpm-build 4f3c61
	set_content_foo (hdrs, "Content-Type", content_type, params);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_get_content_disposition:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @disposition: (out) (transfer full): return location for the
rpm-build 4f3c61
 * disposition-type, or %NULL
rpm-build 4f3c61
 * @params: (out) (transfer full) (element-type utf8 utf8): return
rpm-build 4f3c61
 * location for the Content-Disposition parameters, or %NULL
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Looks up the "Content-Disposition" header in @hdrs, parses it, and
rpm-build 4f3c61
 * returns its value in *@disposition and *@params. @params can be
rpm-build 4f3c61
 * %NULL if you are only interested in the disposition-type.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * In HTTP, the most common use of this header is to set a
rpm-build 4f3c61
 * disposition-type of "attachment", to suggest to the browser that a
rpm-build 4f3c61
 * response should be saved to disk rather than displayed in the
rpm-build 4f3c61
 * browser. If @params contains a "filename" parameter, this is a
rpm-build 4f3c61
 * suggestion of a filename to use. (If the parameter value in the
rpm-build 4f3c61
 * header contains an absolute or relative path, libsoup will truncate
rpm-build 4f3c61
 * it down to just the final path component, so you do not need to
rpm-build 4f3c61
 * test this yourself.)
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Content-Disposition is also used in "multipart/form-data", however
rpm-build 4f3c61
 * this is handled automatically by #SoupMultipart and the associated
rpm-build 4f3c61
 * form methods.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: %TRUE if @hdrs contains a "Content-Disposition"
rpm-build 4f3c61
 * header, %FALSE if not (in which case *@disposition and *@params
rpm-build 4f3c61
 * will be unchanged).
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.26
rpm-build 4f3c61
 **/
rpm-build 4f3c61
gboolean
rpm-build 4f3c61
soup_message_headers_get_content_disposition (SoupMessageHeaders  *hdrs,
rpm-build 4f3c61
					      char               **disposition,
rpm-build 4f3c61
					      GHashTable         **params)
rpm-build 4f3c61
{
rpm-build 4f3c61
	gpointer orig_key, orig_value;
rpm-build 4f3c61
rpm-build 4f3c61
	if (!parse_content_foo (hdrs, "Content-Disposition",
rpm-build 4f3c61
				disposition, params))
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
rpm-build 4f3c61
	/* If there is a filename parameter, make sure it contains
rpm-build 4f3c61
	 * only a single path component
rpm-build 4f3c61
	 */
rpm-build 4f3c61
	if (params && g_hash_table_lookup_extended (*params, "filename",
rpm-build 4f3c61
						    &orig_key, &orig_value)) {
rpm-build 4f3c61
		char *filename = strrchr (orig_value, '/');
rpm-build 4f3c61
rpm-build 4f3c61
		if (filename)
rpm-build 4f3c61
			g_hash_table_insert (*params, g_strdup (orig_key), filename + 1);
rpm-build 4f3c61
	}
rpm-build 4f3c61
	return TRUE;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_message_headers_set_content_disposition:
rpm-build 4f3c61
 * @hdrs: a #SoupMessageHeaders
rpm-build 4f3c61
 * @disposition: the disposition-type
rpm-build 4f3c61
 * @params: (allow-none) (element-type utf8 utf8): additional
rpm-build 4f3c61
 * parameters, or %NULL
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Sets the "Content-Disposition" header in @hdrs to @disposition,
rpm-build 4f3c61
 * optionally with additional parameters specified in @params.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * See soup_message_headers_get_content_disposition() for a discussion
rpm-build 4f3c61
 * of how Content-Disposition is used in HTTP.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Since: 2.26
rpm-build 4f3c61
 **/
rpm-build 4f3c61
void
rpm-build 4f3c61
soup_message_headers_set_content_disposition (SoupMessageHeaders  *hdrs,
rpm-build 4f3c61
					      const char          *disposition,
rpm-build 4f3c61
					      GHashTable          *params)
rpm-build 4f3c61
{
rpm-build 4f3c61
	set_content_foo (hdrs, "Content-Disposition", disposition, params);
rpm-build 4f3c61
}
rpm-build 4f3c61