Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1 | /* |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 2 | * Sample management functions. |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 3 | * |
| 4 | * Copyright 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 5 | * Copyright (C) 2012 Willy Tarreau <w@1wt.eu> |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <string.h> |
| 15 | #include <arpa/inet.h> |
Willy Tarreau | dd2f85e | 2012-09-02 22:34:23 +0200 | [diff] [blame] | 16 | #include <stdio.h> |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 17 | |
Willy Tarreau | 7e2c647 | 2012-10-29 20:44:36 +0100 | [diff] [blame] | 18 | #include <types/global.h> |
| 19 | |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 20 | #include <common/chunk.h> |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 21 | #include <common/hash.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 22 | #include <common/standard.h> |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 23 | #include <common/uri_auth.h> |
Emeric Brun | 53d1a98 | 2014-04-30 18:21:37 +0200 | [diff] [blame] | 24 | #include <common/base64.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 25 | |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 26 | #include <proto/arg.h> |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 27 | #include <proto/auth.h> |
| 28 | #include <proto/log.h> |
Thierry FOURNIER | d437314 | 2013-12-17 01:10:10 +0100 | [diff] [blame] | 29 | #include <proto/proto_http.h> |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 30 | #include <proto/proxy.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 31 | #include <proto/sample.h> |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 32 | #include <proto/stick_table.h> |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 33 | |
Willy Tarreau | 1cf8f08 | 2014-02-07 12:14:54 +0100 | [diff] [blame] | 34 | /* sample type names */ |
| 35 | const char *smp_to_type[SMP_TYPES] = { |
| 36 | [SMP_T_BOOL] = "bool", |
| 37 | [SMP_T_UINT] = "uint", |
| 38 | [SMP_T_SINT] = "sint", |
| 39 | [SMP_T_ADDR] = "addr", |
| 40 | [SMP_T_IPV4] = "ipv4", |
| 41 | [SMP_T_IPV6] = "ipv6", |
| 42 | [SMP_T_STR] = "str", |
| 43 | [SMP_T_BIN] = "bin", |
Willy Tarreau | 1cf8f08 | 2014-02-07 12:14:54 +0100 | [diff] [blame] | 44 | }; |
| 45 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 46 | /* static sample used in sample_process() when <p> is NULL */ |
Willy Tarreau | b4a88f0 | 2012-04-23 21:35:11 +0200 | [diff] [blame] | 47 | static struct sample temp_smp; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 48 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 49 | /* list head of all known sample fetch keywords */ |
| 50 | static struct sample_fetch_kw_list sample_fetches = { |
| 51 | .list = LIST_HEAD_INIT(sample_fetches.list) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 52 | }; |
| 53 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 54 | /* list head of all known sample format conversion keywords */ |
| 55 | static struct sample_conv_kw_list sample_convs = { |
| 56 | .list = LIST_HEAD_INIT(sample_convs.list) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 57 | }; |
| 58 | |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 59 | const unsigned int fetch_cap[SMP_SRC_ENTRIES] = { |
| 60 | [SMP_SRC_INTRN] = (SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 61 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 62 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 63 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 64 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 65 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 66 | SMP_VAL_FE_LOG_END), |
| 67 | |
| 68 | [SMP_SRC_LISTN] = (SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 69 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 70 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 71 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 72 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 73 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 74 | SMP_VAL_FE_LOG_END), |
| 75 | |
| 76 | [SMP_SRC_FTEND] = (SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 77 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 78 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 79 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 80 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 81 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 82 | SMP_VAL_FE_LOG_END), |
| 83 | |
| 84 | [SMP_SRC_L4CLI] = (SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 85 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 86 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 87 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 88 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 89 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 90 | SMP_VAL_FE_LOG_END), |
| 91 | |
| 92 | [SMP_SRC_L5CLI] = (SMP_VAL___________ | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 93 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 94 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 95 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 96 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 97 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 98 | SMP_VAL_FE_LOG_END), |
| 99 | |
| 100 | [SMP_SRC_TRACK] = (SMP_VAL_FE_CON_ACC | SMP_VAL_FE_SES_ACC | SMP_VAL_FE_REQ_CNT | |
| 101 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 102 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 103 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 104 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 105 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 106 | SMP_VAL_FE_LOG_END), |
| 107 | |
| 108 | [SMP_SRC_L6REQ] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_FE_REQ_CNT | |
| 109 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 110 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 111 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL___________ | |
| 112 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 113 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 114 | SMP_VAL___________), |
| 115 | |
| 116 | [SMP_SRC_HRQHV] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_FE_REQ_CNT | |
| 117 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 118 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 119 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL___________ | |
| 120 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 121 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 122 | SMP_VAL___________), |
| 123 | |
| 124 | [SMP_SRC_HRQHP] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_FE_REQ_CNT | |
| 125 | SMP_VAL_FE_HRQ_HDR | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 126 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 127 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 128 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 129 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 130 | SMP_VAL_FE_LOG_END), |
| 131 | |
| 132 | [SMP_SRC_HRQBO] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 133 | SMP_VAL___________ | SMP_VAL_FE_HRQ_BDY | SMP_VAL_FE_SET_BCK | |
| 134 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 135 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL___________ | |
| 136 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 137 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 138 | SMP_VAL___________), |
| 139 | |
| 140 | [SMP_SRC_BKEND] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 141 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 142 | SMP_VAL_BE_REQ_CNT | SMP_VAL_BE_HRQ_HDR | SMP_VAL_BE_HRQ_BDY | |
| 143 | SMP_VAL_BE_SET_SRV | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 144 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 145 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 146 | SMP_VAL_FE_LOG_END), |
| 147 | |
| 148 | [SMP_SRC_SERVR] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 149 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 150 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 151 | SMP_VAL___________ | SMP_VAL_BE_SRV_CON | SMP_VAL_BE_RES_CNT | |
| 152 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 153 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 154 | SMP_VAL_FE_LOG_END), |
| 155 | |
| 156 | [SMP_SRC_L4SRV] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 157 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 158 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 159 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_BE_RES_CNT | |
| 160 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 161 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 162 | SMP_VAL_FE_LOG_END), |
| 163 | |
| 164 | [SMP_SRC_L5SRV] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 165 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 166 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 167 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_BE_RES_CNT | |
| 168 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 169 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 170 | SMP_VAL_FE_LOG_END), |
| 171 | |
| 172 | [SMP_SRC_L6RES] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 173 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 174 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 175 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_BE_RES_CNT | |
| 176 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 177 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 178 | SMP_VAL___________), |
| 179 | |
| 180 | [SMP_SRC_HRSHV] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 181 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 182 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 183 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_BE_RES_CNT | |
| 184 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 185 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 186 | SMP_VAL___________), |
| 187 | |
| 188 | [SMP_SRC_HRSHP] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 189 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 190 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 191 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL_BE_RES_CNT | |
| 192 | SMP_VAL_BE_HRS_HDR | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 193 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 194 | SMP_VAL_FE_LOG_END), |
| 195 | |
| 196 | [SMP_SRC_HRSBO] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 197 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 198 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 199 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 200 | SMP_VAL___________ | SMP_VAL_BE_HRS_BDY | SMP_VAL_BE_STO_RUL | |
| 201 | SMP_VAL_FE_RES_CNT | SMP_VAL_FE_HRS_HDR | SMP_VAL_FE_HRS_BDY | |
| 202 | SMP_VAL___________), |
| 203 | |
| 204 | [SMP_SRC_RQFIN] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 205 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 206 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 207 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 208 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 209 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 210 | SMP_VAL_FE_LOG_END), |
| 211 | |
| 212 | [SMP_SRC_RSFIN] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 213 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 214 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 215 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 216 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 217 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 218 | SMP_VAL_FE_LOG_END), |
| 219 | |
| 220 | [SMP_SRC_TXFIN] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 221 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 222 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 223 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 224 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 225 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 226 | SMP_VAL_FE_LOG_END), |
| 227 | |
| 228 | [SMP_SRC_SSFIN] = (SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 229 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 230 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 231 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 232 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 233 | SMP_VAL___________ | SMP_VAL___________ | SMP_VAL___________ | |
| 234 | SMP_VAL_FE_LOG_END), |
| 235 | }; |
| 236 | |
| 237 | static const char *fetch_src_names[SMP_SRC_ENTRIES] = { |
| 238 | [SMP_SRC_INTRN] = "internal state", |
| 239 | [SMP_SRC_LISTN] = "listener", |
| 240 | [SMP_SRC_FTEND] = "frontend", |
| 241 | [SMP_SRC_L4CLI] = "client address", |
| 242 | [SMP_SRC_L5CLI] = "client-side connection", |
| 243 | [SMP_SRC_TRACK] = "track counters", |
| 244 | [SMP_SRC_L6REQ] = "request buffer", |
| 245 | [SMP_SRC_HRQHV] = "HTTP request headers", |
| 246 | [SMP_SRC_HRQHP] = "HTTP request", |
| 247 | [SMP_SRC_HRQBO] = "HTTP request body", |
| 248 | [SMP_SRC_BKEND] = "backend", |
| 249 | [SMP_SRC_SERVR] = "server", |
| 250 | [SMP_SRC_L4SRV] = "server address", |
| 251 | [SMP_SRC_L5SRV] = "server-side connection", |
| 252 | [SMP_SRC_L6RES] = "response buffer", |
| 253 | [SMP_SRC_HRSHV] = "HTTP response headers", |
| 254 | [SMP_SRC_HRSHP] = "HTTP response", |
| 255 | [SMP_SRC_HRSBO] = "HTTP response body", |
| 256 | [SMP_SRC_RQFIN] = "request buffer statistics", |
| 257 | [SMP_SRC_RSFIN] = "response buffer statistics", |
| 258 | [SMP_SRC_TXFIN] = "transaction statistics", |
| 259 | [SMP_SRC_SSFIN] = "session statistics", |
| 260 | }; |
| 261 | |
Willy Tarreau | bf8e251 | 2013-03-25 14:52:41 +0100 | [diff] [blame] | 262 | static const char *fetch_ckp_names[SMP_CKP_ENTRIES] = { |
| 263 | [SMP_CKP_FE_CON_ACC] = "frontend tcp-request connection rule", |
| 264 | [SMP_CKP_FE_SES_ACC] = "frontend tcp-request session rule", |
| 265 | [SMP_CKP_FE_REQ_CNT] = "frontend tcp-request content rule", |
| 266 | [SMP_CKP_FE_HRQ_HDR] = "frontend http-request header rule", |
| 267 | [SMP_CKP_FE_HRQ_BDY] = "frontend http-request body rule", |
| 268 | [SMP_CKP_FE_SET_BCK] = "frontend use-backend rule", |
| 269 | [SMP_CKP_BE_REQ_CNT] = "backend tcp-request content rule", |
| 270 | [SMP_CKP_BE_HRQ_HDR] = "backend http-request header rule", |
| 271 | [SMP_CKP_BE_HRQ_BDY] = "backend http-request body rule", |
| 272 | [SMP_CKP_BE_SET_SRV] = "backend use-server, balance or stick-match rule", |
| 273 | [SMP_CKP_BE_SRV_CON] = "server source selection", |
| 274 | [SMP_CKP_BE_RES_CNT] = "backend tcp-response content rule", |
| 275 | [SMP_CKP_BE_HRS_HDR] = "backend http-response header rule", |
| 276 | [SMP_CKP_BE_HRS_BDY] = "backend http-response body rule", |
| 277 | [SMP_CKP_BE_STO_RUL] = "backend stick-store rule", |
| 278 | [SMP_CKP_FE_RES_CNT] = "frontend tcp-response content rule", |
| 279 | [SMP_CKP_FE_HRS_HDR] = "frontend http-response header rule", |
| 280 | [SMP_CKP_FE_HRS_BDY] = "frontend http-response body rule", |
| 281 | [SMP_CKP_FE_LOG_END] = "logs", |
| 282 | }; |
| 283 | |
Thierry FOURNIER | 348971e | 2013-11-21 10:50:10 +0100 | [diff] [blame] | 284 | /* This function returns the type of the data returned by the sample_expr. |
| 285 | * It assumes that the <expr> and all of its converters are properly |
| 286 | * initialized. |
| 287 | */ |
| 288 | inline |
| 289 | int smp_expr_output_type(struct sample_expr *expr) |
| 290 | { |
| 291 | struct sample_conv_expr *smp_expr; |
| 292 | |
| 293 | if (!LIST_ISEMPTY(&expr->conv_exprs)) { |
| 294 | smp_expr = LIST_PREV(&expr->conv_exprs, struct sample_conv_expr *, list); |
| 295 | return smp_expr->conv->out_type; |
| 296 | } |
| 297 | return expr->fetch->out_type; |
| 298 | } |
| 299 | |
| 300 | |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 301 | /* fill the trash with a comma-delimited list of source names for the <use> bit |
| 302 | * field which must be composed of a non-null set of SMP_USE_* flags. The return |
| 303 | * value is the pointer to the string in the trash buffer. |
| 304 | */ |
| 305 | const char *sample_src_names(unsigned int use) |
| 306 | { |
| 307 | int bit; |
| 308 | |
| 309 | trash.len = 0; |
| 310 | trash.str[0] = '\0'; |
| 311 | for (bit = 0; bit < SMP_SRC_ENTRIES; bit++) { |
| 312 | if (!(use & ~((1 << bit) - 1))) |
| 313 | break; /* no more bits */ |
| 314 | |
| 315 | if (!(use & (1 << bit))) |
| 316 | continue; /* bit not set */ |
| 317 | |
| 318 | trash.len += snprintf(trash.str + trash.len, trash.size - trash.len, "%s%s", |
| 319 | (use & ((1 << bit) - 1)) ? "," : "", |
| 320 | fetch_src_names[bit]); |
| 321 | } |
| 322 | return trash.str; |
| 323 | } |
| 324 | |
Willy Tarreau | bf8e251 | 2013-03-25 14:52:41 +0100 | [diff] [blame] | 325 | /* return a pointer to the correct sample checkpoint name, or "unknown" when |
| 326 | * the flags are invalid. Only the lowest bit is used, higher bits are ignored |
| 327 | * if set. |
| 328 | */ |
| 329 | const char *sample_ckp_names(unsigned int use) |
| 330 | { |
| 331 | int bit; |
| 332 | |
| 333 | for (bit = 0; bit < SMP_CKP_ENTRIES; bit++) |
| 334 | if (use & (1 << bit)) |
| 335 | return fetch_ckp_names[bit]; |
| 336 | return "unknown sample check place, please report this bug"; |
| 337 | } |
| 338 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 339 | /* |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 340 | * Registers the sample fetch keyword list <kwl> as a list of valid keywords |
| 341 | * for next parsing sessions. The fetch keywords capabilities are also computed |
| 342 | * from their ->use field. |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 343 | */ |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 344 | void sample_register_fetches(struct sample_fetch_kw_list *kwl) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 345 | { |
Willy Tarreau | 80aca90 | 2013-01-07 15:42:20 +0100 | [diff] [blame] | 346 | struct sample_fetch *sf; |
| 347 | int bit; |
| 348 | |
| 349 | for (sf = kwl->kw; sf->kw != NULL; sf++) { |
| 350 | for (bit = 0; bit < SMP_SRC_ENTRIES; bit++) |
| 351 | if (sf->use & (1 << bit)) |
| 352 | sf->val |= fetch_cap[bit]; |
| 353 | } |
| 354 | LIST_ADDQ(&sample_fetches.list, &kwl->list); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 358 | * Registers the sample format coverstion keyword list <pckl> as a list of valid keywords for next |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 359 | * parsing sessions. |
| 360 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 361 | void sample_register_convs(struct sample_conv_kw_list *pckl) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 362 | { |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 363 | LIST_ADDQ(&sample_convs.list, &pckl->list); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 367 | * Returns the pointer on sample fetch keyword structure identified by |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 368 | * string of <len> in buffer <kw>. |
| 369 | * |
| 370 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 371 | struct sample_fetch *find_sample_fetch(const char *kw, int len) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 372 | { |
| 373 | int index; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 374 | struct sample_fetch_kw_list *kwl; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 375 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 376 | list_for_each_entry(kwl, &sample_fetches.list, list) { |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 377 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 378 | if (strncmp(kwl->kw[index].kw, kw, len) == 0 && |
| 379 | kwl->kw[index].kw[len] == '\0') |
| 380 | return &kwl->kw[index]; |
| 381 | } |
| 382 | } |
| 383 | return NULL; |
| 384 | } |
| 385 | |
| 386 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 387 | * Returns the pointer on sample format conversion keyword structure identified by |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 388 | * string of <len> in buffer <kw>. |
| 389 | * |
| 390 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 391 | struct sample_conv *find_sample_conv(const char *kw, int len) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 392 | { |
| 393 | int index; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 394 | struct sample_conv_kw_list *kwl; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 395 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 396 | list_for_each_entry(kwl, &sample_convs.list, list) { |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 397 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 398 | if (strncmp(kwl->kw[index].kw, kw, len) == 0 && |
| 399 | kwl->kw[index].kw[len] == '\0') |
| 400 | return &kwl->kw[index]; |
| 401 | } |
| 402 | } |
| 403 | return NULL; |
| 404 | } |
| 405 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 406 | /******************************************************************/ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 407 | /* Sample casts functions */ |
Willy Tarreau | b8c8f1f | 2012-04-23 22:38:26 +0200 | [diff] [blame] | 408 | /* Note: these functions do *NOT* set the output type on the */ |
| 409 | /* sample, the caller is responsible for doing this on return. */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 410 | /******************************************************************/ |
| 411 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 412 | static int c_ip2int(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 413 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 414 | smp->data.uint = ntohl(smp->data.ipv4.s_addr); |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 415 | smp->type = SMP_T_UINT; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 416 | return 1; |
| 417 | } |
| 418 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 419 | static int c_ip2str(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 420 | { |
Willy Tarreau | 47ca545 | 2012-12-23 20:22:19 +0100 | [diff] [blame] | 421 | struct chunk *trash = get_trash_chunk(); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 422 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 423 | if (!inet_ntop(AF_INET, (void *)&smp->data.ipv4, trash->str, trash->size)) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 424 | return 0; |
| 425 | |
| 426 | trash->len = strlen(trash->str); |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 427 | smp->data.str = *trash; |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 428 | smp->type = SMP_T_STR; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 429 | smp->flags &= ~SMP_F_CONST; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 430 | |
| 431 | return 1; |
| 432 | } |
| 433 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 434 | static int c_ip2ipv6(struct sample *smp) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 435 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 436 | v4tov6(&smp->data.ipv6, &smp->data.ipv4); |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 437 | smp->type = SMP_T_IPV6; |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 438 | return 1; |
| 439 | } |
| 440 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 441 | static int c_ipv62str(struct sample *smp) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 442 | { |
Willy Tarreau | 47ca545 | 2012-12-23 20:22:19 +0100 | [diff] [blame] | 443 | struct chunk *trash = get_trash_chunk(); |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 444 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 445 | if (!inet_ntop(AF_INET6, (void *)&smp->data.ipv6, trash->str, trash->size)) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 446 | return 0; |
| 447 | |
| 448 | trash->len = strlen(trash->str); |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 449 | smp->data.str = *trash; |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 450 | smp->type = SMP_T_STR; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 451 | smp->flags &= ~SMP_F_CONST; |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 452 | return 1; |
| 453 | } |
| 454 | |
| 455 | /* |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 456 | static int c_ipv62ip(struct sample *smp) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 457 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 458 | return v6tov4(&smp->data.ipv4, &smp->data.ipv6); |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 459 | } |
| 460 | */ |
| 461 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 462 | static int c_int2ip(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 463 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 464 | smp->data.ipv4.s_addr = htonl(smp->data.uint); |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 465 | smp->type = SMP_T_IPV4; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 466 | return 1; |
| 467 | } |
| 468 | |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 469 | static int c_str2addr(struct sample *smp) |
| 470 | { |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 471 | if (!buf2ip(smp->data.str.str, smp->data.str.len, &smp->data.ipv4)) { |
Thierry FOURNIER | fd13990 | 2013-12-11 12:38:57 +0100 | [diff] [blame] | 472 | if (!buf2ip6(smp->data.str.str, smp->data.str.len, &smp->data.ipv6)) |
| 473 | return 0; |
| 474 | smp->type = SMP_T_IPV6; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 475 | smp->flags &= ~SMP_F_CONST; |
Thierry FOURNIER | fd13990 | 2013-12-11 12:38:57 +0100 | [diff] [blame] | 476 | return 1; |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 477 | } |
| 478 | smp->type = SMP_T_IPV4; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 479 | smp->flags &= ~SMP_F_CONST; |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 480 | return 1; |
| 481 | } |
| 482 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 483 | static int c_str2ip(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 484 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 485 | if (!buf2ip(smp->data.str.str, smp->data.str.len, &smp->data.ipv4)) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 486 | return 0; |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 487 | smp->type = SMP_T_IPV4; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 488 | smp->flags &= ~SMP_F_CONST; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 489 | return 1; |
| 490 | } |
| 491 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 492 | static int c_str2ipv6(struct sample *smp) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 493 | { |
Thierry FOURNIER | fd13990 | 2013-12-11 12:38:57 +0100 | [diff] [blame] | 494 | if (!buf2ip6(smp->data.str.str, smp->data.str.len, &smp->data.ipv6)) |
| 495 | return 0; |
| 496 | smp->type = SMP_T_IPV6; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 497 | smp->flags &= ~SMP_F_CONST; |
Thierry FOURNIER | fd13990 | 2013-12-11 12:38:57 +0100 | [diff] [blame] | 498 | return 1; |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 499 | } |
| 500 | |
Thierry FOURNIER | e87cac1 | 2014-03-12 15:07:59 +0100 | [diff] [blame] | 501 | /* The sample is always copied into a new one so that smp->size is always |
| 502 | * valid. The NULL char always enforces the end of string if it is met. |
| 503 | */ |
Emeric Brun | 8ac33d9 | 2012-10-17 13:36:06 +0200 | [diff] [blame] | 504 | static int c_bin2str(struct sample *smp) |
| 505 | { |
Willy Tarreau | 47ca545 | 2012-12-23 20:22:19 +0100 | [diff] [blame] | 506 | struct chunk *trash = get_trash_chunk(); |
Emeric Brun | 8ac33d9 | 2012-10-17 13:36:06 +0200 | [diff] [blame] | 507 | unsigned char c; |
| 508 | int ptr = 0; |
| 509 | |
Thierry FOURNIER | e87cac1 | 2014-03-12 15:07:59 +0100 | [diff] [blame] | 510 | while (ptr < smp->data.str.len) { |
| 511 | c = smp->data.str.str[ptr]; |
| 512 | if (!c) |
| 513 | break; |
| 514 | trash->str[ptr] = c; |
| 515 | ptr++; |
Emeric Brun | 8ac33d9 | 2012-10-17 13:36:06 +0200 | [diff] [blame] | 516 | } |
Thierry FOURNIER | e87cac1 | 2014-03-12 15:07:59 +0100 | [diff] [blame] | 517 | trash->len = ptr; |
| 518 | trash->str[ptr] = 0; |
Emeric Brun | 8ac33d9 | 2012-10-17 13:36:06 +0200 | [diff] [blame] | 519 | smp->data.str = *trash; |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 520 | smp->type = SMP_T_STR; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 521 | smp->flags &= ~SMP_F_CONST; |
Emeric Brun | 8ac33d9 | 2012-10-17 13:36:06 +0200 | [diff] [blame] | 522 | return 1; |
| 523 | } |
| 524 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 525 | static int c_int2str(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 526 | { |
Willy Tarreau | 47ca545 | 2012-12-23 20:22:19 +0100 | [diff] [blame] | 527 | struct chunk *trash = get_trash_chunk(); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 528 | char *pos; |
| 529 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 530 | pos = ultoa_r(smp->data.uint, trash->str, trash->size); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 531 | |
| 532 | if (!pos) |
| 533 | return 0; |
| 534 | |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 535 | trash->size = trash->size - (pos - trash->str); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 536 | trash->str = pos; |
| 537 | trash->len = strlen(pos); |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 538 | smp->data.str = *trash; |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 539 | smp->type = SMP_T_STR; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 540 | smp->flags &= ~SMP_F_CONST; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 541 | return 1; |
| 542 | } |
| 543 | |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 544 | /* This function duplicates data and removes the flag "const". */ |
| 545 | int smp_dup(struct sample *smp) |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 546 | { |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 547 | struct chunk *trash; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 548 | |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 549 | /* If the const flag is not set, we don't need to duplicate the |
| 550 | * pattern as it can be modified in place. |
| 551 | */ |
| 552 | if (!(smp->flags & SMP_F_CONST)) |
| 553 | return 1; |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 554 | |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 555 | switch (smp->type) { |
| 556 | case SMP_T_BOOL: |
| 557 | case SMP_T_UINT: |
| 558 | case SMP_T_SINT: |
| 559 | case SMP_T_ADDR: |
| 560 | case SMP_T_IPV4: |
| 561 | case SMP_T_IPV6: |
| 562 | /* These type are not const. */ |
| 563 | break; |
| 564 | case SMP_T_STR: |
| 565 | case SMP_T_BIN: |
| 566 | /* Duplicate data. */ |
| 567 | trash = get_trash_chunk(); |
| 568 | trash->len = smp->data.str.len < trash->size ? smp->data.str.len : trash->size; |
| 569 | memcpy(trash->str, smp->data.str.str, trash->len); |
| 570 | smp->data.str = *trash; |
| 571 | break; |
| 572 | default: |
| 573 | /* Other cases are unexpected. */ |
| 574 | return 0; |
| 575 | } |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 576 | |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 577 | /* remove const flag */ |
| 578 | smp->flags &= ~SMP_F_CONST; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 579 | return 1; |
| 580 | } |
| 581 | |
Thierry FOURNIER | 0e9af55 | 2013-12-14 14:55:04 +0100 | [diff] [blame] | 582 | int c_none(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 583 | { |
| 584 | return 1; |
| 585 | } |
| 586 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 587 | static int c_str2int(struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 588 | { |
| 589 | int i; |
| 590 | uint32_t ret = 0; |
| 591 | |
Thierry FOURNIER | 60bb020 | 2014-01-27 18:20:48 +0100 | [diff] [blame] | 592 | if (smp->data.str.len == 0) |
| 593 | return 0; |
| 594 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 595 | for (i = 0; i < smp->data.str.len; i++) { |
| 596 | uint32_t val = smp->data.str.str[i] - '0'; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 597 | |
Thierry FOURNIER | 60bb020 | 2014-01-27 18:20:48 +0100 | [diff] [blame] | 598 | if (val > 9) { |
| 599 | if (i == 0) |
| 600 | return 0; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 601 | break; |
Thierry FOURNIER | 60bb020 | 2014-01-27 18:20:48 +0100 | [diff] [blame] | 602 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 603 | |
| 604 | ret = ret * 10 + val; |
| 605 | } |
| 606 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 607 | smp->data.uint = ret; |
Thierry FOURNIER | b805f71 | 2013-11-26 20:47:54 +0100 | [diff] [blame] | 608 | smp->type = SMP_T_UINT; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 609 | smp->flags &= ~SMP_F_CONST; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 610 | return 1; |
| 611 | } |
| 612 | |
Thierry FOURNIER | d437314 | 2013-12-17 01:10:10 +0100 | [diff] [blame] | 613 | static int c_str2meth(struct sample *smp) |
| 614 | { |
| 615 | enum http_meth_t meth; |
| 616 | int len; |
| 617 | |
| 618 | meth = find_http_meth(smp->data.str.str, smp->data.str.len); |
| 619 | if (meth == HTTP_METH_OTHER) { |
| 620 | len = smp->data.str.len; |
| 621 | smp->data.meth.str.str = smp->data.str.str; |
| 622 | smp->data.meth.str.len = len; |
| 623 | } |
| 624 | else |
| 625 | smp->flags &= ~SMP_F_CONST; |
| 626 | smp->data.meth.meth = meth; |
| 627 | smp->type = SMP_T_METH; |
| 628 | return 1; |
| 629 | } |
| 630 | |
| 631 | static int c_meth2str(struct sample *smp) |
| 632 | { |
| 633 | int len; |
| 634 | enum http_meth_t meth; |
| 635 | |
| 636 | if (smp->data.meth.meth == HTTP_METH_OTHER) { |
| 637 | /* The method is unknown. Copy the original pointer. */ |
| 638 | len = smp->data.meth.str.len; |
| 639 | smp->data.str.str = smp->data.meth.str.str; |
| 640 | smp->data.str.len = len; |
| 641 | smp->type = SMP_T_STR; |
| 642 | } |
| 643 | else if (smp->data.meth.meth < HTTP_METH_OTHER) { |
| 644 | /* The method is known, copy the pointer containing the string. */ |
| 645 | meth = smp->data.meth.meth; |
| 646 | smp->data.str.str = http_known_methods[meth].name; |
| 647 | smp->data.str.len = http_known_methods[meth].len; |
| 648 | smp->flags |= SMP_F_CONST; |
| 649 | smp->type = SMP_T_STR; |
| 650 | } |
| 651 | else { |
| 652 | /* Unknown method */ |
| 653 | return 0; |
| 654 | } |
| 655 | return 1; |
| 656 | } |
| 657 | |
Willy Tarreau | 9700e5c | 2014-07-15 21:03:26 +0200 | [diff] [blame] | 658 | static int c_addr2bin(struct sample *smp) |
| 659 | { |
| 660 | struct chunk *chk = get_trash_chunk(); |
| 661 | |
| 662 | if (smp->type == SMP_T_IPV4) { |
| 663 | chk->len = 4; |
| 664 | memcpy(chk->str, &smp->data.ipv4, chk->len); |
| 665 | } |
| 666 | else if (smp->type == SMP_T_IPV6) { |
| 667 | chk->len = 16; |
| 668 | memcpy(chk->str, &smp->data.ipv6, chk->len); |
| 669 | } |
| 670 | else |
| 671 | return 0; |
| 672 | |
| 673 | smp->data.str = *chk; |
| 674 | smp->type = SMP_T_BIN; |
| 675 | return 1; |
| 676 | } |
| 677 | |
Willy Tarreau | bbfd1a2 | 2014-07-15 21:19:08 +0200 | [diff] [blame] | 678 | static int c_int2bin(struct sample *smp) |
| 679 | { |
| 680 | struct chunk *chk = get_trash_chunk(); |
| 681 | |
| 682 | *(unsigned int *)chk->str = htonl(smp->data.uint); |
| 683 | chk->len = 4; |
| 684 | |
| 685 | smp->data.str = *chk; |
| 686 | smp->type = SMP_T_BIN; |
| 687 | return 1; |
| 688 | } |
| 689 | |
Willy Tarreau | 9700e5c | 2014-07-15 21:03:26 +0200 | [diff] [blame] | 690 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 691 | /*****************************************************************/ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 692 | /* Sample casts matrix: */ |
| 693 | /* sample_casts[from type][to type] */ |
| 694 | /* NULL pointer used for impossible sample casts */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 695 | /*****************************************************************/ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 696 | |
Thierry FOURNIER | 8af6ff1 | 2013-11-21 10:53:12 +0100 | [diff] [blame] | 697 | sample_cast_fct sample_casts[SMP_TYPES][SMP_TYPES] = { |
Thierry FOURNIER | d437314 | 2013-12-17 01:10:10 +0100 | [diff] [blame] | 698 | /* to: BOOL UINT SINT ADDR IPV4 IPV6 STR BIN METH */ |
| 699 | /* from: BOOL */ { c_none, c_none, c_none, NULL, NULL, NULL, c_int2str, NULL, NULL, }, |
Willy Tarreau | bbfd1a2 | 2014-07-15 21:19:08 +0200 | [diff] [blame] | 700 | /* UINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, NULL, c_int2str, c_int2bin, NULL, }, |
| 701 | /* SINT */ { c_none, c_none, c_none, c_int2ip, c_int2ip, NULL, c_int2str, c_int2bin, NULL, }, |
Thierry FOURNIER | d437314 | 2013-12-17 01:10:10 +0100 | [diff] [blame] | 702 | /* ADDR */ { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }, |
Willy Tarreau | 9700e5c | 2014-07-15 21:03:26 +0200 | [diff] [blame] | 703 | /* IPV4 */ { NULL, c_ip2int, c_ip2int, c_none, c_none, c_ip2ipv6, c_ip2str, c_addr2bin, NULL, }, |
| 704 | /* IPV6 */ { NULL, NULL, NULL, c_none, NULL, c_none, c_ipv62str, c_addr2bin, NULL, }, |
Thierry FOURNIER | d437314 | 2013-12-17 01:10:10 +0100 | [diff] [blame] | 705 | /* STR */ { c_str2int, c_str2int, c_str2int, c_str2addr, c_str2ip, c_str2ipv6, c_none, c_none, c_str2meth, }, |
| 706 | /* BIN */ { NULL, NULL, NULL, NULL, NULL, NULL, c_bin2str, c_none, c_str2meth, }, |
| 707 | /* METH */ { NULL, NULL, NULL, NULL, NULL, NULL, c_meth2str, c_meth2str, c_none, }, |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 708 | }; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 709 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 710 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 711 | * Parse a sample expression configuration: |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 712 | * fetch keyword followed by format conversion keywords. |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 713 | * Returns a pointer on allocated sample expression structure. |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 714 | * The caller must have set al->ctx. |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 715 | */ |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 716 | struct sample_expr *sample_parse_expr(char **str, int *idx, const char *file, int line, char **err_msg, struct arg_list *al) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 717 | { |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 718 | const char *begw; /* beginning of word */ |
| 719 | const char *endw; /* end of word */ |
| 720 | const char *endt; /* end of term */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 721 | struct sample_expr *expr; |
| 722 | struct sample_fetch *fetch; |
| 723 | struct sample_conv *conv; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 724 | unsigned long prev_type; |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 725 | char *fkw = NULL; |
| 726 | char *ckw = NULL; |
Willy Tarreau | 689a1df | 2013-12-13 00:40:11 +0100 | [diff] [blame] | 727 | int err_arg; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 728 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 729 | begw = str[*idx]; |
| 730 | for (endw = begw; *endw && *endw != '(' && *endw != ','; endw++); |
| 731 | |
| 732 | if (endw == begw) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 733 | memprintf(err_msg, "missing fetch method"); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 734 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 735 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 736 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 737 | /* keep a copy of the current fetch keyword for error reporting */ |
| 738 | fkw = my_strndup(begw, endw - begw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 739 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 740 | fetch = find_sample_fetch(begw, endw - begw); |
| 741 | if (!fetch) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 742 | memprintf(err_msg, "unknown fetch method '%s'", fkw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 743 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 744 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 745 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 746 | endt = endw; |
| 747 | if (*endt == '(') { |
Willy Tarreau | 689a1df | 2013-12-13 00:40:11 +0100 | [diff] [blame] | 748 | /* look for the end of this term and skip the opening parenthesis */ |
| 749 | endt = ++endw; |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 750 | while (*endt && *endt != ')') |
| 751 | endt++; |
| 752 | if (*endt != ')') { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 753 | memprintf(err_msg, "missing closing ')' after arguments to fetch keyword '%s'", fkw); |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 754 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 755 | } |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 756 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 757 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 758 | /* At this point, we have : |
| 759 | * - begw : beginning of the keyword |
Willy Tarreau | 689a1df | 2013-12-13 00:40:11 +0100 | [diff] [blame] | 760 | * - endw : end of the keyword, first character not part of keyword |
| 761 | * nor the opening parenthesis (so first character of args |
| 762 | * if present). |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 763 | * - endt : end of the term (=endw or last parenthesis if args are present) |
| 764 | */ |
| 765 | |
| 766 | if (fetch->out_type >= SMP_TYPES) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 767 | memprintf(err_msg, "returns type of fetch method '%s' is unknown", fkw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 768 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 769 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 770 | prev_type = fetch->out_type; |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 771 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 772 | expr = calloc(1, sizeof(struct sample_expr)); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 773 | if (!expr) |
| 774 | goto out_error; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 775 | |
| 776 | LIST_INIT(&(expr->conv_exprs)); |
| 777 | expr->fetch = fetch; |
Willy Tarreau | 2e845be | 2012-10-19 19:49:09 +0200 | [diff] [blame] | 778 | expr->arg_p = empty_arg_list; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 779 | |
Willy Tarreau | 689a1df | 2013-12-13 00:40:11 +0100 | [diff] [blame] | 780 | /* Note that we call the argument parser even with an empty string, |
| 781 | * this allows it to automatically create entries for mandatory |
| 782 | * implicit arguments (eg: local proxy name). |
| 783 | */ |
| 784 | al->kw = expr->fetch->kw; |
| 785 | al->conv = NULL; |
| 786 | if (make_arg_list(endw, endt - endw, fetch->arg_mask, &expr->arg_p, err_msg, NULL, &err_arg, al) < 0) { |
| 787 | memprintf(err_msg, "fetch method '%s' : %s", fkw, *err_msg); |
| 788 | goto out_error; |
| 789 | } |
Willy Tarreau | 2e845be | 2012-10-19 19:49:09 +0200 | [diff] [blame] | 790 | |
Willy Tarreau | 689a1df | 2013-12-13 00:40:11 +0100 | [diff] [blame] | 791 | if (!expr->arg_p) { |
| 792 | expr->arg_p = empty_arg_list; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 793 | } |
Willy Tarreau | 689a1df | 2013-12-13 00:40:11 +0100 | [diff] [blame] | 794 | else if (fetch->val_args && !fetch->val_args(expr->arg_p, err_msg)) { |
| 795 | memprintf(err_msg, "invalid args in fetch method '%s' : %s", fkw, *err_msg); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 796 | goto out_error; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 797 | } |
| 798 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 799 | /* Now process the converters if any. We have two supported syntaxes |
| 800 | * for the converters, which can be combined : |
| 801 | * - comma-delimited list of converters just after the keyword and args ; |
| 802 | * - one converter per keyword |
| 803 | * The combination allows to have each keyword being a comma-delimited |
| 804 | * series of converters. |
| 805 | * |
| 806 | * We want to process the former first, then the latter. For this we start |
| 807 | * from the beginning of the supposed place in the exiting conv chain, which |
| 808 | * starts at the last comma (endt). |
| 809 | */ |
| 810 | |
| 811 | while (1) { |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 812 | struct sample_conv_expr *conv_expr; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 813 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 814 | if (*endt == ')') /* skip last closing parenthesis */ |
| 815 | endt++; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 816 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 817 | if (*endt && *endt != ',') { |
| 818 | if (ckw) |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 819 | memprintf(err_msg, "missing comma after conv keyword '%s'", ckw); |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 820 | else |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 821 | memprintf(err_msg, "missing comma after fetch keyword '%s'", fkw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 822 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 823 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 824 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 825 | while (*endt == ',') /* then trailing commas */ |
| 826 | endt++; |
| 827 | |
| 828 | begw = endt; /* start of conv keyword */ |
| 829 | |
| 830 | if (!*begw) { |
| 831 | /* none ? skip to next string */ |
| 832 | (*idx)++; |
| 833 | begw = str[*idx]; |
| 834 | if (!begw || !*begw) |
| 835 | break; |
| 836 | } |
| 837 | |
| 838 | for (endw = begw; *endw && *endw != '(' && *endw != ','; endw++); |
| 839 | |
| 840 | free(ckw); |
| 841 | ckw = my_strndup(begw, endw - begw); |
| 842 | |
| 843 | conv = find_sample_conv(begw, endw - begw); |
| 844 | if (!conv) { |
| 845 | /* we found an isolated keyword that we don't know, it's not ours */ |
| 846 | if (begw == str[*idx]) |
| 847 | break; |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 848 | memprintf(err_msg, "unknown conv method '%s'", ckw); |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 849 | goto out_error; |
| 850 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 851 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 852 | endt = endw; |
| 853 | if (*endt == '(') { |
| 854 | /* look for the end of this term */ |
| 855 | while (*endt && *endt != ')') |
| 856 | endt++; |
| 857 | if (*endt != ')') { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 858 | memprintf(err_msg, "syntax error: missing ')' after conv keyword '%s'", ckw); |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 859 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 860 | } |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | if (conv->in_type >= SMP_TYPES || conv->out_type >= SMP_TYPES) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 864 | memprintf(err_msg, "returns type of conv method '%s' is unknown", ckw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 865 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 866 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 867 | |
| 868 | /* If impossible type conversion */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 869 | if (!sample_casts[prev_type][conv->in_type]) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 870 | memprintf(err_msg, "conv method '%s' cannot be applied", ckw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 871 | goto out_error; |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 872 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 873 | |
| 874 | prev_type = conv->out_type; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 875 | conv_expr = calloc(1, sizeof(struct sample_conv_expr)); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 876 | if (!conv_expr) |
| 877 | goto out_error; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 878 | |
| 879 | LIST_ADDQ(&(expr->conv_exprs), &(conv_expr->list)); |
| 880 | conv_expr->conv = conv; |
| 881 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 882 | if (endt != endw) { |
Willy Tarreau | b27c0d3 | 2012-04-20 16:04:47 +0200 | [diff] [blame] | 883 | int err_arg; |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 884 | |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 885 | if (!conv->arg_mask) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 886 | memprintf(err_msg, "conv method '%s' does not support any args", ckw); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 887 | goto out_error; |
| 888 | } |
Willy Tarreau | 9e92d32 | 2010-01-26 17:58:06 +0100 | [diff] [blame] | 889 | |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 890 | al->kw = expr->fetch->kw; |
| 891 | al->conv = conv_expr->conv->kw; |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 892 | if (make_arg_list(endw + 1, endt - endw - 1, conv->arg_mask, &conv_expr->arg_p, err_msg, NULL, &err_arg, al) < 0) { |
| 893 | memprintf(err_msg, "invalid arg %d in conv method '%s' : %s", err_arg+1, ckw, *err_msg); |
Willy Tarreau | 21d68a6 | 2012-04-20 15:52:36 +0200 | [diff] [blame] | 894 | goto out_error; |
| 895 | } |
| 896 | |
Willy Tarreau | 2e845be | 2012-10-19 19:49:09 +0200 | [diff] [blame] | 897 | if (!conv_expr->arg_p) |
| 898 | conv_expr->arg_p = empty_arg_list; |
| 899 | |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 900 | if (conv->val_args && !conv->val_args(conv_expr->arg_p, conv, file, line, err_msg)) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 901 | memprintf(err_msg, "invalid args in conv method '%s' : %s", ckw, *err_msg); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 902 | goto out_error; |
| 903 | } |
| 904 | } |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 905 | else if (ARGM(conv->arg_mask)) { |
Willy Tarreau | 975c178 | 2013-12-12 23:16:54 +0100 | [diff] [blame] | 906 | memprintf(err_msg, "missing args for conv method '%s'", ckw); |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 907 | goto out_error; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 908 | } |
| 909 | } |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 910 | |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 911 | out: |
| 912 | free(fkw); |
| 913 | free(ckw); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 914 | return expr; |
| 915 | |
| 916 | out_error: |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 917 | /* TODO: prune_sample_expr(expr); */ |
Willy Tarreau | 833cc79 | 2013-07-24 15:34:19 +0200 | [diff] [blame] | 918 | expr = NULL; |
| 919 | goto out; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | /* |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 923 | * Process a fetch + format conversion of defined by the sample expression <expr> |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 924 | * on request or response considering the <opt> parameter. |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 925 | * Returns a pointer on a typed sample structure containing the result or NULL if |
| 926 | * sample is not found or when format conversion failed. |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 927 | * If <p> is not null, function returns results in structure pointed by <p>. |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 928 | * If <p> is null, functions returns a pointer on a static sample structure. |
Willy Tarreau | b8c8f1f | 2012-04-23 22:38:26 +0200 | [diff] [blame] | 929 | * |
| 930 | * Note: the fetch functions are required to properly set the return type. The |
| 931 | * conversion functions must do so too. However the cast functions do not need |
| 932 | * to since they're made to cast mutiple types according to what is required. |
Willy Tarreau | 6bcb0a8 | 2014-07-30 08:56:35 +0200 | [diff] [blame] | 933 | * |
| 934 | * The caller may indicate in <opt> if it considers the result final or not. |
| 935 | * The caller needs to check the SMP_F_MAY_CHANGE flag in p->flags to verify |
| 936 | * if the result is stable or not, according to the following table : |
| 937 | * |
| 938 | * return MAY_CHANGE FINAL Meaning for the sample |
| 939 | * NULL 0 * Not present and will never be (eg: header) |
| 940 | * NULL 1 0 Not present yet, could change (eg: POST param) |
| 941 | * NULL 1 1 Not present yet, will not change anymore |
| 942 | * smp 0 * Present and will not change (eg: header) |
| 943 | * smp 1 0 Present, may change (eg: request length) |
| 944 | * smp 1 1 Present, last known value (eg: request length) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 945 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 946 | struct sample *sample_process(struct proxy *px, struct session *l4, void *l7, |
| 947 | unsigned int opt, |
| 948 | struct sample_expr *expr, struct sample *p) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 949 | { |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 950 | struct sample_conv_expr *conv_expr; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 951 | |
Willy Tarreau | 18387e2 | 2013-07-25 12:02:38 +0200 | [diff] [blame] | 952 | if (p == NULL) { |
Willy Tarreau | b4a88f0 | 2012-04-23 21:35:11 +0200 | [diff] [blame] | 953 | p = &temp_smp; |
Willy Tarreau | 6c616e0 | 2014-06-25 16:56:41 +0200 | [diff] [blame] | 954 | memset(p, 0, sizeof(*p)); |
Willy Tarreau | 18387e2 | 2013-07-25 12:02:38 +0200 | [diff] [blame] | 955 | } |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 956 | |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame] | 957 | if (!expr->fetch->process(px, l4, l7, opt, expr->arg_p, p, expr->fetch->kw)) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 958 | return NULL; |
| 959 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 960 | list_for_each_entry(conv_expr, &expr->conv_exprs, list) { |
Willy Tarreau | 12e5011 | 2012-04-25 17:21:49 +0200 | [diff] [blame] | 961 | /* we want to ensure that p->type can be casted into |
| 962 | * conv_expr->conv->in_type. We have 3 possibilities : |
| 963 | * - NULL => not castable. |
| 964 | * - c_none => nothing to do (let's optimize it) |
| 965 | * - other => apply cast and prepare to fail |
| 966 | */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 967 | if (!sample_casts[p->type][conv_expr->conv->in_type]) |
Willy Tarreau | 12e5011 | 2012-04-25 17:21:49 +0200 | [diff] [blame] | 968 | return NULL; |
| 969 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 970 | if (sample_casts[p->type][conv_expr->conv->in_type] != c_none && |
| 971 | !sample_casts[p->type][conv_expr->conv->in_type](p)) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 972 | return NULL; |
| 973 | |
Willy Tarreau | 12e5011 | 2012-04-25 17:21:49 +0200 | [diff] [blame] | 974 | /* OK cast succeeded */ |
| 975 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 976 | if (!conv_expr->conv->process(conv_expr->arg_p, p)) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 977 | return NULL; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 978 | } |
| 979 | return p; |
| 980 | } |
| 981 | |
Willy Tarreau | e7ad4bb | 2012-12-21 00:02:32 +0100 | [diff] [blame] | 982 | /* |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 983 | * Resolve all remaining arguments in proxy <p>. Returns the number of |
| 984 | * errors or 0 if everything is fine. |
| 985 | */ |
| 986 | int smp_resolve_args(struct proxy *p) |
| 987 | { |
| 988 | struct arg_list *cur, *bak; |
| 989 | const char *ctx, *where; |
| 990 | const char *conv_ctx, *conv_pre, *conv_pos; |
| 991 | struct userlist *ul; |
| 992 | struct arg *arg; |
| 993 | int cfgerr = 0; |
| 994 | |
| 995 | list_for_each_entry_safe(cur, bak, &p->conf.args.list, list) { |
| 996 | struct proxy *px; |
| 997 | struct server *srv; |
| 998 | char *pname, *sname; |
| 999 | |
| 1000 | arg = cur->arg; |
| 1001 | |
| 1002 | /* prepare output messages */ |
| 1003 | conv_pre = conv_pos = conv_ctx = ""; |
| 1004 | if (cur->conv) { |
| 1005 | conv_ctx = cur->conv; |
| 1006 | conv_pre = "conversion keyword '"; |
| 1007 | conv_pos = "' for "; |
| 1008 | } |
| 1009 | |
| 1010 | where = "in"; |
| 1011 | ctx = "sample fetch keyword"; |
| 1012 | switch (cur->ctx) { |
| 1013 | case ARGC_STK:where = "in stick rule in"; break; |
| 1014 | case ARGC_TRK: where = "in tracking rule in"; break; |
| 1015 | case ARGC_LOG: where = "in log-format string in"; break; |
Thierry FOURNIER | 1c0054f | 2013-11-20 15:09:52 +0100 | [diff] [blame] | 1016 | case ARGC_HRQ: where = "in http-request header format string in"; break; |
| 1017 | case ARGC_HRS: where = "in http-response header format string in"; break; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1018 | case ARGC_UIF: where = "in unique-id-format string in"; break; |
Thierry FOURNIER | d18cd0f | 2013-11-29 12:15:45 +0100 | [diff] [blame] | 1019 | case ARGC_RDR: where = "in redirect format string in"; break; |
Willy Tarreau | 3a4ac42 | 2014-06-13 16:17:14 +0200 | [diff] [blame] | 1020 | case ARGC_CAP: where = "in capture rule in"; break; |
Willy Tarreau | a4312fa | 2013-04-02 16:34:32 +0200 | [diff] [blame] | 1021 | case ARGC_ACL: ctx = "ACL keyword"; break; |
| 1022 | } |
| 1023 | |
| 1024 | /* set a few default settings */ |
| 1025 | px = p; |
| 1026 | pname = p->id; |
| 1027 | |
| 1028 | switch (arg->type) { |
| 1029 | case ARGT_SRV: |
| 1030 | if (!arg->data.str.len) { |
| 1031 | Alert("parsing [%s:%d] : missing server name in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 1032 | cur->file, cur->line, |
| 1033 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 1034 | cfgerr++; |
| 1035 | continue; |
| 1036 | } |
| 1037 | |
| 1038 | /* we support two formats : "bck/srv" and "srv" */ |
| 1039 | sname = strrchr(arg->data.str.str, '/'); |
| 1040 | |
| 1041 | if (sname) { |
| 1042 | *sname++ = '\0'; |
| 1043 | pname = arg->data.str.str; |
| 1044 | |
| 1045 | px = findproxy(pname, PR_CAP_BE); |
| 1046 | if (!px) { |
| 1047 | Alert("parsing [%s:%d] : unable to find proxy '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 1048 | cur->file, cur->line, pname, |
| 1049 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 1050 | cfgerr++; |
| 1051 | break; |
| 1052 | } |
| 1053 | } |
| 1054 | else |
| 1055 | sname = arg->data.str.str; |
| 1056 | |
| 1057 | srv = findserver(px, sname); |
| 1058 | if (!srv) { |
| 1059 | Alert("parsing [%s:%d] : unable to find server '%s' in proxy '%s', referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 1060 | cur->file, cur->line, sname, pname, |
| 1061 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 1062 | cfgerr++; |
| 1063 | break; |
| 1064 | } |
| 1065 | |
| 1066 | free(arg->data.str.str); |
| 1067 | arg->data.str.str = NULL; |
| 1068 | arg->unresolved = 0; |
| 1069 | arg->data.srv = srv; |
| 1070 | break; |
| 1071 | |
| 1072 | case ARGT_FE: |
| 1073 | if (arg->data.str.len) { |
| 1074 | pname = arg->data.str.str; |
| 1075 | px = findproxy(pname, PR_CAP_FE); |
| 1076 | } |
| 1077 | |
| 1078 | if (!px) { |
| 1079 | Alert("parsing [%s:%d] : unable to find frontend '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 1080 | cur->file, cur->line, pname, |
| 1081 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 1082 | cfgerr++; |
| 1083 | break; |
| 1084 | } |
| 1085 | |
| 1086 | if (!(px->cap & PR_CAP_FE)) { |
| 1087 | Alert("parsing [%s:%d] : proxy '%s', referenced in arg %d of %s%s%s%s '%s' %s proxy '%s', has not frontend capability.\n", |
| 1088 | cur->file, cur->line, pname, |
| 1089 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 1090 | cfgerr++; |
| 1091 | break; |
| 1092 | } |
| 1093 | |
| 1094 | free(arg->data.str.str); |
| 1095 | arg->data.str.str = NULL; |
| 1096 | arg->unresolved = 0; |
| 1097 | arg->data.prx = px; |
| 1098 | break; |
| 1099 | |
| 1100 | case ARGT_BE: |
| 1101 | if (arg->data.str.len) { |
| 1102 | pname = arg->data.str.str; |
| 1103 | px = findproxy(pname, PR_CAP_BE); |
| 1104 | } |
| 1105 | |
| 1106 | if (!px) { |
| 1107 | Alert("parsing [%s:%d] : unable to find backend '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 1108 | cur->file, cur->line, pname, |
| 1109 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 1110 | cfgerr++; |
| 1111 | break; |
| 1112 | } |
| 1113 | |
| 1114 | if (!(px->cap & PR_CAP_BE)) { |
| 1115 | Alert("parsing [%s:%d] : proxy '%s', referenced in arg %d of %s%s%s%s '%s' %s proxy '%s', has not backend capability.\n", |
| 1116 | cur->file, cur->line, pname, |
| 1117 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 1118 | cfgerr++; |
| 1119 | break; |
| 1120 | } |
| 1121 | |
| 1122 | free(arg->data.str.str); |
| 1123 | arg->data.str.str = NULL; |
| 1124 | arg->unresolved = 0; |
| 1125 | arg->data.prx = px; |
| 1126 | break; |
| 1127 | |
| 1128 | case ARGT_TAB: |
| 1129 | if (arg->data.str.len) { |
| 1130 | pname = arg->data.str.str; |
| 1131 | px = find_stktable(pname); |
| 1132 | } |
| 1133 | |
| 1134 | if (!px) { |
| 1135 | Alert("parsing [%s:%d] : unable to find table '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 1136 | cur->file, cur->line, pname, |
| 1137 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 1138 | cfgerr++; |
| 1139 | break; |
| 1140 | } |
| 1141 | |
| 1142 | if (!px->table.size) { |
| 1143 | Alert("parsing [%s:%d] : no table in proxy '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 1144 | cur->file, cur->line, pname, |
| 1145 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 1146 | cfgerr++; |
| 1147 | break; |
| 1148 | } |
| 1149 | |
| 1150 | free(arg->data.str.str); |
| 1151 | arg->data.str.str = NULL; |
| 1152 | arg->unresolved = 0; |
| 1153 | arg->data.prx = px; |
| 1154 | break; |
| 1155 | |
| 1156 | case ARGT_USR: |
| 1157 | if (!arg->data.str.len) { |
| 1158 | Alert("parsing [%s:%d] : missing userlist name in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 1159 | cur->file, cur->line, |
| 1160 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 1161 | cfgerr++; |
| 1162 | break; |
| 1163 | } |
| 1164 | |
| 1165 | if (p->uri_auth && p->uri_auth->userlist && |
| 1166 | !strcmp(p->uri_auth->userlist->name, arg->data.str.str)) |
| 1167 | ul = p->uri_auth->userlist; |
| 1168 | else |
| 1169 | ul = auth_find_userlist(arg->data.str.str); |
| 1170 | |
| 1171 | if (!ul) { |
| 1172 | Alert("parsing [%s:%d] : unable to find userlist '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n", |
| 1173 | cur->file, cur->line, arg->data.str.str, |
| 1174 | cur->arg_pos + 1, conv_pre, conv_ctx, conv_pos, ctx, cur->kw, where, p->id); |
| 1175 | cfgerr++; |
| 1176 | break; |
| 1177 | } |
| 1178 | |
| 1179 | free(arg->data.str.str); |
| 1180 | arg->data.str.str = NULL; |
| 1181 | arg->unresolved = 0; |
| 1182 | arg->data.usr = ul; |
| 1183 | break; |
| 1184 | } |
| 1185 | |
| 1186 | LIST_DEL(&cur->list); |
| 1187 | free(cur); |
| 1188 | } /* end of args processing */ |
| 1189 | |
| 1190 | return cfgerr; |
| 1191 | } |
| 1192 | |
| 1193 | /* |
Willy Tarreau | 5b4bf70 | 2014-06-13 16:04:35 +0200 | [diff] [blame] | 1194 | * Process a fetch + format conversion as defined by the sample expression |
| 1195 | * <expr> on request or response considering the <opt> parameter. The output is |
| 1196 | * always of type string. If a stable sample can be fetched, or an unstable one |
| 1197 | * when <opt> contains SMP_OPT_FINAL, the sample is converted to a string and |
| 1198 | * returned without the SMP_F_MAY_CHANGE flag. If an unstable sample is found |
| 1199 | * and <opt> does not contain SMP_OPT_FINAL, then the sample is returned as-is |
| 1200 | * with its SMP_F_MAY_CHANGE flag so that the caller can check it and decide to |
| 1201 | * take actions (eg: wait longer). If a sample could not be found or could not |
Willy Tarreau | 6bcb0a8 | 2014-07-30 08:56:35 +0200 | [diff] [blame] | 1202 | * be converted, NULL is returned. The caller MUST NOT use the sample if the |
| 1203 | * SMP_F_MAY_CHANGE flag is present, as it is used only as a hint that there is |
| 1204 | * still hope to get it after waiting longer, and is not converted to string. |
| 1205 | * The possible output combinations are the following : |
| 1206 | * |
| 1207 | * return MAY_CHANGE FINAL Meaning for the sample |
| 1208 | * NULL * * Not present and will never be (eg: header) |
| 1209 | * smp 0 * Final value converted (eg: header) |
| 1210 | * smp 1 0 Not present yet, may appear later (eg: header) |
| 1211 | * smp 1 1 never happens (either flag is cleared on output) |
Willy Tarreau | e7ad4bb | 2012-12-21 00:02:32 +0100 | [diff] [blame] | 1212 | */ |
| 1213 | struct sample *sample_fetch_string(struct proxy *px, struct session *l4, void *l7, |
| 1214 | unsigned int opt, struct sample_expr *expr) |
| 1215 | { |
Willy Tarreau | 5b4bf70 | 2014-06-13 16:04:35 +0200 | [diff] [blame] | 1216 | struct sample *smp = &temp_smp; |
Willy Tarreau | e7ad4bb | 2012-12-21 00:02:32 +0100 | [diff] [blame] | 1217 | |
Willy Tarreau | 6c616e0 | 2014-06-25 16:56:41 +0200 | [diff] [blame] | 1218 | memset(smp, 0, sizeof(*smp)); |
| 1219 | |
Willy Tarreau | 5b4bf70 | 2014-06-13 16:04:35 +0200 | [diff] [blame] | 1220 | if (!sample_process(px, l4, l7, opt, expr, smp)) { |
| 1221 | if ((smp->flags & SMP_F_MAY_CHANGE) && !(opt & SMP_OPT_FINAL)) |
| 1222 | return smp; |
Willy Tarreau | e7ad4bb | 2012-12-21 00:02:32 +0100 | [diff] [blame] | 1223 | return NULL; |
Willy Tarreau | 5b4bf70 | 2014-06-13 16:04:35 +0200 | [diff] [blame] | 1224 | } |
Willy Tarreau | e7ad4bb | 2012-12-21 00:02:32 +0100 | [diff] [blame] | 1225 | |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 1226 | if (!sample_casts[smp->type][SMP_T_STR]) |
Willy Tarreau | e7ad4bb | 2012-12-21 00:02:32 +0100 | [diff] [blame] | 1227 | return NULL; |
| 1228 | |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 1229 | if (!sample_casts[smp->type][SMP_T_STR](smp)) |
Willy Tarreau | e7ad4bb | 2012-12-21 00:02:32 +0100 | [diff] [blame] | 1230 | return NULL; |
| 1231 | |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 1232 | smp->type = SMP_T_STR; |
Willy Tarreau | 5b4bf70 | 2014-06-13 16:04:35 +0200 | [diff] [blame] | 1233 | smp->flags &= ~SMP_F_MAY_CHANGE; |
Willy Tarreau | e7ad4bb | 2012-12-21 00:02:32 +0100 | [diff] [blame] | 1234 | return smp; |
| 1235 | } |
| 1236 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1237 | /*****************************************************************/ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1238 | /* Sample format convert functions */ |
Willy Tarreau | b8c8f1f | 2012-04-23 22:38:26 +0200 | [diff] [blame] | 1239 | /* These functions set the data type on return. */ |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1240 | /*****************************************************************/ |
| 1241 | |
Emeric Brun | 53d1a98 | 2014-04-30 18:21:37 +0200 | [diff] [blame] | 1242 | static int sample_conv_bin2base64(const struct arg *arg_p, struct sample *smp) |
| 1243 | { |
| 1244 | struct chunk *trash = get_trash_chunk(); |
| 1245 | int b64_len; |
| 1246 | |
| 1247 | trash->len = 0; |
| 1248 | b64_len = a2base64(smp->data.str.str, smp->data.str.len, trash->str, trash->size); |
| 1249 | if (b64_len < 0) |
| 1250 | return 0; |
| 1251 | |
| 1252 | trash->len = b64_len; |
| 1253 | smp->data.str = *trash; |
| 1254 | smp->type = SMP_T_STR; |
| 1255 | smp->flags &= ~SMP_F_CONST; |
| 1256 | return 1; |
| 1257 | } |
| 1258 | |
Thierry FOURNIER | 2f49d6d | 2014-03-12 15:01:52 +0100 | [diff] [blame] | 1259 | static int sample_conv_bin2hex(const struct arg *arg_p, struct sample *smp) |
| 1260 | { |
| 1261 | struct chunk *trash = get_trash_chunk(); |
| 1262 | unsigned char c; |
| 1263 | int ptr = 0; |
| 1264 | |
| 1265 | trash->len = 0; |
| 1266 | while (ptr < smp->data.str.len && trash->len <= trash->size - 2) { |
| 1267 | c = smp->data.str.str[ptr++]; |
| 1268 | trash->str[trash->len++] = hextab[(c >> 4) & 0xF]; |
| 1269 | trash->str[trash->len++] = hextab[c & 0xF]; |
| 1270 | } |
| 1271 | smp->data.str = *trash; |
| 1272 | smp->type = SMP_T_STR; |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 1273 | smp->flags &= ~SMP_F_CONST; |
Thierry FOURNIER | 2f49d6d | 2014-03-12 15:01:52 +0100 | [diff] [blame] | 1274 | return 1; |
| 1275 | } |
| 1276 | |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 1277 | /* hashes the binary input into a 32-bit unsigned int */ |
| 1278 | static int sample_conv_djb2(const struct arg *arg_p, struct sample *smp) |
| 1279 | { |
| 1280 | smp->data.uint = hash_djb2(smp->data.str.str, smp->data.str.len); |
| 1281 | if (arg_p && arg_p->data.uint) |
| 1282 | smp->data.uint = full_hash(smp->data.uint); |
| 1283 | smp->type = SMP_T_UINT; |
| 1284 | return 1; |
| 1285 | } |
| 1286 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1287 | static int sample_conv_str2lower(const struct arg *arg_p, struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1288 | { |
| 1289 | int i; |
| 1290 | |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 1291 | if (!smp_dup(smp)) |
| 1292 | return 0; |
| 1293 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 1294 | if (!smp->data.str.size) |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1295 | return 0; |
| 1296 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 1297 | for (i = 0; i < smp->data.str.len; i++) { |
| 1298 | if ((smp->data.str.str[i] >= 'A') && (smp->data.str.str[i] <= 'Z')) |
| 1299 | smp->data.str.str[i] += 'a' - 'A'; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1300 | } |
| 1301 | return 1; |
| 1302 | } |
| 1303 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1304 | static int sample_conv_str2upper(const struct arg *arg_p, struct sample *smp) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1305 | { |
| 1306 | int i; |
| 1307 | |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 1308 | if (!smp_dup(smp)) |
| 1309 | return 0; |
| 1310 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 1311 | if (!smp->data.str.size) |
Emeric Brun | 485479d | 2010-09-23 18:02:19 +0200 | [diff] [blame] | 1312 | return 0; |
| 1313 | |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 1314 | for (i = 0; i < smp->data.str.len; i++) { |
| 1315 | if ((smp->data.str.str[i] >= 'a') && (smp->data.str.str[i] <= 'z')) |
| 1316 | smp->data.str.str[i] += 'A' - 'a'; |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1317 | } |
| 1318 | return 1; |
| 1319 | } |
| 1320 | |
Willy Tarreau | f995410 | 2012-04-20 14:03:29 +0200 | [diff] [blame] | 1321 | /* takes the netmask in arg_p */ |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1322 | static int sample_conv_ipmask(const struct arg *arg_p, struct sample *smp) |
Willy Tarreau | d31d6eb | 2010-01-26 18:01:41 +0100 | [diff] [blame] | 1323 | { |
Willy Tarreau | 342acb4 | 2012-04-23 22:03:39 +0200 | [diff] [blame] | 1324 | smp->data.ipv4.s_addr &= arg_p->data.ipv4.s_addr; |
Willy Tarreau | b8c8f1f | 2012-04-23 22:38:26 +0200 | [diff] [blame] | 1325 | smp->type = SMP_T_IPV4; |
Willy Tarreau | d31d6eb | 2010-01-26 18:01:41 +0100 | [diff] [blame] | 1326 | return 1; |
| 1327 | } |
| 1328 | |
Willy Tarreau | 0dbfdba | 2014-07-10 16:37:47 +0200 | [diff] [blame] | 1329 | /* takes an UINT value on input supposed to represent the time since EPOCH, |
| 1330 | * adds an optional offset found in args[1] and emits a string representing |
| 1331 | * the local time in the format specified in args[1] using strftime(). |
| 1332 | */ |
| 1333 | static int sample_conv_ltime(const struct arg *args, struct sample *smp) |
| 1334 | { |
| 1335 | struct chunk *temp; |
| 1336 | time_t curr_date = smp->data.uint; |
| 1337 | |
| 1338 | /* add offset */ |
| 1339 | if (args[1].type == ARGT_SINT || args[1].type == ARGT_UINT) |
| 1340 | curr_date += args[1].data.sint; |
| 1341 | |
| 1342 | temp = get_trash_chunk(); |
| 1343 | temp->len = strftime(temp->str, temp->size, args[0].data.str.str, localtime(&curr_date)); |
| 1344 | smp->data.str = *temp; |
| 1345 | smp->type = SMP_T_STR; |
| 1346 | return 1; |
| 1347 | } |
| 1348 | |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 1349 | /* hashes the binary input into a 32-bit unsigned int */ |
| 1350 | static int sample_conv_sdbm(const struct arg *arg_p, struct sample *smp) |
| 1351 | { |
| 1352 | smp->data.uint = hash_sdbm(smp->data.str.str, smp->data.str.len); |
| 1353 | if (arg_p && arg_p->data.uint) |
| 1354 | smp->data.uint = full_hash(smp->data.uint); |
| 1355 | smp->type = SMP_T_UINT; |
| 1356 | return 1; |
| 1357 | } |
| 1358 | |
Willy Tarreau | 0dbfdba | 2014-07-10 16:37:47 +0200 | [diff] [blame] | 1359 | /* takes an UINT value on input supposed to represent the time since EPOCH, |
| 1360 | * adds an optional offset found in args[1] and emits a string representing |
| 1361 | * the UTC date in the format specified in args[1] using strftime(). |
| 1362 | */ |
| 1363 | static int sample_conv_utime(const struct arg *args, struct sample *smp) |
| 1364 | { |
| 1365 | struct chunk *temp; |
| 1366 | time_t curr_date = smp->data.uint; |
| 1367 | |
| 1368 | /* add offset */ |
| 1369 | if (args[1].type == ARGT_SINT || args[1].type == ARGT_UINT) |
| 1370 | curr_date += args[1].data.sint; |
| 1371 | |
| 1372 | temp = get_trash_chunk(); |
| 1373 | temp->len = strftime(temp->str, temp->size, args[0].data.str.str, gmtime(&curr_date)); |
| 1374 | smp->data.str = *temp; |
| 1375 | smp->type = SMP_T_STR; |
| 1376 | return 1; |
| 1377 | } |
| 1378 | |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 1379 | /* hashes the binary input into a 32-bit unsigned int */ |
| 1380 | static int sample_conv_wt6(const struct arg *arg_p, struct sample *smp) |
| 1381 | { |
| 1382 | smp->data.uint = hash_wt6(smp->data.str.str, smp->data.str.len); |
| 1383 | if (arg_p && arg_p->data.uint) |
| 1384 | smp->data.uint = full_hash(smp->data.uint); |
| 1385 | smp->type = SMP_T_UINT; |
| 1386 | return 1; |
| 1387 | } |
| 1388 | |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1389 | /************************************************************************/ |
| 1390 | /* All supported sample fetch functions must be declared here */ |
| 1391 | /************************************************************************/ |
| 1392 | |
| 1393 | /* force TRUE to be returned at the fetch level */ |
| 1394 | static int |
| 1395 | smp_fetch_true(struct proxy *px, struct session *s, void *l7, unsigned int opt, |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame] | 1396 | const struct arg *args, struct sample *smp, const char *kw) |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1397 | { |
| 1398 | smp->type = SMP_T_BOOL; |
| 1399 | smp->data.uint = 1; |
| 1400 | return 1; |
| 1401 | } |
| 1402 | |
| 1403 | /* force FALSE to be returned at the fetch level */ |
| 1404 | static int |
| 1405 | smp_fetch_false(struct proxy *px, struct session *s, void *l7, unsigned int opt, |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame] | 1406 | const struct arg *args, struct sample *smp, const char *kw) |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1407 | { |
| 1408 | smp->type = SMP_T_BOOL; |
| 1409 | smp->data.uint = 0; |
| 1410 | return 1; |
| 1411 | } |
| 1412 | |
| 1413 | /* retrieve environment variable $1 as a string */ |
| 1414 | static int |
| 1415 | smp_fetch_env(struct proxy *px, struct session *s, void *l7, unsigned int opt, |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame] | 1416 | const struct arg *args, struct sample *smp, const char *kw) |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1417 | { |
| 1418 | char *env; |
| 1419 | |
| 1420 | if (!args || args[0].type != ARGT_STR) |
| 1421 | return 0; |
| 1422 | |
| 1423 | env = getenv(args[0].data.str.str); |
| 1424 | if (!env) |
| 1425 | return 0; |
| 1426 | |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 1427 | smp->type = SMP_T_STR; |
| 1428 | smp->flags = SMP_F_CONST; |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1429 | smp->data.str.str = env; |
| 1430 | smp->data.str.len = strlen(env); |
| 1431 | return 1; |
| 1432 | } |
| 1433 | |
Willy Tarreau | 6236d3a | 2013-07-25 14:28:25 +0200 | [diff] [blame] | 1434 | /* retrieve the current local date in epoch time, and applies an optional offset |
| 1435 | * of args[0] seconds. |
| 1436 | */ |
| 1437 | static int |
| 1438 | smp_fetch_date(struct proxy *px, struct session *s, void *l7, unsigned int opt, |
Willy Tarreau | ef38c39 | 2013-07-22 16:29:32 +0200 | [diff] [blame] | 1439 | const struct arg *args, struct sample *smp, const char *kw) |
Willy Tarreau | 6236d3a | 2013-07-25 14:28:25 +0200 | [diff] [blame] | 1440 | { |
| 1441 | smp->data.uint = date.tv_sec; |
| 1442 | |
| 1443 | /* add offset */ |
| 1444 | if (args && (args[0].type == ARGT_SINT || args[0].type == ARGT_UINT)) |
| 1445 | smp->data.uint += args[0].data.sint; |
| 1446 | |
| 1447 | smp->type = SMP_T_UINT; |
| 1448 | smp->flags |= SMP_F_VOL_TEST | SMP_F_MAY_CHANGE; |
| 1449 | return 1; |
| 1450 | } |
| 1451 | |
Willy Tarreau | 84310e2 | 2014-02-14 11:59:04 +0100 | [diff] [blame] | 1452 | /* generate a random 32-bit integer for whatever purpose, with an optional |
| 1453 | * range specified in argument. |
| 1454 | */ |
| 1455 | static int |
| 1456 | smp_fetch_rand(struct proxy *px, struct session *s, void *l7, unsigned int opt, |
| 1457 | const struct arg *args, struct sample *smp, const char *kw) |
| 1458 | { |
| 1459 | smp->data.uint = random(); |
| 1460 | |
| 1461 | /* reduce if needed. Don't do a modulo, use all bits! */ |
| 1462 | if (args && args[0].type == ARGT_UINT) |
| 1463 | smp->data.uint = ((uint64_t)smp->data.uint * args[0].data.uint) >> 32; |
| 1464 | |
| 1465 | smp->type = SMP_T_UINT; |
| 1466 | smp->flags |= SMP_F_VOL_TEST | SMP_F_MAY_CHANGE; |
| 1467 | return 1; |
| 1468 | } |
| 1469 | |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1470 | /* Note: must not be declared <const> as its list will be overwritten. |
| 1471 | * Note: fetches that may return multiple types must be declared as the lowest |
| 1472 | * common denominator, the type that can be casted into all other ones. For |
| 1473 | * instance IPv4/IPv6 must be declared IPv4. |
| 1474 | */ |
| 1475 | static struct sample_fetch_kw_list smp_kws = {ILH, { |
| 1476 | { "always_false", smp_fetch_false, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, |
| 1477 | { "always_true", smp_fetch_true, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, |
Thierry FOURNIER | 7654c9f | 2013-12-17 00:20:33 +0100 | [diff] [blame] | 1478 | { "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_STR, SMP_USE_INTRN }, |
Willy Tarreau | 6236d3a | 2013-07-25 14:28:25 +0200 | [diff] [blame] | 1479 | { "date", smp_fetch_date, ARG1(0,SINT), NULL, SMP_T_UINT, SMP_USE_INTRN }, |
Willy Tarreau | 84310e2 | 2014-02-14 11:59:04 +0100 | [diff] [blame] | 1480 | { "rand", smp_fetch_rand, ARG1(0,UINT), NULL, SMP_T_UINT, SMP_USE_INTRN }, |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1481 | { /* END */ }, |
| 1482 | }}; |
| 1483 | |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1484 | /* Note: must not be declared <const> as its list will be overwritten */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 1485 | static struct sample_conv_kw_list sample_conv_kws = {ILH, { |
Emeric Brun | 53d1a98 | 2014-04-30 18:21:37 +0200 | [diff] [blame] | 1486 | { "base64", sample_conv_bin2base64,0, NULL, SMP_T_BIN, SMP_T_STR }, |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1487 | { "upper", sample_conv_str2upper, 0, NULL, SMP_T_STR, SMP_T_STR }, |
| 1488 | { "lower", sample_conv_str2lower, 0, NULL, SMP_T_STR, SMP_T_STR }, |
Thierry FOURNIER | 2f49d6d | 2014-03-12 15:01:52 +0100 | [diff] [blame] | 1489 | { "hex", sample_conv_bin2hex, 0, NULL, SMP_T_BIN, SMP_T_STR }, |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1490 | { "ipmask", sample_conv_ipmask, ARG1(1,MSK4), NULL, SMP_T_IPV4, SMP_T_IPV4 }, |
Willy Tarreau | 0dbfdba | 2014-07-10 16:37:47 +0200 | [diff] [blame] | 1491 | { "ltime", sample_conv_ltime, ARG2(1,STR,SINT), NULL, SMP_T_UINT, SMP_T_STR }, |
| 1492 | { "utime", sample_conv_utime, ARG2(1,STR,SINT), NULL, SMP_T_UINT, SMP_T_STR }, |
Willy Tarreau | 23ec4ca | 2014-07-15 20:15:37 +0200 | [diff] [blame] | 1493 | { "djb2", sample_conv_djb2, ARG1(0,UINT), NULL, SMP_T_BIN, SMP_T_UINT }, |
| 1494 | { "sdbm", sample_conv_sdbm, ARG1(0,UINT), NULL, SMP_T_BIN, SMP_T_UINT }, |
| 1495 | { "wt6", sample_conv_wt6, ARG1(0,UINT), NULL, SMP_T_BIN, SMP_T_UINT }, |
Willy Tarreau | 9fcb984 | 2012-04-20 14:45:49 +0200 | [diff] [blame] | 1496 | { NULL, NULL, 0, 0, 0 }, |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1497 | }}; |
| 1498 | |
| 1499 | __attribute__((constructor)) |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1500 | static void __sample_init(void) |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1501 | { |
Willy Tarreau | 5b8ad22 | 2013-07-25 12:17:57 +0200 | [diff] [blame] | 1502 | /* register sample fetch and format conversion keywords */ |
| 1503 | sample_register_fetches(&smp_kws); |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 1504 | sample_register_convs(&sample_conv_kws); |
Emeric Brun | 107ca30 | 2010-01-04 16:16:05 +0100 | [diff] [blame] | 1505 | } |