[api] add a device and digest check to /sensor
This commit is contained in:
parent
80073a5de5
commit
f8ba3937bb
|
@ -26,15 +26,18 @@
|
||||||
jsonpCallback}).
|
jsonpCallback}).
|
||||||
|
|
||||||
%% checks
|
%% checks
|
||||||
check_version(undefined, undefined) ->
|
check_version(Version) ->
|
||||||
{false, false};
|
|
||||||
check_version(Version, undefined) ->
|
|
||||||
case Version of
|
case Version of
|
||||||
"1.0" -> {Version, true};
|
"1.0" -> {Version, true};
|
||||||
_ -> {false, false}
|
_ -> {false, false}
|
||||||
end;
|
end.
|
||||||
|
|
||||||
|
check_version(undefined, undefined) ->
|
||||||
|
{false, false};
|
||||||
|
check_version(Version, undefined) ->
|
||||||
|
check_version(Version);
|
||||||
check_version(undefined, Version) ->
|
check_version(undefined, Version) ->
|
||||||
check_version(Version, undefined);
|
check_version(Version);
|
||||||
check_version(_, _) ->
|
check_version(_, _) ->
|
||||||
{false, false}.
|
{false, false}.
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,12 @@ allowed_methods(ReqData, State) ->
|
||||||
{['POST'], ReqData, State}.
|
{['POST'], ReqData, State}.
|
||||||
|
|
||||||
malformed_request(ReqData, State) ->
|
malformed_request(ReqData, State) ->
|
||||||
{_Version, ValidVersion} = check_version(wrq:get_req_header("X-Version", ReqData), wrq:get_qs_value("version", ReqData)),
|
{_Version, ValidVersion} = check_version(wrq:get_req_header("X-Version", ReqData)),
|
||||||
% TODO: check validity of X-Device and X-Digest headers
|
{_Device, ValidDevice} = check_32hex(wrq:get_req_header("X-Device", ReqData)),
|
||||||
|
{_Digest, ValidDigest} = check_32hex(wrq:get_req_header("X-Digest", ReqData)),
|
||||||
|
|
||||||
{case {ValidVersion} of
|
{case {ValidVersion, ValidDevice, ValidDigest} of
|
||||||
{true} -> false;
|
{true, true, true} -> false;
|
||||||
_ -> true
|
_ -> true
|
||||||
end,
|
end,
|
||||||
ReqData, State}.
|
ReqData, State}.
|
||||||
|
|
Loading…
Reference in New Issue