[asterisk-users] Properly Escaping Quotes and Commas

Danny Nicholas danny at debsinc.com
Thu Dec 22 10:40:37 CST 2011


You could use the REPLACE function to zap the quotes and commas.

asterisk -rx "core show function REPLACE"

 

  -= Info about function 'REPLACE' =-

 

[Synopsis]

Replace a set of characters in a given string with another character.

 

[Description]

Iterates through a string replacing all the <find-chars> with <replace-ch

ar>.  <replace-char> may be either empty or contain one character.  If
empty,

all <find-chars> will be deleted from the output.

NOTE: The replacement only occurs in the output.  The original variable is

not altered.

 

[Syntax]

REPLACE(varname,find-chars[,replace-char])

 

[Arguments]

Not available

 

[See Also]

Not available

 

From: asterisk-users-bounces at lists.digium.com
[mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Cody Harris
Sent: Thursday, December 22, 2011 10:35 AM
To: asterisk-users at lists.digium.com
Subject: [asterisk-users] Properly Escaping Quotes and Commas

 

Hello all,

I have a setup where Asterisk sends a message to a few jabber users on each
incoming call, like:

 

exten => s,n,Macro(sendim,"Incoming call from ${CALLERID(all)}")

 

The macro looks like this:

 

[macro-sendimuser2]

exten => s,n,JabberSend(asterisk,user2 at gmail.com,${ARG1})

exten => s,n,JabberSend(asterisk,user2 at internal.jabber.server.tld,${ARG1})

 

[macro-sendim]

exten => s,1,Noop("Holder");

same  => n,Macro(sendimuser1,${ARG1})

same  => n,Macro(sendimuser2,${ARG1})

 

The issue I'm having, is if the callerID contains a command, such as:
Lastname, Firstname, ${CALLERID(all)} turns into "Lastname, Firstname"
<number>.

 

This seems to mess up the quoting, as the macro argument expands to be

"Incoming call from "Lastname, Firstname" <number>, and the ${ARG1} as the
macro sees it is set to "Incoming call from "Lastname

 

The comma ends up outside the double quotes and then it splits the macro
arguments.

 

What's the best way to do this right?

 

 

Thanks!!!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20111222/634b1ab9/attachment-0001.htm>


More information about the asterisk-users mailing list