Skip to content

Commit 85d5443

Browse files
Merge pull request #361 from lo-simon/general_tidy_up
General tidy up
2 parents 25240c4 + 0ed64a7 commit 85d5443

12 files changed

+1675
-1573
lines changed

.github/workflows/build-test.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ jobs:
297297
run: |
298298
echo "CMAKE_EXTRA_ARGS=${{ env.CMAKE_EXTRA_ARGS }} -DNMOS_CPP_CONAN_OPTIONS:STRING=\"cpprestsdk:http_client_impl=asio;cpprestsdk:http_listener_impl=asio\"" >> $GITHUB_ENV
299299
300-
- uses: ilammy/msvc-dev-cmd@v1
300+
- name: setup developer command prompt for Microsoft Visual C++
301+
if: runner.os == 'Windows'
302+
uses: ilammy/msvc-dev-cmd@v1
303+
301304
- name: build
302305
uses: lukka/[email protected]
303306
with:
@@ -833,7 +836,10 @@ jobs:
833836
run: |
834837
echo "CMAKE_EXTRA_ARGS=${{ env.CMAKE_EXTRA_ARGS }} -DNMOS_CPP_CONAN_OPTIONS:STRING=\"cpprestsdk:http_client_impl=asio;cpprestsdk:http_listener_impl=asio\"" >> $GITHUB_ENV
835838
836-
- uses: ilammy/msvc-dev-cmd@v1
839+
- name: setup developer command prompt for Microsoft Visual C++
840+
if: runner.os == 'Windows'
841+
uses: ilammy/msvc-dev-cmd@v1
842+
837843
- name: build
838844
uses: lukka/[email protected]
839845
with:

.github/workflows/src/build.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
- uses: ilammy/msvc-dev-cmd@v1
1+
- name: setup developer command prompt for Microsoft Visual C++
2+
if: runner.os == 'Windows'
3+
uses: ilammy/msvc-dev-cmd@v1
4+
25
- name: build
36
uses: lukka/[email protected]
47
with:

Development/cmake/NmosCppDependencies.cmake

+3-3
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ add_library(nmos-cpp::OpenSSL ALIAS OpenSSL)
189189

190190
if(NMOS_CPP_USE_CONAN)
191191
set(JSON_SCHEMA_VALIDATOR_VERSION_MIN "2.1.0")
192-
set(JSON_SCHEMA_VALIDATOR_VERSION_CUR "2.2.0")
192+
set(JSON_SCHEMA_VALIDATOR_VERSION_CUR "2.3.0")
193193
find_package(nlohmann_json_schema_validator REQUIRED)
194194
if(NOT nlohmann_json_schema_validator_VERSION)
195195
message(STATUS "Found nlohmann_json_schema_validator unknown version; minimum version: " ${JSON_SCHEMA_VALIDATOR_VERSION_MIN})
@@ -202,7 +202,7 @@ if(NMOS_CPP_USE_CONAN)
202202
endif()
203203

204204
set(NLOHMANN_JSON_VERSION_MIN "3.6.0")
205-
set(NLOHMANN_JSON_VERSION_CUR "3.11.2")
205+
set(NLOHMANN_JSON_VERSION_CUR "3.11.3")
206206
find_package(nlohmann_json REQUIRED)
207207
if(NOT nlohmann_json_VERSION)
208208
message(STATUS "Found nlohmann_json unknown version; minimum version: " ${NLOHMANN_JSON_VERSION_MIN})
@@ -461,7 +461,7 @@ endif()
461461

462462
if(NMOS_CPP_USE_CONAN)
463463
set(JWT_VERSION_MIN "0.5.1")
464-
set(JWT_VERSION_CUR "0.6.0")
464+
set(JWT_VERSION_CUR "0.7.0")
465465
find_package(jwt-cpp REQUIRED)
466466
if(NOT jwt-cpp_VERSION)
467467
message(STATUS "Found jwt-cpp unknown version; minimum version: " ${JWT_VERSION_MIN})

