header.h 10.2 KB
/**
 * \file
 *
 * \author	Georg Hopp
 *
 * \copyright
 * Copyright © 2014 Georg Hopp
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */

#ifndef __TR_PROTOCOL_HTTP_HEADER_H__
#define __TR_PROTOCOL_HTTP_HEADER_H__

/**
 * Keys for known headers index.
 * =============================
 */
/**
 * GENERAL-HEADER
 */
#define TR_HTTP_CACHE_CONTROL       0x00
#define TR_HTTP_CONNECTION          0x01
#define TR_HTTP_DATE                0x02
#define TR_HTTP_PRAGMA              0x03
#define TR_HTTP_TRAILER             0x04
#define TR_HTTP_TRANSFER_ENCODING   0x05
#define TR_HTTP_UPGRADE             0x06
#define TR_HTTP_VIA                 0x07
#define TR_HTTP_WARNING             0x08

/**
 * ENTITY-HEADER
 */
#define TR_HTTP_ALLOW               0x09
#define TR_HTTP_CONTENT_ENCODING    0x0a
#define TR_HTTP_CONTENT_LANGUAGE    0x0b
#define TR_HTTP_CONTENT_LENGTH      0x0c
#define TR_HTTP_CONTENT_LOCATION    0x0d
#define TR_HTTP_CONTENT_MD5         0x0e
#define TR_HTTP_CONTENT_RANGE       0x0f
#define TR_HTTP_CONTENT_TYPE        0x10
#define TR_HTTP_EXPIRES             0x11
#define TR_HTTP_LAST_MODIFIED       0x12
#define TR_HTTP_EXTENSION_HEADER    0x13

/**
 * REQUEST-HEADER
 */
#define TR_HTTP_ACCEPT              0x14
#define TR_HTTP_ACCEPT_CHARSET      0x15
#define TR_HTTP_ACCEPT_ENCODING     0x16
#define TR_HTTP_ACCEPT_LANGUAGE     0x17
#define TR_HTTP_AUTHORIZATION       0x18
#define TR_HTTP_EXPECT              0x19
#define TR_HTTP_FROM                0x1a
#define TR_HTTP_HOST                0x1b
#define TR_HTTP_IF_MATCH            0x1c
#define TR_HTTP_IF_MODIFIED_SINCE   0x1d
#define TR_HTTP_IF_NONE_MATCH       0x1e
#define TR_HTTP_IF_RANGE            0x1f
#define TR_HTTP_IF_UNMODIFIED_SINCE 0x20
#define TR_HTTP_MAX_FORWARDS        0x21
#define TR_HTTP_PROXY_AUTHORIZATION 0x22
#define TR_HTTP_RANGE               0x23
#define TR_HTTP_REFERER             0x34
#define TR_HTTP_TE                  0x35
#define TR_HTTP_USER_AGENT          0x36

/**
 * RESPONSE-HEADER
 */
#define TR_HTTP_ACCEPT_RANGES       0x37
#define TR_HTTP_AGE                 0x38
#define TR_HTTP_ETAG                0x39
#define TR_HTTP_LOCATION            0x3a
#define TR_HTTP_PROXY_AUTHENTICATE  0x3b
#define TR_HTTP_RETRY_AFTER         0x3c
#define TR_HTTP_SERVER              0x3d
#define TR_HTTP_VARY                0x3e
#define TR_HTTP_WWW_AUTHENTICATE    0x3f

/**
 * Hashes of known headers.
 * ========================
 */
