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