X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCommandmode.pm;h=a9777cbf0929b2da31cc5d3b76fa30929e6e55cb;hb=ed2d469812ca5ab82baab7f8b4795660e01ef539;hp=6fde1742b6067b8b3b1d717bfdbe073b51c5c29f;hpb=0efcf0d784c8cdaf1af6ab1db5e23715e5b1476d;p=spider.git diff --git a/perl/DXCommandmode.pm b/perl/DXCommandmode.pm index 6fde1742..a9777cbf 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; @@ -65,7 +69,7 @@ sub new my $pkg = shift; my $call = shift; # my @rout = $main::routeroot->add_user($call, Route::here(1)); - DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1]); + DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1, undef, undef, $self->{conn}->peerhost], ); # ALWAYS output the user my $ref = Route::User::get($call); @@ -89,7 +93,7 @@ sub start my $name = $user->{name}; # log it - my $host = $self->{conn}->{peerhost}; + my $host = $self->{conn}->peerhost; $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport}; $host ||= "unknown"; LogDbg('DXCommand', "$call connected from $host"); @@ -1224,7 +1228,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 +1237,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__