From f23e86f5890ad8af2d57765746deb449fd1f7ea1 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Mon, 30 Jan 2012 01:28:43 +0100 Subject: [PATCH] Moved status code API from REST engine to main coap implementation. --- apps/er-coap-07/er-coap-07-engine.c | 18 ++---------------- apps/er-coap-07/er-coap-07.c | 14 ++++++++++++++ apps/er-coap-07/er-coap-07.h | 4 ++++ examples/er-rest-example/Makefile | 14 ++++++++++++++ examples/er-rest-example/coap-client-example.c | 1 + 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/apps/er-coap-07/er-coap-07-engine.c b/apps/er-coap-07/er-coap-07-engine.c index a65262172..f058d499b 100644 --- a/apps/er-coap-07/er-coap-07-engine.c +++ b/apps/er-coap-07/er-coap-07-engine.c @@ -285,20 +285,6 @@ coap_get_rest_method(void *packet) return (rest_resource_flags_t)(1 << (((coap_packet_t *)packet)->code - 1)); } /*-----------------------------------------------------------------------------------*/ -int -coap_set_rest_status(void *packet, unsigned int code) -{ - if (code <= 0xFF) - { - ((coap_packet_t *)packet)->code = (uint8_t) code; - return 1; - } - else - { - return 0; - } -} -/*-----------------------------------------------------------------------------------*/ /*- Server part ---------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/ @@ -395,7 +381,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t { PRINTF("well_known_core_handler(): bufpos<=0\n"); - coap_set_rest_status(response, BAD_OPTION_4_02); + coap_set_status_code(response, BAD_OPTION_4_02); coap_set_payload(response, "BlockOutOfScope", 15); } @@ -522,7 +508,7 @@ const struct rest_implementation coap_rest_implementation = { coap_get_header_uri_path, coap_set_header_uri_path, coap_get_rest_method, - coap_set_rest_status, + coap_set_status_code, coap_get_header_content_type, coap_set_header_content_type, diff --git a/apps/er-coap-07/er-coap-07.c b/apps/er-coap-07/er-coap-07.c index 3745f722f..c5c72abaa 100644 --- a/apps/er-coap-07/er-coap-07.c +++ b/apps/er-coap-07/er-coap-07.c @@ -760,6 +760,20 @@ coap_get_post_variable(void *packet, const char *name, const char **output) return 0; } /*-----------------------------------------------------------------------------------*/ +int +coap_set_status_code(void *packet, unsigned int code) +{ + if (code <= 0xFF) + { + ((coap_packet_t *)packet)->code = (uint8_t) code; + return 1; + } + else + { + return 0; + } +} +/*-----------------------------------------------------------------------------------*/ /*- HEADER OPTION GETTERS AND SETTERS -----------------------------------------------*/ /*-----------------------------------------------------------------------------------*/ unsigned int diff --git a/apps/er-coap-07/er-coap-07.h b/apps/er-coap-07/er-coap-07.h index 2346765da..62f943898 100644 --- a/apps/er-coap-07/er-coap-07.h +++ b/apps/er-coap-07/er-coap-07.h @@ -265,6 +265,10 @@ coap_status_t coap_parse_message(void *request, uint8_t *data, uint16_t data_len int coap_get_query_variable(void *packet, const char *name, const char **output); int coap_get_post_variable(void *packet, const char *name, const char **output); +/*-----------------------------------------------------------------------------------*/ + +int coap_set_status_code(void *packet, unsigned int code); + unsigned int coap_get_header_content_type(void *packet); int coap_set_header_content_type(void *packet, unsigned int content_type); diff --git a/examples/er-rest-example/Makefile b/examples/er-rest-example/Makefile index 50678a2db..3a9c02c58 100644 --- a/examples/er-rest-example/Makefile +++ b/examples/er-rest-example/Makefile @@ -50,8 +50,22 @@ endif APPS += erbium +#CUSTOM_RULE_C_TO_OBJECTDIR_O = 1 +#CUSTOM_RULE_S_TO_OBJECTDIR_O = 1 + include $(CONTIKI)/Makefile.include +#$(OBJECTDIR)/%.o: asmdir/%.S +# $(CC) $(CFLAGS) -MMD -c $< -o $@ +# @$(FINALIZE_DEPENDENCY) +# +#asmdir/%.S: %.c +# $(CC) $(CFLAGS) -MMD -S $< -o $@ + + + + + $(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c (cd $(CONTIKI)/tools && $(MAKE) tunslip6) diff --git a/examples/er-rest-example/coap-client-example.c b/examples/er-rest-example/coap-client-example.c index c67840306..4c6af9298 100644 --- a/examples/er-rest-example/coap-client-example.c +++ b/examples/er-rest-example/coap-client-example.c @@ -100,6 +100,7 @@ void client_chunk_handler(void *response) { uint8_t *chunk; + int len = coap_get_payload(response, &chunk); printf("|%.*s", len, (char *)chunk); }