Commit 5922eb75 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a WS_Copy() function and use it a couple of places.

parent adbff322
......@@ -1034,6 +1034,7 @@ void WS_ReleaseP(struct ws *ws, char *ptr);
void WS_Assert(const struct ws *ws);
void WS_Reset(struct ws *ws, char *p);
char *WS_Alloc(struct ws *ws, unsigned bytes);
char *WS_Copy(struct ws *ws, const char *str, int len);
char *WS_Snapshot(struct ws *ws);
/* rfc2616.c */
......
......@@ -888,10 +888,9 @@ http_CopyHome(const struct http *hp)
continue;
}
l = Tlen(hp->hd[u]);
p = WS_Alloc(hp->ws, l + 1);
p = WS_Copy(hp->ws, hp->hd[u].b, l + 1L);
if (p != NULL) {
http_VSLH(hp, u);
memcpy(p, hp->hd[u].b, l + 1L);
hp->hd[u].b = p;
hp->hd[u].e = p + l;
} else {
......
......@@ -617,9 +617,9 @@ cnt_fetchbody(struct worker *wrk, struct req *req)
req->obj->gziped = 1;
if (vary != NULL) {
req->obj->vary = (void *)WS_Alloc(req->obj->http->ws, varyl);
req->obj->vary = (void *)WS_Copy(req->obj->http->ws,
VSB_data(vary), varyl);
AN(req->obj->vary);
memcpy(req->obj->vary, VSB_data(vary), varyl);
VRY_Validate(req->obj->vary);
VSB_delete(vary);
}
......
......@@ -116,6 +116,33 @@ WS_Alloc(struct ws *ws, unsigned bytes)
return (r);
}
char *
WS_Copy(struct ws *ws, const char *str, int len)
{
char *r;
unsigned bytes;
WS_Assert(ws);
assert(ws->r == NULL);
if (len == -1)
len = strlen(str) + 1;
assert(len >= 0);
bytes = PRNDUP((unsigned)len);
if (ws->f + bytes > ws->e) {
ws->overflow++;
WS_Assert(ws);
return(NULL);
}
r = ws->f;
ws->f += bytes;
memcpy(r, str, len);
DSL(DBG_WORKSPACE, 0, "WS_Copy(%p, %d) = %p", ws, len, r);
WS_Assert(ws);
return (r);
}
char *
WS_Snapshot(struct ws *ws)
{
......@@ -174,15 +201,3 @@ WS_ReleaseP(struct ws *ws, char *ptr)
ws->r = NULL;
WS_Assert(ws);
}
#if 0
/* XXX: not used anywhere (yet) */
void
WS_Return(struct ws *ws, char *s, char *e)
{
WS_Assert(ws);
if (e == ws->f)
ws->f = s;
}
#endif
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