Browse Source

[core] use buffer_eq_icase* funcs

specialized buffer_eq_icase* funcs replace buffer_caseless_compare()
personal/stbuehler/ci-build
Glenn Strauss 3 years ago
parent
commit
e3874a20ba
  1. 2
      src/connections-glue.c
  2. 2
      src/http_header.c
  3. 22
      src/mod_extforward.c
  4. 14
      src/request.c

2
src/connections-glue.c

@ -436,7 +436,7 @@ handler_t connection_handle_read_post_state(server *srv, connection *con) {
&& con->request.http_version != HTTP_VERSION_1_0
&& chunkqueue_is_empty(con->write_queue) && con->is_writable) {
buffer *vb = http_header_request_get(con, HTTP_HEADER_EXPECT, CONST_STR_LEN("Expect"));
if (NULL != vb && 0 == buffer_caseless_compare(CONST_BUF_LEN(vb), CONST_STR_LEN("100-continue"))) {
if (NULL != vb && buffer_eq_icase_slen(vb, CONST_STR_LEN("100-continue"))) {
http_header_request_unset(con, HTTP_HEADER_EXPECT, CONST_STR_LEN("Expect"));
if (!connection_write_100_continue(srv, con)) {
return HANDLER_ERROR;

2
src/http_header.c

@ -49,7 +49,7 @@ enum http_header_e http_header_hkey_get(const char *s, size_t slen) {
const struct keyvlenvalue * const kv = http_headers;
for (int i = 0; kv[i].vlen && slen >= kv[i].vlen; ++i) {
if (slen == kv[i].vlen
&& 0 == buffer_caseless_compare(s, slen, kv[i].value, kv[i].vlen))
&& buffer_eq_icase_ssn(s, kv[i].value, slen))
return (enum http_header_e)kv[i].key;
}
return HTTP_HEADER_OTHER;

22
src/mod_extforward.c

@ -570,10 +570,10 @@ static void mod_extforward_set_proto(server *srv, connection *con, const char *p
if (extforward_check_proxy) {
http_header_env_set(con, CONST_STR_LEN("_L_EXTFORWARD_ACTUAL_PROTO"), CONST_BUF_LEN(con->uri.scheme));
}
if (0 == buffer_caseless_compare(proto, protolen, CONST_STR_LEN("https"))) {
if (buffer_eq_icase_ss(proto, protolen, CONST_STR_LEN("https"))) {
buffer_copy_string_len(con->uri.scheme, CONST_STR_LEN("https"));
config_cond_cache_reset_item(srv, con, COMP_HTTP_SCHEME);
} else if (0 == buffer_caseless_compare(proto, protolen, CONST_STR_LEN("http"))) {
} else if (buffer_eq_icase_ss(proto, protolen, CONST_STR_LEN("http"))) {
buffer_copy_string_len(con->uri.scheme, CONST_STR_LEN("http"));
config_cond_cache_reset_item(srv, con, COMP_HTTP_SCHEME);
}
@ -735,7 +735,7 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_
do {
j -= 3; /*(k, klen, v, vlen come in sets of 4)*/
} while ((3 != offsets[j+1] /* 3 == sizeof("for")-1 */
|| 0 != buffer_caseless_compare(s+offsets[j], 3, "for", 3))
|| !buffer_eq_icase_ssn(s+offsets[j], "for", 3))
&& 0 != j-- && -1 != offsets[j]);
if (j < 0) break;
if (-1 == offsets[j]) { --j; continue; }
@ -816,27 +816,27 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_
switch (offsets[j+1]) {
#if 0
case 2:
if (0 == buffer_caseless_compare(s+offsets[j],2,"by",2))
if (buffer_eq_icase_ssn(s+offsets[j], "by", 2))
oby = j;
break;
#endif
#if 0
/*(already handled above to find IP prior to earliest trusted proxy)*/
case 3:
if (0 == buffer_caseless_compare(s+offsets[j],3,"for",3))
if (buffer_eq_icase_ssn(s+offsets[j], "for", 3))
ofor = j;
break;
#endif
case 4:
if (0 == buffer_caseless_compare(s+offsets[j],4,"host",4))
if (buffer_eq_icase_ssn(s+offsets[j], "host", 4))
ohost = j;
break;
case 5:
if (0 == buffer_caseless_compare(s+offsets[j],5,"proto",5))
if (buffer_eq_icase_ssn(s+offsets[j], "proto", 5))
oproto = j;
break;
case 11:
if (0 == buffer_caseless_compare(s+offsets[j],11,"remote_user",11))
if (buffer_eq_icase_ssn(s+offsets[j], "remote_user", 11))
oremote_user = j;
break;
default:
@ -876,7 +876,7 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_
for (j = i; j < used && -1 == ohost; ) {
if (-1 == offsets[j]) { ++j; continue; }
if (4 == offsets[j+1]
&& 0 == buffer_caseless_compare(s+offsets[j], 4, "host", 4))
&& buffer_eq_icase_ssn(s+offsets[j], "host", 4))
ohost = j;
j += 4; /*(k, klen, v, vlen come in sets of 4)*/
}
@ -926,7 +926,7 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_
for (j = i; j < used; ) {
if (-1 == offsets[j]) { ++j; continue; }
if (11 == offsets[j+1]
&& 0==buffer_caseless_compare(s+offsets[j],11,"remote_user",11))
&& buffer_eq_icase_ssn(s+offsets[j], "remote_user", 11))
oremote_user = j;
j += 4; /*(k, klen, v, vlen come in sets of 4)*/
}
@ -968,7 +968,7 @@ static handler_t mod_extforward_Forwarded (server *srv, connection *con, plugin_
for (j = 0; j < used; ) {
if (-1 == offsets[j]) { ++j; continue; }
if (3 == offsets[j+1]
&& 0 == buffer_caseless_compare(s+offsets[j], 3, "for", 3)) {
&& buffer_eq_icase_ssn(s+offsets[j], "for", 3)) {
if (!buffer_string_is_empty(xff))
buffer_append_string_len(xff, CONST_STR_LEN(", "));
/* quoted-string, IPv6 brackets, and :port already removed */

14
src/request.c

@ -495,13 +495,13 @@ static int parse_single_header(server *srv, connection *con, parse_header_state
http_request_split_value(vals, v, vlen); /* split on , */
for (size_t vi = 0; vi < vals->used; ++vi) {
data_string *dsv = (data_string *)vals->data[vi];
if (0 == buffer_caseless_compare(CONST_BUF_LEN(dsv->value),
CONST_STR_LEN("keep-alive"))) {
if (buffer_eq_icase_slen(dsv->value,
CONST_STR_LEN("keep-alive"))) {
state->keep_alive_set = HTTP_CONNECTION_KEEPALIVE;
break;
}
else if (0 == buffer_caseless_compare(CONST_BUF_LEN(dsv->value),
CONST_STR_LEN("close"))) {
else if (buffer_eq_icase_slen(dsv->value,
CONST_STR_LEN("close"))) {
state->keep_alive_set = HTTP_CONNECTION_CLOSE;
break;
}
@ -641,13 +641,13 @@ static size_t http_request_parse_reqline(server *srv, connection *con, buffer *h
if (*uri == '/') {
/* (common case) */
buffer_copy_string_len(con->request.uri, uri, jlen);
} else if (0 == buffer_caseless_compare(uri, 7, "http://", 7) &&
} else if (jlen > 7 && buffer_eq_icase_ssn(uri, "http://", 7) &&
NULL != (nuri = memchr(uri + 7, '/', jlen-7))) {
state->reqline_host = uri + 7;
state->reqline_hostlen = nuri - state->reqline_host;
buffer_copy_string_len(con->request.uri, nuri, proto - nuri - 1);
} else if (0 == buffer_caseless_compare(uri, 8, "https://", 8) &&
} else if (jlen > 8 && buffer_eq_icase_ssn(uri, "https://", 8) &&
NULL != (nuri = memchr(uri + 8, '/', jlen-8))) {
state->reqline_host = uri + 8;
state->reqline_hostlen = nuri - state->reqline_host;
@ -864,7 +864,7 @@ int http_request_parse(server *srv, connection *con, buffer *hdrs) {
return http_request_header_line_invalid(srv, 400, "HTTP/1.0 with Transfer-Encoding (bad HTTP/1.0 proxy?) -> 400");
}
if (0 != buffer_caseless_compare(CONST_BUF_LEN(vb), CONST_STR_LEN("chunked"))) {
if (!buffer_eq_icase_slen(vb, CONST_STR_LEN("chunked"))) {
/* Transfer-Encoding might contain additional encodings,
* which are not currently supported by lighttpd */
return http_request_header_line_invalid(srv, 501, NULL); /* Not Implemented */

Loading…
Cancel
Save