Erbium code cleanup.
This commit is contained in:
parent
4c3e858df5
commit
2240289d1f
9 changed files with 430 additions and 340 deletions
|
@ -167,7 +167,7 @@ handle_incoming_data(void)
|
|||
PRINTF("handle_incoming_data(): block_offset >= response->payload_len\n");
|
||||
|
||||
response->code = BAD_OPTION_4_02;
|
||||
coap_set_payload(response, (uint8_t*)"BlockOutOfScope", 15);
|
||||
coap_set_payload(response, "BlockOutOfScope", 15); /* a const char str[] and sizeof(str) produces larger code size */
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -259,7 +259,7 @@ handle_incoming_data(void)
|
|||
}
|
||||
/* Reuse input buffer for error message. */
|
||||
coap_init_message(message, COAP_TYPE_ACK, coap_error_code, message->tid);
|
||||
coap_set_payload(message, (uint8_t *) coap_error_message, strlen(coap_error_message));
|
||||
coap_set_payload(message, coap_error_message, strlen(coap_error_message));
|
||||
coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, uip_appdata, coap_serialize_message(message, uip_appdata));
|
||||
}
|
||||
} /* if (new data) */
|
||||
|
@ -396,7 +396,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_payload(response, (uint8_t*)"BlockOutOfScope", 15);
|
||||
coap_set_payload(response, "BlockOutOfScope", 15);
|
||||
}
|
||||
|
||||
if (resource==NULL) {
|
||||
|
|
|
@ -186,27 +186,25 @@ coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payl
|
|||
void
|
||||
coap_observe_handler(resource_t *resource, void *request, void *response)
|
||||
{
|
||||
coap_packet_t *const coap_req = (coap_packet_t *) request;
|
||||
coap_packet_t *const coap_res = (coap_packet_t *) response;
|
||||
|
||||
static char content[26];
|
||||
|
||||
if (response && ((coap_packet_t *)response)->code<128) /* response without error code */
|
||||
if (coap_res && coap_res->code<128) /* response without error code */
|
||||
{
|
||||
if (IS_OPTION((coap_packet_t *)request, COAP_OPTION_OBSERVE))
|
||||
if (IS_OPTION(coap_req, COAP_OPTION_OBSERVE))
|
||||
{
|
||||
if (!IS_OPTION((coap_packet_t *)request, COAP_OPTION_TOKEN))
|
||||
{
|
||||
/* Set default token. */
|
||||
coap_set_header_token(request, (uint8_t *)"", 1);
|
||||
}
|
||||
|
||||
if (coap_add_observer(resource->url, &UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, ((coap_packet_t *)request)->token, ((coap_packet_t *)request)->token_len))
|
||||
if (coap_add_observer(resource->url, &UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, coap_req->token, coap_req->token_len))
|
||||
{
|
||||
coap_set_header_observe(response, 0);
|
||||
coap_set_payload(response, (uint8_t *)content, snprintf(content, sizeof(content), "Added as observer %u/%u", list_length(observers_list), COAP_MAX_OBSERVERS));
|
||||
coap_set_header_observe(coap_res, 0);
|
||||
coap_set_payload(coap_res, content, snprintf(content, sizeof(content), "Added as observer %u/%u", list_length(observers_list), COAP_MAX_OBSERVERS));
|
||||
}
|
||||
else
|
||||
{
|
||||
((coap_packet_t *)response)->code = SERVICE_UNAVAILABLE_5_03;
|
||||
coap_set_payload(response, (uint8_t *)"Too many observers", 18);
|
||||
coap_res->code = SERVICE_UNAVAILABLE_5_03;
|
||||
coap_set_payload(coap_res, "TooManyObservers", 16);
|
||||
} /* if (added observer) */
|
||||
}
|
||||
else /* if (observe) */
|
||||
|
|
|
@ -55,15 +55,18 @@
|
|||
/*-----------------------------------------------------------------------------------*/
|
||||
void coap_separate_handler(resource_t *resource, void *request, void *response)
|
||||
{
|
||||
coap_packet_t *const coap_req = (coap_packet_t *) request;
|
||||
coap_packet_t *const coap_res = (coap_packet_t *) response;
|
||||
|
||||
PRINTF("Separate response for /%s \n", resource->url);
|
||||
/* send separate ACK. */
|
||||
coap_packet_t ack[1];
|
||||
/* ACK with empty code (0) */
|
||||
coap_init_message(ack, COAP_TYPE_ACK, 0, ((coap_packet_t *)request)->tid);
|
||||
coap_init_message(ack, COAP_TYPE_ACK, 0, coap_req->tid);
|
||||
/* Should only overwrite Header which is already parsed to request. */
|
||||
coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, (uip_appdata + uip_ext_len), coap_serialize_message(ack, (uip_appdata + uip_ext_len)));
|
||||
|
||||
/* Change response to separate response. */
|
||||
((coap_packet_t *)response)->type = COAP_TYPE_CON;
|
||||
((coap_packet_t *)response)->tid = coap_get_tid();
|
||||
coap_res->type = COAP_TYPE_CON;
|
||||
coap_res->tid = coap_get_tid();
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -313,7 +313,7 @@ int coap_set_header_block2(void *packet, uint32_t num, uint8_t more, uint16_t si
|
|||
int coap_get_header_block1(void *packet, uint32_t *num, uint8_t *more, uint16_t *size, uint32_t *offset);
|
||||
int coap_set_header_block1(void *packet, uint32_t num, uint8_t more, uint16_t size);
|
||||
|
||||
int coap_get_payload(void *packet, const uint8_t **payload);
|
||||
int coap_set_payload(void *packet, uint8_t *payload, size_t length);
|
||||
int coap_get_payload(void *packet, uint8_t **payload);
|
||||
int coap_set_payload(void *packet, const void *payload, size_t length);
|
||||
|
||||
#endif /* COAP_07_H_ */
|
||||
|
|
|
@ -184,10 +184,10 @@ struct rest_implementation {
|
|||
int (* set_header_location)(void *response, const char *location);
|
||||
|
||||
/** Get the payload option of a request. */
|
||||
int (* get_request_payload)(void *request, const uint8_t **payload);
|
||||
int (* get_request_payload)(void *request, uint8_t **payload);
|
||||
|
||||
/** Set the payload option of a response. */
|
||||
int (* set_response_payload)(void *response, uint8_t *payload, size_t length);
|
||||
int (* set_response_payload)(void *response, const void *payload, size_t length);
|
||||
|
||||
/** Get the query string of a request. */
|
||||
int (* get_query)(void *request, const char **value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue