25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

mod_mam: Improve binary comparison of message UIDs

Make sure the binary comparison performed when clients use message UIDs
to page through Mnesia archives yields correct results even if the
specified UIDs don't have the same number of digits as the UIDs of the
stored messages.  This way, MAM will continue to work as expected after
migrating from mod_mam_mnesia to mod_mam.
This commit is contained in:
Holger Weiss 2016-01-13 23:01:51 +01:00
parent 3dccc20d8b
commit 9cd048c442

View File

@ -44,6 +44,13 @@
-include("mod_muc_room.hrl"). -include("mod_muc_room.hrl").
-include("ejabberd_commands.hrl"). -include("ejabberd_commands.hrl").
-define(BIN_GREATER_THAN(A, B),
((A > B andalso byte_size(A) == byte_size(B))
orelse byte_size(A) > byte_size(B))).
-define(BIN_LESS_THAN(A, B),
((A < B andalso byte_size(A) == byte_size(B))
orelse byte_size(A) < byte_size(B))).
-record(archive_msg, -record(archive_msg,
{us = {<<"">>, <<"">>} :: {binary(), binary()} | '$2', {us = {<<"">>, <<"">>} :: {binary(), binary()} | '$2',
id = <<>> :: binary() | '_', id = <<>> :: binary() | '_',
@ -1014,11 +1021,12 @@ filter_by_rsm(Msgs, #rsm_in{max = Max, direction = Direction, id = ID}) ->
aft when ID /= <<"">> -> aft when ID /= <<"">> ->
lists:filter( lists:filter(
fun(#archive_msg{id = I}) -> fun(#archive_msg{id = I}) ->
I > ID ?BIN_GREATER_THAN(I, ID)
end, Msgs); end, Msgs);
before when ID /= <<"">> -> before when ID /= <<"">> ->
lists:foldl( lists:foldl(
fun(#archive_msg{id = I} = Msg, Acc) when I < ID -> fun(#archive_msg{id = I} = Msg, Acc)
when ?BIN_LESS_THAN(I, ID) ->
[Msg|Acc]; [Msg|Acc];
(_, Acc) -> (_, Acc) ->
Acc Acc