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 29, 2019
1 parent 29aaa4b commit 8425188
Show file tree
Hide file tree
Showing 65 changed files with 16,948 additions and 13,010 deletions.
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 (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();
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();
auto prodIdMaybe = val.FindMember(_X("progid"));
if (prodIdMaybe != val.MemberEnd())
e.progid = prodIdMaybe->value.GetString();

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

0 comments on commit 8425188

Please sign in to comment.