Skip to content

Commit 224c1fe

Browse files
author
Valtteri Heikkila
committed
Removed unnecessary rvalue references and using-declarations, changed to make_shared, and removed some makefiles in oauth1/2.
1 parent e4a9840 commit 224c1fe

File tree

8 files changed

+32
-37
lines changed

8 files changed

+32
-37
lines changed

Release/include/cpprest/http_client.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,12 @@ namespace http
6868
namespace client
6969
{
7070

71-
using web::http::oauth1::experimental::oauth1_config;
72-
using web::http::oauth2::experimental::oauth2_config;
73-
7471
// credentials and web_proxy class has been moved from web::http::client namespace to web namespace.
7572
// The below using declarations ensure we dont break existing code.
7673
// Please use the web::credentials and web::web_proxy class going forward.
7774
using web::credentials;
7875
using web::web_proxy;
7976

80-
8177
#ifdef _MS_WINDOWS
8278
namespace details {
8379
#ifdef __cplusplus_winrt
@@ -111,30 +107,41 @@ class http_client_config
111107
{
112108
}
113109

114-
115110
/// <summary>
116111
/// Get OAuth 1.0 configuration.
117112
/// </summary>
118113
/// <returns>Shared pointer to OAuth 1.0 configuration.</returns>
119-
const std::shared_ptr<oauth1_config> oauth1() const { return m_oauth1; }
114+
const std::shared_ptr<oauth1::experimental::oauth1_config> oauth1() const
115+
{
116+
return m_oauth1;
117+
}
120118

121119
/// <summary>
122120
/// Set OAuth 1.0 configuration.
123121
/// </summary>
124122
/// <param name="config">OAuth 1.0 configuration to set.</param>
125-
void set_oauth1(oauth1_config config) { m_oauth1.reset(new oauth1_config(std::move(config))); }
123+
void set_oauth1(oauth1::experimental::oauth1_config config)
124+
{
125+
m_oauth1 = std::make_shared<oauth1::experimental::oauth1_config>(std::move(config));
126+
}
126127

127128
/// <summary>
128129
/// Get OAuth 2.0 configuration.
129130
/// </summary>
130131
/// <returns>Shared pointer to OAuth 2.0 configuration.</returns>
131-
const std::shared_ptr<oauth2_config> oauth2() const { return m_oauth2; }
132+
const std::shared_ptr<oauth2::experimental::oauth2_config> oauth2() const
133+
{
134+
return m_oauth2;
135+
}
132136

133137
/// <summary>
134138
/// Set OAuth 2.0 configuration.
135139
/// </summary>
136140
/// <param name="config">OAuth 2.0 configuration to set.</param>
137-
void set_oauth2(oauth2_config config) { m_oauth2.reset(new oauth2_config(std::move(config))); }
141+
void set_oauth2(oauth2::experimental::oauth2_config config)
142+
{
143+
m_oauth2 = std::make_shared<oauth2::experimental::oauth2_config>(std::move(config));
144+
}
138145

139146
/// <summary>
140147
/// Get the web proxy object
@@ -282,8 +289,8 @@ class http_client_config
282289
}
283290

284291
private:
285-
std::shared_ptr<oauth1_config> m_oauth1;
286-
std::shared_ptr<oauth2_config> m_oauth2;
292+
std::shared_ptr<oauth1::experimental::oauth1_config> m_oauth1;
293+
std::shared_ptr<oauth2::experimental::oauth2_config> m_oauth2;
287294
web_proxy m_proxy;
288295
http::client::credentials m_credentials;
289296
// Whether or not to guarantee ordering, i.e. only using one underlying TCP connection.

Release/include/cpprest/http_client_impl.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ using namespace utility;
5959
#endif
6060

6161
using namespace web::http::details;
62-
using namespace web::http::oauth1::details;
63-
using namespace web::http::oauth2::details;
6462

6563
namespace web { namespace http { namespace client { namespace details
6664
{
@@ -462,8 +460,8 @@ void http_client::build_pipeline(uri base_uri, http_client_config client_config)
462460
details::verify_uri(base_uri);
463461

464462
std::vector<std::shared_ptr<http::http_pipeline_stage> > extra_handlers;
465-
extra_handlers.push_back(std::shared_ptr<http::http_pipeline_stage>(new oauth1_handler(client_config.oauth1())));
466-
extra_handlers.push_back(std::shared_ptr<http::http_pipeline_stage>(new oauth2_handler(client_config.oauth2())));
463+
extra_handlers.push_back(std::make_shared<oauth1::details::oauth1_handler>(client_config.oauth1()));
464+
extra_handlers.push_back(std::make_shared<oauth2::details::oauth2_handler>(client_config.oauth2()));
467465

468466
m_pipeline = ::web::http::http_pipeline::create_pipeline(std::make_shared<details::http_network_handler>(std::move(base_uri), std::move(client_config)));
469467

Release/include/cpprest/oauth1.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ class oauth1_config
406406
return os.str();
407407
}
408408

409-
_ASYNCRTIMP static std::vector<unsigned char> _hmac_sha1(const utility::string_t&& key, const utility::string_t&& data);
409+
_ASYNCRTIMP static std::vector<unsigned char> _hmac_sha1(const utility::string_t& key, const utility::string_t& data);
410410

411411
static utility::string_t _build_base_string_uri(const uri& u);
412412

Release/include/cpprest/oauth2.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class oauth2_config
264264
ub.append_query(details::oauth2_strings::grant_type, details::oauth2_strings::authorization_code, false);
265265
ub.append_query(details::oauth2_strings::code, uri::encode_data_string(std::move(authorization_code)), false);
266266
ub.append_query(details::oauth2_strings::redirect_uri, uri::encode_data_string(redirect_uri()), false);
267-
return _request_token(std::move(ub));
267+
return _request_token(ub);
268268
}
269269

270270
/// <summary>
@@ -280,7 +280,7 @@ class oauth2_config
280280
uri_builder ub;
281281
ub.append_query(details::oauth2_strings::grant_type, details::oauth2_strings::refresh_token, false);
282282
ub.append_query(details::oauth2_strings::refresh_token, uri::encode_data_string(token().refresh_token()), false);
283-
return _request_token(std::move(ub));
283+
return _request_token(ub);
284284
}
285285

286286
/// <summary>
@@ -451,9 +451,9 @@ class oauth2_config
451451
m_http_basic_auth(true)
452452
{}
453453

454-
_ASYNCRTIMP pplx::task<void> _request_token(uri_builder&& request_body);
454+
_ASYNCRTIMP pplx::task<void> _request_token(uri_builder& request_body);
455455

456-
oauth2_token _parse_token_from_json(const json::value&& token_json);
456+
oauth2_token _parse_token_from_json(const json::value& token_json);
457457

458458
void _authenticate_request(http_request &req) const
459459
{

Release/samples/Oauth1Client/Makefile

Lines changed: 0 additions & 5 deletions
This file was deleted.

Release/samples/Oauth2Client/Makefile

Lines changed: 0 additions & 5 deletions
This file was deleted.

Release/src/http/oauth/oauth1.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace experimental
5656
//
5757
#if _WIN32_WINNT < _WIN32_WINNT_VISTA || _PHONE8_ // Windows XP or Windows Phone 8.0
5858

59-
std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t&&, const utility::string_t&&)
59+
std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t&, const utility::string_t&)
6060
{
6161
throw oauth1_exception(U("oauth1 is not supported"));
6262
}
@@ -66,7 +66,7 @@ std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t&&,
6666
#include <winternl.h>
6767
#include <bcrypt.h>
6868

69-
std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t&& key, const utility::string_t&& data)
69+
std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data)
7070
{
7171
NTSTATUS status;
7272
BCRYPT_ALG_HANDLE alg_handle = nullptr;
@@ -128,7 +128,7 @@ using namespace Windows::Security::Cryptography;
128128
using namespace Windows::Security::Cryptography::Core;
129129
using namespace Windows::Storage::Streams;
130130

131-
std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t&& key, const utility::string_t&& data)
131+
std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data)
132132
{
133133
Platform::String^ data_str = ref new Platform::String(data.c_str());
134134
Platform::String^ key_str = ref new Platform::String(key.c_str());
@@ -149,7 +149,7 @@ std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t&& k
149149

150150
#include <openssl/hmac.h>
151151

152-
std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t&& key, const utility::string_t&& data)
152+
std::vector<unsigned char> oauth1_config::_hmac_sha1(const utility::string_t& key, const utility::string_t& data)
153153
{
154154
unsigned char digest[HMAC_MAX_MD_CBLOCK];
155155
unsigned int digest_len = 0;

Release/src/http/oauth/oauth2.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pplx::task<void> oauth2_config::token_from_redirected_uri(const web::http::uri&
110110
return pplx::task_from_result();
111111
}
112112

113-
pplx::task<void> oauth2_config::_request_token(uri_builder&& request_body_ub)
113+
pplx::task<void> oauth2_config::_request_token(uri_builder& request_body_ub)
114114
{
115115
http_request request;
116116
request.set_method(methods::POST);
@@ -146,11 +146,11 @@ pplx::task<void> oauth2_config::_request_token(uri_builder&& request_body_ub)
146146
})
147147
.then([this](json::value json_resp) -> void
148148
{
149-
set_token(_parse_token_from_json(std::move(json_resp)));
149+
set_token(_parse_token_from_json(json_resp));
150150
});
151151
}
152152

153-
oauth2_token oauth2_config::_parse_token_from_json(const json::value&& token_json)
153+
oauth2_token oauth2_config::_parse_token_from_json(const json::value& token_json)
154154
{
155155
oauth2_token result;
156156

0 commit comments

Comments
 (0)