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.
This commit is contained in:
Willy Tarreau 2020-06-02 19:11:26 +02:00
parent c2f7c5895c
commit cd72d8c981
30 changed files with 150 additions and 104 deletions

View File

@ -15,6 +15,7 @@
#include <haproxy/api.h>
#include <common/cfgparse.h>
#include <haproxy/http.h>
#include <common/htx.h>
#include <haproxy/pool.h>
#include <haproxy/list.h>

View File

@ -25,7 +25,7 @@
#include <haproxy/api.h>
#include <haproxy/dynbuf.h>
#include <haproxy/intops.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <common/http-hdr.h>
#include <import/ist.h>

View File

@ -31,7 +31,7 @@
#include <string.h>
#include <haproxy/api.h>
#include <haproxy/buf-t.h>
#include <common/http.h>
#include <haproxy/http-t.h>
#include <import/ist.h>
int hpack_encode_header(struct buffer *out, const struct ist n,

View File

@ -27,7 +27,7 @@
#include <haproxy/buf.h>
#include <import/ist.h>
#include <haproxy/chunk.h>
#include <common/http.h>
#include <haproxy/http-t.h>
#include <common/http-hdr.h>
/*

View File

@ -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 <haproxy/buf-t.h>
#include <inttypes.h>
#include <import/ist.h>
#include <haproxy/buf-t.h>
/*
* 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:

115
include/haproxy/http.h Normal file
View File

@ -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 <stddef.h>
#include <string.h>
#include <import/ist.h>
#include <haproxy/http-t.h>
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:
*/

View File

@ -23,7 +23,7 @@
#define _TYPES_PROTO_HTTP_H
#include <haproxy/api-t.h>
#include <common/http.h>
#include <haproxy/http-t.h>
#include <types/channel.h>
#include <types/http_htx.h>

View File

@ -26,7 +26,7 @@
#include <import/ebistree.h>
#include <haproxy/buf-t.h>
#include <common/http.h>
#include <haproxy/http-t.h>
#include <common/htx.h>
#include <import/ist.h>

View File

@ -29,7 +29,7 @@
#include <haproxy/api-t.h>
#include <haproxy/chunk.h>
#include <common/http.h>
#include <haproxy/http-t.h>
#include <haproxy/list-t.h>
#include <haproxy/thread.h>

View File

@ -27,7 +27,7 @@
#include <netinet/in.h>
#include <haproxy/buf-t.h>
#include <common/http.h>
#include <haproxy/http-t.h>
#include <haproxy/list-t.h>
struct arg;

View File

@ -21,6 +21,7 @@
#include <haproxy/api.h>
#include <haproxy/hash.h>
#include <haproxy/http.h>
#include <common/htx.h>
#include <haproxy/ticks.h>
#include <haproxy/time.h>

View File

@ -39,7 +39,7 @@
#include <common/standard.h>
#include <haproxy/time.h>
#include <haproxy/thread.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <common/h1.h>
#include <common/htx.h>

View File

@ -3,7 +3,7 @@
#include <haproxy/api.h>
#include <common/cfgparse.h>
#include <haproxy/errors.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <types/global.h>
#include <proto/arg.h>
#include <proto/http_fetch.h>

View File

@ -12,6 +12,7 @@
#include <haproxy/api.h>
#include <haproxy/dynbuf.h>
#include <haproxy/http.h>
#include <common/cfgparse.h>
#include <common/htx.h>
#include <haproxy/list.h>

View File

@ -13,7 +13,7 @@
#include <haproxy/api.h>
#include <common/cfgparse.h>
#include <common/h1.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <common/htx.h>
#include <proto/h1_htx.h>

View File

@ -27,6 +27,7 @@
#include <inttypes.h>
#include <haproxy/api.h>
#include <haproxy/http.h>
#include <common/h2.h>
#include <common/http-hdr.h>
#include <import/ist.h>

View File

@ -18,6 +18,7 @@
#include <lua.h>
#include <lualib.h>
#include <haproxy/http.h>
#include <haproxy/net_helper.h>
#include <haproxy/regex.h>
#include <haproxy/time.h>

View File

@ -12,7 +12,7 @@
#include <ctype.h>
#include <haproxy/api.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <common/standard.h>
/* It is about twice as fast on recent architectures to lookup a byte in a

View File

@ -18,7 +18,7 @@
#include <haproxy/api.h>
#include <haproxy/chunk.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <haproxy/pool.h>
#include <common/standard.h>
#include <haproxy/version.h>

View File

@ -19,7 +19,7 @@
#include <haproxy/api.h>
#include <common/cfgparse.h>
#include <haproxy/chunk.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <haproxy/pool.h>
#include <haproxy/regex.h>
#include <common/standard.h>

View File

@ -12,6 +12,7 @@
#include <haproxy/api.h>
#include <haproxy/base64.h>
#include <haproxy/http.h>
#include <common/htx.h>
#include <haproxy/net_helper.h>
#include <haproxy/regex.h>

View File

@ -18,7 +18,7 @@
#include <haproxy/api.h>
#include <haproxy/chunk.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <haproxy/pool.h>
#include <common/standard.h>
#include <haproxy/version.h>

View File

@ -20,7 +20,7 @@
#include <haproxy/base64.h>
#include <haproxy/chunk.h>
#include <common/h1.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <common/htx.h>
#include <haproxy/pool.h>
#include <common/standard.h>

View File

@ -20,7 +20,7 @@
#include <common/cfgparse.h>
#include <common/h1.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <common/htx.h>
#include <proto/arg.h>

View File

@ -19,7 +19,7 @@
#include <haproxy/api.h>
#include <common/cfgparse.h>
#include <haproxy/chunk.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <haproxy/pool.h>
#include <common/standard.h>
#include <haproxy/version.h>

View File

@ -25,6 +25,7 @@
#include <sys/uio.h>
#include <haproxy/api.h>
#include <haproxy/http.h>
#include <common/standard.h>
#include <haproxy/time.h>
#include <haproxy/version.h>

View File

@ -21,7 +21,7 @@
#include <haproxy/chunk.h>
#include <haproxy/hash.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <haproxy/net_helper.h>
#include <haproxy/regex.h>
#include <common/standard.h>

View File

@ -11,7 +11,7 @@
*/
#include <haproxy/api.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <haproxy/pool.h>
#include <types/global.h>

View File

@ -27,7 +27,7 @@
#include <haproxy/api.h>
#include <common/cfgparse.h>
#include <haproxy/debug.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <common/htx.h>
#include <haproxy/pool.h>
#include <haproxy/list.h>

View File

@ -2,7 +2,7 @@
#include <haproxy/api.h>
#include <common/cfgparse.h>
#include <common/http.h>
#include <haproxy/http.h>
#include <haproxy/list.h>
#include <types/vars.h>