net: lwm2m: only method GET is allowed for .well-known/core

".well-known/core" is mainly used with method GET for performing the
resource discovery (RFC 6690). Since we are implementing a LwM2M client
and is not implement a resource directory which allow others to do the
resource registration (POST to .well-known/core). Only GET method is
allowed for the usage. Report 4.5 (Method Not Allowed) if other methods
are requested.

Signed-off-by: Robert Chou <robert.ch.chou@acer.com>
This commit is contained in:
Robert Chou 2017-08-28 18:11:02 +08:00 committed by Anas Nashif
commit 652cc727fe

View file

@ -2290,12 +2290,17 @@ static int handle_request(struct zoap_packet *request,
in.reader = &plain_text_reader;
out.writer = &plain_text_writer;
code = zoap_header_get_code(in.in_zpkt);
/* parse the URL path into components */
r = zoap_find_options(in.in_zpkt, ZOAP_OPTION_URI_PATH, options, 4);
if (r <= 0) {
/* '/' is used by bootstrap-delete only */
/* TODO: handle bootstrap-delete */
/*
* TODO: Handle bootstrap deleted --
* re-add when DTLS support ready
*/
r = -EPERM;
goto error;
}
@ -2306,6 +2311,11 @@ static int handle_request(struct zoap_packet *request,
strncmp(options[0].value, ".well-known", 11) == 0) &&
(options[1].len == 4 &&
strncmp(options[1].value, "core", 4) == 0)) {
if ((code & ZOAP_REQUEST_MASK) != ZOAP_METHOD_GET) {
r = -EPERM;
goto error;
}
discover = true;
} else {
r = zoap_options_to_path(options, r, &path);
@ -2334,10 +2344,6 @@ static int handle_request(struct zoap_packet *request,
accept = LWM2M_FORMAT_OMA_TLV;
}
/* TODO: Handle bootstrap deleted -- re-add when DTLS support ready */
code = zoap_header_get_code(in.in_zpkt);
/* find registered obj */
obj = get_engine_obj(path.obj_id);
if (!obj) {