Permalink
Browse files

all set of changes from my dev environment that svk lost somehow, pro…

…bably because of corrupt disk

git-svn-id: http://code.sixapart.com/svn/djabberd/trunk@660 43dd9337-660f-0410-bd32-e7601923a1a1
  • Loading branch information...
1 parent de2836c commit d857b4618fb75372749ad1c577c717b16b5088f7 Artur Bergman committed Aug 1, 2006
View
@@ -1,3 +1,5 @@
+--test
+
-- ACKing: http://www.jabber.org/jeps/inbox/ack.html . does anybody do this?
if they do, and declare the xmlns in open stream, our reusing parser might eat it.
we should double-check how we deal with that.
View
@@ -6,7 +6,7 @@ log4perl.logger.DJabberd.Hook = WARN
# This psuedo class is used to control if raw XML is to be showed or not
# at DEBUG it shows all raw traffic
# at INFO it censors out the actual data
-log4perl.logger.DJabberd.Connection.XML = INFO
+log4perl.logger.DJabberd.Connection.XML = WARN
@@ -23,7 +23,7 @@ sub check_digest {
# non-blocking auth lookup, using gearman.
if ($gc) {
- $gc->add_task(Gearman::Task->new("ljtalk_auth_check" => \ "$user,$streamid,$digest", {
+ $gc->add_task(Gearman::Task->new("ljtalk_auth_check" => \Storable::nfreeze([$user,$streamid,$digest,$resource, $conn->peer_ip_string]), {
uniq => "-",
retry_count => 2,
timeout => 10,
@@ -110,7 +110,7 @@ sub send_pending_sub_requests {
sub close {
my $self = shift;
- return if $self->{closed};
+ return if $self->{closed}++;
# send an unavailable presence broadcast if we've gone away
if ($self->is_available) {
@@ -129,7 +129,19 @@ sub close {
DJabberd::Presence->forget_last_presence($jid);
}
- $self->SUPER::close;
+ if ($self->vhost->are_hooks("ConnectionClosing")) {
+ $self->vhost->run_hook_chain(phase => "ConnectionClosing",
+ args => [ $self ],
+ methods => {
+ fallback => sub {
+ $self->SUPER::close;
+ },
+ },
+ );
+
+ } else {
+ $self->SUPER::close;
+ }
}
sub namespace {
View
@@ -144,7 +144,15 @@ $hook{'AlterPresenceAvailable'} = {
callback => {
done => {},
},
- des => "Place to alter outgoing presence available packets from users, in-place. Just modify the provided second argument",
+ des => "Place to alter outgoing presence available packets from users, in-place. Just modify the provided second argument, warning will see directed ones",
+};
+
+$hook{'AlterPresenceUnavailable'} = {
+ args => ['Connection', 'Presence'],
+ callback => {
+ done => {},
+ },
+ des => "Place to alter outgoing presence unavailable packets from users, in-place. Just modify the provided second argument, warning will see directed ones",
};
$hook{'OnInitialPresence'} = {
@@ -154,4 +162,12 @@ $hook{'OnInitialPresence'} = {
des => "Called when a client first comes online and becomes present.",
};
+$hook{'ConnectionClosing'} = {
+ args => ['Connection'],
+ callback => {
+ done => {},
+ },
+ des => "Gets called when a connection is in closing state, you can't do anything but let it fall through",
+};
+
1;
@@ -5,23 +5,24 @@ use warnings;
use Digest::SHA1 qw(sha1_hex);
use MIME::Base64;
use Gearman::Client::Async;
-
+use Gearman::Client;
use LWP::Simple;
our $logger = DJabberd::Log->get_logger();
my $start_time = time();
+our @gearman_servers;
our $gearman_client;
sub gearman_client {
return $gearman_client;
}
sub set_config_gearmanservers {
my ($self, $val) = @_;
- my @list = split(/\s*,\s*/, $val);
+ @gearman_servers = split(/\s*,\s*/, $val);
$gearman_client = Gearman::Client::Async->new;
- $gearman_client->set_job_servers(@list);
+ $gearman_client->set_job_servers(@gearman_servers);
}
sub register {
@@ -41,9 +42,36 @@ sub register {
$vhost->register_hook("switch_incoming_server", $hook_vcard_s2s);
$vhost->register_hook("OnInitialPresence", \&hook_on_initial_presence);
$vhost->register_hook("AlterPresenceAvailable", \&hook_alter_presence);
+ $vhost->register_hook("AlterPresenceUnavailable", \&hook_alter_presence);
+ $vhost->register_hook("ConnectionClosing", \&hook_connection_closing);
$vhost->add_feature("vcard-temp");
+
+ # make sure we init this cluster node when it comes up
+ my $gc = Gearman::Client->new;
+ $gc->job_servers(@gearman_servers);
+ my $rv = $gc->do_task("ljtalk_init", $vhost->server_name . "_cluster_ip_port", {timeout => 5});
+ die "Couldn't init LJ Plugin" unless $$rv eq 'OK';
+
+}
+
+sub get_vcard_keyword {
+ my ($self, $jid, $last_bcast) = @_;
+ $last_bcast ||= DJabberd::Presence->local_presence_info($jid);
+ my $keyword;
+ if (keys %$last_bcast) {
+ foreach my $value (values %$last_bcast) {
+ foreach my $ele ($value->children_elements) {
+ if ($ele->element_name eq 'status') {
+ $keyword = $ele->first_child;
+ }
+ last;
+ }
+ }
+ }
+ return $keyword;
}
+
sub get_vcard {
my ($self, $vhost, $iq) = @_;
@@ -69,7 +97,12 @@ sub get_vcard {
return;
}
- $gc->add_task(Gearman::Task->new("ljtalk_avatar_data" => \ "$username", {
+
+ my $keyword = $self->get_vcard_keyword($iq->to_jid);
+
+ warn "get $keyword";
+
+ $gc->add_task(Gearman::Task->new("ljtalk_avatar_data" => \Storable::nfreeze([$username, $keyword]), {
uniq => "-",
retry_count => 2,
timeout => 10,
@@ -140,9 +173,9 @@ sub hook_on_initial_presence {
return if $bj->node eq 'mart';
- $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.
+# $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.
-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>");
+#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>");
}
sub hook_vcard_switch {
@@ -177,6 +210,32 @@ sub hook_vcard_switch {
$cb->decline;
}
+sub hook_connection_closing {
+ my (undef, $cb, $conn) = @_;
+
+ my $bj = $conn->bound_jid;
+ my $gc = DJabberd::Plugin::LiveJournal->gearman_client;
+
+ unless ($bj && $gc) {
+ $cb->done;
+ return;
+ }
+
+ $gc->add_task(Gearman::Task->new("ljtalk_connection_closing" => \Storable::nfreeze([$bj->node, $bj->resource]), {
+ uniq => '-',
+ retry_count => 2,
+ timeout => 10,
+ on_fail => sub {
+ $DJabberd::Stats::counter{'ljtalk_alter_presence_fail'}++;
+ },
+ on_complete => sub {
+ $DJabberd::Stats::counter{'ljtalk_alter_presence_success'}++;
+ },
+ }));
+
+ $cb->decline;
+}
+
sub hook_alter_presence {
my (undef, $cb, $conn, $pkt) = @_;
@@ -188,15 +247,35 @@ sub hook_alter_presence {
return;
}
+
+ my $priority;
foreach my $ele ($pkt->children_elements) {
+ if ($ele->element_name eq 'priority') {
+ $priority = $ele->first_child;
+ }
next unless ($ele->inner_ns || '') eq "vcard-temp:x:update" && $ele->element_name eq "x";
$pkt->remove_child($ele);
last;
}
my $user = $bj->node;
- $gc->add_task(Gearman::Task->new("ljtalk_avatar_sha1" => \ "$user", {
+ $gc->add_task(Gearman::Task->new("ljtalk_alter_presence" => \Storable::nfreeze([$bj->node, $bj->resource, $priority, $pkt->as_xml]), {
+ uniq => '-',
+ retry_count => 2,
+ timeout => 10,
+ on_fail => sub {
+ $DJabberd::Stats::counter{'ljtalk_alter_presence_fail'}++;
+ },
+ on_complete => sub {
+ $DJabberd::Stats::counter{'ljtalk_alter_presence_success'}++;
+ },
+ }));
+
+ my $keyword = __PACKAGE__->get_vcard_keyword($bj, { dummy => $pkt });
+
+
+ $gc->add_task(Gearman::Task->new("ljtalk_avatar_sha1" => \Storable::nfreeze([$user, $keyword]), {
uniq => "-",
retry_count => 2,
timeout => 10,
View
@@ -476,7 +476,24 @@ sub _process_outbound_available {
}
sub _process_outbound_unavailable {
- my ($self, $conn) = @_;
+ my ($self, $conn, $skip_alter) = @_;
+
+ my $vhost = $conn->vhost;
+ if (!$skip_alter && $vhost->are_hooks("AlterPresenceUnavailable")) {
+ warn "runnig hook chain unavailable";
+ $vhost->run_hook_chain(phase => "AlterPresenceUnavailable",
+ args => [ $conn, $self ],
+ methods => {
+ done => sub {
+ return if $conn->{closed};
+ $self->_process_outbound_unavailable($conn, 1);
+ },
+ },
+ );
+ return;
+ }
+
+
if ($self->is_directed) {
delete($conn->{directed_presence}->{$self->to_jid});
$self->deliver;

0 comments on commit d857b46

Please sign in to comment.