mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-30 16:36:29 +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>
|
||||
|
||||
* src/jlib.erl (parse_xdata_submit, parse_xdata_fields): Fix a bug
|
||||
|
@ -103,16 +103,16 @@ loop(Host, MaxOfflineMsgs) ->
|
||||
From = M#offline_msg.from,
|
||||
To = M#offline_msg.to,
|
||||
Packet0 = exmpp_stanza:set_jids(
|
||||
M#offline_msg.packet,
|
||||
From,
|
||||
To,
|
||||
M#offline_msg.packet),
|
||||
To),
|
||||
Packet1 = exmpp_xml:append_child(Packet0,
|
||||
jlib:timestamp_to_xml(
|
||||
calendar:now_to_universal_time(
|
||||
M#offline_msg.timestamp))),
|
||||
XML =
|
||||
ejabberd_odbc:escape(
|
||||
exmpp_xml:document_to_string(Packet1)),
|
||||
exmpp_xml:document_to_list(Packet1)),
|
||||
odbc_queries:add_spool_sql(Username, XML)
|
||||
end, Msgs),
|
||||
case catch odbc_queries:add_spool(Host, Query) of
|
||||
@ -156,7 +156,7 @@ stop(Host) ->
|
||||
ok.
|
||||
|
||||
store_packet(From, To, Packet) ->
|
||||
Type = exmpp_stanza_:get_type(Packet, 'type'),
|
||||
Type = exmpp_stanza:get_type(Packet),
|
||||
if
|
||||
(Type /= "error") and (Type /= "groupchat") and
|
||||
(Type /= "headline") ->
|
||||
@ -237,6 +237,7 @@ find_x_expire(TimeStamp, [_ | Els]) ->
|
||||
|
||||
|
||||
pop_offline_messages(Ls, User, Server) ->
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
EUser = ejabberd_odbc:escape(LUser),
|
||||
@ -245,7 +246,7 @@ pop_offline_messages(Ls, User, Server) ->
|
||||
Ls ++ lists:flatmap(
|
||||
fun({_, XML}) ->
|
||||
try
|
||||
[El] = exmpp_xml:parse_document(XML, [namespace, name_as_atom]),
|
||||
[El] = exmpp_xml:parse_document(XML, [namespace, name_as_atom, autoload_known]),
|
||||
To = exmpp_jid:list_to_jid(
|
||||
exmpp_stanza:get_recipient(El)),
|
||||
From = exmpp_jid:list_to_jid(
|
||||
@ -258,14 +259,23 @@ pop_offline_messages(Ls, User, Server) ->
|
||||
end, Rs);
|
||||
_ ->
|
||||
Ls
|
||||
end
|
||||
catch
|
||||
_ ->
|
||||
[]
|
||||
end.
|
||||
|
||||
|
||||
remove_user(User, Server) ->
|
||||
try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
odbc_queries:del_spool_msg(LServer, Username).
|
||||
odbc_queries:del_spool_msg(LServer, Username)
|
||||
catch
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
|
||||
%% Helper functions:
|
||||
@ -298,12 +308,13 @@ webadmin_page(_, Host,
|
||||
webadmin_page(Acc, _, _) -> Acc.
|
||||
|
||||
user_queue(User, Server, Query, Lang) ->
|
||||
{US, Msgs, Res} = try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
US = {LUser, LServer},
|
||||
Res = user_queue_parse_query(Username, LServer, Query),
|
||||
Msgs = case catch ejabberd_odbc:sql_query(
|
||||
US0 = {LUser, LServer},
|
||||
R = user_queue_parse_query(Username, LServer, Query),
|
||||
M = case catch ejabberd_odbc:sql_query(
|
||||
LServer,
|
||||
["select username, xml from spool"
|
||||
" where username='", Username, "'"
|
||||
@ -311,7 +322,7 @@ user_queue(User, Server, Query, Lang) ->
|
||||
{selected, ["username", "xml"], Rs} ->
|
||||
lists:flatmap(
|
||||
fun({_, XML}) ->
|
||||
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]
|
||||
catch
|
||||
@ -322,6 +333,11 @@ user_queue(User, Server, Query, Lang) ->
|
||||
_ ->
|
||||
[]
|
||||
end,
|
||||
{US0, M, R}
|
||||
catch
|
||||
_ ->
|
||||
{{"invalid", "invalid"}, [], nothing}
|
||||
end,
|
||||
FMsgs =
|
||||
lists:map(
|
||||
fun(#xmlel{} = Msg) ->
|
||||
@ -373,7 +389,7 @@ user_queue_parse_query(Username, LServer, Query) ->
|
||||
{selected, ["xml", "seq"], Rs} ->
|
||||
lists:flatmap(
|
||||
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, Seq}]
|
||||
catch
|
||||
@ -412,6 +428,7 @@ us_to_list({User, Server}) ->
|
||||
exmpp_jid:jid_to_list(User, Server).
|
||||
|
||||
webadmin_user(Acc, User, Server, Lang) ->
|
||||
FQueueLen = try
|
||||
LUser = exmpp_stringprep:nodeprep(User),
|
||||
LServer = exmpp_stringprep:nameprep(Server),
|
||||
Username = ejabberd_odbc:escape(LUser),
|
||||
@ -424,7 +441,11 @@ webadmin_user(Acc, User, Server, Lang) ->
|
||||
_ ->
|
||||
0
|
||||
end,
|
||||
FQueueLen = [?AC("queue/", QueueLen)],
|
||||
[?AC("queue/", QueueLen)]
|
||||
catch
|
||||
_ ->
|
||||
[?C("?")]
|
||||
end,
|
||||
Acc ++ [?XCT("h3", "Offline Messages:")] ++ FQueueLen.
|
||||
|
||||
%% ------------------------------------------------
|
||||
|
@ -835,7 +835,7 @@ record_to_string(#roster{us = {User, _Server},
|
||||
ask = Ask,
|
||||
askmessage = AskMessage}) ->
|
||||
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)),
|
||||
Nick = ejabberd_odbc:escape(Name),
|
||||
SSubscription = case Subscription of
|
||||
@ -865,7 +865,7 @@ groups_to_string(#roster{us = {User, _Server},
|
||||
jid = JID,
|
||||
groups = Groups}) ->
|
||||
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)),
|
||||
|
||||
%% 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 "
|
||||
"where username='", Username, "';"]) of
|
||||
{selected, ["vcard"], [{SVCARD}]} ->
|
||||
case exmpp_xml:parse_document(SVCARD) of
|
||||
{error, _Reason} ->
|
||||
exmpp_iq:error(IQ_Rec, 'service-unavailable');
|
||||
VCARD ->
|
||||
try exmpp_xml:parse_document(SVCARD,
|
||||
[namespace, name_as_atom, autoload_known]) of
|
||||
[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;
|
||||
{selected, ["vcard"], []} ->
|
||||
exmpp_iq:result(IQ_Rec);
|
||||
|
Loading…
Reference in New Issue
Block a user