| 1 | package AnyEvent::XMPP::Error::MUC; | ||
| 2 | use AnyEvent::XMPP::Error; | ||
| 3 | use strict; | ||
| 4 | our @ISA = qw/AnyEvent::XMPP::Error/; | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | AnyEvent::XMPP::Error::MUC - MUC error | ||
| 9 | |||
| 10 | Subclass of L<AnyEvent::XMPP::Error> | ||
| 11 | |||
| 12 | =head2 METHODS | ||
| 13 | |||
| 14 | =over 4 | ||
| 15 | |||
| 16 | =cut | ||
| 17 | |||
| 18 | sub init { | ||
| 19 | my ($self) = @_; | ||
| 20 | if ($self->{presence_error}) { | ||
| 21 | my %mapping = ( | ||
| 22 | 'not-authorized' => 'password_required', | ||
| 23 | 'forbidden' => 'banned', | ||
| 24 | 'item-not-found' => 'room_locked', | ||
| 25 | 'not-allowed' => 'room_not_creatable', | ||
| 26 | 'not-acceptable' => 'use_reserved_nick', | ||
| 27 | 'registration-required' => 'not_on_memberlist', | ||
| 28 | 'conflict' => 'nickname_in_use', | ||
| 29 | 'service-unavailable' => 'room_full', | ||
| 30 | ); | ||
| 31 | my $cond = $self->{presence_error}->{error_cond}; | ||
| 32 | $self->{type} = $mapping{$cond}; | ||
| 33 | } | ||
| 34 | if ($self->{message_node}) { | ||
| 35 | my $error = AnyEvent::XMPP::Error::Message->new (node => $self->{message_node}); | ||
| 36 | |||
| 37 | if ($self->{message}->any_subject && not defined $self->{message}->any_body) { | ||
| 38 | $self->{type} = 'subject_change_forbidden'; | ||
| 39 | } else { | ||
| 40 | $self->{type} = 'message_error'; | ||
| 41 | } | ||
| 42 | |||
| 43 | $self->{message_error} = $error; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | =item B<type> | ||
| 48 | |||
| 49 | This method returns either: | ||
| 50 | |||
| 51 | =over 4 | ||
| 52 | |||
| 53 | =item join_timeout | ||
| 54 | |||
| 55 | If the joining of the room took too long. | ||
| 56 | |||
| 57 | =item no_config_form | ||
| 58 | |||
| 59 | If the room we requested the configuration from didn't provide a | ||
| 60 | data form. | ||
| 61 | |||
| 62 | =item subject_change_forbidden | ||
| 63 | |||
| 64 | If changing the subject of a room is not allowed. | ||
| 65 | |||
| 66 | =item message_error | ||
| 67 | |||
| 68 | If this is an unidentified message error. | ||
| 69 | |||
| 70 | =back | ||
| 71 | |||
| 72 | If we got a presence error the method C<presence_error> returns a | ||
| 73 | L<AnyEvent::XMPP::Error::Presence> object with further details. However, this class | ||
| 74 | tries to provide a mapping for you (the developer) to ease the load of figuring | ||
| 75 | out which error means what. To make identification of the errors with XEP-0045 | ||
| 76 | more clear I included the error codes and condition names. | ||
| 77 | |||
| 78 | Here are the more descriptive types: | ||
| 79 | |||
| 80 | =over 4 | ||
| 81 | |||
| 82 | =item password_required | ||
| 83 | |||
| 84 | Entering a room Inform user that a password is required. | ||
| 85 | |||
| 86 | (Condition: not-authorized, Code: 401) | ||
| 87 | |||
| 88 | =item banned | ||
| 89 | |||
| 90 | Entering a room Inform user that he or she is banned from the room | ||
| 91 | |||
| 92 | (Condition: forbidden, Code: 403) | ||
| 93 | |||
| 94 | =item room_locked | ||
| 95 | |||
| 96 | Entering a room Inform user that the room does not exist and someone | ||
| 97 | is currently creating it. | ||
| 98 | |||
| 99 | (Condition: item-not-found, Code: 404) | ||
| 100 | |||
| 101 | =item room_not_creatable | ||
| 102 | |||
| 103 | Entering a room Inform user that room creation is restricted | ||
| 104 | |||
| 105 | (Condition: not-allowed, Code: 405) | ||
| 106 | |||
| 107 | =item use_reserved_nick | ||
| 108 | |||
| 109 | Entering a room Inform user that the reserved roomnick must be used | ||
| 110 | |||
| 111 | (Condition: not-acceptable, Code: 406) | ||
| 112 | |||
| 113 | =item not_on_memberlist | ||
| 114 | |||
| 115 | Entering a room Inform user that he or she is not on the member list | ||
| 116 | |||
| 117 | (Condition: registration-required, Code: 407) | ||
| 118 | |||
| 119 | =item nickname_in_use | ||
| 120 | |||
| 121 | Entering a room Inform user that his or her desired room nickname is in use or registered by another user | ||
| 122 | |||
| 123 | (Condition: conflict, Code: 409) | ||
| 124 | |||
| 125 | =item room_full | ||
| 126 | |||
| 127 | Entering a room Inform user that the maximum number of users has been reached | ||
| 128 | |||
| 129 | (Condition: service-unavailable, Code: 503) | ||
| 130 | |||
| 131 | =back | ||
| 132 | |||
| 133 | The condition and code are also available through the L<AnyEvent::XMPP::Error::Presence> | ||
| 134 | object returned by C<presence_error>, see below. | ||
| 135 | |||
| 136 | =cut | ||
| 137 | |||
| 138 | sub type { $_[0]->{type} } | ||
| 139 | |||
| 140 | =item B<text> | ||
| 141 | |||
| 142 | This method returns a human readable text | ||
| 143 | if one is available. | ||
| 144 | |||
| 145 | =cut | ||
| 146 | |||
| 147 | sub text { | ||
| 148 | my ($self) = @_; | ||
| 149 | if (my $p = $self->presence_error) { | ||
| 150 | return $p->text; | ||
| 151 | } elsif (my $m = $self->message_error) { | ||
| 152 | return $m->text; | ||
| 153 | } else { | ||
| 154 | return $self->{text} | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | =item B<presence_error> | ||
| 159 | |||
| 160 | Returns a L<AnyEvent::XMPP::Error::Presence> object if this error | ||
| 161 | origins to such an error and not some internal error. | ||
| 162 | |||
| 163 | =cut | ||
| 164 | |||
| 165 | sub presence_error { $_[0]->{presence_error} } | ||
| 166 | |||
| 167 | =item B<message_error> | ||
| 168 | |||
| 169 | Returns a L<AnyEvent::XMPP::Error::Message> object if this error | ||
| 170 | origins to such an error and not some internal error. | ||
| 171 | |||
| 172 | =cut | ||
| 173 | |||
| 174 | sub message_error { $_[0]->{message_error} } | ||
| 175 | |||
| 176 | sub string { | ||
| 177 | my ($self) = @_; | ||
| 178 | |||
| 179 | sprintf "muc error: '%s': %s", | ||
| 180 | $self->type, | ||
| 181 | ( | ||
| 182 | $self->presence_error | ||
| 183 | ? $self->presence_error ()->string | ||
| 184 | : $self->text | ||
| 185 | ) | ||
| 186 | } | ||
| 187 | |||
| 188 | =back | ||
| 189 | |||
| 190 | =head1 AUTHOR | ||
| 191 | |||
| 192 | Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >> | ||
| 193 | |||
| 194 | =head1 COPYRIGHT & LICENSE | ||
| 195 | |||
| 196 | Copyright 2007, 2008 Robin Redeker, all rights reserved. | ||
| 197 | |||
| 198 | This program is free software; you can redistribute it and/or modify it | ||
| 199 | under the same terms as Perl itself. | ||
| 200 | |||
| 201 | =cut | ||
| 202 | |||
| 203 | 1; |