[Freeswitch-users] originate api: Escaping variable names/values

Shane Mitchell sm at opencluster.com.au
Tue Nov 23 06:48:30 UTC 2021


Using the originate API and enterprise origination: I am attempting to specify various variables, such as custom headers and digest credentials, and am trying to understand how escaping is implemented, as I am inserting user-specified values into the string. I need to set it all up in one API call due to the various ways originate is being used. Here's a simple example:

originate [sip_h_X-Custom=ESCAPED]sofia/public/user at example.com $park()

I have searched the docs and source code, and have a solution that works most of the time, but there are edge cases I can't seem to resolve.

I've tried URL encoding but it seems to have no effect here.  Escaping with back-slash seems to have an effect, so I've experimented with it below.

For example, this works:

Escaped: \'123       (inserted in above API command)
Actual: '123            (the value of X-Custom observed in the generated INVITE)
Expected: '123

While this doesn't:

Escaped: \'1\'23
Actual: 123
Expected: '1'23

In fact, for an even number of quotes, none survive, while for an odd number of quotes, only the last quote ever survives:

Escaped: \'1\'2\'3
Actual: 12'3
Expected: '1'2'3

Escaped: \'1\'2\'3\'4\'5\'6\'7\'8\'9
Actual: 12345678'9
Expected: '1'2'3'4'5'6'7'8'9

Wrapping the entire argument with single quotes does not change the behavior:

Escaped: '\'1\'2\'3\'4\'5\'6\'7\'8\'9'
Actual: 12345678'9
Expected: '1'2'3'4'5'6'7'8'9

Besides single quotes, backslashes also act strangely. Many times they work properly:

Escaped: a\\b\\c
Actual: a\b\c
Expected: a\b\c

But when escape sequences are in a sequence, they act unexpectedly:

Escaped: \\\\
Actual: \
Expected: \\

Escaped: a\\\'b
Actual: a'b
Expected: a\'b

The next example becomes truncated. My guess is that it is interpreting "\n" as a new line.

Escaped: a\\nice\\day
Actual: a
Expected: a\nice\day

Can anyone advise if I'm using the correct syntax/this is an issue, or if there's something I'm missing/doing wrong?

Version: FreeSWITCH Version 1.10.7-release-19-883d2cb662~64bit (-release-19-883d2cb662 64bit)




More information about the FreeSWITCH-users mailing list