]>
Commit | Line | Data |
---|---|---|
cb69b4c7 | 1 | /* |
2 | * $Id: HttpBody.cc,v 1.2 1998/02/21 00:56:40 rousskov Exp $ | |
3 | * | |
4 | * DEBUG: section ?? HTTP Body | |
5 | * AUTHOR: Alex Rousskov | |
6 | * | |
7 | * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ | |
8 | * -------------------------------------------------------- | |
9 | * | |
10 | * Squid is the result of efforts by numerous individuals from the | |
11 | * Internet community. Development is led by Duane Wessels of the | |
12 | * National Laboratory for Applied Network Research and funded by | |
13 | * the National Science Foundation. | |
14 | * | |
15 | * This program is free software; you can redistribute it and/or modify | |
16 | * it under the terms of the GNU General Public License as published by | |
17 | * the Free Software Foundation; either version 2 of the License, or | |
18 | * (at your option) any later version. | |
19 | * | |
20 | * This program is distributed in the hope that it will be useful, | |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | * GNU General Public License for more details. | |
24 | * | |
25 | * You should have received a copy of the GNU General Public License | |
26 | * along with this program; if not, write to the Free Software | |
27 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
28 | * | |
29 | */ | |
30 | ||
31 | #include "squid.h" | |
32 | ||
33 | ||
34 | /* local constants */ | |
35 | ||
36 | /* local routines */ | |
37 | ||
38 | ||
39 | void | |
40 | httpBodyInit(HttpBody *body) | |
41 | { | |
42 | body->buf = NULL; | |
43 | body->size = 0; | |
44 | body->freefunc = NULL; | |
45 | } | |
46 | ||
47 | void | |
48 | httpBodyClean(HttpBody *body) | |
49 | { | |
50 | assert(body); | |
51 | if (body->buf) { | |
52 | assert(body->freefunc); | |
53 | (*body->freefunc)(body->buf); | |
54 | } | |
55 | body->buf = NULL; | |
56 | body->size = 0; | |
57 | } | |
58 | ||
59 | void | |
60 | httpBodySet(HttpBody *body, const char *buf, int size, FREE *freefunc) | |
61 | { | |
62 | assert(body); | |
63 | assert(!body->buf); | |
64 | assert(buf); | |
65 | assert(size); | |
66 | assert(buf[size-1] == '\0'); /* paranoid */ | |
67 | if (!freefunc) { /* they want us to make our own copy */ | |
68 | body->buf = xmalloc(size); | |
69 | xmemcpy(body->buf, buf, size); | |
70 | freefunc = &xfree; | |
71 | } | |
72 | body->freefunc = freefunc; | |
73 | body->size = size; | |
74 | } | |
75 | ||
76 | void | |
77 | httpBodyPackInto(const HttpBody *body, Packer *p) | |
78 | { | |
79 | assert(body && p); | |
80 | /* assume it was a 0-terminating buffer */ | |
81 | if (body->size) | |
82 | packerAppend(p, body->buf, body->size-1); | |
83 | } | |
84 | ||
85 | const char * | |
86 | httpBodyPtr(const HttpBody *body) | |
87 | { | |
88 | return body->buf ? body->buf : ""; | |
89 | } |