source: perl/modules/AIM/lib/Net/OSCAR/Callbacks/1/migrate.pm @ 7a1c90d

barnowl_perlaim
Last change on this file since 7a1c90d was 7a1c90d, checked in by Geoffrey Thomas <geofft@mit.edu>, 16 years ago
Skeleton AIM module, and Net::OSCAR 1.925
  • Property mode set to 100644
File size: 2.1 KB
Line 
1package Net::OSCAR::Callbacks;
2use strict;
3use warnings;
4use vars qw($connection $snac $conntype $family $subtype $data $reqid $reqdata $session $protobit %data);
5sub {
6
7# It looks like we get a blank family if the server sends
8# no migration families (full migration.)  Filter out
9# this dummy entry.
10my @migfamilies = grep { $_ != 0 } @{$data{families}};
11
12$connection->log_print(OSCAR_DBG_WARN, "Migration families received: ", join(" ", @migfamilies));
13$session->loglevel(10);
14
15my $pause_queue;
16if(@{$data{families}} == keys %{$connection->{families}} or @migfamilies == 0) {
17        $connection->log_print(OSCAR_DBG_WARN, "Full migration, disconnecting...");
18        $pause_queue = $connection->{pause_queue};
19
20        # Don't let it think that we've lost the BOS connection
21        my $conntype = $connection->{conntype};
22        $connection->{conntype} = -1 if $connection->{conntype} == CONNTYPE_BOS;
23        $session->delconn($connection);
24        $connection->{conntype} = $conntype;
25
26        $session->log_print(OSCAR_DBG_WARN, "Disconnected.");
27} else {
28        $connection->log_print(OSCAR_DBG_WARN, "Partial migration");
29
30        # Get the list of families which aren't being migrated
31        my @all_families = keys %{$connection->{families}};
32        $connection->{families} = {};
33        foreach my $fam (@all_families) {
34                next if grep { $_ == $fam } @migfamilies;
35                $connection->{families}->{$fam} = 1;
36        }
37
38        # Filter the pause queue according to the migration split
39        my $all_pause_queue = $connection->{pause_queue};
40        $connection->{pause_queue} = [];
41        foreach my $item (@$all_pause_queue) {
42                if(grep { $item->{family} == $_ } @migfamilies) {
43                        push @$pause_queue, $item;
44                } else {
45                        push @{$connection->{pause_queue}}, $item;
46                }
47        }
48
49        $connection->log_printf(OSCAR_DBG_WARN, "Migration pause queue: %d/%d", @{$pause_queue || []}, @{$connection->{pause_queue} || []});
50}
51
52$session->log_print(OSCAR_DBG_WARN, "Creating new connection");
53my $newconn = $session->addconn(
54        auth => $data{cookie},
55        conntype => $connection->{conntype},
56        description => $connection->{description},
57        peer => $data{peer},
58        paused => 1,
59        pause_queue => $pause_queue
60);
61$session->log_print(OSCAR_DBG_WARN, "Created.");
62
63};
Note: See TracBrowser for help on using the repository browser.