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)
void
http_PrintfHeader(struct http *to, const char *fmt, ...)
{
va_list ap;
unsigned l, n;
va_list ap, ap2;
struct vsb vsb[1];
size_t sz;
char *p;
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
l = WS_ReserveAll(to->ws);
va_start(ap, fmt);
n = vsnprintf(to->ws->f, l, fmt, ap);
va_end(ap);
if (n + 1 >= l || to->nhd >= to->shd) {
va_copy(ap2, ap);
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);
va_start(ap, fmt);
VSLbv(to->vsl, SLT_LostHeader, fmt, ap);
va_end(ap);
WS_Release(to->ws, 0);
return;
VSLbv(to->vsl, SLT_LostHeader, fmt, ap2);
} else {
to->hd[to->nhd].b = p;
to->hd[to->nhd].e = p + sz;
to->hdf[to->nhd] = 0;
http_VSLH(to, to->nhd);
to->nhd++;
}
to->hd[to->nhd].b = to->ws->f;
to->hd[to->nhd].e = to->ws->f + n;
to->hdf[to->nhd] = 0;
WS_Release(to->ws, n + 1);
http_VSLH(to, to->nhd);
to->nhd++;
va_end(ap);
va_end(ap2);
}
void
......
......@@ -248,30 +248,17 @@ typedef void filter_list_t(void *, struct vsb *vsb);
static const char *
filter_on_ws(struct ws *ws, filter_list_t *func, void *arg)
{
unsigned u;
struct vsb vsb[1];
const char *p;
AN(func);
AN(arg);
u = WS_ReserveAll(ws);
if (u == 0) {
WS_Release(ws, 0);
WS_MarkOverflow(ws);
return (NULL);
}
AN(VSB_new(vsb, ws->f, u, VSB_FIXEDLEN));
WS_VSB_new(vsb, ws);
func(arg, vsb);
if (VSB_finish(vsb)) {
WS_Release(ws, 0);
WS_MarkOverflow(ws);
return (NULL);
}
if (VSB_len(vsb)) {
WS_Release(ws, VSB_len(vsb) + 1);
return (VSB_data(vsb) + 1);
}
WS_Release(ws, 0);
return ("");
p = WS_VSB_finish(vsb, ws, NULL);
if (p == NULL)
p = "";
return (p);
}
/*--------------------------------------------------------------------
......
......@@ -361,16 +361,14 @@ void
WS_VSB_new(struct vsb *vsb, struct ws *ws)
{
unsigned u;
static char bogus[2]; // Smallest possible vsb
WS_Assert(ws);
u = WS_ReserveAll(ws);
if (WS_Overflowed(ws) || u < 2) {
/* Create a malloced-buffer VSB, and fail it up front */
AN(VSB_new(vsb, NULL, 2, 0));
VSB_cat(vsb, "XXX");
} else {
if (WS_Overflowed(ws) || u < 2)
AN(VSB_new(vsb, bogus, sizeof bogus, 0));
else
AN(VSB_new(vsb, WS_Front(ws), u, 0));
}
}
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