Edit: Apparently Net::XMPP is deprecated. Net::XMPP2 seems to replace it. But Net::XMPP2 is deprecated too. AnyEvent::XMPP replaced it. It seems that new XMPP implementations should use AnyEvent::XMPP.
I've written some sample code to test out Net::XMPP for a cross-platform utility. It works great in Linux. It gives "not-authorized" in Windows.
Using strace, I've grabbed the names of all of the perl modules used in Linux with this script. I've tested to ensure that those modules are all installed in Linux. They all appear to be there.
When testing the code, I'm using the same identical code between Linux and Windows. There is no platform-specific code in it.
It doesn't matter if TLS is 0 or 1. It fails both ways. The XMPP server doesn't require TLS.
Any ideas? I'm lost on this one.
Here's the code:
use strict; use Authen::SASL qw(Perl); use Net::XMPP qw(Client); use Megagram::ResolveSRV; my $VERSION = '0.01'; my $xmpp = Net::XMPP::Client->new(); $xmpp->SetCallBacks(message => \&xmppHandler, presence => \&xmppHandler, iq => \&xmppHandler); my $domain = 'example.com'; my $username = 'bobthebuilder'; my $password = 'yeswecan'; sub xmppConnect { my $rsrv = Megagram::ResolveSRV->new; my @hosts = $rsrv->resolve('_xmpp-server._tcp.'.$domain); unless ($hosts[0]) { print qq($domain doesn't appear to offer XMPP service.\n); return undef; } my $status; foreach my $host (@hosts) { my $target = $host->{target}; my $port = $host->{port}; printf("Attempting to connect to %s:%s\n", $target, $port); $status = $xmpp->Connect(hostname => $target, port => $port, componentname => $domain, tls => 1); last if defined($status); } unless (defined($status)) { print qq(ERROR: XMPP service unavailable: $!\n); return undef; } $xmpp->{STREAM}->{SIDS}->{$xmpp->{SESSION}->{id}}->{hostname} = $dom +ain; my @result = $xmpp->AuthSend(username => $username, password => $password, resource => 'TestClient_'.$VERSION); unless ($result[0] eq 'ok') { print qq(ERROR: Auth failed: $result[0] - $result[1]\n); return undef; } $xmpp->RosterGet(); $xmpp->PresenceSend(status => "Testing."); $xmpp->{presence}->{"$username\@$domain"} = "Testing."; return 1; } sub xmppHandler { my ($sid, $event) = @_; my $type = $event->GetType() || $event->{TREE}->{TAG} || 'unknown'; print qq(XMPP-EVENT: $type\n); use Data::Dumper; print Dumper($event); #runModule(command => '_xmpp_'.$type, sid => $sid, event => $event); } while (1) # process loop { if ($xmpp->Connected()) { xmppConnect() if ($xmpp->Process(1) eq undef); } else { xmppConnect() or die(qq(Can't connect to XMPP.\n)); } sleep(1); }
Edit: TLS info
Edit: FIXED! Changing AuthSend to AuthIQAuth makes it work fine. This disables SASL. TLS will take care of the encryption, though. As long as this doesn't irritate the XMPP server when I lock it down, I'm good to go! Thanks everyone for your help. Here's the updated bit of code that "fixed" it:
my @result = $xmpp->AuthIQAuth(username => $username, password => $password, resource => 'TestClient_'.$VERSION);
In reply to [fixed] Net::XMPP in Win32 gets not-authorized, same code works 100% in Linux by wilsond
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |