Browse Source

[core] http_header_parse_hoff()

moved and renamed from connections.c:connection_read_header_hoff()
master
Glenn Strauss 1 year ago
parent
commit
db7b51a4f6
  1. 20
      src/connections.c
  2. 18
      src/http_header.c
  3. 3
      src/http_header.h

20
src/connections.c

@ -813,23 +813,6 @@ static chunk * connection_read_header_more(connection *con, chunkqueue *cq, chun
: NULL;
}
__attribute_hot__
static uint32_t connection_read_header_hoff(const char *n, const uint32_t clen, unsigned short hoff[8192]) {
uint32_t hlen = 0;
for (const char *b; (n = memchr((b = n),'\n',clen-hlen)); ++n) {
uint32_t x = (uint32_t)(n - b + 1);
hlen += x;
if (x <= 2 && (x == 1 || n[-1] == '\r')) {
hoff[hoff[0]+1] = hlen;
return hlen;
}
if (++hoff[0] >= /*sizeof(hoff)/sizeof(hoff[0])-1*/ 8192-1) break;
hoff[hoff[0]] = hlen;
}
return 0;
}
static void
http_request_headers_process (request_st * const r, char * const hdrs, unsigned short * const hoff, const int scheme_port)
{
@ -904,8 +887,7 @@ static int connection_handle_read_state(connection * const con) {
hoff[1] = (unsigned short)c->offset; /* base offset for all lines */
/*hoff[2] = ...;*/ /* offset from base for 2nd line */
header_len =
connection_read_header_hoff(c->mem->ptr + c->offset, clen, hoff);
header_len = http_header_parse_hoff(c->mem->ptr + c->offset,clen,hoff);
/* casting to (unsigned short) might truncate, and the hoff[]
* addition might overflow, but max_request_field_size is USHRT_MAX,

18
src/http_header.c

@ -241,3 +241,21 @@ void http_header_env_append(request_st * const r, const char *k, uint32_t klen,
if (0 == vlen) return;
http_header_token_append(vb, v, vlen);
}
uint32_t
http_header_parse_hoff (const char *n, const uint32_t clen, unsigned short hoff[8192])
{
uint32_t hlen = 0;
for (const char *b; (n = memchr((b = n),'\n',clen-hlen)); ++n) {
uint32_t x = (uint32_t)(n - b + 1);
hlen += x;
if (x <= 2 && (x == 1 || n[-1] == '\r')) {
hoff[hoff[0]+1] = hlen;
return hlen;
}
if (++hoff[0] >= /*sizeof(hoff)/sizeof(hoff[0])-1*/ 8192-1) break;
hoff[hoff[0]] = hlen;
}
return 0;
}

3
src/http_header.h

@ -70,4 +70,7 @@ buffer * http_header_env_get(const request_st *r, const char *k, uint32_t klen);
void http_header_env_set(request_st *r, const char *k, uint32_t klen, const char *v, uint32_t vlen);
void http_header_env_append(request_st *r, const char *k, uint32_t klen, const char *v, uint32_t vlen);
__attribute_hot__
uint32_t http_header_parse_hoff (const char *n, const uint32_t clen, unsigned short hoff[8192]);
#endif

Loading…
Cancel
Save