about summary refs log tree commit diff
path: root/src/stomp_worker.erl
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2016-02-13T12·00+0100
committerVincent Ambo <tazjin@gmail.com>2016-02-13T12·00+0100
commit763bae8a61cc6981041a0fc145daa9872b5ea7fa (patch)
tree8a41bed350b1e9a9a1c2079c06d095b8ce75fbd3 /src/stomp_worker.erl
parent49c24a12d075b989a6ada5d11970ff29dd6ff226 (diff)
Add header parsing logic
Diffstat (limited to 'src/stomp_worker.erl')
-rw-r--r--src/stomp_worker.erl26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/stomp_worker.erl b/src/stomp_worker.erl
index bbdda73eac..b460498183 100644
--- a/src/stomp_worker.erl
+++ b/src/stomp_worker.erl
@@ -69,11 +69,13 @@ handle_call({subscribe, Dest, Ack}, From, State) ->
 handle_call(_Req, _From, State) ->
     {reply, ignored, State}.
 
-%% Unused gen_server callbacks
-
+handle_info({tcp, Conn, Frame}, State#state{connection = Conn}) ->
+    handle_frame(Frame, State);
 handle_info(_Msg, State) ->
     {noreply, State}.
 
+%% Unused gen_server callbacks
+
 handle_cast(_Msg, State) ->
     {noreply, State}.
 
@@ -106,6 +108,26 @@ subscribe(Socket, Id, Queue, Ack) ->
     {ok, SubscribeFrame} = subscribe_frame(Id, Queue, Ack),
     gen_tcp:send(Socket, SubscribeFrame).
 
+%%% Parsing STOMP frames
+
+handle_frame(<<"MESSAGE", "\n", Frame/binary>>,
+             #state{subscribers = Subscribers,
+                    subscriptions = Subscriptions}) ->
+    
+    {noreply, State};
+handle_frame(Frame, State) ->
+    io:format("Received unknown frame ~p", [Frame]),
+    {noreply, State}.
+
+
+%% Parse out headers into a map
+-spec parse_headers(binary()) -> headers().
+parse_headers(HeadersBin) ->
+    Headers = binary:split(HeadersBin, <<"\n">>, [global]),
+    ToPairs = fun(H, M) -> [K,V | []] = binary:split(H, <<":">>),
+                           maps:put(K, V, M)
+              end,
+    {ok, lists:mapfoldl(ToPairs, #{}, Headers)}.
 
 %%% Making STOMP protocol frames