Browse Source

[multiple] buffer_copy_string_len_lc()

convenience wrapper combining
  buffer_copy_string_len()
  buffer_to_lower()
and making a single pass over string
master
Glenn Strauss 6 months ago
parent
commit
f490078d0f
  1. 10
      src/buffer.c
  2. 1
      src/buffer.h
  3. 4
      src/configfile.c
  4. 5
      src/mod_extforward.c
  5. 3
      src/mod_gnutls.c
  6. 3
      src/mod_mbedtls.c
  7. 3
      src/mod_nss.c
  8. 3
      src/mod_openssl.c
  9. 3
      src/mod_wolfssl.c
  10. 3
      src/request.c
  11. 6
      src/response.c

10
src/buffer.c

@ -264,6 +264,16 @@ buffer_copy_path_len2 (buffer * const restrict b, const char * const restrict s1
buffer_append_path_len(b, s2, len2);/*(choice: not inlined, special-cased)*/
}
void
buffer_copy_string_len_lc (buffer * const restrict b, const char * const restrict s, const size_t len)
{
char * const restrict d = buffer_string_prepare_copy(b, len);
b->used = len+1;
d[len] = '\0';
for (size_t i = 0; i < len; ++i)
d[i] = (!light_isupper(s[i])) ? s[i] : s[i] | 0x20;
}
void buffer_append_uint_hex_lc(buffer *b, uintmax_t value) {
char *buf;
unsigned int shift = 0;

1
src/buffer.h

@ -107,6 +107,7 @@ void buffer_free_ptr(buffer *b);
void buffer_copy_string(buffer * restrict b, const char * restrict s);
void buffer_copy_string_len(buffer * restrict b, const char * restrict s, size_t len);
void buffer_copy_string_len_lc(buffer * restrict b, const char * restrict s, size_t len);
void buffer_append_string(buffer * restrict b, const char * restrict s);
void buffer_append_string_len(buffer * restrict b, const char * restrict s, size_t len);

4
src/configfile.c

@ -2553,9 +2553,7 @@ int config_set_defaults(server *srv) {
s->force_lowercase_filenames = 0; /* default to 0 */
buffer * const tb = srv->tmp_buf;
buffer_copy_buffer(tb, s->document_root);
buffer_to_lower(tb);
buffer_copy_string_len_lc(tb, BUF_PTR_LEN(s->document_root));
if (0 == stat(tb->ptr, &st1)) {
int is_lower = 0;

5
src/mod_extforward.c

@ -949,16 +949,15 @@ static handler_t mod_extforward_Forwarded (request_st * const r, plugin_data * c
while (vlen > v && (s[vlen-1] == ' ' || s[vlen-1] == '\t')) --vlen;
if (vlen > v+1 && s[v] == '"' && s[vlen-1] == '"') {
++v; --vlen;
buffer_copy_string_len(r->http_host, s+v, vlen-v);
buffer_copy_string_len_lc(r->http_host, s+v, vlen-v);
if (!buffer_backslash_unescape(r->http_host)) {
return mod_extforward_bad_request(r, __LINE__,
"invalid host= value in Forwarded header");
}
}
else {
buffer_copy_string_len(r->http_host, s+v, vlen-v);
buffer_copy_string_len_lc(r->http_host, s+v, vlen-v);
}
buffer_to_lower(r->http_host);
if (0 != http_request_host_policy(r->http_host,
r->conf.http_parseopts,

3
src/mod_gnutls.c

@ -1443,8 +1443,7 @@ mod_gnutls_SNI(handler_ctx * const hctx,
}
/* use SNI to patch mod_gnutls config and then reset COMP_HTTP_HOST */
buffer_copy_string_len(&r->uri.authority, (const char *)servername, len);
buffer_to_lower(&r->uri.authority);
buffer_copy_string_len_lc(&r->uri.authority, (const char *)servername, len);
#if 0
/*(r->uri.authority used below for configuration before request read;
* revisit for h2)*/

3
src/mod_mbedtls.c

@ -711,8 +711,7 @@ mod_mbedtls_SNI (void *arg, mbedtls_ssl_context *ssl, const unsigned char *serve
}
/* use SNI to patch mod_mbedtls config and then reset COMP_HTTP_HOST */
buffer_copy_string_len(&r->uri.authority, (const char *)servername, len);
buffer_to_lower(&r->uri.authority);
buffer_copy_string_len_lc(&r->uri.authority, (const char *)servername, len);
#if 0
/*(r->uri.authority used below for configuration before request read;
* revisit for h2)*/

3
src/mod_nss.c

@ -1393,8 +1393,7 @@ mod_nss_SNI (PRFileDesc *ssl, const SECItem *srvNameArr, PRUint32 srvNameArrSize
}
/* use SNI to patch mod_nss config and then reset COMP_HTTP_HOST */
buffer_copy_string_len(&r->uri.authority, (const char *)sn->data, sn->len);
buffer_to_lower(&r->uri.authority);
buffer_copy_string_len_lc(&r->uri.authority,(const char *)sn->data,sn->len);
#if 0
/*(r->uri.authority used below for configuration before request read;
* revisit for h2)*/

3
src/mod_openssl.c

@ -1190,8 +1190,7 @@ mod_openssl_SNI (handler_ctx *hctx, const char *servername, size_t len)
}
/* use SNI to patch mod_openssl config and then reset COMP_HTTP_HOST */
buffer_copy_string_len(&r->uri.authority, servername, len);
buffer_to_lower(&r->uri.authority);
buffer_copy_string_len_lc(&r->uri.authority, servername, len);
#if 0
/*(r->uri.authority used below for configuration before request read;
* revisit for h2)*/

3
src/mod_wolfssl.c

@ -1268,8 +1268,7 @@ mod_openssl_SNI (handler_ctx *hctx, const char *servername, size_t len)
}
/* use SNI to patch mod_openssl config and then reset COMP_HTTP_HOST */
buffer_copy_string_len(&r->uri.authority, servername, len);
buffer_to_lower(&r->uri.authority);
buffer_copy_string_len_lc(&r->uri.authority, servername, len);
#if 0
/*(r->uri.authority used below for configuration before request read;
* revisit for h2)*/

3
src/request.c

@ -270,8 +270,7 @@ static void http_request_header_set_Host(request_st * const restrict r, const ch
{
r->http_host = http_header_request_set_ptr(r, HTTP_HEADER_HOST,
CONST_STR_LEN("Host"));
buffer_copy_string_len(r->http_host, h, hlen);
buffer_to_lower(r->http_host);
buffer_copy_string_len_lc(r->http_host, h, hlen);
}

6
src/response.c

@ -622,10 +622,8 @@ static handler_t http_response_comeback (request_st * const r)
request_config_reset(r);
if (__builtin_expect( (r->http_host != NULL), 1)) {
buffer_copy_buffer(&r->uri.authority, r->http_host);
buffer_to_lower(&r->uri.authority);
}
if (__builtin_expect( (r->http_host != NULL), 1))
buffer_copy_string_len_lc(&r->uri.authority, BUF_PTR_LEN(r->http_host));
else /*(buffer_blank(&r->uri.authority) w/o code inline)*/
buffer_copy_string_len(&r->uri.authority, CONST_STR_LEN(""));

Loading…
Cancel
Save