108 Commits

Author SHA1 Message Date
David Neto
9fd09d6dce
kokoro: update tooling, fix warnings
Kokoro changes:
-  Linux: gcc-13, cmake-3.31.2
- Windows: python 3.12, cmake-3.31.2

* Disable warnings in gtest, gmock

This is required in order to build with GCC 13, and Apple Clang with warnings-as-errors

Bug: crbug.com/383538610

* disable license check on .github/workflows/main.yml

* Use add_subdirectory for internal gtest, gmock

---------

Co-authored-by: Antonio Maiorano <amaiorano@google.com>
2024-12-16 10:51:28 -05:00
Sergei Trofimovich
c69444ed76
include/dap/network.h: add <stdint.h> include for gcc-15 (#133)
On `gcc-15` without the include header can't be used as is. I noticed
`cmake` build failing as:

    dap/network.h:31:39: error: 'uint32_t' has not been declared
       31 |                                       uint32_t timeoutMillis = 0);
          |                                       ^~~~~~~~

The change adds `uint32_t` declaration via `<stdint.h>`.
2024-08-02 11:38:40 -04:00
ocack
0f943b3357 Fix for issue #100 : Let possible to start the server on an address other than localhost
Add a new function for keeping the API stable
2024-04-30 11:03:44 +01:00
nikitalita
37c744c294 Update to 1.65.0 2024-04-10 08:59:08 +01:00
Christoph Grüninger
5857b55c15 cmake: Fix inconsistent endif() argument
The argument in the corresponding if() was changed in
commit ae76a38. CMake emits a warning.
Modern CMake style guides advice on ommitting endif()
arguments.
2024-01-08 10:00:50 +00:00
Christoph Grüninger
bb059f0daf Add reference in range-for for non-trivial type
Avoid copy-ctor and dtor to get called.
Found by Clazy (range-loop-reference)
2024-01-08 09:59:59 +00:00
topazus
ae76a3888e CMake: add CPPDAP_USE_EXTERNAL_GTEST_PACKAGE option 2024-01-02 18:16:46 +00:00
Ben Clayton
bbde7fb4dc Add missing override to ~Impl()
The other virtual methods are marked with `override`, so there's no good reason for the destructor to not have this too.
2023-12-11 19:33:19 +00:00
Frederik Carlier
869caba42c Install the runtime file, too
This makes sure the shared library, which is built when compiling with the BUILD_SHARED_LIBS flag, is installed.
2023-10-09 23:50:20 +01:00
Frederik Carlier
d1eb95c7b6 Compile with both gcc and clang 2023-10-09 23:41:05 +01:00
Frederik Carlier
c9d20322b8 Add GitHub actions 2023-10-09 23:41:05 +01:00
Đoàn Trần Công Danh
cc2f205884 Do not call freeaddrinfo(3) on nullptr
freeaddrinfo(3) only defined to free one or more addrinfo structures
returned by getaddrinfo(3).  Thus, it's undefined behaviour for calling
freeaddrinfo(3) on nullptr, some libc only call free(3) on the the
passed addrinfo, but other libc assumes the addrinfo is always valid.

Let's be explicit instead of relying on undefined behaviours.

Let's drop one call to freeaddrinfo(3) because the addrinfo there is
always nullptr and guard the second.
2023-08-17 13:22:06 +01:00
Julien Schueller
6a3cc9a804 CMake: Allow to build dynamic lib
This allows taking cmake BUILD_SHARED_LIBS option to decide whether to build a shared or static lib
This does not change the default (static)
2023-07-13 19:23:48 +01:00
Dan McNulty
e3379ed8c9 Fix infinite loop when parsing invalid DAP message.
This commit updates `ContentReader::read` to optionally close the
underlying `Reader` when a message is read that does not terminate
the DAP header immediately following the `Content-Length` header
field.

This fixes an infinite loop when parsing an invalid DAP message. In
particular, the infinite loop occurs when a cross-site HTTP request from
a browser running on the same host as a cppdap server is sent to the
server. As cross-site requests to the localhost can be triggered by
untrusted JavaScript, more validation of the DAP messages is required to
protect cppdap-based servers from malicious requests.

This commit introduces a new enum flag on both `Session` and
`ContentReader` to allow a user to indicate that the underlying `Reader`
should be closed when an invalid DAP message is received. The
server example has been updated to indicate that invalid messages
should result in closure of the underlying `Reader`.
2023-07-05 20:12:05 +01:00
Dan McNulty
93d94a7d85 Update StringBuffer to support partial reads test case.
Per #115, `ContentReader::match` must block until the whole pattern is
read or the underlying `Reader` is closed. The previous commit reverted
the change from #50 to ensure this behavior is still implemented.

