1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "rgw_fcgi.h"
#include "acconfig.h"
size_t RGWFCGX::write_data(const char* const buf, const size_t len)
{
/* According to the documentation of FCGX_PutStr if there is no error
* (signalised by negative return value), then always ret == len. */
const auto ret = FCGX_PutStr(buf, len, fcgx->out);
if (ret < 0) {
throw rgw::io::Exception(-ret, std::system_category());
}
return ret;
}
size_t RGWFCGX::read_data(char* const buf, const size_t len)
{
const auto ret = FCGX_GetStr(buf, len, fcgx->in);
if (ret < 0) {
throw rgw::io::Exception(-ret, std::system_category());
}
return ret;
}
void RGWFCGX::flush()
{
txbuf.pubsync();
FCGX_FFlush(fcgx->out);
}
int RGWFCGX::init_env(CephContext* const cct)
{
env.init(cct, (char **)fcgx->envp);
return 0;
}
size_t RGWFCGX::send_status(const int status, const char* const status_name)
{
static constexpr size_t STATUS_BUF_SIZE = 128;
char statusbuf[STATUS_BUF_SIZE];
const auto statuslen = snprintf(statusbuf, sizeof(statusbuf),
"Status: %d %s\r\n", status, status_name);
return txbuf.sputn(statusbuf, statuslen);
}
size_t RGWFCGX::send_100_continue()
{
const auto sent = send_status(100, "Continue");
flush();
return sent;
}
size_t RGWFCGX::send_header(const boost::string_ref& name,
const boost::string_ref& value)
{
static constexpr char HEADER_SEP[] = ": ";
static constexpr char HEADER_END[] = "\r\n";
size_t sent = 0;
sent += txbuf.sputn(name.data(), name.length());
sent += txbuf.sputn(HEADER_SEP, sizeof(HEADER_SEP) - 1);
sent += txbuf.sputn(value.data(), value.length());
sent += txbuf.sputn(HEADER_END, sizeof(HEADER_END) - 1);
return sent;
}
size_t RGWFCGX::send_content_length(const uint64_t len)
{
static constexpr size_t CONLEN_BUF_SIZE = 128;
char sizebuf[CONLEN_BUF_SIZE];
const auto sizelen = snprintf(sizebuf, sizeof(sizebuf),
"Content-Length: %" PRIu64 "\r\n", len);
return txbuf.sputn(sizebuf, sizelen);
}
size_t RGWFCGX::complete_header()
{
static constexpr char HEADER_END[] = "\r\n";
const size_t sent = txbuf.sputn(HEADER_END, sizeof(HEADER_END) - 1);
flush();
return sent;
}
|