Repository navigation
Conversation
…object ArduinoJson accepts unquoted keys, single quotes and raw bytes it then writes back unescaped, so embedding the caller's text could put invalid JSON in client/hello.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the addition of configurable application roles to client hello messages.
No open issues 🎉
What changed in this PR
Adds a configuration hook for applications to advertise custom roles and optional support objects in client/hello, without changing the library’s built-in roles. This supports integrations such as Music Assistant local pairing.
Changes:
- Adds
SendspinApplicationRoleandSendspinClientConfig::application_roles. - Validates role names, rejects duplicates, and normalizes support objects before startup.
- Adds validation and hello-message tests, plus public API documentation.
| File | Description |
|---|---|
tests/test_record_store.cpp |
Tests startup rejection and configured roles in client hello messages. |
tests/test_protocol.cpp |
Tests role formatting, name validation, and support-object normalization. |
tests/CMakeLists.txt |
Documents private hello-builder access used by tests. |
src/protocol.cpp |
Serializes application roles and their support objects. |
src/protocol_messages.h |
Adds application roles to the internal hello message structure. |
src/client.cpp |
Validates configuration at startup and supplies roles to hello messages. |
src/application_role.h |
Implements role-name, UTF-8, and JSON normalization helpers. |
include/sendspin/config.h |
Defines the public application-role configuration API. |
docs/integration-guide.md |
Documents configuration, examples, and validation behavior. |
Review effort: Balanced
chrisuthe
marked this pull request as ready for review
October 29, 2026 12:01
# Conflicts: # src/protocol.cpp # tests/test_protocol.cpp
…mits - client/hello views the configured application roles instead of copying them for each connection, builds each "<role>_support" key on the stack, and embeds the normalized support object without a copy, so the admission window, now with application roles configured, stays at 0 allocations. - start() refuses what messaging.md "client/hello" forbids: a support object nested past the hello's 10-level cap and a hello longer than 16384 bytes, measured on a trial hello with the per-connection fields at their longest; the oversized path rolls the started roles back. - Role names are at most 64 bytes (a library limit) and exclude `"` and `\`; is_valid_utf8() moves to inline_text.h with its own table. - The integration guide says the library does not report which application roles a server activates, and that one listed on a connection that is not playback-capable closes it.
# Conflicts: # docs/internals.md # tests/test_allocations.cpp
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Duplicate keys can hide invalid support-object strings, while hello serialization adds avoidable allocations and its preflight check can fail despite sufficient reserved arena capacity.
6 open issues
Validate strings before duplicate keys are collapsed · New Borrow role-name strings during JSON serialization · New Serialize the normalized fragment without copying it · New Reuse the reserved JSON arena for the pre-task trial · New Assert the player's inbound consumer is unbound after failures · New Add malformed three- and four-byte UTF-8 test cases · New
Review effort: Max
kahrendt
enabled auto-merge (squash)
November 5, 2026 00:18
kahrendt
deleted the
chrisuthe/task/advertise-application-specific-roles-and-support
branch
November 5, 2026 00:22
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Add
SendspinClientConfig::application_rolesso an application can list its own_-prefixed, versioned roles inclient/hellosupported_roles, after the library's roles. A role can also carry a support object, which is sent as"<role>_support"(messaging.md "client/hello", README.md "Application-Specific Roles"). The roles defined in the spec are unchanged.start()refuses to start (it logs an error and returns false) when:_<name>@<version>in visible ASCII;ArduinoJson's parser accepts input that isn't strict JSON, such as unquoted keys and single quotes. So instead of embedding the caller's text,
start()re-serializes each support object and sends that. A support object is also refused if a string in it is not valid UTF-8, or has a control character the serializer would write back unescaped.Application-specific versions of defined roles (
player@_x) are out of scope: the library implements those roles itself.This is the generic hook that local pairing with Music Assistant needs, e.g.
"_ma_local_pairing@v1_support": {"port": N}.Part of Sendspin/backlog#86.
Allocation and limit fixes
Merged main twice (#227 onward) and fixed what the allocation series requires of client/hello (Sendspin/backlog#92):
std::spanover the configstart()normalized) instead of copying them per connection, builds each"<role>_support"key on the stack, and embeds the support object withserialized(data, size), which copies it into the hello's JSON arena (the platform heap past its budget) rather than throughoperator new. The admission window ofsendspin_alloc_testsnow configures two application roles and stays at 0.start()also refuses a support object nested past messaging.md "client/hello"'s 10-level cap, and a hello longer than its 16384 bytes, measured on a trial hello with the per-connection fields at their longest; that failure rolls back the roles it started (ClientLifecycle.OversizedHelloRollsBackStartedRoles, which fails without the rollback by finding the player's sync task still bound to the ring)."and\.is_valid_utf8()lives ininline_text.hwith its own table, which rejects a bad byte at every continuation position.active_roleson a connection that is not playback-capable closes it.