- Handle autosave on module unload/irssi exit
[xmlrtorrent.git] / xmlrtorrent / HTTPTalker.pm
index 9160f8f..1254b2d 100644 (file)
@@ -4,8 +4,8 @@
 # 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;
@@ -18,9 +18,9 @@ sub 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)'],
+        'XMLURL' => ['', 'URL of SCGI script'],
+        'USERNAME' => ['', 'username for RPC credentials (optional)'],
+        'PASSWORD' => ['', 'password for RPC credentials (optional)'],
     };
     $self->{'_LASTXMLURL'} = undef;
 
@@ -35,19 +35,23 @@ sub send_request {
     my $self = shift;
     my @params = @_;
 
-    unless (exists($self->{'_PARAMS'}->{'XMLURL'}) and defined($self->{'_PARAMS'}->{'XMLURL'})) {
-       return 'http talker: XMLURL not set';
+    my $xmlurl = $self->_getval('XMLURL');
+
+    unless (defined($xmlurl) and $xmlurl ne '') {
+        return 'http talker: XMLURL not set';
     }
 
-    if ($self->{'_PARAMS'}->{'XMLURL'} ne $self->{'_LASTXMLURL'}) {
-       $self->{'_LASTXMLURL'} = $self->{'_PARAMS'}->{'XMLURL'};
-       $self->{'__RPCClient'} = RPC::XML::Client->new($self->{'_PARAMS'}->{'XMLURL'});
+    if ($xmlurl ne $self->{'_LASTXMLURL'}) {
+        $self->{'_LASTXMLURL'} = $xmlurl;
+        $self->{'__RPCClient'} = RPC::XML::Client->new($xmlurl);
     }  
     
-    if ((exists($self->{'_PARAMS'}->{'USERNAME'}) and exists($self->{'_PARAMS'}->{'PASSWORD'})) and
-       ($self->{'_PARAMS'}->{'USERNAME'} ne '')) {
-       # mitch: let me guess, the realm must be configurable, too!
-       $self->{'__RPCClient'}->credentials('', $self->{'_PARAMS'}->{'USERNAME'}, $self->{'_PARAMS'}->{'PASSWORD'});
+    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);