Skip to content

Decode the channel data in an outbound socket's connect reply - #20

Closed
henrikbjorn wants to merge 3 commits into
quiet-connection-resetfrom
decode-connect-data
Closed

henrikbjorn wants to merge 3 commits into
quiet-connection-resetfrom
decode-connect-data

Conversation

@henrikbjorn

@henrikbjorn henrikbjorn commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Make librevox URL-decode exactly what FreeSWITCH URL-encodes, and nothing else.

FreeSWITCH encodes values in two places on the event socket, both written with switch_event_serialize(…, SWITCH_TRUE), which runs switch_url_encode on every header value (v1.10.12):

Message Encoded mod_event_socket.c
text/event-plain body: the event's headers yes 1420
command/reply to connect: the channel data, in the reply's headers yes 2032
other command/reply (Reply-Text, Job-UUID) no, plain text 2742, 2374
api/response, log/data, text/disconnect-notice, auth/request no 1591, 1374, 644, 2720

The changes:

  1. Decode the connect reply. Its channel data was kept raw, so the first snapshot of every outbound session held route_plan as %7B%22type%22… and +45… numbers as %2B45…. Response now recognizes a reply that FreeSWITCH built from a whole event: it carries Event-Name, and the connect reply is Event-Name: CHANNEL_DATA. It decodes that reply's headers, so no caller has to know which reply it was.
  2. Decode only event bodies. Response decoded the header lines of any body, so a literal %2B in a log line or a reply came out as +. Bodies are now decoded only for text/event-plain.

Reply headers stay raw, as before. FreeSWITCH's own C client (esl.c) URL-decodes every header value of every message, but that is a shortcut on its side: FreeSWITCH doesn't encode those headers, and decoding them would corrupt a literal %xx.

Tests:

  • An encoded JSON route_plan and a %2B number in the connect reply come out decoded, and so does any reply carrying Event-Name.
  • A log/data body and a reply body with a literal %2B stay raw.

Stacked on #19.

FreeSWITCH URL-encodes the channel data it sends in reply to connect, as
it does in event bodies. Response parses reply headers without decoding,
so the first snapshot of every outbound session held raw values:
route_plan as %7B%22type%22..., and +45... numbers as %2B45.... Later
CHANNEL_DATA and execute-complete updates go through the event body and
were decoded, so the bug showed only in values read before a verb ran.

Response#decoded_headers decodes the values, and Outbound#run_session
uses it for the connect reply only. Other replies' headers are not
encoded.
@henrikbjorn henrikbjorn self-assigned this Oct 1, 2026
FreeSWITCH URL-encodes exactly two things on the event socket, both
with switch_event_serialize(..., SWITCH_TRUE): an event's header values
(text/event-plain) and the channel data in the connect reply. Everything
else (command/reply, api/response, log/data, disconnect notices) is
written raw. Response decoded the header lines of any body, so a literal
%2B in a log line would have come out as +. Bodies are now decoded only
for text/event-plain.
A reply that FreeSWITCH builds from a whole event carries Event-Name; its
reply to connect is the channel data (Event-Name: CHANNEL_DATA). Response
now URL-decodes the headers of such a reply, so the outbound listener no
longer has to know which reply to decode, and decoded_headers goes.
@henrikbjorn

Copy link
Copy Markdown
Member Author

Folded into #25, which collects these changes in one PR.

@henrikbjorn henrikbjorn closed this Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant