Skip to content

Commit

Permalink
More compact H2 error names
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdphk committed Feb 17, 2017
1 parent a62435b commit 7144af0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions bin/varnishd/http2/cache_http2.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ struct h2_error_s {
typedef const struct h2_error_s *h2_error; typedef const struct h2_error_s *h2_error;


#define H2EC0(U,v,d) #define H2EC0(U,v,d)
#define H2EC1(U,v,d) extern const struct h2_error_s H2E_C_##U[1]; #define H2EC1(U,v,d) extern const struct h2_error_s H2CE_##U[1];
#define H2EC2(U,v,d) extern const struct h2_error_s H2E_S_##U[1]; #define H2EC2(U,v,d) extern const struct h2_error_s H2SE_##U[1];
#define H2EC3(U,v,d) H2EC1(U,v,d) H2EC2(U,v,d) #define H2EC3(U,v,d) H2EC1(U,v,d) H2EC2(U,v,d)
#define H2_ERROR(NAME, val, sc, desc) H2EC##sc(NAME, val, desc) #define H2_ERROR(NAME, val, sc, desc) H2EC##sc(NAME, val, desc)
#include "tbl/h2_error.h" #include "tbl/h2_error.h"
Expand Down
32 changes: 16 additions & 16 deletions bin/varnishd/http2/cache_http2_hpack.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ h2h_checkhdr(const struct http *hp, const char *b, size_t namelen, size_t len)


if (namelen == 2) { if (namelen == 2) {
VSLb(hp->vsl, SLT_BogoHeader, "Empty name"); VSLb(hp->vsl, SLT_BogoHeader, "Empty name");
return (H2E_C_PROTOCOL_ERROR); return (H2CE_PROTOCOL_ERROR);
} }


for (p = b; p < b + len; p++) { for (p = b; p < b + len; p++) {
Expand All @@ -64,7 +64,7 @@ h2h_checkhdr(const struct http *hp, const char *b, size_t namelen, size_t len)
VSLb(hp->vsl, SLT_BogoHeader, VSLb(hp->vsl, SLT_BogoHeader,
"Illegal header name: %.*s", "Illegal header name: %.*s",
(int)(len > 20 ? 20 : len), b); (int)(len > 20 ? 20 : len), b);
return (H2E_C_PROTOCOL_ERROR); return (H2CE_PROTOCOL_ERROR);
} else if (p < b + namelen) { } else if (p < b + namelen) {
/* ': ' added by us */ /* ': ' added by us */
assert(*p == ':' || *p == ' '); assert(*p == ':' || *p == ' ');
Expand All @@ -75,7 +75,7 @@ h2h_checkhdr(const struct http *hp, const char *b, size_t namelen, size_t len)
VSLb(hp->vsl, SLT_BogoHeader, VSLb(hp->vsl, SLT_BogoHeader,
"Illegal header value: %.*s", "Illegal header value: %.*s",
(int)(len > 20 ? 20 : len), b); (int)(len > 20 ? 20 : len), b);
return (H2E_C_PROTOCOL_ERROR); return (H2CE_PROTOCOL_ERROR);
} }
} }


Expand All @@ -95,7 +95,7 @@ h2h_addhdr(struct http *hp, char *b, size_t namelen, size_t len)


if (len > UINT_MAX) { /* XXX: cache_param max header size */ if (len > UINT_MAX) { /* XXX: cache_param max header size */
VSLb(hp->vsl, SLT_BogoHeader, "Header too large: %.20s", b); VSLb(hp->vsl, SLT_BogoHeader, "Header too large: %.20s", b);
return (H2E_S_ENHANCE_YOUR_CALM); return (H2SE_ENHANCE_YOUR_CALM);
} }


