]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: hide fcgi details from client code
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 19 Sep 2012 19:36:44 +0000 (12:36 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Mon, 8 Oct 2012 17:57:43 +0000 (10:57 -0700)
client code (rgw_rest* et al) does not need to see the
fcgi library details.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
17 files changed:
src/Makefile.am
src/rgw/rgw_client_io.cc [new file with mode: 0644]
src/rgw/rgw_client_io.h [new file with mode: 0644]
src/rgw/rgw_common.h
src/rgw/rgw_fcgi.cc [new file with mode: 0644]
src/rgw/rgw_fcgi.h [new file with mode: 0644]
src/rgw/rgw_main.cc
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest.cc
src/rgw/rgw_rest.h
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_s3.h
src/rgw/rgw_rest_swift.cc
src/rgw/rgw_rest_swift.h
src/rgw/rgw_swift_auth.cc
src/rgw/rgw_swift_auth.h

index 56fc8f7d4478f9fc85da42618e4a137e8f920167..2cd7b45fd476e459d72622ad1783d9d6b33c2550 100644 (file)
@@ -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 (file)
index 0000000..740418c
--- /dev/null
@@ -0,0 +1,60 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#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 (file)
index 0000000..d4842e9
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef CEPH_RGW_CLIENT_IO_H
+#define CEPH_RGW_CLIENT_IO_H
+
+#include <stdlib.h>
+
+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
index b745d0546248c258cbbe12adf8d4053f09e9e976..4f3f14c07feec8f7c095fbab674fe9a4c8ee937c 100644 (file)
@@ -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 (file)
index 0000000..70ed996
--- /dev/null
@@ -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 (file)
index 0000000..ccf48f5
--- /dev/null
@@ -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
index 7445be86eb7fae61722ded955e1deea1e807cf34..b4d2623c6b63c0395b98f3618ba4575bb936b960 100644 (file)
@@ -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;
index c83509a5408a6c8357328ad0f8655902645f4d6c..66993f73d4c1fb7f56269c450c647abf616c726f 100644 (file)
 #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;
 }
 
index de0ede3e4366a3abc38455a9a47c2296fcee7a70..0e284bab1b9bbd4a15cf8cad9092aba94311a943 100644 (file)
@@ -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;
index b0c7e183bee0c279aae1e0d59d4bd64ce433d7d0..745a0ff51af922fd8d0edcdadc0cd3a4e7986dcd 100644 (file)
 
 #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;
 
index 77ea4971e76ea0479ee7a7e19438b5ad3c97c60f..5b8696f2dd0f7ce31fb179ffe49585b0180ee5ab 100644 (file)
@@ -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);
 };
 
index 0971e457df8daf174ed97a03f3567a34a685505e..8d9bfef03d39c32c7a6373aacc5c65ff5fccfb5f 100644 (file)
 
 #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);
 }
 
 /*
index 9bc124de467f035eb1e7f34d2165fec74c95f259..60b73458d466595efbb27e4681408a029e1077b6 100644 (file)
@@ -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();
 };
 
index 63ccee7e1a9bbfd19f4dc2f69856a3ff917c7b7b..c5498b5f1e0696d28d6567b003b718bb262cbfc6 100644 (file)
@@ -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 <sstream>
 
@@ -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<RGWAccessControlPolicy_SWIFT *>(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);
 }
index 97f24ba293bae3b987484b65a88730687d2d5252..7a0f6506e896177546f6487c57d046fbfd6a130a 100644 (file)
@@ -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; */ }
index 7e00024eb1d6b81beead11098102cad44852a3c5..6c465a240b8558a9cba037cc0d59af95e0e22bf2 100644 (file)
@@ -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()
index b5c26cde0b60d8541310aac4c9e9f30ef2b0093e..fdbf25105f6283ac61f7c1c2495c9370c7d9cb57 100644 (file)
@@ -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; }