line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Jabber::SimpleSend; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
33624
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
101
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
23
|
use Carp; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
123
|
|
9
|
1
|
|
|
1
|
|
691
|
use Net::Jabber qw(Client); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA =qw( Exporter ); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( send_jabber_message ); |
13
|
|
|
|
|
|
|
our $VERSION='0.03'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub send_jabber_message { |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $arguments = {}; |
18
|
|
|
|
|
|
|
my $first_argument = shift; |
19
|
|
|
|
|
|
|
if (ref($first_argument)) { |
20
|
|
|
|
|
|
|
$arguments = $first_argument; |
21
|
|
|
|
|
|
|
} else { |
22
|
|
|
|
|
|
|
$arguments->{user} = $first_argument; |
23
|
|
|
|
|
|
|
($arguments->{password},$arguments->{target},$arguments->{subject},$arguments->{message}) = @_; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
for (qw(user password target message subject)) { |
27
|
|
|
|
|
|
|
croak "send_jabber_message requires a $_ argument." unless defined $arguments->{$_}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
croak "The user argument doesnt look like a valid JID." unless ($arguments->{user} =~ m/.*@.*/); |
31
|
|
|
|
|
|
|
croak "The user argument doesnt look like a valid JID." unless (scalar($arguments->{user} =~ m/@/g) == 1); |
32
|
|
|
|
|
|
|
croak "The target argument doesnt look like a valid JID." unless ($arguments->{target} =~ m/.*@.*/); |
33
|
|
|
|
|
|
|
croak "The target argument doesnt look like a valid JID." unless (scalar($arguments->{target} =~ m/@/g) == 1); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my ($username,$hostname) = split /@/,$arguments->{user}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
croak "The user argument doesnt look like a valid JID." unless (length($username)); |
38
|
|
|
|
|
|
|
croak "The user argument doesnt look like a valid JID." unless (length($hostname)); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $jabber_connection = Net::Jabber::Client->new(); |
42
|
|
|
|
|
|
|
$jabber_connection->Connect( 'hostname' => $hostname, |
43
|
|
|
|
|
|
|
'port' => 5222 |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$jabber_connection->AuthSend( 'username' => $username, |
48
|
|
|
|
|
|
|
'password' => $arguments->{password}, |
49
|
|
|
|
|
|
|
'resource' => 'SimpleSend'); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
die "Could not connect to Jabber server" unless ($jabber_connection->Connected()); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#print STDERR "USERNAME : $username , PASSWORD : $arguments->{password}\n"; |
54
|
|
|
|
|
|
|
$jabber_connection->MessageSend( to => $arguments->{target}, |
55
|
|
|
|
|
|
|
subject => $arguments->{subject}, |
56
|
|
|
|
|
|
|
body => $arguments->{message}); |
57
|
|
|
|
|
|
|
$jabber_connection->Process(1); |
58
|
|
|
|
|
|
|
$jabber_connection->Disconnect(); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return 1; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |