Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Replace JSON parser with RapidJSON #7708

Merged
merged 2 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions THIRD-PARTY-NOTICES.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -629,3 +629,22 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


License notice for RapidJSON
----------------------------

Tencent is pleased to support the open source community by making RapidJSON available.

Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.

Licensed under the MIT License (the "License"); you may not use this file except
in compliance with the License. You may obtain a copy of the License at

http://opensource.org/licenses/MIT

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

9 changes: 3 additions & 6 deletions src/corehost/cli/comhost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set(DOTNET_PROJECT_NAME "comhost")

# Include directories
include_directories(../fxr)
include_directories(../json/casablanca/include)
include_directories(../json)

# CMake does not recommend using globbing since it messes with the freshness checks
set(SOURCES
Expand All @@ -18,16 +18,13 @@ set(SOURCES
clsidmap.cpp
../redirected_error_writer.cpp
../fxr/fx_ver.cpp
../json/casablanca/src/json/json.cpp
../json/casablanca/src/json/json_parsing.cpp
../json/casablanca/src/json/json_serialization.cpp
../json/casablanca/src/utilities/asyncrt_utils.cpp
../json_parser.cpp
)

set(HEADERS
comhost.h
../fxr/fx_ver.h
../json/casablanca/include/cpprest/json.h
../json_parser.h
)

if(WIN32)
Expand Down
33 changes: 13 additions & 20 deletions src/corehost/cli/comhost/clsidmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#include <wintrust.h>
#include <Softpub.h>

#include <cpprest/json.h>
using namespace web;
#include "rapidjson/document.h"
#include "rapidjson/istreamwrapper.h"
#include "json_parser.h"

using comhost::clsid_map_entry;
using comhost::clsid_map;
Expand Down Expand Up @@ -45,29 +46,21 @@ namespace

clsid_map parse_stream(_Inout_ pal::istream_t &json_map_raw)
{
skip_utf8_bom(&json_map_raw);
json_parser_t json;

// Parse JSON
json::value json_map;
try
{
json_map = json::value::parse(json_map_raw);
}
catch (const json::json_exception&)
if (!json.parse_stream(json_map_raw, _X("<embedded .clsidmap>")))
{
trace::error(_X("Embedded .clsidmap format is invalid"));
throw HResultException{ StatusCode::InvalidConfigFile };
}

json::object &json_obj = json_map.as_object();

// Process JSON and construct a map
HRESULT hr;
clsid_map mapping;
for (std::pair<utility::string_t, json::value> &prop : json_obj)
for (const auto &prop : json.document().GetObject())
{
CLSID clsidMaybe;
hr = string_to_clsid(prop.first, clsidMaybe);
hr = string_to_clsid(prop.name.GetString(), clsidMaybe);
if (FAILED(hr))
{
assert(false && "Invalid CLSID");
Expand All @@ -79,14 +72,14 @@ namespace

e.clsid = clsidMaybe;

json::object &val = prop.second.as_object();
e.assembly = val.at(_X("assembly")).as_string();
e.type = val.at(_X("type")).as_string();
const auto &val = prop.value.GetObject();
e.assembly = val[_X("assembly")].GetString();
e.type = val[_X("type")].GetString();

// Check if a ProgID was defined.
auto prodIdMaybe = val.find(_X("progid"));
if (prodIdMaybe != val.cend())
e.progid = prodIdMaybe->second.as_string();
const auto &prodIdMaybe = val.FindMember(_X("progid"));
if (prodIdMaybe != val.MemberEnd())
e.progid = prodIdMaybe->value.GetString();

mapping[clsidMaybe] = std::move(e);
}
Expand Down
Loading