$debug{$socket} .= $message."\n";
return 1;
}
sub serverclose ($) { #argumen is ref to server connection
my $sck = shift;
debug "Closing Server connection...", $sck;
$sl_read->remove($sck);
$sl_write->remove($sck);
delete $st{$sck};
close $sck;
}
sub clientclose($) { #argumen is ref to client connection
my $sck = shift;
serverclose $st{$sck}{ch} if defined $st{$st{$sck}{ch}};
debug "Closing Client connection...", $sck;
print $debug{$sck};
delete $debug{$sck};
$sl_read->remove($sck);
$sl_write->remove($sck);
delete $st{$sck};
close $sck;
return 1;
}
sub decode_b64 ($) { # taken from MIME::Base64
my $str = shift;
my $res = "";
$str =~ tr|A-Za-z0-9+=/||cd; # remove non-base64 chars
return if (length($str) % 4);
$str =~ s/=+$//; # remove padding
$str =~ tr|A-Za-z0-9+/| -_|; # convert to uuencoded format
while ($str =~ /(.{1,60})/gs) {
my $len = chr(32 + length($1)*3/4); # compute length byte
$res .= unpack("u", $len . $1 ); # uudecode
}
return $res;
}
sub htmlfilter ($) { #argumen is reference to string
my $ref_body = shift;
for my $word (@sensors2) {
$$ref_body =~ s|($word)|<font color=red>$1</font>|ig;
}
return 1;
}
sub showcommand ($) {
my $sck = shift;
my $buffer;
my $byte_read = sysread $sck, $buffer, $max_buffering;
chomp $buffer;
if ($buffer eq "h") {
print <<STOP;
Command:
a - active connection
r - readable handles
w - writeable handles
d - toggle debugging
s - statistics
q - quit
h - this help
STOP
}
elsif ($buffer eq "r") {
for my $hd ($sl_read->handles) {
if ($hd == $mainsocket) {
print " main socket\n";
}
elsif (defined $st{$hd}) {
print " $st{$hd}{peerhost}\n";
}
}
}
elsif ($buffer eq "w") {
for my $hd ($sl_write->handles) {
if (defined $st{$hd}) {
print " $st{$hd}{peerhost}\n";
}
}
}
elsif ($buffer eq "q") {
print "Have a nice day...\n";
exit;
}
elsif ($buffer eq "d") {
$opt_d = $opt_d? 0: 1;
print "debugging: $opt_d\n";
}
elsif ($buffer eq "s") {
}
elsif ($buffer eq "n") {
$non_block = $non_block? 0: 1;
print "non-blocking: $non_block\n";
}
return 1;
}
=7= |