mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Store packet table field as binary, not as string
This commit is contained in:
parent
028d158e13
commit
33745954a9
@ -61,7 +61,7 @@
|
|||||||
%%% expire = 0 | integer()
|
%%% expire = 0 | integer()
|
||||||
%%% from = jid()
|
%%% from = jid()
|
||||||
%%% to = jid()
|
%%% to = jid()
|
||||||
%%% packet = string()
|
%%% packet = binary()
|
||||||
%%%
|
%%%
|
||||||
%%% 3.0.0-alpha / odbc / offline_msg
|
%%% 3.0.0-alpha / odbc / offline_msg
|
||||||
%%% user = varchar150
|
%%% user = varchar150
|
||||||
@ -98,8 +98,7 @@
|
|||||||
-include("web/ejabberd_http.hrl").
|
-include("web/ejabberd_http.hrl").
|
||||||
-include("web/ejabberd_web_admin.hrl").
|
-include("web/ejabberd_web_admin.hrl").
|
||||||
|
|
||||||
%% The packet is stored serialized as a string
|
%% The packet is stored serialized as a binary
|
||||||
%% TODO: packet always handled serialized?
|
|
||||||
-record(offline_msg, {user_host, timestamp, expire, from, to, packet}).
|
-record(offline_msg, {user_host, timestamp, expire, from, to, packet}).
|
||||||
|
|
||||||
-define(PROCNAME, ejabberd_offline).
|
-define(PROCNAME, ejabberd_offline).
|
||||||
@ -149,6 +148,12 @@ start(Host, Opts) ->
|
|||||||
register(gen_mod:get_module_proc(Host, ?PROCNAME),
|
register(gen_mod:get_module_proc(Host, ?PROCNAME),
|
||||||
spawn(?MODULE, loop, [AccessMaxOfflineMsgs])).
|
spawn(?MODULE, loop, [AccessMaxOfflineMsgs])).
|
||||||
|
|
||||||
|
stanza_to_store(Stanza) ->
|
||||||
|
exmpp_xml:document_to_binary(Stanza).
|
||||||
|
store_to_stanza(StoreBinary) ->
|
||||||
|
[Xml] = exmpp_xml:parse_document(StoreBinary),
|
||||||
|
Xml.
|
||||||
|
|
||||||
loop(AccessMaxOfflineMsgs) ->
|
loop(AccessMaxOfflineMsgs) ->
|
||||||
receive
|
receive
|
||||||
#offline_msg{user_host=US} = Msg ->
|
#offline_msg{user_host=US} = Msg ->
|
||||||
@ -156,8 +161,6 @@ loop(AccessMaxOfflineMsgs) ->
|
|||||||
Len = length(Msgs),
|
Len = length(Msgs),
|
||||||
%% TODO: is lower?
|
%% TODO: is lower?
|
||||||
{User, Host} = US,
|
{User, Host} = US,
|
||||||
MsgsSerialized = [M#offline_msg{packet = exmpp_xml:document_to_list(P)}
|
|
||||||
|| #offline_msg{packet = P} = M <- Msgs],
|
|
||||||
MaxOfflineMsgs = get_max_user_messages(AccessMaxOfflineMsgs,
|
MaxOfflineMsgs = get_max_user_messages(AccessMaxOfflineMsgs,
|
||||||
User, Host),
|
User, Host),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
@ -180,7 +183,7 @@ loop(AccessMaxOfflineMsgs) ->
|
|||||||
end,
|
end,
|
||||||
lists:foreach(fun(M) ->
|
lists:foreach(fun(M) ->
|
||||||
gen_storage:write(Host, M)
|
gen_storage:write(Host, M)
|
||||||
end, MsgsSerialized)
|
end, Msgs)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
gen_storage:transaction(Host, offline_msg, F),
|
gen_storage:transaction(Host, offline_msg, F),
|
||||||
@ -261,7 +264,7 @@ store_packet(From, To, Packet) ->
|
|||||||
expire = Expire,
|
expire = Expire,
|
||||||
from = From,
|
from = From,
|
||||||
to = To,
|
to = To,
|
||||||
packet = Packet},
|
packet = stanza_to_store(Packet)},
|
||||||
stop;
|
stop;
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
@ -353,7 +356,7 @@ resend_offline_messages(User, Server) ->
|
|||||||
{atomic, Rs} ->
|
{atomic, Rs} ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(R) ->
|
fun(R) ->
|
||||||
Packet = R#offline_msg.packet,
|
Packet = store_to_stanza(R#offline_msg.packet),
|
||||||
TimeXml = timestamp_to_xml(R#offline_msg.timestamp, Server),
|
TimeXml = timestamp_to_xml(R#offline_msg.timestamp, Server),
|
||||||
TimeXml91 = timestamp_to_xml(R#offline_msg.timestamp),
|
TimeXml91 = timestamp_to_xml(R#offline_msg.timestamp),
|
||||||
ejabberd_sm !
|
ejabberd_sm !
|
||||||
@ -389,7 +392,7 @@ pop_offline_messages(Ls, User, Server)
|
|||||||
TS = make_timestamp(),
|
TS = make_timestamp(),
|
||||||
Ls ++ lists:map(
|
Ls ++ lists:map(
|
||||||
fun(R) ->
|
fun(R) ->
|
||||||
[Packet] = exmpp_xml:parse_document(R#offline_msg.packet),
|
Packet = store_to_stanza(R#offline_msg.packet),
|
||||||
TimeXml = timestamp_to_xml(R#offline_msg.timestamp, Server),
|
TimeXml = timestamp_to_xml(R#offline_msg.timestamp, Server),
|
||||||
TimeXml91 = timestamp_to_xml(R#offline_msg.timestamp),
|
TimeXml91 = timestamp_to_xml(R#offline_msg.timestamp),
|
||||||
{route,
|
{route,
|
||||||
@ -487,7 +490,7 @@ update_table(Host, mnesia) ->
|
|||||||
end,
|
end,
|
||||||
PacketXmlel = exmpp_xml:xmlelement_to_xmlel(
|
PacketXmlel = exmpp_xml:xmlelement_to_xmlel(
|
||||||
Packet, [?DEFAULT_NS], ?PREFIXED_NS),
|
Packet, [?DEFAULT_NS], ?PREFIXED_NS),
|
||||||
Packet1 = exmpp_xml:document_to_list(PacketXmlel),
|
Packet1 = stanza_to_store(PacketXmlel),
|
||||||
OM#offline_msg{user_host = {US_U1, US_S1},
|
OM#offline_msg{user_host = {US_U1, US_S1},
|
||||||
timestamp = TsMegaSecs * 1000000000 + TsSecs * 1000 + TsMicroSecs div 1000,
|
timestamp = TsMegaSecs * 1000000000 + TsSecs * 1000 + TsMicroSecs div 1000,
|
||||||
expire = Expire1,
|
expire = Expire1,
|
||||||
@ -571,7 +574,8 @@ find_x_timestamp([_ | Els]) ->
|
|||||||
%% Warn senders that their messages have been discarded:
|
%% Warn senders that their messages have been discarded:
|
||||||
discard_warn_sender(Msgs) ->
|
discard_warn_sender(Msgs) ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(#offline_msg{from=From, to=To, packet=Packet}) ->
|
fun(#offline_msg{from=From, to=To, packet=PacketStored}) ->
|
||||||
|
Packet = store_to_stanza(PacketStored),
|
||||||
ErrText = "Your contact offline message queue is full. The message has been discarded.",
|
ErrText = "Your contact offline message queue is full. The message has been discarded.",
|
||||||
Error = exmpp_stanza:error(Packet#xmlel.ns, 'resource-constraint',
|
Error = exmpp_stanza:error(Packet#xmlel.ns, 'resource-constraint',
|
||||||
{"en", ErrText}),
|
{"en", ErrText}),
|
||||||
@ -612,12 +616,12 @@ user_queue(User, Server, Query, Lang) ->
|
|||||||
FMsgs =
|
FMsgs =
|
||||||
lists:map(
|
lists:map(
|
||||||
fun(#offline_msg{timestamp = TimeStamp, from = From, to = To,
|
fun(#offline_msg{timestamp = TimeStamp, from = From, to = To,
|
||||||
packet = PacketInitialString} = Msg) ->
|
packet = PacketStored} = Msg) ->
|
||||||
ID = jlib:encode_base64(binary_to_list(term_to_binary(Msg))),
|
ID = jlib:encode_base64(binary_to_list(term_to_binary(Msg))),
|
||||||
Time = timestamp_to_isostring(TimeStamp),
|
Time = timestamp_to_isostring(TimeStamp),
|
||||||
SFrom = exmpp_jid:to_list(From),
|
SFrom = exmpp_jid:to_list(From),
|
||||||
STo = exmpp_jid:to_list(To),
|
STo = exmpp_jid:to_list(To),
|
||||||
[Packet] = exmpp_xmlstream:parse_element(PacketInitialString),
|
Packet = store_to_stanza(PacketStored),
|
||||||
Packet1 = exmpp_stanza:set_jids(Packet, SFrom, STo),
|
Packet1 = exmpp_stanza:set_jids(Packet, SFrom, STo),
|
||||||
FPacket = exmpp_xml:node_to_list(
|
FPacket = exmpp_xml:node_to_list(
|
||||||
exmpp_xml:indent_document(Packet1, <<" ">>),
|
exmpp_xml:indent_document(Packet1, <<" ">>),
|
||||||
@ -713,7 +717,7 @@ get_messages_subset2(Max, Length, MsgsAll) ->
|
|||||||
NoJID = exmpp_jid:make("...", "...", ""),
|
NoJID = exmpp_jid:make("...", "...", ""),
|
||||||
TimeStamp = make_timestamp(),
|
TimeStamp = make_timestamp(),
|
||||||
IntermediateMsg = #offline_msg{timestamp = TimeStamp, from = NoJID, to = NoJID,
|
IntermediateMsg = #offline_msg{timestamp = TimeStamp, from = NoJID, to = NoJID,
|
||||||
packet = exmpp_xml:element("...")},
|
packet = <<"...">>},
|
||||||
MsgsFirstN ++ [IntermediateMsg] ++ MsgsLastN.
|
MsgsFirstN ++ [IntermediateMsg] ++ MsgsLastN.
|
||||||
|
|
||||||
webadmin_user(Acc, User, Server, Lang) ->
|
webadmin_user(Acc, User, Server, Lang) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user