This commit re-adds the unit test from #50 with an update to the
behavior of `StringBuffer` to correct implement `Reader` so that
the partial read test case is still covered by the unit tests.
2023-07-05 20:12:05 +01:00
Dan McNulty
8399fbae7f Revert "Fix content reader for partial input"
This reverts commit 77209caf044d58c7d87770b377027a65fe696466.
2023-07-05 20:12:05 +01:00
Ben Clayton
60fee6e505 Remove accidental commit 2023-06-09 14:50:18 +01:00
Gregor Jasny
252b56807b build(cmake): use min CMake version prior to project call
The [CMake documentation](https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html)
mandates that `cmake_minimum_required` should be called early
in the `CMakeLists.txt` prior to any `project()` command.
2023-06-05 09:53:37 +01:00
Brad King
03cc18678e optional: Fix compilation on XLClang 16.1.0
The compiler rejects initialization with `= {}`:

    error: chosen constructor is explicit in copy-initialization

Use just `{}` instead.
2023-05-26 00:20:21 +01:00
Brad King
1344b56dc5 jsoncpp: Cast dap integer to largest JsonCpp integer type
JsonCpp is not always built with support for `int64_t`.
2023-05-23 19:16:39 +01:00
Brad King
4d9f296aa2 jsoncpp: Add missing include <memory>
We use `std::unique_ptr` from this header.
2023-05-23 19:16:39 +01:00
Brad King
79562e0742 any: Add missing include <stdint.h>
We use `uint8_t` and `uintptr_t` from this header.
2023-05-22 23:27:25 +01:00
Ben McMorran
13de893d55 Address PR comments 2023-05-19 17:15:11 +01:00
Ben McMorran
6a3c173aab Add support for JsonCpp 2023-05-19 17:15:11 +01:00
Brad King
385f9ed3ad
any: Tell clang-analyzer a pointer is not nullptr (#107)
Previously, clang-analyzer warned:

    /.../any.h:146:5: warning: Called C++ object pointer is null [core.CallAndMessage]
2023-05-17 20:02:57 +01:00
Brad King
5f49573daf
Fix compiler warning and error encountered on some platforms (#106)
* typeof: Avoid -Wshadow-uncaptured-local in DAP_IMPLEMENT_STRUCT_TYPEINFO

Previously, applications using `DAP_IMPLEMENT_STRUCT_TYPEINFO` may see:

    <app-file>:<app-line>:1: warning: declaration shadows a local variable [-Wshadow-uncaptured-local]
    DAP_IMPLEMENT_STRUCT_TYPEINFO(<app-args>),
    ^
    /.../include/dap/typeof.h:199:3: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_TYPEINFO'
    DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION(STRUCT, NAME, __VA_ARGS__)       \
    ^
    /.../include/dap/typeof.h:168:51: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION'
        if (!d->field(field.name, [&](Deserializer* d) {                        \
                                                    ^
    <app-file>:<app-line>:1: note: previous declaration is here
    /.../include/dap/typeof.h:199:3: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_TYPEINFO'
    DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION(STRUCT, NAME, __VA_ARGS__)       \
    ^
    /.../include/dap/typeof.h:164:62: note: expanded from macro 'DAP_IMPLEMENT_STRUCT_FIELD_SERIALIZATION'
    bool TypeOf<STRUCT>::deserializeFields(const Deserializer* d, void* obj) {  \
                                                               ^

* io: add missing include for std::string
2023-05-17 19:10:58 +01:00
Ben Clayton
619435a703
Add missing include to io.h (#105)
Fixes #104
2023-05-05 18:05:53 +01:00
Brad King
558886e7e0
cmake: Avoid exposing implementation dependencies publicly (#102)
The `CPPDAP_JSON_{NLOHMANN,RAPID}` compile definition is used only in
cppdap's implementation sources, and does not need to be defined by
dependents including our headers.

Also avoid exposing `nlohmann_json::nlohmann_json` as a public link
dependency of our installed package.  It is used only when compiling
cppdap.
2023-03-23 17:56:22 +00:00
nikitalita
bf1f56547c
autogenerate fuzzing data from spec (#95) 2023-03-13 17:17:41 +00:00
Ben Clayton
59819690ec
Add Session::ClosedHandler (#99)
A callback function to signal that the endpoint has closed its connection.

Add this as an optional argument to Session::bind() and Session::startProcessingMessages().

Bug: #98
2023-02-28 14:26:12 +00:00
nikitalita
315ffff9e7
Fix any, embedded object, array, and struct serialization (#94)
* add embedded object serialization tests (failing)

* Add empty object tests (failing)

* test for deserializing null field object (failing)

* Fix embedded object deserialization

* Fix serializing empty objects on nlohmann

* Fix nullptr_t handling in `any`

* Add test for de/serializing struct embedded in `object`

* Remove extraneous `get()` from `any`

* fix compiler errors and warnings on gcc

* add `any = dap::null` assignment test

* Remove extraneous template
2023-02-16 23:09:45 +00:00
nikitalita
d9041149a8
Auto-update cmakelists on protocol sync, update to 1.59.0 (#93)
* CMake: Fix target options

* update CMake package version after protocol sync

* Update protocol to 1.59.0

* protocol_gen: change OneOf to `object` type

The DAP spec introduces ambiguities with its particular uses of OneOf,
which means that we can't deserialize the variants generated from it.
Just set OneOf to an `object` type, like godap does.
2023-02-13 22:55:48 +00:00
nikitalita
0a340c6d71
Add options to link against external JSON libraries (#91)
Add options to link against external JSON libraries

This adds two options to the CMake config:

`CPPDAP_USE_EXTERNAL_NLOHMANN_JSON_PACKAGE` and `CPPDAP_USE_EXTERNAL_RAPIDJSON_PACKAGE`
If either of these is set, instead of using the json submodule, the build will be configured by using `find_package()` and linking against the specified JSON library.
2023-01-10 13:35:23 +00:00
nikitalita
a4bc977343 Exclude .gitattributes from license checker 2023-01-06 15:54:31 +00:00
nikitalita
f08774e5f6 Fix CRLF EOL in config.cmake.in, add gitattributes 2023-01-06 15:54:31 +00:00
zhouyi
574190fb63 fix bug in processEvent function 2023-01-05 15:54:39 +00:00
nikitalita
3b01ef99ae Bump version of cmake in Windows kokoro script 2023-01-05 12:40:05 +00:00
nikitalita
5b796454c1 Bump required CMake to 3.11 2023-01-05 12:40:05 +00:00
nikitalita
7c31141c5a White space fixes 2023-01-05 12:40:05 +00:00
nikitalita
a25be1fa0b cmakelists.txt: add destinations to install targets
Add proper ARCHIVE, LIBRARY, and INCLUDES to install target
2023-01-05 12:40:05 +00:00
nikitalita
eedb5e02b6 add license header to config.in, bump copyright date 2023-01-05 12:40:05 +00:00
nikitalita
22779a0052 bump cmake package version 2023-01-05 12:40:05 +00:00
nikitalita
ebdcc5b9b4 fix semver require, config template 2023-01-05 12:40:05 +00:00
nikitalita
fe8695c502 Add package install and config 2023-01-05 12:40:05 +00:00
Ben Clayton
03e975779e Add a simple network client / server example
Issue: #77
2023-01-04 10:48:24 +00:00
Ben Clayton
8a320f56dc
Minor cleanup + kokoro ubuntu fix (#86)
* tools: Minor clean up of protocol_gen.go

* Fix kokoro/ubuntu builds
2022-12-16 13:53:50 +00:00
nikitalita
87f8b4a06b
Fix "oneOf" parsing, update to protocol version 1.58 (#85)
* fix "oneOf" parsing in protocol_gen

* update protocol version to 1.58.0
2022-12-16 13:43:39 +00:00
Ben Clayton
88e8952014
kokoro: Fix ASAN build (#76)
The VM has been updated to Kokoro 14.04, and now the docker instance requires escalated privileges in order to run some sanitizer builds.
2021-12-23 17:35:56 +00:00
luzhen
a841177c5b
Fix valid function invoke failed in future class (#75)
In C++11, shared_ptr has an explicit operator bool which
means that a shared_ptr can't be implicitly converted to a bool.
adding an explicit cast is a valid fix to the code.
2021-12-23 07:21:55 +00:00
Ben Clayton
5f3169421e
Fix reconnection of sockets (#70)
This was entirely broken:
* The `Server` `Impl` used a `do{}while(false)` block, which never attempted to accept another connection after the first connection closed (#69)
* The `Server` `Impl` could deadlock with the mutex being locked by both the thread calling `isRunning()` and `stopWithLock()` waiting on `thread.join()`.
* `Socket::accept()` didn't check that the returned socket was valid, and could return a `ReaderWriter` that would just error on IO.
* `Socket::accept()` could deadlock on macOS as `shutdown()` can seemingly fail to unblock an accept call. This has been worked around by calling `close()` outside of the mutex write-lock. This introduces a potential race, but I'm not sure of a better solution right now.
 
Fixes: #69
2021-09-07 18:55:02 +01:00