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