25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

* src/mod_muc/mod_muc_room.erl: Bugfix, updated error codes

(thanks to Sergei Golovan)

* src/jlib.hrl: Updated error codes (thanks to Sergei Golovan)

SVN Revision: 199
This commit is contained in:
Alexey Shchepin 2004-01-17 20:26:57 +00:00
parent c7d15b12df
commit 7a002470e6
3 changed files with 131 additions and 76 deletions

View File

@ -1,3 +1,10 @@
2004-01-17 Alexey Shchepin <alexey@sevcom.net>
* src/mod_muc/mod_muc_room.erl: Bugfix, updated error codes
(thanks to Sergei Golovan)
* src/jlib.hrl: Updated error codes (thanks to Sergei Golovan)
2004-01-11 Alexey Shchepin <alexey@sevcom.net> 2004-01-11 Alexey Shchepin <alexey@sevcom.net>
* src/ejabberd_c2s.erl: Fixed bind namespace * src/ejabberd_c2s.erl: Fixed bind namespace

View File

@ -49,37 +49,47 @@
[{xmlelement, Condition, [{"xmlns", ?NS_STANZAS}], []}]}). [{xmlelement, Condition, [{"xmlns", ?NS_STANZAS}], []}]}).
-define(ERR_BAD_REQUEST, -define(ERR_BAD_REQUEST,
?STANZA_ERROR("400", "modify", "bad-request")). ?STANZA_ERROR("400", "modify", "bad-request")).
-define(ERR_CONFLICT, -define(ERR_CONFLICT,
?STANZA_ERROR("409", "cancel", "conflict")). ?STANZA_ERROR("409", "cancel", "conflict")).
-define(ERR_FEATURE_NOT_IMPLEMENTED, -define(ERR_FEATURE_NOT_IMPLEMENTED,
?STANZA_ERROR("501", "cancel", "feature-not-implemented")). ?STANZA_ERROR("501", "cancel", "feature-not-implemented")).
-define(ERR_FORBIDDEN, -define(ERR_FORBIDDEN,
?STANZA_ERROR("403", "auth", "forbidden")). ?STANZA_ERROR("403", "auth", "forbidden")).
-define(ERR_GONE,
?STANZA_ERROR("302", "modify", "gone")).
-define(ERR_INTERNAL_SERVER_ERROR, -define(ERR_INTERNAL_SERVER_ERROR,
?STANZA_ERROR("500", "wait", "internal-server-error")). ?STANZA_ERROR("500", "wait", "internal-server-error")).
-define(ERR_ITEM_NOT_FOUND, -define(ERR_ITEM_NOT_FOUND,
?STANZA_ERROR("404", "cancel", "item-not-found")). ?STANZA_ERROR("404", "cancel", "item-not-found")).
-define(ERR_JID_MALFORMED, -define(ERR_JID_MALFORMED,
?STANZA_ERROR("400", "modify", "jid-malformed")). ?STANZA_ERROR("400", "modify", "jid-malformed")).
-define(ERR_NOT_ACCEPTABLE,
?STANZA_ERROR("406", "modify", "not-acceptable")).
-define(ERR_NOT_ALLOWED, -define(ERR_NOT_ALLOWED,
?STANZA_ERROR("405", "cancel", "not-allowed")). ?STANZA_ERROR("405", "cancel", "not-allowed")).
-define(ERR_NOT_AUTHORIZED,
?STANZA_ERROR("401", "auth", "not-authorized")).
-define(ERR_PAYMENT_REQUIRED,
?STANZA_ERROR("402", "auth", "payment-required")).
-define(ERR_RECIPIENT_UNAVAILABLE, -define(ERR_RECIPIENT_UNAVAILABLE,
?STANZA_ERROR("404", "wait", "recipient-unavailable")). ?STANZA_ERROR("404", "wait", "recipient-unavailable")).
-define(ERR_REDIRECT,
?STANZA_ERROR("302", "modify", "redirect")).
-define(ERR_REGISTRATION_REQUIRED, -define(ERR_REGISTRATION_REQUIRED,
?STANZA_ERROR("407", "auth", "registration-required")). ?STANZA_ERROR("407", "auth", "registration-required")).
-define(ERR_REMOTE_SERVER_NOT_FOUND, -define(ERR_REMOTE_SERVER_NOT_FOUND,
?STANZA_ERROR("404", "cancel", "remote-server-not-found")). ?STANZA_ERROR("404", "cancel", "remote-server-not-found")).
-define(ERR_REMOTE_SERVER_TIMEOUT, -define(ERR_REMOTE_SERVER_TIMEOUT,
?STANZA_ERROR("504", "wait", "remote-server-timeout")). ?STANZA_ERROR("504", "wait", "remote-server-timeout")).
-define(ERR_RESOURCE_CONSTRAINT, -define(ERR_RESOURCE_CONSTRAINT,
?STANZA_ERROR("0", "wait", "resource-constraint")). ?STANZA_ERROR("500", "wait", "resource-constraint")).
-define(ERR_SERVICE_UNAVAILABLE, -define(ERR_SERVICE_UNAVAILABLE,
?STANZA_ERROR("503", "cancel", "service-unavailable")). ?STANZA_ERROR("503", "cancel", "service-unavailable")).
-define(ERR_SUBSCRIPTION_REQUIRED, -define(ERR_SUBSCRIPTION_REQUIRED,
?STANZA_ERROR("0", "auth", "subscription-required")). ?STANZA_ERROR("407", "auth", "subscription-required")).
-define(ERR_UNEXPECTED_REQUEST, -define(ERR_UNEXPECTED_REQUEST,
?STANZA_ERROR("0", "wait", "unexpected-request")). ?STANZA_ERROR("400", "wait", "unexpected-request")).
%-define(ERR_, %-define(ERR_,
% ?STANZA_ERROR("", "", "")). % ?STANZA_ERROR("", "", "")).
@ -103,8 +113,16 @@
-define(STREAM_ERROR(Condition), -define(STREAM_ERROR(Condition),
{xmlelement, "stream:error", {xmlelement, "stream:error",
[], [],
[{xmlelement, Condition, [{"xmlns", ?NS_STANZAS}], []}]}). [{xmlelement, Condition, [{"xmlns", ?NS_STREAMS}], []}]}).
-define(SERR_BAD_FORMAT,
?STREAM_ERROR("bad-format")).
-define(SERR_BAD_NAMESPACE_PREFIX,
?STREAM_ERROR("bad-namespace-prefix")).
-define(SERR_CONFLICT,
?STREAM_ERROR("conflict")).
-define(SERR_CONNECTION_TIMEOUT,
?STREAM_ERROR("connection-timeout")).
-define(SERR_HOST_GONE, -define(SERR_HOST_GONE,
?STREAM_ERROR("host-gone")). ?STREAM_ERROR("host-gone")).
-define(SERR_HOST_UNKNOWN, -define(SERR_HOST_UNKNOWN,
@ -113,23 +131,31 @@
?STREAM_ERROR("improper-addressing")). ?STREAM_ERROR("improper-addressing")).
-define(SERR_INTERNAL_SERVER_ERROR, -define(SERR_INTERNAL_SERVER_ERROR,
?STREAM_ERROR("internal-server-error")). ?STREAM_ERROR("internal-server-error")).
-define(SERR_INVALID_FROM,
?STREAM_ERROR("invalid-from")).
-define(SERR_INVALID_ID, -define(SERR_INVALID_ID,
?STREAM_ERROR("invalid-id")). ?STREAM_ERROR("invalid-id")).
-define(SERR_INVALID_NAMESPACE, -define(SERR_INVALID_NAMESPACE,
?STREAM_ERROR("invalid-namespace")). ?STREAM_ERROR("invalid-namespace")).
-define(SERR_NONMATCHING_HOSTS, -define(SERR_INVALID_XML,
?STREAM_ERROR("nonmatching-hosts")). ?STREAM_ERROR("invalid-xml")).
-define(SERR_NOT_AUTHORIZED, -define(SERR_NOT_AUTHORIZED,
?STREAM_ERROR("not-authorized")). ?STREAM_ERROR("not-authorized")).
-define(SERR_POLICY_VIOLATION,
?STREAM_ERROR("policy-violation")).
-define(SERR_REMOTE_CONNECTION_FAILED, -define(SERR_REMOTE_CONNECTION_FAILED,
?STREAM_ERROR("remote-connection-failed")). ?STREAM_ERROR("remote-connection-failed")).
-define(SERR_RESOURSE_CONSTRAINT, -define(SERR_RESOURSE_CONSTRAINT,
?STREAM_ERROR("resource-constraint")). ?STREAM_ERROR("resource-constraint")).
-define(SERR_RESTRICTED_XML,
?STREAM_ERROR("restricted-xml")).
% TODO: include hostname or IP % TODO: include hostname or IP
-define(SERR_SEE_OTHER_HOST, -define(SERR_SEE_OTHER_HOST,
?STREAM_ERROR("see-other-host")). ?STREAM_ERROR("see-other-host")).
-define(SERR_SYSTEM_SHUTDOWN, -define(SERR_SYSTEM_SHUTDOWN,
?STREAM_ERROR("system-shutdown")). ?STREAM_ERROR("system-shutdown")).
-define(SERR_UNSUPPORTED_ENCODING,
?STREAM_ERROR("unsupported-encoding")).
-define(SERR_UNSUPPORTED_STANZA_TYPE, -define(SERR_UNSUPPORTED_STANZA_TYPE,
?STREAM_ERROR("unsupported-stanza-type")). ?STREAM_ERROR("unsupported-stanza-type")).
-define(SERR_UNSUPPORTED_VERSION, -define(SERR_UNSUPPORTED_VERSION,

View File

@ -68,23 +68,6 @@
subject_author = ""}). subject_author = ""}).
-define(OLD_ERROR(Code, Desc),
{xmlelement, "error",
[{"code", Code}],
[{xmlcdata, Desc}]}).
-define(ERR_MUC_NICK_CONFLICT,
?OLD_ERROR("409", "Please choose a different nickname.")).
-define(ERR_MUC_NICK_CHANGE_CONFLICT,
?OLD_ERROR("409", "Nickname already in use.")).
-define(ERR_MUC_BANNED,
?OLD_ERROR("403", "You have been banned from this room.")).
-define(ERR_MUC_NOT_MEMBER,
?OLD_ERROR("407", "Membership required to enter this room.")).
-define(ERR_MUC_BAD_PASSWORD,
?OLD_ERROR("401", "Bad password.")).
%-define(DBGFSM, true). %-define(DBGFSM, true).
-ifdef(DBGFSM). -ifdef(DBGFSM).
@ -357,7 +340,7 @@ normal_state({route, From, Nick,
true -> true ->
Err = jlib:make_error_reply( Err = jlib:make_error_reply(
Packet, Packet,
?ERR_MUC_NICK_CHANGE_CONFLICT), ?ERR_CONFLICT),
ejabberd_router:route( ejabberd_router:route(
jlib:jid_replace_resource( jlib:jid_replace_resource(
StateData#state.jid, StateData#state.jid,
@ -392,7 +375,8 @@ normal_state({route, From, Nick,
normal_state({route, From, ToNick, normal_state({route, From, ToNick,
{xmlelement, "message", Attrs, Els} = Packet}, {xmlelement, "message", Attrs, Els} = Packet},
StateData) -> StateData) ->
case xml:get_attr_s("type", Attrs) of Type = xml:get_attr_s("type", Attrs),
case Type of
"error" -> "error" ->
case is_user_online(From, StateData) of case is_user_online(From, StateData) of
true -> true ->
@ -412,35 +396,46 @@ normal_state({route, From, ToNick,
case (StateData#state.config)#config.allow_private_messages case (StateData#state.config)#config.allow_private_messages
andalso is_user_online(From, StateData) of andalso is_user_online(From, StateData) of
true -> true ->
case find_jid_by_nick(ToNick, StateData) of case Type of
false -> "groupchat" ->
Err = jlib:make_error_reply( Err = jlib:make_error_reply(
Packet, ?ERR_ITEM_NOT_FOUND), Packet, ?ERR_BAD_REQUEST),
ejabberd_router:route( ejabberd_router:route(
jlib:jid_replace_resource( jlib:jid_replace_resource(
StateData#state.jid, StateData#state.jid,
ToNick), ToNick),
From, Err); From, Err);
ToJID -> _ ->
{ok, #user{nick = FromNick}} = case find_jid_by_nick(ToNick, StateData) of
?DICT:find(jlib:jid_tolower(From), false ->
StateData#state.users), Err = jlib:make_error_reply(
ejabberd_router:route( Packet, ?ERR_ITEM_NOT_FOUND),
jlib:jid_replace_resource( ejabberd_router:route(
StateData#state.jid, jlib:jid_replace_resource(
FromNick), StateData#state.jid,
ToJID, Packet) ToNick),
end, From, Err);
{next_state, normal_state, StateData}; ToJID ->
{ok, #user{nick = FromNick}} =
?DICT:find(jlib:jid_tolower(From),
StateData#state.users),
ejabberd_router:route(
jlib:jid_replace_resource(
StateData#state.jid,
FromNick),
ToJID, Packet)
end
end;
_ -> _ ->
Err = jlib:make_error_reply( Err = jlib:make_error_reply(
Packet, ?ERR_NOT_ALLOWED), Packet, ?ERR_NOT_ALLOWED),
ejabberd_router:route( ejabberd_router:route(
jlib:jid_replace_resource( jlib:jid_replace_resource(
StateData#state.jid, StateData#state.jid,
ToNick), From, Err), ToNick),
{next_state, normal_state, StateData} From, Err)
end end,
{next_state, normal_state, StateData}
end; end;
normal_state({route, From, ToNick, normal_state({route, From, ToNick,
@ -806,7 +801,7 @@ add_new_user(From, Nick, {xmlelement, _, Attrs, Els} = Packet, StateData) ->
case is_nick_exists(Nick, StateData) or case is_nick_exists(Nick, StateData) or
not mod_muc:can_use_nick(From, Nick) of not mod_muc:can_use_nick(From, Nick) of
true -> true ->
Err = jlib:make_error_reply(Packet, ?ERR_MUC_NICK_CONFLICT), Err = jlib:make_error_reply(Packet, ?ERR_CONFLICT),
ejabberd_router:route( ejabberd_router:route(
% TODO: s/Nick/""/ % TODO: s/Nick/""/
jlib:jid_replace_resource(StateData#state.jid, Nick), jlib:jid_replace_resource(StateData#state.jid, Nick),
@ -820,8 +815,8 @@ add_new_user(From, Nick, {xmlelement, _, Attrs, Els} = Packet, StateData) ->
Err = jlib:make_error_reply( Err = jlib:make_error_reply(
Packet, Packet,
case Affiliation of case Affiliation of
outcast -> ?ERR_MUC_BANNED; outcast -> ?ERR_FORBIDDEN;
_ -> ?ERR_MUC_NOT_MEMBER _ -> ?ERR_REGISTRATION_REQUIRED
end), end),
ejabberd_router:route( % TODO: s/Nick/""/ ejabberd_router:route( % TODO: s/Nick/""/
jlib:jid_replace_resource(StateData#state.jid, Nick), jlib:jid_replace_resource(StateData#state.jid, Nick),
@ -846,7 +841,7 @@ add_new_user(From, Nick, {xmlelement, _, Attrs, Els} = Packet, StateData) ->
NewState; NewState;
_ -> _ ->
Err = jlib:make_error_reply( Err = jlib:make_error_reply(
Packet, ?ERR_MUC_BAD_PASSWORD), Packet, ?ERR_NOT_AUTHORIZED),
ejabberd_router:route( % TODO: s/Nick/""/ ejabberd_router:route( % TODO: s/Nick/""/
jlib:jid_replace_resource( jlib:jid_replace_resource(
StateData#state.jid, Nick), StateData#state.jid, Nick),
@ -1412,10 +1407,6 @@ find_changed_items(UJID, UAffiliation, URole, Items, StateData, Res) ->
{error, ?ERR_BAD_REQUEST}. {error, ?ERR_BAD_REQUEST}.
can_change_ra(FAffiliation, FRole, can_change_ra(FAffiliation, FRole,
TAffiliation, TRole, TAffiliation, TRole,
affiliation, Value) affiliation, Value)
@ -1510,9 +1501,20 @@ can_change_ra(FAffiliation, FRole,
when (FAffiliation == owner) or (FAffiliation == admin) -> when (FAffiliation == owner) or (FAffiliation == admin) ->
true; true;
can_change_ra(FAffiliation, FRole, can_change_ra(FAffiliation, FRole,
owner, moderator,
role, participant) ->
false;
can_change_ra(owner, FRole,
TAffiliation, moderator, TAffiliation, moderator,
role, participant) role, participant) ->
when (FAffiliation == owner) or (FAffiliation == admin) -> true;
can_change_ra(FAffiliation, FRole,
admin, moderator,
role, participant) ->
false;
can_change_ra(admin, FRole,
TAffiliation, moderator,
role, participant) ->
true; true;
can_change_ra(FAffiliation, FRole, can_change_ra(FAffiliation, FRole,
TAffiliation, TRole, TAffiliation, TRole,
@ -1736,7 +1738,6 @@ set_config(XEl, StateData) ->
set_xoption(Opts, Config#config{Opt = Val})). set_xoption(Opts, Config#config{Opt = Val})).
set_xoption([], Config) -> set_xoption([], Config) ->
Config; Config;
set_xoption([{"title", [Val]} | Opts], Config) -> set_xoption([{"title", [Val]} | Opts], Config) ->
@ -1871,16 +1872,40 @@ destroy_room(DEls, StateData) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Disco % Disco
-define(FEATURE(Var), {xmlelement, "feature", [{"var", Var}], []}).
-define(CONFIG_OPT_TO_FEATURE(Opt, Fiftrue, Fiffalse),
case Opt of
true ->
?FEATURE(Fiftrue);
false ->
?FEATURE(Fiffalse)
end).
process_iq_disco_info(From, set, StateData) -> process_iq_disco_info(From, set, StateData) ->
{error, ?ERR_NOT_ALLOWED}; {error, ?ERR_NOT_ALLOWED};
process_iq_disco_info(From, get, StateData) -> process_iq_disco_info(From, get, StateData) ->
Config = StateData#state.config,
{result, [{xmlelement, "identity", {result, [{xmlelement, "identity",
[{"category", "conference"}, [{"category", "conference"},
{"type", "text"}, {"type", "text"},
{"name", get_title(StateData)}], []}, {"name", get_title(StateData)}], []},
{xmlelement, "feature", {xmlelement, "feature",
[{"var", ?NS_MUC}], []}], StateData}. [{"var", ?NS_MUC}], []},
?CONFIG_OPT_TO_FEATURE(Config#config.public,
"muc_public", "muc_hidden"),
?CONFIG_OPT_TO_FEATURE(Config#config.persistent,
"muc_persistent", "muc_temporary"),
?CONFIG_OPT_TO_FEATURE(Config#config.members_only,
"muc_membersonly", "muc_open"),
?CONFIG_OPT_TO_FEATURE(Config#config.anonymous,
"muc_semianonymous", "muc_nonanonymous"),
?CONFIG_OPT_TO_FEATURE(Config#config.moderated,
"muc_moderated", "muc_unmoderated"),
?CONFIG_OPT_TO_FEATURE(Config#config.password_protected,
"muc_passwordprotected", "muc_unsecured")
], StateData}.
process_iq_disco_items(From, set, StateData) -> process_iq_disco_items(From, set, StateData) ->
@ -1985,6 +2010,3 @@ check_invitation(From, Els, StateData) ->
error error
end. end.