[Catalyst-commits] r7610 - in Catalyst-Engine-XMPP2/trunk:
lib/Catalyst/Engine t
ruoso at dev.catalyst.perl.org
ruoso at dev.catalyst.perl.org
Thu Apr 10 22:59:28 BST 2008
Author: ruoso
Date: 2008-04-10 22:59:27 +0100 (Thu, 10 Apr 2008)
New Revision: 7610
Modified:
Catalyst-Engine-XMPP2/trunk/lib/Catalyst/Engine/XMPP2.pm
Catalyst-Engine-XMPP2/trunk/t/TestApp.t
Log:
[C-E-XMPP2] the callbacks actually receive the connection object.
Modified: Catalyst-Engine-XMPP2/trunk/lib/Catalyst/Engine/XMPP2.pm
===================================================================
--- Catalyst-Engine-XMPP2/trunk/lib/Catalyst/Engine/XMPP2.pm 2008-04-10 10:09:42 UTC (rev 7609)
+++ Catalyst-Engine-XMPP2/trunk/lib/Catalyst/Engine/XMPP2.pm 2008-04-10 21:59:27 UTC (rev 7610)
@@ -1,7 +1,7 @@
{ package Catalyst::Engine::XMPP2;
use strict;
use warnings;
- our $VERSION = '0.1';
+ our $VERSION = '0.2';
use base qw(Catalyst::Engine::Embeddable);
use Event qw(loop);
use Encode;
@@ -78,7 +78,7 @@
delete $template{jid};
delete $template{resource};
- $app->log->debug('Initializing Net::XMPP2::Connection objects');
+ #$app->log->debug('Initializing Net::XMPP2::Connection objects');
foreach my $resource (@resources) {
$self->connections->{$resource} =
@@ -86,14 +86,14 @@
%template);
}
- $app->log->debug('Connecting XMPP resources.');
+ #$app->log->debug('Connecting XMPP resources.');
foreach my $resource (@resources) {
$self->connections->{$resource}->connect
or die 'Could not connect resource: '.$resource.', '.$!;
$self->connections->{$resource}->reg_cb
(stream_ready => sub {
- $app->log->debug($resource.' ready.');
+ $self->connections->{$resource}->send_presence('available', sub{});
},
bind_error => sub {
die 'Error binding resource '.$resource.': '.shift;
@@ -102,23 +102,23 @@
# handle all other types of events, but we can actually process
# them the same way.
iq_get_request_xml => sub {
- my $node = shift;
- $app->log->debug('Received an iq get stanza at '.$resource);
+ my ($conn, $node) = @_;
+ #$app->log->debug('Received an iq get stanza at '.$resource);
$self->handle_xmpp_node($app, $resource, $node, 'iq');
},
iq_set_request_xml => sub {
- my $node = shift;
- $app->log->debug('Received an iq set stanza at '.$resource);
+ my ($conn, $node) = @_;
+ #$app->log->debug('Received an iq set stanza at '.$resource);
$self->handle_xmpp_node($app, $resource, $node, 'iq');
},
message_xml => sub {
- my $node = shift;
- $app->log->debug('Received a message stanza at '.$resource);
+ my ($conn, $node) = @_;
+ #$app->log->debug('Received a message stanza at '.$resource);
$self->handle_xmpp_node($app, $resource, $node, 'message');
},
presence_xml => sub {
- my $node = shift;
- $app->log->debug('Received a presence stanza at '.$resource);
+ my ($conn, $node) = @_;
+ #$app->log->debug('Received a presence stanza at '.$resource);
$self->handle_xmpp_node($app, $resource, $node, 'presence');
});
}
@@ -129,18 +129,23 @@
sub handle_xmpp_node {
my ($self, $app, $resource, $node, $type) = @_;
+
my $config = $app->config->{'Engine::XMPP2'};
my $url = 'xmpp://'.$config->{username}.'@'.$config->{domain}.'/'.$resource;
+
my $request = HTTP::Request->new(POST => $url);
+
$request->header('Content-type' => 'application/xml; charset=utf-8');
$request->header('XMPP_Stanza' => $type);
$request->header('XMPP_Resource' => $resource);
+
$request->header('XMPP_Stanza_'.$_ => $node->attr($_))
for grep { $node->attr($_) } qw(to from id type xml:lang);
my $content = encode('utf8', join '', $node->text, map { $_->as_string } $node->nodes);
$request->content_length( length($content) );
$request->content( $content);
+
my $response;
$app->handle_request($request, \$response);
@@ -148,7 +153,7 @@
grep { $response->header($_) } qw(to from id type xml:lang);
if ($response->is_success && $type ne 'iq') {
- $app->log->debug('Request ended successfully, no response needed.');
+ #$app->log->debug('Request ended successfully, no response needed.');
} elsif ($response->is_success) {
$self->connections->{$resource}->reply_iq_result
($node->attr('id'), sub {
Modified: Catalyst-Engine-XMPP2/trunk/t/TestApp.t
===================================================================
--- Catalyst-Engine-XMPP2/trunk/t/TestApp.t 2008-04-10 10:09:42 UTC (rev 7609)
+++ Catalyst-Engine-XMPP2/trunk/t/TestApp.t 2008-04-10 21:59:27 UTC (rev 7610)
@@ -36,7 +36,7 @@
};
my $last_set_callback;
-my $expecting;
+my $expecting = '';
{ package Test::XMPP2;
sub connect {
return 1;
@@ -116,7 +116,7 @@
$expecting = 'iq_reply';
my $writer = Test::Writer->new();
- $connections{'foo/iq_req'}{callbacks}{iq_get_request_xml}->($node);
+ $connections{'foo/iq_req'}{callbacks}{iq_get_request_xml}->($parser,$node);
ok($last_set_callback, 'reply sent');
$last_set_callback->($writer) if $last_set_callback;
@@ -141,7 +141,7 @@
$expecting = 'iq_reply';
my $writer = Test::Writer->new();
- $connections{'foo/iq_req_xml'}{callbacks}{iq_set_request_xml}->($node);
+ $connections{'foo/iq_req_xml'}{callbacks}{iq_set_request_xml}->($parser,$node);
ok($last_set_callback, 'reply sent');
$last_set_callback->($writer) if $last_set_callback;
@@ -166,7 +166,7 @@
$expecting = 'message';
my $writer = Test::Writer->new();
- $connections{'foo/message'}{callbacks}{message_xml}->($node);
+ $connections{'foo/message'}{callbacks}{message_xml}->($parser,$node);
ok($last_set_callback, 'reply sent');
$last_set_callback->($writer) if $last_set_callback;
@@ -191,7 +191,7 @@
$expecting = 'presence';
my $writer = Test::Writer->new();
- $connections{'foo/presence'}{callbacks}{message_xml}->($node);
+ $connections{'foo/presence'}{callbacks}{message_xml}->($parser,$node);
ok($last_set_callback, 'reply sent');
$last_set_callback->($writer) if $last_set_callback;
More information about the Catalyst-commits
mailing list