Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use Net::XMPP;
- use strict;
- =bye
- if ($#ARGV < 4)
- {
- print "\nperl client.pl <server> <port> <username> <password> <resource> \n\n";
- exit(0);
- }
- =cut
- my $server = $ARGV[0] || "hostname";
- my $port = $ARGV[1] || "5222";
- my $username = $ARGV[2] || "username";
- my $password = $ARGV[3] || "pass";
- my $resource = $ARGV[4] || "Test";
- my $verbose = 0;
- $SIG{HUP} = \&Stop;
- $SIG{KILL} = \&Stop;
- $SIG{TERM} = \&Stop;
- $SIG{INT} = \&Stop;
- my $Connection = new Net::XMPP::Client();
- $Connection->SetCallBacks(message=>\&InMessage,
- presence=>\&InPresence,
- iq=>\&InIQ);
- my $status = $Connection->Connect(hostname=>$server,
- port=>$port);
- if (!(defined($status)))
- {
- print "ERROR: Jabber server is down or connection was not allowed.\n";
- print " ($!)\n";
- exit(0);
- }
- my @result = $Connection->AuthSend(username=>$username,
- password=>$password,
- resource=>$resource);
- if ($result[0] ne "ok")
- {
- print "ERROR: Authorization failed: $result[0] - $result[1]\n";
- exit(0);
- }
- if ($verbose){
- print "Logged in to $server:$port...\n";
- }
- $Connection->RosterGet();
- if ($verbose){
- print "Getting Roster to tell server to send presence info...\n";
- }
- $Connection->PresenceSend();
- if ($verbose){
- print "Sending presence to tell world that we are logged in...\n";
- }
- if (defined($Connection->Process())) {
- my $Mess = new Net::XMPP::Message();
- $Mess->SetMessage(
- to => "anderson\@dpgsipcall01.vail",
- subject => "Test",
- body => "this is a test"
- );
- print "sent message\n";
- sleep 1;
- }
- if ($verbose){
- print "ERROR: The connection was killed...\n";
- }
- exit(0);
- sub Stop
- {
- print "Exiting...\n";
- $Connection->Disconnect();
- exit(0);
- }
- sub InMessage
- {
- my $sid = shift;
- my $message = shift;
- my $type = $message->GetType();
- my $fromJID = $message->GetFrom("jid");
- my $from = $fromJID->GetUserID();
- my $resource = $fromJID->GetResource();
- my $subject = $message->GetSubject();
- my $body = $message->GetBody();
- =bye
- print "===\n";
- print "Message ($type)\n";
- print " From: $from ($resource)\n";
- print " Subject: $subject\n";
- print " Body: $body\n";
- print "===\n";
- print $message->GetXML(),"\n";
- print "===\n";
- =cut
- }
- sub InIQ
- {
- my $sid = shift;
- my $iq = shift;
- my $from = $iq->GetFrom();
- my $type = $iq->GetType();
- my $query = $iq->GetQuery();
- my $xmlns = $query->GetXMLNS();
- =bye
- print "===\n";
- print "IQ\n";
- print " From $from\n";
- print " Type: $type\n";
- print " XMLNS: $xmlns";
- print "===\n";
- print $iq->GetXML(),"\n";
- print "===\n";
- =cut
- }
- sub InPresence
- {
- my $sid = shift;
- my $presence = shift;
- my $from = $presence->GetFrom();
- my $type = $presence->GetType();
- my $status = $presence->GetStatus();
- =bye
- print "===\n";
- print "Presence\n";
- print " From $from\n";
- print " Type: $type\n";
- print " Status: $status\n";
- print "===\n";
- print $presence->GetXML(),"\n";
- print "===\n";
- =cut
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement