[api] add a device and digest check to /sensor

This commit is contained in:
Bart Van Der Meerssche 2011-03-24 07:31:30 +00:00
parent 80073a5de5
commit f8ba3937bb
2 changed files with 13 additions and 9 deletions

View File

@ -26,15 +26,18 @@
jsonpCallback}).
%% checks
check_version(undefined, undefined) ->
{false, false};
check_version(Version, undefined) ->
check_version(Version) ->
case Version of
"1.0" -> {Version, true};
_ -> {false, false}
end;
end.
check_version(undefined, undefined) ->
{false, false};
check_version(Version, undefined) ->
check_version(Version);
check_version(undefined, Version) ->
check_version(Version, undefined);
check_version(Version);
check_version(_, _) ->
{false, false}.

View File

@ -39,11 +39,12 @@ allowed_methods(ReqData, State) ->
{['POST'], ReqData, State}.
malformed_request(ReqData, State) ->
{_Version, ValidVersion} = check_version(wrq:get_req_header("X-Version", ReqData), wrq:get_qs_value("version", ReqData)),
% TODO: check validity of X-Device and X-Digest headers
{_Version, ValidVersion} = check_version(wrq:get_req_header("X-Version", ReqData)),
{_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
{true} -> false;
{case {ValidVersion, ValidDevice, ValidDigest} of
{true, true, true} -> false;
_ -> true
end,
ReqData, State}.