blob: b48ec64225fa7b524190300bf8b4691b011db360 [file] [log] [blame]
Willy Tarreaub7eba102006-12-04 02:20:02 +01001/*
2 * Header indexation functions.
3 *
Willy Tarreau34eb6712011-10-24 18:15:04 +02004 * Copyright 2000-2011 Willy Tarreau <w@1wt.eu>
Willy Tarreaub7eba102006-12-04 02:20:02 +01005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <common/config.h>
Willy Tarreau34eb6712011-10-24 18:15:04 +020014#include <common/memory.h>
Willy Tarreauec6c5df2008-07-15 00:22:45 +020015#include <proto/hdr_idx.h>
Willy Tarreaub7eba102006-12-04 02:20:02 +010016
Willy Tarreaubafbe012017-11-24 17:34:44 +010017struct pool_head *pool_head_hdr_idx = NULL;
Willy Tarreaub7eba102006-12-04 02:20:02 +010018
19/*
Willy Tarreaub7eba102006-12-04 02:20:02 +010020 * Add a header entry to <list> after element <after>. <after> is ignored when
21 * the list is empty or full. Common usage is to set <after> to list->tail.
22 *
23 * Returns the position of the new entry in the list (from 1 to size-1), or 0
24 * if the array is already full. An effort is made to fill the array linearly,
25 * but once the last entry has been used, we have to search for unused blocks,
26 * which takes much more time. For this reason, it's important to size is
27 * appropriately.
28 */
29int hdr_idx_add(int len, int cr, struct hdr_idx *list, int after)
30{
31 register struct hdr_idx_elem e = { .len=0, .cr=0, .next=0};
32 int new;
33
34 e.len = len;
35 e.cr = cr;
36
37 if (list->used == list->size) {
38 /* list is full */
39 return -1;
40 }
41
42
43 if (list->last < list->size) {
44 /* list is not completely used, we can fill linearly */
45 new = list->last++;
46 } else {
47 /* That's the worst situation :
48 * we have to scan the list for holes. We know that we
49 * will find a place because the list is not full.
50 */
51 new = 1;
52 while (list->v[new].len)
53 new++;
54 }
55
56 /* insert the new element between <after> and the next one (or end) */
57 e.next = list->v[after].next;
58 list->v[after].next = new;
59
60 list->used++;
61 list->v[new] = e;
62 list->tail = new;
63 return new;
64}
65
66
67/*
68 * Local variables:
69 * c-indent-level: 8
70 * c-basic-offset: 8
71 * End:
72 */