/usr/share/doc/libnet-jabber-loudmouth-perl/examples/lm-send-async.pl is in libnet-jabber-loudmouth-perl 0.07-2build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #!/usr/bin/perl
use strict;
use warnings;
use Glib qw/TRUE FALSE/;
use Getopt::Std;
use Net::Jabber::Loudmouth;
my %opts;
getopt('supmtnr', \%opts);
if (!$opts{s} || !$opts{m} || !$opts{t} || !$opts{u} || !$opts{p}) {
print STDERR "Usage: $0 -s <server> -u <username> -p <password> -m <message> -t <recipient> [--n <port>] [-r <resource>]\n";
exit 1;
}
{ no warnings 'once';
$opts{n} ||= $Net::Jaber::Loudmouth::DefaultPort; }
$opts{r} ||= 'jabber-send';
my $context = Glib::MainContext->new();
my $connection = Net::Jabber::Loudmouth::Connection->new_with_context($opts{s}, $context);
my $msg_data = {
recipient => $opts{t},
message => $opts{m}
};
my $connection_data = {
username => $opts{u},
password => $opts{p},
resource => $opts{r},
msg_data => $msg_data
};
$connection->open(\&connection_open_result_cb, $connection_data);
my $main_loop = Glib::MainLoop->new($context, FALSE);
$main_loop->run();
sub connection_open_result_cb {
my ($connection, $success, $data) = @_;
unless ($success) {
print STDERR "Connection failed\n";
exit 2;
}
$connection->authenticate($data->{username}, $data->{password}, $data->{resource}, \&connection_auth_cb, $data->{msg_data});
}
sub connection_auth_cb {
my ($connection, $success, $data) = @_;
unless ($success) {
print STDERR "Authentication failed\n";
exit 3;
}
my $m = Net::Jabber::Loudmouth::Message->new($data->{recipient}, 'message');
$m->get_node->add_child('body', $data->{message});
unless ($connection->send($m)) {
print STDERR "Send failed\n";
exit 4;
}
$connection->close();
$main_loop->quit();
}
|