11 Commits

Author SHA1 Message Date
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
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
Ben Clayton
323e91d80b Session: Expose 'protected' API.
Classify 'advanced' APIs from the 'basic' API.
Move `bind()` up top, which is the typical way to use the Session.
Comment on the other APIs that you should probably just use `bind()`.

Document all the members that are now public.

Fixes: #63
2021-09-07 18:43:12 +01:00
Ben Clayton
2a3ba20937
Merge pull request #58 from ben-clayton/response-callbacks
Add Session::registerHandler() overloads that support response callbacks
2021-02-03 19:08:27 +00:00
Puneetha Ramachandra
e53575d272 Split bind API
Bind API is split into connect and startProcessingMessages calls.
This enables users to directly call connect and manage processing
messages on user threads.
2020-12-01 17:59:43 +00:00
Puneetha Ramachandra
ea6098df7f Added bindNoThread
bindNoThread in conjunction with OnDataAvailable will provide
users with a choice of thread to process requests on. This is
useful when the user relies on single threaded message loop based
design to avoid locking.
2020-12-01 17:59:43 +00:00
Ben Clayton
9d3f5c8f1d clang: Enable -Weverything, fix all warnings
This change fixes the following warnings:

```
    -Wc++98-compat-extra-semi
    -Wc++98-compat-local-type-template-args
    -Wc++98-compat-pedantic
    -Wc++98-compat
    -Wcomma
    -Wdeprecated-copy-dtor
    -Wexit-time-destructors
    -Wextra-semi-stmt
    -Wextra-semi
    -Wfloat-conversion
    -Wfloat-equal
    -Wformat-nonliteral
    -Wglobal-constructors
    -Winconsistent-missing-destructor-override
    -Wnon-virtual-dtor
    -Wold-style-cast
    -Wpadded
    -Wreturn-std-move-in-c++11
    -Wshadow-field-in-constructor
    -Wshadow-uncaptured-local
    -Wshift-sign-overflow
    -Wsign-conversion
    -Wundef
    -Wunreachable-code-return
    -Wused-but-marked-unused
    -Wweak-vtables
    -Wzero-as-null-pointer-constant
```
2020-06-10 15:10:57 +01:00
Ben Clayton
c4358807e2 Fix new gcc 9 'deprecated-copy' warning.
Example warning:

cppdap/include/dap/future.h:172:14: error: implicitly-declared ‘dap::ResponseOrError<dap::StackTraceResponse>& dap::ResponseOrError<dap::StackTraceResponse>::operator=(const dap::ResponseOrError<dap::StackTraceResponse>&)’ is deprecated [-Werror=deprecated-copy]

Add missing constructors and assignment operators.
This probably adds more than is absolutely necessary, but there's no
harm in being thorough.
2020-02-06 13:37:41 +00:00
kuafuwang
73d697eac4 Fix Response type info, make response 'body' field optional
The `body` field of the Response is optional. Do not error if it is missing.

If the typeinfo of the response. This was incorrectly using the Request type.

Authored by kuafuwang, squashed by ben-clayton.
2019-12-31 20:58:33 +00:00
Ben Clayton
44d158805c Reimplement std::future and std::promise to workaround TSAN false positives 2019-11-14 08:10:16 +00:00
Ben Clayton
2dfd15462f Initial drop of cppdap 2019-11-08 21:58:50 +00:00