Skip to content

Commit 83c458f

Browse files
committed
Merge branch 'development' of https://git01.codeplex.com/forks/tsone/casadev into tsone/casadev
2 parents 19f0685 + 66a2304 commit 83c458f

File tree

87 files changed

+7175
-31
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+7175
-31
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
*~
3939
ipch/
4040
obj/
41+
#OSX files
42+
.DS_Store
4143
*.resfiles
4244
[Bb]in
4345
Binaries/

Release/include/cpprest/asyncrt_utils.h

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace pplx = Concurrency;
4040
#include <vector>
4141
#include <cstdint>
4242
#include <system_error>
43+
#include <random>
4344

4445
#if !defined(_MS_WINDOWS) || (_MSC_VER >= 1700)
4546
#include <chrono>
@@ -220,13 +221,6 @@ namespace details
220221
#endif
221222
}
222223

223-
// Turn const_iterator into an iterator
224-
template <typename Container, typename ConstIterator>
225-
typename Container::iterator remove_iterator_constness(Container& c, ConstIterator it)
226-
{
227-
return c.erase(it, it);
228-
}
229-
230224
#ifdef _MS_WINDOWS
231225

232226
/// <summary>
@@ -305,6 +299,28 @@ class datetime
305299
/// </summary>
306300
static _ASYNCRTIMP datetime __cdecl utc_now();
307301

302+
/// <summary>
303+
/// An invalid UTC timestamp value.
304+
/// </summary>
305+
enum:interval_type { utc_timestamp_invalid = static_cast<interval_type>(-1) };
306+
307+
/// <summary>
308+
/// Returns seconds since Unix/POSIX time epoch at 01-01-1970 00:00:00.
309+
/// If time is before epoch, utc_timestamp_invalid is returned.
310+
/// </summary>
311+
static interval_type utc_timestamp()
312+
{
313+
const auto seconds = utc_now().to_interval() / _secondTicks;
314+
if (seconds >= 11644473600LL)
315+
{
316+
return seconds - 11644473600LL;
317+
}
318+
else
319+
{
320+
return utc_timestamp_invalid;
321+
}
322+
}
323+
308324
datetime() : m_interval(0)
309325
{
310326
}
@@ -448,4 +464,50 @@ inline int operator- (datetime t1, datetime t2)
448464
return static_cast<int>(diff);
449465
}
450466

467+
/// <summary>
468+
/// Nonce string generator class.
469+
/// </summary>
470+
class nonce_generator
471+
{
472+
public:
473+
474+
/// <summary>
475+
/// Define default nonce length.
476+
/// </summary>
477+
enum { default_length = 32 };
478+
479+
/// <summary>
480+
/// Nonce generator constructor.
481+
/// </summary>
482+
/// <param name="length">Length of the generated nonce string.</param>
483+
nonce_generator(int length=default_length) :
484+
m_random(static_cast<unsigned int>(utility::datetime::utc_timestamp())),
485+
m_length(length)
486+
{}
487+
488+
/// <summary>
489+
/// Generate a nonce string containing random alphanumeric characters (A-Za-z0-9).
490+
/// Length of the generated string is set by length().
491+
/// </summary>
492+
/// <returns>The generated nonce string.</returns>
493+
_ASYNCRTIMP utility::string_t generate();
494+
495+
/// <summary>
496+
/// Get length of generated nonce string.
497+
/// </summary>
498+
/// <returns>Nonce string length.</returns>
499+
int length() const { return m_length; }
500+
501+
/// <summary>
502+
/// Set length of the generated nonce string.
503+
/// </summary>
504+
/// <param name="length">Lenght of nonce string.</param>
505+
void set_length(int length) { m_length = length; }
506+
507+
private:
508+
static const utility::string_t c_allowed_chars;
509+
std::mt19937 m_random;
510+
int m_length;
511+
};
512+
451513
} // namespace utility;

Release/include/cpprest/http_client.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace pplx = Concurrency;
5858
#include "cpprest/web_utilities.h"
5959
#include "cpprest/basic_types.h"
6060
#include "cpprest/asyncrt_utils.h"
61+
#include "cpprest/oauth1.h"
62+
#include "cpprest/oauth2.h"
6163

