blob: 9e67a003a6d69da309c4652a15f96bffe1986dcb [file] [log] [blame]
Willy Tarreaub7eba102006-12-04 02:20:02 +01001/*
2 include/proto/hdr_idx.h
3 This file defines function prototypes for 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#ifndef _PROTO_HDR_IDX_H
23#define _PROTO_HDR_IDX_H
24
25#include <common/config.h>
26#include <types/hdr_idx.h>
27
28/*
29 * Initialize the list pointers.
30 * list->size must already be set. If list->size is set and list->v is
31 * non-null, list->v is also initialized..
32 */
33static inline void hdr_idx_init(struct hdr_idx *list)
34{
35 if (list->size && list->v) {
36 register struct hdr_idx_elem e = { .len=0, .cr=0, .next=0};
37 list->v[0] = e;
38 }
39 list->tail = 0;
40 list->used = list->last = 1;
41}
42
43/*
Willy Tarreau8d5d7f22007-01-21 19:16:41 +010044 * Return index of the first entry in the list. Usually, it means the index of
45 * the first header just after the request or response. If zero is returned, it
46 * means that the list is empty.
47 */
48static inline int hdr_idx_first_idx(struct hdr_idx *list)
49{
50 return list->v[0].next;
51}
52
53/*
54 * Return position of the first entry in the list. Usually, it means the
55 * position of the first header just after the request, but it can also be the
56 * end of the headers if the request has no header. hdr_idx_start_idx() should
57 * be checked before to ensure there is a valid header.
58 */
59static inline int hdr_idx_first_pos(struct hdr_idx *list)
60{
61 return list->v[0].len + list->v[0].cr + 1;
62}
63
64/*
65 * Sets the information about the start line. Its length and the presence of
66 * the CR are registered so that hdr_idx_first_pos() knows exactly where to
67 * find the first header.
68 */
69static inline void hdr_idx_set_start(struct hdr_idx *list, int len, int cr)
70{
71 list->v[0].len = len;
72 list->v[0].cr = cr;
73}
74
75/*
Willy Tarreaub7eba102006-12-04 02:20:02 +010076 * Add a header entry to <list> after element <after>. <after> is ignored when
77 * the list is empty or full. Common usage is to set <after> to list->tail.
78 *
79 * Returns the position of the new entry in the list (from 1 to size-1), or 0
80 * if the array is already full. An effort is made to fill the array linearly,
81 * but once the last entry has been used, we have to search for unused blocks,
82 * which takes much more time. For this reason, it's important to size is
83 * appropriately.
84 */
85int hdr_idx_add(int len, int cr, struct hdr_idx *list, int after);
86
87#endif /* _PROTO_HDR_IDX_H */
88
89/*
90 * Local variables:
91 * c-indent-level: 8
92 * c-basic-offset: 8
93 * End:
94 */