OBJS = src/mux_h2.o src/stream.o src/mux_fcgi.o src/cfgparse-listen.o \
src/http_ana.o src/stats.o src/mux_h1.o src/flt_spoe.o src/server.o \
src/cfgparse.o src/checks.o src/backend.o src/log.o src/peers.o \
- src/cli.o src/haproxy.o src/stick_table.o src/standard.o src/sample.o \
+ src/cli.o src/haproxy.o src/stick_table.o src/tools.o src/sample.o \
src/proxy.o src/stream_interface.o src/pattern.o src/dns.o \
src/proto_tcp.o src/listener.o src/cfgparse-global.o src/h1.o \
src/http_rules.o src/http_fetch.o src/cache.o src/session.o \
#include <stdarg.h>
#include <haproxy/api.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/chunk.h>
#include <haproxy/time.h>
--- /dev/null
+/*
+ * include/haproxy/tools-t.h
+ * This files contains some general purpose macros and structures.
+ *
+ * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _HAPROXY_TOOLS_T_H
+#define _HAPROXY_TOOLS_T_H
+
+/* size used for max length of decimal representation of long long int. */
+#define NB_LLMAX_STR (sizeof("-9223372036854775807")-1)
+
+/* number of itoa_str entries */
+#define NB_ITOA_STR 16
+
+/* maximum quoted string length (truncated above) */
+#define QSTR_SIZE 200
+#define NB_QSTR 10
+
+/* returns 1 only if only zero or one bit is set in X, which means that X is a
+ * power of 2, and 0 otherwise */
+#define POWEROF2(x) (((x) & ((x)-1)) == 0)
+
+/* return an integer of type <ret> with only the highest bit set. <ret> may be
+ * both a variable or a type.
+ */
+#define MID_RANGE(ret) ((typeof(ret))1 << (8*sizeof(ret) - 1))
+
+/* return the largest possible integer of type <ret>, with all bits set */
+#define MAX_RANGE(ret) (~(typeof(ret))0)
+
+/* DEFNULL() returns either the argument as-is, or NULL if absent. This is for
+ * use in macros arguments.
+ */
+#define DEFNULL(...) _FIRST_ARG(NULL, ##__VA_ARGS__, NULL)
+#define _FIRST_ARG(a, b, ...) b
+
+/* special return values for the time parser (parse_time_err()) */
+#define PARSE_TIME_UNDER ((char *)1)
+#define PARSE_TIME_OVER ((char *)2)
+
+/* unit flags to pass to parse_time_err() */
+#define TIME_UNIT_US 0x0000
+#define TIME_UNIT_MS 0x0001
+#define TIME_UNIT_S 0x0002
+#define TIME_UNIT_MIN 0x0003
+#define TIME_UNIT_HOUR 0x0004
+#define TIME_UNIT_DAY 0x0005
+#define TIME_UNIT_MASK 0x0007
+
+#define SEC 1
+#define MINUTE (60 * SEC)
+#define HOUR (60 * MINUTE)
+#define DAY (24 * HOUR)
+
+/* UTF-8 decoder status */
+#define UTF8_CODE_OK 0x00
+#define UTF8_CODE_OVERLONG 0x10
+#define UTF8_CODE_INVRANGE 0x20
+#define UTF8_CODE_BADSEQ 0x40
+
+/* HAP_STRING() makes a string from a literal while HAP_XSTRING() first
+ * evaluates the argument and is suited to pass macros.
+ *
+ * They allow macros like PCRE_MAJOR to be defined without quotes, which
+ * is convenient for applications that want to test its value.
+ */
+#define HAP_STRING(...) #__VA_ARGS__
+#define HAP_XSTRING(...) HAP_STRING(__VA_ARGS__)
+
+/* operators to compare values. They're ordered that way so that the lowest bit
+ * serves as a negation for the test and contains all tests that are not equal.
+ */
+enum {
+ STD_OP_LE = 0, STD_OP_GT = 1,
+ STD_OP_EQ = 2, STD_OP_NE = 3,
+ STD_OP_GE = 4, STD_OP_LT = 5,
+};
+
+enum http_scheme {
+ SCH_HTTP,
+ SCH_HTTPS,
+};
+
+/* output format used by url2sa() */
+struct split_url {
+ enum http_scheme scheme;
+ const char *host;
+ int host_len;
+};
+
+/* generic structure associating a name and a value, for use in arrays */
+struct name_desc {
+ const char *name;
+ const char *desc;
+};
+
+#endif /* _HAPROXY_TOOLS_T_H */
/*
- * include/common/standard.h
+ * include/haproxy/tools.h
* This files contains some general purpose functions and macros.
*
- * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
+ * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef _COMMON_STANDARD_H
-#define _COMMON_STANDARD_H
+#ifndef _HAPROXY_TOOLS_H
+#define _HAPROXY_TOOLS_H
#ifdef USE_BACKTRACE
#define _GNU_SOURCE
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <import/eb32tree.h>
+#include <import/eb32sctree.h>
#include <haproxy/api.h>
#include <haproxy/intops.h>
#include <haproxy/chunk.h>
#include <haproxy/namespace-t.h>
-#include <import/eb32tree.h>
-#include <import/eb32sctree.h>
#include <haproxy/protocol-t.h>
-
-/* size used for max length of decimal representation of long long int. */
-#define NB_LLMAX_STR (sizeof("-9223372036854775807")-1)
-
-/* number of itoa_str entries */
-#define NB_ITOA_STR 16
-
-/* maximum quoted string length (truncated above) */
-#define QSTR_SIZE 200
-#define NB_QSTR 10
+#include <haproxy/tools-t.h>
/****** string-specific macros and functions ******/
/* if a > max, then bound <a> to <max>. The macro returns the new <a> */
/* if a < min, then bound <a> to <min>. The macro returns the new <a> */
#define LBOUND(a, min) ({ typeof(a) b = (min); if ((a) < b) (a) = b; (a); })
-/* returns 1 only if only zero or one bit is set in X, which means that X is a
- * power of 2, and 0 otherwise */
-#define POWEROF2(x) (((x) & ((x)-1)) == 0)
-
#define SWAP(a, b) do { typeof(a) t; t = a; a = b; b = t; } while(0)
-/* return an integer of type <ret> with only the highest bit set. <ret> may be
- * both a variable or a type.
- */
-#define MID_RANGE(ret) ((typeof(ret))1 << (8*sizeof(ret) - 1))
-
-/* return the largest possible integer of type <ret>, with all bits set */
-#define MAX_RANGE(ret) (~(typeof(ret))0)
-
-/* DEFNULL() returns either the argument as-is, or NULL if absent. This is for
- * use in macros arguments.
- */
-#define DEFNULL(...) _FIRST_ARG(NULL, ##__VA_ARGS__, NULL)
-#define _FIRST_ARG(a, b, ...) b
-
-/* operators to compare values. They're ordered that way so that the lowest bit
- * serves as a negation for the test and contains all tests that are not equal.
- */
-enum {
- STD_OP_LE = 0, STD_OP_GT = 1,
- STD_OP_EQ = 2, STD_OP_NE = 3,
- STD_OP_GE = 4, STD_OP_LT = 5,
-};
-
-enum http_scheme {
- SCH_HTTP,
- SCH_HTTPS,
-};
-
-struct split_url {
- enum http_scheme scheme;
- const char *host;
- int host_len;
-};
-
-/* generic structure associating a name and a value, for use in arrays */
-struct name_desc {
- const char *name;
- const char *desc;
-};
-
extern THREAD_LOCAL int itoa_idx; /* index of next itoa_str to use */
/*
extern const char *parse_time_err(const char *text, unsigned *ret, unsigned unit_flags);
extern const char *parse_size_err(const char *text, unsigned *ret);
-/* special return values for the time parser */
-#define PARSE_TIME_UNDER ((char *)1)
-#define PARSE_TIME_OVER ((char *)2)
-
-/* unit flags to pass to parse_time_err */
-#define TIME_UNIT_US 0x0000
-#define TIME_UNIT_MS 0x0001
-#define TIME_UNIT_S 0x0002
-#define TIME_UNIT_MIN 0x0003
-#define TIME_UNIT_HOUR 0x0004
-#define TIME_UNIT_DAY 0x0005
-#define TIME_UNIT_MASK 0x0007
-
-#define SEC 1
-#define MINUTE (60 * SEC)
-#define HOUR (60 * MINUTE)
-#define DAY (24 * HOUR)
-
/*
* Parse binary string written in hexadecimal (source) and store the decoded
* result into binstr and set binstrlen to the length of binstr. Memory for
return caddr & ~(unsigned long)(data & 3);
}
-/* UTF-8 decoder status */
-#define UTF8_CODE_OK 0x00
-#define UTF8_CODE_OVERLONG 0x10
-#define UTF8_CODE_INVRANGE 0x20
-#define UTF8_CODE_BADSEQ 0x40
-
unsigned char utf8_next(const char *s, int len, unsigned int *c);
static inline unsigned char utf8_return_code(unsigned int code)
return ha_random32() >> 1;
}
-/* HAP_STRING() makes a string from a literal while HAP_XSTRING() first
- * evaluates the argument and is suited to pass macros.
- *
- * They allow macros like PCRE_MAJOR to be defined without quotes, which
- * is convenient for applications that want to test its value.
- */
-#define HAP_STRING(...) #__VA_ARGS__
-#define HAP_XSTRING(...) HAP_STRING(__VA_ARGS__)
-
-#endif /* _COMMON_STANDARD_H */
+#endif /* _HAPROXY_TOOLS_H */
#ifndef _PROTO_STATS_H
#define _PROTO_STATS_H
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/api.h>
#include <types/applet.h>
#include <types/stream_interface.h>
#define _PROTO_STICK_TABLE_H
#include <haproxy/errors.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/ticks.h>
#include <haproxy/time.h>
#include <types/stick_table.h>
#define _PROTO_TRACE_H
#include <haproxy/api.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <import/ist.h>
#include <haproxy/list.h>
#include <types/log.h>
#include <haproxy/api.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <common/uri_auth.h>
#include <types/global.h>
#include <haproxy/api.h>
#include <haproxy/pool.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <proto/action.h>
#include <proto/log.h>
#include <haproxy/api.h>
#include <common/cfgparse.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/thread-t.h>
#include <haproxy/activity-t.h>
#include <proto/channel.h>
#include <sys/socket.h>
#include <arpa/inet.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/chunk.h>
#include <types/global.h>
#include <proto/arg.h>
#include <haproxy/chunk.h>
#include <haproxy/errors.h>
#include <haproxy/pool.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <common/uri_auth.h>
#include <haproxy/namespace.h>
#include <haproxy/istbuf.h>
#include <haproxy/list.h>
#include <haproxy/regex.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <haproxy/thread.h>
#include <haproxy/http.h>
#include <haproxy/api.h>
#include <haproxy/chunk.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/global.h>
#include <haproxy/api.h>
#include <common/cfgparse.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/ticks.h>
#include <haproxy/time.h>
#include <common/uri_auth.h>
#include <haproxy/thread.h>
#include <import/ist.h>
#include <haproxy/net_helper.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/global.h>
#include <types/signal.h>
#include <haproxy/api.h>
#include <haproxy/thread-t.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/ticks.h>
#include <haproxy/time.h>
#include <common/cfgparse.h>
#include <haproxy/errors.h>
#include <haproxy/regex.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/global.h>
#include <haproxy/errors.h>
#include <haproxy/htx.h>
#include <haproxy/namespace.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/filters.h>
#include <types/http_ana.h>
#include <common/cfgparse.h>
#include <haproxy/htx.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/compression.h>
#include <types/filters.h>
#include <haproxy/api.h>
#include <haproxy/htx.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <types/channel.h>
*/
#include <haproxy/api.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <haproxy/freq_ctr.h>
#include <haproxy/api.h>
#include <haproxy/chunk.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <types/global.h>
#include <haproxy/net_helper.h>
#include <haproxy/openssl-compat.h>
#include <haproxy/regex.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <common/uri_auth.h>
#include <haproxy/version.h>
#include <haproxy/regex.h>
#include <haproxy/xref.h>
#include <haproxy/h1.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/cli.h>
#include <types/hlua.h>
#include <stdlib.h>
#include <string.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/hpack-dec.h>
#include <haproxy/hpack-huff.h>
#include <haproxy/hpack-tbl.h>
#include <ctype.h>
#include <haproxy/api.h>
#include <haproxy/http.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
/* It is about twice as fast on recent architectures to lookup a byte in a
* table than to perform a boolean AND or OR between two tests. Refer to
#include <haproxy/chunk.h>
#include <haproxy/http.h>
#include <haproxy/pool.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/version.h>
#include <types/global.h>
#include <haproxy/http.h>
#include <haproxy/pool.h>
#include <haproxy/regex.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <common/uri_auth.h>
#include <haproxy/version.h>
#include <haproxy/chunk.h>
#include <haproxy/http.h>
#include <haproxy/pool.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/version.h>
#include <types/capture.h>
#include <haproxy/http.h>
#include <haproxy/htx.h>
#include <haproxy/pool.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/version.h>
#include <types/global.h>
#include <haproxy/chunk.h>
#include <haproxy/http.h>
#include <haproxy/pool.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/version.h>
#include <types/capture.h>
*/
#include <haproxy/api.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <import/eb32tree.h>
#include <types/global.h>
#include <common/cfgparse.h>
#include <haproxy/errors.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <types/global.h>
#include <haproxy/api.h>
#include <haproxy/http.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <haproxy/version.h>
#include <haproxy/api.h>
#include <haproxy/regex.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/applet.h>
#include <types/cli.h>
#include <haproxy/api.h>
#include <haproxy/net_helper.h>
#include <haproxy/regex.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/global.h>
#include <types/pattern.h>
#include <haproxy/api.h>
#include <haproxy/net_helper.h>
#include <haproxy/time.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/thread.h>
#include <types/global.h>
#include <haproxy/thread.h>
#include <haproxy/pool.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/activity-t.h>
#include <haproxy/api.h>
#include <haproxy/errors.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <haproxy/version.h>
#include <haproxy/api.h>
#include <haproxy/errors.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/namespace.h>
#include <types/action.h>
#include <haproxy/api.h>
#include <haproxy/errors.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <haproxy/version.h>
#include <haproxy/api.h>
#include <haproxy/errors.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/protocol.h>
#include <haproxy/api.h>
#include <haproxy/buf.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/ticks.h>
#include <haproxy/time.h>
#include <haproxy/api.h>
#include <types/global.h>
#include <haproxy/regex.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <proto/log.h>
/* regex trash buffer used by various regex tests */
#include <haproxy/http.h>
#include <haproxy/net_helper.h>
#include <haproxy/regex.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <common/uri_auth.h>
#include <haproxy/base64.h>
#include <haproxy/base64.h>
#include <haproxy/errors.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <import/ebsttree.h>
#include <sys/types.h>
#include <haproxy/errors.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <dirent.h>
#include <import/ebpttree.h>
#include <haproxy/api.h>
#include <haproxy/buf-t.h>
#include <haproxy/openssl-compat.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/sample.h>
#include <types/ssl_sock.h>
#include <haproxy/chunk.h>
#include <haproxy/errors.h>
#include <haproxy/openssl-compat.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/ticks.h>
#include <haproxy/time.h>
#include <haproxy/base64.h>
#include <haproxy/htx.h>
#include <haproxy/pool.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/ticks.h>
#include <haproxy/time.h>
#include <common/uri_auth.h>
#include <haproxy/pool.h>
#include <haproxy/list.h>
#include <haproxy/net_helper.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <import/ebmbtree.h>
#include <haproxy/api.h>
#include <haproxy/dynbuf.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/ticks.h>
#include <haproxy/time.h>
#include <haproxy/api.h>
#include <haproxy/pool.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <import/eb32sctree.h>
#include <import/eb32tree.h>
#include <haproxy/api.h>
#include <common/cfgparse.h>
#include <haproxy/list.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/ticks.h>
#include <haproxy/time.h>
#include <common/cfgparse.h>
#include <haproxy/thread.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/global.h>
#include <proto/fd.h>
#include <sys/time.h>
#include <haproxy/api.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <haproxy/time.h>
#include <haproxy/thread-t.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <import/eb32tree.h>
+#include <import/eb32sctree.h>
+
#include <haproxy/api.h>
#include <haproxy/chunk.h>
#include <haproxy/namespace.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/global.h>
#include <proto/applet.h>
#include <proto/dns.h>
#include <proto/stream_interface.h>
#include <proto/task.h>
-#include <import/eb32tree.h>
-#include <import/eb32sctree.h>
-
/* This macro returns false if the test __x is false. Many
* of the following parsing function must be abort the processing
* if it returns 0, so this macro is useful for writing light code.
#include <haproxy/api.h>
#include <haproxy/debug.h>
#include <haproxy/thread.h>
-#include <common/standard.h>
+#include <haproxy/tools.h>
#include <types/global.h>
#include <types/signal.h>
#include <proto/log.h>