]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/esi/Segment.cc
3 * DEBUG: section 86 ESI processing
4 * AUTHOR: Robert Collins
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
36 #include "esi/Segment.h"
37 #include "SquidString.h"
39 CBDATA_TYPE(ESISegment
);
43 ESISegmentFreeList (ESISegment::Pointer
&head
)
45 while (head
.getRaw()) {
46 ESISegment::Pointer temp
= head
;
53 ESISegment::space() const
55 assert (len
<= sizeof(buf
));
56 return sizeof (buf
) - len
;
60 ESISegment::adsorbList (ESISegment::Pointer from
)
62 assert (next
.getRaw() == NULL
);
63 assert (from
.getRaw() != NULL
);
64 /* prevent worst case */
65 assert (!(len
== 0 && from
->len
== space() ));
66 Pointer copyFrom
= from
;
68 while (copyFrom
.getRaw() && space() >= copyFrom
->len
) {
69 assert (append (copyFrom
) == copyFrom
->len
);
70 copyFrom
= copyFrom
->next
;
77 ESISegment::ListTransfer (ESISegment::Pointer
&from
, ESISegment::Pointer
&to
)
85 ESISegment::Pointer temp
= to
->tail();
86 temp
->adsorbList (from
);
91 ESISegment::listLength() const
94 ESISegment
const* temp
= this;
98 temp
= temp
->next
.getRaw();
105 ESISegment::listToChar() const
107 size_t length
= listLength();
108 char *rv
= (char *)xmalloc (length
+ 1);
112 ESISegment::Pointer temp
= this;
115 while (temp
.getRaw()) {
116 memcpy(&rv
[pos
], temp
->buf
, temp
->len
);
125 ESISegment::listAppend (char const *s
, size_t length
)
127 assert (next
.getRaw() == NULL
);
128 ESISegment::Pointer output
= this;
129 /* copy the string to output */
132 while (pos
< length
) {
133 if (output
->space() == 0) {
134 assert (output
->next
.getRaw() == NULL
);
135 output
->next
= new ESISegment
;
136 output
= output
->next
;
139 pos
+= output
->append(s
+ pos
, length
- pos
);
144 ESISegment::ListAppend (ESISegment::Pointer
&head
, char const *s
, size_t len
)
147 head
= new ESISegment
;
149 head
->tail()->listAppend (s
, len
);
153 ESISegment::operator new(size_t byteCount
)
155 assert (byteCount
== sizeof (ESISegment
));
157 CBDATA_INIT_TYPE(ESISegment
);
158 rv
= (void *)cbdataAlloc (ESISegment
);
163 ESISegment::operator delete (void *address
)
165 cbdataFree (address
);
168 /* XXX: if needed, make this iterative */
170 ESISegment::cloneList () const
172 ESISegment::Pointer result
= new ESISegment (*this);
173 result
->next
= next
.getRaw() ? next
->cloneList() : NULL
;
178 ESISegment::append(char const *appendBuffer
, size_t appendLength
)
180 size_t toCopy
= min(appendLength
, space());
181 memcpy(&buf
[len
], appendBuffer
, toCopy
);
187 ESISegment::append(ESISegment::Pointer from
)
189 return append (from
->buf
, from
->len
);
193 ESISegment::tail() const
195 ESISegment
const *result
= this;
197 while (result
->next
.getRaw())
198 result
= result
->next
.getRaw();
206 ESISegment::Pointer result
= this;
208 while (result
->next
.getRaw())
209 result
= result
->next
;
211 return result
.getRaw();
214 ESISegment::ESISegment() : len(0), next(NULL
)
217 ESISegment::ESISegment(ESISegment
const &old
) : len (0), next(NULL
)
219 append (old
.buf
, old
.len
);
223 ESISegment::dumpToLog() const
225 ESISegment::Pointer temp
= this;
227 while (temp
.getRaw()) {
234 ESISegment::dumpOne() const
237 temp
.limitInit(buf
, len
);
238 debugs(86, 9, "ESISegment::dumpOne: \"" << temp
<< "\"");