From cd72d8c9813c0876866502f16cfab672346e093d Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 2 Jun 2020 19:11:26 +0200 Subject: [PATCH] REORG: include: split common/http.h into haproxy/http{,-t}.h So the enums and structs were placed into http-t.h and the functions into http.h. This revealed that several files were dependeng on http.h but not including it, as it was silently inherited via other files. --- .../prometheus-exporter/service-prometheus.c | 1 + include/common/h1.h | 2 +- include/common/hpack-enc.h | 2 +- include/common/htx.h | 2 +- include/{common/http.h => haproxy/http-t.h} | 90 ++------------ include/haproxy/http.h | 115 ++++++++++++++++++ include/types/http_ana.h | 2 +- include/types/http_htx.h | 2 +- include/types/proxy.h | 2 +- include/types/sample.h | 2 +- src/backend.c | 1 + src/checks.c | 2 +- src/da.c | 2 +- src/flt_http_comp.c | 1 + src/h1_htx.c | 2 +- src/h2.c | 1 + src/hlua_fcn.c | 1 + src/http.c | 2 +- src/http_acl.c | 2 +- src/http_act.c | 2 +- src/http_ana.c | 1 + src/http_conv.c | 2 +- src/http_fetch.c | 2 +- src/http_htx.c | 2 +- src/http_rules.c | 2 +- src/log.c | 1 + src/sample.c | 2 +- src/session.c | 2 +- src/stats.c | 2 +- src/vars.c | 2 +- 30 files changed, 150 insertions(+), 104 deletions(-) rename include/{common/http.h => haproxy/http-t.h} (56%) create mode 100644 include/haproxy/http.h diff --git a/contrib/prometheus-exporter/service-prometheus.c b/contrib/prometheus-exporter/service-prometheus.c index fe2520d62b..a07727e2e9 100644 --- a/contrib/prometheus-exporter/service-prometheus.c +++ b/contrib/prometheus-exporter/service-prometheus.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include diff --git a/include/common/h1.h b/include/common/h1.h index 205a25ce25..7c341fe931 100644 --- a/include/common/h1.h +++ b/include/common/h1.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/common/hpack-enc.h b/include/common/hpack-enc.h index 7d73b35648..ede8d28453 100644 --- a/include/common/hpack-enc.h +++ b/include/common/hpack-enc.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include int hpack_encode_header(struct buffer *out, const struct ist n, diff --git a/include/common/htx.h b/include/common/htx.h index 664aaca9ed..3c3ac0bf3b 100644 --- a/include/common/htx.h +++ b/include/common/htx.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include /* diff --git a/include/common/http.h b/include/haproxy/http-t.h similarity index 56% rename from include/common/http.h rename to include/haproxy/http-t.h index 0173b7acb4..c8bf9a3084 100644 --- a/include/common/http.h +++ b/include/haproxy/http-t.h @@ -1,9 +1,9 @@ /* - * include/common/http.h + * include/haproxy/http-t.h * * Version-agnostic and implementation-agnostic HTTP protocol definitions. * - * Copyright (C) 2000-2018 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 @@ -20,11 +20,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _COMMON_HTTP_H -#define _COMMON_HTTP_H +#ifndef _HAPROXY_HTTP_T_H +#define _HAPROXY_HTTP_T_H -#include +#include #include +#include /* * some macros mainly used when parsing header fields. @@ -122,84 +123,7 @@ struct http_method_desc { const struct ist text; }; -extern const int http_err_codes[HTTP_ERR_SIZE]; -extern const char *http_err_msgs[HTTP_ERR_SIZE]; -extern const struct ist http_known_methods[HTTP_METH_OTHER]; -extern const uint8_t http_char_classes[256]; - -enum http_meth_t find_http_meth(const char *str, const int len); -int http_get_status_idx(unsigned int status); -const char *http_get_reason(unsigned int status); -struct ist http_get_authority(const struct ist uri, int no_userinfo); -struct ist http_get_path(const struct ist uri); -int http_header_match2(const char *hdr, const char *end, - const char *name, int len); -char *http_find_hdr_value_end(char *s, const char *e); -char *http_find_cookie_value_end(char *s, const char *e); -char *http_extract_cookie_value(char *hdr, const char *hdr_end, - char *cookie_name, size_t cookie_name_l, - int list, char **value, size_t *value_l); -int http_parse_qvalue(const char *qvalue, const char **end); -const char *http_find_url_param_pos(const char **chunks, - const char* url_param_name, - size_t url_param_name_l, char delim); -int http_find_next_url_param(const char **chunks, - const char* url_param_name, size_t url_param_name_l, - const char **vstart, const char **vend, char delim); - -int http_parse_header(const struct ist hdr, struct ist *name, struct ist *value); -int http_parse_stline(const struct ist line, struct ist *p1, struct ist *p2, struct ist *p3); -int http_parse_status_val(const struct ist value, struct ist *status, struct ist *reason); - -/* - * Given a path string and its length, find the position of beginning of the - * query string. Returns NULL if no query string is found in the path. - * - * Example: if path = "/foo/bar/fubar?yo=mama;ye=daddy", and n = 22: - * - * find_query_string(path, n, '?') points to "yo=mama;ye=daddy" string. - */ -static inline char *http_find_param_list(char *path, size_t path_l, char delim) -{ - char *p; - - p = memchr(path, delim, path_l); - return p ? p + 1 : NULL; -} - -static inline int http_is_param_delimiter(char c, char delim) -{ - return c == '&' || c == ';' || c == delim; -} - -/* Match language range with language tag. RFC2616 14.4: - * - * A language-range matches a language-tag if it exactly equals - * the tag, or if it exactly equals a prefix of the tag such - * that the first tag character following the prefix is "-". - * - * Return 1 if the strings match, else return 0. - */ -static inline int http_language_range_match(const char *range, int range_len, - const char *tag, int tag_len) -{ - const char *end = range + range_len; - const char *tend = tag + tag_len; - - while (range < end) { - if (*range == '-' && tag == tend) - return 1; - if (*range != *tag || tag == tend) - return 0; - range++; - tag++; - } - /* Return true only if the last char of the tag is matched. */ - return tag == tend; -} - - -#endif /* _COMMON_HTTP_H */ +#endif /* _HAPROXY_HTTP_T_H */ /* * Local variables: diff --git a/include/haproxy/http.h b/include/haproxy/http.h new file mode 100644 index 0000000000..64ac4bcece --- /dev/null +++ b/include/haproxy/http.h @@ -0,0 +1,115 @@ +/* + * include/haproxy/http.h + * + * Functions for version-agnostic and implementation-agnostic HTTP protocol. + * + * 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_HTTP_H +#define _HAPROXY_HTTP_H + +#include +#include +#include +#include + +extern const int http_err_codes[HTTP_ERR_SIZE]; +extern const char *http_err_msgs[HTTP_ERR_SIZE]; +extern const struct ist http_known_methods[HTTP_METH_OTHER]; +extern const uint8_t http_char_classes[256]; + +enum http_meth_t find_http_meth(const char *str, const int len); +int http_get_status_idx(unsigned int status); +const char *http_get_reason(unsigned int status); +struct ist http_get_authority(const struct ist uri, int no_userinfo); +struct ist http_get_path(const struct ist uri); +int http_header_match2(const char *hdr, const char *end, + const char *name, int len); +char *http_find_hdr_value_end(char *s, const char *e); +char *http_find_cookie_value_end(char *s, const char *e); +char *http_extract_cookie_value(char *hdr, const char *hdr_end, + char *cookie_name, size_t cookie_name_l, + int list, char **value, size_t *value_l); +int http_parse_qvalue(const char *qvalue, const char **end); +const char *http_find_url_param_pos(const char **chunks, + const char* url_param_name, + size_t url_param_name_l, char delim); +int http_find_next_url_param(const char **chunks, + const char* url_param_name, size_t url_param_name_l, + const char **vstart, const char **vend, char delim); + +int http_parse_header(const struct ist hdr, struct ist *name, struct ist *value); +int http_parse_stline(const struct ist line, struct ist *p1, struct ist *p2, struct ist *p3); +int http_parse_status_val(const struct ist value, struct ist *status, struct ist *reason); + +/* + * Given a path string and its length, find the position of beginning of the + * query string. Returns NULL if no query string is found in the path. + * + * Example: if path = "/foo/bar/fubar?yo=mama;ye=daddy", and n = 22: + * + * find_query_string(path, n, '?') points to "yo=mama;ye=daddy" string. + */ +static inline char *http_find_param_list(char *path, size_t path_l, char delim) +{ + char *p; + + p = memchr(path, delim, path_l); + return p ? p + 1 : NULL; +} + +static inline int http_is_param_delimiter(char c, char delim) +{ + return c == '&' || c == ';' || c == delim; +} + +/* Match language range with language tag. RFC2616 14.4: + * + * A language-range matches a language-tag if it exactly equals + * the tag, or if it exactly equals a prefix of the tag such + * that the first tag character following the prefix is "-". + * + * Return 1 if the strings match, else return 0. + */ +static inline int http_language_range_match(const char *range, int range_len, + const char *tag, int tag_len) +{ + const char *end = range + range_len; + const char *tend = tag + tag_len; + + while (range < end) { + if (*range == '-' && tag == tend) + return 1; + if (*range != *tag || tag == tend) + return 0; + range++; + tag++; + } + /* Return true only if the last char of the tag is matched. */ + return tag == tend; +} + + +#endif /* _HAPROXY_HTTP_H */ + +/* + * Local variables: + * c-indent-level: 8 + * c-basic-offset: 8 + * End: + */ diff --git a/include/types/http_ana.h b/include/types/http_ana.h index 7bade13039..4a1a9cdcef 100644 --- a/include/types/http_ana.h +++ b/include/types/http_ana.h @@ -23,7 +23,7 @@ #define _TYPES_PROTO_HTTP_H #include -#include +#include #include #include diff --git a/include/types/http_htx.h b/include/types/http_htx.h index 4123e7e7cb..2f6b10b52c 100644 --- a/include/types/http_htx.h +++ b/include/types/http_htx.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include diff --git a/include/types/proxy.h b/include/types/proxy.h index 2e6a26cd84..2019de8050 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include diff --git a/include/types/sample.h b/include/types/sample.h index 618be08bf2..0bec0c4f90 100644 --- a/include/types/sample.h +++ b/include/types/sample.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include struct arg; diff --git a/src/backend.c b/src/backend.c index a002bbe0ae..6d85967350 100644 --- a/src/backend.c +++ b/src/backend.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include diff --git a/src/checks.c b/src/checks.c index 2374f65e7e..b0d677621e 100644 --- a/src/checks.c +++ b/src/checks.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/da.c b/src/da.c index c783fb1522..51f6e38234 100644 --- a/src/da.c +++ b/src/da.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index 4b0e546ab6..5f0853a6d2 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include diff --git a/src/h1_htx.c b/src/h1_htx.c index 6e582e3898..83ebfb1a15 100644 --- a/src/h1_htx.c +++ b/src/h1_htx.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/h2.c b/src/h2.c index c94ea8e034..fa72e1c902 100644 --- a/src/h2.c +++ b/src/h2.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index 53a2b4039a..b759f11dec 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include diff --git a/src/http.c b/src/http.c index 0bd8f87ffb..ae315a8287 100644 --- a/src/http.c +++ b/src/http.c @@ -12,7 +12,7 @@ #include #include -#include +#include #include /* It is about twice as fast on recent architectures to lookup a byte in a diff --git a/src/http_acl.c b/src/http_acl.c index 368a4b113c..780962af26 100644 --- a/src/http_acl.c +++ b/src/http_acl.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/http_act.c b/src/http_act.c index 4193b91c10..a5ce9d780f 100644 --- a/src/http_act.c +++ b/src/http_act.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/http_ana.c b/src/http_ana.c index 9f65082777..d89bcf54b3 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include diff --git a/src/http_conv.c b/src/http_conv.c index 8937fa0b8c..72cb4af68f 100644 --- a/src/http_conv.c +++ b/src/http_conv.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/http_fetch.c b/src/http_fetch.c index 8fe22b8cc5..2d99642821 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/http_htx.c b/src/http_htx.c index af8758c992..ede8a0ea21 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include diff --git a/src/http_rules.c b/src/http_rules.c index 96508e9a84..94aff63c79 100644 --- a/src/http_rules.c +++ b/src/http_rules.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/log.c b/src/log.c index d4f49226c8..5778994b77 100644 --- a/src/log.c +++ b/src/log.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/src/sample.c b/src/sample.c index 14615a1ba1..380dd6fb06 100644 --- a/src/sample.c +++ b/src/sample.c @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/session.c b/src/session.c index d31806a2ba..619ff069a3 100644 --- a/src/session.c +++ b/src/session.c @@ -11,7 +11,7 @@ */ #include -#include +#include #include #include diff --git a/src/stats.c b/src/stats.c index b5f5e9c89b..4820d3b8bb 100644 --- a/src/stats.c +++ b/src/stats.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/vars.c b/src/vars.c index 227c94b9f4..edcf1af1c0 100644 --- a/src/vars.c +++ b/src/vars.c @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include -- 2.47.2