#define TR_HTTP_CACHE_CONTROL_HASH       0x10ebed1ca8c23b92
#define TR_HTTP_CONNECTION_HASH          0xdf36a16b81e885be
#define	TR_HTTP_DATE_HASH                0x644a475ce1876e
#define TR_HTTP_PRAGMA_HASH              0x55d60d17c6e74a7c
#define	TR_HTTP_TRAILER_HASH             0xa0d2d161f2a6a1f3
#define TR_HTTP_TRANSFER_ENCODING_HASH   0x77560878338b21b5
#define TR_HTTP_UPGRADE_HASH             0xcd68a236d154b3dc
#define TR_HTTP_VIA_HASH                 0x763a843fae
#define TR_HTTP_WARNING_HASH             0x7a6ff0ee66182ebc
#define TR_HTTP_ALLOW_HASH               0x600b954a930db629
#define TR_HTTP_CONTENT_ENCODING_HASH    0x255bb87d2a28e067
#define TR_HTTP_CONTENT_LANGUAGE_HASH    0xf5d09db2a6f834ac
#define TR_HTTP_CONTENT_LENGTH_HASH      0xd1087ddaa397adba
#define TR_HTTP_CONTENT_LOCATION_HASH    0x5afce14ea7508549
#define	TR_HTTP_CONTENT_MD5_HASH         0x494a50455baa33ea
#define TR_HTTP_CONTENT_RANGE_HASH       0x2bdea46d9b7cd529
#define TR_HTTP_CONTENT_TYPE_HASH        0x599621fd130ed04e
#define TR_HTTP_EXPIRES_HASH             0xdf910203e8faddf4
#define TR_HTTP_LAST_MODIFIED_HASH       0xfa560d925c994000
#define TR_HTTP_EXTENSION_HEADER_HASH    0x53941c8ea8a1e7db
#define TR_HTTP_ACCEPT_HASH              0x2f3c03f7db888a08
#define TR_HTTP_ACCEPT_CHARSET_HASH      0xb37d0a6b711f7ac7
#define TR_HTTP_ACCEPT_ENCODING_HASH     0x4726b8f7454ad8b8
#define TR_HTTP_ACCEPT_LANGUAGE_HASH     0x179b9e2cc21a2cfd
#define TR_HTTP_AUTHORIZATION_HASH       0x4532c2919a3fd8b9
#define TR_HTTP_EXPECT_HASH              0xb0bd60f223697099
#define TR_HTTP_FROM_HASH                0x664bd2c2492f4a
#define TR_HTTP_HOST_HASH                0x684d4a1de0a348
#define TR_HTTP_IF_MATCH_HASH            0x41d2aaf0e365b1d5
#define TR_HTTP_IF_MODIFIED_SINCE_HASH   0xf274d261b51c4346
#define TR_HTTP_IF_NONE_MATCH_HASH       0xf9944adc1db092c0
#define TR_HTTP_IF_RANGE_HASH            0x46c07c55341330cd
#define TR_HTTP_IF_UNMODIFIED_SINCE_HASH 0x5168b51c08ddb0ff
#define TR_HTTP_MAX_FORWARDS_HASH        0x1a77424bd2be9957
#define TR_HTTP_PROXY_AUTHORIZATION_HASH 0x70e31fa0e6a3863a
#define TR_HTTP_RANGE_HASH               0x70c2bb9516e929fd
#define TR_HTTP_REFERER_HASH             0xa4479c0c286c9cd
#define TR_HTTP_TE_HASH                  0x741cf1
#define TR_HTTP_USER_AGENT_HASH          0x7b0fac82315c4c3
#define TR_HTTP_ACCEPT_RANGES_HASH       0xbed0ffaee7c0c65b
#define TR_HTTP_AGE_HASH                 0x61302af99f
#define TR_HTTP_ETAG_HASH                0x654b1794b07a15
#define TR_HTTP_LOCATION_HASH            0xbea0ee8241080f75
#define TR_HTTP_PROXY_AUTHENTICATE_HASH  0xe8909f18b6b8f7f4
#define	TR_HTTP_RETRY_AFTER_HASH         0x1481da5b8cb48417
#define TR_HTTP_SERVER_HASH              0x1aa6e41ab4ba5e83
#define TR_HTTP_VARY_HASH                0x765794a25a3472
#define TR_HTTP_WWW_AUTHENTICATE_HASH    0x71324edcfda58eeb

#define TR_HTTP_CLOSE_HASH      0x62044f781c64a398
#define TR_HTTP_KEEP_ALIVE_HASH 0xef5fed49e89640e5

/**
 * Big ternery to map hashes to keys of knwon headers.
 * ===================================================
 */
