| | varnish-cache/bin/varnishd/hash/mgt_hash.c |
0 |
|
/*- |
1 |
|
* Copyright (c) 2006 Verdens Gang AS |
2 |
|
* Copyright (c) 2006-2011 Varnish Software AS |
3 |
|
* All rights reserved. |
4 |
|
* |
5 |
|
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk> |
6 |
|
* |
7 |
|
* SPDX-License-Identifier: BSD-2-Clause |
8 |
|
* |
9 |
|
* Redistribution and use in source and binary forms, with or without |
10 |
|
* modification, are permitted provided that the following conditions |
11 |
|
* are met: |
12 |
|
* 1. Redistributions of source code must retain the above copyright |
13 |
|
* notice, this list of conditions and the following disclaimer. |
14 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
15 |
|
* notice, this list of conditions and the following disclaimer in the |
16 |
|
* documentation and/or other materials provided with the distribution. |
17 |
|
* |
18 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
19 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
22 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
23 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
24 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
25 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
26 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
27 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
28 |
|
* SUCH DAMAGE. |
29 |
|
* |
30 |
|
*/ |
31 |
|
|
32 |
|
#include "config.h" |
33 |
|
|
34 |
|
#include <stdio.h> |
35 |
|
#include <stdlib.h> |
36 |
|
#include <unistd.h> |
37 |
|
|
38 |
|
#include "mgt/mgt.h" |
39 |
|
#include "common/heritage.h" |
40 |
|
|
41 |
|
#include "hash/hash_slinger.h" |
42 |
|
#include "vav.h" |
43 |
|
|
44 |
|
static const struct choice hsh_choice[] = { |
45 |
|
{ "classic", &hcl_slinger }, |
46 |
|
{ "simple", &hsl_slinger }, |
47 |
|
{ "simple_list", &hsl_slinger }, /* backwards compat */ |
48 |
|
{ "critbit", &hcb_slinger }, |
49 |
|
{ NULL, NULL } |
50 |
|
}; |
51 |
|
|
52 |
|
/*--------------------------------------------------------------------*/ |
53 |
|
|
54 |
|
void |
55 |
37720 |
HSH_config(const char *h_arg) |
56 |
|
{ |
57 |
|
char **av; |
58 |
|
int ac; |
59 |
|
const struct hash_slinger *hp; |
60 |
|
|
61 |
37720 |
ASSERT_MGT(); |
62 |
37720 |
av = VAV_Parse(h_arg, NULL, ARGV_COMMA); |
63 |
37720 |
AN(av); |
64 |
|
|
65 |
37720 |
if (av[0] != NULL) |
66 |
0 |
ARGV_ERR("%s\n", av[0]); |
67 |
|
|
68 |
37720 |
if (av[1] == NULL) |
69 |
0 |
ARGV_ERR("-h argument is empty\n"); |
70 |
|
|
71 |
37760 |
for (ac = 0; av[ac + 2] != NULL; ac++) |
72 |
40 |
continue; |
73 |
|
|
74 |
37720 |
hp = MGT_Pick(hsh_choice, av[1], "hash"); |
75 |
37720 |
CHECK_OBJ_NOTNULL(hp, SLINGER_MAGIC); |
76 |
37720 |
VSB_printf(vident, ",-h%s", av[1]); |
77 |
37720 |
heritage.hash = hp; |
78 |
37720 |
if (hp->init != NULL) |
79 |
40 |
hp->init(ac, av + 2); |
80 |
37680 |
else if (ac > 0) |
81 |
0 |
ARGV_ERR("Hash method \"%s\" takes no arguments\n", |
82 |
|
hp->name); |
83 |
|
/* NB: Don't free av, the hasher is allowed to keep it. */ |
84 |
37720 |
} |