Ery Lee пре 11 година
родитељ
комит
99633fb815

+ 69 - 0
apps/emqtt/include/emqtt.hrl

@@ -0,0 +1,69 @@
+%%%-----------------------------------------------------------------------------
+%%% @Copyright (C) 2012-2015, Feng Lee <feng@emqtt.io>
+%%%
+%%% Permission is hereby granted, free of charge, to any person obtaining a copy
+%%% of this software and associated documentation files (the "Software"), to deal
+%%% in the Software without restriction, including without limitation the rights
+%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+%%% copies of the Software, and to permit persons to whom the Software is
+%%% furnished to do so, subject to the following conditions:
+%%%
+%%% The above copyright notice and this permission notice shall be included in all
+%%% copies or substantial portions of the Software.
+%%%
+%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+%%% SOFTWARE.
+%%%-----------------------------------------------------------------------------
+%%% @doc
+%%% MQTT Common Header.
+%%%
+%%% @end
+%%%-----------------------------------------------------------------------------
+
+%%------------------------------------------------------------------------------
+%% MQTT Protocol Version and Levels
+%%------------------------------------------------------------------------------
+-define(MQTT_PROTO_V31,  3).
+-define(MQTT_PROTO_V311, 4).
+
+-define(PROTOCOL_NAMES, [
+    {?MQTT_PROTO_V31, <<"MQIsdp">>},
+    {?MQTT_PROTO_V311, <<"MQTT">>}]).
+
+-type mqtt_vsn() :: ?MQTT_PROTO_V31 | ?MQTT_PROTO_V311.
+
+%%------------------------------------------------------------------------------
+%% QoS Levels
+%%------------------------------------------------------------------------------
+
+-define(QOS_0, 0).
+-define(QOS_1, 1).
+-define(QOS_2, 2).
+
+-define(IS_QOS(I), (I >= ?QOS_0 andalso I =< ?QOS_2)).
+
+-type mqtt_qos() :: ?QOS_0 | ?QOS_1 | ?QOS_2.
+
+%%------------------------------------------------------------------------------
+%% MQTT Message
+%%------------------------------------------------------------------------------
+
+-type mqtt_msgid() :: undefined | 1..16#ffff.
+
+-record(mqtt_message, {
+    %% topic is first for message may be retained
+    topic           :: binary(),
+    qos    = ?QOS_0 :: mqtt_qos(),
+    retain = false  :: boolean(),
+    dup    = false  :: boolean(),
+    msgid           :: mqtt_msgid(),
+    payload         :: binary()
+}).
+
+-type mqtt_message() :: #mqtt_message{}.
+

+ 0 - 27
apps/emqtt/include/emqtt_packet.hrl

@@ -25,33 +25,6 @@
 %%% @end
 %%% @end
 %%%-----------------------------------------------------------------------------
 %%%-----------------------------------------------------------------------------
 
 
--author("feng@emqtt.io").
-
-%%------------------------------------------------------------------------------
-%% MQTT Protocol Version and Levels
-%%------------------------------------------------------------------------------
--define(MQTT_PROTO_V31, 3).
--define(MQTT_PROTO_V311, 4).
-
--define(PROTOCOL_NAMES, [
-    {?MQTT_PROTO_V31, <<"MQIsdp">>},
-    {?MQTT_PROTO_V311, <<"MQTT">>}]).
-
--type mqtt_vsn() :: ?MQTT_PROTO_V31 | ?MQTT_PROTO_V311.
-
-%%------------------------------------------------------------------------------
-%% QoS Levels
-%%------------------------------------------------------------------------------
-
--define(QOS_0, 0).
--define(QOS_1, 1).
--define(QOS_2, 2).
--define(QOS_ERR, 128).
-
--define(IS_QOS(I), (I >= ?QOS_0 andalso I =< ?QOS_2)).
-
--type mqtt_qos() :: ?QOS_0 | ?QOS_1 | ?QOS_2.
-
 %%------------------------------------------------------------------------------
 %%------------------------------------------------------------------------------
 %% Max ClientId Length. Why 1024? NiDongDe!
 %% Max ClientId Length. Why 1024? NiDongDe!
 %%------------------------------------------------------------------------------
 %%------------------------------------------------------------------------------

+ 1 - 3
apps/emqtt/src/emqtt.app.src

