]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/esi/Segment.cc
5 * DEBUG: section 86 ESI processing
6 * AUTHOR: Robert Collins
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
37 #include "esi/Segment.h"
38 #include "SquidString.h"
40 CBDATA_TYPE(ESISegment
);
44 ESISegmentFreeList (ESISegment::Pointer
&head
)
46 while (head
.getRaw()) {
47 ESISegment::Pointer temp
= head
;
54 ESISegment::space() const
56 assert (len
<= sizeof(buf
));
57 return sizeof (buf
) - len
;
61 ESISegment::adsorbList (ESISegment::Pointer from
)
63 assert (next
.getRaw() == NULL
);
64 assert (from
.getRaw() != NULL
);
65 /* prevent worst case */
66 assert (!(len
== 0 && from
->len
== space() ));
67 Pointer copyFrom
= from
;
69 while (copyFrom
.getRaw() && space() >= copyFrom
->len
) {
70 assert (append (copyFrom
) == copyFrom
->len
);
71 copyFrom
= copyFrom
->next
;
78 ESISegment::ListTransfer (ESISegment::Pointer
&from
, ESISegment::Pointer
&to
)
86 ESISegment::Pointer temp
= to
->tail();
87 temp
->adsorbList (from
);
92 ESISegment::listLength() const
95 ESISegment
const* temp
= this;
99 temp
= temp
->next
.getRaw();
106 ESISegment::listToChar() const
108 size_t length
= listLength();
109 char *rv
= (char *)xmalloc (length
+ 1);
113 ESISegment::Pointer temp
= this;
116 while (temp
.getRaw()) {
117 xmemcpy (&rv
[pos
], temp
->buf
, temp
->len
);
126 ESISegment::listAppend (char const *s
, size_t length
)
128 assert (next
.getRaw() == NULL
);
129 ESISegment::Pointer output
= this;
130 /* copy the string to output */
133 while (pos
< length
) {
134 if (output
->space() == 0) {
135 assert (output
->next
.getRaw() == NULL
);
136 output
->next
= new ESISegment
;
137 output
= output
->next
;
140 pos
+= output
->append(s
+ pos
, length
- pos
);
145 ESISegment::ListAppend (ESISegment::Pointer
&head
, char const *s
, size_t len
)
148 head
= new ESISegment
;
150 head
->tail()->listAppend (s
, len
);
154 ESISegment::operator new(size_t byteCount
)
156 assert (byteCount
== sizeof (ESISegment
));
158 CBDATA_INIT_TYPE(ESISegment
);
159 rv
= (void *)cbdataAlloc (ESISegment
);
164 ESISegment::operator delete (void *address
)
166 cbdataFree (address
);
169 /* XXX: if needed, make this iterative */
171 ESISegment::cloneList () const
173 ESISegment::Pointer result
= new ESISegment (*this);
174 result
->next
= next
.getRaw() ? next
->cloneList() : NULL
;
179 ESISegment::append(char const *appendBuffer
, size_t appendLength
)
181 size_t toCopy
= min(appendLength
, space());
182 xmemcpy (&buf
[len
], appendBuffer
, toCopy
);
188 ESISegment::append(ESISegment::Pointer from
)
190 return append (from
->buf
, from
->len
);
194 ESISegment::tail() const
196 ESISegment
const *result
= this;
198 while (result
->next
.getRaw())
199 result
= result
->next
.getRaw();
207 ESISegment::Pointer result
= this;
209 while (result
->next
.getRaw())
210 result
= result
->next
;
212 return result
.getRaw();
215 ESISegment::ESISegment() : len(0), next(NULL
)
218 ESISegment::ESISegment(ESISegment
const &old
) : len (0), next(NULL
)
220 append (old
.buf
, old
.len
);
224 ESISegment::dumpToLog() const
226 ESISegment::Pointer temp
= this;
228 while (temp
.getRaw()) {
235 ESISegment::dumpOne() const
238 temp
.limitInit(buf
, len
);
239 debugs(86, 9, "ESISegment::dumpOne: \"" << temp
<< "\"");