<DIV> </DIV>
<DIV>I never heard of a macro , it looks cool and I'll probably go use it 100 times now </DIV>
<DIV>thank you for pointing it out.... I have my box in production so I dont look </DIV>
<DIV>at the new config file very much to catch these new things.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>I still think it would be cool to have in/out functions and that is my motivation for </DIV>
<DIV>making the app_perl</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Macros look neat but only work in a 1 way type request </DIV>
<DIV>which I realize will satisfy my original example (well not the <STRONG>"*"</STRONG> to <STRONG>"."</STRONG> ip translation part)</DIV>
<DIV>but i'd like to get something back from it too and continue on with that info.</DIV>
<DIV> </DIV>
<DIV>Does anyone think its useful to feed the data collected on the call into a Perl</DIV>
<DIV>function who can eat it up and set more global vars etc based on the input?</DIV>
<DIV> </DIV>
<DIV>or perhaps something cool like this below:</DIV>
<DIV> </DIV>
<DIV>(all my perl examples are really possible btw not just my imagination) </DIV>
<DIV> </DIV>
<DIV>DISCLAIMER:</DIV>
<DIV>The following is an arbitrary example I came up with and if there already </DIV>
<DIV>is a way to perform the same thing I am just providing it as a demonstration</DIV>
<DIV>of something one could home grow for an application without hacking the </DIV>
<DIV>actual asterisk software. also I braved my way through setting up a box </DIV>
<DIV>with 4 t100p's and 1 tdm400p as well as another one with a t400p</DIV>
<DIV>all without asking 1 stupid rtfm type question. so I beg of you not </DIV>
<DIV>to jump on me for missing somehting along the way, (not that anyone has yet </DIV>
<DIV>but I have read some other ones where ppl do) (maybe there should be </DIV>
<DIV>rtfm.asterisk.org !) </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>[authed]</DIV>
<DIV>exten => s,1,Festival,Hello ${AUTH_USER}</DIV>
<DIV> </DIV>
<DIV>[incoming]</DIV>
<DIV>exten _XXXX,1,Perl,dbauth:${EXTEN}</DIV>
<DIV>exten _XXXX,2,Authenticate(${THEPASS})</DIV>
<DIV>exten _XXXX,3,Goto(authed,s,1)</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>sub lookup_pass($) {</DIV>
<DIV>
<DIV> # any dbi code to look up $exten's pass in a db or elsewhere </DIV>
<DIV> #.... for simplicity i'll hardcode 1234 </DIV>
<DIV> my $pass = "1234";</DIV>
<DIV> return($pass); </DIV></DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV>sub dbauth(@) {</DIV>
<DIV> my($exten) = shift;</DIV>
<DIV> </DIV>
<DIV> my $pass = lookup_pass($exten);</DIV>
<DIV> return )"setvar:THEPASS:$pass",</DIV>
<DIV> "setvar:AUTH_USER:$exten"</DIV>
<DIV> );</DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><BR> </DIV>
<DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">Subject: Re: [Asterisk-Dev] Variable Ideas, Perl a possiblity but native<BR>would be cool too.<BR>From: Steven Critchfield <CRITCH@BASESYS.COM><BR>To: asterisk-dev@lists.digium.com<BR>Date: 01 Sep 2003 11:52:42 -0500<BR>Reply-To: asterisk-dev@lists.digium.com<BR><BR>On Mon, 2003-09-01 at 11:35, Anthony Minessale wrote:<BR>> I was setting up an extensions.conf the other day when I realized some<BR>> things I wish were possible and just tossing it up for input. <BR>> <BR>> 1)<BR>> <BR>> If you used a certian variable in a context it would be nice if you<BR>> could<BR>> change the value of that variable right before you do an include so<BR>> you <BR>> could make templates of sorts that could be controlled by the include<BR>> command.<BR>> <BR>> For example<BR>> <BR>> [globals]<BR>> OUT1=Zap/1<BR>> OUT2=Zap/2<BR>> <BR>>
[generic]<BR>> exten => _9.,1,Dial(${OUT}/${EXTEN:1})<BR>> <BR>> [ex1]<BR>> include => generic, OUT=${OUT1}<BR>> <BR>> [ex2] <BR>> include => generic, OUT=${OUT2}<BR>> <BR>> <BR>> I accomplished this using my app_perl module but doing at natively<BR>> doesnt seem too complicated.<BR>> <BR>> [generic]<BR>> exten => _9.,1,Perl,dial_by_context:${CONTEXT}<BR>> exten => _9.,2,Dial(${USETRUNK}/${EXTEN:1})<BR>> <BR>> [ex1]<BR>> include => generic<BR>> <BR>> [ex2] <BR>> include => generic<BR>> <BR>> # in my asterisk_init.pm <BR>> <BR>> sub dial_by_context(@) {<BR>> my ($context) = @_;<BR>> my %trunks = (<BR>> ex1 => "Zap/1",<BR>> ex2 => "Zap/2",<BR>> default => "Zap/1"<BR>> );<BR>> $trunks{$context} ||= $trunks{default};<BR>> return ("setvar:USETRUNK:$trunks{$context}");<BR>> }<BR>> <BR>> then when you are in context ex1 the ${USETRUNK} is Zap/1<BR>>
and in ex2 it's Zap/2 but you only need 1 generic context.<BR>> <BR>> <BR>> 2)<BR>> <BR>> Another possibility could be to implement associative arrays as global<BR>> variables.<BR>> <BR>> [globals]<BR>> <BR>> [global_hashes]<BR>> TRUNKS = (ex1 => "Zap/1", ex2 => "Zap/2") <BR>> <BR>> [generic]<BR>> exten => _9.,1,Dial(${TRUNKS}->[${CONTEXT}]/${EXTEN:1})<BR>> <BR>> [ex1]<BR>> include => generic, OUT=${OUT1}<BR>> <BR>> [ex2] <BR>> include => generic, OUT=${OUT2}<BR>> <BR>> 3)<BR>> <BR>> Finally a regex engine would be nice to perform tranlation on<BR>> variables<BR>> I also do this with app_perl but it could be native as well<BR>> <BR>> Say you want to be able to dial an IP address on an analog phone by<BR>> using the * as a period and pattern match it and feed it to H323<BR>> <BR>> exten => _9*.*.*.*.,1,Perl,star_to_ip:${EXTEN:2}<BR>> exten =>
_9*.*.*.*.,2,Ringing<BR>> exten => _9*.*.*.*.,3,Dial(H323/${CALLIP})<BR>> exten => _9*.*.*.*.,4,Congestion<BR>> <BR>> sub star_to_ip(@) {<BR>> my $num = shift;<BR>> $num =~ s/\*/\./g;<BR>> return "setvar:CALLIP:$num";<BR>> }<BR>> <BR>> perhaps just magic special var called ${SUBSTITUTE}<BR>> <BR>> <BR>> exten => _9*.*.*.*.,1,Substitute,${EXTEN:2},*,.<BR>> exten => _9*.*.*.*.,2,Ringing<BR>> exten => _9*.*.*.*.,3,Dial(H323/${SUBSTITUTED})<BR>> exten => _9*.*.*.*.,4,Congestion<BR>> <BR>> i'm sure app_substitute could be its own module I'm just offering<BR>> input <BR>> That's kinda why I wanted to make an app_perl so I could just make<BR>> stuff <BR>> on the fly w/o doing any C but I think i need to go work on it a<BR>> little more before <BR>> it's pubicly accepted.<BR><BR><BR>So why wouldn't a Macro work for you? <BR>-- <BR>Steven Critchfield
<CRITCH@BASESYS.COM><BR><BR><BR></BLOCKQUOTE></DIV><p><hr SIZE=1>
Do you Yahoo!?<br>
<a href="http://us.rd.yahoo.com/evt=10469/*http://sitebuilder.yahoo.com">Yahoo! SiteBuilder</a> - Free, easy-to-use web site design software