Development/conanfile.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ boost/1.80.0
33
cpprestsdk/2.10.18
44
websocketpp/0.8.2
55
openssl/1.1.1s
6-
json-schema-validator/2.2.0
7-
nlohmann_json/3.11.2
6+
json-schema-validator/2.3.0
7+
nlohmann_json/3.11.3
88
zlib/1.2.13
99
jwt-cpp/0.7.0
1010

Development/nmos-cpp-registry/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int main(int argc, char* argv[])
112112
#endif
113113

114114
// only implement communication with Authorization server if IS-10/BCP-003-02 is required
115-
// cf. preprocessor conditions in nmos::make_registration_api, nmos::make_query_api, make_query_ws_validate_handler
115+
// cf. preprocessor conditions in nmos::make_registration_api, nmos::make_query_api, nmos::make_query_ws_validate_handler, nmos::make_events_ws_validate_handler
116116
nmos::experimental::authorization_state authorization_state;
117117
if (nmos::experimental::fields::server_authorization(registry_model.settings))
118118
{

Development/nmos/events_ws_api.cpp

-69
Original file line numberDiff line numberDiff line change
@@ -62,75 +62,6 @@ namespace nmos
6262
};
6363
}
6464

65-
web::websockets::experimental::listener::validate_handler make_events_ws_validate_handler(nmos::node_model& model, nmos::experimental::authorization_state& authorization_state, nmos::experimental::validate_authorization_token_handler access_token_validation, slog::base_gate& gate_)
66-
{
67-
return [&model, &authorization_state, access_token_validation, &gate_](web::http::http_request req)
68-
{
69-
nmos::ws_api_gate gate(gate_, req.request_uri());
70-
auto lock = model.write_lock();
71-
auto& resources = model.connection_resources;
72-
73-
// RFC 6750 defines two methods of sending bearer access tokens which are applicable to WebSocket
74-
// Clients SHOULD use the "Authorization Request Header Field" method.
75-
// Clients MAY use a "URI Query Parameter".
76-
// See https://tools.ietf.org/html/rfc6750#section-2
77-
if (web::http::methods::OPTIONS != req.method() && nmos::experimental::fields::server_authorization(model.settings))
78-
{
79-
const auto& settings = model.settings;
80-
81-
web::uri token_issuer;
82-
// note: ws_validate_authorization returns the token_issuer via function parameter
83-
const auto result = nmos::experimental::ws_validate_authorization(req, nmos::experimental::scopes::events, nmos::get_host_name(settings), token_issuer, access_token_validation, gate_);
84-
if (!result)
85-
{
86-
// set error repsonse
87-
auto realm = web::http::get_host_port(req).first;
88-
if (realm.empty()) { realm = nmos::get_host(settings); }
89-
web::http::http_response res;
90-
const auto retry_after = nmos::experimental::fields::service_unavailable_retry_after(settings);
91-
nmos::experimental::details::set_error_reply(res, realm, retry_after, result);
92-
req.reply(res);
93-
94-
// if no matching public keys caused the error, trigger a re-fetch to obtain public keys from the token issuer (authorization_state.token_issuer)
95-
if (result.value == nmos::experimental::authorization_error::no_matching_keys)
96-
{
97-
slog::log<slog::severities::warning>(gate, SLOG_FLF) << "Invalid websocket connection to: " << req.request_uri().path() << ": " << result.message;
98-
99-
with_write_lock(authorization_state.mutex, [&authorization_state, token_issuer]
100-
{
101-
authorization_state.fetch_token_issuer_pubkeys = true;
102-
authorization_state.token_issuer = token_issuer;
103-
});
104-
105-
model.notify();
106-
}
107-
else
108-
{
109-
slog::log<slog::severities::error>(gate, SLOG_FLF) << "Invalid websocket connection to: " << req.request_uri().path() << ": " << result.message;
110-
}
111-
return false;
112-
}
113-
}
114-
115-
// For now, to determine whether the "resource name" is valid, only look at the path, and ignore any query parameters
116-
const auto& ws_resource_path = req.request_uri().path();
117-
slog::log<slog::severities::more_info>(gate, SLOG_FLF) << "Validating websocket connection to: " << ws_resource_path;
118-
119-
const bool has_ws_resource_path = resources.end() != find_resource_if(resources, nmos::types::sender, [&ws_resource_path](const nmos::resource& resource)
120-
{
121-
auto active = nmos::fields::master_enable(nmos::fields::endpoint_active(resource.data));
122-
auto& transport_params = nmos::fields::transport_params(nmos::fields::endpoint_active(resource.data));
123-
auto& connection_uri = nmos::fields::connection_uri(transport_params.at(0));
124-
return active
125-
&& !connection_uri.is_null()
126-
&& ws_resource_path == web::uri(connection_uri.as_string()).path();
127-
});
128-
129-
if (!has_ws_resource_path) slog::log<slog::severities::error>(gate, SLOG_FLF) << "Invalid websocket connection to: " << ws_resource_path;
130-
return has_ws_resource_path;
131-
};
132-
}
133-
13465
web::websockets::experimental::listener::open_handler make_events_ws_open_handler(nmos::node_model& model, nmos::websockets& websockets, slog::base_gate& gate_)
13566
{
13667
using web::json::value;

Development/third_party/nlohmann/json-patch.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ class json_patch
2828
json_patch &replace(const json::json_pointer &, json value);
2929
json_patch &remove(const json::json_pointer &);
3030

31+
json &get_json() { return j_; }
32+
const json &get_json() const { return j_; }
33+
3134
operator json() const { return j_; }
3235

3336
private:
34-
json j_;
37+
json j_ = nlohmann::json::array();
3538

3639
static void validateJsonPatch(json const &patch);
3740
};

