X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Frgw%2Frgw_fcgi.cc;fp=src%2Fceph%2Fsrc%2Frgw%2Frgw_fcgi.cc;h=68eee4760333a76e479db19657648488c7b9437e;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/rgw/rgw_fcgi.cc b/src/ceph/src/rgw/rgw_fcgi.cc new file mode 100644 index 0000000..68eee47 --- /dev/null +++ b/src/ceph/src/rgw/rgw_fcgi.cc @@ -0,0 +1,90 @@ +// -*- 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); +} + +void RGWFCGX::init_env(CephContext* const cct) +{ + env.init(cct, (char **)fcgx->envp); +} + +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; +}