blob: e9f9e25121b04b3d3825b4f4bd4c94f3bc0aedb9 [file] [log] [blame]
Emeric Brun107ca302010-01-04 16:16:05 +01001/*
Willy Tarreaucd3b0942012-04-27 21:52:18 +02002 * include/proto/sample.h
3 * Functions for samples management.
Emeric Brun107ca302010-01-04 16:16:05 +01004 *
5 * Copyright (C) 2009-2010 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
Willy Tarreaucd3b0942012-04-27 21:52:18 +02006 * Copyright (C) 2012 Willy Tarreau <w@1wt.eu>
Emeric Brun107ca302010-01-04 16:16:05 +01007 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation, version 2.1
11 * exclusively.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
Willy Tarreaucd3b0942012-04-27 21:52:18 +020023#ifndef _PROTO_SAMPLE_H
24#define _PROTO_SAMPLE_H
Emeric Brun107ca302010-01-04 16:16:05 +010025
Willy Tarreaucd3b0942012-04-27 21:52:18 +020026#include <types/sample.h>
Emeric Brun107ca302010-01-04 16:16:05 +010027#include <types/stick_table.h>
28
Willy Tarreau1cf8f082014-02-07 12:14:54 +010029extern const char *smp_to_type[SMP_TYPES];
30
Thierry FOURNIEReeaa9512014-02-11 14:00:19 +010031struct sample_expr *sample_parse_expr(char **str, int *idx, const char *file, int line, char **err, struct arg_list *al);
Thierry FOURNIER20f49962013-11-21 10:51:50 +010032struct sample_conv *find_sample_conv(const char *kw, int len);
Willy Tarreau87b09662015-04-03 00:22:06 +020033struct sample *sample_process(struct proxy *px, struct stream *l4,
Willy Tarreau12785782012-04-27 21:37:17 +020034 void *l7, unsigned int dir, struct sample_expr *expr,
Willy Tarreaub4a88f02012-04-23 21:35:11 +020035 struct sample *p);
Willy Tarreau87b09662015-04-03 00:22:06 +020036struct sample *sample_fetch_string(struct proxy *px, struct stream *l4, void *l7,
Willy Tarreaue7ad4bb2012-12-21 00:02:32 +010037 unsigned int opt, struct sample_expr *expr);
Willy Tarreau12785782012-04-27 21:37:17 +020038void sample_register_fetches(struct sample_fetch_kw_list *psl);
39void sample_register_convs(struct sample_conv_kw_list *psl);
Willy Tarreau80aca902013-01-07 15:42:20 +010040const char *sample_src_names(unsigned int use);
Willy Tarreaua91d0a52013-03-25 08:12:18 +010041const char *sample_ckp_names(unsigned int use);
Willy Tarreau8ed669b2013-01-11 15:49:37 +010042struct sample_fetch *find_sample_fetch(const char *kw, int len);
Thierry FOURNIER4d9a1d12014-12-08 14:49:19 +010043struct sample_fetch *sample_fetch_getnext(struct sample_fetch *current, int *idx);
Thierry FOURNIER8fd13762015-03-10 23:56:48 +010044struct sample_conv *sample_conv_getnext(struct sample_conv *current, int *idx);
Willy Tarreaua4312fa2013-04-02 16:34:32 +020045int smp_resolve_args(struct proxy *p);
Thierry FOURNIER348971e2013-11-21 10:50:10 +010046int smp_expr_output_type(struct sample_expr *expr);
Thierry FOURNIER0e9af552013-12-14 14:55:04 +010047int c_none(struct sample *smp);
Thierry FOURNIER7654c9f2013-12-17 00:20:33 +010048int smp_dup(struct sample *smp);
Willy Tarreaucd3b0942012-04-27 21:52:18 +020049
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010050/*
51 * This function just apply a cast on sample. It returns 0 if the cast is not
52 * avalaible or if the cast fails, otherwise returns 1. It does not modify the
53 * input sample on failure.
54 */
55static inline
56int sample_convert(struct sample *sample, int req_type)
57{
58 if (!sample_casts[sample->type][req_type])
59 return 0;
Thierry FOURNIER0e9af552013-12-14 14:55:04 +010060 if (sample_casts[sample->type][req_type] == c_none)
61 return 1;
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010062 return sample_casts[sample->type][req_type](sample);
63}
64
Willy Tarreaucd3b0942012-04-27 21:52:18 +020065#endif /* _PROTO_SAMPLE_H */