Import Upstream version 0.0.7.1 upstream/0.0.7.1
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Fri, 11 Aug 2017 22:35:25 +0000 (19:35 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Fri, 11 Aug 2017 22:35:25 +0000 (19:35 -0300)
INSTALL
META.yml
Makefile.PL
README
sendxmpp

diff --git a/INSTALL b/INSTALL
index 08e77a1..3add5de 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -4,9 +4,13 @@ sendxmpp requires perl 5.x, Getopt::Long and Net::XMPP.
 
 $ tar xvfz sendxmpp-(version).tar.gz
 $ cd sendxmpp-(version)
-$ perl Makefile.pm
+$ perl Makefile.PL
 $ make
 $ make install
 
+This will install under /usr/local; to install under another prefix, for exampl;e "/usr", do:
 
+$ perl Makefile.PL PREFIX=/usr
+
+instead.
 
index 1eeca68..3e2695b 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,7 +1,7 @@
 # http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         sendxmpp
-version:      0.0.5
+version:      0.0.7.1
 version_from: sendxmpp
 installdirs:  site
 requires:
index 46a74a8..1cfca54 100644 (file)
@@ -2,6 +2,12 @@
 
 use ExtUtils::MakeMaker;
 
+# do this so we default to install to /usr/local, unless
+# PREFIX is provided, ie.:
+# perl Makefile.pl PREFIX=/usr
+$ENV{'PREFIX'}='/usr/local/' unless ($ENV{'PREFIX'});
+
+
 WriteMakefile (NAME => 'sendxmpp',
               AUTHOR => 'Dirk-Jan C. Binnema (djcb@djcbsoftware.nl)',
               ABSTRACT => 'Script for sending xmpp messages',
diff --git a/README b/README
index 939ec3d..357e9d9 100644 (file)
--- a/README
+++ b/README
@@ -16,7 +16,7 @@ Obviously, you also need a jabber account; they are freely available
 at jabber.org, but you can also install your own servers.
 
 sendxmpp is already in use for monitoring remote servers (servers can
-warn by sending xmmp-messages), and watching CVS commit messages
+warn by sending xmpp-messages), and watching CVS commit messages
 (developers are all connected to a XMPP-chatroom to which messages are
 sent. 
 
index 10bc604..0c9452e 100755 (executable)
--- a/sendxmpp
+++ b/sendxmpp
@@ -1,22 +1,22 @@
 #!/usr/bin/perl -w
 #-*-mode:perl-*-
-#Time-stamp: <2004-12-01 14:52:47 (djcb)>
+#Time-stamp: <2005-05-02 01:00:02 (djcb)>
 
 # script to send message using xmpp (aka jabber), 
 #   somewhat resembling mail(1)
 
-# author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
-# copyright (c) 2004, Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
-#
-# released under the terms of the GNU General Public License v2
+# Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+# Copyright (c) 2004,2005 Dirk-Jan C. Binnema
+
+# Released under the terms of the GNU General Public License v2
 
 use Net::XMPP;
 use Getopt::Long;
 use strict;
 
-
 # subroutines decls
 sub xmpp_login($$$$$$);
+sub xmpp_send ($$$);
 sub xmpp_send_message($$$$);
 sub xmpp_send_chatroom_message($$$$$);
 sub xmpp_logout($);
@@ -26,20 +26,18 @@ sub error_exit;
 sub debug_print;
 sub read_config_file($);
 sub push_hash($$);
-sub main ();
-
+sub terminate();
+sub main();
 
 my # MakeMaker
-$VERSION     = '0.0.5';
+$VERSION     = '0.0.7.1';
 my $RESOURCE = 'sendxmpp';
 my $VERBOSE  = 0;
 my $DEBUG    = 0;
-
             
 # start!
 &main;
 
-
 #
 # main: main routine
 #
@@ -47,9 +45,11 @@ sub main () {
 
     my $cmdline = parse_cmdline();
     
+    $| = 1; # no output buffering
+
     $DEBUG   = 1 if ($$cmdline{'debug'});
     $VERBOSE = 1 if ($$cmdline{'verbose'});
-
+    
     my $config = read_config_file ($$cmdline{'file'})
        unless ($$cmdline{'jserver'} && $$cmdline{'username'} && $$cmdline{'password'});        
     
@@ -60,27 +60,46 @@ sub main () {
                           $$cmdline{'resource'},
                           $$cmdline{'tls'},
                           $$cmdline{'debug'})
-       or error_exit("cannot login: $!");
+      or error_exit("cannot login: $!");
     
+   
+    # read message from STDIN or or from -m/--message parameter
+    if (!$$cmdline{interactive}) {
+       
+       # the non-interactive case
+       my $txt;
+       my $message = $$cmdline{'message'}; 
+       if ($message) {
+           open (MSG, "<$message")
+             or error_exit ("cannot open message file '$message': $!");
+           while (<MSG>) {$txt.=$_};
+           close(MSG);
+       }  else  {
+           $txt.=$_ while (<STDIN>);
+       }
+       
+       xmpp_send ($cnx,$cmdline,$txt);
     
-    unless ($$cmdline{'chatroom'}) {
-       xmpp_send_message ($cnx,
-                          $$cmdline{'recipient'},
-                          $$cmdline{'subject'},
-                          $$cmdline{'message'});
     } else {
-       xmpp_send_chatroom_message ($cnx,
-                                $$cmdline{'resource'},
-                                $$cmdline{'subject'},
-                                $$cmdline{'recipient'},
-                                $$cmdline{'message'});
+       # the interactive case, read stdin line by line
+
+       # deal with TERM
+       $main::CNX = $cnx;  
+       $SIG{INT}=\&terminate;
+
+       # line by line...
+       while (<STDIN>) {
+           chomp;
+           xmpp_send ($cnx,$cmdline,$_);
+       }
     }
 
     xmpp_logout($cnx);
-    exit(0);
+    exit 0;
 }
 
 
+
 #
 # read_config_file: read the configuration file
 # input: filename
@@ -94,13 +113,13 @@ sub read_config_file ($) {
        unless (-r $cfg_file);    
     my $owner  = (stat($cfg_file))[4];
     error_exit ("you must own $cfg_file")
-       unless ($owner == $>); 
+      unless ($owner == $>); 
     my $mode = (stat($cfg_file))[2] & 07777;
     error_exit ("$cfg_file must have mode 0600")
-       unless ($mode == 0600);
+      unless ($mode == 0600);
     
     open (CFG,"<$cfg_file")
-       or error_exit("cannot open $cfg_file for reading: $!");
+      or error_exit("cannot open $cfg_file for reading: $!");
 
     my %config;
     my $line = 0;
@@ -114,27 +133,26 @@ sub read_config_file ($) {
        s/\#.*$//; # ignore comments in lines
        
        if (/([-\.\w]+)@([-\.\w]+)\s+(\S+)\s*$/) {
-           %config = ('username'=>$1,
-                      'jserver'=>$2, 
-                      'password'=>$3);
-
+           %config = ('username' => $1,
+                      'jserver'  => $2, 
+                      'password' => $3);
        } else {
-           close(CFG);
+           close CFG;
            error_exit ("syntax error in line $line of $cfg_file");
        }
     }
-
-    close(CFG);
+    
+    close CFG;
     
     error_exit ("no correct config found in $cfg_file") 
-       unless (scalar(%config));       
+      unless (scalar(%config));       
 
     if ($DEBUG || $VERBOSE) {
        while (my ($key,$val) = each %config) {
            debug_print ("config: '$key' => '$val'");
        }
     }      
-
+    
     return \%config;              
 }
 
@@ -146,10 +164,10 @@ sub read_config_file ($) {
 #
 sub parse_cmdline () {
     
-   usage() unless (scalar(@ARGV));
-           
+    usage() unless (scalar(@ARGV));
+    
     my ($subject,$file,$resource,$jserver,$username,$password,
-       $message,$chatroom,$debug,$tls,$help,$verbose);
+       $message,$chatroom,$debug,$tls,$interactive,$help,$verbose);
     my $res = GetOptions ('subject|s=s'    => \$subject,
                          'file|f=s'       => \$file,
                          'resource|r=s'   => \$resource,
@@ -159,38 +177,32 @@ sub parse_cmdline () {
                          'message|m=s'    => \$message,
                          'chatroom|c'     => \$chatroom,
                          'tls|t'          => \$tls,
+                         'interactive|i'  => \$interactive,
                          'help|usage|h'   => \$help,
                          'debug|d'        => \$debug,
                          'verbose|v'      => \$verbose);
     usage () 
-       if ($help);   
-   
-    my $rcpt = $ARGV[0]
-       or error_exit("no recipient specified");
-
-    # read message from STDIN or or from -m/--message parameter
-    my $txt;
-    if ($message) {
-       open (MSG, "<$message")
-           or error_exit ("cannot open message file '$message': $!");
-       while (<MSG>) {$txt.=$_};
-       close(MSG);
-    } else {
-       while (<STDIN>) {$txt.=$_};
-    }
+      if ($help);   
     
-    my %dict = ('subject'    => ($subject  or ''),
-               'resource'   => ($resource or $RESOURCE),
-               'jserver'    => ($jserver or ''),
-               'username'   => ($username or ''),
-               'password'   => ($password or ''),
-               'chatroom'   => ($chatroom or 0),
-               'tls'        => ($tls or 0),
-               'debug'      => ($debug or 0),
-               'message'    => ($txt or ''),
-               'verbose'    => ($verbose or 0),
-               'file'       => ($file or ($ENV{'HOME'}.'/.sendxmpprc')),
-               'recipient'  => $rcpt);
+    my $rcpt = $ARGV[0]
+      or error_exit "no recipient specified";
+   if ($message && $interactive) {
+       error_exit "cannot have both -m (--message) and -i (--interactive)\n";
+   } 
+       
+    my %dict = ('subject'     => ($subject  or ''),
+               'resource'    => ($resource or $RESOURCE),
+               'jserver'     => ($jserver or ''),
+               'username'    => ($username or ''),
+               'password'    => ($password or ''),
+               'chatroom'    => ($chatroom or 0),
+               'interactive' => ($interactive or 0),
+               'tls'         => ($tls or 0),
+               'debug'       => ($debug or 0),
+               'verbose'     => ($verbose or 0),
+               'file'        => ($file or ($ENV{'HOME'}.'/.sendxmpprc')),
+               'recipient'   => $rcpt);
 
    if ($DEBUG || $VERBOSE) {
        while (my ($key,$val) = each %dict) {
@@ -202,9 +214,8 @@ sub parse_cmdline () {
 }
 
 
-
 #
-# xmpp_login: login to the xmmp (jabber) server
+# xmpp_login: login to the xmpp (jabber) server
 # input: hostname,username,password,resource,tls,debug
 # output: an XMPP connection object
 #
@@ -212,28 +223,51 @@ sub xmpp_login ($$$$$$) {
 
     my ($host,$user,$pw,$res,$tls,$debug) = @_;
     my $cnx = new Net::XMPP::Client(debuglevel=>($debug?2:0));
-    error_exit ("could not create XMPP client object: $!")
+    error_exit "could not create XMPP client object: $!"
        unless ($cnx);    
 
     my @res = $cnx->Connect(hostname=>$host,tls=>$tls);
     xmpp_check_result("Connect",\@res,$cnx);
 
     
-    @res = $cnx->AuthSend('hostname'=>$host,
-                         'username'=>$user,
-                         'password'=>$pw,
-                         'resource'=>$res);
+    @res = $cnx->AuthSend('hostname' => $host,
+                         'username' => $user,
+                         'password' => $pw,
+                         'resource' => $res);
     xmpp_check_result('AuthSend',\@res,$cnx);
-        
-    #@res = $cnx->PresenceSend(type=>'unavailable');
-    #mpp_check_result("PresenceSend",\@res,$cnx);
     
     return $cnx;    
 }
 
 
+
+
 #
-# xmmp_send_message: send a message to some xmmp user
+# xmmp_send: send the message, determine from cmdline
+# whether it's to individual or chatroom
+#
+sub xmpp_send ($$$) {
+    
+    my ($cnx, $cmdline, $txt) = @_;
+    
+    unless ($$cmdline{'chatroom'}) {
+       xmpp_send_message ($cnx,
+                          $$cmdline{'recipient'},
+                          $$cmdline{'subject'},
+                          $txt);
+    } else {
+       xmpp_send_chatroom_message ($cnx,
+                                   $$cmdline{'resource'},
+                                   $$cmdline{'subject'},
+                                   $$cmdline{'recipient'},
+                                   $txt);
+    }
+}
+
+
+
+#
+# xmpp_send_message: send a message to some xmpp user
 # input: connection,recipient,subject,msg
 #
 sub xmpp_send_message ($$$$) {
@@ -241,9 +275,9 @@ sub xmpp_send_message ($$$$) {
     my ($cnx,$rcpt,$subject,$msg) = @_;
  
     # for some reason, MessageSend does not return anything
-    $cnx->MessageSend('to'=>$rcpt,
-                     'subject'=>$subject,
-                     'body'=>$msg);
+    $cnx->MessageSend('to'      => $rcpt,
+                     'subject' => $subject,
+                     'body'    => $msg);
     
     xmpp_check_result('MessageSend',0,$cnx);
 }
@@ -265,10 +299,10 @@ sub xmpp_send_chatroom_message ($$$$$) {
 
     # create/send the message
     my $groupmsg = new Net::XMPP::Message;
-    $groupmsg->SetMessage(to=>$rcpt, 
-                         body=>$msg,
-                         subject=>$subject,
-                         type=>'groupchat');
+    $groupmsg->SetMessage(to      => $rcpt, 
+                         body    => $msg,
+                         subject => $subject,
+                         type    => 'groupchat');
 
     $res = $cnx->Send($groupmsg);
     xmpp_check_result ('Send',$res,$cnx); 
@@ -279,7 +313,7 @@ sub xmpp_send_chatroom_message ($$$$$) {
 
 
 #
-# xmmp_logout: log out from the xmpp server
+# xmpp_logout: log out from the xmpp server
 # input: connection
 #
 sub xmpp_logout($) {
@@ -320,12 +354,22 @@ sub xmpp_check_result {
 }
 
 
+#
+# terminate; exit the program upon TERM sig reception
+#
+sub terminate () {
+    debug_print "caught TERM";
+    xmpp_logout($main::CNX);
+    exit 0;
+}
+
+
 #
 # debug_print: print the data if defined and DEBUG || VERBOSE is TRUE
 # input: [array of strings]
 #
 sub debug_print {
-    print STDERR "sendxmpp: " . (join ' ',@_) . "\n"
+    print STDERR "sendxmpp: " . (join ' ', @_) . "\n"
        if (@_ && ($DEBUG ||$VERBOSE));
 }
 
@@ -351,8 +395,8 @@ sub error_exit {
 #
 sub usage () {
    
-    print 
-       "sendxmpp version $VERSION, (c) 2004 Dirk-Jan C. Binnema\n" .
+    print STDERR 
+       "sendxmpp version $VERSION, Copyright (c) 2004,2005 Dirk-Jan C. Binnema\n" .
        "usage: sendxmpp [options] <recipient>\n" .
        "or refer to the the sendxmpp manpage\n";
     
@@ -360,10 +404,10 @@ sub usage () {
 }
 
 
-
 #
 # the fine manual
 #
+=pod
 =head1 NAME
 
 sendxmpp - send xmpp messages from the commandline.
@@ -377,9 +421,6 @@ sendxmpp [options] <recipient>
 sendxmpp is a program to send XMPP (Jabber) messages from the commandline, not
 unlike L<mail(1)>. Messages can be sent both to individual recipients and chatrooms.
 
-the recipient is either another jabber-account or a jabber-chatroom (use '-c' to tell 
-sendxmpp it's a chatroom)
-
 =head1 OPTIONS
 
 B<-f>,B<--file> <file>
@@ -410,6 +451,9 @@ this will set the subject for the chatroom
 B<-m>,B<--message> <message>
 read the message from <message> (a file) instead of stdin
 
+B<-i>,B<--interactive>
+work in interactive mode, reading lines from stdin and sending the one-at-time
+
 B<-v>,B<--verbose>
 give verbose output about what is happening
 
@@ -422,7 +466,7 @@ show debugging info while running. B<WARNING>: This will include passwords etc.
 =head1 CONFIGURATION FILE
 
 You may define a '~/.sendxmpprc' file with the necessary data for your 
-xmmp-account, with a line of the format:
+xmpp-account, with a line of the format:
 
    <user>@<host> <password>
 
@@ -450,15 +494,11 @@ Documentation for the L<Net::XMPP> module
 
 The jabber homepage: http://www.jabber.org/
 
-The sendxmpp homepage: http://www.djcbsoftware.nl/code/sendxmmp (the xmmp homepage)
+The sendxmpp homepage: http://www.djcbsoftware.nl/code/sendxmpp
 
 =head1 AUTHOR
 
-sendxmpp has been written by Dirk-Jan C. Binnema <dirk-jan@djcbsoftware.nl>, and uses
+sendxmpp has been written by Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>, and uses
 the L<Net::XMPP> modules written by Ryan Eatmon.
 
 =cut
-
-
-
-