commit
1de176a887
|
@ -88,13 +88,13 @@ handle_request(Method, Path, Req) ->
|
|||
%%--------------------------------------------------------------------
|
||||
|
||||
http_publish(Req) ->
|
||||
Params = mochiweb_request:parse_post(Req),
|
||||
Params = [{iolist_to_binary(Key), Val} || {Key, Val} <- mochiweb_request:parse_post(Req)],
|
||||
lager:info("HTTP Publish: ~p", [Params]),
|
||||
Topics = topics(Params),
|
||||
ClientId = get_value("client", Params, http),
|
||||
Qos = int(get_value("qos", Params, "0")),
|
||||
Retain = bool(get_value("retain", Params, "0")),
|
||||
Payload = list_to_binary(get_value("message", Params)),
|
||||
ClientId = get_value(<<"client">>, Params, http),
|
||||
Qos = int(get_value(<<"qos">>, Params, "0")),
|
||||
Retain = bool(get_value(<<"retain">>, Params, "0")),
|
||||
Payload = iolist_to_binary(get_value(<<"message">>, Params)),
|
||||
case {validate(qos, Qos), validate(topics, Topics)} of
|
||||
{true, true} ->
|
||||
lists:foreach(fun(Topic) ->
|
||||
|
@ -109,8 +109,8 @@ http_publish(Req) ->
|
|||
end.
|
||||
|
||||
topics(Params) ->
|
||||
Tokens = [get_value("topic", Params) | string:tokens(get_value("topics", Params, ""), ",")],
|
||||
[list_to_binary(Token) || Token <- Tokens, Token =/= undefined].
|
||||
Tokens = [get_value(<<"topic">>, Params) | string:tokens(get_value(<<"topics">>, Params, ""), ",")],
|
||||
[iolist_to_binary(Token) || Token <- Tokens, Token =/= undefined].
|
||||
|
||||
validate(qos, Qos) ->
|
||||
(Qos >= ?QOS_0) and (Qos =< ?QOS_2);
|
||||
|
@ -151,10 +151,16 @@ authorized(Req) ->
|
|||
user_passwd(BasicAuth) ->
|
||||
list_to_tuple(binary:split(base64:decode(BasicAuth), <<":">>)).
|
||||
|
||||
int(I) when is_integer(I)-> I;
|
||||
int(B) when is_binary(B)-> binary_to_integer(B);
|
||||
int(S) -> list_to_integer(S).
|
||||
|
||||
bool(0) -> false;
|
||||
bool(1) -> true;
|
||||
bool("0") -> false;
|
||||
bool("1") -> true.
|
||||
bool("1") -> true;
|
||||
bool(<<"0">>) -> false;
|
||||
bool(<<"1">>) -> true.
|
||||
|
||||
is_websocket(Upgrade) ->
|
||||
Upgrade =/= undefined andalso string:to_lower(Upgrade) =:= "websocket".
|
||||
|
|
Loading…
Reference in New Issue