Просмотр исходного кода

fix issues #118 - protect from empty sub/unsub topic list

Feng Lee 11 лет назад
Родитель
Сommit
914fa668b7
1 измененных файлов с 10 добавлено и 1 удалено
  1. 10 1
      apps/emqttd/src/emqttd_protocol.erl

+ 10 - 1
apps/emqttd/src/emqttd_protocol.erl

@@ -191,18 +191,27 @@ handle(?PUBACK_PACKET(Type, PacketId), State = #proto_state{session = Session})
     end,
 	{ok, NewState};
 
+%% protect from empty topic list
+handle(?SUBSCRIBE_PACKET(PacketId, []), State) ->
+    send(?SUBACK_PACKET(PacketId, []), State);
+
 handle(?SUBSCRIBE_PACKET(PacketId, TopicTable), State = #proto_state{clientid = ClientId, session = Session}) ->
     AllowDenies = [check_acl(subscribe, Topic, State) || {Topic, _Qos} <- TopicTable],
     case lists:member(deny, AllowDenies) of
         true ->
-            %%TODO: return 128 QoS when deny...
+            %%TODO: return 128 QoS when deny... no need to SUBACK?
             lager:error("SUBSCRIBE from '~s' Denied: ~p", [ClientId, TopicTable]),
             {ok, State};
         false ->
+            %%TODO: GrantedQos should be renamed.
             {ok, NewSession, GrantedQos} = emqttd_session:subscribe(Session, TopicTable),
             send(?SUBACK_PACKET(PacketId, GrantedQos), State#proto_state{session = NewSession})
     end;
 
+%% protect from empty topic list
+handle(?UNSUBSCRIBE_PACKET(PacketId, []), State) ->
+    send(?UNSUBACK_PACKET(PacketId), State);
+
 handle(?UNSUBSCRIBE_PACKET(PacketId, Topics), State = #proto_state{session = Session}) ->
     {ok, NewSession} = emqttd_session:unsubscribe(Session, Topics),
     send(?UNSUBACK_PACKET(PacketId), State#proto_state{session = NewSession});