- Handle autosave on module unload/irssi exit
[xmlrtorrent.git] / xmlrtorrent / HTTPTalker.pm
index 612d9fc..1254b2d 100644 (file)
@@ -4,11 +4,11 @@
 # licensed under GNU GPL v2
 
 package xmlrtorrent::HTTPTalker;
-use xmlrtorrent::TalkerBase;
-@ISA = qw(xmlrtorrent::TalkerBase);
+use xmlrtorrent::RTorrentTalkerBase;
+@ISA = qw(xmlrtorrent::RTorrentTalkerBase);
 
 use Data::Dumper;
-
+use RPC::XML::Client;
 use strict;
 
 sub new {
@@ -16,6 +16,13 @@ sub new {
     my $self = $class->SUPER::new();
 
     $self->{'NAME'} = 'http';
+    $self->{'DESC'} = 'talker using RPC over HTTP';
+    $self->{'_PARAMS'} = {
+        'XMLURL' => ['', 'URL of SCGI script'],
+        'USERNAME' => ['', 'username for RPC credentials (optional)'],
+        'PASSWORD' => ['', 'password for RPC credentials (optional)'],
+    };
+    $self->{'_LASTXMLURL'} = undef;
 
     bless($self, $class);
 
@@ -24,4 +31,30 @@ sub new {
     return $self;
 }
 
+sub send_request {
+    my $self = shift;
+    my @params = @_;
+
+    my $xmlurl = $self->_getval('XMLURL');
+
+    unless (defined($xmlurl) and $xmlurl ne '') {
+        return 'http talker: XMLURL not set';
+    }
+
+    if ($xmlurl ne $self->{'_LASTXMLURL'}) {
+        $self->{'_LASTXMLURL'} = $xmlurl;
+        $self->{'__RPCClient'} = RPC::XML::Client->new($xmlurl);
+    }  
+    
+    my $username = $self->_getval('USERNAME');
+    my $password = $self->_getval('PASSWORD');
+
+    if (defined $username and defined $password and $username ne '') {
+        # mitch: let me guess, the realm must be configurable, too!
+        $self->{'__RPCClient'}->credentials('', $username, $password);
+    }
+
+    return $self->{'__RPCClient'}->send_request(@params);
+}
+
 1;