Changeset 660
- Timestamp:
- 08/01/06 05:53:47 (4 years ago)
- Location:
- trunk
- Files:
-
- 7 modified
-
doc/TODO (modified) (1 diff)
-
etc/log.conf.default (modified) (1 diff)
-
lib/DJabberd/Authen/LiveJournal.pm (modified) (1 diff)
-
lib/DJabberd/Connection/ClientIn.pm (modified) (2 diffs)
-
lib/DJabberd/HookDocs.pm (modified) (2 diffs)
-
lib/DJabberd/Plugin/LiveJournal.pm (modified) (9 diffs)
-
lib/DJabberd/Presence.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/TODO
r652 r660 1 --test 2 1 3 -- ACKing: http://www.jabber.org/jeps/inbox/ack.html . does anybody do this? 2 4 if they do, and declare the xmlns in open stream, our reusing parser might eat it. -
trunk/etc/log.conf.default
r489 r660 7 7 # at DEBUG it shows all raw traffic 8 8 # at INFO it censors out the actual data 9 log4perl.logger.DJabberd.Connection.XML = INFO9 log4perl.logger.DJabberd.Connection.XML = WARN 10 10 11 11 -
trunk/lib/DJabberd/Authen/LiveJournal.pm
r531 r660 24 24 # non-blocking auth lookup, using gearman. 25 25 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]), { 27 27 uniq => "-", 28 28 retry_count => 2, -
trunk/lib/DJabberd/Connection/ClientIn.pm
r594 r660 111 111 sub close { 112 112 my $self = shift; 113 return if $self->{closed} ;113 return if $self->{closed}++; 114 114 115 115 # send an unavailable presence broadcast if we've gone away … … 130 130 } 131 131 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 } 133 145 } 134 146 -
trunk/lib/DJabberd/HookDocs.pm
r510 r660 145 145 done => {}, 146 146 }, 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", 148 156 }; 149 157 … … 155 163 }; 156 164 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 157 173 1; -
trunk/lib/DJabberd/Plugin/LiveJournal.pm
r651 r660 6 6 use MIME::Base64; 7 7 use Gearman::Client::Async; 8 8 use Gearman::Client; 9 9 use LWP::Simple; 10 10 … … 13 13 my $start_time = time(); 14 14 15 our @gearman_servers; 15 16 our $gearman_client; 16 17 sub gearman_client { … … 20 21 sub set_config_gearmanservers { 21 22 my ($self, $val) = @_; 22 my @list= split(/\s*,\s*/, $val);23 @gearman_servers = split(/\s*,\s*/, $val); 23 24 $gearman_client = Gearman::Client::Async->new; 24 $gearman_client->set_job_servers(@ list);25 $gearman_client->set_job_servers(@gearman_servers); 25 26 } 26 27 … … 42 43 $vhost->register_hook("OnInitialPresence", \&hook_on_initial_presence); 43 44 $vhost->register_hook("AlterPresenceAvailable", \&hook_alter_presence); 45 $vhost->register_hook("AlterPresenceUnavailable", \&hook_alter_presence); 46 $vhost->register_hook("ConnectionClosing", \&hook_connection_closing); 44 47 $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 57 sub 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 46 74 47 75 sub get_vcard { … … 70 98 } 71 99 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]), { 73 106 uniq => "-", 74 107 retry_count => 2, … … 141 174 return if $bj->node eq 'mart'; 142 175 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>"); 146 179 } 147 180 … … 178 211 } 179 212 213 sub 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 180 239 sub hook_alter_presence { 181 240 my (undef, $cb, $conn, $pkt) = @_; … … 189 248 } 190 249 250 251 my $priority; 191 252 foreach my $ele ($pkt->children_elements) { 253 if ($ele->element_name eq 'priority') { 254 $priority = $ele->first_child; 255 } 192 256 next unless ($ele->inner_ns || '') eq "vcard-temp:x:update" && $ele->element_name eq "x"; 193 257 $pkt->remove_child($ele); … … 197 261 my $user = $bj->node; 198 262 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]), { 200 279 uniq => "-", 201 280 retry_count => 2, -
trunk/lib/DJabberd/Presence.pm
r658 r660 477 477 478 478 sub _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 480 497 if ($self->is_directed) { 481 498 delete($conn->{directed_presence}->{$self->to_jid});
