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