X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Xchat%2FXPI%2FNet.pm;h=d4823a82b622e01037ed6c0374e8f69f3d1a5999;hb=7e00cc69db0ee7a4379b5378f1673efc4b531ae8;hp=9c83b14594c253cb2c4c90da880027972dc8aed0;hpb=5348c2908f450bcbe36e5ec2bf6be4eab21df021;p=perl%2Fscripts%2Fxchat.git diff --git a/Xchat/XPI/Net.pm b/Xchat/XPI/Net.pm index 9c83b14..d4823a8 100644 --- a/Xchat/XPI/Net.pm +++ b/Xchat/XPI/Net.pm @@ -3,12 +3,15 @@ package Xchat::XPI::Net; use strict; use warnings; +use Xchat qw<:all>; + +use lib get_info 'xchatdir'; +use Xchat::XPI::Utils qw; + use IO::Socket::INET; use Net::DNS; -use Xchat qw<:all>; - our $VERSION = '0.03'; my $res; @@ -32,10 +35,12 @@ sub resolve { return unless $sock; $sock->autoflush(1); - return Xchat::hook_fd($sock, \&_dns_recv, { - flags => FD_READ, - data => [ $callback, $args ], - }); + return called_from_script { + Xchat::hook_fd($sock, \&_dns_recv, { + flags => FD_READ, + data => [ $callback, $args ], + }); + } } sub _dns_recv { @@ -62,16 +67,21 @@ my %whois_servers = ( ipv6 => { default => 'whois.6bone.net' }, ); +my $ipv4_rx = qr/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/; +my $ipv6_rx = qr/[0-9:]+/; + sub whois { my ($host, $callback, $args) = @_; return unless $host and $callback; my $server; - if ($host =~ /^\s*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\/\d{1,2})?$/) { + if ($host =~ /^\s*($ipv4_rx)(?:\/[0-9]{1,2})?[\s\.]*$/o) { + $host = $1; $server = $whois_servers{ipv4}{default}; - } elsif ($host =~ /^\s*[\d:]*(\/\d{1,2})?\s*$/) { + } elsif ($host =~ /^\s*($ipv6_rx)(?:\/[0-9]{1,2})?[\s\.]*$/o) { + $host = $1; $server = $whois_servers{ipv6}{default}; - } elsif ($host =~ /([^\.]+)\.+([a-z]+)\.*$/) { + } elsif ($host =~ /([^\.]+)\.+([a-z]+)[\.\s]*$/) { $host = $1 . '.' . $2; $server = $whois_servers{domain}{$2}; $server = $whois_servers{domain}{default} unless $server; @@ -102,10 +112,12 @@ sub whois { print $sock "$host\x0D\x0A"; $sock->shutdown(1); # stop writing - return Xchat::hook_fd($sock, \&_whois_recv, { - flags => FD_READ, - data => [ $callback, $args ], - }); + return called_from_script { + Xchat::hook_fd($sock, \&_whois_recv, { + flags => FD_READ, + data => [ $callback, $args ], + }); + } } sub _whois_recv {