Moved status code API from REST engine to main coap implementation.

This commit is contained in:
Matthias Kovatsch 2012-01-30 01:28:43 +01:00
parent a4589ee9da
commit f23e86f589
5 changed files with 35 additions and 16 deletions

View File

@ -285,20 +285,6 @@ coap_get_rest_method(void *packet)
return (rest_resource_flags_t)(1 << (((coap_packet_t *)packet)->code - 1)); 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 ---------------------------------------------------------------------*/ /*- 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"); 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); coap_set_payload(response, "BlockOutOfScope", 15);
} }
@ -522,7 +508,7 @@ const struct rest_implementation coap_rest_implementation = {
coap_get_header_uri_path, coap_get_header_uri_path,
coap_set_header_uri_path, coap_set_header_uri_path,
coap_get_rest_method, coap_get_rest_method,
coap_set_rest_status, coap_set_status_code,
coap_get_header_content_type, coap_get_header_content_type,
coap_set_header_content_type, coap_set_header_content_type,

View File

@ -760,6 +760,20 @@ coap_get_post_variable(void *packet, const char *name, const char **output)
return 0; 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 -----------------------------------------------*/ /*- HEADER OPTION GETTERS AND SETTERS -----------------------------------------------*/
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
unsigned int unsigned int

View File

@ -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_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_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); unsigned int coap_get_header_content_type(void *packet);
int coap_set_header_content_type(void *packet, unsigned int content_type); int coap_set_header_content_type(void *packet, unsigned int content_type);

View File

@ -50,8 +50,22 @@ endif
APPS += erbium APPS += erbium
#CUSTOM_RULE_C_TO_OBJECTDIR_O = 1
#CUSTOM_RULE_S_TO_OBJECTDIR_O = 1
include $(CONTIKI)/Makefile.include 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 $(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
(cd $(CONTIKI)/tools && $(MAKE) tunslip6) (cd $(CONTIKI)/tools && $(MAKE) tunslip6)

View File

@ -100,6 +100,7 @@ void
client_chunk_handler(void *response) client_chunk_handler(void *response)
{ {
uint8_t *chunk; uint8_t *chunk;
int len = coap_get_payload(response, &chunk); int len = coap_get_payload(response, &chunk);
printf("|%.*s", len, (char *)chunk); printf("|%.*s", len, (char *)chunk);
} }