]> granicus.if.org Git - ejabberd/commitdiff
mod_irc: Make use of MUC password
authorMaxim Ignatenko <gelraen.ua@gmail.com>
Tue, 24 Apr 2012 11:11:17 +0000 (14:11 +0300)
committerBadlop <badlop@process-one.net>
Tue, 24 Apr 2012 13:21:46 +0000 (15:21 +0200)
src/mod_irc/mod_irc_connection.erl

index 7206c7c5e0ad41f54216521fb73dc7a0a3826f41..fcb5297caa62da4fcb2d8251f5e154d04bf1e815 100644 (file)
@@ -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)}