mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 01:26:58 +00:00
Change the socket protocol and the sample client to use multiline input
valid input: ------------------------- <command>[ <args>] ------------------------- or ------------------------- <command>[ <args>] Header1: Val HeaderN: Val ------------------------- git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2109 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -89,7 +89,7 @@ sub output($$) {
|
||||
my ($self,$data) = @_;
|
||||
my $s = $self->{_sock};
|
||||
|
||||
print $s $data;
|
||||
print $s $data ;
|
||||
}
|
||||
|
||||
sub cmd($$$) {
|
||||
@@ -97,12 +97,26 @@ sub cmd($$$) {
|
||||
my $cmd = shift;
|
||||
my $to = shift;
|
||||
|
||||
$self->output($cmd);
|
||||
$self->output($cmd->{command});
|
||||
foreach(keys %{$cmd}) {
|
||||
next if ($_ eq "command");
|
||||
$self->output($cmd->{$_});
|
||||
}
|
||||
$self->output("\n\n");
|
||||
|
||||
my $h = $self->readhash($to);
|
||||
|
||||
$h;
|
||||
}
|
||||
|
||||
sub disconnect($) {
|
||||
my $self = shift;
|
||||
$self->{_sock}->shutdown(2);
|
||||
$self->{_sock}->close();
|
||||
undef $self->{_sock};
|
||||
delete $self->{_sock};
|
||||
}
|
||||
|
||||
sub connect($) {
|
||||
my $self = shift;
|
||||
|
||||
@@ -120,8 +134,7 @@ sub connect($) {
|
||||
|
||||
if ($h->{"content-type"} eq "auth/request") {
|
||||
my $pass = $self->{"_password"};
|
||||
$self->output("auth $pass");
|
||||
$h = $self->readhash(undef);
|
||||
$h = $self->cmd({command => "auth $pass"});
|
||||
}
|
||||
|
||||
if ($h->{'reply-text'} =~ "OK") {
|
||||
|
@@ -11,21 +11,29 @@ my $OUT = $term->OUT .. \*STDOUT;
|
||||
|
||||
my $log = shift;
|
||||
|
||||
$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("log $log");
|
||||
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +42,11 @@ while ( defined ($_ = $term->readline($prompt)) ) {
|
||||
my $reply;
|
||||
|
||||
if ($_) {
|
||||
my $reply = $fs->cmd("api $_");
|
||||
|
||||
my $reply = $fs->cmd({command => "api $_"});
|
||||
if ($reply->{socketerror}) {
|
||||
$fs2->disconnect();
|
||||
die "socket error";
|
||||
}
|
||||
if ($reply->{body}) {
|
||||
print $reply->{body};
|
||||
} elsif ($reply->{'reply-text'}) {
|
||||
|
Reference in New Issue
Block a user