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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
package AnyEvent::XMPP::Error::MUC;
use AnyEvent::XMPP::Error;
use strict;
our @ISA = qw/AnyEvent::XMPP::Error/;
=head1 NAME
AnyEvent::XMPP::Error::MUC - MUC error
Subclass of L<AnyEvent::XMPP::Error>
=head2 METHODS
=over 4
=cut
sub init {
my ($self) = @_;
if ($self->{presence_error}) {
my %mapping = (
'not-authorized' => 'password_required',
'forbidden' => 'banned',
'item-not-found' => 'room_locked',
'not-allowed' => 'room_not_creatable',
'not-acceptable' => 'use_reserved_nick',
'registration-required' => 'not_on_memberlist',
'conflict' => 'nickname_in_use',
'service-unavailable' => 'room_full',
);
my $cond = $self->{presence_error}->{error_cond};
$self->{type} = $mapping{$cond};
}
if ($self->{message_node}) {
my $error = AnyEvent::XMPP::Error::Message->new (node => $self->{message_node});
if ($self->{message}->any_subject && not defined $self->{message}->any_body) {
$self->{type} = 'subject_change_forbidden';
} else {
$self->{type} = 'message_error';
}
$self->{message_error} = $error;
}
}
=item B<type>
This method returns either:
=over 4
=item join_timeout
If the joining of the room took too long.
=item no_config_form
If the room we requested the configuration from didn't provide a
data form.
=item subject_change_forbidden
If changing the subject of a room is not allowed.
=item message_error
If this is an unidentified message error.
=back
If we got a presence error the method C<presence_error> returns a
L<AnyEvent::XMPP::Error::Presence> object with further details. However, this class
tries to provide a mapping for you (the developer) to ease the load of figuring
out which error means what. To make identification of the errors with XEP-0045
more clear I included the error codes and condition names.
Here are the more descriptive types:
=over 4
=item password_required
Entering a room Inform user that a password is required.
(Condition: not-authorized, Code: 401)
=item banned
Entering a room Inform user that he or she is banned from the room
(Condition: forbidden, Code: 403)
=item room_locked
Entering a room Inform user that the room does not exist and someone
is currently creating it.
(Condition: item-not-found, Code: 404)
=item room_not_creatable
Entering a room Inform user that room creation is restricted
(Condition: not-allowed, Code: 405)
=item use_reserved_nick
Entering a room Inform user that the reserved roomnick must be used
(Condition: not-acceptable, Code: 406)
=item not_on_memberlist
Entering a room Inform user that he or she is not on the member list
(Condition: registration-required, Code: 407)
=item nickname_in_use
Entering a room Inform user that his or her desired room nickname is in use or registered by another user
(Condition: conflict, Code: 409)
=item room_full
Entering a room Inform user that the maximum number of users has been reached
(Condition: service-unavailable, Code: 503)
=back
The condition and code are also available through the L<AnyEvent::XMPP::Error::Presence>
object returned by C<presence_error>, see below.
=cut
sub type { $_[0]->{type} }
=item B<text>
This method returns a human readable text
if one is available.
=cut
sub text {
my ($self) = @_;
if (my $p = $self->presence_error) {
return $p->text;
} elsif (my $m = $self->message_error) {
return $m->text;
} else {
return $self->{text}
}
}
=item B<presence_error>
Returns a L<AnyEvent::XMPP::Error::Presence> object if this error
origins to such an error and not some internal error.
=cut
sub presence_error { $_[0]->{presence_error} }
=item B<message_error>
Returns a L<AnyEvent::XMPP::Error::Message> object if this error
origins to such an error and not some internal error.
=cut
sub message_error { $_[0]->{message_error} }
sub string {
my ($self) = @_;
sprintf "muc error: '%s': %s",
$self->type,
(
$self->presence_error
? $self->presence_error ()->string
: $self->text
)
}
=back
=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;
|