[JDEV] Help with Net::Jabber problem
g
jdev at graham.globalcloud.net
Wed Sep 18 14:34:05 CDT 2002
Here is the directory structure (I installed it via interactive cpan)
All the files appear to be installed correctly.
-r--r--r-- 1 root root 43913 Jun 11 22:56
/usr/lib/perl5/site_perl/5.6.0/Net/Jabber.pm
/usr/lib/perl5/site_perl/5.6.0/Net/Jabber:
total 536
-r--r--r-- 1 root root 7739 Jun 11 22:56 Client.pm
-r--r--r-- 1 root root 15092 Jun 11 22:56 Component.pm
-r--r--r-- 1 root root 13837 Jun 11 22:56 Data.pm
-r--r--r-- 1 root root 9526 Jun 11 22:56 Debug.pm
drwxr-xr-x 2 root root 4096 Sep 18 11:38 Dialback
-r--r--r-- 1 root root 3351 Jun 11 22:56 Dialback.pm
-r--r--r-- 1 root root 11583 Jun 11 22:56 IQ.pm
-r--r--r-- 1 root root 9707 Jun 11 22:56 JID.pm
-r--r--r-- 1 root root 5002 Jun 11 22:56 Key.pm
-r--r--r-- 1 root root 8980 Jun 11 22:56 Log.pm
-r--r--r-- 1 root root 15885 Jun 11 22:56 Message.pm
-r--r--r-- 1 root root 17069 May 9 2001 Namespaces.pm
-r--r--r-- 1 root root 12047 Jun 11 22:56 Presence.pm
-r--r--r-- 1 root root 114841 Sep 18 12:49 Protocol.pm
-r--r--r-- 1 root root 78288 Jun 11 22:56 Query.pm
-r--r--r-- 1 root root 9153 Jun 11 22:56 Server.pm
-r--r--r-- 1 root root 12785 Jun 11 22:56 XDB.pm
-r--r--r-- 1 root root 30970 Jun 11 22:56 X.pm
/usr/lib/perl5/site_perl/5.6.0/Net/Jabber/Dialback:
total 16
-r-xr-xr-x 1 root root 6924 Jun 11 22:56 Result.pm
-r--r--r-- 1 root root 7418 Jun 11 22:56 Verify.pm
And the example code from DJ Adams "Fun with Jabber:
A More Sensitive Mail Notifier"
from http://www.pipetree.com/jabber/extended_notify.html
I changed Adams'
use Net::Jabber
to
use Net::Jabber::Client;
use Net::Jabber::Protocol;
use Net::Jabber::Debug;
use Net::Jabber::IQ;
because I received the error "Failed to load any schema for
Net::Jabber from the use line."
(RECIPIENT and SERVER constants were also modified)
Here's the code
#!/usr/bin/perl -w
# notify.pl
# Version 2
# Email notification script to Jabber client
# Only send notification if recipient is willing to receive
use Mail::Internet;
use Net::Jabber::Client;
use Net::Jabber::Protocol;
use Net::Jabber::Debug;
use Net::Jabber::IQ;
# Hash to hold presence info received from Jabber server
# ------------------------------------------------------
use vars qw/%presence/;
# Declare our constants
# ---------------------
use constant RECIPIENT => 'a-user at some.place'; # Jabber ID to be
notified
use constant SERVER => 'a.host.name'; # Jabber server to
connect to
use constant PORT => 5222; # Port to connect to
use constant USER => 'notify'; # user this script connects as
use constant PASSWORD => 'notify'; # password associated with USER
use constant RESOURCE => 'perl';
# Read and parse email and extract header info
# --------------------------------------------
my $header = Mail::Internet->new(*STDIN)->head()->header_hashref();
chomp $header->{$_}[0] foreach keys(%{$header});
# Create a new Jabber client and connect
# --------------------------------------
my $connection = Net::Jabber::Client->new();
$connection->Connect( "hostname" => SERVER,
"port" => PORT )
or die "Cannot connect ($!)\n";
# Identify and authenticate with the server
# -----------------------------------------
my @result = $connection->AuthSend( "username" => USER,
"password" => PASSWORD,
"resource" => RESOURCE );
if ($result[0] ne "ok") {
die "Ident/Auth with server failed: $result[0] - $result[1]\n";
}
# Set presence callback
# ---------------------
$connection->SetCallBacks( "presence" => \&handle_presence );
# Send our presence
# -----------------
$connection->PresenceSend();
# Wait for data
# -------------
die "Uh-oh - something has gone wrong with the connection\n"
unless(defined($connection->Process(2)));
# Send notification only if appropriate
# -------------------------------------
my $r = RECIPIENT;
if ($presence{$r} =~ /(normal|chat)/) {
# Create a message and build it up
# --------------------------------
my $msg = Net::Jabber::Message->new();
$msg->SetMessage( "to" => RECIPIENT,
"subject" => "Email from $header->{From}[0]",
"body" => join("\n", "Subject:
$header->{Subject}[0]",
"Date: $header->{Date}[0]") );
# Send the message
# ----------------
$connection->Send($msg);
}
# Disconnect from the Jabber server
# ---------------------------------
$connection->Disconnect();
exit;
# Presence data handler
# ---------------------
sub handle_presence {
my $presence = Net::Jabber::Presence->new(@_);
my $jid = $presence->GetFrom();
$jid =~ s!\/.*$!!; # remove any resource suffix from JID
$presence{$jid} = $presence->GetShow() || 'normal';
}
Chris Wilkes wrote:
>On Wed, Sep 18, 2002 at 01:08:31PM -0400, g wrote:
>
>
>>With the follwing files:
>>Net::Jabber::Protocol VERSION 1.26
>>Net::Jabber::IQ VERSION 1.26
>>
>>I am getting the following error:
>>Undefined subroutine &Net::Jabber::IQ called at
>>/usr/lib/perl5/site_perl/5.6.0/Net/Jabber/Protocol.pm line 1829.
>>
>>
>
>Can you post your code? Also is there a IQ.pm file in the above
>directory?
>
>Chris
>_______________________________________________
>jdev mailing list
>jdev at jabber.org
>http://mailman.jabber.org/listinfo/jdev
>
>
More information about the JDev
mailing list