[Chicago-talk] transl. php to perl?

Richard Reina richard at rushlogistics.com
Mon Mar 28 13:17:01 PST 2005


Warren,

Thanks so much for your help thus far.  Forgive for my
ignorance.  But I am confused about exactly how this 
script interfaces with *.  When (and how) do you
execute it so that it coincides with each incoming
phone call?
> 
> I dunno if one exists, but I wrote one that does
> summarily this:
> 
> use Asterisk::AGI;
> use RPC::XML::Client;
> use RPC::XML;
> my $agi = Asterisk::AGI->new();
> my $input = $agi->ReadParse();
> 
> my $clid = $input{callerid}; # caller id
> my $dnid = $input{dnid}; # dialed number id
> 
> my $cli =
> RPC::XML::Client->new('http://my.rpc.server/RPC');
> $cli->send_request(
> 	'call.incoming', RPC_STRING($clid),
> RPC_STRING($dnid));
> 
> 
> Where my.rpc.server provides the method
> call.incoming and does something
> useful with it.
> 
> Hope this helps. (I've done a *lot* of AGI
> development, so if you have
> any other questions (perl-related or not), don't
> hesitate to ask).
> 
> -Warren
> 
> 
> 
> On Mon, 2005-03-28 at 08:02 -0800, Richard Reina
> wrote:
> > --- Warren Smith <warren at warrenandrachel.com>
> wrote:
> > 
> > > Ahh agi. Perhaps you should look for
> Asterisk::AGI.
> > > It does all this
> > > work for you ;). But anyways, here goes...
> > > 
> > 
> > I did but I can't seem to find an AGI command that
> > will pass the called id number to another machine
> on
> > my local network?  Do you know of one?
> > 
> > Thanks for the translation help.
> > 
> > Richard
> > 
> > 
> > > #!/usr/bin/perl
> > > 
> > > use strict;
> > > use warnings;
> > > 
> > > my $debug = 0;
> > > my %agi = ();
> > > 
> > > while(<STDIN>) {
> > > 	chomp; # get a line from stdin and put it into
> $_
> > > 	last unless $_; # exit early if $_ is empty
> > > 	print "read: $_\n" if $debug;
> > > 	my ($var, $value) = split /: /; # split $_ into
> two
> > > parts
> > > 	$var =~ s/^agi_//; # strip off agi_ prefix
> > > 	$value =~ s/\s*(.*?)\s*/$1/; # trim $value
> > > 	$agi{$var} = $value; # save value
> > > }
> > > 
> > > On Mon, 2005-03-28 at 05:24 -0800, Richard Reina
> > > wrote:
> > > > perl is the only language I know, and even
> that is
> > > > debatable.  So any of you know enogh php to
> help
> > > me
> > > > translate the script below? I know which lines
> are
> > > the
> > > > comments that's about it.
> > > > 
> > > > 
> > > > #!/usr/bin/php4 -q
> > > > <?php
> > > > ob_implicit_flush(true);
> > > > set_time_limit(6);
> > > > $in = fopen("php://stdin","r");
> > > > $stdlog =
> fopen("/var/log/asterisk/my_agi.log",
> > > "w");
> > > > // toggle debugging output (more verbose)
> > > > $debug = false;
> > > > // Do function definitions before we start the
> > > main
> > > > loop
> > > > function read() {
> > > > 	global $in, $debug, $stdlog;
> > > > 	$input = str_replace("\n", "", fgets($in,
> 4096));
> > > > 	if ($debug) fputs($stdlog, "read: $input\n");
> > > > 	return $input;
> > > > }
> > > > 				
> > > > // parse agi headers into array
> > > > while ($env=read()) {
> > > > 	$s = split(": ",$env);
> > > > 	$agi[str_replace("agi_","",$s[0])] =
> trim($s[1]);
> > > > 	if (($env == "") || ($env == "\n")) {
> > > > 		break;
> > > > 	}
> > > > }
> > > >
> _______________________________________________
> > > > Chicago-talk mailing list
> > > > Chicago-talk at pm.org
> > > >
> http://mail.pm.org/mailman/listinfo/chicago-talk
> > > > 
> > > 
> > > _______________________________________________
> > > Chicago-talk mailing list
> > > Chicago-talk at pm.org
> > > http://mail.pm.org/mailman/listinfo/chicago-talk
> > > 
> > 
> > _______________________________________________
> > Chicago-talk mailing list
> > Chicago-talk at pm.org
> > http://mail.pm.org/mailman/listinfo/chicago-talk
> > 
> 
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
> 




More information about the Chicago-talk mailing list