From a9c9f96ba57578e74dca882c76276506c652a929 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 19 Sep 2012 12:36:44 -0700 Subject: [PATCH] rgw: hide fcgi details from client code client code (rgw_rest* et al) does not need to see the fcgi library details. Signed-off-by: Yehuda Sadeh --- src/Makefile.am | 4 ++ src/rgw/rgw_client_io.cc | 60 +++++++++++++++++++++++++ src/rgw/rgw_client_io.h | 32 ++++++++++++++ src/rgw/rgw_common.h | 31 ++----------- src/rgw/rgw_fcgi.cc | 31 +++++++++++++ src/rgw/rgw_fcgi.h | 24 ++++++++++ src/rgw/rgw_main.cc | 5 ++- src/rgw/rgw_op.cc | 14 +++--- src/rgw/rgw_op.h | 2 +- src/rgw/rgw_rest.cc | 92 +++++++++++++++++++++++++++------------ src/rgw/rgw_rest.h | 6 ++- src/rgw/rgw_rest_s3.cc | 30 ++++++------- src/rgw/rgw_rest_s3.h | 2 +- src/rgw/rgw_rest_swift.cc | 33 ++++++-------- src/rgw/rgw_rest_swift.h | 2 +- src/rgw/rgw_swift_auth.cc | 18 +++----- src/rgw/rgw_swift_auth.h | 2 +- 17 files changed, 270 insertions(+), 118 deletions(-) create mode 100644 src/rgw/rgw_client_io.cc create mode 100644 src/rgw/rgw_client_io.h create mode 100644 src/rgw/rgw_fcgi.cc create mode 100644 src/rgw/rgw_fcgi.h diff --git a/src/Makefile.am b/src/Makefile.am index 56fc8f7d4478f..2cd7b45fd476e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -310,6 +310,8 @@ librgw_a_SOURCES = \ rgw/rgw_acl.cc \ rgw/rgw_acl_s3.cc \ rgw/rgw_acl_swift.cc \ + rgw/rgw_client_io.cc \ + rgw/rgw_fcgi.cc \ rgw/rgw_xml.cc \ rgw/rgw_user.cc \ rgw/rgw_tools.cc \ @@ -1695,6 +1697,8 @@ noinst_HEADERS = \ rgw/rgw_acl.h\ rgw/rgw_acl_s3.h\ rgw/rgw_acl_swift.h\ + rgw/rgw_client_io.h\ + rgw/rgw_fcgi.h\ rgw/rgw_xml.h\ rgw/rgw_cache.h\ rgw/rgw_common.h\ diff --git a/src/rgw/rgw_client_io.cc b/src/rgw/rgw_client_io.cc new file mode 100644 index 0000000000000..740418c9ab165 --- /dev/null +++ b/src/rgw/rgw_client_io.cc @@ -0,0 +1,60 @@ + +#include +#include +#include + +#include "rgw_client_io.h" + + +int RGWClientIO::print(const char *format, ...) +{ +#define LARGE_ENOUGH 128 + int size = LARGE_ENOUGH; + + va_list ap; + + while(1) { + char buf[size]; + va_start(ap, format); + int ret = vsnprintf(buf, size, format, ap); + va_end(ap); + + if (ret >= 0 && ret < size) { + return write(buf, ret); + } + + if (ret >= 0) + size = ret + 1; + else + size *= 2; + } + + /* not reachable */ +} + +int RGWClientIO::write(const char *buf, int len) +{ + int ret = write_data(buf, len); + if (ret < 0) + return ret; + + if (account) + bytes_sent += len; + + return 0; +} + + +int RGWClientIO::read(char *buf, int max, int *actual) +{ + int ret = read_data(buf, max); + if (ret < 0) + return ret; + + *actual = ret; + + if (account) + bytes_received += *actual; + + return 0; +} diff --git a/src/rgw/rgw_client_io.h b/src/rgw/rgw_client_io.h new file mode 100644 index 0000000000000..d4842e97e6e6f --- /dev/null +++ b/src/rgw/rgw_client_io.h @@ -0,0 +1,32 @@ +#ifndef CEPH_RGW_CLIENT_IO_H +#define CEPH_RGW_CLIENT_IO_H + +#include + +class RGWClientIO { + bool account; + + size_t bytes_sent; + size_t bytes_received; + +protected: + virtual int write_data(const char *buf, int len) = 0; + virtual int read_data(char *buf, int max) = 0; + +public: + virtual ~RGWClientIO() {} + RGWClientIO() : account(false), bytes_sent(0), bytes_received(0) {} + + int print(const char *format, ...); + int write(const char *buf, int len); + virtual void flush() = 0; + int read(char *buf, int max, int *actual); + + virtual const char **envp() = 0; + + void set_account(bool _account) { + account = _account; + } +}; + +#endif diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index b745d0546248c..4f3f14c07feec 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -71,32 +71,6 @@ using ceph::crypto::MD5; #define RGW_DEFAULT_MAX_BUCKETS 1000 -#define CGI_PRINTF(state, format, ...) do { \ - int __ret = FCGX_FPrintF(state->fcgx->out, format, __VA_ARGS__); \ - if (state->header_ended) \ - state->bytes_sent += __ret; \ - int l = 32, n; \ - while (1) { \ - char __buf[l]; \ - n = snprintf(__buf, sizeof(__buf), format, __VA_ARGS__); \ - if (n != l) \ - dout(10) << "--> " << __buf << dendl; \ - break; \ - l *= 2; \ - } \ -} while (0) - -#define CGI_PutStr(state, buf, len) do { \ - FCGX_PutStr(buf, len, state->fcgx->out); \ - if (state->header_ended) \ - state->bytes_sent += len; \ -} while (0) - -#define CGI_GetStr(state, buf, buf_len, olen) do { \ - olen = FCGX_GetStr(buf, buf_len, state->fcgx->in); \ - state->bytes_received += olen; \ -} while (0) - #define STATUS_CREATED 1900 #define STATUS_ACCEPTED 1901 #define STATUS_NO_CONTENT 1902 @@ -544,12 +518,13 @@ struct RGWBucketStats struct req_state; struct RGWEnv; -struct FCGX_Request; + +class RGWClientIO; /** Store all the state necessary to complete and respond to an HTTP request*/ struct req_state { CephContext *cct; - FCGX_Request *fcgx; + RGWClientIO *cio; http_op op; bool content_started; int format; diff --git a/src/rgw/rgw_fcgi.cc b/src/rgw/rgw_fcgi.cc new file mode 100644 index 0000000000000..70ed99619754c --- /dev/null +++ b/src/rgw/rgw_fcgi.cc @@ -0,0 +1,31 @@ + + +#include "rgw_fcgi.h" + +#include "acconfig.h" +#ifdef FASTCGI_INCLUDE_DIR +# include "fastcgi/fcgiapp.h" +#else +# include "fcgiapp.h" +#endif + + +int RGWFCGX::write_data(const char *buf, int len) +{ + return FCGX_PutStr(buf, len, fcgx->out); +} + +int RGWFCGX::read_data(char *buf, int len) +{ + return FCGX_GetStr(buf, len, fcgx->in); +} + +void RGWFCGX::flush() +{ + FCGX_FFlush(fcgx->out); +} + +const char **RGWFCGX::envp() +{ + return (const char **)fcgx->envp; +} diff --git a/src/rgw/rgw_fcgi.h b/src/rgw/rgw_fcgi.h new file mode 100644 index 0000000000000..ccf48f5954da9 --- /dev/null +++ b/src/rgw/rgw_fcgi.h @@ -0,0 +1,24 @@ +#ifndef CEPH_RGW_FCGI_H +#define CEPH_RGW_FCGI_H + +#include "rgw_client_io.h" + + +struct FCGX_Request; + + +class RGWFCGX : public RGWClientIO +{ + FCGX_Request *fcgx; +protected: + int write_data(const char *buf, int len); + int read_data(char *buf, int len); + +public: + RGWFCGX(FCGX_Request *_fcgx) : fcgx(_fcgx) {} + void flush(); + const char **envp(); +}; + + +#endif diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 7445be86eb7fa..b4d2623c6b63c 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -17,6 +17,8 @@ # include "fcgiapp.h" #endif +#include "rgw_fcgi.h" + #include "common/ceph_argparse.h" #include "global/global_init.h" #include "global/signal_handler.h" @@ -248,6 +250,7 @@ void RGWProcess::handle_request(RGWRequest *req) RGWRESTMgr rest; int ret; RGWEnv rgw_env; + RGWFCGX client_io(fcgx); req->log_init(); @@ -264,7 +267,7 @@ void RGWProcess::handle_request(RGWRequest *req) RGWOp *op = NULL; int init_error = 0; - RGWHandler *handler = rest.get_handler(s, fcgx, &init_error); + RGWHandler *handler = rest.get_handler(s, &client_io, &init_error); if (init_error != 0) { abort_early(s, init_error); goto done; diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index c83509a5408a6..66993f73d4c1f 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -19,11 +19,7 @@ #include "rgw_multi.h" #include "rgw_multi_del.h" -#ifdef FASTCGI_INCLUDE_DIR -# include "fastcgi/fcgiapp.h" -#else -# include "fcgiapp.h" -#endif +#include "rgw_client_io.h" #define dout_subsys ceph_subsys_rgw @@ -2035,16 +2031,18 @@ RGWHandler::~RGWHandler() { } -int RGWHandler::init(struct req_state *_s, FCGX_Request *fcgx) +int RGWHandler::init(struct req_state *_s, RGWClientIO *cio) { s = _s; if (s->cct->_conf->subsys.should_gather(ceph_subsys_rgw, 20)) { - char *p; - for (int i=0; (p = fcgx->envp[i]); ++i) { + const char *p; + const char **envp = cio->envp(); + for (int i=0; (p = envp[i]); ++i) { ldout(s->cct, 20) << p << dendl; } } + return 0; } diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index de0ede3e4366a..0e284bab1b9bb 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -664,7 +664,7 @@ protected: public: RGWHandler() {} virtual ~RGWHandler(); - virtual int init(struct req_state *_s, FCGX_Request *fcgx); + virtual int init(struct req_state *_s, RGWClientIO *cio); virtual bool filter_request(struct req_state *s) = 0; virtual RGWOp *get_op() = 0; diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index b0c7e183bee0c..745a0ff51af92 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -13,17 +13,16 @@ #include "rgw_formats.h" -#ifdef FASTCGI_INCLUDE_DIR -# include "fastcgi/fcgiapp.h" -#else -# include "fcgiapp.h" -#endif +#include "rgw_client_io.h" #define dout_subsys ceph_subsys_rgw static void dump_status(struct req_state *s, const char *status) { - CGI_PRINTF(s,"Status: %s\n", status); + int r = s->cio->print("Status: %s\n", status); + if (r < 0) { + ldout(s->cct, 0) << "ERROR: s->cio->print() returned err=" << r << dendl; + } } void rgw_flush_formatter_and_reset(struct req_state *s, Formatter *formatter) @@ -32,7 +31,7 @@ void rgw_flush_formatter_and_reset(struct req_state *s, Formatter *formatter) formatter->flush(oss); std::string outs(oss.str()); if (!outs.empty()) { - CGI_PutStr(s, outs.c_str(), outs.size()); + s->cio->write(outs.c_str(), outs.size()); } s->formatter->reset(); @@ -44,7 +43,7 @@ void rgw_flush_formatter(struct req_state *s, Formatter *formatter) formatter->flush(oss); std::string outs(oss.str()); if (!outs.empty()) { - CGI_PutStr(s, outs.c_str(), outs.size()); + s->cio->write(outs.c_str(), outs.size()); } } @@ -93,16 +92,26 @@ void dump_content_length(struct req_state *s, size_t len) { char buf[16]; snprintf(buf, sizeof(buf), "%lu", (long unsigned int)len); - CGI_PRINTF(s, "Content-Length: %s\n", buf); - CGI_PRINTF(s, "Accept-Ranges: %s\n", "bytes"); + int r = s->cio->print("Content-Length: %s\n", buf); + if (r < 0) { + ldout(s->cct, 0) << "ERROR: s->cio->print() returned err=" << r << dendl; + } + r = s->cio->print("Accept-Ranges: %s\n", "bytes"); + if (r < 0) { + ldout(s->cct, 0) << "ERROR: s->cio->print() returned err=" << r << dendl; + } } void dump_etag(struct req_state *s, const char *etag) { + int r; if (s->prot_flags & RGW_REST_SWIFT) - CGI_PRINTF(s,"etag: %s\n", etag); + r = s->cio->print("etag: %s\n", etag); else - CGI_PRINTF(s,"ETag: \"%s\"\n", etag); + r = s->cio->print("ETag: \"%s\"\n", etag); + if (r < 0) { + ldout(s->cct, 0) << "ERROR: s->cio->print() returned err=" << r << dendl; + } } void dump_last_modified(struct req_state *s, time_t t) @@ -116,7 +125,10 @@ void dump_last_modified(struct req_state *s, time_t t) if (strftime(timestr, sizeof(timestr), "%a, %d %b %Y %H:%M:%S %Z", tmp) == 0) return; - CGI_PRINTF(s, "Last-Modified: %s\n", timestr); + int r = s->cio->print("Last-Modified: %s\n", timestr); + if (r < 0) { + ldout(s->cct, 0) << "ERROR: s->cio->print() returned err=" << r << dendl; + } } void dump_time(struct req_state *s, const char *name, time_t *t) @@ -182,8 +194,11 @@ void end_header(struct req_state *s, const char *content_type) s->formatter->close_section(); dump_content_length(s, s->formatter->get_len()); } - CGI_PRINTF(s,"Content-type: %s\r\n\r\n", content_type); - s->header_ended = true; + int r = s->cio->print("Content-type: %s\r\n\r\n", content_type); + if (r < 0) { + ldout(s->cct, 0) << "ERROR: s->cio->print() returned err=" << r << dendl; + } + s->cio->set_account(true); rgw_flush_formatter_and_reset(s, s->formatter); } @@ -199,7 +214,7 @@ void abort_early(struct req_state *s, int err_no) void dump_continue(struct req_state *s) { dump_status(s, "100"); - FCGX_FFlush(s->fcgx->out); + s->cio->flush(); } void dump_range(struct req_state *s, uint64_t ofs, uint64_t end, uint64_t total) @@ -208,7 +223,10 @@ void dump_range(struct req_state *s, uint64_t ofs, uint64_t end, uint64_t total) /* dumping range into temp buffer first, as libfcgi will fail to digest %lld */ snprintf(range_buf, sizeof(range_buf), "%lld-%lld/%lld", (long long)ofs, (long long)end, (long long)total); - CGI_PRINTF(s,"Content-Range: bytes %s\n", range_buf); + int r = s->cio->print("Content-Range: bytes %s\n", range_buf); + if (r < 0) { + ldout(s->cct, 0) << "ERROR: s->cio->print() returned err=" << r << dendl; + } } int RGWGetObj_REST::get_params() @@ -257,7 +275,11 @@ int RGWPutObj_REST::get_data(bufferlist& bl) if (cl) { bufferptr bp(cl); - CGI_GetStr(s, bp.c_str(), cl, len); + int read_len; /* cio->read() expects int * */ + int r = s->cio->read(bp.c_str(), cl, &read_len); + len = read_len; + if (r < 0) + return ret; bl.append(bp); } @@ -282,7 +304,11 @@ int RGWPutACLs_REST::get_params() ret = -ENOMEM; return ret; } - CGI_GetStr(s, data, cl, len); + int read_len; + int r = s->cio->read(data, cl, &read_len); + len = read_len; + if (r < 0) + return r; data[len] = '\0'; } else { len = 0; @@ -312,7 +338,9 @@ static int read_all_chunked_input(req_state *s, char **pdata, int *plen) int read_len = 0, len = 0; do { - CGI_GetStr(s, data + len, need_to_read, read_len); + int r = s->cio->read(data + len, need_to_read, &read_len); + if (r < 0) + return r; len += read_len; @@ -359,7 +387,9 @@ int RGWCompleteMultipart_REST::get_params() ret = -ENOMEM; return ret; } - CGI_GetStr(s, data, cl, len); + ret = s->cio->read(data, cl, &len); + if (ret < 0) + return ret; data[len] = '\0'; } else { const char *encoding = s->env->get("HTTP_TRANSFER_ENCODING"); @@ -432,7 +462,11 @@ int RGWDeleteMultiObj_REST::get_params() ret = -ENOMEM; return ret; } - CGI_GetStr(s, data, cl, len); + int read_len; + ret = s->cio->read(data, cl, &read_len); + len = read_len; + if (ret < 0) + return ret; data[len] = '\0'; } else { return -EINVAL; @@ -494,7 +528,9 @@ static int init_meta_info(struct req_state *s) s->x_meta_map.clear(); - for (int i=0; (p = s->fcgx->envp[i]); ++i) { + const char **envp = s->cio->envp(); + + for (int i=0; (p = envp[i]); ++i) { const char *prefix; for (int prefix_num = 0; (prefix = meta_prefixes[prefix_num].str) != NULL; prefix_num++) { int len = meta_prefixes[prefix_num].len; @@ -605,9 +641,9 @@ static http_op op_from_method(const char *method) return OP_UNKNOWN; } -int RGWHandler_REST::preprocess(struct req_state *s, FCGX_Request *fcgx) +int RGWHandler_REST::preprocess(struct req_state *s, RGWClientIO *cio) { - s->fcgx = fcgx; + s->cio = cio; s->request_uri = s->env->get("REQUEST_URI"); int pos = s->request_uri.find('?'); if (pos >= 0) { @@ -722,12 +758,12 @@ RGWRESTMgr::~RGWRESTMgr() } } -RGWHandler *RGWRESTMgr::get_handler(struct req_state *s, FCGX_Request *fcgx, +RGWHandler *RGWRESTMgr::get_handler(struct req_state *s, RGWClientIO *cio, int *init_error) { RGWHandler *handler; - *init_error = RGWHandler_REST::preprocess(s, fcgx); + *init_error = RGWHandler_REST::preprocess(s, cio); if (*init_error < 0) return NULL; @@ -740,7 +776,7 @@ RGWHandler *RGWRESTMgr::get_handler(struct req_state *s, FCGX_Request *fcgx, if (iter == protocol_handlers.end()) return NULL; - *init_error = handler->init(s, fcgx); + *init_error = handler->init(s, cio); if (*init_error < 0) return NULL; diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index 77ea4971e76ea..5b8696f2dd0f7 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -10,6 +10,8 @@ extern void rgw_flush_formatter_and_reset(struct req_state *s, extern void rgw_flush_formatter(struct req_state *s, ceph::Formatter *formatter); +class RGWClientIO; + class RGWGetObj_REST : public RGWGetObj { protected: @@ -172,7 +174,7 @@ public: RGWOp *get_op(); void put_op(RGWOp *op); - static int preprocess(struct req_state *s, FCGX_Request *fcgx); + static int preprocess(struct req_state *s, RGWClientIO *cio); virtual bool filter_request(struct req_state *s) = 0; virtual int authorize() = 0; }; @@ -187,7 +189,7 @@ class RGWRESTMgr { public: RGWRESTMgr(); ~RGWRESTMgr(); - RGWHandler *get_handler(struct req_state *s, FCGX_Request *fcgx, + RGWHandler *get_handler(struct req_state *s, RGWClientIO *cio, int *init_error); }; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 0971e457df8da..8d9bfef03d39c 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -10,11 +10,7 @@ #include "common/armor.h" -#ifdef FASTCGI_INCLUDE_DIR -# include "fastcgi/fcgiapp.h" -#else -# include "fcgiapp.h" -#endif +#include "rgw_client_io.h" #define dout_subsys ceph_subsys_rgw @@ -88,26 +84,26 @@ int RGWGetObj_REST_S3::send_response(bufferlist& bl) content_type = content_type_str.c_str(); string val = s->args.get("response-content-language", &exists); if (exists) - CGI_PRINTF(s, "Content-Language: %s\n", val.c_str()); + s->cio->print("Content-Language: %s\n", val.c_str()); val = s->args.get("response-expires", &exists); if (exists) - CGI_PRINTF(s, "Expires: %s\n", val.c_str()); + s->cio->print("Expires: %s\n", val.c_str()); val = s->args.get("response-cache-control", &exists); if (exists) - CGI_PRINTF(s, "Cache-Control: %s\n", val.c_str()); + s->cio->print("Cache-Control: %s\n", val.c_str()); val = s->args.get("response-content-disposition", &exists); if (exists) - CGI_PRINTF(s, "Content-Disposition: %s\n", val.c_str()); + s->cio->print("Content-Disposition: %s\n", val.c_str()); val = s->args.get("response-content-encoding", &exists); if (exists) - CGI_PRINTF(s, "Content-Encoding: %s\n", val.c_str()); + s->cio->print("Content-Encoding: %s\n", val.c_str()); } for (iter = attrs.begin(); iter != attrs.end(); ++iter) { const char *name = iter->first.c_str(); if (strncmp(name, RGW_ATTR_META_PREFIX, sizeof(RGW_ATTR_META_PREFIX)-1) == 0) { name += sizeof(RGW_ATTR_PREFIX) - 1; - CGI_PRINTF(s,"%s: %s\r\n", name, iter->second.c_str()); + s->cio->print("%s: %s\r\n", name, iter->second.c_str()); } else if (!content_type && strcmp(name, RGW_ATTR_CONTENT_TYPE) == 0) { content_type = iter->second.c_str(); } @@ -127,7 +123,7 @@ done: send_data: if (get_data && !orig_ret) { - CGI_PutStr(s, bl.c_str(), len); + s->cio->write(bl.c_str(), len); } return 0; @@ -223,9 +219,9 @@ static void dump_bucket_metadata(struct req_state *s, RGWBucketEnt& bucket) { char buf[32]; snprintf(buf, sizeof(buf), "%lld", (long long)bucket.count); - CGI_PRINTF(s,"X-RGW-Object-Count: %s\n", buf); + s->cio->print("X-RGW-Object-Count: %s\n", buf); snprintf(buf, sizeof(buf), "%lld", (long long)bucket.size); - CGI_PRINTF(s,"X-RGW-Bytes-Used: %s\n", buf); + s->cio->print("X-RGW-Bytes-Used: %s\n", buf); } void RGWStatBucket_REST_S3::send_response() @@ -396,7 +392,7 @@ void RGWGetACLs_REST_S3::send_response() dump_errno(s); end_header(s, "application/xml"); dump_start(s); - CGI_PutStr(s, acls.c_str(), acls.size()); + s->cio->write(acls.c_str(), acls.size()); } int RGWPutACLs_REST_S3::get_canned_policy(ACLOwner& owner, stringstream& ss) @@ -863,7 +859,7 @@ int RGWHandler_REST_S3::validate_bucket_name(const string& bucket) return 0; } -int RGWHandler_REST_S3::init(struct req_state *s, FCGX_Request *fcgx) +int RGWHandler_REST_S3::init(struct req_state *s, RGWClientIO *cio) { int ret = init_from_header(s); if (ret < 0) @@ -886,7 +882,7 @@ int RGWHandler_REST_S3::init(struct req_state *s, FCGX_Request *fcgx) s->dialect = "s3"; - return RGWHandler_REST::init(s, fcgx); + return RGWHandler_REST::init(s, cio); } /* diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 9bc124de467f0..60b73458d4665 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -187,7 +187,7 @@ public: bool filter_request(struct req_state *state) { return true; } int validate_bucket_name(const string& bucket); - virtual int init(struct req_state *state, FCGX_Request *fcgx); + virtual int init(struct req_state *state, RGWClientIO *cio); int authorize(); }; diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index 63ccee7e1a9bb..c5498b5f1e069 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -5,12 +5,7 @@ #include "rgw_rest_swift.h" #include "rgw_acl_swift.h" #include "rgw_formats.h" - -#ifdef FASTCGI_INCLUDE_DIR -# include "fastcgi/fcgiapp.h" -#else -# include "fcgiapp.h" -#endif +#include "rgw_client_io.h" #include @@ -195,21 +190,21 @@ static void dump_container_metadata(struct req_state *s, RGWBucketEnt& bucket) { char buf[32]; snprintf(buf, sizeof(buf), "%lld", (long long)bucket.count); - CGI_PRINTF(s,"X-Container-Object-Count: %s\n", buf); + s->cio->print("X-Container-Object-Count: %s\n", buf); snprintf(buf, sizeof(buf), "%lld", (long long)bucket.size); - CGI_PRINTF(s,"X-Container-Bytes-Used: %s\n", buf); + s->cio->print("X-Container-Bytes-Used: %s\n", buf); snprintf(buf, sizeof(buf), "%lld", (long long)bucket.size_rounded); - CGI_PRINTF(s,"X-Container-Bytes-Used-Actual: %s\n", buf); + s->cio->print("X-Container-Bytes-Used-Actual: %s\n", buf); if (!s->object) { RGWAccessControlPolicy_SWIFT *swift_policy = static_cast(s->bucket_acl); string read_acl, write_acl; swift_policy->to_str(read_acl, write_acl); if (read_acl.size()) { - CGI_PRINTF(s, "X-Container-Read: %s\r\n", read_acl.c_str()); + s->cio->print("X-Container-Read: %s\r\n", read_acl.c_str()); } if (write_acl.size()) { - CGI_PRINTF(s, "X-Container-Write: %s\r\n", write_acl.c_str()); + s->cio->print("X-Container-Write: %s\r\n", write_acl.c_str()); } } } @@ -219,13 +214,13 @@ static void dump_account_metadata(struct req_state *s, uint32_t buckets_count, { char buf[32]; snprintf(buf, sizeof(buf), "%lld", (long long)buckets_count); - CGI_PRINTF(s,"X-Account-Container-Count: %s\n", buf); + s->cio->print("X-Account-Container-Count: %s\n", buf); snprintf(buf, sizeof(buf), "%lld", (long long)buckets_object_count); - CGI_PRINTF(s,"X-Account-Object-Count: %s\n", buf); + s->cio->print("X-Account-Object-Count: %s\n", buf); snprintf(buf, sizeof(buf), "%lld", (long long)buckets_size); - CGI_PRINTF(s,"X-Account-Bytes-Used: %s\n", buf); + s->cio->print("X-Account-Bytes-Used: %s\n", buf); snprintf(buf, sizeof(buf), "%lld", (long long)buckets_size_rounded); - CGI_PRINTF(s,"X-Account-Bytes-Used-Actual: %s\n", buf); + s->cio->print("X-Account-Bytes-Used-Actual: %s\n", buf); } void RGWStatAccount_REST_SWIFT::send_response() @@ -462,7 +457,7 @@ int RGWGetObj_REST_SWIFT::send_response(bufferlist& bl) const char *name = iter->first.c_str(); if (strncmp(name, RGW_ATTR_META_PREFIX, sizeof(RGW_ATTR_META_PREFIX)-1) == 0) { name += sizeof(RGW_ATTR_META_PREFIX) - 1; - CGI_PRINTF(s, "X-%s-Meta-%s: %s\r\n", (s->object ? "Object" : "Container"), name, iter->second.c_str()); + s->cio->print("X-%s-Meta-%s: %s\r\n", (s->object ? "Object" : "Container"), name, iter->second.c_str()); } else if (!content_type && strcmp(name, RGW_ATTR_CONTENT_TYPE) == 0) { content_type = iter->second.c_str(); } @@ -483,7 +478,7 @@ int RGWGetObj_REST_SWIFT::send_response(bufferlist& bl) send_data: if (get_data && !orig_ret) { - CGI_PutStr(s, bl.c_str(), len); + s->cio->write(bl.c_str(), len); } rgw_flush_formatter_and_reset(s, s->formatter); @@ -746,7 +741,7 @@ int RGWHandler_REST_SWIFT::init_from_header(struct req_state *s) return 0; } -int RGWHandler_REST_SWIFT::init(struct req_state *s, FCGX_Request *fcgx) +int RGWHandler_REST_SWIFT::init(struct req_state *s, RGWClientIO *cio) { int ret = init_from_header(s); if (ret < 0) @@ -765,5 +760,5 @@ int RGWHandler_REST_SWIFT::init(struct req_state *s, FCGX_Request *fcgx) s->dialect = "swift"; - return RGWHandler_REST::init(s, fcgx); + return RGWHandler_REST::init(s, cio); } diff --git a/src/rgw/rgw_rest_swift.h b/src/rgw/rgw_rest_swift.h index 97f24ba293bae..7a0f6506e8961 100644 --- a/src/rgw/rgw_rest_swift.h +++ b/src/rgw/rgw_rest_swift.h @@ -151,7 +151,7 @@ public: bool filter_request(struct req_state *s); int validate_bucket_name(const string& bucket); - int init(struct req_state *state, FCGX_Request *fcgx); + int init(struct req_state *state, RGWClientIO *cio); int authorize(); RGWAccessControlPolicy *alloc_policy() { return NULL; /* return new RGWAccessControlPolicy_SWIFT; */ } diff --git a/src/rgw/rgw_swift_auth.cc b/src/rgw/rgw_swift_auth.cc index 7e00024eb1d6b..6c465a240b855 100644 --- a/src/rgw/rgw_swift_auth.cc +++ b/src/rgw/rgw_swift_auth.cc @@ -6,11 +6,7 @@ #include "auth/Crypto.h" -#ifdef FASTCGI_INCLUDE_DIR -# include "fastcgi/fcgiapp.h" -#else -# include "fcgiapp.h" -#endif +#include "rgw_client_io.h" #define dout_subsys ceph_subsys_rgw @@ -202,8 +198,8 @@ void RGW_SWIFT_Auth_Get::execute() goto done; } - CGI_PRINTF(s, "X-Storage-Url: %s/%s/v1\n", swift_url.c_str(), - swift_prefix.c_str()); + s->cio->print("X-Storage-Url: %s/%s/v1\n", swift_url.c_str(), + swift_prefix.c_str()); if ((ret = encode_token(s->cct, swift_key->id, swift_key->key, bl)) < 0) goto done; @@ -212,8 +208,8 @@ void RGW_SWIFT_Auth_Get::execute() char buf[bl.length() * 2 + 1]; buf_to_hex((const unsigned char *)bl.c_str(), bl.length(), buf); - CGI_PRINTF(s, "X-Storage-Token: AUTH_rgwtk%s\n", buf); - CGI_PRINTF(s, "X-Auth-Token: AUTH_rgwtk%s\n", buf); + s->cio->print("X-Storage-Token: AUTH_rgwtk%s\n", buf); + s->cio->print("X-Auth-Token: AUTH_rgwtk%s\n", buf); } ret = STATUS_NO_CONTENT; @@ -266,11 +262,11 @@ bool RGWHandler_SWIFT_Auth::filter_request(struct req_state *s) return (bucket.compare(auth_bucket) == 0); } -int RGWHandler_SWIFT_Auth::init(struct req_state *state, FCGX_Request *fcgx) +int RGWHandler_SWIFT_Auth::init(struct req_state *state, RGWClientIO *cio) { state->dialect = "swift-auth"; - return RGWHandler::init(state, fcgx); + return RGWHandler::init(state, cio); } int RGWHandler_SWIFT_Auth::authorize() diff --git a/src/rgw/rgw_swift_auth.h b/src/rgw/rgw_swift_auth.h index b5c26cde0b60d..fdbf25105f628 100644 --- a/src/rgw/rgw_swift_auth.h +++ b/src/rgw/rgw_swift_auth.h @@ -28,7 +28,7 @@ public: int validate_bucket_name(const string& bucket) { return 0; } int validate_object_name(const string& object) { return 0; } - int init(struct req_state *state, FCGX_Request *fcgx); + int init(struct req_state *state, RGWClientIO *cio); int authorize(); int read_permissions(RGWOp *op) { return 0; } -- 2.39.5