Segment.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 86 ESI processing */
10
11#include "squid.h"
12#include "debug/Stream.h"
13#include "esi/Segment.h"
14#include "SquidString.h"
15
17
18void
20{
21 while (head.getRaw()) {
23 head = head->next;
24 temp->next = nullptr;
25 }
26}
27
28size_t
30{
31 assert (len <= sizeof(buf));
32 return sizeof (buf) - len;
33}
34
35void
37{
38 assert (next.getRaw() == nullptr);
39 assert (from.getRaw() != nullptr);
40 /* prevent worst case */
41 assert (!(len == 0 && from->len == space() ));
42 Pointer copyFrom = from;
43
44 while (copyFrom.getRaw() && space() >= copyFrom->len) {
45 assert (append (copyFrom) == copyFrom->len);
46 copyFrom = copyFrom->next;
47 }
48
49 next = copyFrom;
50}
51
52void
54{
55 if (!to.getRaw()) {
56 to = from;
57 from = nullptr;
58 return;
59 }
60
61 ESISegment::Pointer temp = to->tail();
62 temp->adsorbList (from);
63 from = nullptr;
64}
65
66size_t
68{
69 size_t result = 0;
70 ESISegment const* temp = this;
71
72 while (temp) {
73 result += temp->len;
74 temp = temp->next.getRaw();
75 }
76
77 return result;
78}
79
80char *
82{
83 size_t length = listLength();
84 char *rv = (char *)xmalloc (length + 1);
85 assert (rv);
86 rv [length] = '\0';
87
88 ESISegment::Pointer temp = this;
89 size_t pos = 0;
90
91 while (temp.getRaw()) {
92 memcpy(&rv[pos], temp->buf, temp->len);
93 pos += temp->len;
94 temp = temp->next;
95 }
96
97 return rv;
98}
99
100void
101ESISegment::listAppend (char const *s, size_t length)
102{
103 assert (next.getRaw() == nullptr);
104 ESISegment::Pointer output = this;
105 /* copy the string to output */
106 size_t pos=0;
107
108 while (pos < length) {
109 if (output->space() == 0) {
110 assert (output->next.getRaw() == nullptr);
111 output->next = new ESISegment;
112 output = output->next;
113 }
114
115 pos += output->append(s + pos, length - pos);
116 }
117}
118
119void
121{
122 if (!head.getRaw())
123 head = new ESISegment;
124
125 head->tail()->listAppend (s, len);
126}
127
128/* XXX: if needed, make this iterative */
131{
132 ESISegment::Pointer result = new ESISegment (*this);
133 result->next = next.getRaw() ? next->cloneList() : nullptr;
134 return result;
135}
136
137size_t
138ESISegment::append(char const *appendBuffer, size_t appendLength)
139{
140 size_t toCopy = min(appendLength, space());
141 memcpy(&buf[len], appendBuffer, toCopy);
142 len += toCopy;
143 return toCopy;
144}
145
146size_t
148{
149 return append (from->buf, from->len);
150}
151
152ESISegment const *
154{
155 ESISegment const *result = this;
156
157 while (result->next.getRaw())
158 result = result->next.getRaw();
159
160 return result;
161}
162
165{
166 ESISegment::Pointer result = this;
167
168 while (result->next.getRaw())
169 result = result->next;
170
171 return result.getRaw();
172}
173
174ESISegment::ESISegment(ESISegment const &old) : len (0), next(nullptr)
175{
176 append (old.buf, old.len);
177}
178
179void
181{
182 ESISegment::Pointer temp = this;
183
184 while (temp.getRaw()) {
185 temp->dumpOne();
186 temp = temp->next;
187 }
188}
189
190void
192{
193 String temp;
194 temp.assign(buf, len);
195 debugs(86, 9, "ESISegment::dumpOne: \"" << temp << "\"");
196}
197
squidaio_request_t * head
Definition: aiops.cc:127
#define assert(EX)
Definition: assert.h:17
static void ListTransfer(Pointer &from, Pointer &to)
Definition: Segment.cc:53
size_t len
Definition: Segment.h:41
static void ListAppend(Pointer &, char const *, size_t)
Definition: Segment.cc:120
ESISegment const * tail() const
Definition: Segment.cc:153
char * listToChar() const
Definition: Segment.cc:81
void adsorbList(ESISegment::Pointer from)
Definition: Segment.cc:36
ESISegment()
Definition: Segment.h:30
ESISegment::Pointer cloneList() const
Definition: Segment.cc:130
size_t append(char const *, size_t)
Definition: Segment.cc:138
void listAppend(char const *s, size_t length)
Definition: Segment.cc:101
size_t listLength() const
Definition: Segment.cc:67
size_t space() const
Definition: Segment.cc:29
Pointer next
Definition: Segment.h:42
char buf[HTTP_REQBUF_SZ]
Definition: Segment.h:40
void dumpToLog() const
Definition: Segment.cc:180
void dumpOne() const
Definition: Segment.cc:191
C * getRaw() const
Definition: RefCount.h:89
void assign(const char *str, int len)
Definition: String.cc:78
A const & min(A const &lhs, A const &rhs)
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
CBDATA_CLASS_INIT(ESISegment)
void ESISegmentFreeList(ESISegment::Pointer &head)
Definition: Segment.cc:19
#define xmalloc
struct squidaio_request_t * next
Definition: aiops.cc:51

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors