]> granicus.if.org Git - ejabberd/commitdiff
Merge branch 'master' into xml-ng
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sat, 12 Nov 2016 11:41:37 +0000 (14:41 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sat, 12 Nov 2016 11:41:37 +0000 (14:41 +0300)
1  2 
src/mod_muc_room.erl

index c83565734917736a3ff7f5e8ada7f89e93f64acd,054900399f63f19e0ebc5893815098f154534f03..e31ec6b0fd39be66e62a511fe7178bc5ac0a4cde
@@@ -3697,47 -4618,51 +3697,48 @@@ process_iq_vcard(From, #iq{type = set, 
            change_config(NewConfig, StateData);
        _ ->
            ErrText = <<"Owner privileges required">>,
 -          {error, ?ERRT_FORBIDDEN(Lang, ErrText)}
 -    end.
 -
 -process_iq_mucsub(From, Packet,
 +          {error, xmpp:err_forbidden(ErrText, Lang)}
 +    end.
 +
 +-spec process_iq_mucsub(jid(), iq(), state()) ->
 +                             {error, stanza_error()} |
 +                             {result, undefined | muc_subscribe(), state()} |
 +                             {ignore, state()}.
 +process_iq_mucsub(_From, #iq{type = set, lang = Lang,
 +                           sub_els = [#muc_subscribe{}]},
 +                #state{config = #config{allow_subscription = false}}) ->
 +    {error, xmpp:err_not_allowed(<<"Subscriptions are not allowed">>, Lang)};
 +process_iq_mucsub(From,
                  #iq{type = set, lang = Lang,
 -                    sub_el = #xmlel{name = <<"subscribe">>} = SubEl},
 -                #state{config = Config} = StateData) ->
 -    case fxml:get_tag_attr_s(<<"nick">>, SubEl) of
 -      <<"">> ->
 -          Err = ?ERRT_BAD_REQUEST(Lang, <<"Missing 'nick' attribute">>),
 -          {error, Err};
 -      Nick when Config#config.allow_subscription ->
 -          LBareJID = jid:tolower(jid:remove_resource(From)),
 -          case (?DICT):find(LBareJID, StateData#state.subscribers) of
 -              {ok, #subscriber{nick = Nick1}} when Nick1 /= Nick ->
 -                  Nodes = get_subscription_nodes(Packet),
 -                  case {nick_collision(From, Nick, StateData),
 -                        mod_muc:can_use_nick(StateData#state.server_host,
 -                                             StateData#state.host,
 -                                             From, Nick)} of
 -                      {true, _} ->
 -                          ErrText = <<"That nickname is already in use by another occupant">>,
 -                          {error, ?ERRT_CONFLICT(Lang, ErrText)};
 -                      {_, false} ->
 -                          ErrText = <<"That nickname is registered by another person">>,
 -                          {error, ?ERRT_CONFLICT(Lang, ErrText)};
 -                      _ ->
 -                          NewStateData = set_subscriber(From, Nick, Nodes, StateData),
 -                          {result, subscription_nodes_to_events(Nodes), NewStateData}
 -                  end;
 -              {ok, #subscriber{}} ->
 -                  Nodes = get_subscription_nodes(Packet),
 +                    sub_els = [#muc_subscribe{nick = Nick}]} = Packet,
 +                StateData) ->
 +    LBareJID = jid:tolower(jid:remove_resource(From)),
 +    case (?DICT):find(LBareJID, StateData#state.subscribers) of
 +      {ok, #subscriber{nick = Nick1}} when Nick1 /= Nick ->
 +          Nodes = get_subscription_nodes(Packet),
 +          case {nick_collision(From, Nick, StateData),
 +                mod_muc:can_use_nick(StateData#state.server_host,
 +                                     StateData#state.host,
 +                                     From, Nick)} of
 +              {true, _} ->
 +                  ErrText = <<"That nickname is already in use by another occupant">>,
 +                  {error, xmpp:err_conflict(ErrText, Lang)};
 +              {_, false} ->
 +                  ErrText = <<"That nickname is registered by another person">>,
 +                  {error, xmpp:err_conflict(ErrText, Lang)};
 +              _ ->
                    NewStateData = set_subscriber(From, Nick, Nodes, StateData),
 -                  {result, subscription_nodes_to_events(Nodes), NewStateData};
 -              error ->
 +                  {result, subscribe_result(Packet), NewStateData}
 +          end;
 +      {ok, #subscriber{}} ->
 +          Nodes = get_subscription_nodes(Packet),
 +          NewStateData = set_subscriber(From, Nick, Nodes, StateData),
 +          {result, subscribe_result(Packet), 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">>),
 -          {error, Err}
      end;
 -process_iq_mucsub(From, _Packet,
 -                #iq{type = set,
 -                    sub_el = #xmlel{name = <<"unsubscribe">>}},
 +process_iq_mucsub(From, #iq{type = set, sub_els = [#muc_unsubscribe{}]},
                  StateData) ->
      LBareJID = jid:tolower(jid:remove_resource(From)),
      case ?DICT:find(LBareJID, StateData#state.subscribers) of
@@@ -3757,19 -4683,26 +3758,24 @@@ process_iq_mucsub(From, #iq{type = get
      FAffiliation = get_affiliation(From, StateData),
      FRole = get_role(From, StateData),
      if FRole == moderator; FAffiliation == owner; FAffiliation == admin ->
 -          Subs = dict:fold(
 +          JIDs = dict:fold(
                     fun(_, #subscriber{jid = J}, Acc) ->
 -                           SJID = jid:to_string(J),
 -                           [#xmlel{name = <<"subscription">>,
 -                                   attrs = [{<<"jid">>, SJID}]}|Acc]
 +                           [J|Acc]
                     end, [], StateData#state.subscribers),
 -          {result, Subs, StateData};
 +          {result, #muc_subscriptions{list = JIDs}, StateData};
         true ->
            Txt = <<"Moderator privileges required">>,
 -          {error, ?ERRT_FORBIDDEN(Lang, Txt)}
 +          {error, xmpp:err_forbidden(Txt, Lang)}
      end;
 -process_iq_mucsub(_From, _Packet, #iq{lang = Lang}, _StateData) ->
 -    Txt = <<"Unrecognized subscription command">>,
 -    {error, ?ERRT_BAD_REQUEST(Lang, Txt)}.
 +process_iq_mucsub(_From, #iq{type = get, lang = Lang}, _StateData) ->
 +    Txt = <<"Value 'get' of 'type' attribute is not allowed">>,
 +    {error, xmpp:err_bad_request(Txt, Lang)}.
  
+ 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(),