Skip to content

Commit

Permalink
Made libwebsocket usage as default, and websocket++ usage enabled wit…
Browse files Browse the repository at this point in the history
…h a cmake option that is default OFF

Signed-off-by: AssemblyJohn <[email protected]>
  • Loading branch information
AssemblyJohn committed Apr 8, 2024
1 parent 5c66e7b commit 7e5ad55
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,14 @@ Local testing is still in progress.
## Building with FetchContent instead of EDM
In [doc/build-with-fetchcontent](doc/build-with-fetchcontent) you can find an example how to build libocpp with FetchContent instead of EDM.

## Support for libwebsockets
### Support for TPM keys

A new websocket implementation based on libwebsockets will deprecate the old websocket++ implmentation. It supports all security profiles, along with TPM usage.
In order to use the TPM keys, it is mandatory to use the default libwebsocket implementation.

### Support for TPM keys
## Support for websocket++

In order to use the TPM keys, it is mandatory to use the libwebsocket implementation with the following cmake option.
The old old websocket++ implmentation has been deprecated. For enabling old websocket++ support use the following cmake option:

```bash
cmake .. -DLIBOCPP_ENABLE_LIBWEBSOCKETS=ON
cmake .. -DLIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP=ON
```
5 changes: 2 additions & 3 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ date:
options: ["BUILD_TZ_LIB ON", "HAS_REMOTE_API 0", "USE_AUTOLOAD 0", "USE_SYSTEM_TZ_DB ON"]
websocketpp:
git: https://github.com/zaphoyd/websocketpp.git
git_tag: 0.8.2
git_tag: 0.8.2
libevse-security:
git: https://github.com/EVerest/libevse-security.git
git_tag: v0.5.0
libwebsockets:
git: https://github.com/warmcat/libwebsockets.git
git_tag: v4.3.3
cmake_condition: "LIBOCPP_ENABLE_LIBWEBSOCKETS"
git_tag: v4.3.3
options:
- CMAKE_POLICY_DEFAULT_CMP0077 NEW
- LWS_ROLE_RAW_FILE OFF
Expand Down
20 changes: 10 additions & 10 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ add_subdirectory(ocpp/v16/messages)
add_subdirectory(ocpp/v201/messages)

option(LIBOCPP_USE_BOOST_FILESYSTEM "Usage of boost/filesystem.hpp instead of std::filesystem" OFF)
option(LIBOCPP_ENABLE_LIBWEBSOCKETS "Usage of libwebsockets instead of websockets++" OFF)
option(LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP "Usage of deprecated websocket++ instad of libwebsockets" OFF)

target_include_directories(ocpp
PUBLIC
Expand Down Expand Up @@ -110,10 +110,10 @@ endif()

target_link_libraries(ocpp
PUBLIC
everest::timer
websocketpp::websocketpp
everest::timer
nlohmann_json_schema_validator
everest::evse_security
websocketpp::websocketpp
PRIVATE
OpenSSL::SSL
OpenSSL::Crypto
Expand All @@ -124,15 +124,15 @@ target_link_libraries(ocpp
date::date-tz
)

if(LIBOCPP_ENABLE_LIBWEBSOCKETS)
find_package(libwebsockets REQUIRED)
target_link_libraries(ocpp
PUBLIC
websockets_shared
)
target_link_libraries(ocpp
PUBLIC
websockets_shared
)

if(LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP)
target_compile_definitions(ocpp
PRIVATE
LIBOCPP_ENABLE_LIBWEBSOCKETS
LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP
)
endif()

Expand Down
14 changes: 5 additions & 9 deletions lib/ocpp/common/websocket/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
target_sources(ocpp
PRIVATE
websocket_base.cpp
websocket_uri.cpp
websocket_uri.cpp
websocket.cpp
websocket_libwebsockets.cpp

# TODO: remove when interface refactor is done
websocket_plain.cpp
websocket_tls.cpp
websocket.cpp
)

if(LIBOCPP_ENABLE_LIBWEBSOCKETS)
target_sources(ocpp
PRIVATE
websocket_libwebsockets.cpp
)
endif()
10 changes: 6 additions & 4 deletions lib/ocpp/common/websocket/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include <ocpp/common/websocket/websocket.hpp>
#include <ocpp/v16/types.hpp>

#ifdef LIBOCPP_ENABLE_LIBWEBSOCKETS
#include <ocpp/common/websocket/websocket_libwebsockets.hpp>

#ifdef LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP
#include <ocpp/common
#endif
#include <boost/algorithm/string.hpp>
Expand All @@ -19,14 +21,14 @@ Websocket::Websocket(const WebsocketConnectionOptions& connection_options, std::
std::shared_ptr<MessageLogging> logging) :
logging(logging) {

#ifdef LIBOCPP_ENABLE_LIBWEBSOCKETS
this->websocket = std::make_unique<WebsocketTlsTPM>(connection_options, evse_security);
#else
#ifdef LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP
if (connection_options.security_profile <= 1) {
this->websocket = std::make_unique<WebsocketPlain>(connection_options);
} else if (connection_options.security_profile >= 2) {
this->websocket = std::make_unique<WebsocketTLS>(connection_options, evse_security);
}
#else
this->websocket = std::make_unique<WebsocketTlsTPM>(connection_options, evse_security);
#endif
}

Expand Down

0 comments on commit 7e5ad55

Please sign in to comment.