@@ -2,9 +2,7 @@
  [
  [
   {description, "Erlang MQTT Common Library"},
   {description, "Erlang MQTT Common Library"},
   {vsn, "0.6.0"},
   {vsn, "0.6.0"},
-  {modules, [
-             emqtt_parser
-            ]},
+  {modules, []},
   {registered, []},
   {registered, []},
   {applications, [
   {applications, [
                   kernel,
                   kernel,

+ 0 - 18
apps/emqtt/src/emqtt.erl

@@ -1,18 +0,0 @@
--module(emqtt).
-
-%% emqtt: emqtt library's entry point.
-
--export([my_func/0]).
-
-
-%% API
-
-my_func() ->
-    ok().
-
-%% Internals
-
-ok() ->
-    ok.
-
-%% End of Module.

+ 2 - 0
apps/emqtt/src/emqtt_packet.erl

@@ -28,6 +28,8 @@
 
 
 -author("feng@emqtt.io").
 -author("feng@emqtt.io").
 
 
+-include("emqtt.hrl").
+
 -include("emqtt_packet.hrl").
 -include("emqtt_packet.hrl").
 
 
 %% API
 %% API

+ 2 - 0
apps/emqtt/src/emqtt_parser.erl

@@ -28,6 +28,8 @@
 
 
 -author("feng@emqtt.io").
 -author("feng@emqtt.io").
 
 
+-include("emqtt.hrl").
+
 -include("emqtt_packet.hrl").
 -include("emqtt_packet.hrl").
 
 
 %% API
 %% API

+ 2 - 0
apps/emqtt/src/emqtt_serialiser.erl

@@ -28,6 +28,8 @@
 
 
 -author("feng@emqtt.io").
 -author("feng@emqtt.io").
 
 
+-include("emqtt.hrl").
+
 -include("emqtt_packet.hrl").
 -include("emqtt_packet.hrl").
 
 
 %% API
 %% API

+ 8 - 7
apps/emqtt/test/emqtt_parser_tests.erl

@@ -26,6 +26,7 @@
 %%%-----------------------------------------------------------------------------
 %%%-----------------------------------------------------------------------------
 -module(emqtt_parser_tests).
 -module(emqtt_parser_tests).
 
 
+-include("emqtt.hrl").
 -include("emqtt_packet.hrl").
 -include("emqtt_packet.hrl").
 
 
 -ifdef(TEST).
 -ifdef(TEST).
@@ -41,9 +42,9 @@ parse_connect_test() ->
                                                       dup  = false,
                                                       dup  = false,
                                                       qos  = 0,
                                                       qos  = 0,
                                                       retain = false},
                                                       retain = false},
-                         variable = #mqtt_packet_connect{proto_ver = 3,
+                         variable = #mqtt_packet_connect{proto_ver  = 3,
                                                          proto_name = <<"MQIsdp">>,
                                                          proto_name = <<"MQIsdp">>,
-                                                         client_id = <<"mosqpub/10451-iMac.loca">>,
+                                                         clientid   = <<"mosqpub/10451-iMac.loca">>,
                                                          clean_sess = true,
                                                          clean_sess = true,
                                                          keep_alive = 60}}, <<>>}, emqtt_parser:parse(V31ConnBin, State)),
                                                          keep_alive = 60}}, <<>>}, emqtt_parser:parse(V31ConnBin, State)),
     %% CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10451-iMac.loca, ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60, Username=undefined, Password=undefined)
     %% CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10451-iMac.loca, ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60, Username=undefined, Password=undefined)
@@ -53,11 +54,11 @@ parse_connect_test() ->
                                                       dup = false, 
                                                       dup = false, 
                                                       qos = 0, 
                                                       qos = 0, 
                                                       retain = false}, 
                                                       retain = false}, 
-                         variable = #mqtt_packet_connect{proto_ver = 4, 
+                         variable = #mqtt_packet_connect{proto_ver  = 4, 
                                                          proto_name = <<"MQTT">>, 
                                                          proto_name = <<"MQTT">>, 
-                                                         client_id = <<"mosqpub/10451-iMac.loca">>,
+                                                         clientid   = <<"mosqpub/10451-iMac.loca">>,
                                                          clean_sess = true, 
                                                          clean_sess = true, 
-                                                           keep_alive = 60 } }, <<>>}, emqtt_parser:parse(V311ConnBin, State)),
+                                                         keep_alive = 60 } }, <<>>}, emqtt_parser:parse(V311ConnBin, State)),
 
 
     %% CONNECT(Qos=0, Retain=false, Dup=false, ClientId="", ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60)
     %% CONNECT(Qos=0, Retain=false, Dup=false, ClientId="", ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60)
     V311ConnWithoutClientId = <<16,12,0,4,77,81,84,84,4,2,0,60,0,0>>,
     V311ConnWithoutClientId = <<16,12,0,4,77,81,84,84,4,2,0,60,0,0>>,