Development/third_party/nlohmann/json-validator.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,12 @@ class logical_combination : public schema
436436

437437
for (auto &s : subschemata_) {
438438
first_error_handler esub;
439+
auto oldPatchSize = patch.get_json().size();
439440
s->validate(ptr, instance, patch, esub);
440441
if (!esub)
441442
count++;
443+
else
444+
patch.get_json().get_ref<nlohmann::json::array_t &>().resize(oldPatchSize);
442445

443446
if (is_validate_complete(instance, ptr, e, esub, count))
444447
return;
@@ -553,6 +556,9 @@ class type_schema : public schema
553556
else_->validate(ptr, instance, patch, e);
554557
}
555558
}
559+
if (instance.is_null()) {
560+
patch.add(nlohmann::json::json_pointer{}, default_value_);
561+
}
556562
}
557563

558564
protected:
@@ -601,10 +607,12 @@ class type_schema : public schema
601607
} break;
602608

603609
case json::value_t::array: // "type": ["type1", "type2"]
604-
for (auto &schema_type : attr.value())
610+
for (auto &array_value : attr.value()) {
611+
auto schema_type = array_value.get<std::string>();
605612
for (auto &t : schema_types)
606613
if (t.first == schema_type)
607614
type_[static_cast<uint8_t>(t.second)] = type_schema::make(sch, t.second, root, uris, known_keywords);
615+
}
608616
break;
609617

610618
default:
@@ -856,7 +864,12 @@ class numeric : public schema
856864
bool violates_multiple_of(T x) const
857865
{
858866
double res = std::remainder(x, multipleOf_.second);
867+
double multiple = std::fabs(x / multipleOf_.second);
868+
if (multiple > 1) {
869+
res = res / multiple;
870+
}
859871
double eps = std::nextafter(x, 0) - static_cast<double>(x);
872+
860873
return std::fabs(res) > std::fabs(eps);
861874
}
862875

@@ -1134,6 +1147,11 @@ class object : public schema
11341147
propertyNames_ = schema::make(attr.value(), root, {"propertyNames"}, uris);
11351148
sch.erase(attr);
11361149
}
1150+
1151+
attr = sch.find("default");
1152+
if (attr != sch.end()) {
1153+
set_default_value(*attr);
1154+
}
11371155
}
11381156
};
11391157

0 commit comments

Comments
 (0)