#!/usr/bin/perl # # # This file is licensed under the fpsn.net, Inc. # GOSL (General Open Source License), Exact details # of this and warrenty information with the GOSL # may be obtained by visting the following # website: # http://www.fpsn.net/license/GOSL.txt # # Should you request this license via Mail you # may write to: # # License request # 910 Grape Ave. # Boulder, Colorado 80304 # # # Please be sure to include your name mailing address # and a self addressed stamped envelope, and the license(s) # you wish to receive. # Please allow for 3 to 5 weeks for mailing. # # # Check for the latest versions of this software at: # http://www.fpsn.net # # # Should you wish to receive commercial support on this # product please visit http://www.fpsn.net/contact.cgi # and drop us a line. # # use XML::Simple; use strict; use Getopt::Std; use vars qw($ref $xml %conf $VERSION $AUTHOR $FILE $NAME); use Data::Dumper; $VERSION = '1.0'; $AUTHOR = 'Colin Faber '; getopt('hbev',\%conf); $FILE = ($conf{b} || $conf{e}); $NAME = ($ARGV[0] ? $ARGV[0] : ($ENV{USER} ? $ENV{USER} : 'trillian2gaim_db')); if(exists $conf{v}){ print "Trillion2Gaim $VERSION"; exit; } elsif(exists $conf{h} || !$FILE){ print "\n Trillion2Gaim $VERSION by $AUTHOR\n\tUsage: $0 [opts] [file_title]\n\t-b [file]\tParse Buddies XML file\n\t-e [file]\tParse Events XML file\n\t-v\t\tShow version and exit\n\n"; exit; } my $ref; if(-f $FILE){ $ref = XMLin($FILE) || die "$!\n"; if($conf{b}){ buddy_parser($ref); } else { print Dumper($ref); } } elsif(!-f $FILE){ print "Unable to open fine source file $FILE\n"; } sub decode_uri { my $data = shift; $data =~ s/%(..)/pack("c",hex($1))/ge; return $data; } sub buddy_parser { my $ref = shift; if(ref($ref) eq 'HASH'){ if(ref($ref->{buddy}) eq 'ARRAY'){ for my $buddy (@{ $ref->{buddy} }){ my ($type, $str) = split(/:/, $buddy->{uri}, 2); my ($expand, $id, $alias) = split(/:/, decode_uri($str), 3); printl("m 1\n", $type); printl("g Buddies\n", $type); printl('b ' . $id . ($alias ? ':' . $alias : undef) . "\n", $type); } } if(ref($ref->{group}) eq 'ARRAY'){ for my $group (@{ $ref->{group} }){ for my $buddy (@{ $group->{buddy} }){ my ($type, $str) = split(/:/, $buddy->{uri}, 2); my ($expand, $id, $alias) = split(/:/, decode_uri($str), 3); printl("m 1\n", $type); printl("g $group->{title}\n", $type); printl('b ' . $id . ($alias ? ':' . $alias : undef) . "\n", $type); } } } } else { print ref($ref) . "\n"; } } sub printl { my ($str, $type) = @_; if(!$::unique{$str . $type}){ $::unique{$str . $type} = 1; if($type){ open(FILE, '>>' . $NAME . '.' . lc($type)) || die " Unable to open outfile: " . $NAME . '.' . lc($type) . " $!\n"; print FILE $str; chomp $str; print STDOUT "Writing line [$NAME." . lc($type) . "]:" . $str . "\n"; close(FILE); } else { print " Type may not be blank. Skipping: $str"; } } }