Daniel Gonzalez
2014-Dec-09 09:44 UTC
[asterisk-users] Passing literals with commas to subroutine
Hi, Let's say I do: Set(data=xxx,yyy) Gosub(my-sub,s,1(${data})) My subroutine will only receive "xxx" for ARG1. How can I pass a literal with a comma to a single argument in a subroutine? (The point is: when calling the subroutine I do not know if the variable has a comma or not.) Thanks, Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20141209/46621939/attachment.html>
John Kiniston
2014-Dec-09 15:23 UTC
[asterisk-users] Passing literals with commas to subroutine
You can escape characters with a backslash, I've not tried it in this case but it may help you. Another idea is you could encode your data with the BASE64_ENCODE or URIENCODE * functions and decode it in your subroutine. https://wiki.asterisk.org/wiki/display/AST/Function_BASE64_ENCODE https://wiki.asterisk.org/wiki/display/AST/Function_URIENCODE * I'm not certain if URIENCODE will escape the comma, it sounds like it should reading the RFC. On Tue, Dec 9, 2014 at 2:44 AM, Daniel Gonzalez <gonvaled at gonvaled.com> wrote:> Hi, > > Let's say I do: > > Set(data=xxx,yyy) > Gosub(my-sub,s,1(${data})) > > My subroutine will only receive "xxx" for ARG1. How can I pass a literal > with a comma to a single argument in a subroutine? > > (The point is: when calling the subroutine I do not know if the variable > has a comma or not.) > > Thanks, > Daniel > > -- > _____________________________________________________________________ > -- Bandwidth and Colocation Provided by http://www.api-digital.com -- > New to Asterisk? Join us for a live introductory webinar every Thurs: > http://www.asterisk.org/hello > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users >-- A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects. ---Heinlein -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20141209/359344f1/attachment.html>
A J Stiles
2014-Dec-09 15:37 UTC
[asterisk-users] Passing literals with commas to subroutine
On Tuesday 09 Dec 2014, Daniel Gonzalez wrote:> Hi, > > Let's say I do: > > Set(data=xxx,yyy) > Gosub(my-sub,s,1(${data})) > > My subroutine will only receive "xxx" for ARG1. How can I pass a literal > with a comma to a single argument in a subroutine? > > (The point is: when calling the subroutine I do not know if the variable > has a comma or not.)What happens if you use speech marks around the variable, like so: "${data}" ? -- AJS Note: Originating address only accepts e-mail from list! If replying off- list, change address to asterisk1list at earthshod dot co dot uk .
A J Stiles
2014-Dec-11 12:40 UTC
[asterisk-users] Passing literals with commas to subroutine [SOLVED]
On Tuesday 09 Dec 2014, Daniel Gonzalez wrote:> Hi, > > Let's say I do: > > Set(data=xxx,yyy) > Gosub(my-sub,s,1(${data})) > > My subroutine will only receive "xxx" for ARG1. How can I pass a literal > with a comma to a single argument in a subroutine? > > (The point is: when calling the subroutine I do not know if the variable > has a comma or not.)O.K. I've managed to set myself up a temporary Asterisk box, so I was able to do some testing without risking bringing down a production server :) And I have managed to put together a solution, if you can call it that. If you put speech marks around the argument, like so: Gosub(my-sub,s,1("${data}")) then what actually comes through in ${ARG1} is "xxx,yyy" (complete with the speech marks). But at least that comma is protected. So then within my-sub, you just need to evaluate ${ARG1:1:-1}, ${ARG2:1:-1} &c. to strip off the first and last characters (skip one, show all but one). It's a bit ugly -- but so is a lot of stuff written in the Dialplan. Just because a language is Turing-complete, doesn't mean any code written in it is going to be pretty. But you might be able to mitigate some of the ugliness with comments (introduced with a semicolon in Dialplan, because the comment mark is a valid "digit"). -- AJS Note: Originating address only accepts e-mail from list! If replying off- list, change address to asterisk1list at earthshod dot co dot uk .
Eric Wieling
2014-Dec-11 15:51 UTC
[asterisk-users] Passing literals with commas to subroutine [SOLVED]
The easiest way is to escape the commas is with a \ (backslash). -----Original Message----- From: asterisk-users-bounces at lists.digium.com [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of A J Stiles Sent: Thursday, December 11, 2014 7:41 AM To: Asterisk Users Mailing List - Non-Commercial Discussion Subject: Re: [asterisk-users] Passing literals with commas to subroutine [SOLVED] On Tuesday 09 Dec 2014, Daniel Gonzalez wrote:> Hi, > > Let's say I do: > > Set(data=xxx,yyy) > Gosub(my-sub,s,1(${data})) > > My subroutine will only receive "xxx" for ARG1. How can I pass a literal > with a comma to a single argument in a subroutine? > > (The point is: when calling the subroutine I do not know if the variable > has a comma or not.)O.K. I've managed to set myself up a temporary Asterisk box, so I was able to do some testing without risking bringing down a production server :) And I have managed to put together a solution, if you can call it that. If you put speech marks around the argument, like so: Gosub(my-sub,s,1("${data}")) then what actually comes through in ${ARG1} is "xxx,yyy" (complete with the speech marks). But at least that comma is protected. So then within my-sub, you just need to evaluate ${ARG1:1:-1}, ${ARG2:1:-1} &c. to strip off the first and last characters (skip one, show all but one). It's a bit ugly -- but so is a lot of stuff written in the Dialplan. Just because a language is Turing-complete, doesn't mean any code written in it is going to be pretty. But you might be able to mitigate some of the ugliness with comments (introduced with a semicolon in Dialplan, because the comment mark is a valid "digit"). -- AJS Note: Originating address only accepts e-mail from list! If replying off- list, change address to asterisk1list at earthshod dot co dot uk . -- _____________________________________________________________________ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- New to Asterisk? Join us for a live introductory webinar every Thurs: http://www.asterisk.org/hello asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users