cleanup job name and owner description
[safeq] / terminal-emulator.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use Data::Dump qw(dump);
6
7 use IO::Socket::INET;
8
9 my $ip   = shift @ARGV || '127.0.0.1';
10 my $port = shift @ARGV || 4096;
11
12 my $socket = IO::Socket::INET->new(
13         PeerAddr => $ip,
14         PeerPort => $port,
15         Proto => 'tcp',
16 ) or die "ERROR $ip:$port - $!";
17
18 warn "# connected to $ip:$port\n";
19
20 my @send_receive = grep { /^.+$/ } split(/\n/, q{
21 .SQ 3.2.9 SQPR8463332F62E
22 .SQ OK
23
24 .CFG gd lang=HR
25 .CFG OK %s
26
27 .SERVER LIST
28 .ERROR NO-ENTERPRISE
29
30 .CARD E009000000009999
31 .CARD OK Ime Prezime (nobody@example.com)
32
33 .ACTION
34 .ACTION CMENUS
35
36 .NOP
37 .NOP
38
39 .NOP
40 .NOP
41
42 .END
43 });
44
45 #warn "# send_receive=",dump( \@send_receive );
46
47 while ( @send_receive ) {
48         my $send   = shift @send_receive;
49         my $expect = shift @send_receive;
50         warn ">> $send\n";
51         print $socket "$send\r\n";
52         my $got = <$socket>;
53         $got =~ s/[\r\n]+$//;
54 warn "# send/expect/got ",dump($send,$expect,$got);
55         warn "<< $got\n";
56         if ( defined $got && defined $expect && $expect ne substr($got,0,length($expect)) ) {
57                 warn "ERROR expected [$expect] got [$got]\n";
58                 print "Response>";
59                 my $r = <STDIN>; chomp $r;
60                 print $socket "$r\r\n";
61         }
62
63 }
64
65 $socket->close();