summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--Changes8
-rw-r--r--MANIFEST9
-rw-r--r--Makefile.PL18
-rw-r--r--README40
-rw-r--r--lib/DJabberd/Plugin/EntityTime.pm102
-rw-r--r--t/00-load.t9
-rw-r--r--t/boilerplate.t48
-rw-r--r--t/pod-coverage.t6
-rw-r--r--t/pod.t6
10 files changed, 250 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..10b5458
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
1META.yml
2Makefile
3/blib
4/pm_to_blib
diff --git a/Changes b/Changes
new file mode 100644
index 0000000..9a0732c
--- /dev/null
+++ b/Changes
@@ -0,0 +1,8 @@
1Revision history for DJabberd-Plugin-EntityTime
2
30.02 2007-08-03
4 Fixed xmlns on XEP-0202 response
5
60.01 2007-08-03
7 First version, released on an unsuspecting world.
8
diff --git a/MANIFEST b/MANIFEST
new file mode 100644
index 0000000..73aafd0
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,9 @@
1Changes
2MANIFEST
3Makefile.PL
4README
5lib/DJabberd/Plugin/EntityTime.pm
6t/00-load.t
7t/boilerplate.t
8t/pod-coverage.t
9t/pod.t
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..ce0d492
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,18 @@
1use strict;
2use warnings;
3use ExtUtils::MakeMaker;
4
5WriteMakefile(
6 NAME => 'DJabberd::Plugin::EntityTime',
7 AUTHOR => 'Edward Rudd <urkle@outoforder.cc>',
8 VERSION_FROM => 'lib/DJabberd/Plugin/EntityTime.pm',
9 ABSTRACT_FROM => 'lib/DJabberd/Plugin/EntityTime.pm',
10 PL_FILES => {},
11 PREREQ_PM => {
12 'Test::More' => 0,
13 'DJabberd' => 0.83,
14 },
15 DISTNAME => 'DJabberd-EntityTime',
16 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
17 clean => { FILES => 'DJabberd-Plugin-EntityTime-*' },
18);
diff --git a/README b/README
new file mode 100644
index 0000000..78e9d8a
--- /dev/null
+++ b/README
@@ -0,0 +1,40 @@
1DJabberd-Plugin-EntityTime
2
3Implements XEP-0090 and XEP-0202 for DJabberd
4
5INSTALLATION
6
7To install this module, run the following commands:
8
9 perl Makefile.PL
10 make
11 make test
12 make install
13
14
15SUPPORT AND DOCUMENTATION
16
17After installing, you can find documentation for this module with the perldoc command.
18
19 perldoc DJabberd::Plugin::EntityTime
20
21You can also look for information at:
22
23 Search CPAN
24 http://search.cpan.org/dist/DJabberd-Plugin-EntityTime
25
26 CPAN Request Tracker:
27 http://rt.cpan.org/NoAuth/Bugs.html?Dist=DJabberd-Plugin-EntityTime
28
29 AnnoCPAN, annotated CPAN documentation:
30 http://annocpan.org/dist/DJabberd-Plugin-EntityTime
31
32 CPAN Ratings:
33 http://cpanratings.perl.org/d/DJabberd-Plugin-EntityTime
34
35COPYRIGHT AND LICENCE
36
37Copyright (C) 2007 Edward Rudd
38
39This program is free software; you can redistribute it and/or modify it
40under the same terms as Perl itself.
diff --git a/lib/DJabberd/Plugin/EntityTime.pm b/lib/DJabberd/Plugin/EntityTime.pm
new file mode 100644
index 0000000..b59cff6
--- /dev/null
+++ b/lib/DJabberd/Plugin/EntityTime.pm
@@ -0,0 +1,102 @@
1package DJabberd::Plugin::EntityTime;
2
3use warnings;
4use strict;
5use base 'DJabberd::Plugin';
6
7use POSIX qw(strftime);
8
9our $logger = DJabberd::Log->get_logger();
10
11=head1 NAME
12
13DJabberd::Plugin::EntityTime - Implements XEP-0090 and XEP-0202
14
15=head1 VERSION
16
17Version 0.02
18
19=cut
20
21our $VERSION = '0.02';
22
23=head1 SYNOPSIS
24
25Implements XEP-0090 and XEP-0202
26
27 <Vhost mydomain.com>
28 <Plugin DJabberd::Plugin::EntityTime />
29 </VHost>
30
31=cut
32
33=head2 register($self, $vhost)
34
35Register the vhost with the module.
36
37=cut
38
39sub register {
40 my ($self,$vhost) = @_;
41 my $private_cb = sub {
42 my ($vh, $cb, $iq) = @_;
43 unless ($iq->isa("DJabberd::IQ") and defined $iq->to) {
44 $cb->decline;
45 return;
46 }
47 unless ($iq->to eq $vhost->{server_name}) {
48 $cb->decline;
49 return;
50 }
51 if ($iq->signature eq 'get-{jabber:iq:time}query') {
52 $self->_get_time90($vh, $iq);
53 $cb->stop_chain;
54 return;
55 } elsif ($iq->signature eq 'get-{urn:xmpp:time}time') {
56 $self->_get_time202($vh, $iq);
57 $cb->stop_chain;
58 return;
59 }
60 $cb->decline;
61 };
62 $vhost->register_hook("switch_incoming_client",$private_cb);
63 $vhost->register_hook("switch_incoming_server",$private_cb);
64 $vhost->add_feature("jabber:iq:time");
65 $vhost->add_feature("urn:xmpp:time");
66}
67
68sub _get_time90 {
69 my ($self, $vh, $iq) = @_;
70 $logger->info('Getting time from : '.$iq->from_jid);
71 $iq->send_reply('result',qq(<query xmlns="jabber:iq:time">)
72 .'<utc>'.strftime("%Y%m%dT%H:%M:%S",gmtime).'</utc>'
73 .'<display>'.gmtime().'</display>'
74 .'<tz>'.strftime("%Z",gmtime).'</tz>'
75 .qq(</query>) );
76}
77
78sub _get_time202 {
79 my ($self, $vh, $iq) = @_;
80 $logger->info('Getting time from : '.$iq->from_jid);
81 my $zone = strftime("%z",gmtime);
82 $zone =~ s/(\d\d)(\d\d)$/$1:$2/;
83 $iq->send_reply('result',qq(<time xmlns="urn:xmpp:time">)
84 .'<tzo>'.$zone.'</tzo>'
85 .'<utc>'.strftime("%Y%m%dT%H:%M:%S",gmtime).'</utc>'
86 .qq(</time>) );
87}
88
89=head1 AUTHOR
90
91Edward Rudd, C<< <urkle at outoforder.cc> >>
92
93=head1 COPYRIGHT & LICENSE
94
95Copyright 2007 Edward Rudd, all rights reserved.
96
97This program is free software; you can redistribute it and/or modify it
98under the same terms as Perl itself.
99
100=cut
101
1021; # End of DJabberd::Plugin::EntityTime
diff --git a/t/00-load.t b/t/00-load.t
new file mode 100644
index 0000000..2ff39a8
--- /dev/null
+++ b/t/00-load.t
@@ -0,0 +1,9 @@
1#!perl -T
2
3use Test::More tests => 1;
4
5BEGIN {
6 use_ok( 'DJabberd::Plugin::EntityTime' );
7}
8
9diag( "Testing DJabberd::Plugin::EntityTime $DJabberd::Plugin::EntityTime::VERSION, Perl $], $^X" );
diff --git a/t/boilerplate.t b/t/boilerplate.t
new file mode 100644
index 0000000..6502722
--- /dev/null
+++ b/t/boilerplate.t
@@ -0,0 +1,48 @@
1#!perl -T
2
3use strict;
4use warnings;
5use Test::More tests => 3;
6
7sub not_in_file_ok {
8 my ($filename, %regex) = @_;
9 open my $fh, "<", $filename
10 or die "couldn't open $filename for reading: $!";
11
12 my %violated;
13
14 while (my $line = <$fh>) {
15 while (my ($desc, $regex) = each %regex) {
16 if ($line =~ $regex) {
17 push @{$violated{$desc}||=[]}, $.;
18 }
19 }
20 }
21
22 if (%violated) {
23 fail("$filename contains boilerplate text");
24 diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
25 } else {
26 pass("$filename contains no boilerplate text");
27 }
28}
29
30not_in_file_ok(README =>
31 "The README is used..." => qr/The README is used/,
32 "'version information here'" => qr/to provide version information/,
33);
34
35not_in_file_ok(Changes =>
36 "placeholder date/time" => qr(Date/time)
37);
38
39sub module_boilerplate_ok {
40 my ($module) = @_;
41 not_in_file_ok($module =>
42 'the great new $MODULENAME' => qr/ - The great new /,
43 'boilerplate description' => qr/Quick summary of what the module/,
44 'stub function definition' => qr/function[12]/,
45 );
46}
47
48module_boilerplate_ok('lib/DJabberd/Plugin/EntityTime.pm');
diff --git a/t/pod-coverage.t b/t/pod-coverage.t
new file mode 100644
index 0000000..703f91d
--- /dev/null
+++ b/t/pod-coverage.t
@@ -0,0 +1,6 @@
1#!perl -T
2
3use Test::More;
4eval "use Test::Pod::Coverage 1.04";
5plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
6all_pod_coverage_ok();
diff --git a/t/pod.t b/t/pod.t
new file mode 100644
index 0000000..976d7cd
--- /dev/null
+++ b/t/pod.t
@@ -0,0 +1,6 @@
1#!perl -T
2
3use Test::More;
4eval "use Test::Pod 1.14";
5plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
6all_pod_files_ok();