[Freeswitch-svn] [commit] r3468 - in freeswitch/branches/igorneves/scripts: . socket

Freeswitch SVN igorneves at freeswitch.org
Tue Nov 28 14:07:24 EST 2006


Author: igorneves
Date: Tue Nov 28 14:07:23 2006
New Revision: 3468

Added:
   freeswitch/branches/igorneves/scripts/
   freeswitch/branches/igorneves/scripts/socket/
   freeswitch/branches/igorneves/scripts/socket/fs.pl

Log:
some new updates to fs.pl, improves usability

Added: freeswitch/branches/igorneves/scripts/socket/fs.pl
==============================================================================
--- (empty file)
+++ freeswitch/branches/igorneves/scripts/socket/fs.pl	Tue Nov 28 14:07:23 2006
@@ -0,0 +1,75 @@
+use FreeSWITCH::Client;
+use Data::Dumper;
+use Sys::Hostname;
+use Term::ReadLine;
+
+my $password = "ClueCon";
+
+$HISTFILE = ($ENV{HOME} || ((getpwuid($<))[7])) . "/.fs_history";
+$HISTSIZE = 256;
+
+my $fs = init FreeSWITCH::Client {-password => $password} or die "Error $@";
+my $term = new Term::ReadLine "FreeSWITCH CLI";
+my $prompt = hostname.">";
+my $OUT = $term->OUT .. \*STDOUT;
+
+my $log = shift;
+
+$term->stifle_history($HISTSIZE);
+if (-f $HISTFILE) {
+   $term->ReadHistory($HISTFILE)
+     or warn "cannot read history file: $!\n";
+}
+
+$SIG{CHLD} = sub {$fs->disconnect(); die "done"};
+
+if ($log) {
+  $pid = fork;
+  if (!$pid) {
+    my $fs2 = init FreeSWITCH::Client {-password => $password} or die "Error $@";
+    
+
+    $fs2->cmd({ command => "log $log" });
+    while (1) {
+      my $reply = $fs2->readhash(undef);
+      if ($reply->{socketerror}) {
+	die "socket error";
+      }
+      if ($reply->{body}) {
+	print $reply->{body} . "\n";
+      } elsif ($reply->{'reply-text'}) {
+	print $reply->{'reply-text'} . "\n";
+      }
+    }
+    exit;
+  }
+
+}
+
+
+
+while ( defined ($_ = $term->readline($prompt)) ) {
+  my $reply;
+
+  if ($_) {
+    my $reply = $fs->cmd({command => "api $_"});
+    if ($reply->{socketerror}) {
+      $fs2->disconnect();
+      die "socket error";
+    }
+    if ($reply->{body}) {
+      print $reply->{body};
+    } elsif ($reply->{'reply-text'}) {
+      print $reply->{'reply-text'};
+    }
+    print "\n";
+    if ($_ =~ /exit/) {
+      last;
+    }
+  }
+  $term->addhistory($_) if /\S/;
+  $term->write_history($HISTFILE)
+    or warn "cannot write history file: $!\n";
+
+}
+  



More information about the Freeswitch-svn mailing list