6264
namespace web
6365
{
@@ -105,6 +107,42 @@ class http_client_config
105107
{
106108
}
107109

110+
/// <summary>
111+
/// Get OAuth 1.0 configuration.
112+
/// </summary>
113+
/// <returns>Shared pointer to OAuth 1.0 configuration.</returns>
114+
const std::shared_ptr<oauth1::experimental::oauth1_config> oauth1() const
115+
{
116+
return m_oauth1;
117+
}
118+
119+
/// <summary>
120+
/// Set OAuth 1.0 configuration.
121+
/// </summary>
122+
/// <param name="config">OAuth 1.0 configuration to set.</param>
123+
void set_oauth1(oauth1::experimental::oauth1_config config)
124+
{
125+
m_oauth1 = std::make_shared<oauth1::experimental::oauth1_config>(std::move(config));
126+
}
127+
128+
/// <summary>
129+
/// Get OAuth 2.0 configuration.
130+
/// </summary>
131+
/// <returns>Shared pointer to OAuth 2.0 configuration.</returns>
132+
const std::shared_ptr<oauth2::experimental::oauth2_config> oauth2() const
133+
{
134+
return m_oauth2;
135+
}
136+
137+
/// <summary>
138+
/// Set OAuth 2.0 configuration.
139+
/// </summary>
140+
/// <param name="config">OAuth 2.0 configuration to set.</param>
141+
void set_oauth2(oauth2::experimental::oauth2_config config)
142+
{
143+
m_oauth2 = std::make_shared<oauth2::experimental::oauth2_config>(std::move(config));
144+
}
145+
108146
/// <summary>
109147
/// Get the web proxy object
110148
/// </summary>
@@ -251,6 +289,8 @@ class http_client_config
251289
}
252290

253291
private:
292+
std::shared_ptr<oauth1::experimental::oauth1_config> m_oauth1;
293+
std::shared_ptr<oauth2::experimental::oauth2_config> m_oauth2;
254294
web_proxy m_proxy;
255295
http::client::credentials m_credentials;
256296
// Whether or not to guarantee ordering, i.e. only using one underlying TCP connection.

Release/include/cpprest/http_client_impl.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ using namespace utility;
5858
# define CRLF std::string("\r\n")
5959
#endif
6060

61-
6261
using namespace web::http::details;
6362

6463
namespace web { namespace http { namespace client { namespace details
@@ -460,7 +459,16 @@ void http_client::build_pipeline(uri base_uri, http_client_config client_config)
460459
}
461460
details::verify_uri(base_uri);
462461

462+
std::vector<std::shared_ptr<http::http_pipeline_stage> > extra_handlers;
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()));
465+
463466
m_pipeline = ::web::http::http_pipeline::create_pipeline(std::make_shared<details::http_network_handler>(std::move(base_uri), std::move(client_config)));
467+
468+
for (auto& handler : extra_handlers)
469+
{
470+
add_handler(handler);
471+
}
464472
}
465473

466474
const http_client_config& http_client::client_config() const

Release/include/cpprest/http_constants.dat

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,49 @@ DAT(text_xjson, "text/x-json")
126126
#endif // _MIME_TYPES
127127

128128
#ifdef _CHARSET_TYPES
129+
DAT(ascii, "ascii")
129130
DAT(usascii, "us-ascii")
130131
DAT(latin1, "iso-8859-1")
131132
DAT(utf8, "utf-8")
132133
DAT(utf16, "utf-16")
133134
DAT(utf16le, "utf-16le")
134135
DAT(utf16be, "utf-16be")
135136
#endif // _CHARSET_TYPES
137+
138+
#ifdef _OAUTH1_METHODS
139+
DAT(hmac_sha1, _XPLATSTR("HMAC-SHA1"))
140+
DAT(plaintext, _XPLATSTR("PLAINTEXT"))
141+
#endif // _OAUTH1_METHODS
142+
143+
#ifdef _OAUTH1_STRINGS
144+
DAT(callback, "oauth_callback")
145+
DAT(callback_confirmed, "oauth_callback_confirmed")
146+
DAT(consumer_key, "oauth_consumer_key")
147+
DAT(nonce, "oauth_nonce")
148+
DAT(realm, "realm") // NOTE: No "oauth_" prefix.
149+
DAT(signature, "oauth_signature")
150+
DAT(signature_method, "oauth_signature_method")
151+
DAT(timestamp, "oauth_timestamp")
152+
DAT(token, "oauth_token")
153+
DAT(token_secret, "oauth_token_secret")
154+
DAT(verifier, "oauth_verifier")
155+
DAT(version, "oauth_version")
156+
#endif // _OAUTH1_STRINGS
157+
158+
#ifdef _OAUTH2_STRINGS
159+
DAT(access_token, "access_token")
160+
DAT(authorization_code, "authorization_code")
161+
DAT(bearer, "bearer")
162+
DAT(client_id, "client_id")
163+
DAT(client_secret, "client_secret")
164+
DAT(code, "code")
165+
DAT(expires_in, "expires_in")
166+
DAT(grant_type, "grant_type")
167+
DAT(redirect_uri, "redirect_uri")
168+
DAT(refresh_token, "refresh_token")
169+
DAT(response_type, "response_type")
170+
DAT(scope, "scope")
171+
DAT(state, "state")
172+
DAT(token, "token")
173+
DAT(token_type, "token_type")
174+
#endif // _OAUTH2_STRINGS

