From 7623ebd3278550648cf943af591cbafcb6457e18 Mon Sep 17 00:00:00 2001 From: Maxim Ignatenko Date: Tue, 24 Apr 2012 14:11:17 +0300 Subject: [PATCH] mod_irc: Make use of MUC password --- src/mod_irc/mod_irc_connection.erl | 34 ++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/mod_irc/mod_irc_connection.erl b/src/mod_irc/mod_irc_connection.erl index 7206c7c5e..fcb5297ca 100644 --- a/src/mod_irc/mod_irc_connection.erl +++ b/src/mod_irc/mod_irc_connection.erl @@ -206,6 +206,31 @@ code_change(_OldVsn, StateName, StateData, _Extra) -> StateData#state{outbuf = StateData#state.outbuf ++ S} end). +get_password_from_presence({xmlelement, "presence", _Attrs, Els}) -> + case lists:filter(fun(El) -> + case El of + {xmlelement, "x", Attrs, _Els} -> + case xml:get_attr_s("xmlns", Attrs) of + ?NS_MUC -> + true; + _ -> + false + end; + _ -> + false + end + end, Els) of + [ElXMUC | _] -> + case xml:get_subtag(ElXMUC, "password") of + {xmlelement, "password", _, _} = PasswordTag -> + {true, xml:get_tag_cdata(PasswordTag)}; + _ -> + false + end; + _ -> + false + end. + %%---------------------------------------------------------------------- %% Func: handle_info/3 %% Returns: {next_state, NextStateName, NextStateData} | @@ -213,7 +238,7 @@ code_change(_OldVsn, StateName, StateData, _Extra) -> %% {stop, Reason, NewStateData} %%---------------------------------------------------------------------- handle_info({route_chan, Channel, Resource, - {xmlelement, "presence", Attrs, _Els}}, + {xmlelement, "presence", Attrs, _Els} = Presence}, StateName, StateData) -> NewStateData = case xml:get_attr_s("type", Attrs) of @@ -247,7 +272,12 @@ handle_info({route_chan, Channel, Resource, true -> S1; _ -> - S2 = ?SEND(io_lib:format("JOIN #~s\r\n", [Channel])), + case get_password_from_presence(Presence) of + {true, Password} -> + S2 = ?SEND(io_lib:format("JOIN #~s ~s\r\n", [Channel, Password])); + _ -> + S2 = ?SEND(io_lib:format("JOIN #~s\r\n", [Channel])) + end, S2#state{channels = dict:store(Channel, ?SETS:new(), S1#state.channels)}