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

Commit

Permalink
First pass in using RapidJSON instead of Casablanca to parse JSON
Browse files Browse the repository at this point in the history
RapidJSON is based off of commit d87b698d0fcc10a5f632ecbc80a9cb2a8fa094a5.
  • Loading branch information
lpereira committed Aug 15, 2019
1 parent 68951b0 commit 955c3ae
Show file tree
Hide file tree
Showing 64 changed files with 16,909 additions and 13,005 deletions.
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.h
)

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

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

using comhost::clsid_map_entry;
using comhost::clsid_map;
Expand Down Expand Up @@ -45,29 +45,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, "<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 (auto &prop : json_map.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,9 +71,9 @@ 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();
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"));
Expand Down
Loading

0 comments on commit 955c3ae

Please sign in to comment.