From 6907d4feed40efc31ab311649b0aea6e7161440b Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Tue, 21 Apr 2015 14:38:18 +0800 Subject: [PATCH] misc fix --- apps/emqtt/src/emqtt.app.src | 4 +-- apps/emqtt/src/emqtt_message.erl | 24 ++++++------------ apps/emqtt/src/emqtt_packet.erl | 24 ++++++------------ apps/emqtt/src/emqtt_parser.erl | 20 ++++++--------- apps/emqtt/src/emqtt_serialiser.erl | 8 +++--- apps/emqtt/src/emqtt_topic.erl | 38 +++++++++++------------------ 6 files changed, 41 insertions(+), 77 deletions(-) diff --git a/apps/emqtt/src/emqtt.app.src b/apps/emqtt/src/emqtt.app.src index ff295a8a3..61e5bbaef 100644 --- a/apps/emqtt/src/emqtt.app.src +++ b/apps/emqtt/src/emqtt.app.src @@ -1,7 +1,7 @@ {application, emqtt, [ - {description, "Erlang MQTT Common Library"}, - {vsn, "0.6.0"}, + {description, "Erlang Common MQTT Library"}, + {vsn, "0.6.1"}, {modules, []}, {registered, []}, {applications, [ diff --git a/apps/emqtt/src/emqtt_message.erl b/apps/emqtt/src/emqtt_message.erl index 86351f9eb..899de380d 100644 --- a/apps/emqtt/src/emqtt_message.erl +++ b/apps/emqtt/src/emqtt_message.erl @@ -20,13 +20,13 @@ %%% SOFTWARE. %%%----------------------------------------------------------------------------- %%% @doc -%%% MQTT Message. +%%% MQTT Message Functions %%% %%% @end %%%----------------------------------------------------------------------------- -module(emqtt_message). --author('feng@emqtt.io'). +-author("Feng Lee "). -include("emqtt.hrl"). @@ -39,9 +39,7 @@ -export([format/1]). %%------------------------------------------------------------------------------ -%% @doc -%% Message from Packet. -%% +%% @doc Message from Packet %% @end %%------------------------------------------------------------------------------ -spec from_packet(mqtt_packet()) -> mqtt_message(). @@ -73,9 +71,7 @@ from_packet(#mqtt_packet_connect{will_retain = Retain, payload = Msg}. %%------------------------------------------------------------------------------ -%% @doc -%% Message to packet -%% +%% @doc Message to packet %% @end %%------------------------------------------------------------------------------ -spec to_packet(mqtt_message()) -> mqtt_packet(). @@ -100,9 +96,7 @@ to_packet(#mqtt_message{msgid = MsgId, payload = Payload}. %%------------------------------------------------------------------------------ -%% @doc -%% set dup, retain flag -%% +%% @doc set dup, retain flag %% @end %%------------------------------------------------------------------------------ -spec set_flag(mqtt_message()) -> mqtt_message(). @@ -118,9 +112,7 @@ set_flag(Flag, Msg) when Flag =:= dup orelse Flag =:= retain -> Msg. %%------------------------------------------------------------------------------ -%% @doc -%% Unset dup, retain flag -%% +%% @doc Unset dup, retain flag %% @end %%------------------------------------------------------------------------------ -spec unset_flag(mqtt_message()) -> mqtt_message(). @@ -135,9 +127,7 @@ unset_flag(retain, Msg = #mqtt_message{retain = true}) -> unset_flag(Flag, Msg) when Flag =:= dup orelse Flag =:= retain -> Msg. %%------------------------------------------------------------------------------ -%% @doc -%% Format MQTT Message. -%% +%% @doc Format MQTT Message %% @end %%------------------------------------------------------------------------------ format(#mqtt_message{msgid=MsgId, qos=Qos, retain=Retain, dup=Dup, topic=Topic}) -> diff --git a/apps/emqtt/src/emqtt_packet.erl b/apps/emqtt/src/emqtt_packet.erl index 9688a8fed..93ba83f2f 100644 --- a/apps/emqtt/src/emqtt_packet.erl +++ b/apps/emqtt/src/emqtt_packet.erl @@ -20,13 +20,13 @@ %%% SOFTWARE. %%%----------------------------------------------------------------------------- %%% @doc -%%% MQTT packet utility functions. +%%% MQTT Packet Functions %%% %%% @end %%%----------------------------------------------------------------------------- -module(emqtt_packet). --author("feng@emqtt.io"). +-author("Feng Lee "). -include("emqtt.hrl"). @@ -38,21 +38,15 @@ -export([format/1]). %%------------------------------------------------------------------------------ -%% @doc -%% Protocol name of version. -%% +%% @doc Protocol name of version %% @end %%------------------------------------------------------------------------------ --spec protocol_name(Ver) -> Name when - Ver :: mqtt_vsn(), - Name :: binary(). +-spec protocol_name(mqtt_vsn()) -> binary(). protocol_name(Ver) when Ver =:= ?MQTT_PROTO_V31; Ver =:= ?MQTT_PROTO_V311-> proplists:get_value(Ver, ?PROTOCOL_NAMES). %%------------------------------------------------------------------------------ -%% @doc -%% Name of MQTT packet type. -%% +%% @doc Name of MQTT packet type %% @end %%------------------------------------------------------------------------------ -spec type_name(mqtt_packet_type()) -> atom(). @@ -60,9 +54,7 @@ type_name(Type) when Type > ?RESERVED andalso Type =< ?DISCONNECT -> lists:nth(Type, ?TYPE_NAMES). %%------------------------------------------------------------------------------ -%% @doc -%% Connack Name. -%% +%% @doc Connack Name %% @end %%------------------------------------------------------------------------------ -spec connack_name(mqtt_connack()) -> atom(). @@ -74,9 +66,7 @@ connack_name(?CONNACK_CREDENTIALS) -> 'CONNACK_CREDENTIALS'; connack_name(?CONNACK_AUTH) -> 'CONNACK_AUTH'. %%------------------------------------------------------------------------------ -%% @doc -%% Format packet. -%% +%% @doc Format packet %% @end %%------------------------------------------------------------------------------ -spec format(mqtt_packet()) -> iolist(). diff --git a/apps/emqtt/src/emqtt_parser.erl b/apps/emqtt/src/emqtt_parser.erl index 40969c05b..94abe65aa 100644 --- a/apps/emqtt/src/emqtt_parser.erl +++ b/apps/emqtt/src/emqtt_parser.erl @@ -20,13 +20,13 @@ %%% SOFTWARE. %%%----------------------------------------------------------------------------- %%% @doc -%%% emqtt packet parser. +%%% MQTT Packet Parser. %%% %%% @end %%%----------------------------------------------------------------------------- -module(emqtt_parser). --author("feng@emqtt.io"). +-author("Feng Lee "). -include("emqtt.hrl"). @@ -39,24 +39,20 @@ -type option() :: {atom(), any()}. -%%%----------------------------------------------------------------------------- -%% @doc -%% Initialize a parser. -%% +%%------------------------------------------------------------------------------ +%% @doc Initialize a parser %% @end -%%%----------------------------------------------------------------------------- +%%------------------------------------------------------------------------------ -spec init(Opts :: [option()]) -> {none, #mqtt_packet_limit{}}. init(Opts) -> {none, limit(Opts)}. limit(Opts) -> #mqtt_packet_limit{max_packet_size = proplists:get_value(max_packet_size, Opts, ?MAX_LEN)}. -%%%----------------------------------------------------------------------------- -%% @doc -%% Parse MQTT Packet. -%% +%%------------------------------------------------------------------------------ +%% @doc Parse MQTT Packet %% @end -%%%----------------------------------------------------------------------------- +%%------------------------------------------------------------------------------ -spec parse(binary(), {none, [option()]} | fun()) -> {ok, mqtt_packet()} | {error, any()} | {more, fun()}. parse(<<>>, {none, Limit}) -> {more, fun(Bin) -> parse(Bin, {none, Limit}) end}; diff --git a/apps/emqtt/src/emqtt_serialiser.erl b/apps/emqtt/src/emqtt_serialiser.erl index 402b6cba3..1807ae51b 100644 --- a/apps/emqtt/src/emqtt_serialiser.erl +++ b/apps/emqtt/src/emqtt_serialiser.erl @@ -20,13 +20,13 @@ %%% SOFTWARE. %%%----------------------------------------------------------------------------- %%% @doc -%%% emqtt packet serialiser. +%%% MQTT Packet Serialiser. %%% %%% @end %%%----------------------------------------------------------------------------- -module(emqtt_serialiser). --author("feng@emqtt.io"). +-author("Feng Lee "). -include("emqtt.hrl"). @@ -36,9 +36,7 @@ -export([serialise/1]). %%------------------------------------------------------------------------------ -%% @doc -%% Serialise MQTT Packet. -%% +%% @doc Serialise MQTT Packet %% @end %%------------------------------------------------------------------------------ -spec serialise(mqtt_packet()) -> binary(). diff --git a/apps/emqtt/src/emqtt_topic.erl b/apps/emqtt/src/emqtt_topic.erl index e9f4a1a05..697fe5d9a 100644 --- a/apps/emqtt/src/emqtt_topic.erl +++ b/apps/emqtt/src/emqtt_topic.erl @@ -20,13 +20,13 @@ %%% SOFTWARE. %%%----------------------------------------------------------------------------- %%% @doc -%%% emqtt topic. +%%% MQTT Topic %%% %%% @end %%%----------------------------------------------------------------------------- -module(emqtt_topic). --author('feng@emqtt.io'). +-author("Feng Lee "). -import(lists, [reverse/1]). @@ -42,12 +42,10 @@ -export_type([word/0, triple/0]). --define(MAX_TOPIC_LEN, 65535). +-define(MAX_TOPIC_LEN, 4096). %%%----------------------------------------------------------------------------- -%% @doc -%% Is wildcard topic? -%% +%% @doc Is wildcard topic? %% @end %%%----------------------------------------------------------------------------- -spec wildcard(binary()) -> true | false. @@ -62,12 +60,10 @@ wildcard(['+'|_]) -> wildcard([_H|T]) -> wildcard(T). -%%%----------------------------------------------------------------------------- -%% @doc -%% Match Topic name with filter. -%% +%%------------------------------------------------------------------------------ +%% @doc Match Topic name with filter %% @end -%%%----------------------------------------------------------------------------- +%%------------------------------------------------------------------------------ -spec match(Name, Filter) -> boolean() when Name :: binary() | words(), Filter :: binary() | words(). @@ -92,12 +88,10 @@ match([_H1|_], []) -> match([], [_H|_T2]) -> false. -%%%----------------------------------------------------------------------------- -%% @doc -%% Validate Topic -%% +%%------------------------------------------------------------------------------ +%% @doc Validate Topic %% @end -%%%----------------------------------------------------------------------------- +%%------------------------------------------------------------------------------ -spec validate({name | filter, binary()}) -> boolean(). validate({_, <<>>}) -> false; @@ -133,9 +127,7 @@ validate3(<<_/utf8, Rest/binary>>) -> validate3(Rest). %%%----------------------------------------------------------------------------- -%% @doc -%% Topic to Triples. -%% +%% @doc Topic to Triples %% @end %%%----------------------------------------------------------------------------- -spec triples(binary()) -> list(triple()). @@ -159,12 +151,10 @@ bin('+') -> <<"+">>; bin('#') -> <<"#">>; bin(B) when is_binary(B) -> B. -%%%----------------------------------------------------------------------------- -%% @doc -%% Split Topic to Words. -%% +%%------------------------------------------------------------------------------ +%% @doc Split Topic Path to Words %% @end -%%%----------------------------------------------------------------------------- +%%------------------------------------------------------------------------------ -spec words(binary()) -> words(). words(Topic) when is_binary(Topic) -> [word(W) || W <- binary:split(Topic, <<"/">>, [global])].