Release/include/cpprest/http_helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace details
8181
/// Parses the given Content-Type header value to get out actual content type and charset.
8282
/// If the charset isn't specified the default charset for the content type will be set.
8383
/// </summary>
84-
void parse_content_type_and_charset(const utility::string_t &content_type, utility::string_t &content, utility::string_t &charset);
84+
void parse_content_type_and_charset(const utility::string_t &content_type, utility::string_t &content, utility::string_t &charset);
8585

8686
/// <summary>
8787
/// Gets the default charset for given content type. If the MIME type is not textual or recognized Latin1 will be returned.

Release/include/cpprest/http_msg.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@ class _http_request : public http::details::http_msg_base, public std::enable_sh
646646

647647
uri &request_uri() { return m_uri; }
648648

649+
_ASYNCRTIMP uri absolute_uri() const;
650+
649651
_ASYNCRTIMP uri relative_uri() const;
650652

651653
_ASYNCRTIMP void set_request_uri(const uri&);
@@ -688,6 +690,8 @@ class _http_request : public http::details::http_msg_base, public std::enable_sh
688690

689691
void _set_listener_path(const utility::string_t &path) { m_listener_path = path; }
690692

693+
void _set_base_uri(http::uri base_uri) { m_base_uri = std::move(base_uri); }
694+
691695
private:
692696

693697
// Actual initiates sending the response, without checking if a response has already been sent.
@@ -700,6 +704,7 @@ class _http_request : public http::details::http_msg_base, public std::enable_sh
700704

701705
http::method m_method;
702706

707+
http::uri m_base_uri;
703708
http::uri m_uri;
704709
utility::string_t m_listener_path;
705710
std::shared_ptr<http::details::_http_server_context> m_server_context;
@@ -790,6 +795,15 @@ class http_request
790795
/// </remarks>
791796
uri relative_uri() const { return _m_impl->relative_uri(); }
792797

798+
/// <summary>
799+
/// Get an absolute URI with scheme, host, port, path, query, and fragment part of
800+
/// the request message.
801+
/// </summary>
802+
/// <remarks>Absolute URI is only valid after this http_request object has been passed
803+
/// to http_client::request().
804+
/// </remarks>
805+
uri absolute_uri() const { return _m_impl->absolute_uri(); }
806+
793807
/// <summary>
794808
/// Gets a reference to the headers of the response message.
795809
/// </summary>
@@ -1137,6 +1151,11 @@ class http_request
11371151
return _m_impl->cancellation_token();
11381152
}
11391153

1154+
void _set_base_uri(http::uri base_uri)
1155+
{
1156+
_m_impl->_set_base_uri(std::move(base_uri));
1157+
}
1158+
11401159
private:
11411160
friend class http::details::_http_request;
11421161
friend class http::client::http_client;

Release/include/cpprest/json.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -934,16 +934,6 @@ namespace web { namespace json
934934
return find_internal(key);
935935
}
936936

937-
/// <summary>
938-
/// Gets an iterator to an element of a JSON object.
939-
/// </summary>
940-
/// <param name="key">The key of an element in the JSON object.</param>
941-
/// <returns>An iterator to the value kept in the field.</returns>
942-
iterator find(const utility::string_t& key)
943-
{
944-
return utility::details::remove_iterator_constness(m_elements, find_internal(key));
945-
}
946-
947937
/// <summary>
948938
/// Gets the number of elements of the object.
949939
/// </summary>

0 commit comments

Comments
 (0)