blob: 809ea8399087c25ab77377cf46939df02b1cbcfb [file] [log] [blame]
Willy Tarreaub7eba102006-12-04 02:20:02 +01001/*
2 include/types/hdr_idx.h
3 This file defines everything related to fast header indexation.
4
5 Copyright (C) 2000-2006 Willy Tarreau - w@1wt.eu
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation, version 2.1
10 exclusively.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
22
23/*
24 * The type of structure described here is a finite linked list used to
25 * reference small number of objects of small size. This is typically used
26 * to index HTTP headers within one request or response, in order to be able
27 * to add, remove, modify and check them in an efficient way. The overhead is
28 * very low : 32 bits are used per list element. This is enough to reference
29 * 32k headers of at most 64kB each, with one bit to indicate if the header
30 * is terminated by 1 or 2 chars. It may also evolve towards something like
31 * 1k headers of at most 64B for the name and 32kB of data + CR/CRLF.
32 *
33 * A future evolution of this concept may allow for fast header manipulation
34 * without data movement through the use of vectors. This is not yet possible
35 * in this version, whose goal is only to avoid parsing whole lines for each
36 * consultation.
37 *
38 */
39
40
41#ifndef _TYPES_HDR_IDX_H
42#define _TYPES_HDR_IDX_H
43
44/*
45 * This describes one element of the hdr_idx array.
46 * It's a tiny linked list of at most 32k 32bit elements. The first one has a
47 * special meaning, it's used as the head of the list and cannod be removed.
48 * That way, we know that 'next==0' is not possible so we use it to indicate
49 * an end of list. Also, [0]->next always designates the head of the list. The
50 * first allocatable element is at 1. By convention, [0]->len indicates how
51 * many chars should be skipped in the original buffer before finding the first
52 * header.
53 *
54 */
55
56struct hdr_idx_elem {
57 unsigned len :16; /* length of this header not counting CRLF. 0=unused entry. */
58 unsigned cr : 1; /* CR present (1=CRLF, 0=LF). Total line size=len+cr+1. */
59 unsigned next :15; /* offset of next header if len>0. 0=end of list. */
60};
61
62/*
63 * This structure provides necessary information to store, find, remove
64 * index entries from a list. This list cannot reference more than 32k
65 * elements of 64k each.
66 */
67struct hdr_idx {
68 struct hdr_idx_elem *v; /* the array itself */
69 short size; /* size of the array including the head */
70 short used; /* # of elements really used (1..size) */
71 short last; /* length of the allocated area (1..size) */
72 signed short tail; /* last used element, 0..size-1 */
73};
74
75
76
77#endif /* _TYPES_HDR_IDX_H */
78
79/*
80 * Local variables:
81 * c-indent-level: 8
82 * c-basic-offset: 8
83 * End:
84 */