Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: replace dom parser with sax parser #972

Merged
merged 18 commits into from
May 17, 2017
Merged
14 changes: 7 additions & 7 deletions include/envoy/json/json_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Envoy {
namespace Json {
class Object;

typedef std::unique_ptr<Object> ObjectPtr;
typedef std::shared_ptr<Object> ObjectSharedPtr;

// @return false if immediate exit from iteration required.
typedef std::function<bool(const std::string&, const Object&)> ObjectCallback;
Expand All @@ -36,9 +36,9 @@ class Object {
/**
* Convert a generic object into an array of objects. This is useful for dealing
* with arrays of arrays.
* @return std::vector<ObjectPtr> the converted object.
* @return std::vector<ObjectSharedPtr> the converted object.
*/
virtual std::vector<ObjectPtr> asObjectArray() const PURE;
virtual std::vector<ObjectSharedPtr> asObjectArray() const PURE;

/**
* Get a boolean value by name.
Expand Down Expand Up @@ -75,16 +75,16 @@ class Object {
* @param name supplies the key name.
* @param allow_empty supplies whether to return an empty object if the key does not
* exist.
* @return ObjectObjectPtr the sub-object.
* @return ObjectObjectSharedPtr the sub-object.
*/
virtual ObjectPtr getObject(const std::string& name, bool allow_empty = false) const PURE;
virtual ObjectSharedPtr getObject(const std::string& name, bool allow_empty = false) const PURE;

/**
* Get an array by name.
* @param name supplies the key name.
* @return std::vector<ObjectPtr> the array of JSON objects.
* @return std::vector<ObjectSharedPtr> the array of JSON objects.
*/
virtual std::vector<ObjectPtr> getObjectArray(const std::string& name) const PURE;
virtual std::vector<ObjectSharedPtr> getObjectArray(const std::string& name) const PURE;

/**
* Get a string value by name.
Expand Down
4 changes: 2 additions & 2 deletions source/common/dynamo/dynamo_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void DynamoFilter::onDecodeComplete(const Buffer::Instance& data) {
std::string body = buildBody(decoder_callbacks_->decodingBuffer(), data);
if (!body.empty()) {
try {
Json::ObjectPtr json_body = Json::Factory::loadFromString(body);
Json::ObjectSharedPtr json_body = Json::Factory::loadFromString(body);
table_descriptor_ = RequestParser::parseTable(operation_, *json_body);
} catch (const Json::Exception& jsonEx) {
// Body parsing failed. This should not happen, just put a stat for that.
Expand All @@ -72,7 +72,7 @@ void DynamoFilter::onEncodeComplete(const Buffer::Instance& data) {
std::string body = buildBody(encoder_callbacks_->encodingBuffer(), data);
if (!body.empty()) {
try {
Json::ObjectPtr json_body = Json::Factory::loadFromString(body);
Json::ObjectSharedPtr json_body = Json::Factory::loadFromString(body);
chargeTablePartitionIdStats(*json_body);

if (Http::CodeUtility::is4xx(status)) {
Expand Down
6 changes: 3 additions & 3 deletions source/common/dynamo/dynamo_request_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ RequestParser::TableDescriptor RequestParser::parseTable(const std::string& oper
table.table_name = json_data.getString("TableName", "");
} else if (find(BATCH_OPERATIONS.begin(), BATCH_OPERATIONS.end(), operation) !=
BATCH_OPERATIONS.end()) {
Json::ObjectPtr tables = json_data.getObject("RequestItems", true);
Json::ObjectSharedPtr tables = json_data.getObject("RequestItems", true);
tables->iterate([&table](const std::string& key, const Json::Object&) {
if (table.table_name.empty()) {
table.table_name = key;
Expand All @@ -94,7 +94,7 @@ RequestParser::TableDescriptor RequestParser::parseTable(const std::string& oper
}
std::vector<std::string> RequestParser::parseBatchUnProcessedKeys(const Json::Object& json_data) {
std::vector<std::string> unprocessed_tables;
Json::ObjectPtr tables = json_data.getObject("UnprocessedKeys", true);
Json::ObjectSharedPtr tables = json_data.getObject("UnprocessedKeys", true);
tables->iterate([&unprocessed_tables](const std::string& key, const Json::Object&) {
unprocessed_tables.emplace_back(key);
return true;
Expand Down Expand Up @@ -126,7 +126,7 @@ std::vector<RequestParser::PartitionDescriptor>
RequestParser::parsePartitions(const Json::Object& json_data) {
std::vector<RequestParser::PartitionDescriptor> partition_descriptors;

Json::ObjectPtr partitions =
Json::ObjectSharedPtr partitions =
json_data.getObject("ConsumedCapacity", true)->getObject("Partitions", true);
partitions->iterate([&partition_descriptors, &partitions](const std::string& key,
const Json::Object&) {
Expand Down
4 changes: 2 additions & 2 deletions source/common/filter/auth/client_ssl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ GlobalStats Config::generateStats(Stats::Store& store, const std::string& prefix

void Config::parseResponse(const Http::Message& message) {
AllowedPrincipalsSharedPtr new_principals(new AllowedPrincipals());
Json::ObjectPtr loader = Json::Factory::loadFromString(message.bodyAsString());
for (const Json::ObjectPtr& certificate : loader->getObjectArray("certificates")) {
Json::ObjectSharedPtr loader = Json::Factory::loadFromString(message.bodyAsString());
for (const Json::ObjectSharedPtr certificate : loader->getObjectArray("certificates")) {
new_principals->add(certificate->getString("fingerprint_sha256"));
}

Expand Down
4 changes: 2 additions & 2 deletions source/common/filter/ratelimit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Config::Config(const Json::Object& config, Stats::Store& stats_store, Runtime::L

config.validateSchema(Json::Schema::RATELIMIT_NETWORK_FILTER_SCHEMA);

for (const Json::ObjectPtr& descriptor : config.getObjectArray("descriptors")) {
for (const Json::ObjectSharedPtr descriptor : config.getObjectArray("descriptors")) {
Descriptor new_descriptor;
for (const Json::ObjectPtr& entry : descriptor->asObjectArray()) {
for (const Json::ObjectSharedPtr entry : descriptor->asObjectArray()) {
new_descriptor.entries_.push_back({entry->getString("key"), entry->getString("value")});
}
descriptors_.push_back(new_descriptor);
Expand Down
2 changes: 1 addition & 1 deletion source/common/filter/tcp_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ TcpProxyConfig::TcpProxyConfig(const Json::Object& config,
: stats_(generateStats(config.getString("stat_prefix"), stats_store)) {
config.validateSchema(Json::Schema::TCP_PROXY_NETWORK_FILTER_SCHEMA);

for (const Json::ObjectPtr& route_desc :
for (const Json::ObjectSharedPtr route_desc :
config.getObject("route_config")->getObjectArray("routes")) {
routes_.emplace_back(Route(*route_desc));

Expand Down
4 changes: 2 additions & 2 deletions source/common/http/access_log/access_log_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool RuntimeFilter::evaluate(const RequestInfo&, const HeaderMap& request_header
}

OperatorFilter::OperatorFilter(const Json::Object& json, Runtime::Loader& runtime) {
for (Json::ObjectPtr& filter : json.getObjectArray("filters")) {
for (Json::ObjectSharedPtr filter : json.getObjectArray("filters")) {
filters_.emplace_back(FilterImpl::fromJson(*filter, runtime));
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ InstanceSharedPtr InstanceImpl::fromJson(Json::Object& json, Runtime::Loader& ru

FilterPtr filter;
if (json.hasObject("filter")) {
Json::ObjectPtr filterObject = json.getObject("filter");
Json::ObjectSharedPtr filterObject = json.getObject("filter");
filter = FilterImpl::fromJson(*filterObject, runtime);
}

Expand Down
8 changes: 4 additions & 4 deletions source/common/http/filter/fault_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ FaultFilterConfig::FaultFilterConfig(const Json::Object& json_config, Runtime::L

json_config.validateSchema(Json::Schema::FAULT_HTTP_FILTER_SCHEMA);

const Json::ObjectPtr config_abort = json_config.getObject("abort", true);
const Json::ObjectPtr config_delay = json_config.getObject("delay", true);
const Json::ObjectSharedPtr config_abort = json_config.getObject("abort", true);
const Json::ObjectSharedPtr config_delay = json_config.getObject("delay", true);

if (config_abort->empty() && config_delay->empty()) {
throw EnvoyException("fault filter must have at least abort or delay specified in the config.");
Expand All @@ -51,8 +51,8 @@ FaultFilterConfig::FaultFilterConfig(const Json::Object& json_config, Runtime::L
}

if (json_config.hasObject("headers")) {
std::vector<Json::ObjectPtr> config_headers = json_config.getObjectArray("headers");
for (const Json::ObjectPtr& header_map : config_headers) {
std::vector<Json::ObjectSharedPtr> config_headers = json_config.getObjectArray("headers");
for (const Json::ObjectSharedPtr header_map : config_headers) {
fault_filter_headers_.push_back(*header_map);
}
}
Expand Down
7 changes: 6 additions & 1 deletion source/common/json/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ envoy_cc_library(
srcs = ["json_loader.cc"],
hdrs = ["json_loader.h"],
external_deps = ["rapidjson"],
deps = ["//include/envoy/json:json_object_interface"],
deps = [
"//include/envoy/json:json_object_interface",
"//source/common/common:assert_lib",
"//source/common/common:utility_lib",
"//source/common/filesystem:filesystem_lib",
],
)

envoy_cc_library(
Expand Down
Loading