if (b[0] == ':') { if (b[0] == ':') {
Expand Down Expand Up @@ -127,7 +127,7 @@ h2h_addhdr(struct http *hp, char *b, size_t namelen, size_t len)
VSLb(hp->vsl, SLT_BogoHeader, VSLb(hp->vsl, SLT_BogoHeader,
"Unknown pseudo-header: %.*s", "Unknown pseudo-header: %.*s",
(int)(len > 20 ? 20 : len), b); (int)(len > 20 ? 20 : len), b);
return (H2E_S_PROTOCOL_ERROR); return (H2SE_PROTOCOL_ERROR);
} }
} else } else
n = hp->nhd; n = hp->nhd;
Expand All @@ -138,14 +138,14 @@ h2h_addhdr(struct http *hp, char *b, size_t namelen, size_t len)
VSLb(hp->vsl, SLT_BogoHeader, VSLb(hp->vsl, SLT_BogoHeader,
"Duplicate pseudo-header: %.*s", "Duplicate pseudo-header: %.*s",
(int)(len > 20 ? 20 : len), b); (int)(len > 20 ? 20 : len), b);
return (H2E_S_PROTOCOL_ERROR); return (H2SE_PROTOCOL_ERROR);
} }
} else { } else {
/* Check for space in struct http */ /* Check for space in struct http */
if (n >= hp->shd) { if (n >= hp->shd) {
VSLb(hp->vsl, SLT_LostHeader, "Too many headers: %.*s", VSLb(hp->vsl, SLT_LostHeader, "Too many headers: %.*s",
(int)(len > 20 ? 20 : len), b); (int)(len > 20 ? 20 : len), b);
return (H2E_S_ENHANCE_YOUR_CALM); return (H2SE_ENHANCE_YOUR_CALM);
} }
hp->nhd++; hp->nhd++;
} }
Expand Down Expand Up @@ -195,7 +195,7 @@ h2h_decode_fini(const struct h2_sess *h2, struct h2h_decode *d)
boundary */ boundary */
VSLb(h2->new_req->http->vsl, SLT_BogoHeader, VSLb(h2->new_req->http->vsl, SLT_BogoHeader,
"HPACK compression error (%s)", VHD_Error(d->vhd_ret)); "HPACK compression error (%s)", VHD_Error(d->vhd_ret));
ret = H2E_C_COMPRESSION_ERROR; ret = H2CE_COMPRESSION_ERROR;
} else } else
ret = d->error; ret = d->error;
d->magic = 0; d->magic = 0;
Expand Down Expand Up @@ -227,7 +227,7 @@ h2h_decode_bytes(struct h2_sess *h2, struct h2h_decode *d,
/* Only H2E_ENHANCE_YOUR_CALM indicates that we should continue /* Only H2E_ENHANCE_YOUR_CALM indicates that we should continue
processing. Other errors should have been returned and handled processing. Other errors should have been returned and handled
by the caller. */ by the caller. */
assert(d->error == 0 || d->error == H2E_S_ENHANCE_YOUR_CALM); assert(d->error == 0 || d->error == H2SE_ENHANCE_YOUR_CALM);


while (1) { while (1) {
AN(d->out); AN(d->out);
Expand All @@ -239,14 +239,14 @@ h2h_decode_bytes(struct h2_sess *h2, struct h2h_decode *d,
VSLb(hp->vsl, SLT_BogoHeader, VSLb(hp->vsl, SLT_BogoHeader,
"HPACK compression error (%s)", "HPACK compression error (%s)",
VHD_Error(d->vhd_ret)); VHD_Error(d->vhd_ret));
d->error = H2E_C_COMPRESSION_ERROR; d->error = H2CE_COMPRESSION_ERROR;
break; break;
} else if (d->vhd_ret == VHD_OK || d->vhd_ret == VHD_MORE) { } else if (d->vhd_ret == VHD_OK || d->vhd_ret == VHD_MORE) {
assert(in_u == in_l); assert(in_u == in_l);
break; break;
} }


if (d->error == H2E_S_ENHANCE_YOUR_CALM) { if (d->error == H2SE_ENHANCE_YOUR_CALM) {
d->out_u = 0; d->out_u = 0;
assert(d->out_u < d->out_l); assert(d->out_u < d->out_l);
continue; continue;
Expand All @@ -258,7 +258,7 @@ h2h_decode_bytes(struct h2_sess *h2, struct h2h_decode *d,
case VHD_NAME: case VHD_NAME:
assert(d->namelen == 0); assert(d->namelen == 0);
if (d->out_l - d->out_u < 2) { if (d->out_l - d->out_u < 2) {
d->error = H2E_S_ENHANCE_YOUR_CALM; d->error = H2SE_ENHANCE_YOUR_CALM;
break; break;
} }
d->out[d->out_u++] = ':'; d->out[d->out_u++] = ':';
Expand All @@ -271,7 +271,7 @@ h2h_decode_bytes(struct h2_sess *h2, struct h2h_decode *d,
case VHD_VALUE: case VHD_VALUE:
assert(d->namelen > 0); assert(d->namelen > 0);
if (d->out_l - d->out_u < 1) { if (d->out_l - d->out_u < 1) {
d->error = H2E_S_ENHANCE_YOUR_CALM; d->error = H2SE_ENHANCE_YOUR_CALM;
break; break;
} }
d->error = h2h_checkhdr(hp, d->out, d->namelen, d->error = h2h_checkhdr(hp, d->out, d->namelen,
Expand All @@ -289,15 +289,15 @@ h2h_decode_bytes(struct h2_sess *h2, struct h2h_decode *d,
break; break;


case VHD_BUF: case VHD_BUF:
d->error = H2E_S_ENHANCE_YOUR_CALM; d->error = H2SE_ENHANCE_YOUR_CALM;
break; break;


default: default:
WRONG("Unhandled return value"); WRONG("Unhandled return value");
break; break;
} }


if (d->error == H2E_S_ENHANCE_YOUR_CALM) { if (d->error == H2SE_ENHANCE_YOUR_CALM) {
http_Teardown(hp); http_Teardown(hp);
d->out = d->reset; d->out = d->reset;
d->out_l = hp->ws->r - d->out; d->out_l = hp->ws->r - d->out;
Expand All @@ -307,7 +307,7 @@ h2h_decode_bytes(struct h2_sess *h2, struct h2h_decode *d,
break; break;
} }


if (d->error == H2E_S_ENHANCE_YOUR_CALM) if (d->error == H2SE_ENHANCE_YOUR_CALM)
return (0); /* Stream error, delay reporting until return (0); /* Stream error, delay reporting until
h2h_decode_fini so that we can process the h2h_decode_fini so that we can process the
complete header block */ complete header block */
Expand Down
8 changes: 4 additions & 4 deletions bin/varnishd/http2/cache_http2_proto.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
#include "vtim.h" #include "vtim.h"


#define H2EC0(U,v,d) #define H2EC0(U,v,d)
#define H2EC1(U,v,d) const struct h2_error_s H2E_C_##U[1] = {{#U,d,v,0,1}}; #define H2EC1(U,v,d) const struct h2_error_s H2CE_##U[1] = {{#U,d,v,0,1}};
#define H2EC2(U,v,d) const struct h2_error_s H2E_S_##U[1] = {{#U,d,v,1,0}}; #define H2EC2(U,v,d) const struct h2_error_s H2SE_##U[1] = {{#U,d,v,1,0}};
#define H2EC3(U,v,d) H2EC1(U,v,d) H2EC2(U,v,d) #define H2EC3(U,v,d) H2EC1(U,v,d) H2EC2(U,v,d)
#define H2_ERROR(NAME, val, sc, desc) H2EC##sc(NAME, val, desc) #define H2_ERROR(NAME, val, sc, desc) H2EC##sc(NAME, val, desc)
#include "tbl/h2_error.h" #include "tbl/h2_error.h"
Expand Down Expand Up @@ -394,7 +394,7 @@ h2_do_req(struct worker *wrk, void *priv)
VSL(SLT_Debug, 0, "H2REQ CNT done"); VSL(SLT_Debug, 0, "H2REQ CNT done");
/* XXX clean up req */ /* XXX clean up req */
r2->state = H2_S_CLOSED; r2->state = H2_S_CLOSED;
h2_del_req(wrk, r2, H2E_S_NO_ERROR); h2_del_req(wrk, r2, H2SE_NO_ERROR);
} }


void __match_proto__(h2_frame_f) void __match_proto__(h2_frame_f)
Expand Down Expand Up @@ -765,7 +765,7 @@ h2_new_session(struct worker *wrk, void *arg)
/* Delete all idle streams */ /* Delete all idle streams */
VTAILQ_FOREACH_SAFE(r2, &h2->streams, list, r22) { VTAILQ_FOREACH_SAFE(r2, &h2->streams, list, r22) {
if (r2->state == H2_S_IDLE) if (r2->state == H2_S_IDLE)
h2_del_req(wrk, r2, H2E_S_NO_ERROR); h2_del_req(wrk, r2, H2SE_NO_ERROR);
} }
} }


Expand Down

0 comments on commit 7144af0

Please sign in to comment.