-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved subdomain handling with dedicated registry #1116
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,8 +49,6 @@ | |
room_process_mam_iq/3, | ||
forget_room/2]). | ||
|
||
-export([server_host/1]). | ||
|
||
%% private | ||
-export([archive_message/8]). | ||
-export([lookup_messages/13]). | ||
|
@@ -140,104 +138,68 @@ max_result_limit() -> 50. | |
%% API | ||
|
||
-spec delete_archive(ejabberd:server(), ejabberd:user()) -> 'ok'. | ||
delete_archive(Server, User) | ||
when is_binary(Server), is_binary(User) -> | ||
?DEBUG("Remove user ~p from ~p.", [User, Server]), | ||
ArcJID = jid:make(User, Server, <<>>), | ||
Host = server_host(ArcJID), | ||
delete_archive(SubHost, RoomName) when is_binary(SubHost), is_binary(RoomName) -> | ||
?DEBUG("Remove room ~p from ~p.", [RoomName, SubHost]), | ||
ArcJID = jid:make(RoomName, SubHost, <<>>), | ||
{ok, Host} = mongoose_subhosts:get_host(SubHost), | ||
ArcID = archive_id_int(Host, ArcJID), | ||
remove_archive(Host, ArcID, ArcJID), | ||
ok. | ||
|
||
|
||
-spec archive_size(ejabberd:server(), ejabberd:user()) -> integer(). | ||
archive_size(Server, User) | ||
when is_binary(Server), is_binary(User) -> | ||
ArcJID = jid:make(User, Server, <<>>), | ||
Host = server_host(ArcJID), | ||
archive_size(SubHost, RoomName) when is_binary(SubHost), is_binary(RoomName) -> | ||
ArcJID = jid:make(RoomName, SubHost, <<>>), | ||
{ok, Host} = mongoose_subhosts:get_host(SubHost), | ||
ArcID = archive_id_int(Host, ArcJID), | ||
archive_size(Host, ArcID, ArcJID). | ||
|
||
|
||
-spec archive_id(ejabberd:server(), ejabberd:user()) -> integer(). | ||
archive_id(Server, User) | ||
when is_binary(Server), is_binary(User) -> | ||
ArcJID = jid:make(User, Server, <<>>), | ||
Host = server_host(ArcJID), | ||
archive_id(SubHost, RoomName) when is_binary(SubHost), is_binary(RoomName) -> | ||
ArcJID = jid:make(RoomName, SubHost, <<>>), | ||
{ok, Host} = mongoose_subhosts:get_host(SubHost), | ||
archive_id_int(Host, ArcJID). | ||
|
||
%% ---------------------------------------------------------------------- | ||
%% gen_mod callbacks | ||
%% Starting and stopping functions for MUC archives | ||
|
||
-spec start(Host :: ejabberd:server(), Opts :: list()) -> any(). | ||
start(ServerHost, Opts) -> | ||
start(Host, Opts) -> | ||
?DEBUG("mod_mam_muc starting", []), | ||
compile_params_module(Opts), | ||
%% MUC host. | ||
Host = gen_mod:get_opt_host(ServerHost, Opts, <<"conference.@HOST@">>), | ||
start_host_mapping(Host, ServerHost), | ||
MUCHost = gen_mod:get_opt_subhost(Host, Opts, mod_muc:default_host()), | ||
IQDisc = gen_mod:get_opt(iqdisc, Opts, parallel), %% Type | ||
mod_disco:register_feature(Host, ?NS_MAM), | ||
mod_disco:register_feature(Host, ?NS_MAM_03), | ||
mod_disco:register_feature(Host, ?NS_MAM_04), | ||
gen_iq_handler:add_iq_handler(mod_muc_iq, Host, ?NS_MAM, | ||
mod_disco:register_feature(MUCHost, ?NS_MAM), | ||
mod_disco:register_feature(MUCHost, ?NS_MAM_03), | ||
mod_disco:register_feature(MUCHost, ?NS_MAM_04), | ||
gen_iq_handler:add_iq_handler(mod_muc_iq, MUCHost, ?NS_MAM, | ||
?MODULE, room_process_mam_iq, IQDisc), | ||
gen_iq_handler:add_iq_handler(mod_muc_iq, Host, ?NS_MAM_03, | ||
gen_iq_handler:add_iq_handler(mod_muc_iq, MUCHost, ?NS_MAM_03, | ||
?MODULE, room_process_mam_iq, IQDisc), | ||
gen_iq_handler:add_iq_handler(mod_muc_iq, Host, ?NS_MAM_04, | ||
gen_iq_handler:add_iq_handler(mod_muc_iq, MUCHost, ?NS_MAM_04, | ||
?MODULE, room_process_mam_iq, IQDisc), | ||
ejabberd_hooks:add(filter_room_packet, Host, ?MODULE, | ||
ejabberd_hooks:add(filter_room_packet, MUCHost, ?MODULE, | ||
filter_room_packet, 90), | ||
ejabberd_hooks:add(forget_room, Host, ?MODULE, forget_room, 90), | ||
ejabberd_hooks:add(forget_room, MUCHost, ?MODULE, forget_room, 90), | ||
ok. | ||
|
||
-spec stop(Host :: ejabberd:server()) -> any(). | ||
stop(ServerHost) -> | ||
%% MUC host. | ||
Host = gen_mod:get_module_opt_host( | ||
ServerHost, ?MODULE, <<"conference.@HOST@">>), | ||
stop(Host) -> | ||
MUCHost = gen_mod:get_module_opt_subhost(Host, mod_mam_muc, mod_muc:default_host()), | ||
?DEBUG("mod_mam stopping", []), | ||
ejabberd_hooks:delete(filter_room_packet, Host, ?MODULE, filter_room_packet, 90), | ||
ejabberd_hooks:delete(forget_room, Host, ?MODULE, forget_room, 90), | ||
gen_iq_handler:remove_iq_handler(mod_muc_iq, Host, ?NS_MAM), | ||
gen_iq_handler:remove_iq_handler(mod_muc_iq, Host, ?NS_MAM_03), | ||
gen_iq_handler:remove_iq_handler(mod_muc_iq, Host, ?NS_MAM_04), | ||
mod_disco:unregister_feature(Host, ?NS_MAM), | ||
mod_disco:unregister_feature(Host, ?NS_MAM_03), | ||
mod_disco:unregister_feature(Host, ?NS_MAM_04), | ||
stop_host_mapping(Host, ServerHost), | ||
ejabberd_hooks:delete(filter_room_packet, MUCHost, ?MODULE, filter_room_packet, 90), | ||
ejabberd_hooks:delete(forget_room, MUCHost, ?MODULE, forget_room, 90), | ||
gen_iq_handler:remove_iq_handler(mod_muc_iq, MUCHost, ?NS_MAM), | ||
gen_iq_handler:remove_iq_handler(mod_muc_iq, MUCHost, ?NS_MAM_03), | ||
gen_iq_handler:remove_iq_handler(mod_muc_iq, MUCHost, ?NS_MAM_04), | ||
mod_disco:unregister_feature(MUCHost, ?NS_MAM), | ||
mod_disco:unregister_feature(MUCHost, ?NS_MAM_03), | ||
mod_disco:unregister_feature(MUCHost, ?NS_MAM_04), | ||
ok. | ||
|
||
%% ---------------------------------------------------------------------- | ||
%% Host to ServerHost mapping | ||
|
||
-record(mam_host, {host :: ejabberd:server(), | ||
server_host :: ejabberd:server()}). | ||
|
||
-spec start_host_mapping(ejabberd:server(), ejabberd:server()) -> any(). | ||
start_host_mapping(Host, ServerHost) -> | ||
mnesia:create_table(mam_host, | ||
[{ram_copies, [node()]}, | ||
{type, set}, | ||
{attributes, record_info(fields, mam_host)}]), | ||
mnesia:add_table_copy(mam_host, node(), ram_copies), | ||
mnesia:dirty_write(#mam_host{host = Host, server_host = ServerHost}). | ||
|
||
|
||
-spec stop_host_mapping(ejabberd:server(), ejabberd:server()) -> any(). | ||
stop_host_mapping(Host, ServerHost) -> | ||
mnesia:dirty_delete_object( | ||
#mam_host{host = Host, server_host = ServerHost}). | ||
|
||
|
||
-spec server_host(ejabberd:jid()) -> ejabberd:server(). | ||
server_host(#jid{lserver=Host}) -> | ||
server_host_1(Host, mnesia:dirty_read(mam_host, Host)). | ||
|
||
server_host_1(_Host, [#mam_host{ server_host = ServerHost }]) -> | ||
ServerHost. | ||
|
||
%% ---------------------------------------------------------------------- | ||
%% hooks and handlers for MUC | ||
|
||
|
@@ -263,7 +225,7 @@ filter_room_packet(Packet, EventData) -> | |
FromJID :: ejabberd:jid(), RoomJID :: ejabberd:jid(), | ||
Role :: mod_muc:role(), Affiliation :: mod_muc:affiliation()) -> packet(). | ||
archive_room_packet(Packet, FromNick, FromJID=#jid{}, RoomJID=#jid{}, Role, Affiliation) -> | ||
Host = server_host(RoomJID), | ||
{ok, Host} = mongoose_subhosts:get_host(RoomJID#jid.lserver), | ||
ArcID = archive_id_int(Host, RoomJID), | ||
%% Occupant JID <room@service/nick> | ||
SrcJID = jid:replace_resource(RoomJID, FromNick), | ||
|
@@ -445,7 +407,7 @@ handle_set_prefs(ArcJID=#jid{}, | |
{DefaultMode, AlwaysJIDs, NeverJIDs} = parse_prefs(PrefsEl), | ||
?DEBUG("Parsed data~n\tDefaultMode ~p~n\tAlwaysJIDs ~p~n\tNeverJIDS ~p~n", | ||
[DefaultMode, AlwaysJIDs, NeverJIDs]), | ||
Host = server_host(ArcJID), | ||
{ok, Host} = mongoose_subhosts:get_host(ArcJID#jid.lserver), | ||
ArcID = archive_id_int(Host, ArcJID), | ||
Res = set_prefs(Host, ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs), | ||
handle_set_prefs_result(Res, DefaultMode, AlwaysJIDs, NeverJIDs, IQ). | ||
|
@@ -461,7 +423,7 @@ handle_set_prefs_result({error, Reason}, | |
-spec handle_get_prefs(ejabberd:jid(), ejabberd:iq()) -> | ||
ejabberd:iq() | {error, any(), ejabberd:iq()}. | ||
handle_get_prefs(ArcJID=#jid{}, IQ=#iq{}) -> | ||
Host = server_host(ArcJID), | ||
{ok, Host} = mongoose_subhosts:get_host(ArcJID#jid.lserver), | ||
ArcID = archive_id_int(Host, ArcJID), | ||
Res = get_prefs(Host, ArcID, ArcJID, always), | ||
handle_get_prefs_result(Res, IQ). | ||
|
@@ -482,7 +444,7 @@ handle_lookup_messages( | |
ArcJID=#jid{}, | ||
IQ=#iq{xmlns = MamNs, sub_el = QueryEl}) -> | ||
Now = mod_mam_utils:now_to_microseconds(now()), | ||
Host = server_host(ArcJID), | ||
{ok, Host} = mongoose_subhosts:get_host(ArcJID#jid.lserver), | ||
ArcID = archive_id_int(Host, ArcJID), | ||
QueryID = xml:get_tag_attr_s(<<"queryid">>, QueryEl), | ||
%% Filtering by date. | ||
|
@@ -537,7 +499,7 @@ handle_set_message_form( | |
ArcJID=#jid{}, | ||
IQ=#iq{xmlns=MamNs, sub_el = QueryEl}) -> | ||
Now = mod_mam_utils:now_to_microseconds(now()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Compiler:
|
||
Host = server_host(ArcJID), | ||
{ok, Host} = mongoose_subhosts:get_host(ArcJID#jid.lserver), | ||
ArcID = archive_id_int(Host, ArcJID), | ||
QueryID = xml:get_tag_attr_s(<<"queryid">>, QueryEl), | ||
%% Filtering by date. | ||
|
@@ -623,7 +585,7 @@ handle_get_message_form(_From=#jid{}, _ArcJID=#jid{}, IQ=#iq{}) -> | |
handle_purge_multiple_messages(ArcJID=#jid{}, | ||
IQ=#iq{sub_el = PurgeEl}) -> | ||
Now = mod_mam_utils:now_to_microseconds(now()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Compiler:
|
||
Host = server_host(ArcJID), | ||
{ok, Host} = mongoose_subhosts:get_host(ArcJID#jid.lserver), | ||
ArcID = archive_id_int(Host, ArcJID), | ||
%% Filtering by date. | ||
%% Start :: integer() | undefined | ||
|
@@ -643,7 +605,7 @@ handle_purge_multiple_messages(ArcJID=#jid{}, | |
handle_purge_single_message(ArcJID=#jid{}, | ||
IQ=#iq{sub_el = PurgeEl}) -> | ||
Now = mod_mam_utils:now_to_microseconds(now()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Compiler:
|
||
Host = server_host(ArcJID), | ||
{ok, Host} = mongoose_subhosts:get_host(ArcJID#jid.lserver), | ||
ArcID = archive_id_int(Host, ArcJID), | ||
BExtMessID = xml:get_tag_attr_s(<<"id">>, PurgeEl), | ||
MessID = mod_mam_utils:external_binary_to_mess_id(BExtMessID), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Compiler: