]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: restructure http/rest client class hierarchy
authorYehuda Sadeh <yehuda@redhat.com>
Mon, 28 Aug 2017 09:33:49 +0000 (02:33 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 10 Apr 2018 15:05:05 +0000 (08:05 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_rest_client.cc
src/rgw/rgw_rest_client.h

index 93bfcedc57cf6762e8dcbca039cf6d149edb384e..6c2d6c5dda5dca0ae23b92efcc13a884216e6c2b 100644 (file)
@@ -16,7 +16,7 @@
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_rgw
 
-int RGWRESTSimpleRequest::get_status()
+int RGWHTTPSimpleRequest::get_status()
 {
   int retcode = get_req_retcode();
   if (retcode < 0) {
@@ -25,7 +25,7 @@ int RGWRESTSimpleRequest::get_status()
   return status;
 }
 
-int RGWRESTSimpleRequest::handle_header(const string& name, const string& val) 
+int RGWHTTPSimpleRequest::handle_header(const string& name, const string& val) 
 {
   if (name == "CONTENT_LENGTH") {
     string err;
@@ -41,7 +41,7 @@ int RGWRESTSimpleRequest::handle_header(const string& name, const string& val)
   return 0;
 }
 
-int RGWRESTSimpleRequest::receive_header(void *ptr, size_t len)
+int RGWHTTPSimpleRequest::receive_header(void *ptr, size_t len)
 {
   char line[len + 1];
 
@@ -147,7 +147,7 @@ int RGWRESTSimpleRequest::execute(RGWAccessKey& key, const char *_method, const
   return status;
 }
 
-int RGWRESTSimpleRequest::send_data(void *ptr, size_t len)
+int RGWHTTPSimpleRequest::send_data(void *ptr, size_t len)
 {
   if (!send_iter)
     return 0;
@@ -160,7 +160,7 @@ int RGWRESTSimpleRequest::send_data(void *ptr, size_t len)
   return len;
 }
 
-int RGWRESTSimpleRequest::receive_data(void *ptr, size_t len)
+int RGWHTTPSimpleRequest::receive_data(void *ptr, size_t len)
 {
   size_t cp_len, left_len;
 
@@ -177,7 +177,7 @@ int RGWRESTSimpleRequest::receive_data(void *ptr, size_t len)
 
 }
 
-void RGWRESTSimpleRequest::append_param(string& dest, const string& name, const string& val)
+void RGWHTTPSimpleRequest::append_param(string& dest, const string& name, const string& val)
 {
   if (dest.empty()) {
     dest.append("?");
@@ -196,7 +196,7 @@ void RGWRESTSimpleRequest::append_param(string& dest, const string& name, const
   }
 }
 
-void RGWRESTSimpleRequest::get_params_str(map<string, string>& extra_args, string& dest)
+void RGWHTTPSimpleRequest::get_params_str(map<string, string>& extra_args, string& dest)
 {
   map<string, string>::iterator miter;
   for (miter = extra_args.begin(); miter != extra_args.end(); ++miter) {
@@ -208,7 +208,7 @@ void RGWRESTSimpleRequest::get_params_str(map<string, string>& extra_args, strin
   }
 }
 
-int RGWRESTSimpleRequest::sign_request(RGWAccessKey& key, RGWEnv& env, req_info& info)
+static int sign_request(CephContext *cct, RGWAccessKey& key, RGWEnv& env, req_info& info)
 {
   /* don't sign if no key is provided */
   if (key.key.empty()) {
@@ -256,7 +256,7 @@ int RGWRESTSimpleRequest::forward_request(RGWAccessKey& key, req_info& info, siz
 
   new_env.set("HTTP_DATE", date_str.c_str());
 
-  int ret = sign_request(key, new_env, new_info);
+  int ret = sign_request(cct, key, new_env, new_info);
   if (ret < 0) {
     ldout(cct, 0) << "ERROR: failed to sign request" << dendl;
     return ret;
@@ -483,7 +483,7 @@ int RGWRESTStreamWriteRequest::put_obj_init(RGWAccessKey& key, rgw_obj& obj, uin
     grants_by_type_add_perm(grants_by_type, perm.get_permissions(), grant);
   }
   add_grants_headers(grants_by_type, new_env, new_info.x_meta_map);
-  ret = sign_request(key, new_env, new_info);
+  ret = sign_request(cct, key, new_env, new_info);
   if (ret < 0) {
     ldout(cct, 0) << "ERROR: failed to sign request" << dendl;
     return ret;
@@ -671,7 +671,7 @@ int RGWRESTStreamRWRequest::send_request(RGWAccessKey *key, map<string, string>&
   new_info.init_meta_info(NULL);
 
   if (key) {
-    int ret = sign_request(*key, new_env, new_info);
+    int ret = sign_request(cct, *key, new_env, new_info);
     if (ret < 0) {
       ldout(cct, 0) << "ERROR: failed to sign request" << dendl;
       return ret;
index c71b50750dfe197a05c5abab38eba60f33f1bbdb..9c474534e9ceb4068d0f1b8ed01268eccf20ce1b 100644 (file)
@@ -8,7 +8,7 @@
 
 class RGWGetDataCB;
 
-class RGWRESTSimpleRequest : public RGWHTTPClient {
+class RGWHTTPSimpleRequest : public RGWHTTPClient {
 protected:
   int http_status;
   int status;
@@ -25,9 +25,8 @@ protected:
   void append_param(string& dest, const string& name, const string& val);
   void get_params_str(map<string, string>& extra_args, string& dest);
 
-  int sign_request(RGWAccessKey& key, RGWEnv& env, req_info& info);
 public:
-  RGWRESTSimpleRequest(CephContext *_cct, const string& _method, const string& _url,
+  RGWHTTPSimpleRequest(CephContext *_cct, const string& _method, const string& _url,
                        param_vec_t *_headers, param_vec_t *_params) : RGWHTTPClient(_cct, _method, _url),
                 http_status(0), status(0),
                 send_iter(NULL),
@@ -52,15 +51,21 @@ public:
 
   bufferlist& get_response() { return response; }
 
-  int execute(RGWAccessKey& key, const char *method, const char *resource);
-  int forward_request(RGWAccessKey& key, req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl);
-
   map<string, string>& get_out_headers() { return out_headers; }
 
   int get_http_status() { return http_status; }
   int get_status();
 };
 
+class RGWRESTSimpleRequest : public RGWHTTPSimpleRequest {
+public:
+  RGWRESTSimpleRequest(CephContext *_cct, const string& _method, const string& _url,
+                       param_vec_t *_headers, param_vec_t *_params) : RGWHTTPSimpleRequest(_cct, _method, _url, _headers, _params) {}
+
+  int execute(RGWAccessKey& key, const char *method, const char *resource);
+  int forward_request(RGWAccessKey& key, req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl);
+};
+
 
 class RGWRESTStreamWriteRequest : public RGWRESTSimpleRequest {
   Mutex lock;
@@ -81,7 +86,7 @@ public:
   RGWGetDataCB *get_out_cb() { return cb; }
 };
 
-class RGWHTTPStreamRWRequest : public RGWRESTSimpleRequest {
+class RGWHTTPStreamRWRequest : public RGWHTTPSimpleRequest {
   Mutex lock;
   Mutex write_lock;
   RGWGetDataCB *cb;
@@ -100,8 +105,8 @@ public:
   int receive_data(void *ptr, size_t len) override;
 
   RGWHTTPStreamRWRequest(CephContext *_cct, const string& _method, const string& _url, RGWGetDataCB *_cb,
-                         param_vec_t *_headers, param_vec_t *_params) : RGWRESTSimpleRequest(_cct, _method, _url, _headers, _params),
-                                                                        lock("RGWRESTStreamRWRequest"), write_lock("RGWRESTStreamRWRequest::write_lock"), cb(_cb) {
+                         param_vec_t *_headers, param_vec_t *_params) : RGWHTTPSimpleRequest(_cct, _method, _url, _headers, _params),
+                                                                        lock("RGWHTTPStreamRWRequest"), write_lock("RGWHTTPStreamRWRequest::write_lock"), cb(_cb) {
   }
   virtual ~RGWHTTPStreamRWRequest() override {}