]> granicus.if.org Git - ejabberd/commitdiff
Support to provide password when subscribing to a room (#1306)
authorBadlop <badlop@process-one.net>
Thu, 10 Nov 2016 19:48:43 +0000 (20:48 +0100)
committerBadlop <badlop@process-one.net>
Thu, 10 Nov 2016 19:48:43 +0000 (20:48 +0100)
src/mod_muc_room.erl

index 6010e0bbf5e8c5236fb57ba2aed0762288d0895f..054900399f63f19e0ebc5893815098f154534f03 100644 (file)
@@ -4653,7 +4653,8 @@ process_iq_mucsub(From, Packet,
                    NewStateData = set_subscriber(From, Nick, Nodes, StateData),
                    {result, subscription_nodes_to_events(Nodes), NewStateData};
                error ->
-                   add_new_user(From, Nick, Packet, StateData)
+                   Packet2 = copy_password_xelement(Packet),
+                   add_new_user(From, Nick, Packet2, StateData)
            end;
        _ ->
            Err = ?ERRT_NOT_ALLOWED(Lang, <<"Subscriptions are not allowed">>),
@@ -4697,6 +4698,11 @@ process_iq_mucsub(_From, _Packet, #iq{lang = Lang}, _StateData) ->
     Txt = <<"Unrecognized subscription command">>,
     {error, ?ERRT_BAD_REQUEST(Lang, Txt)}.
 
+copy_password_xelement(Packet) ->
+    SubsEl = fxml:get_subtag_with_xmlns(Packet, <<"subscribe">>, ?NS_MUCSUB),
+    XEl = fxml:get_subtag_with_xmlns(SubsEl, <<"x">>, ?NS_MUC),
+    fxml:append_subtags(Packet, [XEl]).
+
 remove_subscriptions(StateData) ->
     if not (StateData#state.config)#config.allow_subscription ->
            StateData#state{subscribers = ?DICT:new(),