Skip to content

Commit 37b0582

Browse files
committed
Sync to TFS
1 parent 19b45a0 commit 37b0582

33 files changed

+769
-225
lines changed

Release/casablanca.xcworkspace/contents.xcworkspacedata

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

Release/include/cpprest/base_uri.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
#include "cpprest/xxpublic.h"
3838
#include "cpprest/basic_types.h"
3939

40-
namespace web { namespace http
41-
{
40+
namespace web {
4241
namespace details
4342
{
4443
struct _uri_components
@@ -391,4 +390,4 @@ namespace web { namespace http
391390
details::_uri_components m_components;
392391
};
393392

394-
}} // namespace web::http
393+
} // namespace web

Release/include/cpprest/http_msg.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ namespace iis_host
6262

6363
namespace http
6464
{
65+
// URI class has been moved from web::http namespace to web namespace.
66+
// The below using declarations ensure we dont break existing code.
67+
// Please use the web::uri class going forward.
68+
using web::uri;
69+
using web::uri_builder;
70+
6571
namespace client
6672
{
6773
class http_client;

Release/include/cpprest/json.h

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,11 @@ namespace web { namespace json
711711
typedef storage_type::size_type size_type;
712712

713713
private:
714-
object() : m_elements(), m_sorted(false) { }
715-
object(storage_type elements) : m_elements(std::move(elements)), m_sorted(false) { }
714+
object() : m_elements() { }
715+
object(storage_type elements) : m_elements(std::move(elements))
716+
{
717+
sort(m_elements.begin(), m_elements.end(), compare_pairs);
718+
}
716719
object(const object& obj); // non copyable
717720
object& operator=(const object& obj) // non copyable
718721
{
@@ -836,45 +839,42 @@ namespace web { namespace json
836839
/// <returns>If the key exists, a reference to the value kept in the field, otherwise a newly created null value that will be stored for the given key.</returns>
837840
json::value& operator[](const utility::string_t& key)
838841
{
839-
if (!m_sorted)
840-
{
841-
sort(m_elements.begin(), m_elements.end(),
842-
[] (const std::pair<utility::string_t,value>& a,
843-
const std::pair<utility::string_t, value>& b)
844-
{
845-
return a.first < b.first;
846-
});
847-
m_sorted = true;
848-
}
849-
850-
std::pair<utility::string_t, value> val = std::pair<utility::string_t, value>(key, value());
851-
852-
auto iter = std::lower_bound(m_elements.begin(), m_elements.end(), val,
853-
[] (const std::pair<utility::string_t, value>& p1,
854-
const std::pair<utility::string_t, value>& p2)
855-
{
856-
return p1.first < p2.first;
857-
});
842+
auto iter = std::lower_bound(m_elements.begin(), m_elements.end(), key, compare_with_key);
858843

859844
if (iter == m_elements.end() || key != (iter->first))
860-
return m_elements.insert(iter, val)->second;
845+
return m_elements.insert(iter, std::pair<utility::string_t, value>(key, value()))->second;
861846

862847
return iter->second;
863848
}
864849

865850
/// <summary>
866-
/// Accesses an element of a JSON object.
851+
/// Gets an iterator to an element of a JSON object.
867852
/// </summary>
868-
/// <param name="index">The key of an element in the JSON object.</param>
869-
/// <returns>A reference to the value kept in the field</returns>
870-
const json::value& operator[](const utility::string_t& key) const
853+
/// <param name="key">The key of an element in the JSON object.</param>
854+
/// <returns>A const iterator to the value kept in the field</returns>
855+
const_iterator find(const utility::string_t& key) const
871856
{
872-
for (auto& pair : m_elements)
873-
{
874-
if (pair.first == key)
875-
return pair.second;
876-
}
877-
throw web::json::json_exception(_XPLATSTR("No such a key"));
857+
auto iter = std::lower_bound(m_elements.begin(), m_elements.end(), key, compare_with_key);
858+
859+
if (iter != m_elements.end() && key != (iter->first))
860+
return m_elements.end();
861+
862+
return iter;
863+
}
864+
865+
/// <summary>
866+
/// Gets an iterator to an element of a JSON object.
867+
/// </summary>
868+
/// <param name="key">The key of an element in the JSON object.</param>
869+
/// <returns>An iterator to the value kept in the field</returns>
870+
iterator find(const utility::string_t& key)
871+
{
872+
auto iter = std::lower_bound(m_elements.begin(), m_elements.end(), key, compare_with_key);
873+
874+
if (iter != m_elements.end() && key != (iter->first))
875+
return m_elements.end();
876+
877+
return iter;
878878
}
879879

880880
/// <summary>
@@ -895,9 +895,15 @@ namespace web { namespace json
895895
return m_elements.empty();
896896
}
897897
private:
898+
static bool compare_pairs(const std::pair<utility::string_t, value>& p1, const std::pair<utility::string_t, value>& p2)
899+
{
900+
return p1.first < p2.first;
901+
}
902+
static bool compare_with_key(const std::pair<utility::string_t, value>& p1, const utility::string_t& key)
903+
{
904+
return p1.first < key;
905+
}
898906
storage_type m_elements;
899-
bool m_sorted;
900-
static _ASYNCRTIMP const value m_null_value;
901907
friend class details::_Object;
902908

903909
template<typename CharType> friend class json::details::JSON_Parser;
@@ -1367,9 +1373,7 @@ namespace web { namespace json
13671373

13681374
virtual bool has_field(const utility::string_t &) const;
13691375

1370-
_ASYNCRTIMP virtual value get_field(const utility::string_t &) const;
13711376
_ASYNCRTIMP virtual json::value &index(const utility::string_t &key);
1372-
_ASYNCRTIMP virtual const json::value &cnst_index(const utility::string_t &key) const;
13731377

13741378
bool is_equal(const _Object* other) const
13751379
{
@@ -1494,7 +1498,7 @@ namespace web { namespace json
14941498
if (nlastSize < nMinSize)
14951499
m_array.m_elements.resize(nMinSize);
14961500

1497-
return m_array.m_elements[index];
1501+
return m_array.m_elements[index];
14981502
}
14991503

15001504
virtual const json::value &cnst_index(array::size_type index) const

Release/include/cpprest/uri_builder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "cpprest/base_uri.h"
3535
#include "cpprest/xxpublic.h"
3636

37-
namespace web { namespace http
37+
namespace web
3838
{
3939
/// <summary>
4040
/// Builder for constructing URIs incrementally.
@@ -239,7 +239,7 @@ namespace web { namespace http
239239
/// </summary>
240240
/// <param name="relative_uri">The relative uri to append.</param>
241241
/// <returns>A reference to this uri_builder to support chaining.</returns>
242-
_ASYNCRTIMP uri_builder &append(const http::uri &relative_uri);
242+
_ASYNCRTIMP uri_builder &append(const uri &relative_uri);
243243

244244
/// <summary>
245245
/// Appends another query to the query of this uri_builder, encoding it first. This overload is useful when building a query segment of
@@ -281,4 +281,4 @@ namespace web { namespace http
281281
private:
282282
details::_uri_components m_uri;
283283
};
284-
}} // namespace web::http
284+
} // namespace web

Release/include/cpprest/uri_parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <locale>
2929
#include <string>
3030

31-
namespace web { namespace http { namespace details
31+
namespace web { namespace details
3232
{
3333
class uri_parser
3434
{
@@ -220,4 +220,4 @@ namespace web { namespace http { namespace details
220220

221221
static const std::locale loc;
222222
};
223-
}}}
223+
}}

Release/src/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ if(UNIX)
1010
utilities/asyncrt_utils.cpp
1111
pplx/pplx.cpp
1212
pplx/threadpool.cpp
13-
http/uri/uri.cpp
14-
http/uri/uri_builder.cpp
15-
http/uri/uri_parser.cpp
13+
uri/uri.cpp
14+
uri/uri_builder.cpp
15+
uri/uri_parser.cpp
1616
http/common/http_msg.cpp
1717
http/common/http_helpers.cpp
1818
http/client/http_msg_client.cpp
@@ -36,9 +36,9 @@ elseif(WIN32)
3636
json/json_parsing.cpp
3737
json/json_serialization.cpp
3838
utilities/asyncrt_utils.cpp
39-
http/uri/uri.cpp
40-
http/uri/uri_builder.cpp
41-
http/uri/uri_parser.cpp
39+
uri/uri.cpp
40+
uri/uri_builder.cpp
41+
uri/uri_parser.cpp
4242
http/common/http_msg.cpp
4343
http/common/http_helpers.cpp
4444
http/client/http_msg_client.cpp

Release/src/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ SOURCES = \
88
utilities/asyncrt_utils.cpp \
99
pplx/pplx.cpp \
1010
pplx/threadpool.cpp \
11-
http/uri/uri.cpp \
12-
http/uri/uri_builder.cpp \
13-
http/uri/uri_parser.cpp \
11+
uri/uri.cpp \
12+
uri/uri_builder.cpp \
13+
uri/uri_parser.cpp \
1414
http/common/http_msg.cpp \
1515
http/common/http_helpers.cpp \
1616
http/client/http_msg_client.cpp \

Release/src/build/sources.proj

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@
129129
<ClCompile Include="$(CasablancaSrcDir)\json\json_serialization.cpp">
130130
<Filter>Source Files</Filter>
131131
</ClCompile>
132-
<ClCompile Include="$(CasablancaSrcDir)\http\uri\uri.cpp">
132+
<ClCompile Include="$(CasablancaSrcDir)\uri\uri.cpp">
133133
<Filter>Source Files</Filter>
134134
</ClCompile>
135-
<ClCompile Include="$(CasablancaSrcDir)\http\uri\uri_builder.cpp">
135+
<ClCompile Include="$(CasablancaSrcDir)\uri\uri_builder.cpp">
136136
<Filter>Source Files</Filter>
137137
</ClCompile>
138-
<ClCompile Include="$(CasablancaSrcDir)\http\uri\uri_parser.cpp">
138+
<ClCompile Include="$(CasablancaSrcDir)\uri\uri_parser.cpp">
139139
<Filter>Source Files</Filter>
140140
</ClCompile>
141141
<ClCompile Include="$(CasablancaSrcDir)\utilities\asyncrt_utils.cpp">
@@ -185,12 +185,24 @@
185185

186186
<!-- WinRT-only files go here -->
187187
<ItemGroup Condition="'$(WinRTProject)' == 'true'">
188+
<ClInclude Include="$(CasablancaIncludeDir)\cpprest\ws_client.h">
189+
<Filter>Header Files\cpprest</Filter>
190+
</ClInclude>
191+
<ClInclude Include="$(CasablancaIncludeDir)\cpprest\ws_msg.h">
192+
<Filter>Header Files\cpprest</Filter>
193+
</ClInclude>
188194
<ClCompile Include="$(CasablancaSrcDir)\http\client\http_win8.cpp">
189195
<Filter>Source Files</Filter>
190196
</ClCompile>
191197
<ClCompile Include="$(CasablancaSrcDir)\streams\windows\fileio_winrt.cpp">
192198
<Filter>Source Files</Filter>
193199
</ClCompile>
200+
<ClCompile Include="$(CasablancaSrcDir)\websockets\client\ws_winrt.cpp">
201+
<Filter>Source Files</Filter>
202+
</ClCompile>
203+
<ClCompile Include="$(CasablancaSrcDir)\websockets\client\ws_msg.cpp">
204+
<Filter>Source Files</Filter>
205+
</ClCompile>
194206
</ItemGroup>
195207

196208
<!-- non-WinRT and non-TargetXP files go here -->

Release/src/http/client/http_linux.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,11 @@ namespace web { namespace http
406406
auto progress = ctx->m_request._get_impl()->_progress_handler();
407407
if ( progress )
408408
{
409-
(*progress)(message_direction::upload, ctx->m_uploaded);
409+
try { (*progress)(message_direction::upload, ctx->m_uploaded); } catch(...)
410+
{
411+
ctx->report_exception(std::current_exception());
412+
return;
413+
}
410414
}
411415

412416
auto readbuf = ctx->_get_readbuffer();
@@ -446,7 +450,11 @@ namespace web { namespace http
446450
auto progress = ctx->m_request._get_impl()->_progress_handler();
447451
if ( progress )
448452
{
449-
(*progress)(message_direction::upload, ctx->m_uploaded);
453+
try { (*progress)(message_direction::upload, ctx->m_uploaded); } catch(...)
454+
{
455+
ctx->report_exception(std::current_exception());
456+
return;
457+
}
450458
}
451459

452460
auto readbuf = ctx->_get_readbuffer();
@@ -499,7 +507,11 @@ namespace web { namespace http
499507
auto progress = ctx->m_request._get_impl()->_progress_handler();
500508
if ( progress )
501509
{
502-
(*progress)(message_direction::upload, ctx->m_uploaded);
510+
try { (*progress)(message_direction::upload, ctx->m_uploaded); } catch(...)
511+
{
512+
ctx->report_exception(std::current_exception());
513+
return;
514+
}
503515
}
504516

505517
// Read until the end of entire headers
@@ -586,7 +598,11 @@ namespace web { namespace http
586598
auto progress = ctx->m_request._get_impl()->_progress_handler();
587599
if ( progress )
588600
{
589-
(*progress)(message_direction::download, 0);
601+
try { (*progress)(message_direction::download, 0); } catch(...)
602+
{
603+
ctx->report_exception(std::current_exception());
604+
return;
605+
}
590606
}
591607

592608
ctx->complete_request(0);
@@ -666,7 +682,11 @@ namespace web { namespace http
666682
auto progress = ctx->m_request._get_impl()->_progress_handler();
667683
if ( progress )
668684
{
669-
(*progress)(message_direction::download, ctx->m_downloaded);
685+
try { (*progress)(message_direction::download, ctx->m_downloaded); } catch(...)
686+
{
687+
ctx->report_exception(std::current_exception());
688+
return;
689+
}
670690
}
671691

672692
if (to_read == 0)
@@ -731,7 +751,11 @@ namespace web { namespace http
731751
auto progress = ctx->m_request._get_impl()->_progress_handler();
732752
if ( progress )
733753
{
734-
(*progress)(message_direction::download, ctx->m_downloaded);
754+
try { (*progress)(message_direction::download, ctx->m_downloaded); } catch(...)
755+
{
756+
ctx->report_exception(std::current_exception());
757+
return;
758+
}
735759
}
736760

737761
if (ctx->m_current_size < ctx->m_known_size)

0 commit comments

Comments
 (0)