24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-12 21:52:07 +02:00

* src/treap.erl: Bugfix

* src/mod_register.erl: Fixed table creation, timeout isn't
activated when registration fails

SVN Revision: 1300
This commit is contained in:
Alexey Shchepin 2008-04-23 13:14:08 +00:00
parent 797544333c
commit b1756e8e34
3 changed files with 52 additions and 9 deletions

View File

@ -1,5 +1,10 @@
2008-04-23 Alexey Shchepin <alexey@process-one.net> 2008-04-23 Alexey Shchepin <alexey@process-one.net>
* src/treap.erl: Bugfix
* src/mod_register.erl: Fixed table creation, timeout isn't
activated when registration fails
* src/mod_register.erl: Restrict registration frequency per IP or * src/mod_register.erl: Restrict registration frequency per IP or
user user
* src/ejabberd_c2s.erl: Pass IP to the c2s_unauthenticated_iq hook * src/ejabberd_c2s.erl: Pass IP to the c2s_unauthenticated_iq hook

View File

@ -52,6 +52,7 @@ start(Host, Opts) ->
[{ram_copies, [node()]}, [{ram_copies, [node()]},
{local_content, true}, {local_content, true},
{attributes, [key, value]}]), {attributes, [key, value]}]),
mnesia:add_table_copy(mod_register_ip, node(), ram_copies),
ok. ok.
stop(Host) -> stop(Host) ->
@ -212,14 +213,18 @@ try_register(User, Server, Password, Source) ->
send_welcome_message(JID), send_welcome_message(JID),
send_registration_notifications(JID), send_registration_notifications(JID),
ok; ok;
{atomic, exists} -> Error ->
{error, ?ERR_CONFLICT}; remove_timeout(Source),
{error, invalid_jid} -> case Error of
{error, ?ERR_JID_MALFORMED}; {atomic, exists} ->
{error, not_allowed} -> {error, ?ERR_CONFLICT};
{error, ?ERR_NOT_ALLOWED}; {error, invalid_jid} ->
{error, _Reason} -> {error, ?ERR_JID_MALFORMED};
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, not_allowed} ->
{error, ?ERR_NOT_ALLOWED};
{error, _Reason} ->
{error, ?ERR_INTERNAL_SERVER_ERROR}
end
end; end;
false -> false ->
{error, ?ERR_RESOURCE_CONSTRAINT} {error, ?ERR_RESOURCE_CONSTRAINT}
@ -327,3 +332,36 @@ clean_treap(Treap, CleanPriority) ->
Treap Treap
end end
end. end.
remove_timeout(undefined) ->
true;
remove_timeout(Source) ->
Timeout = case ejabberd_config:get_local_option(registration_timeout) of
undefined -> 600;
TO -> TO
end,
if
is_integer(Timeout) ->
F = fun() ->
Treap = case mnesia:read(mod_register_ip, treap,
write) of
[] ->
treap:empty();
[{mod_register_ip, treap, T}] -> T
end,
Treap1 = treap:delete(Source, Treap),
mnesia:write({mod_register_ip, treap, Treap1}),
ok
end,
case mnesia:transaction(F) of
{atomic, ok} ->
ok;
{aborted, Reason} ->
?ERROR_MSG("mod_register: timeout remove error: ~p~n",
[Reason]),
ok
end;
true ->
ok
end.

View File

@ -103,7 +103,7 @@ heapify({HashKey, Priority, Value,
delete(Key, Tree) -> delete(Key, Tree) ->
HashKey = {erlang:phash2(Key), Key}, HashKey = {erlang:phash2(Key), Key},
delete1(Tree, HashKey). delete1(HashKey, Tree).
delete1(HashKey, {HashKey1, Priority1, Value1, Left, Right} = Tree) -> delete1(HashKey, {HashKey1, Priority1, Value1, Left, Right} = Tree) ->
if if