X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCommandmode.pm;h=a27d8d3060b842cd1618c4bbc67c583fc041d2bc;hb=fb8e4bcdc434a78a5fee2837e02401df88623555;hp=87182fc69f08b44218f9f8fb2e9b29251469280d;hpb=ca46fb0822f3998466ffbe4c669271ee2af86859;p=spider.git diff --git a/perl/DXCommandmode.pm b/perl/DXCommandmode.pm index 87182fc6..a27d8d30 100644 --- a/perl/DXCommandmode.pm +++ b/perl/DXCommandmode.pm @@ -13,6 +13,10 @@ package DXCommandmode; @ISA = qw(DXChannel); +use AnyEvent; +use AnyEvent::Handle; +use AnyEvent::Socket; + use POSIX qw(:math_h); use DXUtil; use DXChannel; @@ -32,7 +36,6 @@ use WCY; use Sun; use Internet; use Script; -use Net::Telnet; use QSL; use DB_File; use VE7CC; @@ -1224,7 +1227,7 @@ sub send_motd } $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd; $motd = $main::motd unless $motd && -e $motd; - if ($self->conn->{csort} eq 'ax25') { + if ($self->conn->ax25) { if ($motd) { $motd = "${motd}_ax25" if -e "${motd}_ax25"; } else { @@ -1233,5 +1236,50 @@ sub send_motd } $self->send_file($motd) if -e $motd; } + +sub http_get +{ + my $self = shift; + my ($host, $uri, $cb) = @_; + + # store results here + my ($response, $header, $body); + + my $handle; + $handle = AnyEvent::Handle->new( + connect => [$host => 'http'], + on_error => sub { + $cb->("HTTP/1.0 500 $!"); + $self->anyevent_del($handle); + $handle->destroy; # explicitly destroy handle + }, + on_eof => sub { + $cb->($response, $header, $body); + $self->anyevent_del($handle); + $handle->destroy; # explicitly destroy handle + } + ); + $self->anyevent_add($handle); + $handle->push_write ("GET $uri HTTP/1.0\015\012\015\012"); + + # now fetch response status line + $handle->push_read (line => sub { + my ($handle, $line) = @_; + $response = $line; + }); + + # then the headers + $handle->push_read (line => "\015\012\015\012", sub { + my ($handle, $line) = @_; + $header = $line; + }); + + # and finally handle any remaining data as body + $handle->on_read (sub { + $body .= $_[0]->rbuf; + $_[0]->rbuf = ""; + }); +} + 1; __END__