| 1 |
elmex |
1.1 |
package Net::XMPP2::Error::Stanza; |
| 2 |
|
|
use Net::XMPP2::Error; |
| 3 |
|
|
our @ISA = qw/Net::XMPP2::Error/; |
| 4 |
|
|
|
| 5 |
|
|
=head1 NAME |
| 6 |
|
|
|
| 7 |
|
|
Net::XMPP2::Error::Stanza - Stanza 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 |
|
|
unless (defined $node) { |
| 18 |
|
|
$self->{error_cond} = 'client-timeout'; |
| 19 |
|
|
$self->{error_type} = 'cancel'; |
| 20 |
|
|
return; |
| 21 |
|
|
} |
| 22 |
|
|
|
| 23 |
|
|
my @error; |
| 24 |
|
|
my ($err) = $node->find_all ([qw/client error/]); |
| 25 |
|
|
|
| 26 |
|
|
unless ($err) { |
| 27 |
|
|
warn "No error element found in error stanza!"; |
| 28 |
|
|
$self->{text} = "Unknown Stanza error"; |
| 29 |
|
|
return |
| 30 |
|
|
} |
| 31 |
|
|
|
| 32 |
|
|
$self->{error_type} = $err->attr ('type'); |
| 33 |
|
|
$self->{error_code} = $err->attr ('code'); |
| 34 |
|
|
|
| 35 |
|
|
if (my ($txt) = $err->find_all ([qw/stanzas text/])) { |
| 36 |
|
|
$self->{error_text} = $txt->text; |
| 37 |
|
|
} |
| 38 |
|
|
|
| 39 |
|
|
for my $er ( |
| 40 |
|
|
qw/bad-request conflict feature-not-implemented forbidden |
| 41 |
|
|
gone internal-server-error item-not-found jid-malformed |
| 42 |
|
|
not-acceptable not-allowed not-authorized payment-required |
| 43 |
|
|
recipient-unavailable redirect registration-required |
| 44 |
|
|
remote-server-not-found remote-server-timeout resource-constraint |
| 45 |
|
|
service-unavailable subscription-required undefined-condition |
| 46 |
|
|
unexpected-request/) |
| 47 |
|
|
{ |
| 48 |
|
|
if (my ($el) = $err->find_all ([stanzas => $er])) { |
| 49 |
|
|
$self->{error_cond} = $er; |
| 50 |
|
|
$self->{error_cond_node} = $el; |
| 51 |
|
|
last; |
| 52 |
|
|
} |
| 53 |
|
|
} |
| 54 |
|
|
} |
| 55 |
|
|
|
| 56 |
|
|
=head2 METHODS |
| 57 |
|
|
|
| 58 |
|
|
=over 4 |
| 59 |
|
|
|
| 60 |
|
|
=item B<xml_node ()> |
| 61 |
|
|
|
| 62 |
|
|
Returns the L<Net::XMPP2::Node> object for this Stanza error. |
| 63 |
|
|
This method returns undef if the Stanza timeouted. |
| 64 |
|
|
|
| 65 |
|
|
In the case of a timeout the C<condition> method returns C<client-timeout>, |
| 66 |
|
|
C<type> returns 'cancel' and C<code> undef. |
| 67 |
|
|
|
| 68 |
|
|
=cut |
| 69 |
|
|
|
| 70 |
|
|
sub xml_node { |
| 71 |
|
|
$_[0]->{node} |
| 72 |
|
|
} |
| 73 |
|
|
|
| 74 |
|
|
=item B<type ()> |
| 75 |
|
|
|
| 76 |
|
|
This method returns one of: |
| 77 |
|
|
|
| 78 |
|
|
'cancel', 'continue', 'modify', 'auth' and 'wait' |
| 79 |
|
|
|
| 80 |
|
|
=cut |
| 81 |
|
|
|
| 82 |
|
|
sub type { $_[0]->{error_type} } |
| 83 |
|
|
|
| 84 |
|
|
=item B<code ()> |
| 85 |
|
|
|
| 86 |
|
|
This method returns the error code if one was found. |
| 87 |
|
|
|
| 88 |
|
|
=cut |
| 89 |
|
|
|
| 90 |
|
|
sub code { $_[0]->{error_code} } |
| 91 |
|
|
|
| 92 |
|
|
=item B<condition ()> |
| 93 |
|
|
|
| 94 |
|
|
Returns the error condition string if one was found when receiving the Stanza error. |
| 95 |
|
|
It can be undef or one of: |
| 96 |
|
|
|
| 97 |
|
|
bad-request |
| 98 |
|
|
conflict |
| 99 |
|
|
feature-not-implemented |
| 100 |
|
|
forbidden |
| 101 |
|
|
gone |
| 102 |
|
|
internal-server-error |
| 103 |
|
|
item-not-found |
| 104 |
|
|
jid-malformed |
| 105 |
|
|
not-acceptable |
| 106 |
|
|
not-allowed |
| 107 |
|
|
not-authorized |
| 108 |
|
|
payment-required |
| 109 |
|
|
recipient-unavailable |
| 110 |
|
|
redirect |
| 111 |
|
|
registration-required |
| 112 |
|
|
remote-server-not-found |
| 113 |
|
|
remote-server-timeout |
| 114 |
|
|
resource-constraint |
| 115 |
|
|
service-unavailable |
| 116 |
|
|
subscription-required |
| 117 |
|
|
undefined-condition |
| 118 |
|
|
unexpected-request |
| 119 |
|
|
|
| 120 |
|
|
|
| 121 |
|
|
=cut |
| 122 |
|
|
|
| 123 |
|
|
sub condition { $_[0]->{error_cond} } |
| 124 |
|
|
|
| 125 |
|
|
=item B<condition_node ()> |
| 126 |
|
|
|
| 127 |
|
|
Returns the error condition node if one was found when receiving the Stanza error. |
| 128 |
|
|
This is mostly for debugging purposes. |
| 129 |
|
|
|
| 130 |
|
|
=cut |
| 131 |
|
|
|
| 132 |
|
|
sub condition_node { $_[0]->{error_cond_node} } |
| 133 |
|
|
|
| 134 |
|
|
=item B<text ()> |
| 135 |
|
|
|
| 136 |
|
|
The humand readable error portion. Might be undef if none was received. |
| 137 |
|
|
|
| 138 |
|
|
=cut |
| 139 |
|
|
|
| 140 |
|
|
sub text { $_[0]->{error_text} } |
| 141 |
|
|
|
| 142 |
|
|
sub string { |
| 143 |
|
|
my ($self) = @_; |
| 144 |
|
|
|
| 145 |
|
|
sprintf "stanza error: %s/%s (type %s): %s", |
| 146 |
|
|
$self->code || '', |
| 147 |
|
|
$self->condition || '', |
| 148 |
|
|
$self->type, |
| 149 |
|
|
$self->text |
| 150 |
|
|
} |
| 151 |
|
|
|
| 152 |
|
|
=back |
| 153 |
|
|
|
| 154 |
|
|
=cut |
| 155 |
|
|
|
| 156 |
|
|
|
| 157 |
|
|
=head1 AUTHOR |
| 158 |
|
|
|
| 159 |
|
|
Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >> |
| 160 |
|
|
|
| 161 |
|
|
=head1 COPYRIGHT & LICENSE |
| 162 |
|
|
|
| 163 |
|
|
Copyright 2007 Robin Redeker, all rights reserved. |
| 164 |
|
|
|
| 165 |
|
|
This program is free software; you can redistribute it and/or modify it |
| 166 |
|
|
under the same terms as Perl itself. |
| 167 |
|
|
|
| 168 |
|
|
=cut |
| 169 |
|
|
|
| 170 |
|
|
1; # End of Net::XMPP2 |