- Add authentication support
[xmlrtorrent.git] / xmlrtorrent.pm
index 92cd1aa..b1c41b9 100644 (file)
@@ -9,11 +9,15 @@ sub new {
     my $class = shift;
     my $self = {@_};
 
-    unless(exists($self->{'XMLURL'}) && defined($self->{'XMLURL'})) {
+    unless(exists($self->{'XMLURL'}) and defined($self->{'XMLURL'})) {
         return undef;
     }
 
     $self->{'__RPCClient'} = RPC::XML::Client->new($self->{'XMLURL'});
+    if ((exists($self->{'USERNAME'}) and exists($self->{'PASSWORD'})) and
+        ($self->{'USERNAME'} ne '')) {
+        $self->{'__RPCClient'}->credentials('', $self->{'USERNAME'}, $self->{'PASSWORD'});
+    }
 
     return bless($self, $class);
 }