[Asterisk-Dev] Variable Ideas, Perl a possiblity but native would be cool too.
Anthony Minessale
anthmct at yahoo.com
Mon Sep 1 09:35:17 MST 2003
I was setting up an extensions.conf the other day when I realized some things I wish were possible and just tossing it up for input.
1)
If you used a certian variable in a context it would be nice if you could
change the value of that variable right before you do an include so you
could make templates of sorts that could be controlled by the include command.
For example
[globals]
OUT1=Zap/1
OUT2=Zap/2
[generic]
exten => _9.,1,Dial(${OUT}/${EXTEN:1})
[ex1]
include => generic, OUT=${OUT1}
[ex2]
include => generic, OUT=${OUT2}
I accomplished this using my app_perl module but doing at natively doesnt seem too complicated.
[generic]
exten => _9.,1,Perl,dial_by_context:${CONTEXT}
exten => _9.,2,Dial(${USETRUNK}/${EXTEN:1})
[ex1]
include => generic
[ex2]
include => generic
# in my asterisk_init.pm
sub dial_by_context(@) {
my ($context) = @_;
my %trunks = (
ex1 => "Zap/1",
ex2 => "Zap/2",
default => "Zap/1"
);
$trunks{$context} ||= $trunks{default};
return ("setvar:USETRUNK:$trunks{$context}");
}
then when you are in context ex1 the ${USETRUNK} is Zap/1
and in ex2 it's Zap/2 but you only need 1 generic context.
2)
Another possibility could be to implement associative arrays as global variables.
[globals]
[global_hashes]
TRUNKS = (ex1 => "Zap/1", ex2 => "Zap/2")
[generic]
exten => _9.,1,Dial(${TRUNKS}->[${CONTEXT}]/${EXTEN:1})
[ex1]
include => generic, OUT=${OUT1}
[ex2]
include => generic, OUT=${OUT2}
3)
Finally a regex engine would be nice to perform tranlation on variables
I also do this with app_perl but it could be native as well
Say you want to be able to dial an IP address on an analog phone by
using the * as a period and pattern match it and feed it to H323
exten => _9*.*.*.*.,1,Perl,star_to_ip:${EXTEN:2}
exten => _9*.*.*.*.,2,Ringing
exten => _9*.*.*.*.,3,Dial(H323/${CALLIP})
exten => _9*.*.*.*.,4,Congestion
sub star_to_ip(@) {
my $num = shift;
$num =~ s/\*/\./g;
return "setvar:CALLIP:$num";
}
perhaps just magic special var called ${SUBSTITUTE}
exten => _9*.*.*.*.,1,Substitute,${EXTEN:2},*,.
exten => _9*.*.*.*.,2,Ringing
exten => _9*.*.*.*.,3,Dial(H323/${SUBSTITUTED})
exten => _9*.*.*.*.,4,Congestion
i'm sure app_substitute could be its own module I'm just offering input
That's kinda why I wanted to make an app_perl so I could just make stuff
on the fly w/o doing any C but I think i need to go work on it a little more before
it's pubicly accepted.
---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20030901/cc9291f8/attachment.htm
More information about the asterisk-dev
mailing list