support http
This commit is contained in:
parent
417909de20
commit
4e01e12e25
|
@ -1,31 +1,46 @@
|
||||||
%% The contents of this file are subject to the Mozilla Public License
|
%%-----------------------------------------------------------------------------
|
||||||
%% Version 1.1 (the "License"); you may not use this file except in
|
%% Copyright (c) 2014, Feng Lee <feng.lee@slimchat.io>
|
||||||
%% compliance with the License. You may obtain a copy of the License at
|
|
||||||
%% http://www.mozilla.org/MPL/
|
|
||||||
%%
|
%%
|
||||||
%% Software distributed under the License is distributed on an "AS IS"
|
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
%% of this software and associated documentation files (the "Software"), to deal
|
||||||
%% License for the specific language governing rights and limitations
|
%% in the Software without restriction, including without limitation the rights
|
||||||
%% under the License.
|
%% 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 Original Code is eMQTT
|
%% The above copyright notice and this permission notice shall be included in all
|
||||||
|
%% copies or substantial portions of the Software.
|
||||||
%%
|
%%
|
||||||
%% The Initial Developer of the Original Code is <ery.lee at gmail dot com>
|
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
%% Copyright (C) 2012 Ery Lee All Rights Reserved.
|
%% 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.
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
|
||||||
-module(emqtt).
|
-module(emqtt).
|
||||||
|
|
||||||
-export([start/0]).
|
-export([listen/1]).
|
||||||
|
|
||||||
|
-define(MQTT_SOCKOPTS, [
|
||||||
|
binary,
|
||||||
|
{packet, raw},
|
||||||
|
{reuseaddr, true},
|
||||||
|
{backlog, 512},
|
||||||
|
{nodelay, false}
|
||||||
|
]).
|
||||||
|
|
||||||
%%
|
listen(Listeners) when is_list(Listeners) ->
|
||||||
%% @spec start() -> 'ok'
|
[listen(Listener) || Listener <- Listeners];
|
||||||
%%
|
|
||||||
start() ->
|
|
||||||
application:start(sasl),
|
|
||||||
mnesia:create_schema([node()]),
|
|
||||||
mnesia:start(),
|
|
||||||
lager:start(),
|
|
||||||
application:start(emqtt).
|
|
||||||
|
|
||||||
|
listen({mqtt, Port, Options}) ->
|
||||||
|
MFArgs = {emqtt_client, start_link, []},
|
||||||
|
esockd:listen(mqtt, Port, Options ++ ?MQTT_SOCKOPTS, MFArgs);
|
||||||
|
|
||||||
|
listen({http, Port, Options}) ->
|
||||||
|
Auth = proplists:get_value(auth, Options),
|
||||||
|
MFArgs = {emqtt_http, handle, [Auth]},
|
||||||
|
mochiweb:start_http(Port, proplists:delete(auth, Options), MFArgs).
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ start(_StartType, _StartArgs) ->
|
||||||
print_banner(),
|
print_banner(),
|
||||||
{ok, SupPid} = emqtt_sup:start_link(),
|
{ok, SupPid} = emqtt_sup:start_link(),
|
||||||
{ok, Listeners} = application:get_env(listen),
|
{ok, Listeners} = application:get_env(listen),
|
||||||
emqtt_listener:start(Listeners),
|
emqtt:listen(Listeners),
|
||||||
register(emqtt, self()),
|
register(emqtt, self()),
|
||||||
print_vsn(),
|
print_vsn(),
|
||||||
{ok, SupPid}.
|
{ok, SupPid}.
|
||||||
|
|
|
@ -1,17 +1,24 @@
|
||||||
%% The contents of this file are subject to the Mozilla Public License
|
%%-----------------------------------------------------------------------------
|
||||||
%% Version 1.1 (the "License"); you may not use this file except in
|
%% Copyright (c) 2014, Feng Lee <feng.lee@slimchat.io>
|
||||||
%% compliance with the License. You may obtain a copy of the License at
|
|
||||||
%% http://www.mozilla.org/MPL/
|
|
||||||
%%
|
%%
|
||||||
%% Software distributed under the License is distributed on an "AS IS"
|
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
%% of this software and associated documentation files (the "Software"), to deal
|
||||||
%% License for the specific language governing rights and limitations
|
%% in the Software without restriction, including without limitation the rights
|
||||||
%% under the License.
|
%% 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 Original Code is eMQTT
|
%% The above copyright notice and this permission notice shall be included in all
|
||||||
|
%% copies or substantial portions of the Software.
|
||||||
%%
|
%%
|
||||||
%% The Initial Developer of the Original Code is <ery.lee at gmail dot com>
|
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
%% Copyright (C) 2012 Ery Lee All Rights Reserved.
|
%% 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.
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
|
||||||
-module(emqtt_auth_anonymous).
|
-module(emqtt_auth_anonymous).
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,24 @@
|
||||||
%% The contents of this file are subject to the Mozilla Public License
|
%%-----------------------------------------------------------------------------
|
||||||
%% Version 1.1 (the "License"); you may not use this file except in
|
%% Copyright (c) 2014, Feng Lee <feng.lee@slimchat.io>
|
||||||
%% compliance with the License. You may obtain a copy of the License at
|
|
||||||
%% http://www.mozilla.org/MPL/
|
|
||||||
%%
|
%%
|
||||||
%% Software distributed under the License is distributed on an "AS IS"
|
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
%% of this software and associated documentation files (the "Software"), to deal
|
||||||
%% License for the specific language governing rights and limitations
|
%% in the Software without restriction, including without limitation the rights
|
||||||
%% under the License.
|
%% 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 Original Code is eMQTT
|
%% The above copyright notice and this permission notice shall be included in all
|
||||||
|
%% copies or substantial portions of the Software.
|
||||||
%%
|
%%
|
||||||
%% The Initial Developer of the Original Code is <ery.lee at gmail dot com>
|
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
%% Copyright (C) 2012 Ery Lee All Rights Reserved.
|
%% 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.
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
|
||||||
-module(emqtt_db).
|
-module(emqtt_db).
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,28 @@
|
||||||
%% This file is a copy of `rabbitmq_mqtt_frame.erl' from rabbitmq.
|
%%------------------------------------------------------------------------------
|
||||||
%% License:
|
%% Copyright (c) 2014, Feng Lee <feng.lee@slimchat.io>
|
||||||
%% The contents of this file are subject to the Mozilla Public License
|
|
||||||
%% Version 1.1 (the "License"); you may not use this file except in
|
|
||||||
%% compliance with the License. You may obtain a copy of the License
|
|
||||||
%% at http://www.mozilla.org/MPL/
|
|
||||||
%%
|
%%
|
||||||
%% Software distributed under the License is distributed on an "AS IS"
|
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
%% of this software and associated documentation files (the "Software"), to deal
|
||||||
%% the License for the specific language governing rights and
|
%% in the Software without restriction, including without limitation the rights
|
||||||
%% limitations under the License.
|
%% 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 Original Code is RabbitMQ.
|
%% The above copyright notice and this permission notice shall be included in all
|
||||||
|
%% copies or substantial portions of the Software.
|
||||||
%%
|
%%
|
||||||
%% The Initial Developer of the Original Code is VMware, Inc.
|
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved.
|
%% 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.
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
%%
|
%%
|
||||||
|
%% The Original Code is from RabbitMQ.
|
||||||
|
%%
|
||||||
|
|
||||||
-module(emqtt_frame).
|
-module(emqtt_frame).
|
||||||
|
|
||||||
-include("emqtt_frame.hrl").
|
-include("emqtt_frame.hrl").
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
|
|
||||||
-module(emqtt_http).
|
-module(emqtt_http).
|
||||||
|
|
||||||
-export([handle/1]).
|
-export([handle/2]).
|
||||||
|
|
||||||
handle(Req) ->
|
handle(Req, Auth) ->
|
||||||
Req:not_found().
|
Req:not_found().
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,24 @@
|
||||||
%% The contents of this file are subject to the Mozilla Public License
|
%%-----------------------------------------------------------------------------
|
||||||
%% Version 1.1 (the "License"); you may not use this file except in
|
%% Copyright (c) 2014, Feng Lee <feng.lee@slimchat.io>
|
||||||
%% compliance with the License. You may obtain a copy of the License
|
|
||||||
%% at http://www.mozilla.org/MPL/
|
|
||||||
%%
|
%%
|
||||||
%% Software distributed under the License is distributed on an "AS IS"
|
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
%% of this software and associated documentation files (the "Software"), to deal
|
||||||
%% the License for the specific language governing rights and
|
%% in the Software without restriction, including without limitation the rights
|
||||||
%% limitations under the License.
|
%% 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:
|
||||||
%%
|
%%
|
||||||
%% Developer of the eMQTT Code is <ery.lee@gmail.com>
|
%% The above copyright notice and this permission notice shall be included in all
|
||||||
%% Copyright (c) 2012 Ery Lee. All rights reserved.
|
%% 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.
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
-module(emqtt_keep_alive).
|
-module(emqtt_keep_alive).
|
||||||
|
|
||||||
-export([new/2,
|
-export([new/2,
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
%%------------------------------------------------------------------------------
|
|
||||||
%% Copyright (c) 2014, Feng Lee <feng.lee@slimchat.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.
|
|
||||||
%%------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
-module(emqtt_listener).
|
|
||||||
|
|
||||||
-include("emqtt.hrl").
|
|
||||||
|
|
||||||
-define(MQTT_SOCKOPTS, [
|
|
||||||
binary,
|
|
||||||
{packet, raw},
|
|
||||||
{reuseaddr, true},
|
|
||||||
{backlog, 512},
|
|
||||||
{nodelay, false}
|
|
||||||
]).
|
|
||||||
|
|
||||||
-export([start/1]).
|
|
||||||
|
|
||||||
start(Listeners) ->
|
|
||||||
[open(Listener) || Listener <- Listeners].
|
|
||||||
|
|
||||||
open({mqtt, Port, Options}) ->
|
|
||||||
MFArgs = {emqtt_client, start_link, []},
|
|
||||||
Res = esockd:listen(mqtt, Port, Options ++ ?MQTT_SOCKOPTS, MFArgs),
|
|
||||||
io:format("~p~n", [Res]);
|
|
||||||
|
|
||||||
open({http, Port, Options}) ->
|
|
||||||
MFArgs = {emqtt_http, handle, []},
|
|
||||||
esockd:listen(http, Port, Options, MFArgs).
|
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,8 @@
|
||||||
]},
|
]},
|
||||||
{http, 8883, [
|
{http, 8883, [
|
||||||
{max_conns, 512},
|
{max_conns, 512},
|
||||||
{acceptor_pool, 1}
|
{acceptor_pool, 1},
|
||||||
|
{auth, {"username", "passwd"}}
|
||||||
]}
|
]}
|
||||||
]}
|
]}
|
||||||
]}
|
]}
|
||||||
|
|
Loading…
Reference in New Issue