ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/lib/Net/XMPP2/Ext/Disco/Info.pm
Revision: 1.6
Committed: Wed Jul 25 13:53:33 2007 UTC (19 years, 3 months ago) by elmex
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +1 -1 lines
Log Message:
implemented OOB and fixed bugs in Disco and further developed in band registration.

File Contents

# Content
1 package Net::XMPP2::Ext::Disco::Info;
2 use Net::XMPP2::Namespaces qw/xmpp_ns/;
3
4 =head1 NAME
5
6 Net::XMPP2::Ext::Disco::Info - Service discovery info
7
8 =head1 SYNOPSIS
9
10 =head1 DESCRIPTION
11
12 This class represents the result of a disco info request
13 sent by a C<Net::XMPP2::Ext::Disco> handler.
14
15 =head1 METHODS
16
17 =over 4
18
19 =cut
20
21 sub new {
22 my $this = shift;
23 my $class = ref($this) || $this;
24 my $self = bless { @_ }, $class;
25 $self->init;
26 $self
27 }
28
29 =item B<xml_node ()>
30
31 Returns the L<Net::XMPP2::Node> object of the IQ query.
32
33 =cut
34
35 sub xml_node {
36 my ($self) = @_;
37 $self->{xmlnode}
38 }
39
40 =item B<jid ()>
41
42 Returns the JID these items belong to.
43
44 =cut
45
46 sub jid { $_[0]->{jid} }
47
48 =item B<node ()>
49
50 Returns the node these items belong to (may be undef).
51
52 =cut
53
54 sub node { $_[0]->{node} }
55
56 sub init {
57 my ($self) = @_;
58 my $node = $self->{xmlnode};
59 return unless $node;
60
61 my (@ids) = $node->find_all ([qw/disco_info identity/]);
62 for (@ids) {
63 push @{$self->{identities}}, {
64 category => $_->attr ('category'),
65 type => $_->attr ('type'),
66 name => $_->attr ('name'),
67 xml_node => $_,
68 };
69 }
70
71 my (@fs) = $node->find_all ([qw/disco_info feature/]);
72 $self->{features}->{$_->attr ('var')} = $_ for @fs;
73
74 }
75
76 =item B<identities ()>
77
78 Returns a list of hashrefs which contain following keys:
79
80 category, type, name, xml_node
81
82 C<category> is the category of the identity. C<type> is the
83 type of the identity. C<name> is the human readable name of
84 the identity and might be undef. C<xml_node> is the L<Net::XMPP2::Node>
85 object of the <identity/> node.
86
87 C<category> and C<type> may be one of those defined on:
88
89 http://www.xmpp.org/registrar/disco-categories.html
90
91 =cut
92
93 sub identities {
94 my ($self) = @_;
95 @{$self->{identities}}
96 }
97
98 =item B<features ()>
99
100 Returns a hashref of key/value pairs where the key is the feature name
101 as listed on:
102
103 http://www.xmpp.org/registrar/disco-features.html
104
105 and the value is a L<Net::XMPP2::Node> object for the <feature/> node.
106
107 =cut
108
109 sub features { $_[0]->{features} || {} }
110
111
112 =item B<debug_dump ()>
113
114 Prints the information of this Info object to stdout.
115
116 =cut
117
118 sub debug_dump {
119 my ($self) = @_;
120 printf "INFO FOR %s (%s):\n", $self->jid, $self->node;
121 for ($self->identities) {
122 printf " ID : %20s/%-10s (%s)\n", $_->{category}, $_->{type}, $_->{name}
123 }
124 for (sort keys %{$self->features}) {
125 printf " FEATURE: %s\n", $_;
126 }
127 print "END ITEMS\n";
128
129 }
130
131 =back
132
133 =head1 AUTHOR
134
135 Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >>
136
137 =head1 COPYRIGHT & LICENSE
138
139 Copyright 2007 Robin Redeker, all rights reserved.
140
141 This program is free software; you can redistribute it and/or modify it
142 under the same terms as Perl itself.
143
144 =cut
145
146 1;