mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-26 16:26:24 +01:00
Fix multiple bugs in ODBC mods.
PR: EJABP-1 Submitted by: Pablo Polvorin <pablo.polvorin@process-one.net> SVN Revision: 1589
This commit is contained in:
parent
ddcb94649d
commit
2309f9b8bc
@ -1,3 +1,9 @@
|
|||||||
|
2008-10-01 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||||
|
|
||||||
|
* src/mod_offline_odbc.erl, src/mod_vcard_odbc.erl,
|
||||||
|
src/mod_roster_odbc.erl: Fix multiple bugs in ODBC mods, thanks to
|
||||||
|
Pablo Polvorin!
|
||||||
|
|
||||||
2008-09-29 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
2008-09-29 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||||
|
|
||||||
* src/jlib.erl (parse_xdata_submit, parse_xdata_fields): Fix a bug
|
* src/jlib.erl (parse_xdata_submit, parse_xdata_fields): Fix a bug
|
||||||
|
@ -103,16 +103,16 @@ loop(Host, MaxOfflineMsgs) ->
|
|||||||
From = M#offline_msg.from,
|
From = M#offline_msg.from,
|
||||||
To = M#offline_msg.to,
|
To = M#offline_msg.to,
|
||||||
Packet0 = exmpp_stanza:set_jids(
|
Packet0 = exmpp_stanza:set_jids(
|
||||||
|
M#offline_msg.packet,
|
||||||
From,
|
From,
|
||||||
To,
|
To),
|
||||||
M#offline_msg.packet),
|
|
||||||
Packet1 = exmpp_xml:append_child(Packet0,
|
Packet1 = exmpp_xml:append_child(Packet0,
|
||||||
jlib:timestamp_to_xml(
|
jlib:timestamp_to_xml(
|
||||||
calendar:now_to_universal_time(
|
calendar:now_to_universal_time(
|
||||||
M#offline_msg.timestamp))),
|
M#offline_msg.timestamp))),
|
||||||
XML =
|
XML =
|
||||||
ejabberd_odbc:escape(
|
ejabberd_odbc:escape(
|
||||||
exmpp_xml:document_to_string(Packet1)),
|
exmpp_xml:document_to_list(Packet1)),
|
||||||
odbc_queries:add_spool_sql(Username, XML)
|
odbc_queries:add_spool_sql(Username, XML)
|
||||||
end, Msgs),
|
end, Msgs),
|
||||||
case catch odbc_queries:add_spool(Host, Query) of
|
case catch odbc_queries:add_spool(Host, Query) of
|
||||||
@ -156,7 +156,7 @@ stop(Host) ->
|
|||||||
ok.
|
ok.
|
||||||
|
|
||||||
store_packet(From, To, Packet) ->
|
store_packet(From, To, Packet) ->
|
||||||
Type = exmpp_stanza_:get_type(Packet, 'type'),
|
Type = exmpp_stanza:get_type(Packet),
|
||||||
if
|
if
|
||||||
(Type /= "error") and (Type /= "groupchat") and
|
(Type /= "error") and (Type /= "groupchat") and
|
||||||
(Type /= "headline") ->
|
(Type /= "headline") ->
|
||||||
@ -237,35 +237,45 @@ find_x_expire(TimeStamp, [_ | Els]) ->
|
|||||||
|
|
||||||
|
|
||||||
pop_offline_messages(Ls, User, Server) ->
|
pop_offline_messages(Ls, User, Server) ->
|
||||||
LUser = exmpp_stringprep:nodeprep(User),
|
try
|
||||||
LServer = exmpp_stringprep:nameprep(Server),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
EUser = ejabberd_odbc:escape(LUser),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
case odbc_queries:get_and_del_spool_msg_t(LServer, EUser) of
|
EUser = ejabberd_odbc:escape(LUser),
|
||||||
{atomic, {selected, ["username","xml"], Rs}} ->
|
case odbc_queries:get_and_del_spool_msg_t(LServer, EUser) of
|
||||||
Ls ++ lists:flatmap(
|
{atomic, {selected, ["username","xml"], Rs}} ->
|
||||||
fun({_, XML}) ->
|
Ls ++ lists:flatmap(
|
||||||
try
|
fun({_, XML}) ->
|
||||||
[El] = exmpp_xml:parse_document(XML, [namespace, name_as_atom]),
|
try
|
||||||
To = exmpp_jid:list_to_jid(
|
[El] = exmpp_xml:parse_document(XML, [namespace, name_as_atom, autoload_known]),
|
||||||
exmpp_stanza:get_recipient(El)),
|
To = exmpp_jid:list_to_jid(
|
||||||
From = exmpp_jid:list_to_jid(
|
exmpp_stanza:get_recipient(El)),
|
||||||
exmpp_stanza:get_sender(El)),
|
From = exmpp_jid:list_to_jid(
|
||||||
[{route, From, To, El}]
|
exmpp_stanza:get_sender(El)),
|
||||||
catch
|
[{route, From, To, El}]
|
||||||
_ ->
|
catch
|
||||||
[]
|
_ ->
|
||||||
end
|
[]
|
||||||
end, Rs);
|
end
|
||||||
|
end, Rs);
|
||||||
|
_ ->
|
||||||
|
Ls
|
||||||
|
end
|
||||||
|
catch
|
||||||
_ ->
|
_ ->
|
||||||
Ls
|
[]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
remove_user(User, Server) ->
|
remove_user(User, Server) ->
|
||||||
LUser = exmpp_stringprep:nodeprep(User),
|
try
|
||||||
LServer = exmpp_stringprep:nameprep(Server),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
odbc_queries:del_spool_msg(LServer, Username).
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
|
odbc_queries:del_spool_msg(LServer, Username)
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
%% Helper functions:
|
%% Helper functions:
|
||||||
@ -298,30 +308,36 @@ webadmin_page(_, Host,
|
|||||||
webadmin_page(Acc, _, _) -> Acc.
|
webadmin_page(Acc, _, _) -> Acc.
|
||||||
|
|
||||||
user_queue(User, Server, Query, Lang) ->
|
user_queue(User, Server, Query, Lang) ->
|
||||||
LUser = exmpp_stringprep:nodeprep(User),
|
{US, Msgs, Res} = try
|
||||||
LServer = exmpp_stringprep:nameprep(Server),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
US = {LUser, LServer},
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
Res = user_queue_parse_query(Username, LServer, Query),
|
US0 = {LUser, LServer},
|
||||||
Msgs = case catch ejabberd_odbc:sql_query(
|
R = user_queue_parse_query(Username, LServer, Query),
|
||||||
LServer,
|
M = case catch ejabberd_odbc:sql_query(
|
||||||
["select username, xml from spool"
|
LServer,
|
||||||
" where username='", Username, "'"
|
["select username, xml from spool"
|
||||||
" order by seq;"]) of
|
" where username='", Username, "'"
|
||||||
{selected, ["username", "xml"], Rs} ->
|
" order by seq;"]) of
|
||||||
lists:flatmap(
|
{selected, ["username", "xml"], Rs} ->
|
||||||
fun({_, XML}) ->
|
lists:flatmap(
|
||||||
try exmpp_xml:parse_document(XML, [namespace, name_as_atom]) of
|
fun({_, XML}) ->
|
||||||
[El] ->
|
try exmpp_xml:parse_document(XML, [namespace, name_as_atom, autoload_known]) of
|
||||||
[El]
|
[El] ->
|
||||||
catch
|
[El]
|
||||||
_ ->
|
catch
|
||||||
[]
|
_ ->
|
||||||
end
|
[]
|
||||||
end, Rs);
|
end
|
||||||
_ ->
|
end, Rs);
|
||||||
[]
|
_ ->
|
||||||
end,
|
[]
|
||||||
|
end,
|
||||||
|
{US0, M, R}
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
{{"invalid", "invalid"}, [], nothing}
|
||||||
|
end,
|
||||||
FMsgs =
|
FMsgs =
|
||||||
lists:map(
|
lists:map(
|
||||||
fun(#xmlel{} = Msg) ->
|
fun(#xmlel{} = Msg) ->
|
||||||
@ -373,7 +389,7 @@ user_queue_parse_query(Username, LServer, Query) ->
|
|||||||
{selected, ["xml", "seq"], Rs} ->
|
{selected, ["xml", "seq"], Rs} ->
|
||||||
lists:flatmap(
|
lists:flatmap(
|
||||||
fun({XML, Seq}) ->
|
fun({XML, Seq}) ->
|
||||||
try exmpp_xml:parse_document(XML, [namespace, name_as_atom]) of
|
try exmpp_xml:parse_document(XML, [namespace, name_as_atom, autoload_known]) of
|
||||||
[El] ->
|
[El] ->
|
||||||
[{El, Seq}]
|
[{El, Seq}]
|
||||||
catch
|
catch
|
||||||
@ -412,19 +428,24 @@ us_to_list({User, Server}) ->
|
|||||||
exmpp_jid:jid_to_list(User, Server).
|
exmpp_jid:jid_to_list(User, Server).
|
||||||
|
|
||||||
webadmin_user(Acc, User, Server, Lang) ->
|
webadmin_user(Acc, User, Server, Lang) ->
|
||||||
LUser = exmpp_stringprep:nodeprep(User),
|
FQueueLen = try
|
||||||
LServer = exmpp_stringprep:nameprep(Server),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
Username = ejabberd_odbc:escape(LUser),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
QueueLen = case catch ejabberd_odbc:sql_query(
|
Username = ejabberd_odbc:escape(LUser),
|
||||||
LServer,
|
QueueLen = case catch ejabberd_odbc:sql_query(
|
||||||
["select count(*) from spool"
|
LServer,
|
||||||
" where username='", Username, "';"]) of
|
["select count(*) from spool"
|
||||||
{selected, [_], [{SCount}]} ->
|
" where username='", Username, "';"]) of
|
||||||
SCount;
|
{selected, [_], [{SCount}]} ->
|
||||||
_ ->
|
SCount;
|
||||||
0
|
_ ->
|
||||||
end,
|
0
|
||||||
FQueueLen = [?AC("queue/", QueueLen)],
|
end,
|
||||||
|
[?AC("queue/", QueueLen)]
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
[?C("?")]
|
||||||
|
end,
|
||||||
Acc ++ [?XCT("h3", "Offline Messages:")] ++ FQueueLen.
|
Acc ++ [?XCT("h3", "Offline Messages:")] ++ FQueueLen.
|
||||||
|
|
||||||
%% ------------------------------------------------
|
%% ------------------------------------------------
|
||||||
|
@ -835,7 +835,7 @@ record_to_string(#roster{us = {User, _Server},
|
|||||||
ask = Ask,
|
ask = Ask,
|
||||||
askmessage = AskMessage}) ->
|
askmessage = AskMessage}) ->
|
||||||
Username = ejabberd_odbc:escape(User),
|
Username = ejabberd_odbc:escape(User),
|
||||||
{U, S, R} = jlib:short_prepd_jid(JID),
|
{U, S, R} = JID,
|
||||||
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U, S, R)),
|
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U, S, R)),
|
||||||
Nick = ejabberd_odbc:escape(Name),
|
Nick = ejabberd_odbc:escape(Name),
|
||||||
SSubscription = case Subscription of
|
SSubscription = case Subscription of
|
||||||
@ -865,7 +865,7 @@ groups_to_string(#roster{us = {User, _Server},
|
|||||||
jid = JID,
|
jid = JID,
|
||||||
groups = Groups}) ->
|
groups = Groups}) ->
|
||||||
Username = ejabberd_odbc:escape(User),
|
Username = ejabberd_odbc:escape(User),
|
||||||
{U, S, R} = jlib:short_prepd_jid(JID),
|
{U, S, R} = JID,
|
||||||
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U, S, R)),
|
SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(U, S, R)),
|
||||||
|
|
||||||
%% Empty groups do not need to be converted to string to be inserted in
|
%% Empty groups do not need to be converted to string to be inserted in
|
||||||
|
@ -136,11 +136,14 @@ process_sm_iq(_From, To, #iq{type = get} = IQ_Rec) ->
|
|||||||
["select vcard from vcard "
|
["select vcard from vcard "
|
||||||
"where username='", Username, "';"]) of
|
"where username='", Username, "';"]) of
|
||||||
{selected, ["vcard"], [{SVCARD}]} ->
|
{selected, ["vcard"], [{SVCARD}]} ->
|
||||||
case exmpp_xml:parse_document(SVCARD) of
|
try exmpp_xml:parse_document(SVCARD,
|
||||||
{error, _Reason} ->
|
[namespace, name_as_atom, autoload_known]) of
|
||||||
exmpp_iq:error(IQ_Rec, 'service-unavailable');
|
[VCARD] ->
|
||||||
VCARD ->
|
|
||||||
exmpp_iq:result(IQ_Rec, VCARD)
|
exmpp_iq:result(IQ_Rec, VCARD)
|
||||||
|
catch
|
||||||
|
_Type:_Error ->
|
||||||
|
?ERROR_MSG("Error parsing vCard: ~s", [SVCARD]),
|
||||||
|
exmpp_iq:error(IQ_Rec, 'service-unavailable')
|
||||||
end;
|
end;
|
||||||
{selected, ["vcard"], []} ->
|
{selected, ["vcard"], []} ->
|
||||||
exmpp_iq:result(IQ_Rec);
|
exmpp_iq:result(IQ_Rec);
|
||||||
|
Loading…
Reference in New Issue
Block a user