summaryrefslogtreecommitdiff
path: root/src/mod_caps.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mod_caps.erl')
-rw-r--r--src/mod_caps.erl36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/mod_caps.erl b/src/mod_caps.erl
index 13b8e1a7..408415bb 100644
--- a/src/mod_caps.erl
+++ b/src/mod_caps.erl
@@ -35,6 +35,7 @@
note_caps/3,
clear_caps/1,
get_features/2,
+ get_user_resource/2,
handle_disco_response/3]).
%% gen_mod callbacks
@@ -60,6 +61,7 @@
-record(caps, {node, version, exts}).
-record(caps_features, {node_pair, features}).
-record(user_caps, {jid, caps}).
+-record(user_caps_default, {uid, resource}).
-record(state, {host,
disco_requests = ?DICT:new(),
feature_queries = []}).
@@ -103,7 +105,26 @@ get_caps(JID) ->
%% clear_caps removes user caps from database
clear_caps(JID) ->
- catch mnesia:dirty_delete({user_caps, list_to_binary(jlib:jid_to_string(JID))}).
+ {U, S, R} = jlib:jid_tolower(JID),
+ BJID = list_to_binary(jlib:jid_to_string(JID)),
+ BUID = list_to_binary(jlib:jid_to_string({U, S, []})),
+ catch mnesia:dirty_delete({user_caps, BJID}),
+ case catch mnesia:dirty_read({user_caps_default, BUID}) of
+ [#user_caps_default{resource=R}] ->
+ catch mnesia:dirty_delete({user_caps_default, BUID});
+ _ ->
+ ok
+ end.
+
+%% give default user resource
+get_user_resource(LUser, LServer) ->
+ BUID = list_to_binary(jlib:jid_to_string({LUser, LServer, []})),
+ case catch mnesia:dirty_read({user_caps_default, BUID}) of
+ [#user_caps_default{resource=R}] ->
+ R;
+ _ ->
+ []
+ end.
%% note_caps should be called to make the module request disco
%% information. Host is the host that asks, From is the full JID that
@@ -122,7 +143,8 @@ note_caps(Host, From, Caps) ->
%% timeout error.
get_features(Host, Caps) ->
case Caps of
- nothing -> [];
+ nothing ->
+ [];
#caps{} ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:call(Proc, {get_features, Caps})
@@ -158,6 +180,9 @@ init([Host, _Opts]) ->
mnesia:create_table(user_caps,
[{disc_copies, [node()]},
{attributes, record_info(fields, user_caps)}]),
+ mnesia:create_table(user_caps_default,
+ [{disc_copies, [node()]},
+ {attributes, record_info(fields, user_caps_default)}]),
{ok, #state{host = Host}}.
maybe_get_features(#caps{node = Node, version = Version, exts = Exts}) ->
@@ -209,8 +234,11 @@ handle_cast({note_caps, From,
#state{host = Host, disco_requests = Requests} = State) ->
%% XXX: this leads to race conditions where ejabberd will send
%% lots of caps disco requests.
- mnesia:dirty_write(#user_caps{jid = list_to_binary(jlib:jid_to_string(From)),
- caps = Caps}),
+ {_, _, R} = jlib:jid_tolower(From),
+ BJID = list_to_binary(jlib:jid_to_string(From)),
+ BUID = list_to_binary(jlib:jid_to_string(jlib:jid_remove_resource(From))),
+ mnesia:dirty_write(#user_caps{jid = BJID, caps = Caps}),
+ mnesia:dirty_write(#user_caps_default{uid = BUID, resource = R}),
SubNodes = [Version | Exts],
%% Now, find which of these are not already in the database.
Fun = fun() ->