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
Dynamic lookup of GDPR-related modules for retrieval #2297
Changes from all commits
cdc6925
5967b34
3db2b47
2f3ccee
c28612d
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
-module(mongoose_lib). | ||
-export([bin_to_int/1, log_if_backend_error/4]). | ||
|
||
-export([find_behaviour_implementations/1]). | ||
-export([log_if_backend_error/4]). | ||
%% Maps | ||
-export([maps_append/3]). | ||
-export([maps_foreach/2]). | ||
|
@@ -9,15 +10,29 @@ | |
|
||
-include("mongoose.hrl"). | ||
|
||
%% @doc string:to_integer/1 for binaries | ||
bin_to_int(Bin) -> | ||
bin_to_int(Bin, 0). | ||
%% ------------------------------------------------------------------ | ||
%% Behaviour util | ||
%% ------------------------------------------------------------------ | ||
|
||
bin_to_int(<<H, T/binary>>, X) when $0 =< H, H =< $9 -> | ||
bin_to_int(T, (X*10)+(H-$0)); | ||
bin_to_int(Bin, X) -> | ||
{X, Bin}. | ||
%% WARNING! For simplicity, this function searches only MongooseIM code dir | ||
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. Would it work for MIM installed from binaries? 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. I'm 99.9% certain it will because we're asking for a path for |
||
-spec find_behaviour_implementations(Behaviour :: module()) -> [module()]. | ||
find_behaviour_implementations(Behaviour) -> | ||
{ok, EbinFiles} = file:list_dir(code:lib_dir(mongooseim, ebin)), | ||
Mods = [ list_to_atom(filename:rootname(File)) | ||
|| File <- EbinFiles, filename:extension(File) == ".beam" ], | ||
lists:filter(fun(M) -> | ||
try lists:keyfind([Behaviour], 2, M:module_info(attributes)) of | ||
{behavior, _} -> true; | ||
{behaviour, _} -> true; | ||
_ -> false | ||
catch | ||
_:_ -> false | ||
end | ||
end, Mods). | ||
|
||
%% ------------------------------------------------------------------ | ||
%% Logging | ||
%% ------------------------------------------------------------------ | ||
|
||
%% @doc Database backends for various modules return ok, {atomic, ok} | ||
%% or {atomic, []} on success, and usually {error, ...} on failure. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -262,14 +262,24 @@ process_packet(Acc, From, To, El, #state{server_host = ServerHost, access = Acce | |
get_personal_data(Username, Server) -> | ||
LUser = jid:nodeprep(Username), | ||
LServer = jid:nodeprep(Server), | ||
Payloads = mod_pubsub_db_backend:get_user_payloads(LUser, LServer), | ||
Nodes = mod_pubsub_db_backend:get_user_nodes(LUser, LServer), | ||
Subscriptions = mod_pubsub_db_backend:get_user_subscriptions(LUser, LServer), | ||
Backends = mongoose_lib:find_behaviour_implementations(mod_pubsub_db), | ||
Payloads = get_personal_data_group(LUser, LServer, Backends, get_user_payloads), | ||
Nodes = get_personal_data_group(LUser, LServer, Backends, get_user_nodes), | ||
Subscriptions = get_personal_data_group(LUser, LServer, Backends, get_user_subscriptions), | ||
|
||
[{pubsub_payloads, ["node_name", "item_id", "payload"], Payloads}, | ||
{pubsub_nodes, ["node_name", "type"], Nodes}, | ||
{pubsub_subscriptions, ["node_name"], Subscriptions}]. | ||
|
||
get_personal_data_group(LUser, LServer, Backends, FunctionName) -> | ||
lists:flatmap(fun(B) -> try B:FunctionName(LUser, LServer) of | ||
Result when is_list(Result) -> Result; | ||
_ -> [] | ||
catch | ||
_:_ -> [] | ||
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. FYI, a similar silent catch-all |
||
end | ||
end, Backends). | ||
|
||
%%==================================================================== | ||
%% gen_server callbacks | ||
%%==================================================================== | ||
|
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.
Silent catch-all error - is there really a reason not to log it? This will be a nightmare to debug.
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.
I thought about the same thing after merging and decided to fix it after all other PRs are merged.