#define TR_IDX_BY_HASH(hash) ( \
		(hash) == TR_HTTP_CACHE_CONTROL_HASH       ? TR_HTTP_CACHE_CONTROL       : \
		(hash) == TR_HTTP_CONNECTION_HASH          ? TR_HTTP_CONNECTION          : \
		(hash) == TR_HTTP_DATE_HASH                ? TR_HTTP_DATE                : \
		(hash) == TR_HTTP_PRAGMA_HASH              ? TR_HTTP_PRAGMA              : \
		(hash) == TR_HTTP_TRAILER_HASH             ? TR_HTTP_TRAILER             : \
		(hash) == TR_HTTP_TRANSFER_ENCODING_HASH   ? TR_HTTP_TRANSFER_ENCODING   : \
		(hash) == TR_HTTP_UPGRADE_HASH             ? TR_HTTP_UPGRADE             : \
		(hash) == TR_HTTP_VIA_HASH                 ? TR_HTTP_VIA                 : \
		(hash) == TR_HTTP_WARNING_HASH             ? TR_HTTP_WARNING             : \
		(hash) == TR_HTTP_ALLOW_HASH               ? TR_HTTP_ALLOW               : \
		(hash) == TR_HTTP_CONTENT_ENCODING_HASH    ? TR_HTTP_CONTENT_ENCODING    : \
		(hash) == TR_HTTP_CONTENT_LANGUAGE_HASH    ? TR_HTTP_CONTENT_LANGUAGE    : \
		(hash) == TR_HTTP_CONTENT_LENGTH_HASH      ? TR_HTTP_CONTENT_LENGTH      : \
		(hash) == TR_HTTP_CONTENT_LOCATION_HASH    ? TR_HTTP_CONTENT_LOCATION    : \
		(hash) == TR_HTTP_CONTENT_MD5_HASH         ? TR_HTTP_CONTENT_MD5         : \
		(hash) == TR_HTTP_CONTENT_RANGE_HASH       ? TR_HTTP_CONTENT_RANGE       : \
		(hash) == TR_HTTP_CONTENT_TYPE_HASH        ? TR_HTTP_CONTENT_TYPE        : \
		(hash) == TR_HTTP_EXPIRES_HASH             ? TR_HTTP_EXPIRES             : \
		(hash) == TR_HTTP_LAST_MODIFIED_HASH       ? TR_HTTP_LAST_MODIFIED       : \
		(hash) == TR_HTTP_EXTENSION_HEADER_HASH    ? TR_HTTP_EXTENSION_HEADER    : \
		(hash) == TR_HTTP_ACCEPT_HASH              ? TR_HTTP_ACCEPT              : \
		(hash) == TR_HTTP_ACCEPT_CHARSET_HASH      ? TR_HTTP_ACCEPT_CHARSET      : \
		(hash) == TR_HTTP_ACCEPT_ENCODING_HASH     ? TR_HTTP_ACCEPT_ENCODING     : \
		(hash) == TR_HTTP_ACCEPT_LANGUAGE_HASH     ? TR_HTTP_ACCEPT_LANGUAGE     : \
		(hash) == TR_HTTP_AUTHORIZATION_HASH       ? TR_HTTP_AUTHORIZATION       : \
		(hash) == TR_HTTP_EXPECT_HASH              ? TR_HTTP_EXPECT              : \
		(hash) == TR_HTTP_FROM_HASH                ? TR_HTTP_FROM                : \
		(hash) == TR_HTTP_HOST_HASH                ? TR_HTTP_HOST                : \
		(hash) == TR_HTTP_IF_MATCH_HASH            ? TR_HTTP_IF_MATCH            : \
		(hash) == TR_HTTP_IF_MODIFIED_SINCE_HASH   ? TR_HTTP_IF_MODIFIED_SINCE   : \
		(hash) == TR_HTTP_IF_NONE_MATCH_HASH       ? TR_HTTP_IF_NONE_MATCH       : \
		(hash) == TR_HTTP_IF_RANGE_HASH            ? TR_HTTP_IF_RANGE            : \
		(hash) == TR_HTTP_IF_UNMODIFIED_SINCE_HASH ? TR_HTTP_IF_UNMODIFIED_SINCE : \
		(hash) == TR_HTTP_MAX_FORWARDS_HASH        ? TR_HTTP_MAX_FORWARDS        : \
		(hash) == TR_HTTP_PROXY_AUTHORIZATION_HASH ? TR_HTTP_PROXY_AUTHORIZATION : \
		(hash) == TR_HTTP_RANGE_HASH               ? TR_HTTP_RANGE               : \
		(hash) == TR_HTTP_REFERER_HASH             ? TR_HTTP_REFERER             : \
		(hash) == TR_HTTP_TE_HASH                  ? TR_HTTP_TE                  : \
		(hash) == TR_HTTP_USER_AGENT_HASH          ? TR_HTTP_USER_AGENT          : \
		(hash) == TR_HTTP_ACCEPT_RANGES_HASH       ? TR_HTTP_ACCEPT_RANGES       : \
		(hash) == TR_HTTP_AGE_HASH                 ? TR_HTTP_AGE                 : \
		(hash) == TR_HTTP_ETAG_HASH                ? TR_HTTP_ETAG                : \
		(hash) == TR_HTTP_LOCATION_HASH            ? TR_HTTP_LOCATION            : \
		(hash) == TR_HTTP_PROXY_AUTHENTICATE_HASH  ? TR_HTTP_PROXY_AUTHENTICATE  : \
		(hash) == TR_HTTP_RETRY_AFTER_HASH         ? TR_HTTP_RETRY_AFTER         : \
		(hash) == TR_HTTP_SERVER_HASH              ? TR_HTTP_SERVER              : \
		(hash) == TR_HTTP_VARY_HASH                ? TR_HTTP_VARY                : \
		(hash) == TR_HTTP_WWW_AUTHENTICATE_HASH    ? TR_HTTP_WWW_AUTHENTICATE    : -1)

#define TR_N_HTTP_HEADER_IDX 0x40

extern const char* const   TR_http_header_keys[];
extern const unsigned long TR_http_header_hashes[];

#include "trbase.h"
#include "trdata.h"

TR_CLASS(TR_HttpHeader) {
	unsigned long   hash;
	int             idx;
	const char    * key;
	TR_Queue        value;
};
TR_INSTANCE_INIT(TR_HttpHeader);
TR_CLASSVARS_DECL(TR_HttpHeader) {};

int _httpHeaderCompare(const void *, const void *);

#endif // __TR_PROTOCOL_HTTP_HEADER_H__

// vim: set ts=4 sw=4: