Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | |
| 3 | #include <common/cfgparse.h> |
| 4 | #include <common/chunk.h> |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 5 | #include <common/buffer.h> |
Willy Tarreau | 9f3f254 | 2016-12-21 20:30:05 +0100 | [diff] [blame^] | 6 | #include <common/errors.h> |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 7 | #include <proto/arg.h> |
| 8 | #include <proto/log.h> |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 9 | #include <proto/proto_http.h> |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 10 | #include <proto/sample.h> |
| 11 | #include <import/xxhash.h> |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 12 | #include <import/lru.h> |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 13 | #include <import/51d.h> |
| 14 | |
| 15 | struct _51d_property_names { |
| 16 | struct list list; |
| 17 | char *name; |
| 18 | }; |
| 19 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 20 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 21 | static struct lru64_head *_51d_lru_tree = NULL; |
| 22 | static unsigned long long _51d_lru_seed; |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 23 | #endif |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 24 | |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 25 | static int _51d_data_file(char **args, int section_type, struct proxy *curpx, |
| 26 | struct proxy *defpx, const char *file, int line, |
| 27 | char **err) |
| 28 | { |
| 29 | if (*(args[1]) == 0) { |
| 30 | memprintf(err, |
| 31 | "'%s' expects a filepath to a 51Degrees trie or pattern data file.", |
| 32 | args[0]); |
| 33 | return -1; |
| 34 | } |
| 35 | |
| 36 | if (global._51degrees.data_file_path) |
| 37 | free(global._51degrees.data_file_path); |
| 38 | global._51degrees.data_file_path = strdup(args[1]); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static int _51d_property_name_list(char **args, int section_type, struct proxy *curpx, |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 44 | struct proxy *defpx, const char *file, int line, |
| 45 | char **err) |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 46 | { |
| 47 | int cur_arg = 1; |
| 48 | struct _51d_property_names *name; |
| 49 | |
| 50 | if (*(args[cur_arg]) == 0) { |
| 51 | memprintf(err, |
| 52 | "'%s' expects at least one 51Degrees property name.", |
| 53 | args[0]); |
| 54 | return -1; |
| 55 | } |
| 56 | |
| 57 | while (*(args[cur_arg])) { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 58 | name = calloc(1, sizeof(*name)); |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 59 | name->name = strdup(args[cur_arg]); |
| 60 | LIST_ADDQ(&global._51degrees.property_names, &name->list); |
| 61 | ++cur_arg; |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static int _51d_property_separator(char **args, int section_type, struct proxy *curpx, |
| 68 | struct proxy *defpx, const char *file, int line, |
| 69 | char **err) |
| 70 | { |
| 71 | if (*(args[1]) == 0) { |
| 72 | memprintf(err, |
| 73 | "'%s' expects a single character.", |
| 74 | args[0]); |
| 75 | return -1; |
| 76 | } |
| 77 | if (strlen(args[1]) > 1) { |
| 78 | memprintf(err, |
| 79 | "'%s' expects a single character, got '%s'.", |
| 80 | args[0], args[1]); |
| 81 | return -1; |
| 82 | } |
| 83 | |
| 84 | global._51degrees.property_separator = *args[1]; |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 89 | static int _51d_cache_size(char **args, int section_type, struct proxy *curpx, |
| 90 | struct proxy *defpx, const char *file, int line, |
| 91 | char **err) |
| 92 | { |
| 93 | if (*(args[1]) == 0) { |
| 94 | memprintf(err, |
| 95 | "'%s' expects a positive numeric value.", |
| 96 | args[0]); |
| 97 | return -1; |
| 98 | } |
| 99 | |
| 100 | global._51degrees.cache_size = atoi(args[1]); |
| 101 | if (global._51degrees.cache_size < 0) { |
| 102 | memprintf(err, |
| 103 | "'%s' expects a positive numeric value, got '%s'.", |
| 104 | args[0], args[1]); |
| 105 | return -1; |
| 106 | } |
| 107 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static int _51d_fetch_check(struct arg *arg, char **err_msg) |
| 112 | { |
| 113 | if (global._51degrees.data_file_path) |
| 114 | return 1; |
| 115 | |
| 116 | memprintf(err_msg, "51Degrees data file is not specified (parameter '51degrees-data-file')"); |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | |
Dragan Dosen | 9373fc5 | 2015-08-07 16:41:23 +0200 | [diff] [blame] | 120 | static int _51d_conv_check(struct arg *arg, struct sample_conv *conv, |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 121 | const char *file, int line, char **err_msg) |
Dragan Dosen | 9373fc5 | 2015-08-07 16:41:23 +0200 | [diff] [blame] | 122 | { |
| 123 | if (global._51degrees.data_file_path) |
| 124 | return 1; |
| 125 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 126 | memprintf(err_msg, "51Degrees data file is not specified (parameter '51degrees-data-file')"); |
Dragan Dosen | 9373fc5 | 2015-08-07 16:41:23 +0200 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 130 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
ben@51degrees.com | c9dfa24 | 2016-01-08 13:47:46 +0000 | [diff] [blame] | 131 | static void _51d_lru_free(void *cache_entry) |
| 132 | { |
| 133 | struct chunk *ptr = cache_entry; |
| 134 | |
| 135 | if (!ptr) |
| 136 | return; |
| 137 | |
| 138 | free(ptr->str); |
| 139 | free(ptr); |
| 140 | } |
| 141 | |
| 142 | /* Allocates memory freeing space in the cache if necessary. |
| 143 | */ |
| 144 | static void *_51d_malloc(int size) |
| 145 | { |
| 146 | void *ptr = malloc(size); |
| 147 | |
| 148 | if (!ptr) { |
| 149 | /* free the oldest 10 entries from lru to free up some memory |
| 150 | * then try allocating memory again */ |
| 151 | lru64_kill_oldest(_51d_lru_tree, 10); |
| 152 | ptr = malloc(size); |
| 153 | } |
| 154 | |
| 155 | return ptr; |
| 156 | } |
| 157 | |
James Rosewell | 63426cb | 2015-09-18 19:53:05 +0100 | [diff] [blame] | 158 | /* Insert the data associated with the sample into the cache as a fresh item. |
| 159 | */ |
ben@51degrees.com | 82a9d76 | 2016-01-08 13:42:41 +0000 | [diff] [blame] | 160 | static void _51d_insert_cache_entry(struct sample *smp, struct lru64 *lru, void* domain) |
James Rosewell | 63426cb | 2015-09-18 19:53:05 +0100 | [diff] [blame] | 161 | { |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 162 | struct chunk *cache_entry = _51d_malloc(sizeof(*cache_entry)); |
James Rosewell | 63426cb | 2015-09-18 19:53:05 +0100 | [diff] [blame] | 163 | |
| 164 | if (!cache_entry) |
| 165 | return; |
| 166 | |
ben@51degrees.com | c9dfa24 | 2016-01-08 13:47:46 +0000 | [diff] [blame] | 167 | cache_entry->str = _51d_malloc(smp->data.u.str.len + 1); |
| 168 | if (!cache_entry->str) { |
| 169 | free(cache_entry); |
James Rosewell | 63426cb | 2015-09-18 19:53:05 +0100 | [diff] [blame] | 170 | return; |
ben@51degrees.com | c9dfa24 | 2016-01-08 13:47:46 +0000 | [diff] [blame] | 171 | } |
James Rosewell | 63426cb | 2015-09-18 19:53:05 +0100 | [diff] [blame] | 172 | |
| 173 | memcpy(cache_entry->str, smp->data.u.str.str, smp->data.u.str.len); |
| 174 | cache_entry->str[smp->data.u.str.len] = 0; |
| 175 | cache_entry->len = smp->data.u.str.len; |
ben@51degrees.com | c9dfa24 | 2016-01-08 13:47:46 +0000 | [diff] [blame] | 176 | lru64_commit(lru, cache_entry, domain, 0, _51d_lru_free); |
James Rosewell | 63426cb | 2015-09-18 19:53:05 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /* Retrieves the data from the cache and sets the sample data to this string. |
| 180 | */ |
| 181 | static void _51d_retrieve_cache_entry(struct sample *smp, struct lru64 *lru) |
| 182 | { |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 183 | struct chunk *cache_entry = lru->data; |
James Rosewell | 63426cb | 2015-09-18 19:53:05 +0100 | [diff] [blame] | 184 | smp->data.u.str.str = cache_entry->str; |
| 185 | smp->data.u.str.len = cache_entry->len; |
| 186 | } |
| 187 | #endif |
| 188 | |
| 189 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 190 | /* Sets the important HTTP headers ahead of the detection |
| 191 | */ |
| 192 | static void _51d_set_headers(struct sample *smp, fiftyoneDegreesWorkset *ws) |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 193 | { |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 194 | struct hdr_idx *idx; |
| 195 | struct hdr_ctx ctx; |
| 196 | const struct http_msg *msg; |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 197 | int i; |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 198 | |
| 199 | idx = &smp->strm->txn->hdr_idx; |
| 200 | msg = &smp->strm->txn->req; |
| 201 | |
| 202 | ws->importantHeadersCount = 0; |
| 203 | |
| 204 | for (i = 0; i < global._51degrees.header_count; i++) { |
| 205 | ctx.idx = 0; |
| 206 | if (http_find_full_header2( |
| 207 | (global._51degrees.header_names + i)->str, |
| 208 | (global._51degrees.header_names + i)->len, |
| 209 | msg->chn->buf->p, idx, &ctx) == 1) { |
| 210 | ws->importantHeaders[ws->importantHeadersCount].header = ws->dataSet->httpHeaders + i; |
| 211 | ws->importantHeaders[ws->importantHeadersCount].headerValue = ctx.line + ctx.val; |
| 212 | ws->importantHeaders[ws->importantHeadersCount].headerValueLength = ctx.vlen; |
| 213 | ws->importantHeadersCount++; |
| 214 | } |
| 215 | } |
| 216 | } |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 217 | #endif |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 218 | |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 219 | #ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 220 | static void _51d_set_device_offsets(struct sample *smp) |
| 221 | { |
| 222 | struct hdr_idx *idx; |
| 223 | struct hdr_ctx ctx; |
| 224 | const struct http_msg *msg; |
| 225 | int index; |
| 226 | fiftyoneDegreesDeviceOffsets *offsets = &global._51degrees.device_offsets; |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 227 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 228 | idx = &smp->strm->txn->hdr_idx; |
| 229 | msg = &smp->strm->txn->req; |
| 230 | offsets->size = 0; |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 231 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 232 | for (index = 0; index < global._51degrees.header_count; index++) { |
| 233 | ctx.idx = 0; |
| 234 | if (http_find_full_header2( |
| 235 | (global._51degrees.header_names + index)->str, |
| 236 | (global._51degrees.header_names + index)->len, |
| 237 | msg->chn->buf->p, idx, &ctx) == 1) { |
| 238 | (offsets->firstOffset + offsets->size)->httpHeaderOffset = *(global._51degrees.header_offsets + index); |
ben51degrees | 1f077eb | 2016-07-06 12:07:21 +0100 | [diff] [blame] | 239 | (offsets->firstOffset + offsets->size)->deviceOffset = fiftyoneDegreesGetDeviceOffset(&global._51degrees.data_set, ctx.line + ctx.val); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 240 | offsets->size++; |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 241 | } |
| 242 | } |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 243 | } |
| 244 | #endif |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 245 | |
| 246 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 247 | /* Provides a hash code for the important HTTP headers. |
| 248 | */ |
| 249 | unsigned long long _51d_req_hash(const struct arg *args, fiftyoneDegreesWorkset* ws) |
| 250 | { |
| 251 | unsigned long long seed = _51d_lru_seed ^ (long)args; |
| 252 | unsigned long long hash = 0; |
| 253 | int i; |
| 254 | for(i = 0; i < ws->importantHeadersCount; i++) { |
| 255 | hash ^= ws->importantHeaders[i].header->headerNameOffset; |
| 256 | hash ^= XXH64(ws->importantHeaders[i].headerValue, |
| 257 | ws->importantHeaders[i].headerValueLength, |
| 258 | seed); |
| 259 | } |
| 260 | return hash; |
| 261 | } |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 262 | #endif |
| 263 | |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 264 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 265 | static void _51d_process_match(const struct arg *args, struct sample *smp, fiftyoneDegreesWorkset* ws) |
| 266 | { |
| 267 | char *methodName; |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 268 | #endif |
| 269 | #ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 270 | static void _51d_process_match(const struct arg *args, struct sample *smp) |
| 271 | { |
| 272 | char valuesBuffer[1024]; |
ben51degrees | 1f077eb | 2016-07-06 12:07:21 +0100 | [diff] [blame] | 273 | const char **requiredProperties = fiftyoneDegreesGetRequiredPropertiesNames(&global._51degrees.data_set); |
| 274 | int requiredPropertiesCount = fiftyoneDegreesGetRequiredPropertiesCount(&global._51degrees.data_set); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 275 | fiftyoneDegreesDeviceOffsets *deviceOffsets = &global._51degrees.device_offsets; |
| 276 | |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 277 | #endif |
| 278 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 279 | char no_data[] = "NoData"; /* response when no data could be found */ |
| 280 | struct chunk *temp = get_trash_chunk(); |
| 281 | int j, i = 0, found; |
| 282 | const char* property_name; |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 283 | |
| 284 | /* Loop through property names passed to the filter and fetch them from the dataset. */ |
| 285 | while (args[i].data.str.str) { |
| 286 | /* Try to find request property in dataset. */ |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 287 | found = 0; |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 288 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
| 289 | if (strcmp("Method", args[i].data.str.str) == 0) { |
| 290 | switch(ws->method) { |
| 291 | case EXACT: methodName = "Exact"; break; |
| 292 | case NUMERIC: methodName = "Numeric"; break; |
| 293 | case NEAREST: methodName = "Nearest"; break; |
| 294 | case CLOSEST: methodName = "Closest"; break; |
| 295 | default: |
| 296 | case NONE: methodName = "None"; break; |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 297 | } |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 298 | chunk_appendf(temp, "%s", methodName); |
| 299 | found = 1; |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 300 | } |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 301 | else if (strcmp("Difference", args[i].data.str.str) == 0) { |
| 302 | chunk_appendf(temp, "%d", ws->difference); |
| 303 | found = 1; |
| 304 | } |
| 305 | else if (strcmp("Rank", args[i].data.str.str) == 0) { |
| 306 | chunk_appendf(temp, "%d", fiftyoneDegreesGetSignatureRank(ws)); |
| 307 | found = 1; |
| 308 | } |
| 309 | else { |
| 310 | for (j = 0; j < ws->dataSet->requiredPropertyCount; j++) { |
| 311 | property_name = fiftyoneDegreesGetPropertyName(ws->dataSet, ws->dataSet->requiredProperties[j]); |
| 312 | if (strcmp(property_name, args[i].data.str.str) == 0) { |
| 313 | found = 1; |
| 314 | fiftyoneDegreesSetValues(ws, j); |
| 315 | chunk_appendf(temp, "%s", fiftyoneDegreesGetValueName(ws->dataSet, *ws->values)); |
| 316 | break; |
| 317 | } |
| 318 | } |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 319 | } |
| 320 | #endif |
| 321 | #ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 322 | found = 0; |
| 323 | for (j = 0; j < requiredPropertiesCount; j++) { |
| 324 | property_name = requiredProperties[j]; |
| 325 | if (strcmp(property_name, args[i].data.str.str) == 0 && |
ben51degrees | 1f077eb | 2016-07-06 12:07:21 +0100 | [diff] [blame] | 326 | fiftyoneDegreesGetValueFromOffsets(&global._51degrees.data_set, deviceOffsets, j, valuesBuffer, 1024) > 0) { |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 327 | found = 1; |
| 328 | chunk_appendf(temp, "%s", valuesBuffer); |
| 329 | break; |
| 330 | } |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 331 | } |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 332 | #endif |
ben@51degrees.com | d384252 | 2016-01-08 13:52:32 +0000 | [diff] [blame] | 333 | if (!found) |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 334 | chunk_appendf(temp, "%s", no_data); |
ben@51degrees.com | d384252 | 2016-01-08 13:52:32 +0000 | [diff] [blame] | 335 | |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 336 | /* Add separator. */ |
| 337 | chunk_appendf(temp, "%c", global._51degrees.property_separator); |
| 338 | ++i; |
| 339 | } |
| 340 | |
| 341 | if (temp->len) { |
| 342 | --temp->len; |
| 343 | temp->str[temp->len] = '\0'; |
| 344 | } |
| 345 | |
Thierry FOURNIER | 2046c46 | 2015-08-20 13:42:12 +0200 | [diff] [blame] | 346 | smp->data.u.str.str = temp->str; |
James Rosewell | 63426cb | 2015-09-18 19:53:05 +0100 | [diff] [blame] | 347 | smp->data.u.str.len = temp->len; |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static int _51d_fetch(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 351 | { |
| 352 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
| 353 | fiftyoneDegreesWorkset* ws; /* workset for detection */ |
| 354 | struct lru64 *lru = NULL; |
| 355 | #endif |
| 356 | |
| 357 | /* Needed to ensure that the HTTP message has been fully recieved when |
| 358 | * used with TCP operation. Not required for HTTP operation. |
| 359 | * Data type has to be reset to ensure the string output is processed |
| 360 | * correctly. |
| 361 | */ |
| 362 | CHECK_HTTP_MESSAGE_FIRST(); |
| 363 | smp->data.type = SMP_T_STR; |
| 364 | |
ben@51degrees.com | 82a9d76 | 2016-01-08 13:42:41 +0000 | [diff] [blame] | 365 | /* Flags the sample to show it uses constant memory*/ |
| 366 | smp->flags |= SMP_F_CONST; |
| 367 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 368 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
| 369 | |
| 370 | /* Get only the headers needed for device detection so they can be used |
| 371 | * with the cache to return previous results. Pattern is slower than |
| 372 | * Trie so caching will help improve performance. |
| 373 | */ |
| 374 | |
| 375 | /* Get a workset from the pool which will later contain detection results. */ |
| 376 | ws = fiftyoneDegreesWorksetPoolGet(global._51degrees.pool); |
| 377 | if (!ws) |
| 378 | return 0; |
| 379 | |
| 380 | /* Set the important HTTP headers for this request in the workset. */ |
| 381 | _51d_set_headers(smp, ws); |
| 382 | |
| 383 | /* Check the cache to see if there's results for these headers already. */ |
| 384 | if (_51d_lru_tree) { |
| 385 | lru = lru64_get(_51d_req_hash(args, ws), |
ben@51degrees.com | 82a9d76 | 2016-01-08 13:42:41 +0000 | [diff] [blame] | 386 | _51d_lru_tree, (void*)args, 0); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 387 | if (lru && lru->domain) { |
ben@51degrees.com | 6baceb9 | 2016-01-08 13:48:37 +0000 | [diff] [blame] | 388 | fiftyoneDegreesWorksetPoolRelease(global._51degrees.pool, ws); |
James Rosewell | 63426cb | 2015-09-18 19:53:05 +0100 | [diff] [blame] | 389 | _51d_retrieve_cache_entry(smp, lru); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 390 | return 1; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | fiftyoneDegreesMatchForHttpHeaders(ws); |
| 395 | |
| 396 | _51d_process_match(args, smp, ws); |
| 397 | |
| 398 | #endif |
| 399 | |
| 400 | #ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED |
| 401 | |
| 402 | /* Trie is very fast so all the headers can be passed in and the result |
| 403 | * returned faster than the hashing algorithm process. |
| 404 | */ |
| 405 | _51d_set_device_offsets(smp); |
| 406 | _51d_process_match(args, smp); |
| 407 | |
| 408 | #endif |
| 409 | |
| 410 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
| 411 | fiftyoneDegreesWorksetPoolRelease(global._51degrees.pool, ws); |
ben@51degrees.com | d384252 | 2016-01-08 13:52:32 +0000 | [diff] [blame] | 412 | if (lru) |
ben@51degrees.com | 82a9d76 | 2016-01-08 13:42:41 +0000 | [diff] [blame] | 413 | _51d_insert_cache_entry(smp, lru, (void*)args); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 414 | #endif |
| 415 | |
| 416 | return 1; |
| 417 | } |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 418 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 419 | static int _51d_conv(const struct arg *args, struct sample *smp, void *private) |
| 420 | { |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 421 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 422 | fiftyoneDegreesWorkset* ws; /* workset for detection */ |
| 423 | struct lru64 *lru = NULL; |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 424 | #endif |
| 425 | |
ben@51degrees.com | 82a9d76 | 2016-01-08 13:42:41 +0000 | [diff] [blame] | 426 | /* Flags the sample to show it uses constant memory*/ |
| 427 | smp->flags |= SMP_F_CONST; |
| 428 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 429 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
| 430 | |
| 431 | /* Look in the list. */ |
| 432 | if (_51d_lru_tree) { |
| 433 | unsigned long long seed = _51d_lru_seed ^ (long)args; |
| 434 | |
| 435 | lru = lru64_get(XXH64(smp->data.u.str.str, smp->data.u.str.len, seed), |
ben@51degrees.com | 82a9d76 | 2016-01-08 13:42:41 +0000 | [diff] [blame] | 436 | _51d_lru_tree, (void*)args, 0); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 437 | if (lru && lru->domain) { |
James Rosewell | 63426cb | 2015-09-18 19:53:05 +0100 | [diff] [blame] | 438 | _51d_retrieve_cache_entry(smp, lru); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 439 | return 1; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | /* Create workset. This will later contain detection results. */ |
| 444 | ws = fiftyoneDegreesWorksetPoolGet(global._51degrees.pool); |
| 445 | if (!ws) |
| 446 | return 0; |
| 447 | #endif |
| 448 | |
| 449 | /* Duplicate the data and remove the "const" flag before device detection. */ |
| 450 | if (!smp_dup(smp)) |
| 451 | return 0; |
| 452 | |
| 453 | smp->data.u.str.str[smp->data.u.str.len] = '\0'; |
| 454 | |
| 455 | /* Perform detection. */ |
| 456 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
| 457 | fiftyoneDegreesMatch(ws, smp->data.u.str.str); |
| 458 | _51d_process_match(args, smp, ws); |
| 459 | #endif |
| 460 | #ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED |
ben51degrees | 1f077eb | 2016-07-06 12:07:21 +0100 | [diff] [blame] | 461 | global._51degrees.device_offsets.firstOffset->deviceOffset = fiftyoneDegreesGetDeviceOffset(&global._51degrees.data_set, smp->data.u.str.str); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 462 | global._51degrees.device_offsets.size = 1; |
| 463 | _51d_process_match(args, smp); |
| 464 | #endif |
| 465 | |
| 466 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
| 467 | fiftyoneDegreesWorksetPoolRelease(global._51degrees.pool, ws); |
ben@51degrees.com | d384252 | 2016-01-08 13:52:32 +0000 | [diff] [blame] | 468 | if (lru) |
ben@51degrees.com | 82a9d76 | 2016-01-08 13:42:41 +0000 | [diff] [blame] | 469 | _51d_insert_cache_entry(smp, lru, (void*)args); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 470 | #endif |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 471 | |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 472 | return 1; |
| 473 | } |
| 474 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 475 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
| 476 | void _51d_init_http_headers() |
| 477 | { |
| 478 | int index = 0; |
| 479 | const fiftyoneDegreesAsciiString *headerName; |
| 480 | fiftyoneDegreesDataSet *ds = &global._51degrees.data_set; |
| 481 | global._51degrees.header_count = ds->httpHeadersCount; |
ben@51degrees.com | d384252 | 2016-01-08 13:52:32 +0000 | [diff] [blame] | 482 | global._51degrees.header_names = malloc(global._51degrees.header_count * sizeof(struct chunk)); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 483 | for (index = 0; index < global._51degrees.header_count; index++) { |
| 484 | headerName = fiftyoneDegreesGetString(ds, ds->httpHeaders[index].headerNameOffset); |
| 485 | (global._51degrees.header_names + index)->str = (char*)&headerName->firstByte; |
| 486 | (global._51degrees.header_names + index)->len = headerName->length - 1; |
| 487 | (global._51degrees.header_names + index)->size = (global._51degrees.header_names + index)->len; |
| 488 | } |
| 489 | } |
| 490 | #endif |
| 491 | |
| 492 | #ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED |
| 493 | void _51d_init_http_headers() |
| 494 | { |
| 495 | int index = 0; |
ben51degrees | 1f077eb | 2016-07-06 12:07:21 +0100 | [diff] [blame] | 496 | fiftyoneDegreesDataSet *ds = &global._51degrees.data_set; |
| 497 | global._51degrees.header_count = fiftyoneDegreesGetHttpHeaderCount(ds); |
Vincent Bernat | 3c2f2f2 | 2016-04-03 13:48:42 +0200 | [diff] [blame] | 498 | global._51degrees.device_offsets.firstOffset = malloc( |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 499 | global._51degrees.header_count * sizeof(fiftyoneDegreesDeviceOffset)); |
ben@51degrees.com | d384252 | 2016-01-08 13:52:32 +0000 | [diff] [blame] | 500 | global._51degrees.header_names = malloc(global._51degrees.header_count * sizeof(struct chunk)); |
| 501 | global._51degrees.header_offsets = malloc(global._51degrees.header_count * sizeof(int32_t)); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 502 | for (index = 0; index < global._51degrees.header_count; index++) { |
ben51degrees | 1f077eb | 2016-07-06 12:07:21 +0100 | [diff] [blame] | 503 | global._51degrees.header_offsets[index] = fiftyoneDegreesGetHttpHeaderNameOffset(ds, index); |
| 504 | global._51degrees.header_names[index].str = (char*)fiftyoneDegreesGetHttpHeaderNamePointer(ds, index); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 505 | global._51degrees.header_names[index].len = strlen(global._51degrees.header_names[index].str); |
| 506 | global._51degrees.header_names[index].size = global._51degrees.header_names[index].len; |
| 507 | } |
| 508 | } |
| 509 | #endif |
| 510 | |
Willy Tarreau | 9f3f254 | 2016-12-21 20:30:05 +0100 | [diff] [blame^] | 511 | /* |
| 512 | * module init / deinit functions. Returns 0 if OK, or a combination of ERR_*. |
| 513 | */ |
| 514 | static int init_51degrees(void) |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 515 | { |
| 516 | int i = 0; |
| 517 | struct chunk *temp; |
| 518 | struct _51d_property_names *name; |
| 519 | char **_51d_property_list = NULL; |
| 520 | fiftyoneDegreesDataSetInitStatus _51d_dataset_status = DATA_SET_INIT_STATUS_NOT_SET; |
| 521 | |
Dragan Dosen | 9373fc5 | 2015-08-07 16:41:23 +0200 | [diff] [blame] | 522 | if (!global._51degrees.data_file_path) |
Willy Tarreau | 9f3f254 | 2016-12-21 20:30:05 +0100 | [diff] [blame^] | 523 | return 0; |
Dragan Dosen | 9373fc5 | 2015-08-07 16:41:23 +0200 | [diff] [blame] | 524 | |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 525 | if (!LIST_ISEMPTY(&global._51degrees.property_names)) { |
| 526 | i = 0; |
| 527 | list_for_each_entry(name, &global._51degrees.property_names, list) |
| 528 | ++i; |
| 529 | _51d_property_list = calloc(i, sizeof(char *)); |
| 530 | |
| 531 | i = 0; |
| 532 | list_for_each_entry(name, &global._51degrees.property_names, list) |
| 533 | _51d_property_list[i++] = name->name; |
| 534 | } |
| 535 | |
ben@51degrees.com | 496299a | 2016-01-08 13:49:32 +0000 | [diff] [blame] | 536 | _51d_dataset_status = fiftyoneDegreesInitWithPropertyArray(global._51degrees.data_file_path, &global._51degrees.data_set, (const char**)_51d_property_list, i); |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 537 | |
| 538 | temp = get_trash_chunk(); |
| 539 | chunk_reset(temp); |
| 540 | |
| 541 | switch (_51d_dataset_status) { |
| 542 | case DATA_SET_INIT_STATUS_SUCCESS: |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 543 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
| 544 | /* only 1 workset in the pool because HAProxy is currently single threaded |
| 545 | * this value should be set to the number of threads in future versions. |
| 546 | */ |
| 547 | global._51degrees.pool = fiftyoneDegreesWorksetPoolCreate(&global._51degrees.data_set, NULL, 1); |
| 548 | #endif |
| 549 | _51d_init_http_headers(); |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 550 | break; |
| 551 | case DATA_SET_INIT_STATUS_INSUFFICIENT_MEMORY: |
| 552 | chunk_printf(temp, "Insufficient memory."); |
| 553 | break; |
| 554 | case DATA_SET_INIT_STATUS_CORRUPT_DATA: |
| 555 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
| 556 | chunk_printf(temp, "Corrupt data file. Check that the data file provided is uncompressed and Pattern data format."); |
| 557 | #endif |
| 558 | #ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED |
| 559 | chunk_printf(temp, "Corrupt data file. Check that the data file provided is uncompressed and Trie data format."); |
| 560 | #endif |
| 561 | break; |
| 562 | case DATA_SET_INIT_STATUS_INCORRECT_VERSION: |
| 563 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
| 564 | chunk_printf(temp, "Incorrect version. Check that the data file provided is uncompressed and Pattern data format."); |
| 565 | #endif |
| 566 | #ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED |
| 567 | chunk_printf(temp, "Incorrect version. Check that the data file provided is uncompressed and Trie data format."); |
| 568 | #endif |
| 569 | break; |
| 570 | case DATA_SET_INIT_STATUS_FILE_NOT_FOUND: |
| 571 | chunk_printf(temp, "File not found."); |
| 572 | break; |
ben51degrees | 1f077eb | 2016-07-06 12:07:21 +0100 | [diff] [blame] | 573 | case DATA_SET_INIT_STATUS_NULL_POINTER: |
| 574 | chunk_printf(temp, "Null pointer to the existing dataset or memory location."); |
| 575 | break; |
| 576 | case DATA_SET_INIT_STATUS_POINTER_OUT_OF_BOUNDS: |
| 577 | chunk_printf(temp, "Allocated continuous memory containing 51Degrees data file appears to be smaller than expected. Most likely" |
| 578 | " because the data file was not fully loaded into the allocated memory."); |
| 579 | break; |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 580 | case DATA_SET_INIT_STATUS_NOT_SET: |
| 581 | chunk_printf(temp, "Data set not initialised."); |
| 582 | break; |
| 583 | } |
| 584 | if (_51d_dataset_status != DATA_SET_INIT_STATUS_SUCCESS) { |
| 585 | if (temp->len) |
| 586 | Alert("51Degrees Setup - Error reading 51Degrees data file. %s\n", temp->str); |
| 587 | else |
| 588 | Alert("51Degrees Setup - Error reading 51Degrees data file.\n"); |
Willy Tarreau | 9f3f254 | 2016-12-21 20:30:05 +0100 | [diff] [blame^] | 589 | return ERR_ALERT | ERR_FATAL; |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 590 | } |
| 591 | free(_51d_property_list); |
| 592 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 593 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 594 | _51d_lru_seed = random(); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 595 | if (global._51degrees.cache_size) { |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 596 | _51d_lru_tree = lru64_new(global._51degrees.cache_size); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 597 | } |
| 598 | #endif |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 599 | |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | void deinit_51degrees(void) |
| 604 | { |
| 605 | struct _51d_property_names *_51d_prop_name, *_51d_prop_nameb; |
| 606 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 607 | free(global._51degrees.header_names); |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 608 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 609 | fiftyoneDegreesWorksetPoolFree(global._51degrees.pool); |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 610 | #endif |
| 611 | #ifdef FIFTYONEDEGREES_H_TRIE_INCLUDED |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 612 | free(global._51degrees.device_offsets.firstOffset); |
| 613 | free(global._51degrees.header_offsets); |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 614 | #endif |
ben51degrees | 1f077eb | 2016-07-06 12:07:21 +0100 | [diff] [blame] | 615 | fiftyoneDegreesDataSetFree(&global._51degrees.data_set); |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 616 | |
| 617 | free(global._51degrees.data_file_path); global._51degrees.data_file_path = NULL; |
| 618 | list_for_each_entry_safe(_51d_prop_name, _51d_prop_nameb, &global._51degrees.property_names, list) { |
| 619 | LIST_DEL(&_51d_prop_name->list); |
| 620 | free(_51d_prop_name); |
| 621 | } |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 622 | |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 623 | #ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 624 | while (lru64_destroy(_51d_lru_tree)); |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 625 | #endif |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | static struct cfg_kw_list _51dcfg_kws = {{ }, { |
| 629 | { CFG_GLOBAL, "51degrees-data-file", _51d_data_file }, |
| 630 | { CFG_GLOBAL, "51degrees-property-name-list", _51d_property_name_list }, |
| 631 | { CFG_GLOBAL, "51degrees-property-separator", _51d_property_separator }, |
Dragan Dosen | 105c8e6 | 2015-06-29 16:43:26 +0200 | [diff] [blame] | 632 | { CFG_GLOBAL, "51degrees-cache-size", _51d_cache_size }, |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 633 | { 0, NULL, NULL }, |
| 634 | }}; |
| 635 | |
| 636 | /* Note: must not be declared <const> as its list will be overwritten */ |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 637 | static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { |
| 638 | { "51d.all", _51d_fetch, ARG5(1,STR,STR,STR,STR,STR), _51d_fetch_check, SMP_T_STR, SMP_USE_HRQHV }, |
| 639 | { NULL, NULL, 0, 0, 0 }, |
| 640 | }}; |
| 641 | |
| 642 | /* Note: must not be declared <const> as its list will be overwritten */ |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 643 | static struct sample_conv_kw_list conv_kws = {ILH, { |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 644 | { "51d.single", _51d_conv, ARG5(1,STR,STR,STR,STR,STR), _51d_conv_check, SMP_T_STR, SMP_T_STR }, |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 645 | { NULL, NULL, 0, 0, 0 }, |
| 646 | }}; |
| 647 | |
| 648 | __attribute__((constructor)) |
| 649 | static void __51d_init(void) |
| 650 | { |
James Rosewell | a28bbd5 | 2015-09-18 18:28:52 +0100 | [diff] [blame] | 651 | /* register sample fetch and conversion keywords */ |
| 652 | sample_register_fetches(&sample_fetch_keywords); |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 653 | sample_register_convs(&conv_kws); |
| 654 | cfg_register_keywords(&_51dcfg_kws); |
Willy Tarreau | b5e58d6 | 2016-12-21 18:49:29 +0100 | [diff] [blame] | 655 | hap_register_build_opts("Built with 51Degrees support.", 0); |
Willy Tarreau | 9f3f254 | 2016-12-21 20:30:05 +0100 | [diff] [blame^] | 656 | hap_register_post_check(init_51degrees); |
Dragan Dosen | 93b38d9 | 2015-06-29 16:43:25 +0200 | [diff] [blame] | 657 | } |