Limit the number of simultaneous connect attempts passed to libpurple.
[thrasher.git] / perl / lib / Thrasher / Backend / PyYahoo.pm
blob8dee75f55b364861682500314df2664fde5fb0da
1 package Thrasher::Backend::PyYahoo;
2 use strict;
3 use warnings;
5 use base 'Thrasher::Backend';
6 use IPC::Run qw(run);
8 =pod
10 =head1 NAME
12 Thrasher::Backend::PyYahoo - Read-only backend for migration from
13 PyYIMt.
15 =head1 DESCRIPTION
17 PyYIMt ( http://xmpppy.sourceforge.net/yahoo/ ) stores its backend
18 information in a GDBM file. This extract the useful information from
19 that GDBM file so that the migration script can use it as a
20 source to populate Thrasher's database with the proper values.
22 This translator will only get your username and password, since
23 that appears to be all it stores.
25 This just barely implements enough to allow migration out of this
26 format.
28 =cut
30 sub new {
31 my $class = shift;
32 my $parameters = shift;
34 my $self = bless $parameters, $class;
36 my @missing;
37 for my $required qw(location) {
38 if (!defined($self->{$required})) {
39 push @missing, $required;
42 if (@missing) {
43 die "$class required the following parameters that weren't "
44 ."provided: " . join(', ', @missing);
47 if (!-e $self->{location}) {
48 die "For PyYahoo, could not find the shelve file $self->{location}.";
51 my $python_program = <<PYTHON;
52 import shelve
54 # technically, this will still fail if you have three quotes in
55 # your shelve file name, in which case all I can say is that
56 # what the heck were you thinking?
57 s = shelve.open("""/mail/jabber/spool/yahoouser.dbm""")
59 def encode(s):
60 return "".join(['\%'+str(ord(x)) for x in s])
62 user_data = [(encode(x), encode(s[x]['username']),
63 encode(s[x]['password'])) for x in s.keys()]
65 for jid, username, password in user_data:
66 print jid, username, password
67 #print "end"
69 s.close()
71 PYTHON
73 my $out;
74 run ['python'], \$python_program, \$out;
75 print $out;
77 my @lines = split (/\r?\n/m, $out);
78 use Data::Dumper;
79 print Dumper(\@lines);
81 for my $line (@lines) {
82 my ($jid, $username, $password) = map { decode($_) } split(/ /, $line);
83 $self->{registrations}->{$jid} = {username => $username,
84 password => $password};
87 return $self;
90 # The inverse of that python encode function up there
91 sub decode {
92 my $s = shift;
93 $s =~ s/%(\d+)/chr($1)/ge;
94 return $s;
97 sub all_jids {
98 my $self = shift;
99 my @jids = keys %{$self->{registrations}};
100 return \@jids;
103 sub registered {
104 my $self = shift;
105 my $jid = shift;
107 return $self->{registrations}->{$jid};
110 sub all_mappings { return {} }
111 sub get_roster { return {} }
112 sub all_avatars { return {} }