| 1 |
package Net::XMPP2::Error::Stream; |
| 2 |
use Net::XMPP2::Error; |
| 3 |
our @ISA = qw/Net::XMPP2::Error/; |
| 4 |
|
| 5 |
=head1 NAME |
| 6 |
|
| 7 |
Net::XMPP2::Error::Stream - XML Stream errors |
| 8 |
|
| 9 |
Subclass of L<Net::XMPP2::Error> |
| 10 |
|
| 11 |
=cut |
| 12 |
|
| 13 |
sub init { |
| 14 |
my ($self) = @_; |
| 15 |
my $node = $self->xml_node; |
| 16 |
|
| 17 |
my @txt = $node->find_all ([qw/streams text/]); |
| 18 |
my $error; |
| 19 |
for my $er ( |
| 20 |
qw/bad-format bad-namespace-prefix conflict connection-timeout host-gone |
| 21 |
host-unknown improper-addressing internal-server-error invalid-from |
| 22 |
invalid-id invalid-namespace invalid-xml not-authorized policy-violation |
| 23 |
remote-connection-failed resource-constraint restricted-xml |
| 24 |
see-other-host system-shutdown undefined-condition unsupported-stanza-type |
| 25 |
unsupported-version xml-not-well-formed/) |
| 26 |
{ |
| 27 |
if (my (@n) = $node->find_all ([streams => $er])) { |
| 28 |
$error = $n[0]->name; |
| 29 |
last; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
unless ($error) { |
| 34 |
#d# warn "got undefined error stanza, trying to find any undefined error..."; |
| 35 |
for my $n ($node->nodes) { |
| 36 |
if ($n->eq_ns ('streams')) { |
| 37 |
$error = $n->name; |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
$self->{error_name} = $error; |
| 43 |
$self->{error_text} = @txt ? $txt[0]->text : ''; |
| 44 |
} |
| 45 |
|
| 46 |
=head2 METHODS |
| 47 |
|
| 48 |
=over 4 |
| 49 |
|
| 50 |
=item B<xml_node ()> |
| 51 |
|
| 52 |
Returns the L<Net::XMPP2::Node> object for this stream error. |
| 53 |
|
| 54 |
=cut |
| 55 |
|
| 56 |
sub xml_node { |
| 57 |
$_[0]->{node} |
| 58 |
} |
| 59 |
|
| 60 |
=item B<name ()> |
| 61 |
|
| 62 |
Returns the name of the error. That might be undef, one of the following |
| 63 |
strings or some other string that has been discovered by a heuristic |
| 64 |
(because some servers send errors that are not in the RFC). |
| 65 |
|
| 66 |
bad-format |
| 67 |
bad-namespace-prefix |
| 68 |
conflict |
| 69 |
connection-timeout |
| 70 |
host-gone |
| 71 |
host-unknown |
| 72 |
improper-addressing |
| 73 |
internal-server-error |
| 74 |
invalid-from |
| 75 |
invalid-id |
| 76 |
invalid-namespace |
| 77 |
invalid-xml |
| 78 |
not-authorized |
| 79 |
policy-violation |
| 80 |
remote-connection-failed |
| 81 |
resource-constraint |
| 82 |
restricted-xml |
| 83 |
see-other-host |
| 84 |
system-shutdown |
| 85 |
undefined-condition |
| 86 |
unsupported-stanza-type |
| 87 |
unsupported-version |
| 88 |
xml-not-well-formed |
| 89 |
|
| 90 |
=cut |
| 91 |
|
| 92 |
sub name { $_[0]->{error_name} } |
| 93 |
|
| 94 |
=item B<text ()> |
| 95 |
|
| 96 |
The humand readable error portion. Might be undef if none was received. |
| 97 |
|
| 98 |
=cut |
| 99 |
|
| 100 |
sub text { $_[0]->{error_text} } |
| 101 |
|
| 102 |
sub string { |
| 103 |
my ($self) = @_; |
| 104 |
|
| 105 |
sprintf ("stream error: %s: %s", |
| 106 |
$self->name, |
| 107 |
$self->text) |
| 108 |
} |
| 109 |
|
| 110 |
=back |
| 111 |
|
| 112 |
=cut |
| 113 |
|
| 114 |
|
| 115 |
=head1 AUTHOR |
| 116 |
|
| 117 |
Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >> |
| 118 |
|
| 119 |
=head1 COPYRIGHT & LICENSE |
| 120 |
|
| 121 |
Copyright 2007 Robin Redeker, all rights reserved. |
| 122 |
|
| 123 |
This program is free software; you can redistribute it and/or modify it |
| 124 |
under the same terms as Perl itself. |
| 125 |
|
| 126 |
=cut |
| 127 |
|
| 128 |
1; # End of Net::XMPP2 |