Changeset 660

Show
Ignore:
Timestamp:
08/01/06 05:53:47 (4 years ago)
Author:
sky
Message:

all set of changes from my dev environment that svk lost somehow, probably because of corrupt disk

Location:
trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/doc/TODO

    r652 r660  
     1--test 
     2 
    13-- ACKing: http://www.jabber.org/jeps/inbox/ack.html .  does anybody do this? 
    24   if they do, and declare the xmlns in open stream, our reusing parser might eat it. 
  • trunk/etc/log.conf.default

    r489 r660  
    77# at DEBUG it shows all raw traffic 
    88# at INFO  it censors out the actual data 
    9 log4perl.logger.DJabberd.Connection.XML = INFO 
     9log4perl.logger.DJabberd.Connection.XML = WARN 
    1010 
    1111 
  • trunk/lib/DJabberd/Authen/LiveJournal.pm

    r531 r660  
    2424    # non-blocking auth lookup, using gearman. 
    2525    if ($gc) { 
    26         $gc->add_task(Gearman::Task->new("ljtalk_auth_check" => \ "$user,$streamid,$digest", { 
     26         $gc->add_task(Gearman::Task->new("ljtalk_auth_check" => \Storable::nfreeze([$user,$streamid,$digest,$resource, $conn->peer_ip_string]), { 
    2727            uniq        => "-", 
    2828            retry_count => 2, 
  • trunk/lib/DJabberd/Connection/ClientIn.pm

    r594 r660  
    111111sub close { 
    112112    my $self = shift; 
    113     return if $self->{closed}; 
     113    return if $self->{closed}++; 
    114114 
    115115    # send an unavailable presence broadcast if we've gone away 
     
    130130    } 
    131131 
    132     $self->SUPER::close; 
     132    if ($self->vhost->are_hooks("ConnectionClosing")) { 
     133        $self->vhost->run_hook_chain(phase => "ConnectionClosing", 
     134                               args  => [ $self ], 
     135                               methods => { 
     136                                   fallback => sub { 
     137                                       $self->SUPER::close; 
     138                                   }, 
     139                               }, 
     140                               ); 
     141 
     142    } else { 
     143        $self->SUPER::close; 
     144    } 
    133145} 
    134146 
  • trunk/lib/DJabberd/HookDocs.pm

    r510 r660  
    145145        done => {}, 
    146146    }, 
    147     des => "Place to alter outgoing presence available packets from users, in-place.  Just modify the provided second argument", 
     147    des => "Place to alter outgoing presence available packets from users, in-place.  Just modify the provided second argument, warning will see directed ones", 
     148}; 
     149 
     150$hook{'AlterPresenceUnavailable'} = { 
     151    args => ['Connection', 'Presence'], 
     152    callback => { 
     153        done => {}, 
     154    }, 
     155    des => "Place to alter outgoing presence unavailable packets from users, in-place.  Just modify the provided second argument, warning will see directed ones", 
    148156}; 
    149157 
     
    155163}; 
    156164 
     165$hook{'ConnectionClosing'} = { 
     166    args => ['Connection'], 
     167    callback => { 
     168        done => {}, 
     169    }, 
     170    des => "Gets called when a connection is in closing state, you can't do anything but let it fall through", 
     171}; 
     172 
    1571731; 
  • trunk/lib/DJabberd/Plugin/LiveJournal.pm

    r651 r660  
    66use MIME::Base64; 
    77use Gearman::Client::Async; 
    8  
     8use Gearman::Client; 
    99use LWP::Simple; 
    1010 
     
    1313my $start_time = time(); 
    1414 
     15our @gearman_servers; 
    1516our $gearman_client; 
    1617sub gearman_client { 
     
    2021sub set_config_gearmanservers { 
    2122    my ($self, $val) = @_; 
    22     my @list = split(/\s*,\s*/, $val); 
     23    @gearman_servers = split(/\s*,\s*/, $val); 
    2324    $gearman_client = Gearman::Client::Async->new; 
    24     $gearman_client->set_job_servers(@list); 
     25    $gearman_client->set_job_servers(@gearman_servers); 
    2526} 
    2627 
     
    4243    $vhost->register_hook("OnInitialPresence",      \&hook_on_initial_presence); 
    4344    $vhost->register_hook("AlterPresenceAvailable", \&hook_alter_presence); 
     45    $vhost->register_hook("AlterPresenceUnavailable", \&hook_alter_presence); 
     46    $vhost->register_hook("ConnectionClosing", \&hook_connection_closing); 
    4447    $vhost->add_feature("vcard-temp"); 
    45 } 
     48 
     49    # make sure we init this cluster node when it comes up 
     50    my $gc = Gearman::Client->new; 
     51    $gc->job_servers(@gearman_servers); 
     52    my $rv = $gc->do_task("ljtalk_init", $vhost->server_name . "_cluster_ip_port", {timeout => 5}); 
     53    die "Couldn't init LJ Plugin" unless $$rv eq 'OK'; 
     54 
     55} 
     56 
     57sub get_vcard_keyword { 
     58    my ($self, $jid, $last_bcast) = @_; 
     59    $last_bcast ||= DJabberd::Presence->local_presence_info($jid); 
     60    my $keyword; 
     61    if (keys %$last_bcast) { 
     62        foreach my $value (values %$last_bcast) { 
     63            foreach my $ele ($value->children_elements) { 
     64                if ($ele->element_name eq 'status') { 
     65                    $keyword = $ele->first_child; 
     66                } 
     67                last; 
     68            } 
     69        } 
     70    } 
     71    return $keyword; 
     72} 
     73 
    4674 
    4775sub get_vcard { 
     
    7098    } 
    7199 
    72     $gc->add_task(Gearman::Task->new("ljtalk_avatar_data" => \ "$username", { 
     100 
     101    my $keyword = $self->get_vcard_keyword($iq->to_jid); 
     102 
     103    warn "get $keyword"; 
     104 
     105    $gc->add_task(Gearman::Task->new("ljtalk_avatar_data" => \Storable::nfreeze([$username, $keyword]), { 
    73106        uniq        => "-", 
    74107        retry_count => 2, 
     
    141174    return if $bj->node eq 'mart'; 
    142175 
    143     $conn->write("<message to='$bj' from='livejournal.com' type='headline'><body>LJ Talk is currently a pre-alpha service lacking tons of features and probably with a bunch of bugs. 
    144  
    145 We're actively developing it, constantly restarting it with new stuff.  So just don't be surprised if the service goes up and down $how_much.</body></message>"); 
     176#    $conn->write("<message to='$bj' from='livejournal.com' type='headline'><body>LJ Talk is currently a pre-alpha service lacking tons of features and probably with a bunch of bugs. 
     177 
     178#We're actively developing it, constantly restarting it with new stuff.  So just don't be surprised if the service goes up and down $how_much.</body></message>"); 
    146179} 
    147180 
     
    178211} 
    179212 
     213sub hook_connection_closing { 
     214    my (undef, $cb, $conn) = @_; 
     215 
     216    my $bj = $conn->bound_jid; 
     217    my $gc = DJabberd::Plugin::LiveJournal->gearman_client; 
     218 
     219    unless ($bj && $gc) { 
     220        $cb->done; 
     221        return; 
     222    } 
     223 
     224    $gc->add_task(Gearman::Task->new("ljtalk_connection_closing" => \Storable::nfreeze([$bj->node, $bj->resource]), { 
     225                                     uniq => '-', 
     226                                     retry_count => 2, 
     227                                     timeout => 10, 
     228                                     on_fail => sub { 
     229                                         $DJabberd::Stats::counter{'ljtalk_alter_presence_fail'}++; 
     230                                     }, 
     231                                     on_complete => sub { 
     232                                         $DJabberd::Stats::counter{'ljtalk_alter_presence_success'}++; 
     233                                     }, 
     234                                 })); 
     235 
     236    $cb->decline; 
     237} 
     238 
    180239sub hook_alter_presence { 
    181240    my (undef, $cb, $conn, $pkt) = @_; 
     
    189248    } 
    190249 
     250 
     251    my $priority; 
    191252    foreach my $ele ($pkt->children_elements) { 
     253        if ($ele->element_name eq 'priority') { 
     254            $priority = $ele->first_child; 
     255        } 
    192256        next unless ($ele->inner_ns || '') eq "vcard-temp:x:update" && $ele->element_name eq "x"; 
    193257        $pkt->remove_child($ele); 
     
    197261    my $user = $bj->node; 
    198262 
    199     $gc->add_task(Gearman::Task->new("ljtalk_avatar_sha1" => \ "$user", { 
     263    $gc->add_task(Gearman::Task->new("ljtalk_alter_presence" => \Storable::nfreeze([$bj->node, $bj->resource, $priority,  $pkt->as_xml]), { 
     264                                     uniq => '-', 
     265                                     retry_count => 2, 
     266                                     timeout => 10, 
     267                                     on_fail => sub { 
     268                                         $DJabberd::Stats::counter{'ljtalk_alter_presence_fail'}++; 
     269                                     }, 
     270                                     on_complete => sub { 
     271                                         $DJabberd::Stats::counter{'ljtalk_alter_presence_success'}++; 
     272                                     }, 
     273                                 })); 
     274 
     275    my $keyword = __PACKAGE__->get_vcard_keyword($bj, { dummy => $pkt }); 
     276 
     277 
     278    $gc->add_task(Gearman::Task->new("ljtalk_avatar_sha1" => \Storable::nfreeze([$user, $keyword]), { 
    200279        uniq        => "-", 
    201280        retry_count => 2, 
  • trunk/lib/DJabberd/Presence.pm

    r658 r660  
    477477 
    478478sub _process_outbound_unavailable { 
    479     my ($self, $conn) = @_; 
     479    my ($self, $conn, $skip_alter) = @_; 
     480 
     481    my $vhost = $conn->vhost; 
     482    if (!$skip_alter && $vhost->are_hooks("AlterPresenceUnavailable")) { 
     483        warn "runnig hook chain unavailable"; 
     484        $vhost->run_hook_chain(phase => "AlterPresenceUnavailable", 
     485                               args  => [ $conn, $self ], 
     486                               methods => { 
     487                                   done => sub { 
     488                                       return if $conn->{closed}; 
     489                                       $self->_process_outbound_unavailable($conn, 1); 
     490                                   }, 
     491                               }, 
     492                               ); 
     493        return; 
     494    } 
     495 
     496 
    480497    if ($self->is_directed) { 
    481498        delete($conn->{directed_presence}->{$self->to_jid});