]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/beast/http/impl/serializer.ipp
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / boost / beast / http / impl / serializer.ipp
CommitLineData
b32b8144
FG
1//
2// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3//
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7// Official repository: https://github.com/boostorg/beast
8//
9
10#ifndef BOOST_BEAST_HTTP_IMPL_SERIALIZER_IPP
11#define BOOST_BEAST_HTTP_IMPL_SERIALIZER_IPP
12
13#include <boost/beast/core/detail/buffers_ref.hpp>
14#include <boost/beast/http/error.hpp>
15#include <boost/beast/http/status.hpp>
16#include <boost/beast/core/detail/config.hpp>
17#include <boost/assert.hpp>
18#include <ostream>
19
20namespace boost {
21namespace beast {
22namespace http {
23
24template<
25 bool isRequest, class Body, class Fields>
26void
27serializer<isRequest, Body, Fields>::
11fdf7f2 28fwrinit(std::true_type)
b32b8144 29{
11fdf7f2 30 fwr_.emplace(m_, m_.version(), m_.method());
b32b8144
FG
31}
32
33template<
34 bool isRequest, class Body, class Fields>
35void
36serializer<isRequest, Body, Fields>::
11fdf7f2 37fwrinit(std::false_type)
b32b8144 38{
11fdf7f2 39 fwr_.emplace(m_, m_.version(), m_.result_int());
b32b8144
FG
40}
41
42template<
43 bool isRequest, class Body, class Fields>
44template<std::size_t I, class Visit>
45inline
46void
47serializer<isRequest, Body, Fields>::
48do_visit(error_code& ec, Visit& visit)
49{
50 pv_.template emplace<I>(limit_, v_.template get<I>());
51 visit(ec, beast::detail::make_buffers_ref(
52 pv_.template get<I>()));
53}
54
55//------------------------------------------------------------------------------
56
57template<
58 bool isRequest, class Body, class Fields>
59serializer<isRequest, Body, Fields>::
11fdf7f2
TL
60serializer(value_type& m, std::true_type)
61 : m_(m)
62 , wr_(m_)
63{
64#ifndef BOOST_BEAST_ALLOW_DEPRECATED
65 // Deprecated BodyWriter Concept (v1.66)
66 static_assert(sizeof(Body) == 0,
67 BOOST_BEAST_DEPRECATION_STRING);
68#endif
69}
70
71template<
72 bool isRequest, class Body, class Fields>
73serializer<isRequest, Body, Fields>::
74serializer(value_type& m, std::false_type)
b32b8144 75 : m_(m)
11fdf7f2
TL
76 , wr_(m_.base(), m_.body())
77{
78}
79
80template<
81 bool isRequest, class Body, class Fields>
82serializer<isRequest, Body, Fields>::
83serializer(value_type& m)
84 : serializer(m, detail::has_deprecated_body_writer<Body>{})
b32b8144
FG
85{
86}
87
88template<
89 bool isRequest, class Body, class Fields>
90template<class Visit>
91void
92serializer<isRequest, Body, Fields>::
93next(error_code& ec, Visit&& visit)
94{
95 using boost::asio::buffer_size;
96 switch(s_)
97 {
98 case do_construct:
99 {
11fdf7f2 100 fwrinit(std::integral_constant<bool,
b32b8144
FG
101 isRequest>{});
102 if(m_.chunked())
103 goto go_init_c;
104 s_ = do_init;
11fdf7f2 105 BOOST_FALLTHROUGH;
b32b8144
FG
106 }
107
108 case do_init:
109 {
11fdf7f2 110 wr_.init(ec);
b32b8144
FG
111 if(ec)
112 return;
113 if(split_)
114 goto go_header_only;
11fdf7f2 115 auto result = wr_.get(ec);
b32b8144
FG
116 if(ec == error::need_more)
117 goto go_header_only;
118 if(ec)
119 return;
120 if(! result)
121 goto go_header_only;
122 more_ = result->second;
123 v_.template emplace<2>(
124 boost::in_place_init,
11fdf7f2 125 fwr_->get(),
b32b8144
FG
126 result->first);
127 s_ = do_header;
11fdf7f2 128 BOOST_FALLTHROUGH;
b32b8144
FG
129 }
130
131 case do_header:
132 do_visit<2>(ec, visit);
133 break;
134
135 go_header_only:
11fdf7f2 136 v_.template emplace<1>(fwr_->get());
b32b8144 137 s_ = do_header_only;
11fdf7f2 138 BOOST_FALLTHROUGH;
b32b8144
FG
139 case do_header_only:
140 do_visit<1>(ec, visit);
141 break;
142
143 case do_body:
144 s_ = do_body + 1;
11fdf7f2 145 BOOST_FALLTHROUGH;
b32b8144
FG
146
147 case do_body + 1:
148 {
11fdf7f2 149 auto result = wr_.get(ec);
b32b8144
FG
150 if(ec)
151 return;
152 if(! result)
153 goto go_complete;
154 more_ = result->second;
155 v_.template emplace<3>(result->first);
156 s_ = do_body + 2;
11fdf7f2 157 BOOST_FALLTHROUGH;
b32b8144
FG
158 }
159
160 case do_body + 2:
161 do_visit<3>(ec, visit);
162 break;
163
164 //----------------------------------------------------------------------
165
166 go_init_c:
167 s_ = do_init_c;
11fdf7f2 168 BOOST_FALLTHROUGH;
b32b8144
FG
169 case do_init_c:
170 {
11fdf7f2 171 wr_.init(ec);
b32b8144
FG
172 if(ec)
173 return;
174 if(split_)
175 goto go_header_only_c;
11fdf7f2 176 auto result = wr_.get(ec);
b32b8144
FG
177 if(ec == error::need_more)
178 goto go_header_only_c;
179 if(ec)
180 return;
181 if(! result)
182 goto go_header_only_c;
183 more_ = result->second;
184 if(! more_)
185 {
186 // do it all in one buffer
187 v_.template emplace<7>(
188 boost::in_place_init,
11fdf7f2 189 fwr_->get(),
b32b8144
FG
190 buffer_size(result->first),
191 boost::asio::const_buffer{nullptr, 0},
192 chunk_crlf{},
193 result->first,
194 chunk_crlf{},
195 detail::chunk_last(),
196 boost::asio::const_buffer{nullptr, 0},
197 chunk_crlf{});
198 goto go_all_c;
199 }
200 v_.template emplace<4>(
201 boost::in_place_init,
11fdf7f2 202 fwr_->get(),
b32b8144
FG
203 buffer_size(result->first),
204 boost::asio::const_buffer{nullptr, 0},
205 chunk_crlf{},
206 result->first,
207 chunk_crlf{});
208 s_ = do_header_c;
11fdf7f2 209 BOOST_FALLTHROUGH;
b32b8144
FG
210 }
211
212 case do_header_c:
213 do_visit<4>(ec, visit);
214 break;
215
216 go_header_only_c:
11fdf7f2 217 v_.template emplace<1>(fwr_->get());
b32b8144 218 s_ = do_header_only_c;
11fdf7f2
TL
219 BOOST_FALLTHROUGH;
220
b32b8144
FG
221 case do_header_only_c:
222 do_visit<1>(ec, visit);
223 break;
224
225 case do_body_c:
226 s_ = do_body_c + 1;
11fdf7f2 227 BOOST_FALLTHROUGH;
b32b8144
FG
228
229 case do_body_c + 1:
230 {
11fdf7f2 231 auto result = wr_.get(ec);
b32b8144
FG
232 if(ec)
233 return;
234 if(! result)
235 goto go_final_c;
236 more_ = result->second;
237 if(! more_)
238 {
239 // do it all in one buffer
240 v_.template emplace<6>(
241 boost::in_place_init,
242 buffer_size(result->first),
243 boost::asio::const_buffer{nullptr, 0},
244 chunk_crlf{},
245 result->first,
246 chunk_crlf{},
247 detail::chunk_last(),
248 boost::asio::const_buffer{nullptr, 0},
249 chunk_crlf{});
250 goto go_body_final_c;
251 }
252 v_.template emplace<5>(
253 boost::in_place_init,
254 buffer_size(result->first),
255 boost::asio::const_buffer{nullptr, 0},
256 chunk_crlf{},
257 result->first,
258 chunk_crlf{});
259 s_ = do_body_c + 2;
11fdf7f2 260 BOOST_FALLTHROUGH;
b32b8144
FG
261 }
262
263 case do_body_c + 2:
264 do_visit<5>(ec, visit);
265 break;
266
267 go_body_final_c:
268 s_ = do_body_final_c;
11fdf7f2 269 BOOST_FALLTHROUGH;
b32b8144
FG
270 case do_body_final_c:
271 do_visit<6>(ec, visit);
272 break;
273
274 go_all_c:
275 s_ = do_all_c;
11fdf7f2 276 BOOST_FALLTHROUGH;
b32b8144
FG
277 case do_all_c:
278 do_visit<7>(ec, visit);
279 break;
280
281 go_final_c:
282 case do_final_c:
283 v_.template emplace<8>(
284 boost::in_place_init,
285 detail::chunk_last(),
286 boost::asio::const_buffer{nullptr, 0},
287 chunk_crlf{});
288 s_ = do_final_c + 1;
11fdf7f2 289 BOOST_FALLTHROUGH;
b32b8144
FG
290
291 case do_final_c + 1:
292 do_visit<8>(ec, visit);
293 break;
294
295 //----------------------------------------------------------------------
296
297 default:
298 case do_complete:
299 BOOST_ASSERT(false);
300 break;
301
302 go_complete:
303 s_ = do_complete;
304 break;
305 }
306}
307
308template<
309 bool isRequest, class Body, class Fields>
310void
311serializer<isRequest, Body, Fields>::
312consume(std::size_t n)
313{
314 using boost::asio::buffer_size;
315 switch(s_)
316 {
317 case do_header:
318 BOOST_ASSERT(
319 n <= buffer_size(v_.template get<2>()));
320 v_.template get<2>().consume(n);
321 if(buffer_size(v_.template get<2>()) > 0)
322 break;
323 header_done_ = true;
324 v_.reset();
325 if(! more_)
326 goto go_complete;
327 s_ = do_body + 1;
328 break;
329
330 case do_header_only:
331 BOOST_ASSERT(
332 n <= buffer_size(v_.template get<1>()));
333 v_.template get<1>().consume(n);
334 if(buffer_size(v_.template get<1>()) > 0)
335 break;
11fdf7f2 336 fwr_ = boost::none;
b32b8144
FG
337 header_done_ = true;
338 if(! split_)
339 goto go_complete;
340 s_ = do_body;
341 break;
342
343 case do_body + 2:
344 {
345 BOOST_ASSERT(
346 n <= buffer_size(v_.template get<3>()));
347 v_.template get<3>().consume(n);
348 if(buffer_size(v_.template get<3>()) > 0)
349 break;
350 v_.reset();
351 if(! more_)
352 goto go_complete;
353 s_ = do_body + 1;
354 break;
355 }
356
357 //----------------------------------------------------------------------
358
359 case do_header_c:
360 BOOST_ASSERT(
361 n <= buffer_size(v_.template get<4>()));
362 v_.template get<4>().consume(n);
363 if(buffer_size(v_.template get<4>()) > 0)
364 break;
365 header_done_ = true;
366 v_.reset();
367 if(more_)
368 s_ = do_body_c + 1;
369 else
370 s_ = do_final_c;
371 break;
372
373 case do_header_only_c:
374 {
375 BOOST_ASSERT(
376 n <= buffer_size(v_.template get<1>()));
377 v_.template get<1>().consume(n);
378 if(buffer_size(v_.template get<1>()) > 0)
379 break;
11fdf7f2 380 fwr_ = boost::none;
b32b8144
FG
381 header_done_ = true;
382 if(! split_)
383 {
384 s_ = do_final_c;
385 break;
386 }
387 s_ = do_body_c;
388 break;
389 }
390
391 case do_body_c + 2:
392 BOOST_ASSERT(
393 n <= buffer_size(v_.template get<5>()));
394 v_.template get<5>().consume(n);
395 if(buffer_size(v_.template get<5>()) > 0)
396 break;
397 v_.reset();
398 if(more_)
399 s_ = do_body_c + 1;
400 else
401 s_ = do_final_c;
402 break;
403
404 case do_body_final_c:
405 {
406 BOOST_ASSERT(
407 n <= buffer_size(v_.template get<6>()));
408 v_.template get<6>().consume(n);
409 if(buffer_size(v_.template get<6>()) > 0)
410 break;
411 v_.reset();
412 s_ = do_complete;
413 break;
414 }
415
416 case do_all_c:
417 {
418 BOOST_ASSERT(
419 n <= buffer_size(v_.template get<7>()));
420 v_.template get<7>().consume(n);
421 if(buffer_size(v_.template get<7>()) > 0)
422 break;
423 header_done_ = true;
424 v_.reset();
425 s_ = do_complete;
426 break;
427 }
428
429 case do_final_c + 1:
430 BOOST_ASSERT(buffer_size(v_.template get<8>()));
431 v_.template get<8>().consume(n);
432 if(buffer_size(v_.template get<8>()) > 0)
433 break;
434 v_.reset();
435 goto go_complete;
436
437 //----------------------------------------------------------------------
438
439 default:
440 BOOST_ASSERT(false);
441 case do_complete:
442 break;
443
444 go_complete:
445 s_ = do_complete;
446 break;
447 }
448}
449
450} // http
451} // beast
452} // boost
453
454#endif