misc fix
This commit is contained in:
parent
aab6dcf8d1
commit
6907d4feed
|
@ -1,7 +1,7 @@
|
||||||
{application, emqtt,
|
{application, emqtt,
|
||||||
[
|
[
|
||||||
{description, "Erlang MQTT Common Library"},
|
{description, "Erlang Common MQTT Library"},
|
||||||
{vsn, "0.6.0"},
|
{vsn, "0.6.1"},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications, [
|
{applications, [
|
||||||
|
|
|
@ -20,13 +20,13 @@
|
||||||
%%% SOFTWARE.
|
%%% SOFTWARE.
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% MQTT Message.
|
%%% MQTT Message Functions
|
||||||
%%%
|
%%%
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
-module(emqtt_message).
|
-module(emqtt_message).
|
||||||
|
|
||||||
-author('feng@emqtt.io').
|
-author("Feng Lee <feng@emqtt.io>").
|
||||||
|
|
||||||
-include("emqtt.hrl").
|
-include("emqtt.hrl").
|
||||||
|
|
||||||
|
@ -39,9 +39,7 @@
|
||||||
-export([format/1]).
|
-export([format/1]).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Message from Packet
|
||||||
%% Message from Packet.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec from_packet(mqtt_packet()) -> mqtt_message().
|
-spec from_packet(mqtt_packet()) -> mqtt_message().
|
||||||
|
@ -73,9 +71,7 @@ from_packet(#mqtt_packet_connect{will_retain = Retain,
|
||||||
payload = Msg}.
|
payload = Msg}.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Message to packet
|
||||||
%% Message to packet
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec to_packet(mqtt_message()) -> mqtt_packet().
|
-spec to_packet(mqtt_message()) -> mqtt_packet().
|
||||||
|
@ -100,9 +96,7 @@ to_packet(#mqtt_message{msgid = MsgId,
|
||||||
payload = Payload}.
|
payload = Payload}.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc set dup, retain flag
|
||||||
%% set dup, retain flag
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec set_flag(mqtt_message()) -> mqtt_message().
|
-spec set_flag(mqtt_message()) -> mqtt_message().
|
||||||
|
@ -118,9 +112,7 @@ set_flag(Flag, Msg) when Flag =:= dup orelse Flag =:= retain -> Msg.
|
||||||
|
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Unset dup, retain flag
|
||||||
%% Unset dup, retain flag
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec unset_flag(mqtt_message()) -> mqtt_message().
|
-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.
|
unset_flag(Flag, Msg) when Flag =:= dup orelse Flag =:= retain -> Msg.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Format MQTT Message
|
||||||
%% Format MQTT Message.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
format(#mqtt_message{msgid=MsgId, qos=Qos, retain=Retain, dup=Dup, topic=Topic}) ->
|
format(#mqtt_message{msgid=MsgId, qos=Qos, retain=Retain, dup=Dup, topic=Topic}) ->
|
||||||
|
|
|
@ -20,13 +20,13 @@
|
||||||
%%% SOFTWARE.
|
%%% SOFTWARE.
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% MQTT packet utility functions.
|
%%% MQTT Packet Functions
|
||||||
%%%
|
%%%
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
-module(emqtt_packet).
|
-module(emqtt_packet).
|
||||||
|
|
||||||
-author("feng@emqtt.io").
|
-author("Feng Lee <feng@emqtt.io>").
|
||||||
|
|
||||||
-include("emqtt.hrl").
|
-include("emqtt.hrl").
|
||||||
|
|
||||||
|
@ -38,21 +38,15 @@
|
||||||
-export([format/1]).
|
-export([format/1]).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Protocol name of version
|
||||||
%% Protocol name of version.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec protocol_name(Ver) -> Name when
|
-spec protocol_name(mqtt_vsn()) -> binary().
|
||||||
Ver :: mqtt_vsn(),
|
|
||||||
Name :: binary().
|
|
||||||
protocol_name(Ver) when Ver =:= ?MQTT_PROTO_V31; Ver =:= ?MQTT_PROTO_V311->
|
protocol_name(Ver) when Ver =:= ?MQTT_PROTO_V31; Ver =:= ?MQTT_PROTO_V311->
|
||||||
proplists:get_value(Ver, ?PROTOCOL_NAMES).
|
proplists:get_value(Ver, ?PROTOCOL_NAMES).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Name of MQTT packet type
|
||||||
%% Name of MQTT packet type.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec type_name(mqtt_packet_type()) -> atom().
|
-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).
|
lists:nth(Type, ?TYPE_NAMES).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Connack Name
|
||||||
%% Connack Name.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec connack_name(mqtt_connack()) -> atom().
|
-spec connack_name(mqtt_connack()) -> atom().
|
||||||
|
@ -74,9 +66,7 @@ connack_name(?CONNACK_CREDENTIALS) -> 'CONNACK_CREDENTIALS';
|
||||||
connack_name(?CONNACK_AUTH) -> 'CONNACK_AUTH'.
|
connack_name(?CONNACK_AUTH) -> 'CONNACK_AUTH'.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Format packet
|
||||||
%% Format packet.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec format(mqtt_packet()) -> iolist().
|
-spec format(mqtt_packet()) -> iolist().
|
||||||
|
|
|
@ -20,13 +20,13 @@
|
||||||
%%% SOFTWARE.
|
%%% SOFTWARE.
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% emqtt packet parser.
|
%%% MQTT Packet Parser.
|
||||||
%%%
|
%%%
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
-module(emqtt_parser).
|
-module(emqtt_parser).
|
||||||
|
|
||||||
-author("feng@emqtt.io").
|
-author("Feng Lee <feng@emqtt.io>").
|
||||||
|
|
||||||
-include("emqtt.hrl").
|
-include("emqtt.hrl").
|
||||||
|
|
||||||
|
@ -39,24 +39,20 @@
|
||||||
|
|
||||||
-type option() :: {atom(), any()}.
|
-type option() :: {atom(), any()}.
|
||||||
|
|
||||||
%%%-----------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Initialize a parser
|
||||||
%% Initialize a parser.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec init(Opts :: [option()]) -> {none, #mqtt_packet_limit{}}.
|
-spec init(Opts :: [option()]) -> {none, #mqtt_packet_limit{}}.
|
||||||
init(Opts) -> {none, limit(Opts)}.
|
init(Opts) -> {none, limit(Opts)}.
|
||||||
|
|
||||||
limit(Opts) ->
|
limit(Opts) ->
|
||||||
#mqtt_packet_limit{max_packet_size = proplists:get_value(max_packet_size, Opts, ?MAX_LEN)}.
|
#mqtt_packet_limit{max_packet_size = proplists:get_value(max_packet_size, Opts, ?MAX_LEN)}.
|
||||||
|
|
||||||
%%%-----------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Parse MQTT Packet
|
||||||
%% Parse MQTT Packet.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec parse(binary(), {none, [option()]} | fun()) -> {ok, mqtt_packet()} | {error, any()} | {more, fun()}.
|
-spec parse(binary(), {none, [option()]} | fun()) -> {ok, mqtt_packet()} | {error, any()} | {more, fun()}.
|
||||||
parse(<<>>, {none, Limit}) ->
|
parse(<<>>, {none, Limit}) ->
|
||||||
{more, fun(Bin) -> parse(Bin, {none, Limit}) end};
|
{more, fun(Bin) -> parse(Bin, {none, Limit}) end};
|
||||||
|
|
|
@ -20,13 +20,13 @@
|
||||||
%%% SOFTWARE.
|
%%% SOFTWARE.
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% emqtt packet serialiser.
|
%%% MQTT Packet Serialiser.
|
||||||
%%%
|
%%%
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
-module(emqtt_serialiser).
|
-module(emqtt_serialiser).
|
||||||
|
|
||||||
-author("feng@emqtt.io").
|
-author("Feng Lee <feng@emqtt.io>").
|
||||||
|
|
||||||
-include("emqtt.hrl").
|
-include("emqtt.hrl").
|
||||||
|
|
||||||
|
@ -36,9 +36,7 @@
|
||||||
-export([serialise/1]).
|
-export([serialise/1]).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Serialise MQTT Packet
|
||||||
%% Serialise MQTT Packet.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec serialise(mqtt_packet()) -> binary().
|
-spec serialise(mqtt_packet()) -> binary().
|
||||||
|
|
|
@ -20,13 +20,13 @@
|
||||||
%%% SOFTWARE.
|
%%% SOFTWARE.
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% emqtt topic.
|
%%% MQTT Topic
|
||||||
%%%
|
%%%
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
-module(emqtt_topic).
|
-module(emqtt_topic).
|
||||||
|
|
||||||
-author('feng@emqtt.io').
|
-author("Feng Lee <feng@emqtt.io>").
|
||||||
|
|
||||||
-import(lists, [reverse/1]).
|
-import(lists, [reverse/1]).
|
||||||
|
|
||||||
|
@ -42,12 +42,10 @@
|
||||||
|
|
||||||
-export_type([word/0, triple/0]).
|
-export_type([word/0, triple/0]).
|
||||||
|
|
||||||
-define(MAX_TOPIC_LEN, 65535).
|
-define(MAX_TOPIC_LEN, 4096).
|
||||||
|
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Is wildcard topic?
|
||||||
%% Is wildcard topic?
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
-spec wildcard(binary()) -> true | false.
|
-spec wildcard(binary()) -> true | false.
|
||||||
|
@ -62,12 +60,10 @@ wildcard(['+'|_]) ->
|
||||||
wildcard([_H|T]) ->
|
wildcard([_H|T]) ->
|
||||||
wildcard(T).
|
wildcard(T).
|
||||||
|
|
||||||
%%%-----------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Match Topic name with filter
|
||||||
%% Match Topic name with filter.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec match(Name, Filter) -> boolean() when
|
-spec match(Name, Filter) -> boolean() when
|
||||||
Name :: binary() | words(),
|
Name :: binary() | words(),
|
||||||
Filter :: binary() | words().
|
Filter :: binary() | words().
|
||||||
|
@ -92,12 +88,10 @@ match([_H1|_], []) ->
|
||||||
match([], [_H|_T2]) ->
|
match([], [_H|_T2]) ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
%%%-----------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Validate Topic
|
||||||
%% Validate Topic
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec validate({name | filter, binary()}) -> boolean().
|
-spec validate({name | filter, binary()}) -> boolean().
|
||||||
validate({_, <<>>}) ->
|
validate({_, <<>>}) ->
|
||||||
false;
|
false;
|
||||||
|
@ -133,9 +127,7 @@ validate3(<<_/utf8, Rest/binary>>) ->
|
||||||
validate3(Rest).
|
validate3(Rest).
|
||||||
|
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Topic to Triples
|
||||||
%% Topic to Triples.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
-spec triples(binary()) -> list(triple()).
|
-spec triples(binary()) -> list(triple()).
|
||||||
|
@ -159,12 +151,10 @@ bin('+') -> <<"+">>;
|
||||||
bin('#') -> <<"#">>;
|
bin('#') -> <<"#">>;
|
||||||
bin(B) when is_binary(B) -> B.
|
bin(B) when is_binary(B) -> B.
|
||||||
|
|
||||||
%%%-----------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc Split Topic Path to Words
|
||||||
%% Split Topic to Words.
|
|
||||||
%%
|
|
||||||
%% @end
|
%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
-spec words(binary()) -> words().
|
-spec words(binary()) -> words().
|
||||||
words(Topic) when is_binary(Topic) ->
|
words(Topic) when is_binary(Topic) ->
|
||||||
[word(W) || W <- binary:split(Topic, <<"/">>, [global])].
|
[word(W) || W <- binary:split(Topic, <<"/">>, [global])].
|
||||||
|
|
Loading…
Reference in New Issue