From bc0d8613abde6439ee5235a4a8c01864bc00846a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Mon, 6 Oct 2008 15:16:09 +0000 Subject: [PATCH] Fix status handling by always using binaries: until now, we were mixing lists and binaries in a non-working way. PR: EJABP-1 Submitted by: Pablo Polvorin SVN Revision: 1608 --- ChangeLog | 4 ++++ src/ejabberd_sm.erl | 6 +++--- src/mod_roster.erl | 14 +++++++++----- src/mod_roster_odbc.erl | 20 ++++++++++++-------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index c7c8f9b14..7e9b774ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,10 @@ * src/mod_privacy.erl: The Mnesia table wasn't updated when converting from an old schema. + * src/ejabberd_sm.erl, src/mod_roster.erl, src/mod_roster_odbc.erl: + Fix status handling by always using binaries: until now, we were + mixing lists and binaries in a non-working way. + 2008-10-02 Jean-Sébastien Pédron * src/mod_roster_odbc.erl: Fix a bug where a JID represented as a diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl index 4d8ea55c2..0ce7505bf 100644 --- a/src/ejabberd_sm.erl +++ b/src/ejabberd_sm.erl @@ -420,21 +420,21 @@ do_route(From, To, Packet) -> roster_in_subscription, LServer, false, - [User, Server, From, subscribed, ""]), + [User, Server, From, subscribed, <<>>]), true}; 'unsubscribe' -> {ejabberd_hooks:run_fold( roster_in_subscription, LServer, false, - [User, Server, From, unsubscribe, ""]), + [User, Server, From, unsubscribe, <<>>]), true}; 'unsubscribed' -> {ejabberd_hooks:run_fold( roster_in_subscription, LServer, false, - [User, Server, From, unsubscribed, ""]), + [User, Server, From, unsubscribed, <<>>]), true}; _ -> {true, false} diff --git a/src/mod_roster.erl b/src/mod_roster.erl index ebaebbbc0..a18fc0d03 100644 --- a/src/mod_roster.erl +++ b/src/mod_roster.erl @@ -367,7 +367,7 @@ in_subscription(_, User, Server, JID, Type, Reason) -> process_subscription(in, User, Server, JID, Type, Reason). out_subscription(User, Server, JID, Type) -> - process_subscription(out, User, Server, JID, Type, []). + process_subscription(out, User, Server, JID, Type, <<>>). process_subscription(Direction, User, Server, JID1, Type, Reason) -> try @@ -406,7 +406,7 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) -> AskMessage = case NewState of {_, both} -> Reason; {_, in} -> Reason; - _ -> "" + _ -> <<>> end, case NewState of none -> @@ -416,9 +416,13 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) -> mnesia:delete({roster, {LUser, LServer, LJID}}), {none, AutoReply}; {Subscription, Pending} -> + AskBinary = case AskMessage of + undefined -> <<>>; + B -> B + end, NewItem = Item#roster{subscription = Subscription, ask = Pending, - askmessage = list_to_binary(AskMessage)}, + askmessage = AskBinary}, mnesia:write(NewItem), {{push, NewItem}, AutoReply} end @@ -648,10 +652,10 @@ get_in_pending_subscriptions(Ls, User, Server) -> Ls ++ lists:map( fun(R) -> Message = R#roster.askmessage, - {U, S, R} = R#roster.jid, + {U0, S0, R0} = R#roster.jid, Pres1 = exmpp_presence:subscribe(), Pres2 = exmpp_stanza:set_jids(Pres1, - exmpp_jid:jid_to_list(U, S, R), + exmpp_jid:jid_to_list(U0, S0, R0), exmpp_jid:jid_to_list(JID)), exmpp_presence:set_status(Pres2, Message) end, diff --git a/src/mod_roster_odbc.erl b/src/mod_roster_odbc.erl index be3ffcb03..88d0b8667 100644 --- a/src/mod_roster_odbc.erl +++ b/src/mod_roster_odbc.erl @@ -411,15 +411,15 @@ in_subscription(_, User, Server, JID, Type, Reason) -> process_subscription(in, User, Server, JID, Type, Reason). out_subscription(User, Server, JID, Type) -> - process_subscription(out, User, Server, JID, Type, []). + process_subscription(out, User, Server, JID, Type, <<>>). process_subscription(Direction, User, Server, JID1, Type, Reason) -> try LUser = exmpp_stringprep:nodeprep(User), LServer = exmpp_stringprep:nameprep(Server), - LJID = exmpp_jid:jid_to_bare_jid(JID1), + {N0,D0,R0} = LJID = jlib:short_prepd_jid(JID1), Username = ejabberd_odbc:escape(LUser), - SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(LJID)), + SJID = ejabberd_odbc:escape(exmpp_jid:jid_to_list(N0,D0,R0)), F = fun() -> Item = case odbc_queries:get_roster_by_jid(LServer, Username, SJID) of @@ -467,7 +467,7 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) -> AskMessage = case NewState of {_, both} -> Reason; {_, in} -> Reason; - _ -> "" + _ -> <<>> end, case NewState of none -> @@ -477,9 +477,13 @@ process_subscription(Direction, User, Server, JID1, Type, Reason) -> odbc_queries:del_roster(LServer, Username, SJID), {none, AutoReply}; {Subscription, Pending} -> + AskBinary = case AskMessage of + undefined -> <<>>; + B -> B + end, NewItem = Item#roster{subscription = Subscription, ask = Pending, - askmessage = list_to_binary(AskMessage)}, + askmessage = AskBinary}, ItemVals = record_to_string(NewItem), odbc_queries:roster_subscribe(LServer, Username, SJID, ItemVals), {{push, NewItem}, AutoReply} @@ -712,10 +716,10 @@ get_in_pending_subscriptions(Ls, User, Server) -> Ls ++ lists:map( fun(R) -> Message = R#roster.askmessage, - {U, S, R} = R#roster.jid, + {U0, S0, R0} = R#roster.jid, Pres1 = exmpp_presence:subscribe(), Pres2 = exmpp_stanza:set_jids(Pres1, - exmpp_jid:jid_to_list(U, S, R), + exmpp_jid:jid_to_list(U0, S0, R0), exmpp_jid:jid_to_list(JID)), exmpp_presence:set_status(Pres2, Message) end, @@ -876,7 +880,7 @@ groups_to_string(#roster{us = {User, _Server}, (Group, Acc) -> String = ["'", Username, "'," "'", SJID, "'," - "'", ejabberd_odbc:escape(Group), "'"], + "'", ejabberd_odbc:escape(binary_to_list(Group)), "'"], [String|Acc] end, [], Groups). webadmin_page(_, Host,