Commit 6e25bf69 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Two more uses for WS_VSB()

parent 7c4dcd66
...@@ -1228,28 +1228,32 @@ http_ForceHeader(struct http *to, const char *hdr, const char *val) ...@@ -1228,28 +1228,32 @@ http_ForceHeader(struct http *to, const char *hdr, const char *val)
void void
http_PrintfHeader(struct http *to, const char *fmt, ...) http_PrintfHeader(struct http *to, const char *fmt, ...)
{ {
va_list ap; va_list ap, ap2;
unsigned l, n; struct vsb vsb[1];
size_t sz;
char *p;
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
l = WS_ReserveAll(to->ws);
va_start(ap, fmt); va_start(ap, fmt);
n = vsnprintf(to->ws->f, l, fmt, ap); va_copy(ap2, ap);
va_end(ap);
if (n + 1 >= l || to->nhd >= to->shd) { WS_VSB_new(vsb, to->ws);
VSB_vprintf(vsb, fmt, ap);
p = WS_VSB_finish(vsb, to->ws, &sz);
if (p == NULL || to->nhd >= to->shd) {
http_fail(to); http_fail(to);
va_start(ap, fmt); VSLbv(to->vsl, SLT_LostHeader, fmt, ap2);
VSLbv(to->vsl, SLT_LostHeader, fmt, ap); } else {
va_end(ap); to->hd[to->nhd].b = p;
WS_Release(to->ws, 0); to->hd[to->nhd].e = p + sz;
return; to->hdf[to->nhd] = 0;
http_VSLH(to, to->nhd);
to->nhd++;
} }
to->hd[to->nhd].b = to->ws->f; va_end(ap);
to->hd[to->nhd].e = to->ws->f + n; va_end(ap2);
to->hdf[to->nhd] = 0;
WS_Release(to->ws, n + 1);
http_VSLH(to, to->nhd);
to->nhd++;
} }
void void
......
...@@ -248,30 +248,17 @@ typedef void filter_list_t(void *, struct vsb *vsb); ...@@ -248,30 +248,17 @@ typedef void filter_list_t(void *, struct vsb *vsb);
static const char * static const char *
filter_on_ws(struct ws *ws, filter_list_t *func, void *arg) filter_on_ws(struct ws *ws, filter_list_t *func, void *arg)
{ {
unsigned u;
struct vsb vsb[1]; struct vsb vsb[1];
const char *p;
AN(func); AN(func);
AN(arg); AN(arg);
u = WS_ReserveAll(ws); WS_VSB_new(vsb, ws);
if (u == 0) {
WS_Release(ws, 0);
WS_MarkOverflow(ws);
return (NULL);
}
AN(VSB_new(vsb, ws->f, u, VSB_FIXEDLEN));
func(arg, vsb); func(arg, vsb);
if (VSB_finish(vsb)) { p = WS_VSB_finish(vsb, ws, NULL);
WS_Release(ws, 0); if (p == NULL)
WS_MarkOverflow(ws); p = "";
return (NULL); return (p);
}
if (VSB_len(vsb)) {
WS_Release(ws, VSB_len(vsb) + 1);
return (VSB_data(vsb) + 1);
}
WS_Release(ws, 0);
return ("");
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
......
...@@ -361,16 +361,14 @@ void ...@@ -361,16 +361,14 @@ void
WS_VSB_new(struct vsb *vsb, struct ws *ws) WS_VSB_new(struct vsb *vsb, struct ws *ws)
{ {
unsigned u; unsigned u;
static char bogus[2]; // Smallest possible vsb
WS_Assert(ws); WS_Assert(ws);
u = WS_ReserveAll(ws); u = WS_ReserveAll(ws);
if (WS_Overflowed(ws) || u < 2) { if (WS_Overflowed(ws) || u < 2)
/* Create a malloced-buffer VSB, and fail it up front */ AN(VSB_new(vsb, bogus, sizeof bogus, 0));
AN(VSB_new(vsb, NULL, 2, 0)); else
VSB_cat(vsb, "XXX");
} else {
AN(VSB_new(vsb, WS_Front(ws), u, 0)); AN(VSB_new(vsb, WS_Front(ws), u, 0));
}
} }
char * char *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment