[Asterisk-Dev] Re: Variable Ideas, Perl a possiblity but native

Anthony Minessale anthmct at yahoo.com
Tue Sep 2 14:18:09 MST 2003


 
I never heard of a macro , it looks cool and I'll probably go use it 100 times now 
thank you for pointing it out.... I have my box in production so I dont look 
at the new config file very much to catch these new things.
 
 
I still think it would be cool to have in/out functions and that is my motivation for 
making the app_perl
 
 
Macros look neat but only work in a 1 way type request 
which I realize will satisfy my original example (well not the "*" to "." ip translation part)
but i'd like to get something back from it too and continue on with that info.
 
Does anyone think its useful to feed the data collected on the call into a Perl
function who can eat it up and set more global vars etc based on the input?
 
or perhaps something cool like this below:
 
(all my perl examples are really possible btw not just my imagination) 
 
DISCLAIMER:
The following is an arbitrary example I came up with and if there already 
is a way to perform the same thing I am just providing it as a demonstration
of something one could home grow for an application without hacking the 
actual asterisk software.  also I braved my way through setting up a box 
with 4 t100p's and 1 tdm400p as well as another one with a t400p
all without asking 1 stupid rtfm type question. so I beg of you not 
to jump on me for missing somehting along the way, (not that anyone has yet 
but I have read some other ones where ppl do)  (maybe there should be 
rtfm.asterisk.org !) 
 
 
 
[authed]
exten => s,1,Festival,Hello ${AUTH_USER}
 
[incoming]
exten _XXXX,1,Perl,dbauth:${EXTEN}
exten _XXXX,2,Authenticate(${THEPASS})
exten _XXXX,3,Goto(authed,s,1)
 
 
 
sub lookup_pass($) {
  # any dbi code to look up $exten's pass in a db or elsewhere  
  #.... for simplicity i'll hardcode 1234 
  my $pass = "1234";
  return($pass); 

}
 
sub dbauth(@) {
  my($exten) = shift;
  
 my $pass = lookup_pass($exten);
 return )"setvar:THEPASS:$pass",
             "setvar:AUTH_USER:$exten"
           );
}
 
 
 
 
 
 
 
 

 
Subject: Re: [Asterisk-Dev] Variable Ideas, Perl a possiblity but native
would be cool too.
From: Steven Critchfield 
To: asterisk-dev at lists.digium.com
Date: 01 Sep 2003 11:52:42 -0500
Reply-To: asterisk-dev at lists.digium.com

On Mon, 2003-09-01 at 11:35, Anthony Minessale wrote:
> 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.


So why wouldn't a Macro work for you? 
-- 
Steven Critchfield 





---------------------------------
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/20030902/622f090a/attachment.htm


More information about the asterisk-dev mailing list