From 5e04d3976534ee5c19cf68802f790bca7cb9239f Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Wed, 6 Apr 2016 17:38:53 +0200 Subject: [PATCH] rgw: replace RGWPostHTTPData with RGW[Keystone]HTTPTransceiver. Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_http_client.cc | 37 +--------------------------------- src/rgw/rgw_http_client.h | 41 +++++++++++++++++++++++--------------- src/rgw/rgw_swift.cc | 31 ++++++++++++++++++++++------ 3 files changed, 51 insertions(+), 58 deletions(-) diff --git a/src/rgw/rgw_http_client.cc b/src/rgw/rgw_http_client.cc index 1d0872e5e979a..90217ad087b83 100644 --- a/src/rgw/rgw_http_client.cc +++ b/src/rgw/rgw_http_client.cc @@ -399,7 +399,7 @@ int RGWHTTPHeadersCollector::receive_header(void * const ptr, const size_t len) return 0; } -int RGWPostHTTPData::send_data(void* ptr, size_t len) +int RGWHTTPTransceiver::send_data(void* ptr, size_t len) { int length_to_copy = 0; if (post_data_index < post_data.length()) { @@ -410,41 +410,6 @@ int RGWPostHTTPData::send_data(void* ptr, size_t len) return length_to_copy; } -int RGWPostHTTPData::receive_header(void *ptr, size_t len) { - char line[len + 1]; - - char *s = (char *)ptr, *end = (char *)ptr + len; - char *p = line; - ldout(cct, 20) << "RGWPostHTTPData::receive_header parsing HTTP headers" << dendl; - - while (s != end) { - if (*s == '\r') { - s++; - continue; - } - if (*s == '\n') { - *p = '\0'; - ldout(cct, 20) << "RGWPostHTTPData::receive_header: line=" - << line << dendl; - // TODO: fill whatever data required here - char *l = line; - char *tok = strsep(&l, " \t:"); - if (tok) { - while (l && *l == ' ') { - l++; - } - - if (strcasecmp(tok, "X-Subject-Token") == 0) { - subject_token = l; - } - } - } - if (s != end) { - *p++ = *s++; - } - } - return 0; -} #if HAVE_CURL_MULTI_WAIT diff --git a/src/rgw/rgw_http_client.h b/src/rgw/rgw_http_client.h index 3603c6cfde9c8..f9b9e473b5ba7 100644 --- a/src/rgw/rgw_http_client.h +++ b/src/rgw/rgw_http_client.h @@ -84,14 +84,14 @@ public: static const long HTTP_STATUS_UNAUTHORIZED = 401; virtual ~RGWHTTPClient(); - explicit RGWHTTPClient(CephContext *_cct) + explicit RGWHTTPClient(CephContext *cct) : send_len(0), has_send_len(false), http_status(HTTP_STATUS_NOSTATUS), req_data(nullptr), user_info(nullptr), verify_ssl(true), - cct(_cct) { + cct(cct) { } void set_user_info(void *info) { @@ -178,14 +178,27 @@ private: }; -class RGWPostHTTPData : public RGWHTTPClient { - bufferlist *bl; +class RGWHTTPTransceiver : public RGWHTTPHeadersCollector { + bufferlist * const read_bl; std::string post_data; size_t post_data_index; - std::string subject_token; + public: - RGWPostHTTPData(CephContext *_cct, bufferlist *_bl) : RGWHTTPClient(_cct), bl(_bl), post_data_index(0) {} - RGWPostHTTPData(CephContext *_cct, bufferlist *_bl, bool verify_ssl) : RGWHTTPClient(_cct), bl(_bl), post_data_index(0){ + RGWHTTPTransceiver(CephContext * const cct, + bufferlist * const read_bl, + const header_spec_t intercept_headers = {}) + : RGWHTTPHeadersCollector(cct, intercept_headers), + read_bl(read_bl), + post_data_index(0) { + } + + RGWHTTPTransceiver(CephContext * const cct, + bufferlist * const read_bl, + const bool verify_ssl, + const header_spec_t intercept_headers = {}) + : RGWHTTPHeadersCollector(cct, intercept_headers), + read_bl(read_bl), + post_data_index(0) { set_verify_ssl(verify_ssl); } @@ -193,21 +206,17 @@ public: this->post_data = _post_data; } - std::string get_subject_token() { - return subject_token; - } - protected: - int send_data(void* ptr, size_t len); + int send_data(void* ptr, size_t len) override; - int receive_data(void *ptr, size_t len) { - bl->append((char *)ptr, len); + int receive_data(void *ptr, size_t len) override { + read_bl->append((char *)ptr, len); return 0; } - - int receive_header(void *ptr, size_t len); }; +typedef RGWHTTPTransceiver RGWPostHTTPData; + class RGWCompletionManager; diff --git a/src/rgw/rgw_swift.cc b/src/rgw/rgw_swift.cc index 204129926660b..dae77b1f4996a 100644 --- a/src/rgw/rgw_swift.cc +++ b/src/rgw/rgw_swift.cc @@ -105,17 +105,36 @@ int RGWSwift::validate_token(const char *token, struct rgw_swift_auth_info *info } -typedef RGWPostHTTPData RGWValidateKeystoneToken; -typedef RGWPostHTTPData RGWGetKeystoneAdminToken; -typedef RGWPostHTTPData RGWGetRevokedTokens; +class RGWKeystoneHTTPTransceiver : public RGWHTTPTransceiver { +public: + RGWKeystoneHTTPTransceiver(CephContext * const cct, + bufferlist * const token_body_bl) + : RGWHTTPTransceiver(cct, token_body_bl, + cct->_conf->rgw_keystone_verify_ssl, + { "X-Subject-Token" }) { + } + + std::string get_subject_token() const { + try { + return get_header_value("X-Subject-Token"); + } catch (std::out_of_range&) { + return header_value_t(); + } + } +}; + +typedef RGWKeystoneHTTPTransceiver RGWValidateKeystoneToken; +typedef RGWKeystoneHTTPTransceiver RGWGetKeystoneAdminToken; +typedef RGWKeystoneHTTPTransceiver RGWGetRevokedTokens; static RGWKeystoneTokenCache *keystone_token_cache = NULL; int RGWSwift::get_keystone_url(CephContext * const cct, std::string& url) { + // FIXME: it seems we don't need RGWGetRevokedToken here bufferlist bl; - RGWGetRevokedTokens req(cct, &bl, cct->_conf->rgw_keystone_verify_ssl); + RGWGetRevokedTokens req(cct, &bl); url = cct->_conf->rgw_keystone_url; if (url.empty()) { @@ -161,7 +180,7 @@ int RGWSwift::get_keystone_admin_token(CephContext * const cct, } bufferlist token_bl; - RGWGetKeystoneAdminToken token_req(cct, &token_bl, cct->_conf->rgw_keystone_verify_ssl); + RGWGetKeystoneAdminToken token_req(cct, &token_bl); token_req.append_header("Content-Type", "application/json"); JSONFormatter jf; @@ -421,7 +440,7 @@ int RGWSwift::validate_keystone_token(RGWRados *store, const string& token, /* can't decode, just go to the keystone server for validation */ - RGWValidateKeystoneToken validate(cct, &bl, cct->_conf->rgw_keystone_verify_ssl); + RGWValidateKeystoneToken validate(cct, &bl); string url = g_conf->rgw_keystone_url; if (url.empty()) { -- 2.39.5