aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2008-04-23 13:14:08 +0000
committerAlexey Shchepin <alexey@process-one.net>2008-04-23 13:14:08 +0000
commitb1756e8e34826e26d814d54626d5642b49ebc859 (patch)
tree3ba5cf905d32c916b543e38ca0f237aae9eb50e2 /src
parent* src/mod_register.erl: Restrict registration frequency per IP or (diff)
* src/treap.erl: Bugfix
* src/mod_register.erl: Fixed table creation, timeout isn't activated when registration fails SVN Revision: 1300
Diffstat (limited to 'src')
-rw-r--r--src/mod_register.erl54
-rw-r--r--src/treap.erl2
2 files changed, 47 insertions, 9 deletions
diff --git a/src/mod_register.erl b/src/mod_register.erl
index b8f99df3f..36f3e5462 100644
--- a/src/mod_register.erl
+++ b/src/mod_register.erl
@@ -52,6 +52,7 @@ start(Host, Opts) ->
[{ram_copies, [node()]},
{local_content, true},
{attributes, [key, value]}]),
+ mnesia:add_table_copy(mod_register_ip, node(), ram_copies),
ok.
stop(Host) ->
@@ -212,14 +213,18 @@ try_register(User, Server, Password, Source) ->
send_welcome_message(JID),
send_registration_notifications(JID),
ok;
- {atomic, exists} ->
- {error, ?ERR_CONFLICT};
- {error, invalid_jid} ->
- {error, ?ERR_JID_MALFORMED};
- {error, not_allowed} ->
- {error, ?ERR_NOT_ALLOWED};
- {error, _Reason} ->
- {error, ?ERR_INTERNAL_SERVER_ERROR}
+ Error ->
+ remove_timeout(Source),
+ case Error of
+ {atomic, exists} ->
+ {error, ?ERR_CONFLICT};
+ {error, invalid_jid} ->
+ {error, ?ERR_JID_MALFORMED};
+ {error, not_allowed} ->
+ {error, ?ERR_NOT_ALLOWED};
+ {error, _Reason} ->
+ {error, ?ERR_INTERNAL_SERVER_ERROR}
+ end
end;
false ->
{error, ?ERR_RESOURCE_CONSTRAINT}
@@ -327,3 +332,36 @@ clean_treap(Treap, CleanPriority) ->
Treap
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.
+
diff --git a/src/treap.erl b/src/treap.erl
index d7b070b9e..48361d17d 100644
--- a/src/treap.erl
+++ b/src/treap.erl
@@ -103,7 +103,7 @@ heapify({HashKey, Priority, Value,
delete(Key, Tree) ->
HashKey = {erlang:phash2(Key), Key},
- delete1(Tree, HashKey).
+ delete1(HashKey, Tree).
delete1(HashKey, {HashKey1, Priority1, Value1, Left, Right} = Tree) ->
if