@@ -68,7 +69,7 @@ parse_connect_test() ->
                                                       retain = false}, 
                                                       retain = false}, 
                          variable = #mqtt_packet_connect{proto_ver = 4, 
                          variable = #mqtt_packet_connect{proto_ver = 4, 
                                                          proto_name = <<"MQTT">>, 
                                                          proto_name = <<"MQTT">>, 
-                                                         client_id = <<>>,
+                                                         clientid = <<>>,
                                                          clean_sess = true, 
                                                          clean_sess = true, 
                                                          keep_alive = 60 } }, <<>>}, emqtt_parser:parse(V311ConnWithoutClientId, State)),
                                                          keep_alive = 60 } }, <<>>}, emqtt_parser:parse(V311ConnWithoutClientId, State)),
     %%CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10452-iMac.loca, ProtoName=MQIsdp, ProtoVsn=3, CleanSess=true, KeepAlive=60, Username=test, Password=******, Will(Qos=1, Retain=false, Topic=/will, Msg=willmsg))
     %%CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10452-iMac.loca, ProtoName=MQIsdp, ProtoVsn=3, CleanSess=true, KeepAlive=60, Username=test, Password=******, Will(Qos=1, Retain=false, Topic=/will, Msg=willmsg))
@@ -80,7 +81,7 @@ parse_connect_test() ->
                                                       retain = false},
                                                       retain = false},
                          variable = #mqtt_packet_connect{proto_ver = 3,
                          variable = #mqtt_packet_connect{proto_ver = 3,
                                                          proto_name = <<"MQIsdp">>, 
                                                          proto_name = <<"MQIsdp">>, 
-                                                         client_id = <<"mosqpub/10452-iMac.loca">>,
+                                                         clientid = <<"mosqpub/10452-iMac.loca">>,
                                                          clean_sess = true, 
                                                          clean_sess = true, 
                                                          keep_alive = 60,
                                                          keep_alive = 60,
                                                          will_retain = false,
                                                          will_retain = false,

+ 1 - 0
apps/emqtt/test/emqtt_serialiser_tests.erl

@@ -26,6 +26,7 @@
 %%%-----------------------------------------------------------------------------
 %%%-----------------------------------------------------------------------------
 -module(emqtt_serialiser_tests).
 -module(emqtt_serialiser_tests).
 
 
+-include("emqtt.hrl").
 -include("emqtt_packet.hrl").
 -include("emqtt_packet.hrl").
 
 
 -ifdef(TEST).
 -ifdef(TEST).

+ 2 - 2
apps/emqttd/src/emqttd_retained.erl

@@ -42,13 +42,13 @@
 -export([retain/1, redeliver/2]).
 -export([retain/1, redeliver/2]).
 
 
 mnesia(create) ->
 mnesia(create) ->
-    ok = emqtt_mnesia:create_table(message, [
+    ok = emqttd_mnesia:create_table(message, [
                 {type, ordered_set},
                 {type, ordered_set},
                 {ram_copies, [node()]},
                 {ram_copies, [node()]},
                 {record_name, mqtt_message},
                 {record_name, mqtt_message},
                 {attributes, record_info(fields, mqtt_message)}]);
                 {attributes, record_info(fields, mqtt_message)}]);
 mnesia(replicate) ->
 mnesia(replicate) ->
-    ok = emqtt_mnesia:copy_table(message).
+    ok = emqttd_mnesia:copy_table(message).
 
 
 
 
 
 

+ 1 - 1
rel/reltool.config

@@ -47,7 +47,7 @@
        {app, lager, [{mod_cond, app}, {incl_cond, include}]},
        {app, lager, [{mod_cond, app}, {incl_cond, include}]},
        {app, esockd, [{mod_cond, app}, {incl_cond, include}]},
        {app, esockd, [{mod_cond, app}, {incl_cond, include}]},
        {app, mochiweb, [{mod_cond, app}, {incl_cond, include}]},
        {app, mochiweb, [{mod_cond, app}, {incl_cond, include}]},
-       {app, emqtt, [{mod_cond, app}, {incl_cond, include}]}
+       {app, emqtt, [{mod_cond, app}, {incl_cond, include}]},
        {app, emqttd, [{mod_cond, app}, {incl_cond, include}]}
        {app, emqttd, [{mod_cond, app}, {incl_cond, include}]}
       ]}.
       ]}.