<DIV>
<DIV><FONT size=2>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>I just made my first 2 modules for asterisk (The 1st one is depriciated already).</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>I was annoyed that i couldn't get GotoIf to take any expressions besides a boolean </FONT></DIV>
<DIV><FONT size=2>then i made a module to mimic gotoif and parse a few expressions like (${var} > 12)</FONT></DIV>
<DIV><FONT size=2>exten => 1,1,gotoif_expr,${var} > 12:1|4:1|5</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>Then I immediatly obseleted it with this new embedded perl module that lets </FONT></DIV>
<DIV><FONT size=2>you implement stuff at will from perl instead of needing to make a module </FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>Say you want to make gotoif that can parse expressions </FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>exten => 1,1,Perl,gotoif:${var} > 12:1|4:1|5</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>say ${var} = 4</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>then gotoif perl sub is launched as</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>gotoif(4,"1|4","1|5");</FONT></DIV>
<DIV><FONT size=2> </FONT></DIV>
<DIV><FONT size=2>and gotoif() looks like: </FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>sub gotoif(@) {<BR> my($expr,$goto1,$goto2) = @_;<BR> my $test;</FONT></DIV>
<DIV><FONT size=2> eval "\$test = ($expr)";<BR> my $ret = "goto:" . (($test) ? $goto1 : $goto2);<BR> print "test: [$expr] = [$test] [$ret]\n";<BR> $ret;<BR>}<BR></FONT></DIV>
<DIV><FONT size=2>Funy thing is I was too obcessed with what I had already seen so far in asterisk that </FONT></DIV>
<DIV><FONT size=2>I didnt even notice AGI </FONT><FONT size=2>until yesterday =)</FONT></DIV>
<DIV><FONT size=2> </DIV></FONT>
<DIV><FONT size=2>here is my beta README </FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>app_perl 1.0</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV><FONT size=2>
<DIV><BR>This is app_perl the "mod_perl" of sorts for asterisk. It is an actual live Perl Interpreter<BR>embeded in a module so when it starts up the perl stays resident in memory the whole life of the<BR>Asterisk process.</DIV>
<DIV> </DIV>
<DIV>FEATURES:</DIV>
<DIV> </DIV>
<DIV> It can call perl functions from extensions.conf in a special package called Asterisk::Perl.<BR> that is loaded on startup from /etc/asterisk/Asterisk::Perl.pm.</DIV>
<DIV> </DIV>
<DIV> exten => 1,1,Perl,myfunc:arg_1:arg_2:arg_n......</DIV>
<DIV> </DIV>
<DIV> It then does it's business and returns one or more special directives that<BR> are asterisk related operations processed by the module.<BR> they are returned as a list (array) of scalar each containing a specially formated<BR> command to feed back into asterisk via the C module.</DIV>
<DIV> </DIV>
<DIV> These are counterparts to the real directives found in extensions.conf only probably<BR> there is less error checking and more direct control a.k.a. likelyhood to crash.</DIV>
<DIV> </DIV>
<DIV><BR> Valid commands so far.......</DIV>
<DIV> </DIV>
<DIV> setvar:<name>:<value><BR> goto:<ext>|<line><BR> add_ext:<context>:<replace>:<extension>:<priority>:<application>:<data>:<callerid><BR> runapp:<app>:<data><BR> include:<new_context>:<existing_context><BR> ignorepat:<context>:<name><BR> switch:<context>:<app>:<data></DIV>
<DIV> </DIV>
<DIV><BR> There are also some special commands: (1 for now)</DIV>
<DIV> </DIV>
<DIV> thread:<function><BR> This will spin off a thread with the perl sub you specify running inside it.<BR> the sub will get 1 scalar arg being the number of times it was run (starting with 1)<BR> you can return an array full of more commands listed above with 1 exception:<BR> if you put the keyword "loop" in the list, it will call the function again and increment the counter arg.<BR> You can use this to say run 1 thread to listen on a tcp port and populate a shared data object<BR> and use another to run in a loop and pass the altered data back to asterisk and relaunch<BR> every 1 min or so. And of core all this stuff can be used to horribly
crash the program.</DIV>
<DIV> </DIV>
<DIV> The function can return as many commands as it wants but of corse several goto or other such nonsense<BR> may not be too smart.</DIV>
<DIV> </DIV>
<DIV><BR> The functions startup() and shutdown() are called respectively on load and unload of the module<BR> allowing you to create on the fly contexts and configuration by looking up data from a database,more files etc.<BR> you can even make the dialing of a certian extension cause a perl func to create more extensions or to<BR> rewrite the existing one on the fly. Of course, you can't do any channel related commands (runapp etc)<BR> from the startup function because there is no call in progress so they get ignored.</DIV>
<DIV> </DIV>
<DIV><BR>BUGS:</DIV>
<DIV> </DIV>
<DIV> If you stare at the source code from about 2 feet back for approx 30 seconds you will start<BR> to see that the entire thing is in itself 1 large bug. I am not a C programmer but rather<BR> a Perl programmer so that was my motivation for this idea but it probably is sucky C style etc...</DIV>
<DIV> </DIV>
<DIV><BR></FONT><FONT size=3> </FONT></DIV></FONT></DIV></DIV><p><hr SIZE=1>
Do you Yahoo!?<br>
<a href="http://pa.yahoo.com/*http://rd.yahoo.com/evt=1207/*http://promo.yahoo.com/sbc/">SBC Yahoo! DSL</a> - Now only $29.95 per month!