+
+sub print_find_reply
+{
+ my ($self, $node, $target, $flag, $ms) = @_;
+ my $sort = $flag == 2 ? "External" : "Local";
+ $self->send("$sort $target found at $node in $ms ms" );
+}
+
+# send the most relevant motd
+sub send_motd
+{
+ my $self = shift;
+ my $motd;
+
+ unless ($self->{registered}) {
+ $motd = "${main::motd}_nor_$self->{lang}";
+ $motd = "${main::motd}_nor" unless -e $motd;
+ }
+ $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd;
+ $motd = $main::motd unless $motd && -e $motd;
+ if ($self->conn->ax25) {
+ if ($motd) {
+ $motd = "${motd}_ax25" if -e "${motd}_ax25";
+ } else {
+ $motd = "${main::motd}_ax25" if -e "${main::motd}_ax25";
+ }
+ }
+ $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 = "";
+ });
+}
+