about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <vincent@kivra.com>2016-02-13T14·30+0100
committerVincent Ambo <vincent@kivra.com>2016-02-13T14·30+0100
commitad0d127ab3ce0d56c275d8b5ea5f56b7a9e4c852 (patch)
tree536185a97f752efca5c6fc1a609cd8138b553187
parent763bae8a61cc6981041a0fc145daa9872b5ea7fa (diff)
Use maps for headers
-rw-r--r--Makefile6
-rw-r--r--src/stomp.app.src2
-rw-r--r--src/stomp_worker.erl48
3 files changed, 28 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index 8be69c1eef8d..b3bc54673d0b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
-PROJECT = stomp.erl
-PROJECT_DESCRIPTION = New project
-PROJECT_VERSION = 0.0.1
+PROJECT = stomp
+PROJECT_DESCRIPTION = STOMP client for Erlang
+PROJECT_VERSION = 0.1.0
 
 # Whitespace to be used when creating files from templates.
 SP = 4
diff --git a/src/stomp.app.src b/src/stomp.app.src
index 15c1f386e805..baf0e271d1f0 100644
--- a/src/stomp.app.src
+++ b/src/stomp.app.src
@@ -4,4 +4,4 @@
                       {registered, [stomp_worker]},
                       {env, []},
                       {applications, [kernel, stdlib]},
-                      {mod, {stomp_app, []}}].
+                      {mod, {stomp_app, []}}]}.
diff --git a/src/stomp_worker.erl b/src/stomp_worker.erl
index b4604981836d..80981d37ab52 100644
--- a/src/stomp_worker.erl
+++ b/src/stomp_worker.erl
@@ -12,6 +12,9 @@
 -export([terminate/2]).
 -export([code_change/3]).
 
+%% Testing
+-compile(export_all).
+
 -include("stomp.hrl").
 
 %% State of a stomp_worker
@@ -69,7 +72,7 @@ handle_call({subscribe, Dest, Ack}, From, State) ->
 handle_call(_Req, _From, State) ->
     {reply, ignored, State}.
 
-handle_info({tcp, Conn, Frame}, State#state{connection = Conn}) ->
+handle_info({tcp, Conn, Frame}, State) when Conn =:= State#state.connection ->
     handle_frame(Frame, State);
 handle_info(_Msg, State) ->
     {noreply, State}.
@@ -110,10 +113,7 @@ subscribe(Socket, Id, Queue, Ack) ->
 
 %%% Parsing STOMP frames
 
-handle_frame(<<"MESSAGE", "\n", Frame/binary>>,
-             #state{subscribers = Subscribers,
-                    subscriptions = Subscriptions}) ->
-    
+handle_frame(<<"MESSAGE", "\n", _Frame/binary>>, State) ->
     {noreply, State};
 handle_frame(Frame, State) ->
     io:format("Received unknown frame ~p", [Frame]),
@@ -134,15 +134,15 @@ parse_headers(HeadersBin) ->
 %% Format a header
 -spec format_header({binary(), binary()}) -> binary().
 format_header({Key, Val}) ->
-    <<Key, ":", Val, "\n">>.
+    <<Key/binary, ":", Val/binary, "\n">>.
 
 %% Build a single STOMP frame
 -spec make_frame(binary(),
-                 list({binary(), binary()}),
+                 headers(),
                  binary())
                 -> {ok, iolist()}.
 make_frame(Command, HeaderMap, Body) ->
-    Headers = lists:map(fun format_header/1, HeaderMap),
+    Headers = lists:map(fun format_header/1, maps:to_list(HeaderMap)),
     Frame = [Command, <<"\n">>, Headers, <<"\n">>, Body, <<0>>],
     {ok, Frame}.
 
@@ -151,31 +151,31 @@ make_frame(Command, HeaderMap, Body) ->
 -spec connect_frame(list(), any(), any()) -> iolist().
 connect_frame(Host, {ok, Login}, {ok, Pass}) ->
     make_frame(<<"CONNECT">>,
-               [{"accept-version", "1.2"},
-                {"host", Host},
-                {"login", Login},
-                {"passcode", Pass},
-                {"heart-beat", "0,5000"}],
+               #{<<"accept-version">> => <<"1.2">>,
+                 <<"host">>           => Host,
+                 <<"login">>          => Login,
+                 <<"passcode">>       => Pass,
+                 <<"heart-beat">>     => <<"0,5000">>},
                []);
 connect_frame(Host, _Login, _Pass) ->
     make_frame(<<"CONNECT">>,
-               [{"accept-version", "1.2"},
-                {"host", Host},
-                %% Expect a server heartbeat every 5 seconds, let the server
-                %% expect one every 10. We don't actually check this and just
-                %% echo server heartbeats.
-                %% TODO: For now the server is told not to expect replies due to
-                %% a weird behaviour.
-                {"heart-beat", "0,5000"}],
+               #{<<"accept-version">> => <<"1.2">>,
+                 <<"host">>           => Host,
+                 %% Expect a server heartbeat every 5 seconds, let the server
+                 %% expect one every 10. We don't actually check this and just
+                 %% echo server heartbeats.
+                 %% TODO: For now the server is told not to expect replies due to
+                 %% a weird behaviour.
+                 <<"heart-beat">>     => <<"0,5000">>},
                []).
 
 
 -spec subscribe_frame(sub_id(), destination(), ack_mode()) -> iolist().
 subscribe_frame(Id, Queue, Ack) ->
     make_frame(<<"SUBSCRIBE">>,
-               [{"id", integer_to_binary(Id)},
-                {"destination", Queue},
-                {"ack", ack_mode_to_binary(Ack)}],
+               #{<<"id">>          => integer_to_binary(Id),
+                 <<"destination">> => Queue,
+                 <<"ack">>         => ack_mode_to_binary(Ack)},
                []).
 
 -spec ack_mode_to_binary(ack_mode()) -> binary().